用 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:" ...
随机推荐
- java与.net之间xml传递,xml最前面多了个?
最近做一个项目,是java提供webservice供.net调用.参数采用xml格式.首先碰到的问题: 1).net这边采用XmlSerializer 方式序列化对象传递给对方.对方在本机调试可以收到 ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 3(Sorting/Searching)
第一题:340 - Master-Mind Hints UVA:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Item ...
- c#百分比
<div class="inner" style="width:@string.Format("{0:P1}", item.Maturitys) ...
- ExtJs之DHTML,DOM,EXTJS的事件绑定区别
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- SVN使用之分支、合并
首先说下为什么我们需要用到分支-合 并.比如项目demo下有两个小组,svn下有一个trunk版.由于客户需求突然变化,导致项目需要做较大改动,此时项目组决定由小组1继续完成原来正 进行到一半的工作[ ...
- lintcode:移动零
题目 给一个数组 nums 写一个函数将 0 移动到数组的最后面,非零元素保持原数组的顺序 注意事项 1.必须在原数组上操作2.最小化操作数 样例 给出 nums = [0, 1, 0, 3, 1 ...
- iOS 开发--转场动画
"用过格瓦拉电影,或者其他app可能都知道,一种点击按钮用放大效果实现转场的动画现在很流行,效果大致如下:" 本文主讲SWIFT版,OC版在后面会留下Demo下载 在iOS中,在同 ...
- JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-001Hibernate映射继承的方法
There are four different strategies for representing an inheritance hierarchy: Use one table per co ...
- 嵌入式linux的学习之路[转]
我认为的一条学习嵌入式Linux的路: 1)学习 Linux系统安装. 常用命令.应用程序安装. 2) 学习 Linux 下的 C 编程.这本书必学<UNIX 环境高级编程>.<UN ...
- 299. Bulls and Cows
题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...