Skip to content

Instantly share code, notes, and snippets.

@holyhan
Created September 12, 2018 11:05
Show Gist options
  • Select an option

  • Save holyhan/74f6233f118328a38afb4b04b67f467f to your computer and use it in GitHub Desktop.

Select an option

Save holyhan/74f6233f118328a38afb4b04b67f467f to your computer and use it in GitHub Desktop.

Revisions

  1. holyhan created this gist Sep 12, 2018.
    60 changes: 60 additions & 0 deletions SymbolResolution.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    #!/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()