关于这方面的中文资料太少了,以至于可能很多对插件开发感兴趣的孩子们都不知从何下手,于是呢我就写了这篇文章,希望对你能有所帮助。如果你觉得文章内容有什么错误呢也请提出来。

准备开发环境

1. 从 App Store 安装 Xcode,再安装 Command Line Tools。这个可以在 Xcode 的偏好设置里找到。

2. 安装 dpkg,用于 Debian 打包。先到 http://www.macports.org/install.php 下载安装对应操作系统版本的 MacPorts。然后在终端中通过 MacPorts 安装 dpkg,这里还是挺耗时间的,看网速了。

sudo port install dpkg

3. 同意 Xcode 的用户协议。在终端分别运行下面的两个命令,协议出来之后一直翻页到最后,输入 agree 后回车。

xcode-license
sudo xcode-license

4. 安装 iOSOpenDev。这是一个用于 Xcode 的各类 iOS 插件和工具开发的工程模板包。到 http://iosopendev.com/download/ 下载最新版本安装即可。

一个例子

iOSOpenDev 提供了各种各样的工程模板,涵盖命令行程序和各类插件,这里以一个 Substrate 插件为例,其它请同学们自行探索吧。

1. 新建一个工程,使用 CaptainHook Tweak 模板。记得要关闭 ARC。

2. 模板里面的注释很多,我觉得我已经没什么可说的了。于是偷懒一下啦,复制过来。重要的地方我加了中文注释。

//
// Hello.mm
// Hello
// // CaptainHook by Ryan Petrich
// see https://github.com/rpetrich/CaptainHook/ #import <Foundation/Foundation.h>
#import "CaptainHook/CaptainHook.h"
#include // not required; for examples only // Objective-C runtime hooking using CaptainHook:
// 1. declare class using CHDeclareClass()
// 2. load class using CHLoadClass() or CHLoadLateClass() in CHConstructor
// 3. hook method using CHOptimizedMethod()
// 4. register hook using CHHook() in CHConstructor
// 5. (optionally) call old method using CHSuper() @interface Hello : NSObject @end @implementation Hello -(id)init
{
if ((self = [super init]))
{
} return self;
} @end @class ClassToHook; // 这里以及下面所有的 ClassToHook 都换成你要 Hook 的类的名字 CHDeclareClass(ClassToHook); // declare class CHOptimizedMethod(0, self, void, ClassToHook, messageName) // hook method (with no arguments and no return value) // Hook 一个没有参数和返回值的方法,同学们按这个格式依葫芦画瓢地来就可以了,下面也一样。
{
// write code here ... CHSuper(0, ClassToHook, messageName); // call old (original) method
} CHOptimizedMethod(2, self, BOOL, ClassToHook, arg1, NSString*, value1, arg2, BOOL, value2) // hook method (with 2 arguments and a return value) // Hook 一个有 2 个参数,有返回值的方法
{
// write code here ... return CHSuper(2, ClassToHook, arg1, value1, arg2, value2); // call old (original) method and return its return value
} static void WillEnterForeground(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
// not required; for example only
} static void ExternallyPostedNotification(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
// not required; for example only
} CHConstructor // code block that runs immediately upon load
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // listen for local notification (not required; for example only)
CFNotificationCenterRef center = CFNotificationCenterGetLocalCenter();
CFNotificationCenterAddObserver(center, NULL, WillEnterForeground, CFSTR("UIApplicationWillEnterForegroundNotification"), NULL, CFNotificationSuspensionBehaviorCoalesce); // listen for system-side notification (not required; for example only)
// this would be posted using: notify_post("Qusic.Tweaks.Hello.eventname");
CFNotificationCenterRef darwin = CFNotificationCenterGetDarwinNotifyCenter();
CFNotificationCenterAddObserver(darwin, NULL, ExternallyPostedNotification, CFSTR("Qusic.Tweaks.Hello.eventname"), NULL, CFNotificationSuspensionBehaviorCoalesce); // CHLoadClass(ClassToHook); // load class (that is "available now")
// CHLoadLateClass(ClassToHook); // load class (that will be "available later") CHHook(0, ClassToHook, messageName); // register hook
CHHook(2, ClassToHook, arg1, arg2); // register hook [pool drain];
}

LZ你是不是忘了什么重要的东西?

讲到这里新同学们估计就会有类似下面的各种问题了:

  • Hook 是什么东西?
  • 我怎么知道我要 Hook 的类叫什么名字?
  • 我怎么知道我要 Hook 的方法的名字、参数、返回类型?
  • ……

