编写tweak——新时代的hacking

I am not a prolific programmer by any means.I have a programmer’s mind,and I have proven in my days I am capable of writing working solutions.I have a few tweaks in my name,and more ideas to be realized.Creating more has been about having more free time.However,my time has been spent becoming familiar with iOS-internals,because I find that I am a good learner.I have a fair understanding due to the tools we have available,made by great programmers before our time,and from documentation and examples shared by the community.Because of the nature of Cocoa and Objective-C,we can take a great adventure and introspection into the workings of third-party software,and Apple’s operating system.This provides a foundation and skills for making tweaks.We want to encourage tweak making because it has been the driving initiative behind the audience that wants to have jailbroken devices,besides for the groups that wish to only have a jailbreak for pirating apps and games.The growth of this jailbreak ecosystem has gone with the proliferation of new tweaks,ever pushing the boundaries of modification while maintaining a safe environment for the end-users.

The jailbreak development scene has given a unique opportunity to developers to express themselves in a new way.In the days before CydiaSubstrate,apps and games were not tweaked.This is a new concept;examining and debugging existing software and then rewriting portions of it with the least invasive tools available,the changes are nonpermanent and for the most part free of worry for breaking something with any lasting effect.Tweaks allow for a redefining of how software works and behaves.We do this with tweaks,and there has really been nothing like it before in the world of programming,even on the PC.There were opportunities throughout previous decades to make game patches,hacks and so forth,but it’s only with the emergence of the audience of jailbreakers and iOS that we find our unique situation.Only recently has it become feasible to make small adjustments to existing UI and modify how things work without requiring the replacement of whole parts of the code-CydiaSubstrate allows careful targeting of methods and functions.

It’s a lot of fun to discover how things work,and tweak making is the embodiment of that fun time for developers.One of the challenges for tweak making is coming up with new ideas to create,and sometimes these ideas only arise after studying the internals in some detail.If you make tweaks as a hobby,and not as a profession,you’re free to do as you wish and to focus on projects that interest you.For new tweak makers,there’re quite a lot of existing projects to learn from,but a lot of the easier projects have already been realized.Creating new original ideas that are unique is a task of being familiar with the available tweaks on Cydia,and then going to work discovering how the internal parts work,debugging and testing until you have a diagram or picture in your mind how it’s put together.When you reach a near complete understanding,you are primed to tackle whatever challenge you make for yourself.

Some of our greatest tools and resources are free:Apple’s own documentation is excellent,and for tweak makers we have a wiki and the opportunity to use class-dump to examine what methods are exposed for hooking inside the target app or process.Debugging and disassembly tools that vary from free to paid,all can be great assets for tweak makers.A well-studied programmer with some prior experience with standard projects will be in a good position to continue learning from these materials.To the contrary,a newcomer programmer,even a person with some good ideas will struggle at first with the learning curve.We recommend a core understanding of Objective-C and Cocoa principles for aspiring young tweak makers;this can be a significant investment of time,but it is really a hurdle for new tweak makers that haven’t a clue where to start.To the uninitiated,the object-oriented nature of the programming involved can be a daunting thing to realize.Generating tweak ideas can be a task for amateurs,but the writing of the code for the tweak implementation is often the result of planning and research and testing for a significant time.We find that many young new programmers are impatient because their ideas for new tweaks do take more time to materialize than they were willing to invest.Patience is a virtue of course,and the best-made tweaks are all products of careful programmers.

The greatest tweak is Activator(libactivator).Based on a commonsense idea of having more triggers system-wide,activator is also a graciously open-sourced project;the product of many months and years of work by our most senior tweak maker,Ryan Petrich.His dedication and expertise shines through in Activator,which doubles as a platform for third-parties to harness the powerful triggers from anyplace to use in their own projects.It represents a lot of research and understanding of the most obscure internals on iOS:SpringBoard and backboard.If there is one shining example to point to as a goal for a tweak maker to show how much research and careful planning can go into a tweak,that is the example to look towards.It’s a lofty project that none should consider as being trivial to do,however.For some aspiring developers it can be a great encouragement to see what is possible.Kudos to Ryan Petrich for making it,and for all he does to further the jailbreak development community.

