restore-symbol编译与使用

1、Mac电脑中新建一个文件夹restoresym
2、终端命令行 cd 到restoresym文件夹
3、在restoresym文件夹目录下 输入终端命令如下

git clone --recursive https://github.com/tobefuturer/restore-symbol.git

得到结果

Cloning into 'restore-symbol'...
remote: Enumerating objects: 85, done.
remote: Total 85 (delta 0), reused 0 (delta 0), pack-reused 85
Unpacking objects: 100% (85/85), done.
Submodule 'class-dump' (https://github.com/0xced/class-dump) registered for path 'class-dump'
Cloning into '/Users/username/Desktop/restoresym/restore-symbol/class-dump'...
remote: Enumerating objects: 10038, done.        
remote: Total 10038 (delta 0), reused 0 (delta 0), pack-reused 10038        
Receiving objects: 100% (10038/10038), 3.63 MiB | 2.01 MiB/s, done.
Resolving deltas: 100% (6518/6518), done.
Submodule path 'class-dump': checked out 'a8877b6695f317816322134944a410de09da4911'

4、终端cd到git刚克隆的restore-symbol目录下,并 ls -l 查看信息

cd /Users/UserName/Desktop/restoresym/restore-symbol

ls -l

total 16
-rw-r--r--   1 UserName  staff  3142  5 14 15:22 README.md
drwxr-xr-x  20 UserName  staff   640  5 14 15:22 class-dump
-rw-r--r--   1 UserName  staff   415  5 14 15:22 makefile
drwxr-xr-x   3 UserName  staff    96  5 14 15:22 picture
drwxr-xr-x   4 UserName  staff   128  5 14 15:22 restore-symbol.xcodeproj
drwxr-xr-x   3 UserName  staff    96  5 14 15:22 search_oc_block
drwxr-xr-x  11 UserName  staff   352  5 14 15:22 source

5、终端执行make

make

得到结果

rm -rf libMachObjC.a restore-symbol.dSYM/ build/ class-dump/build/ 
rm -f restore-symbol
git submodule update --init --recursive
xcodebuild -project "restore-symbol.xcodeproj" -target "restore-symbol" -configuration "Release" CONFIGURATION_BUILD_DIR="/Users/username/Desktop/restoresym/restore-symbol" -jobs 4 build
User defaults from command line:
    IDEBuildOperationMaxNumberOfConcurrentCompileTasks = 4

Build settings from command line:
    CONFIGURATION_BUILD_DIR = /Users/username/Desktop/restoresym/restore-symbol

Build Preparation
Build task concurrency set to 4 via user default IDEBuildOperationMaxNumberOfConcurrentCompileTasks

note: Using new build system
note: Planning build
note: Constructing build description

2021-05-14 15:23:28.558 xcodebuild[12345:123456]  iPhoneConnect: 📱<DVTiOSDevice (0x123412341234), iphonename的 iPhone, iPhone, 14.4 (12345),12345678901234567890> unable to mount developer disk image, (Error Domain=com.apple.dtdevicekit Code=601 "Could not locate device support files." UserInfo={DeviceType=iPhone9,2, NSLocalizedDescription=Could not locate device support files., NSLocalizedRecoverySuggestion=This iPhone 7 P(Model 1234, 1234, 1234, 1234) is running iOS 14.4 (12345), which may not be supported by this version of Xcode.}) {
    DeviceType = "iPhone9,2";
    NSLocalizedDescription = "Could not locate device support files.";
    NSLocalizedRecoverySuggestion = "This iPhone 7 Plus (Model 1234, 1234, 1234, 1234) is running iOS 14.4 (12345), which may not be supported by this version of Xcode.";
}
CreateBuildDirectory /Users/username/Desktop/restoresym/restore-symbol/build (in target: restore-symbol)
    cd /Users/username/Desktop/restoresym/restore-symbol
    builtin-create-build-directory /Users/username/Desktop/restoresym/restore-symbol/build

省略

GenerateDSYMFile /Users/username/Desktop/restoresym/restore-symbol/restore-symbol.dSYM /Users/username/Desktop/restoresym/restore-symbol/restore-symbol (in target: restore-symbol)
    cd /Users/username/Desktop/restoresym/restore-symbol
    /Users/username/Desktop/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil /Users/username/Desktop/restore-symbol/restore-symbol -o /Users/username/Desktop/restoresym/restore-symbol/restore-symbol.dSYM

CodeSign /Users/username/Desktop/restoresym/restore-symbol/restore-symbol (in target: restore-symbol)
    cd /Users/username/Desktop/restoresym/restore-symbol
    export CODESIGN_ALLOCATE=/Users/username/Desktop/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
    
Signing Identity:     "-"

    /usr/bin/codesign --force --sign - --entitlements /Users/username/Desktop/restoresym/restore-symbol/build/restore-symbol.build/Release/restore-symbol.build/restore-symbol.xcent --timestamp=none /Users/username/Desktop/restoresym/restore-symbol/restore-symbol

** BUILD SUCCEEDED **

rm -rf libMachObjC.a restore-symbol.dSYM/ build/ class-dump/build/

可以看到,上面出现一个错误
running iOS 14.4 (12345), which may not be supported by this version of Xcode.}) {
DeviceType = "iPhone9,2";
NSLocalizedDescription = "Could not locate device support files.";

解决方案
连接iPhone 14.4报错,更换成连接 iPhone 6 V12.4.9,
重新

make

6、终端在restore-symbol目录下 ls -l

ls -l

得到结果

total 303360
-rw-r--r--   1 username  staff       3142  5 14 15:22 README.md
-rwxr-xr-x   1 username  staff  153430752  5  6 16:22 Snapchat
drwxr-xr-x  20 username  staff        640  5 14 15:23 class-dump
-rw-r--r--   1 username  staff        415  5 14 15:22 makefile
drwxr-xr-x   3 username  staff         96  5 14 15:22 picture
-rwxr-xr-x   1 username  staff     603584  5 14 15:23 restore-symbol
drwxr-xr-x   4 username  staff        128  5 14 15:22 restore-symbol.xcodeproj
drwxr-xr-x   3 username  staff         96  5 14 15:22 search_oc_block
drwxr-xr-x  11 username  staff        352  5 14 15:22 source

7、对APPName.app中的二进制文件APPName进行符号还原,复制二进制文件APPName到restore-symbol目录下,
注意,此时二进制文件添加了可执行权限。

chmod +x APPName

然后执行终端命令如下

./restore-symbol APPName -o APPName_with_symbol

结果如下,出现报错

=========== Start =============
Scan OC method in mach-o-file.
2021-05-14 15:33:23.255 restore-symbol[10711:121535] *** Assertion failure in -[CDObjectiveC2Processor loadClassAtAddress:], /Users/username/Desktop/restoresym/restore-symbol/class-dump/Source/CDObjectiveC2Processor.m:258
2021-05-14 15:33:23.269 restore-symbol[10711:121535] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: moduleName.length == length'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff207956af __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007fff204cd3c9 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff207be512 +[NSException raise:format:arguments:] + 88
    3   Foundation                          0x00007fff2157a6c9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
    4   restore-symbol                      0x0000000101a227ad -[CDObjectiveC2Processor loadClassAtAddress:] + 2813
    5   restore-symbol                      0x0000000101a202ab -[CDObjectiveC2Processor loadClasses] + 244
    6   restore-symbol                      0x0000000101a1d5b6 -[CDObjectiveCProcessor process] + 387
    7   restore-symbol                      0x0000000101a0af38 -[CDClassDump processObjectiveCData] + 344
    8   restore-symbol                      0x0000000101a0035d restore_symbol + 829
    9   restore-symbol                      0x0000000101a082de main + 514
    10  libdyld.dylib                       0x00007fff2063e621 start + 1
    11  ???                                 0x0000000000000004 0x0 + 4
)
libc++abi.dylib: terminating with uncaught exception of type NSException
zsh: abort      ./restore-symbol Snapchat -o Snapchat_with_symbol

