restore-symbol編譯與使用

1杀捻、Mac電腦中新建一個文件夾restoresym
2古沥、終端命令行 cd 到restoresym文件夾
3彩扔、在restoresym文件夾目錄下 輸入終端命令如下

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

得到結(jié)果

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蒸痹、終端執(zhí)行make

make

得到結(jié)果

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/

可以看到春弥,上面出現(xiàn)一個錯誤
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

得到結(jié)果

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中的二進(jìn)制文件APPName進(jìn)行符號還原俺祠,復(fù)制二進(jìn)制文件APPName到restore-symbol目錄下公给,
注意,此時二進(jìn)制文件添加了可執(zhí)行權(quán)限蜘渣。

chmod +x APPName

然后執(zhí)行終端命令如下

./restore-symbol APPName -o APPName_with_symbol

結(jié)果如下淌铐,出現(xiàn)報錯

=========== 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

根據(jù)上面的報錯分析,restore-symbol/class-dump/Source/CDObjectiveC2Processor.m:258報錯蔫缸。

解決方案
在github上找class-dump的master上最新的代碼腿准,下載后替換掉

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

里面的代碼,然后終端重新

make

結(jié)果如下

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中的二進(jìn)制文件APPName進(jìn)行符號還原吐葱,復(fù)制二進(jìn)制文件APPName到restore-symbol目錄下,
注意校翔,此時二進(jìn)制文件添加了可執(zhí)行權(quán)限弟跑。

chmod +x APPName

然后執(zhí)行終端命令如下

./restore-symbol APPName -o APPName_with_symbol

結(jié)果成功

=========== 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復(fù)制回APPName.app替換掉原來的APPName可執(zhí)行文件防症,在XCode編譯時孟辑,LLDB調(diào)試時可以看到完整的帶符號的調(diào)試堆棧信息。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末蔫敲,一起剝皮案震驚了整個濱河市饲嗽,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌奈嘿,老刑警劉巖貌虾,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異裙犹,居然都是意外死亡尽狠,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進(jìn)店門叶圃,熙熙樓的掌柜王于貴愁眉苦臉地迎上來袄膏,“玉大人,你說我怎么就攤上這事盗似。” “怎么了平项?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵赫舒,是天一觀的道長。 經(jīng)常有香客問我闽瓢,道長接癌,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任扣讼,我火速辦了婚禮缺猛,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己荔燎,他們只是感情好耻姥,可當(dāng)我...
    茶點故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著有咨,像睡著了一般琐簇。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上座享,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天婉商,我揣著相機與錄音,去河邊找鬼渣叛。 笑死丈秩,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的淳衙。 我是一名探鬼主播蘑秽,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼滤祖!你這毒婦竟也來了筷狼?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤匠童,失蹤者是張志新(化名)和其女友劉穎埂材,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體汤求,經(jīng)...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡俏险,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了扬绪。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片竖独。...
    茶點故事閱讀 39,902評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖挤牛,靈堂內(nèi)的尸體忽然破棺而出莹痢,到底是詐尸還是另有隱情,我是刑警寧澤墓赴,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布竞膳,位于F島的核電站,受9級特大地震影響诫硕,放射性物質(zhì)發(fā)生泄漏坦辟。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一章办、第九天 我趴在偏房一處隱蔽的房頂上張望锉走。 院中可真熱鬧滨彻,春花似錦、人聲如沸挪蹭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽嚣潜。三九已至冬骚,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間懂算,已是汗流浹背只冻。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留计技,地道東北人喜德。 一個月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像垮媒,于是被迫代替她去往敵國和親舍悯。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,843評論 2 354

推薦閱讀更多精彩內(nèi)容