iOS 越狱开发环境搭建教程

导出Private API

首先介绍下private API 它共分为两类:
1 在官方文档中没有呈现的API(在frameworks 下隐藏)
2 苹果明确申明不能使用的API ,在privateFrameworks 下
然后我们用到的工具是class-dump+DumpFrameworks.pl
class-dump可以从编译后的Objective-C的二进制文件中提取对应的数据结构及函数等声明
DumpFrameworks.pl是一个脚本,会在你的主目录下生成private的.h文件
DumpFrameworks.pl下载地址: http://ericasadun.com/HeaderDumpKit/
pl脚本需要简单的修改一下路径。
用法:
1 将下载好的 class-dump 放入usr/local/bin 下. 
     如果 ‘/usr/local/bin’ 不知道在哪里,可以在terminal 下输入cd ../.. 然后cd usr/bin  ‘open -a Finder /usr/local/bin’ 以便打开目录.
     记着 class-dump 要 使用 chmod 修改下执行权限.    例如:在usr/local/bin 对 class-dump 修改,可以这      样在terminal 切换到  usr/local/bin 目录下: chmod 777 class-dump .
2 将DumpFrameworks.pl 放入任意目录下.同样需要修改执行权限.
3. OK..现在所有的准备工作作好了. 我们在 terminal 的任意目录下 输入 : ./DumpFrameworks.pl
     等待…
     会有一个Heards 文件夹在你的主目录下. 里面包含了 Frmeworks 和 privateFrameworks 下所有的私有 API
这里说明一下,我在使用的时候有时候会报错,class-dump报错:Warning: This file does not contain any Objective-C runtime information. 目前还没有找到解决方案,估计是有些Frmeworks是用C写的,所以没法导出来。

导出的时候注意一下SpringBoard的路径,我这里导出ios5.0的如下:

class-dump -H /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/CoreServices/SpringBoard.app -o /Users/x/Desktop/SpringBoard

执行完命令之后就会生成.h文件了

然后把头文件拷贝到

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include/SpringBoard/

并将substrate.h移动到/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include/目录下

substrate.h文件的代码如下:

#ifndef SUBSTRATE_H_
#define SUBSTRATE_H_

#ifdef __cplusplus
extern "C" {
#endif
#include <mach-o/nlist.h>
#ifdef __cplusplus
}
#endif

#include <objc/runtime.h>
//#include <objc/message.h>
#include <dlfcn.h>

#ifdef __cplusplus
#define _default(value) = value
#else
#define _default(value)
#endif

#ifdef __cplusplus
extern "C" {
#endif
    
    void MSHookFunction(void *symbol, void *replace, void **result);
    IMP MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix _default(NULL));
    
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus

template <typename Type_>
static inline Type_ *MSHookMessage(Class _class, SEL sel, Type_ *imp, const char *prefix = NULL) {
    return reinterpret_cast<Type_ *>(MSHookMessage(_class, sel, reinterpret_cast<IMP>(imp), prefix));
}

template <typename Type_>
static inline void MSHookFunction(Type_ *symbol, Type_ *replace, Type_ **result) {
    return MSHookFunction(
                          reinterpret_cast<void *>(symbol),
                          reinterpret_cast<void *>(replace),
                          reinterpret_cast<void **>(result)
                          );
}

template <typename Type_>
static inline void MSHookFunction(Type_ *symbol, Type_ *replace) {
    return MSHookFunction(symbol, replace, reinterpret_cast<Type_ **>(NULL));
}

template <typename Type_>
static inline void MSHookSymbol(Type_ *&value, const char *name, void *handle) {
    value = reinterpret_cast<Type_ *>(dlsym(handle, name));
}

template <typename Type_>
static inline Type_ &MSHookIvar(id self, const char *name) {
    Ivar ivar(class_getInstanceVariable(object_getClass(self), name));
    void *pointer(ivar == NULL ? NULL : reinterpret_cast<char *>(self) + ivar_getOffset(ivar));
    return *reinterpret_cast<Type_ *>(pointer);
}

#endif

#define MSHook(type, name, args...) \
static type (*_ ## name)(args); \
static type $ ## name(args) \

#define Foundation_f "/System/Library/Frameworks/Foundation.framework/Foundation"
#define UIKit_f "/System/Library/Frameworks/UIKit.framework/UIKit"
#define JavaScriptCore_f "/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore"
#define IOKit_f "/System/Library/Frameworks/IOKit.framework/IOKit"

#endif//SUBSTRATE_H_


然后把libsubstrate.dylib(网上下载)复制到:

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/

目录下。

至此导入完成,剩下的就是在工程中加入libsubstrate.dylib,引入头文件了。

MobileSubstrate Dylib Template for Xcode

下载地址:(http://modmyi.com/forums/iphone-ipod-touch-sdk-development-discussion/536221-mobilesubstrate-dylib-template-xcode-bam.html  )

 下载MobileSubstrate Dylib.zip‎并移动到:/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application目录下


xcode添加MobileSubstrateDylib开发模版这里没有测试成功,

方法:把MobileSubstrateDylib模版复制到

/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application目录下

然后新建工程即可看到MobileSubstrateDylib模版

之前的模板会出现在选项中
(PS:记得添加头文件substrate.h,已经添加framework---libsubstrate.dylib)
(PS:编译的时候选择Device)

编译好后,右键点击生成的app,选择显示包内容,给里面的程序添加后缀—.dylib,即:***.dylib
自己新建个后缀为.plist的同名文件,在里面添加要hook的应用

最后将dylib和同名的plist放到/Library/MobileSubstrate/DynamicLibraries目录下,重启springboard即可

参考资料:http://www.ifans.com/forums/threads/xcode-template-mobilesubstrate-dylib-template-for-xcode.163185/
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值