1. 工具class-dump可以去官网下载
class-dump.下载地址 下载完成之后,将dmg文件中的class-dump复制到/usr/bin目录,并在终端执行如下执行进行赋权:
sudo chmod 777 /usr/bin/class-dump
复制代码
然后运行class-dump指令,即可看到很多输出,
class-dump
class-dump 3.5 (64 bit)
Usage: class-dump [options] <mach-o-file>
where options are:
-a show instance variable offsets
-A show implementation addresses
--arch <arch> choose a specific architecture from a universal binary (ppc, ppc64, i386, x86_64, armv6, armv7, armv7s, arm64)
-C <regex> only display classes matching regular expression
-f <str> find string in method name
-H generate header files in current directory, or directory specified with -o
-I sort classes, categories, and protocols by inheritance (overrides -s)
-o <dir> output directory used for -H
-r recursively expand frameworks and fixed VM shared libraries
-s sort classes and categories by name
-S sort methods by name
-t suppress header in output, for testing
--list-arches list the arches in the file, then exit
--sdk-ios specify iOS SDK version (will look in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS<version>.sdk
--sdk-mac specify Mac OS X version (will look in /Developer/SDKs/MacOSX<version>.sdk
--sdk-root specify the full SDK root path (or use --sdk-ios/--sdk-mac for a shortcut)
复制代码
如果有以上是输出说明安装class-dump成功了
2.使用class-dump
class-dump -H 小程序支付测试.app -o /Users/chiyz/Desktop/测试项目/ceshiyueyu
复制代码
二.查看可执行文件使用了哪些动态库?
可以使用终端查看:
otool -L testmacho
复制代码
三.在已经发布的.ipa包中注入代码
1.首先需要创建一个动态库,将动态库导入到app包中 2.需要在app包中的可执行文件添加动态库路径(相对路径) 下载yololib ->yololib binary (可执行文件) dylib file(动态库路径,相对于可执行文件的路径)-> 对app包进行签名压缩成xxxx.ipa->安装测试 执行命令的前提是要解锁yololib的权限,然后拷贝到/usr/local/lib目录下
yololib binary dylibfile
复制代码
在使用yololib命令处理之后可以使用
otool -L binary
复制代码
查看是否导入成功
在以上的操作中可能会遇到打开闪退的情况,这个时候可以使用另一个工具 下载地址:optool 将下载的optool拷贝到
/usr/local/lib
复制代码
接着执行命令
optool install -c load -p "@executable_path/xxx.framework/xxx" -t binary //executable_path为固定字符,不能更改
复制代码
对应的删除依赖库
发现用optool挺好用的,可以直接删掉依赖
optool uninstall -p @executable_pach/XXX.dylib -t TargetApp
复制代码
最后对app包进行签名压缩重命名。
3. 注入dylib动态库
1.创建dylib:⚠️注意dylib是Macos动态库所以创建的时候需要选择
- 至于在动态库中要实现什么功能自由发挥,可以在类的+load方法中测试打印、定时任务、网络请求、弹窗……。
- 或者找到main函数的入口执行默认操作,只需要在函数签名声明
__attribute__((constructor)) static
即可。
// 在一个动态库注入的类中添加的函数
__attribute__((constructor)) static void entry1() {
NSLog(@"开始调用了entry1函数");
}
__attribute__((constructor)) static void entry2() {
NSLog(@"开始调用了entry2函数");
}
+ (void)load {
NSLog(@"调用了load inMyHookPerson");
}
// 调用了load inMyHookPerson
// 开始调用了entry1函数
// 开始调用了entry2函数
复制代码
4.查看文件内是否包含关键字的命令
grep -r wechat .
复制代码
首先在命令行工具中,cd到指定的文件路径,接着执行grep -r (关键字) 例如查找wechat 可以使用grep -r wechat 注意在最后要加空格和点
[Binary file Data/Raw/uires/package_3_5.assetbundle matches
复制代码
相关参考链接:
- IOS 非越狱代码注入(Framework)
- iOS非越狱逆向--代码注入
- 注入动态库闪退
- 免越狱iOS插件注入
- iOS代码注入+HOOK微信登录详细描述了如何创建Dylib