用 Xcode 开发 Cydia Substrate 插件(一)
关于这方面的中文资料太少了,以至于可能很多对插件开发感兴趣的孩子们都不知从何下手,于是呢我就写了这篇文章,希望对你能有所帮助。如果你觉得文章内容有什么错误呢也请提出来。
准备开发环境
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 插件(一)的更多相关文章
- 用 Xcode 开发 Cydia Substrate 插件(二)
上次介绍了一个如何用 Xcode 来构建 Substrate 插件,但是开发的具体过程还没有涉及,而这往往又正是初学者最难下手的地方,所以有了本文的后续. 不过在开始之前你要先做好思想准备,相比较开发 ...
- Android上玩玩Hook:Cydia Substrate实战
作者简介:周圣韬,百度高级Android开发工程师,博客地址:http://blog.csdn.net/yzzst 了解Hook 还没有接触过Hook技术读者一定会对Hook一词感觉到特别的陌生,Ho ...
- 那些Xcode不能错过的插件
转载来自网络 古人云“工欲善其事必先利其器”,打造一个强大的开发环境,是立即提升自身战斗力的绝佳途径!以下是搜集的一些有力的XCode插件. 1.全能搜索家CodePilot 2.0 你要找的 ...
- Xcode好用的插件
注释:每当Xcode升级之后,都会导致原有的Xcode插件不能使用,这是因为每个插件的Info.plist中记录了该插件兼容Xcode版本的DVTPlugInCompatibilityUUID,而每个 ...
- Xcode好用的插件(随时更新)
古人云"工欲善其事必先利其器",打造一个强大的开发环境,是立即提升自身战斗力的绝佳途径!下面简单介绍下插件是什么.如何使用Xcode插件以及一些常用的Xcode插件的推荐. 一.插 ...
- 利用Cydia Substrate进行Android HOOK
Cydia Substrate是一个代码修改平台.它可以修改任何主进程的代码,不管是用Java还是C/C++(native代码)编写的.而Xposed只支持HOOK app_process中的java ...
- Android HOOK工具Cydia Substrate使用详解
目录(?)[+] Substrate几个重要API介绍 MShookClassLoad MShookMethod 使用方法 短信监控实例 Cydia Substrate是一个代码修改平台.它可以修 ...
- 为WLW开发Latex公式插件
WLW是写博客的利器,支持离线.格式排版等,而且拥有众多的插件.博客园推荐了代码插入插件,但是没有提供WLW的公式编译插件.目前我的一般做法是:先在Word下使用MathType编辑好公式,然后将公式 ...
- 我利用网上特效开发的Jquery插件
我利用网上特效开发的Jquery插件 代码如下 (function($){ $.fn.Dialogx = function(options) { var defaults={ Width:" ...
随机推荐
- UITbaleView上按钮的单选
设置Id属性,标记是哪个cell @property (nonatomic,assign)NSInteger Id; 设置一个普通状态和选中状态图片不同的按钮 _choose = [[UIButton ...
- DF学Mysql(三)——索引操作
概要: 数据库对象索引其实与书的目录非常相似,主要是为了提高从表中检索数据的速度. 由于数据存储在数据库表中,所以索引是创建在数据库表对象上的,由表中的一个字段或多个字段生成的键组成,这些键存储在数据 ...
- springmvc web应用程序 java
搭建普通 springmvc 1.如图建立相关文件 建立在WEB-INF下比较安全,不能直接访问资源. 2.建立Controller控制器,如图 3.需要导入的jar包 commons-logging ...
- ExtJs之Ext.core.Element
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- Codeforces Round #336 (Div. 2) B. Hamming Distance Sum 计算答案贡献+前缀和
B. Hamming Distance Sum Genos needs your help. He was asked to solve the following programming pro ...
- shell脚本执行查找进程,然后查杀进程
shell 执行查找进程,然后查杀进程脚本如下: ps -ef | grep 'IOE' |grep -v 'grep'| awk '{print \$2}' |while read pid; do ...
- 阿里巴巴fastJson进行json数据解析
1.生成JsonObject:将Java bean转换成易于处理和传输的strig的key value形式. 2.解析JsonObject:将收到的字符串转换成JsonObejct这种对象形式,Jso ...
- linux下配置QT(很全的步骤,从下载开始,配置QMAKESPEC)
一.下载Qt源码包到本机,然后解压缩#tar zxvf qt-x11-opensource-src-4.3.2.tar.gz -C /usr/local //将qt-x11-opensource-sr ...
- JBoss 性能优化(解决Jboss内存紧张的问题)
修改$JBOSS_HOME/bin/run.conf文件 JAVA_OPTS="-Xms 520m -Xmx 1220m -Xss 15120k +XX:AggressiveHeap&q ...
- .NET单例模式-------各种写法&&验证
.NET单例模式-------各种写法&&验证 前言 单例模式对大家来说都不陌生,也很容易搞懂其原理,本篇文章也不提供单例模式的详细原理解析,本篇文章的目的是展示在C#中单例模式的各种 ...