你应该注意到文章的标题里的“一”了吧… 好吧,我将在下一篇教程里回答上面的问题。

用 Xcode 开发 Cydia Substrate 插件(一)的更多相关文章

  1. 用 Xcode 开发 Cydia Substrate 插件(二)

    上次介绍了一个如何用 Xcode 来构建 Substrate 插件,但是开发的具体过程还没有涉及,而这往往又正是初学者最难下手的地方,所以有了本文的后续. 不过在开始之前你要先做好思想准备,相比较开发 ...

  2. Android上玩玩Hook:Cydia Substrate实战

    作者简介:周圣韬,百度高级Android开发工程师,博客地址:http://blog.csdn.net/yzzst 了解Hook 还没有接触过Hook技术读者一定会对Hook一词感觉到特别的陌生,Ho ...

  3. 那些Xcode不能错过的插件

    转载来自网络   古人云“工欲善其事必先利其器”,打造一个强大的开发环境,是立即提升自身战斗力的绝佳途径!以下是搜集的一些有力的XCode插件.   1.全能搜索家CodePilot 2.0 你要找的 ...

  4. Xcode好用的插件

    注释:每当Xcode升级之后,都会导致原有的Xcode插件不能使用,这是因为每个插件的Info.plist中记录了该插件兼容Xcode版本的DVTPlugInCompatibilityUUID,而每个 ...

  5. Xcode好用的插件(随时更新)

    古人云"工欲善其事必先利其器",打造一个强大的开发环境,是立即提升自身战斗力的绝佳途径!下面简单介绍下插件是什么.如何使用Xcode插件以及一些常用的Xcode插件的推荐. 一.插 ...

  6. 利用Cydia Substrate进行Android HOOK

    Cydia Substrate是一个代码修改平台.它可以修改任何主进程的代码,不管是用Java还是C/C++(native代码)编写的.而Xposed只支持HOOK app_process中的java ...

  7. Android HOOK工具Cydia Substrate使用详解

    目录(?)[+] Substrate几个重要API介绍 MShookClassLoad MShookMethod 使用方法 短信监控实例   Cydia Substrate是一个代码修改平台.它可以修 ...

  8. 为WLW开发Latex公式插件

    WLW是写博客的利器,支持离线.格式排版等,而且拥有众多的插件.博客园推荐了代码插入插件,但是没有提供WLW的公式编译插件.目前我的一般做法是:先在Word下使用MathType编辑好公式,然后将公式 ...

  9. 我利用网上特效开发的Jquery插件

    我利用网上特效开发的Jquery插件 代码如下 (function($){ $.fn.Dialogx = function(options) { var defaults={ Width:" ...

随机推荐

  1. HDU 2674 N!Again(数学思维水题)

    题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...

  2. C++引用变量(转)

    引用变量 c++中引用变量的使用: 定义: int rate=80; int  & pt=rate 1.pt 是引用变量,申明引用变量时必须将其初始化.pt 和rate 的值指向相同的内存变量 ...

  3. Jquery 中map和each的区别

    <script type="text/javascript"> $(function () { var json = {"Name":"L ...

  4. HTTP协议header标头详解

    本文根据RFC2616(HTTP/1.1规范),参考 http://www.w3.org/Protocols/rfc2068/rfc2068 http://www.w3.org/Protocols/r ...

  5. POJ 1027 The Same Game(模拟)

    题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluste ...

  6. [转载] ACE 组播校验和出错问题解决

    源地址:http://yuanmuqiuyu2000.blog.sohu.com/140904942.html 使用ACE框架写了个组播简单的测试工具,但是测试过程中,总是发现udp校验和出错的信息. ...

  7. 李洪强iOS开发之添加手势

    李洪强iOS开发之添加手势 02 - 添加手势

  8. 重温《js权威指南》 第7,8章

    第七章 数组         数组是值的有序集合.js数组是无类型的,数组元素可以是任意类型,同一个数组中不同元素也可能有不同的类型.数组可以动态增长或缩减,创建时无须生命那个一个固定的大小并且数组大 ...

  9. 图解TCP/IP读书笔记(二)

    图解TCP/IP读书笔记(二) 第二章.TCP/IP基础知识 一.TCP/IP出现的背景及其历史 年份 事件 20世纪60年代后半叶 应DoD(美国国防部)要求,美国开始进行通信技术相关的研发 196 ...

  10. [iOS]为什么不要在init初始化方法里调用self.view

    首先.如果你调用self.view的时候,就会调用view的getter方法, 这个时候,view是空的,那么系统就会自动给你创建一个view,然后就会触发ViewDidLoad方法.那么这个时候,如 ...