class-dump
,顾名思义,就是用来dump
目标对象的class
信息的工具。它利用Objective-C
语言的runtime
特性,将存储在Mach-O
文件中得@interface
和@protocol
信息提取出来,并生成对应的.h
文件。
前提
当Mac
升级了OSX 10.11
后,配置class-dump
的时候,会发现逆向书上推荐的class-dump
存放目录/usr/bin
,class-dump
存放不进去,尝试过用sudo
还是不被允许。
原因
原因是 OSX10.11
的一个新特性Rootless
,也叫System Integrity Protection(SIP)
和SELinux
差不多,都是限制root
用户的权限。
其实可以在RecoveryMode
关闭这个特性,这样就直接可以读写/usr/bin
了,不过不建议。
(关闭方法:开机的时候按住option
出现选择磁盘的界面按command + R
进入RecoveryMode
,选择实用工具终端,输入csrutil disable
回车搞定)
解决
查找网上的资料,目前我用的方法是改变class-dump
的环境变量来使用。
class-dump下载点击这里
- 打开终端,输入mkdir ~/bin,在当前用户根目录下创建一个bin目录。
mkdir ~/bin
2.把下载下来的 dmg
打开,复制文件里面的class-dump
到创建的bin
目录下。赋予其可执行权限:
chmod +x ~/bin/class-dump
3.打开bash_profile
文件配置环境变量:
vim ~/.bash_profile
1> 按下 i 键进入编辑状态,在最下方加一行
export PATH=$HOME/bin/:$PATH
2> 按下esc
键,再按shift+
: 输入wq
进行保存退出编辑
4.在终端中执行
source ~/.bash_profile
5.测试是否改变成功,在终端输入
class-dump
6.如果出现如下,恭喜你,安装成功
zydeMacBook-Pro:~ zy$ class-dump
class-dump 3.5 (64 bit)
Usage: class-dump [options]
where options are:
-a show instance variable offsets
-A show implementation addresses
--arch choose a specific architecture from a universal binary (ppc, ppc64, i386, x86_64, armv6, armv7, armv7s, arm64)
-C only display classes matching regular expression
-f 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 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.sdk
--sdk-mac specify Mac OS X version (will look in /Developer/SDKs/MacOSX.sdk
--sdk-root specify the full SDK root path (or use --sdk-ios/--sdk-mac for a shortcut)
zydeMacBook-Pro:~ zy$
原文地址:class-dump最新安装方法