As the repo maintainer for TheBigBoss,I have a job description for myself.Doing my job has given tremendous opportunity to be an influence or guidance for new tweak makers.Often their first experience with another member of the jailbreak development community is with myself when they first contact me or submit to the repo.We wish that all developers can be involved in the social channels of this scene:chat,forums,twitter et al.,however,it’s not uncommon that some developers work in relative isolation from these social groups.My involvement then can be seen as important:I may be the only other voice that the programmer will hear,and I will give an opinion on the technical merits of new tweak projects;often this first encounter is invaluable because those developers that work in isolation are not wise to many of the caveats and conventions we hold as important in this community.Our documentation and wikis have improved to make these details more available,but still I am often the first time a developer has some interaction with someone with a greater expertise than their own.I try to give my wisdom and guidance to the developers because its in our best interest to support,if not groom,newcomer developers so they feel as part of the group of jailbreak developers,and they can be pointed towards ways to avoid some of the pitfalls that many newcomers make.I take some pride in doing this and helping in part to strengthen the developer community that is based around the tweak-making culture.I want the jailbreak platform to continue to grow and mature by the great ideas that are envisioned and the expertise to realize them.

Do not be discouraged when the task seems difficult.We have some developers with years and decades of programming experience,and we also have some with only a few weeks or months.I come from the school of thought that it should be well made and well tested,and not rushed or forced.If you have a goal,it should not be merely to have something of yours published on a Cydia repo,but to give something to the public,which will enrich their jailbreak experiences-that is for hobbyists like myself.If you have some commercial interest in Cydia,and for making an selling tweaks,do wide testing with users and alongside other tweaks to help assure a product that works for many users and their combinations of tweaks;your duty as a responsible tweak maker is to be careful while you modify the insides of others’programs or apps,and to be thorough in testing compatibility with others’tweaks.

Tweak making is the new-age hacking.There’re already enough reasons for you to get started with tweak development,and we need tweaks to keep the jailbreak community in bloom.Join us,learn from others,work hard,be patient,and have fun.

