用 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:" ...
随机推荐
- POJ 3320
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6496 Accept ...
- C#编程使用Managed Wifi API连接无线SSID
C#编程使用Managed Wifi API连接无线SSIDhttp://www.2cto.com/kf/201307/227623.html Managed Wifi API - Homehttp: ...
- zoj 3529 A Game Between Alice and Bob 博弈论
思路:每个数的SG值就是其质因子个数,在进行nim博弈 代码如下: #include<iostream> #include<cstdio> #include<cmath& ...
- UVA 10497 - Sweet Child Makes Trouble 高精度DP
Children are always sweet but they can sometimes make you feel bitter. In this problem, you will see ...
- JS初学的一些易错的知识点
1. false ,0 , "" ,undefined , null 在Boolean 环境下当成 false: null 在数值环境下当成 0: undefined 在数值 ...
- 笔者带你剖析淘宝TDDL(TAOBAO DISTRIBUTE DATA LAYER)
注:本文部分内容引用本人博客http://gao-xianglong.iteye.com/blog/1973591 前言 在开始讲解淘宝的TDDL(Taobao Distribute Data L ...
- 查找当前SQL Server下的Active Session正连接着哪个数据库
今天碰到个事.原本想把数据库设为单用户模式然后把REMOVE FILE.没想到悲剧了.因为很多进程都是需要远程连接这个库,导致别的进程抢在我前面连接了这个数据库,反到我连不上了.想把数据库切回MULT ...
- springboot源码解析 - 构建SpringApplication
1 package com.microservice.framework; 2 3 import org.springframework.boot.SpringApplication; 4 impor ...
- webapp 开发之iScroll 学习
demo.html <!doctype html> <html lang="en"> <head> <meta charset=" ...
- 测试用例生成工具ALLPAIRS(转)
ALLPAIRS是一个测试用例设计工具,用于Windows,但移植到了多种平台,以适应该脚本文件的一些小改动.它自动对所有实验技术进行设计,通过这个工具的方法可以在海量的数据组合中选择少量的数据生成测 ...