[英]Counting the number of selectors in an objective-c binary
Is there a tool/script which can help me iterate over (or just count) all the selectors in a objective-c binary. 是否有工具/脚本可以帮助我遍历(或仅计数)objective-c二进制文件中的所有选择器。 I want to statically analyze objective c binaries and get that metric.
我想静态分析目标c二进制文件并获取该指标。 I tried
otool -tV
but all it dumps is hex-data which I'm unable to parse. 我试过了
otool -tV
但是它只转储了我无法解析的十六进制数据。 Some people suggest using lldb
but I'm unsure how to do that. 有人建议使用
lldb
但我不确定该怎么做。
You can print all of the selectors like this: 您可以像这样打印所有选择器:
$ objdump -section=__objc_selrefs -macho /Applications/Xcode.app/Contents/Frameworks/IBFoundation.framework/IBFoundation
/Applications/Xcode.app/Contents/Frameworks/IBFoundation.framework/IBFoundation:
Contents of (__DATA,__objc_selrefs) section
000000000016a808 __TEXT:__objc_methname:init
000000000016a810 __TEXT:__objc_methname:copy
000000000016a818 __TEXT:__objc_methname:array
000000000016a820 __TEXT:__objc_methname:dictionary
000000000016a828 __TEXT:__objc_methname:addObject:
000000000016a830 __TEXT:__objc_methname:setObject:forKey:
000000000016a838 __TEXT:__objc_methname:appendString:
000000000016a840 __TEXT:__objc_methname:allKeys
...
If you want to count them, grep out the two header lines and pipe the rest into wc: 如果要计算它们,请grep出两条标题行,然后将其余的行传送到wc中:
$ objdump -section=__objc_selrefs -macho /Applications/Xcode.app/Contents/Frameworks/IBFoundation.framework/IBFoundation | grep ^'[0-9a-f]' | wc -l
1668
Another tool to explore is objdump
, which is otool
's successor. 另一个探索的工具是
objdump
,它是otool
的后继者。 You may need to use xcrun objdump
to run it, and it takes a -help
argument. 您可能需要使用
xcrun objdump
来运行它,并且它带有-help
参数。 For example try: 例如,尝试:
xcrun objdump -macho -objc-meta-data <binary> | grep "name 0x"
which may get you close to what you are after. 这可能会使您接近所追求的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.