前言
最近苹果的热更新和私有库问题检查的更严了,如果应用被拒,苹果在拒绝信中会说到使用strings
/otool
/nm
命令进行自查,所以总结了一些命令,方便查找和定位文件内容相关信息。
1、grep
作用:判断是否包含字符串
使用示例:
grep -r "xxx" path
检查是否包含(weixin)字符串:
matches
表示包含。
2、strings
作用:find the printable strings in a object, or other binary, file
使用示例:
strings a.out | grep hello
//检查 a.out 文件中含有 hello 字符串的字节序列检查二进制是否含有关键词的库(比如检查私有库):

- 更多使用说明
man strings
3、otool
作用: object file displaying tool. (针对目标文件的展示工具,用来发现应用中使用到了哪些系统库,调用了其中哪些方法,使用了库中哪些对象及属性)
使用示例:
otool -L path
//查看可执行程序都链接了那些库otool -L path | grep "xxx"
//筛选是否链接了xxx库otool -D path
//查看支持的架构otool -ov path
//output the Objective-C class structures and their defined methods.(输出Object-C类结构以及定义的方法)查看该应用是否砸壳:
otool -l path | grep crypt
//cryptid 0(砸壳) 1(未砸壳)
更多用法
man otool
4、nm
作用:display name list (symbol table). (显示符号表)
使用示例:
nm path
//得到Mach-O中的程序符号表nm -nm path
//目标文件的所有符号
符号表中标示为 undefined,意思是目标文件引用了类_XXX(XXX库),不过这并没有实现它。
nm -u path
//Display only undefined symbols.更多用法
man nm
5、file
作用:determine file type. (判断文件类型)
使用示例:
file path
判断.a/framework是静态库还是动态库:
静态库:

动态库:

6、lipo
作用:create or operate on universal files(创建或处理通用文件的工具)
使用示例:
lipo -info 'file path'
// 判断静态库所支持的平台 - i386 armv7 armv7s x86_64 arm64lipo -remove i386 origin_xxx.a -output op_xxx.a
// 删除静态库包括的i386平台lipo -thin i386 origin_xxx.a -output op_xxx.a
// 拆分静态库,只保留i386 CPU架构lipo -create device_xxx.a simulator_xxx.a -output universal_xxx.a
//对真机或者模拟器分别打出 .a 文件合并
7、参考阅读
- “nm tool” Xcode manual page
- iOS-private-api-scanner/iOS私有API扫描工作总结· mrmign/iOS-private-api-scanner
- iOS-private-api-checker苹果iOS私有API检查工具
- iOS开发-如何判断framework是动态库或静态库以及framework静态库转.a静态库
> 注:本文首发于 [iHTCboy's blog](http://iHTCboy.com),如若转载,请注来源