根据上面的报错分析,restore-symbol/class-dump/Source/CDObjectiveC2Processor.m:258报错。

解决方案
在github上找class-dump的master上最新的代码,下载后替换掉

/Users/username/Desktop/restoresym/restore-symbol/class-dump/

里面的代码,然后终端重新

make

结果如下

rm -rf libMachObjC.a restore-symbol.dSYM/ build/ class-dump/build/ 
rm -f restore-symbol
git submodule update --init --recursive
xcodebuild -project "restore-symbol.xcodeproj" -target "restore-symbol" -configuration "Release" CONFIGURATION_BUILD_DIR="/Users/username/Desktop/restoresym/restore-symbol" -jobs 4 build
User defaults from command line:
    IDEBuildOperationMaxNumberOfConcurrentCompileTasks = 4

Build settings from command line:
    CONFIGURATION_BUILD_DIR = /Users/username/Desktop/restoresym/restore-symbol

Build Preparation
Build task concurrency set to 4 via user default IDEBuildOperationMaxNumberOfConcurrentCompileTasks

note: Using new build system
note: Planning build
note: Constructing build description
CreateBuildDirectory /Users/username/Desktop/restoresym/restore-symbol/build (in target: restore-symbol)
    cd /Users/username/Desktop/restoresym/restore-symbol
    builtin-create-build-directory /Users/username/Desktop/restoresym/restore-symbol/build

