iOS App提交审核后,有时候会被打回原因是因为某个方法有问题,或者用了某些私有API,
有时候使用私有API不是自己的业务代码而是二方SDK,或者三方SDK所导致,为了快速找到使用的类和文件,我们可以用命令strings
和 otool
来帮助我们。
下面主要看看用法:
快速查找字符串
strings
是可以查看任意文件的任意字符串,strings命令在对象文件或二进制文件中查找可打印的字符串。字符串是4个或更多可打印字符的任意序列,以换行符或空字符结束。 strings命令对识别随机对象文件很有用。
strings Hema4iPhone | grep -i FFAbout
strings (可执行文件) | grep -i (查找的字符串)
举个例子,我们要查找Hema4iPhone可执行文件中是不是包含IOServiceGetMatchingService
字符串,那么可以这样:
strings Hema4iPhone | grep -i IOServiceGetMatchingService
结果,如果有就会显示,如果没有就没有:
justinjingdeMacBook-Pro-2:Desktop justinjing$ strings Hema4iPhone | grep -i IOServiceGetMatchingService
_IOServiceGetMatchingService
IOServiceGetMatchingService
_IOServiceGetMatchingService
IOServiceGetMatchingService
justinjingdeMacBook-Pro-2:Desktop justinjing$
快速查找方法或类
otool
是otool就是针对目标文件的展示工具(object file displaying tool)。
使用otool可以对指定的目标文件(object file)或库文件中的特定部分以特定的形式展现出来。
otool能够理解Mach-O格式和任何通用文件格式。
依赖的库查询
比如这个可执行文件名为Hema4iPhone,我们通过使用:
otool -L Hema4iPhone
结果:
justinjingdeMacBook-Pro-2:Desktop justinjing$ otool -L Hema4iPhone
Hema4iPhone (architecture armv7):
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 57.1.0)
/usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 254.6.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.2.0)
/usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.9.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8)
/System/Library/Frameworks/AVFoundation.framework/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
/System/Library/Frameworks/AVKit.framework/AVKit (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Accelerate.framework/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/System/Library/Frameworks/AddressBook.framework/AddressBook (compatibility version 1.0.0, current version 30.0.0)
/System/Library/Frameworks/AddressBookUI.framework/AddressBookUI (compatibility version 1.0.0, current version 33.0.0)
/System/Library/Frameworks/AssetsLibrary.framework/AssetsLibrary (compatibility version 1.0.0, current version 1.0.0)
......
就能看到这个应用运行所需要的系统库,这样app依赖了哪些系统库,版本号分别是多少就一目了然了。
汇编码
其实,查看依赖系统库仅仅是其中的一小功能。otool命令配上不同的参数可以发挥很强大的功用。
如果使用(这个命令慎用,会让电脑非常卡!!!)
otool -tV Hema4iPhone
则整个ARM的汇编码就都显示出来了,能看到ARM的汇编码。
Mach-O头结构等
其实otool文档本身的介绍就是:otool是对目标文件或者库文件的特定部分进行展示。这里举个例子,看一下其头部的内容是怎样的:
otool -h Hema4iPhone
结果显示如下:
justinjingdeMacBook-Pro-2:Desktop justinjing$ otool -h Hema4iPhone
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
0xfeedface 12 9 0x00 2 73 7444 0x00218085
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
0xfeedfacf 16777228 0 0x00 2 73 8256 0x00218085
justinjingdeMacBook-Pro-2:Desktop justinjing$
至于各字段的含义,可参考如下:
struct mach_header {
uint32_t magic; /* mach magic number identifier 魔鬼数字*/
cpu_type_t cputype; /* cpu specifier cpu类型和子类型 */
cpu_subtype_t cpusubtype; /* cpu specifier cpu类型和子类型 */
/* machine specifier */
uint32_t caps; /* capabilities 容量大小 */
uint32_t filetype; /* type of file 文件类型 */
uint32_t ncmds; /* number of load commands commands的个数 */
uint32_t sizeofcmds; /* the size of all the load commands commands大小 */
uint32_t flags; /* flags */
};
类的继承结构和引用关系
命令:
otool -ov Hema4iPhone
结果,然后可以根据结构来分析调用关系和继承关系了:
/Users/justinjing/Desktop
justinjingdeMacBook-Pro-2:Desktop justinjing$ otool -ov Hema4iPhone
Hema4iPhone (architecture armv7):
Contents of (__DATA,__objc_classlist) section
018b09a8 0x1afa7d4 _OBJC_CLASS_$_PodsDummy_XXXSQLite
isa 0x1afa7c0 _OBJC_METACLASS_$_PodsDummy_XXXSQLite
superclass 0x0
cache 0x0
vtable 0x0
data 0x18b6a78 (struct class_ro_t *)
flags 0x80
instanceStart 4
instanceSize 4
ivarLayout 0x0
name 0x17140ad PodsDummy_XXXSQLite
baseMethods 0x0 (struct method_list_t *)
baseProtocols 0x0
ivars 0x0
weakIvarLayout 0x0
baseProperties 0x0
Meta Class
isa 0x0
superclass 0x0
cache 0x0
vtable 0x0
data 0x18b6a50 (struct class_ro_t *)
flags 0x81 RO_META
instanceStart 20
instanceSize 20
ivarLayout 0x0
name 0x17140ad PodsDummy_XXXSQLite
baseMethods 0x0 (struct method_list_t *)
baseProtocols 0x0
ivars 0x0
weakIvarLayout 0x0
baseProperties 0x0
018b09ac 0x1afa7e8 _OBJC_CLASS_$_A2BlockInvocation
isa 0x1afa7fc _OBJC_METACLASS_$_A2BlockInvocation
superclass 0x0
cache 0x0
vtable 0x0
data 0x18b6be4 (struct class_ro_t *)
flags 0x184 RO_HAS_CXX_STRUCTORS
instanceStart 4
instanceSize 16
ivarLayout 0x17140d3
layout map: 0x03
name 0x17140c1 A2BlockInvocation
baseMethods 0x18b6b00 (struct method_list_t *)
entsize 12
count 10
name 0x14e30cf initWithBlock:methodSignature:blockSignature:
types 0x1730e62 @20@0:4@8@12@16
imp 0x5f171
name 0x14e3281 initWithBlock:
types 0x1730e58 @12@0:4@8
imp 0x5f22d
name 0x14e3290 initWithBlock:methodSignature:
types 0x1730e72 @16@0:4@8@12
imp 0x5f2c7
name 0x14e3236 invokeWithInvocation:returnValue:setOnInvocation:
types 0x1730e7f c20@0:4@8o^@12c16
imp 0x5f3f1
name 0x14e32af invokeWithInvocation:
types 0x1730e91 v12@0:4@8
imp 0x5f657
name 0x14e32c5 invokeWithInvocation:returnValue:
types 0x1730e9b c16@0:4@8o^@12
imp 0x5f677
name 0x14e32e7 .cxx_destruct
types 0x1730eaa v8@0:4
imp 0x5f6cb
name 0x14e316a methodSignature
types 0x1730eb1 @8@0:4
imp 0x5f699
name 0x14e31d2 block
types 0x1730eb1 @8@0:4
imp 0x5f6a9
name 0x14e317a blockSignature
types 0x1730eb1 @8@0:4
imp 0x5f6bb
baseProtocols 0x0
ivars 0x18b6b80
entsize 20
count 3
offset 0x1ae6fec 4
name 0x14e32f5 _methodSignature
type 0x1730eb8 @"NSMethodSignature"
alignment 2
size 4
offset 0x1ae6fe8 8
name 0x14e3306 _block
type 0x1730ecd @
alignment 2
size 4
offset 0x1ae6ff0 12
name 0x14e330d _blockSignature
type 0x1730eb8 @"NSMethodSignature"
alignment 2
size 4
weakIvarLayout 0x0
baseProperties 0x18b6bc4
entsize 8
count 3
name 0x15f31ca blockSignature
attributes 0x15f31d9 T@"NSMethodSignature",R,N,V_blockSignature
name 0x15f3204 methodSignature
attributes 0x15f3214 T@"NSMethodSignature",R,N,V_methodSignature
name 0x15f3240 block
attributes 0x15f3246 T@,R,C,N,V_block
instanceProperties 0x0
Contents of (__DATA,__objc_protolist) section
0000000101d26360 0x1021a3fb0
0000000101d26368 0x1021bd300
0000000101d26370 0x1021a4010
0000000101d26378 0x1021a4070
0000000101d26380 0x1021a40f8
0000000101d26388 0x1021a4158
0000000101d26390 0x1021a41b8
0000000101d26398 0x1021a4218
0000000101d263a0 0x1021a4280
0000000101d27878 0x1021c39d8
0000000101d27880 0x1021c3a30
Contents of (__DATA,__objc_imageinfo) section
version 0
flags 0x0