(怎么说我都不算是一个高产的程序员,不过我的思维方式完全是程序员式的,因为在写程序时,我已经证明了自己具备解决问题的能力。虽然我以个人开发者的身份发布了几款tweak,但是还有很多想法没来得及实现,因为我的时间大都花在研究iOS内部构造上了,而且作品越多,意味着花在它们上面的时间就越多,所以……

通过使用前辈们创造的分析工具,参考iOS社区共享的文档和例子,我对iOS的了解还算深入。因为Cocoa和Objective-C语言的本质,我们有机会观察分析iOS及其软件的工作原理,这些都是编写tweak的先决条件。很多越狱iOS用户越狱自己设备的根本原因就是要安装那些方便好用的tweak,这也是我们鼓励iOS程序员来研究/开发tweak的原因之一,而绝不是为了安装盗版软件。随着新tweak的出现,这种越狱生态系统也在不断蓬勃发展,同时也促成iOS上发生越来越多的改变。

在传统AppStore开发之外,越狱开发提供了一种非常独特的方式让开发者们表达自己的想法。在CydiaSubstrate出现之前,tweak的概念十分抽象,而现在它已经有了非常具体的定义:调试分析现有的软件,然后重写它的某个部分,并尽可能减小对其他部分的影响。重写所造成的改变并不是永久的,即使这种改变破坏了原有软件,也可以很方便地修复。用一句话概括就是:tweak重新定义了软件的功能。在编程的历史中,这种概念前所未有。在过去,做游戏修改器、给软件打补丁是很常见的现象,但随着iOS和越狱平台的出现,借助CydiaSubstrate的力量,我们可以把对软件的修改精确到函数级别,这是越狱开发的一大特色。

探索事物的工作原理是一件充满乐趣的事情,开发者编写tweak就是一例。在编写tweak之前,我们最先面对的挑战就是寻找灵感,而灵感往往是在对iOS进行重重分析之后才产生的。初学者可以从很多现成开源工程中学习,但很多简单的想法都已得到实现。如果想要原创tweak,那么首先你要熟悉Cydia上现有的tweak,然后分析它们的实现方法,直到理清所有逻辑,并且有把握编写相同功能的tweak。不断地重复这个过程,等你熟悉这个套路之后,也就基本具备把灵感变成tweak的能力了。

投入到iOS越狱开发并不是一件很无助的事情,因为许多最常用的工具和资源都是免费的:Apple官方文档编写十分详尽,iphonedevwiki上有很多有价值的信息,class-dump可以导出详尽的头信息。而且调试和反汇编工具也有免费的,如IDA demo和LLDB,这些都是编写tweak的利器。一名合格的AppStore开发者完全可以从这个角度入手,开始越狱开发之路;不过如果是一名纯菜鸟,你的日子可能就不那么好过了,我建议你先完整学习Objective-C和Cocoa的概念及原理,之后再考虑进入越狱开发这个领域。虽然前期的概念学习过程需要花费较长时间,但这是新手必须迈过的坎。小小提醒:Objective-C语言的面向对象特性可不是那么好懂的。虽然tweak的创意构思不设门槛,普通用户即可轻松完成,但实现的过程却需要程序员投入大量时间。在这些年的经历中,我发现很多初学者都不够耐心,他们有很好的想法,但是太急于求成,一旦发现完成tweak所需的时间多于预期,就打退堂鼓了。殊不知,Cydia中最出色的tweak,往往都是由那些有耐心、能坚持的开发者完成的。

比如Activator,它是迄今为止我眼中当之无愧的tweak界无冕之王,但它的创意并不高深,就是把常见的手势使用范围扩展至全系统(rpetrich不仅将它开源,还为第三方应用提供了接口,大将风范展露无疑)。虽然这个概念看似每个iOS用户都想得到,但Activator是iOS越狱社区最顶尖的开发者之一rpetrich经年累月完成的作品,凝结了他智慧的结晶,难度可想而知。Activator饱含rpetrich对iOS中最晦涩的SpringBoard和backboard的深入研究,如果一个tweak开发者想要拿一个tweak作为自己努力的终极目标,那么Activator再合适不过了。千万不要以为Activator完成的工作难度不大,如果你觉得自己足够强,可以试试看能不能写出同样功能的tweak。在此向rpetrich致敬!

作为TheBigBoss源的管理员,简单地说,我的工作是积极影响、向上引导初学者。对于这些人来说,我往往是他们进入越狱开发社区后碰到的第一个圈内人。我希望所有越狱开发者都能通过各种渠道,比如聊天工具、论坛、微博等,进行交流,但很多情况下还是有些开发者不善交流,独自工作,而这时我的作用就凸显出来了:他们往TheBigBoss源提交作品,就必须跟我交流,而我也会从技术角度评价他们tweak的优劣。他们或许不熟悉这个圈子的各种规则,于是我就会对他们进行科普,让他们少走些弯路。我愿意尽可能向他们提供帮助,让他们感觉自己是这个大圈子中的一员。我为自己的所作所为感到骄傲,因为我为越狱社区的文化建设贡献了一份力量。我衷心希望越狱社区能蓬勃发展,各种创意层出不穷,各类人才百花齐放。

当你碰到难题时,不要气馁。在越狱社区里,有些程序员已身经百战,也有些才刚刚上路,不管你属于哪一类,都应该以严肃、认真、负责的态度对待自己的作品,水到方能渠成,揠苗焉能助长?你要设立的目标不应仅仅是在Cydia上发布什么软件,而是分享你的经验,让大家受益于此。当然,这是站在非商业角度来说的。如果你想要靠卖Cydia软件赚钱,就尽可能广泛地测试你的软件,确保它能正常工作。作为一个负责任的tweak开发者,你要记住,你是在改动别人的软件,还要和其他的tweak兼容,所以要慎之又慎。

tweak开发是新时代的hacking。你已有足够的理由来说服自己加入tweak开发的大部队,越狱社区也需要tweak来保持旺盛的生命力。加入我们,从中学习,好好努力,保持耐心,你一定会感到由衷的快乐。)

Optimo

Cydia中最知名默认软件源TheBigBoss的管理员