(sym, options, exe_ctx)
| 55 | result.AppendMessage(output) |
| 56 | |
| 57 | def generateAssemblyFromSymbol(sym, options, exe_ctx): |
| 58 | target = exe_ctx.target |
| 59 | frame = exe_ctx.GetFrame() |
| 60 | instructions = sym.GetInstructions(target) |
| 61 | output = ds.attrStr(str(sym.addr.module.file.basename) + ', ', 'cyan') + ds.attrStr(str(sym.name), 'yellow') + '\n' |
| 62 | counter = 0 |
| 63 | |
| 64 | if len(instructions) == 0: |
| 65 | return |
| 66 | startAddress = instructions.GetInstructionAtIndex(0).GetAddress().GetLoadAddress(target) |
| 67 | |
| 68 | branches = [] |
| 69 | offsetSizeDict = {} |
| 70 | grepSearch = False |
| 71 | for inst in instructions: |
| 72 | line = ds.attrStr(str(counter).ljust(4), 'grey') |
| 73 | offset = str(inst.addr.GetLoadAddress(target) - startAddress) |
| 74 | branch = (ds.attrStr('*', 'yellow') if inst.is_branch else ' ') |
| 75 | pc = ds.attrStr('-> ', 'red') if frame.addr == inst.addr else ' ' |
| 76 | |
| 77 | loadaddr = ds.attrStr(hex(inst.addr.GetLoadAddress(target)) + (' <+' + offset + '>:').ljust(8), 'grey') |
| 78 | mnemonic = ds.attrStr(inst.GetMnemonic(target).ljust(5), 'red') |
| 79 | mnemonicStr = inst.GetMnemonic(target).ljust(5) |
| 80 | if len(inst.GetOperands(target).split(',')) > 1: |
| 81 | ops = inst.GetOperands(target).split(',') |
| 82 | operands = ds.attrStr(ops[0], 'bold') + ', ' + ds.attrStr(ops[1], 'yellow') |
| 83 | else: |
| 84 | operands = ds.attrStr(inst.GetOperands(target), 'bold') |
| 85 | comments = ds.attrStr(inst.GetComment(target), 'cyan') |
| 86 | |
| 87 | if options.grep_functions: |
| 88 | if re.search(options.grep_functions, comments): |
| 89 | grepSearch = True |
| 90 | |
| 91 | # TODO x64 only, need arm64 |
| 92 | if 'rip' in inst.GetOperands(target): |
| 93 | nextInst = instructions[counter + 1] |
| 94 | m = re.search(r"(?<=\[).*(?=\])", inst.GetOperands(target)) |
| 95 | pcComment = '' |
| 96 | |
| 97 | |
| 98 | |
| 99 | if m and nextInst: |
| 100 | nextPCAddr = hex(nextInst.addr.GetLoadAddress(target)) |
| 101 | commentLoadAddr = eval(m.group(0).replace('rip', nextPCAddr)) |
| 102 | |
| 103 | addr = target.ResolveLoadAddress(commentLoadAddr) |
| 104 | showComments, modName = generateDescriptionByAddress(addr, target) |
| 105 | if not showComments: |
| 106 | comments = '' |
| 107 | |
| 108 | if modName in comments: |
| 109 | comments = '' |
| 110 | pcComment += ds.attrStr('; ' + modName, 'green') |
| 111 | # interpreter.HandleCommand('image lookup -a ' + nextPCAddr, res) |
| 112 | |
| 113 | # # m = re.search('(?<=\().*(?=\s)', res.GetOutput()) |
| 114 | # # if m: |
no test coverage detected
searching dependent graphs…