Example #1
0
    def test_search_with_constraints(self):
        # now add some constraints to the search for struct_test3
        handler = constraints.ConstraintsConfigHandler()
        my_constraints = handler.read('test/src/ctypes3.constraints')
        results = haystack.search_record(self.memory_handler,
                                         self.ctypes3.struct_test3,
                                         my_constraints)
        # all valid record addresses are in self.offsets
        valid = self.offsets['test3']
        self.assertEqual(len(results), len(valid))
        for record, addr in results:
            self.assertIn(addr, valid)

        # search struct_Node with constraints
        results = haystack.search_record(self.memory_handler,
                                         self.ctypes3.struct_Node,
                                         my_constraints)
        # check the string output
        out = haystack.output_to_string(self.memory_handler, results)
        valid = self.offsets['test1']
        self.assertEqual(len(results), len(valid))
        for x in valid:
            self.assertIn(hex(x), out)
        # all valid record addresses are in self.offsets
        for record, addr in results:
            self.assertIn(addr, valid)
Example #2
0
    def test_search(self):
        handler = constraints.ConstraintsConfigHandler()
        my_constraints = handler.read('test/src/ctypes6.constraints')
        results = haystack.search_record(self.memory_handler, self.node, my_constraints)
        # 2 from test1
        # 3 from test_pointer_to_list
        # the rest have bad values in constrainged fields
        self.assertEquals(len(results), 2 + 3)
        # FIXME: that is a weird idea, that allocations are ordered that way
        (node1, offset1), (node2, offset2) = results[:2]
        self.assertEquals(node1.val1, 0xdeadbeef)
        self.assertEquals(node1.val2, 0xffffffff)
        self.assertEquals(node2.val1, 0xdeadbabe)
        self.assertEquals(node2.val2, 0xffffffff)

        # FIXME there is a circular reference in json.
        #with self.assertRaises(ValueError):
        #    haystack.output_to_json(self.memory_handler, results)
        #self.assertEquals(node2s['val1'], 0xdeadbabe)
        #self.assertEquals(node2s['val2'], 0xffffffff)
        model = self.memory_handler.get_model()
        #import code
        #code.interact(local=locals())
        x = api.output_to_pickle(self.memory_handler, results)
        rest = pickle.loads(x)
        return
Example #3
0
 def test_search(self):
     results = haystack.search_record(self.memory_handler, self.ctypes3.struct_test3)
     # without constraints, struct_test3 could be mapped pretty much anywhere in x64
     # all valid record addresses are in self.offsets
     valid = self.offsets['test1'] + self.offsets['test3']
     self.assertEqual(len(results), len(valid))
     for record, addr in results:
         self.assertIn(addr, valid)
Example #4
0
 def test_search(self):
     results = haystack.search_record(self.memory_handler, self.ctypes3.struct_test3)
     # without constraints, struct_test3 can only be mapped correctly to sutrc_test3.
     # struct_node is too small in x32
     valid = self.offsets['test3']
     self.assertEqual(len(results), len(valid))
     for record, addr in results:
         self.assertIn(addr, valid)
Example #5
0
    def test_search_with_constraints(self):
        # now add some constraints to the search for struct_test3
        handler = constraints.ConstraintsConfigHandler()
        my_constraints = handler.read('test/src/ctypes3.constraints')
        results = haystack.search_record(self.memory_handler, self.ctypes3.struct_test3, my_constraints)
        # all valid record addresses are in self.offsets
        valid = self.offsets['test3']
        self.assertEqual(len(results), len(valid))
        for record, addr in results:
            self.assertIn(addr, valid)

        # search struct_Node with constraints
        results = haystack.search_record(self.memory_handler, self.ctypes3.struct_Node, my_constraints)
        # check the string output
        out = haystack.output_to_string(self.memory_handler, results)
        valid = self.offsets['test1']
        self.assertEqual(len(results), len(valid))
        for x in valid:
            self.assertIn(hex(x), out)
        # all valid record addresses are in self.offsets
        for record, addr in results:
            self.assertIn(addr, valid)
Example #6
0
    def test_search(self):
        handler = constraints.ConstraintsConfigHandler()
        my_constraints = handler.read('test/src/ctypes6.constraints')
        results = haystack.search_record(self.memory_handler, self.node,
                                         my_constraints)
        self.assertEquals(len(results), 2)
        (node1, offset1), (node2, offset2) = results
        self.assertEquals(node1.val1, 0xdeadbeef)
        self.assertEquals(node1.val2, 0xffffffff)
        self.assertEquals(node2.val1, 0xdeadbabe)
        self.assertEquals(node2.val2, 0xffffffff)

        # FIXME there is a circular reference in json.
        #with self.assertRaises(ValueError):
        #    haystack.output_to_json(self.memory_handler, results)
        #self.assertEquals(node2s['val1'], 0xdeadbabe)
        #self.assertEquals(node2s['val2'], 0xffffffff)
        model = self.memory_handler.get_model()
        #import code
        #code.interact(local=locals())
        x = api.output_to_pickle(self.memory_handler, results)
        rest = pickle.loads(x)
        return