CreateBuildDirectory /Users/username/Desktop/restoresym/restore-symbol/class-dump/build (in target: MachObjC)
    cd /Users/username/Desktop/restoresym/restore-symbol/class-dump
    builtin-create-build-directory /Users/username/Desktop/restoresym/restore-symbol/class-dump/build

WriteAuxiliaryFile /Users/username/Desktop/restoresym/restore-symbol/class-dump/build/class-dump.build/Release/MachObjC.build/all-product-headers.yaml (in target: MachObjC)
    cd /Users/username/Desktop/restoresym/restore-symbol/class-dump
    write-file /Users/username/Desktop/restoresym/restore-symbol/class-dump/build/class-dump.build/Release/MachObjC.build/all-product-headers.yaml

省略

Ld /Users/username/Desktop/restoresym/restore-symbol/restore-symbol normal x86_64 (in target: restore-symbol)
    cd /Users/username/Desktop/restoresym/restore-symbol
    export MACOSX_DEPLOYMENT_TARGET=10.11
    /Users/username/Desktop/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Users/username/Desktop/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -L/Users/username/Desktop/restoresym/restore-symbol -F/Users/username/Desktop/restoresym/restore-symbol -filelist /Users/username/Desktop/restoresym/restore-symbol/build/restore-symbol.build/Release/restore-symbol.build/Objects-normal/x86_64/restore-symbol.LinkFileList -mmacosx-version-min=10.11 -Xlinker -object_path_lto -Xlinker /Users/username/Desktop/restoresym/restore-symbol/build/restore-symbol.build/Release/restore-symbol.build/Objects-normal/x86_64/restore-symbol_lto.o -fobjc-arc -fobjc-link-runtime -all_load -framework Foundation /Users/username/Desktop/restoresym/restore-symbol/libMachObjC.a -Xlinker -dependency_info -Xlinker /Users/username/Desktop/restoresym/restore-symbol/build/restore-symbol.build/Release/restore-symbol.build/Objects-normal/x86_64/restore-symbol_dependency_info.dat -o /Users/username/Desktop/restoresym/restore-symbol/restore-symbol

GenerateDSYMFile /Users/username/Desktop/restoresym/restore-symbol/restore-symbol.dSYM /Users/username/Desktop/restoresym/restore-symbol/restore-symbol (in target: restore-symbol)
    cd /Users/username/Desktop/restoresym/restore-symbol
    /Users/username/Desktop/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil /Users/username/Desktop/restoresym/restore-symbol/restore-symbol -o /Users/username/Desktop/restoresym/restore-symbol/restore-symbol.dSYM

CodeSign /Users/username/Desktop/restoresym/restore-symbol/restore-symbol (in target: restore-symbol)
    cd /Users/username/Desktop/restoresym/restore-symbol
    export CODESIGN_ALLOCATE=/Users/username/Desktop/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
    
Signing Identity:     "-"

    /usr/bin/codesign --force --sign - --entitlements /Users/username/Desktop/restoresym/restore-symbol/build/restore-symbol.build/Release/restore-symbol.build/restore-symbol.xcent --timestamp=none /Users/username/Desktop/restoresym/restore-symbol/restore-symbol

** BUILD SUCCEEDED **

rm -rf libMachObjC.a restore-symbol.dSYM/ build/ class-dump/build/

8、对APPName.app中的二进制文件APPName进行符号还原,复制二进制文件APPName到restore-symbol目录下,
注意,此时二进制文件添加了可执行权限。

chmod +x APPName

然后执行终端命令如下

./restore-symbol APPName -o APPName_with_symbol

结果成功

=========== Start =============
Scan OC method in mach-o-file.
2021-05-17 14:30:33.764 restore-symbol[3812:74088] Warning: Parsing method types failed, initFromAttributedSticker:originalContent:withStickerSearch:queryParams:
2021-05-17 14:30:33.780 restore-symbol[3812:74088] Warning: Parsing method types failed, convertQueryParams:withQuery:
2021-05-17 14:30:33.780 restore-symbol[3812:74088] Warning: Parsing instance variable type failed, aiTextBuilder
Scan OC method finish.
=========== Finish ============

即在restore-symbol目录中得到了APPName_with_symbol,把APPName_with_symbol复制回APPName.app替换掉原来的APPName可执行文件,在XCode编译时,LLDB调试时可以看到完整的带符号的调试堆栈信息。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,406评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,732评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,711评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,380评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,432评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,301评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,145评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,008评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,443评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,649评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,795评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,501评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,119评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,731评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,865评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,899评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,724评论 2 354

推荐阅读更多精彩内容