您的位置:首页 > 移动开发 > IOS开发

iOS逆向工程之class-dump

2017-04-23 18:43 393 查看
最近研究一些iOS逆向工程的知识,发现自己对iOS的了解还有很大的局限。逆向工程会用到很多工具,class-dump便是其中之一。

class-dump,顾名思义就是用来dump目标对象的class信息的工具,它利用的是Objective-C语言的runtime特性,将储存在Mach-O文件的头文件信息取出来,并生成对应的.h文件。下面介绍一下它的使用:

首先去点击打开链接下载最新版class-dump,然后将dmg文件里的class-dump复制到“/usr/bin”下,然后在终端里执行"sudo chmod 777/usr/bin/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)
-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)
但可能因为你的Mac版本过高没有/usr/sin这一项,可以按一下操作:

1、打开Terminal,输入mkdir~/bin,在当前用户根目录下创建一个bin目录;
2、把class-dump给拷贝到这个目录里,并赋予其可执行权限:
sudo chmod 777/usr/local/bin/class-dump
再执行
mv class-dump ~/bin;chmod +x ~/bin/class-dump;
3、打开~/.bash_profile文件:vi~/.bash_profile,在文件最上方加一行:
exportPATH=$HOME/bin/:$PATH,
然后保存并退出(在英文输入法中依次按下esc和:(shift
+ ;,即冒号),然后输入wq,回车即可);
4、在Terminal中执行source~/.bash_profile;
5、上面的操作把~/bin路径给加入了环境变量,我们测试一下好不好用;

使用方法:

在Terminal中执行:class-dump -H 我的app -o 我的app.h,我的app是你要提取的app的ipa文件,我的app.h是导出的目录,这样就可以去提取一些你想要了解的app的头文件了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS