def execute(self, api: Api): trace = api.get_visible_trace() if not trace: return api.print('') trace_data = api.get_trace_data() ip_name = trace_data.get_instruction_pointer_name() if ip_name not in trace_data.regs: api.print('Error. Unknown instruction pointer name.') return ip_index = trace_data.regs[ip_name] counts = {} for t in trace: addr = t['regs'][ip_index] if addr in counts: counts[addr] += 1 else: counts[addr] = 1 api.print('%d unique addresses executed.' % len(counts)) api.print('Top 30 executed addresses:') counts = sorted(counts.items(), key=itemgetter(1), reverse=True) for address, count in counts[:30]: api.print('%s %d ' % (hex(address), count))
def execute(self, api: Api): api.print('') bookmarks = api.get_selected_bookmarks() for b in bookmarks: rows = "{:<13}".format(f"{b.startrow} - {b.endrow}") addr = "{:<12}".format(b.addr) disasm = "{:<20}".format(b.disasm) api.print(f"{rows} {addr} {disasm} ; {b.comment}")
def execute(self, api: Api): api.print("") bookmarks = api.get_selected_bookmarks() for b in bookmarks: if b.startrow is not b.endrow: rows = "{:<13}".format(f"{b.startrow} - {b.endrow}") else: rows = "{:<13}".format(f"{b.startrow}") addr = "{:<16}".format(b.addr) disasm = "{:<33}".format(b.disasm) api.print(f"{rows} {addr} {disasm} ; {b.comment}")
def execute(self, api: Api): trace_data = api.get_trace_data() trace = api.get_selected_trace() if not trace: print('PluginPrintRows error: Nothing selected.') return api.print('') row_id_digits = len(str(trace[-1]['id'])) for t in trace: ip = hex(trace_data.get_instruction_pointer(t['id'])) api.print('{:<{}} '.format(t['id'], row_id_digits) + ' %s ' % ip + ' {:<42}'.format(t['disasm']) + '; %s' % t['comment'])
def execute(self, api: Api): trace_data = api.get_trace_data() trace = api.get_selected_trace() if not trace: print("PluginPrintRows error: Nothing selected.") return api.print("") row_id_digits = len(str(trace[-1]["id"])) for t in trace: ip = hex(trace_data.get_instruction_pointer(t["id"])) api.print("{:<{}} ".format(t["id"], row_id_digits) + " %s " % ip + " {:<42}".format(t["disasm"]) + "; %s" % t.get("comment", ""))
def execute(self, api: Api): addr_and_size = api.get_values_from_user( "Filter by memory address", "Give me memory address and size, separated by comma:" ) if not addr_and_size or len(addr_and_size) != 2: print('Error. Wrong values given') return addr, size = addr_and_size api.print(f"Filtering by mem access addr: from {hex(addr)} to {hex(addr+size)}") trace = api.get_visible_trace() filtered_trace = [] for t in trace: for mem in t['mem']: if addr <= mem['addr'] <= (addr + size): filtered_trace.append(t.copy()) continue trace_len = len(filtered_trace) if trace_len > 0: api.print(f"Length of filtered trace: {trace_len}") api.set_filtered_trace(filtered_trace) api.show_filtered_trace() else: api.print("Filter plugin resulted in empty trace")
def execute(self, api: Api): api.print('----------------------------------') bookmarks = api.get_bookmarks() if not bookmarks: api.print('No bookmarks found.') return for b in bookmarks: row = '{:<8}'.format(b.startrow) api.print(row + '{:<20}'.format(b.disasm) + '; %s' % b.comment) api.print('') addresses = {} for b in bookmarks: if b.addr in addresses: addresses[b.addr] += 1 else: addresses[b.addr] = 1 addresses = sorted(addresses.items(), key=itemgetter(1), reverse=True) api.print('Duplicate bookmarks:') api.print('Address | count | start row') for address, count in addresses: # [:15] b_rows = [] for b in bookmarks: if address == b.addr: b_rows.append(b.startrow) b_rows_str = ' '.join(map(str, b_rows)) api.print('%s | %d | %s' % (address, count, b_rows_str)) api.print('') api.print('%d bookmarks total.' % len(bookmarks)) api.print('%d unique bookmarks.' % len(addresses)) lengths = [] for b in bookmarks: lengths.append(b.endrow - b.startrow + 1) avg_len = sum(lengths) / len(bookmarks) shortest = min(lengths) longtest = max(lengths) api.print('Average length of bookmark: %d' % avg_len) api.print('Longest: %d Shortest: %d' % (longtest, shortest))