Skip to content

Instantly share code, notes, and snippets.

@holyhan
Created September 12, 2018 11:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holyhan/74f6233f118328a38afb4b04b67f467f to your computer and use it in GitHub Desktop.
Save holyhan/74f6233f118328a38afb4b04b67f467f to your computer and use it in GitHub Desktop.
iOS crash file symbolized!
#!/usr/bin/env python3
import os
import sys
import re
def symbol_crash_file():
'''
crash file symbolized
'''
if len(sys.argv) < 4:
print("Please input follow command:'python3 SymbolResolution.py 'dSYM filename' 'raw crash file' 'output crash file''")
return
dSYMFileName = sys.argv[1]
crashFileName = sys.argv[2]
outputFileName = sys.argv[3]
if not os.path.exists(dSYMFileName):
print("dSYM file not exist!")
return
if not os.path.exists(crashFileName):
print("Raw crash file not exist!")
return
crashFile = open(crashFileName)
#
crashLineList = crashFile.readlines()
crashFile.close()
# raw crash file line count
lineCount = len(crashLineList)
currentLintCount = 0;
if not crashFile:
print("Open raw crash file failed, check if it exist!")
else:
regex = re.compile(r'^[0-9]+\s+\S+\s+0x[0-9a-f]{16}\s+0x[0-9a-f]{9}\s+\+\s+[0-9]+$')
outputFile = open(outputFileName, 'w')
print("Start symbolized crash file!")
for line in crashLineList:
currentLintCount += 1
if regex.match(line):
pattern = re.compile(r'0x\w+')
addrList = pattern.findall(line)
if len(addrList) == 2:
result = os.popen('atos -o ' + dSYMFileName + '/Contents/Resources/DWARF/' + dSYMFileName.split('.')[0] + ' -arch armv7 -l ' + addrList[1] + ' ' + addrList[0])
replacedText = re.sub(r'0x\w+.+', result.read(), line)
outputFile.write(replacedText.strip() + '\n')
else:
outputFile.write(line)
else:
outputFile.write(line)
print('\r', end='')
print("Finished line count: %d, total line count: %d" %(currentLintCount, lineCount), end='')
sys.stdout.flush()
print('\n')
outputFile.close()
if __name__ == '__main__':
symbol_crash_file()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment