示例#1
0
    def test_add_dependencies_for_concrete_pointers_of_adds_a_definition_for_data_pointed_to_by_given_definition(
            self):
        arch = self.ArchMock()
        loader = self.LoaderMock(self.MainObjectMock(self.SectionMock(True)))

        memory_datum = self.MemoryDataMock(self.memory_address,
                                           str.encode(self.string_in_memory),
                                           len(self.string_in_memory),
                                           'string')
        cfg = self.CFGMock({self.memory_address: memory_datum})

        register_definition = Definition(
            Register(0, 4),
            None,
        )

        dependency_graph = DepGraph()
        dependency_graph.add_node(register_definition)

        dependency_graph.add_dependencies_for_concrete_pointers_of(
            [claripy.BVV(self.memory_address, arch.bits)], register_definition,
            cfg, loader)

        memory_definition = Definition(
            MemoryLocation(self.memory_address, self.string_in_memory_length),
            ExternalCodeLocation(),
        )

        nodes = list(dependency_graph.nodes())
        predecessors = list(
            dependency_graph.graph.predecessors(register_definition))
        self.assertEqual(nodes, [register_definition, memory_definition])
        self.assertListEqual(predecessors, [memory_definition])
示例#2
0
    def test_add_dependencies_for_concrete_pointers_of_does_nothing_if_data_pointed_to_by_definition_is_already_in_dependency_graph(
            self):
        arch = self.ArchMock()
        loader = self.LoaderMock(self.MainObjectMock(self.SectionMock(True)))

        memory_datum = self.MemoryDataMock(self.memory_address,
                                           str.encode(self.string_in_memory),
                                           len(self.string_in_memory),
                                           'string')
        cfg = self.CFGMock({self.memory_address: memory_datum})

        memory_location_definition = Definition(
            MemoryLocation(self.memory_address, self.string_in_memory_length),
            CodeLocation(0, 0),
        )

        register_definition = Definition(
            Register(0, 4),
            CodeLocation(0x42, 0),
        )

        dependency_graph = DepGraph(
            networkx.DiGraph([(memory_location_definition, register_definition)
                              ]))

        nodes_before_call = dependency_graph.nodes()

        dependency_graph.add_dependencies_for_concrete_pointers_of(
            [claripy.BVV(self.memory_address, arch.bits)], register_definition,
            cfg, loader)

        self.assertEqual(nodes_before_call, dependency_graph.nodes())
示例#3
0
    def test_add_dependencies_for_concrete_pointers_of_create_memory_location_with_undefined_data_if_data_pointed_to_by_definition_is_not_known(
            self):
        arch = self.ArchMock()
        cfg = self.CFGMock({})
        loader = self.LoaderMock(self.MainObjectMock(self.SectionMock(True)))

        datum_content = None
        datum_size = 0x4242
        memory_datum = self.MemoryDataMock(self.memory_address, datum_content,
                                           datum_size, 'unknown')
        cfg = self.CFGMock({self.memory_address: memory_datum})

        memory_definition = Definition(
            MemoryLocation(self.memory_address, datum_size),
            ExternalCodeLocation(), DataSet(UNDEFINED, datum_size * 8))

        register_definition = Definition(
            Register(0, 4), CodeLocation(0x42, 0),
            DataSet(self.memory_address, arch.bits))

        dependency_graph = DepGraph()
        dependency_graph.add_node(register_definition)

        dependency_graph.add_dependencies_for_concrete_pointers_of(
            register_definition, cfg, loader)

        nodes = list(dependency_graph.nodes())
        predecessors = list(
            dependency_graph.graph.predecessors(register_definition))
        self.assertEqual(nodes, [register_definition, memory_definition])
        self.assertListEqual(predecessors, [memory_definition])
示例#4
0
    target_atom = None
    reg_name = config["register"]
    if reg_name.startswith("MEM"):
        print("Target MEM is:",reg_name)
        mem_magic,target_mem_addr,mem_size = reg_name.split(",")
        if target_mem_addr.startswith("0x"):
            target_mem_addr = int(target_mem_addr,16)
        else:
            target_mem_addr = int(target_mem_addr)
        if mem_size.startswith("0x"):
            mem_size = int(mem_size,16)
        else:
            mem_size = int(mem_size)

        target_atom = MemoryLocation(bv_sp_init+target_mem_addr,mem_size)

    else:
        reg_vex_offset, reg_vex_size = prj.arch.registers[config["register"].lower()]
        print("Finding reg: %s  index: %d  size: %d" % (config["register"].lower(), reg_vex_offset, reg_vex_size))
        target_atom = Register(reg_vex_offset, reg_vex_size)

    obv_res = rd.observed_results[observation_point]

    # reg_def = obv_res.register_definitions.load(reg_vex_offset, reg_vex_size)
    # print(reg_def.values)
    # def_info_list = []
    # def_infos = []

    # def get_predecessors_rc(di):
    #     for i in rd.dep_graph.predecessors(di):