MacOS10.11的/usr/bin目录不可写后class-dump的处理办法

许多升级了OSX 10.11的朋友在配置class-dump的时候,会发现书上推荐的class-dump存放目录/usr/bin不再可写,如下所示:

 

192:~ snakeninny$ touch class-dump /usr/bin touch: /usr/bin: Operation not permitted 192:~ snakeninny$ sudo touch class-dump /usr/bin Password: touch: /usr/bin: Operation not permitted

可以把class-dump放到/usr/local/bin下,虽然每次执行class-dump都不需要输入全路径(即不用输入/usr/local/bin/class-dump),但此目录下的可执行文件要求执行者是super user,所以每次class-dump都需要输入sudo class-dump,比较麻烦,而且有安全隐患。我们的口号一贯是既要方便,又要安全,那么面对这种情况,我们该怎么办呢?跟我一起来操作吧~

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

 

192:~ snakeninny$ pwd class-dump /Users/snakeninny 192:~ snakeninny$ 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

你可能感兴趣的:(MacOS10.11的/usr/bin目录不可写后class-dump的处理办法)