def execute(self, api: Api):

        input_dlg_data = [
            {
                "label": "Memory address",
                "data": "0x0"
            },
            {
                "label": "Size",
                "data": 2000
            },
            {
                "label": "Access types",
                "data": ["Reads and writes", "Reads", "Writes"]
            },
            {
                "label": "Source trace",
                "data": ["Full trace", "Filtered trace"]
            },
        ]
        options = api.get_values_from_user("Filter by memory address",
                                           input_dlg_data)

        if not options:
            return

        addr, size, access_types, trace_id = options
        addr = self.str_to_int(addr)

        print(
            f"Filtering by mem address: from {hex(addr)} to {hex(addr+size)}")

        if trace_id == 0:
            trace = api.get_full_trace()
        else:
            trace = api.get_filtered_trace()

        result_trace = []

        for t in trace:
            for mem in t["mem"]:
                if mem["access"].upper() == "READ" and access_types == 2:
                    continue
                elif mem["access"].upper() == "WRITE" and access_types == 1:
                    continue
                if addr <= mem["addr"] <= (addr + size):
                    result_trace.append(t.copy())
                    break  # avoid adding the same row more than once

        if len(result_trace) > 0:
            print(f"Length of filtered trace: {len(result_trace)}")
            api.set_filtered_trace(result_trace)
            api.show_filtered_trace()
        else:
            api.show_messagebox(
                "Error", "Could not find any rows accessing given memory area")
示例#2
0
    def execute(self, api: Api):

        self.api = api

        input_dlg_data = [
            {"label": "Memory address", "data": "0x0"},
            {"label": "Size", "data": 2000},
            {"label": "Source trace", "data": ["Full trace", "Filtered trace"]},
            {"label": "Memory operations", "data": ["Reads", "Writes"]},
            {"label": "Byte order", "data": ["Little endian", "Big endian"]},
        ]
        options = api.get_values_from_user("Data visualizer", input_dlg_data)

        if not options:
            return

        self.address, self.mem_size, trace_id, mem_op, byte_order = options
        self.address = self.str_to_int(self.address)

        if trace_id == 0:
            trace = api.get_full_trace()
        else:
            trace = api.get_filtered_trace()

        if not trace:
            print("Plugin error: empty trace.")
            return

        if mem_op == 0:
            self.mem_op = "READ"
        else:
            self.mem_op = "WRITE"

        if byte_order == 0:
            self.byteorder = "little"
        else:
            self.byteorder = "big"

        self.color_counter = 0
        self.address_colors = {}
        self.show_first_mem_access = True

        data = self.prepare_data(trace)
        self.show_hex_window(data)