コード例 #1
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())
コード例 #2
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])
コード例 #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
    def test_add_dependencies_for_concrete_pointers_of_adds_a_definition_with_codelocation_in_binary_if_data_in_readonly_memory(
            self):
        arch = self.ArchMock()

        writable = False
        loader = self.LoaderMock(
            self.MainObjectMock(self.SectionMock(writable)))

        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),
            CodeLocation(0x42, 0),
        )

        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,
        )

        origin_codelocation = CodeLocation(0, 0, info={'readonly': True})

        predecessor = list(
            dependency_graph.graph.predecessors(register_definition))[0]
        self.assertEqual(predecessor.codeloc, origin_codelocation)
コード例 #5
0
    def test_add_dependencies_for_concrete_pointers_of_fails_if_the_given_definition_is_not_in_the_graph(
            self):
        dependency_graph = DepGraph()

        definition = Definition(Register(0, 4), CodeLocation(0x42, 0),
                                DataSet(UNDEFINED, 4))

        with self.assertRaises(AssertionError) as cm:
            dependency_graph.add_dependencies_for_concrete_pointers_of(
                definition, None, None)

        ex = cm.exception
        self.assertEqual(
            str(ex),
            'The given Definition must be present in the given graph.')
コード例 #6
0
    def test_add_dependencies_for_concrete_pointers_of_does_nothing_if_pointer_is_not_concrete(
            self):
        arch = self.ArchMock()
        cfg = self.CFGMock({})
        loader = self.LoaderMock(self.MainObjectMock(self.SectionMock(True)))

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

        dependency_graph = DepGraph()
        dependency_graph.add_node(register_definition)

        nodes_before_call = dependency_graph.nodes()

        dependency_graph.add_dependencies_for_concrete_pointers_of(
            register_definition, cfg, loader)

        self.assertEqual(nodes_before_call, dependency_graph.nodes())
コード例 #7
0
def _a_mock_definition(atom: Atom = None):
    # Randomise code locations to forcefully produce "different" <Definition>s.
    statement_index = unique_randrange(1000)
    code_location = CodeLocation(0x42, statement_index)
    return Definition(atom, code_location, DataSet(set(), 8), None)