コード例 #1
0
    def execute(self, api: Api):
        self.api = api

        max_distance = api.get_string_from_user(
            "Max distance",
            f"Give a max distance between addresses, leave empty for default ({DEFAULT_MAX_DISTANCE})",
        )
        try:
            max_distance = int(max_distance)
        except ValueError:
            max_distance = DEFAULT_MAX_DISTANCE

        self.init_gui()

        trace = api.get_visible_trace()
        row_id_min = sys.maxsize
        row_id_max = 0
        data_reads = []
        data_writes = []
        addresses = set()

        # get all memory accesses from trace
        for t in trace:
            if t["mem"]:
                if t["id"] > row_id_max:
                    row_id_max = t["id"]
                if t["id"] < row_id_min:
                    row_id_min = t["id"]
                for mem in t["mem"]:
                    if mem["access"] == "READ":
                        data_reads.append({"x": t["id"], "y": mem["addr"]})
                    elif mem["access"] == "WRITE":
                        data_writes.append({"x": t["id"], "y": mem["addr"]})
                    addresses.add(mem["addr"])

        # convert a set to sorted list
        addresses = sorted(addresses)

        # convert mem addresses to indexes (0..x)
        new_index = 0
        addr_indexes = {}
        i = 0
        for (i, addr) in enumerate(addresses):
            if i > 0:
                if abs(addr - addresses[i - 1]) > max_distance:
                    new_index += max_distance
            addr_indexes[addr] = new_index + i
        addr_max = new_index + i

        # replace addresses with indexes
        for d in data_reads:
            d["y"] = addr_indexes[d["y"]]
        for d in data_writes:
            d["y"] = addr_indexes[d["y"]]

        self.plot_item.setXRange(row_id_min, row_id_max, padding=0)
        self.plot_item.setYRange(1, addr_max, padding=0)

        self.scatter_plot_reads.setData(data_reads)
        self.scatter_plot_writes.setData(data_writes)
コード例 #2
0
    def execute(self, api: Api):

        want_to_continue = api.ask_user(
            "Warning",
            "This plugin may replace some of your comments, continue?")
        if not want_to_continue:
            return

        trace_data = api.get_trace_data()
        trace = api.get_visible_trace()

        for i, t in enumerate(trace):
            if 'mem' in t and t['mem']:
                comment = ""
                for mem in t['mem']:
                    addr = hex(mem['addr'])
                    value = mem['value']
                    if mem['access'] == "READ":
                        comment += f"[{ addr }] -> { hex(value) } "
                    elif mem['access'] == "WRITE":
                        comment += f"[{ addr }] <- { hex(value) } "
                    if 0x20 <= value <= 0x7e:
                        comment += f"'{ chr(value) }' "

                # Add comment to full trace
                row = t["id"]
                trace_data.trace[row]['comment'] = comment

                # Add comment to visible trace too because it could be filtered_trace
                trace[i]['comment'] = comment

        api.update_trace_table()
コード例 #3
0
    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")
コード例 #4
0
    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))