Esempio n. 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)
Esempio n. 2
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)
Esempio n. 3
0
    def test_refresh(self):
        #handler = constraints.ConstraintsConfigHandler()
        #my_constraints = handler.read('test/src/ctypes6.constraints')
        #results = haystack.search_record(self.memory_handler, self.usual_structname, my_constraints)
        # search struct_usual with constraints
        results, validated = haystack.search.api.load_record(self.memory_handler, self.usual, self.address1)
        # check the string output
        retstr = haystack.output_to_string(self.memory_handler, [(results, validated)])
        self.assertTrue(isinstance(retstr, str))

        # string
        #retstr = api.show_dumpname(self.usual_structname, self.memdumpname,
        #                                self.address1, rtype='string')
        self.assertIn(str(0x0aaaaaaa), retstr)  # 0xaaaaaaa/178956970L
        self.assertIn(str(0x0ffffff0), retstr)
        self.assertIn('"val2b": 0L,', retstr)
        self.assertIn('"val1b": 0L,', retstr)

        # usual->root.{f,b}link = &node1->list; # offset list is (wordsize) bytes
        ## TU results based on __book
        node1_list_addr = hex(self.address2 + self.my_target.get_word_size())
        self.assertIn('"flink": { # <struct_entry at %s' % node1_list_addr, retstr)
        self.assertIn('"blink": { # <struct_entry at %s' % node1_list_addr, retstr)
        ## TU results based on direct access
        #node1_list_addr = self.address2 + self.my_target.get_word_size()
        #self.assertIn('"flink": 0x%0.8x' % node1_list_addr, retstr)
        #self.assertIn('"blink": 0x%0.8x' % node1_list_addr, retstr)

        # python
        usuals = haystack.output_to_python(self.memory_handler, [(results, validated)])
        usual, validated = usuals[0]
        self.assertEquals(validated, True)
        self.assertEquals(usual.val1, 0x0aaaaaaa)
        self.assertEquals(usual.val2, 0x0ffffff0)
        self.assertEquals(usual.txt, 'This a string with a test this is a test '
                                     'string')

        # so now we got python objects
        # that is node 1
        self.assertIsNotNone(usual.root.flink)
        self.assertEquals(usual.root.flink, usual.root.blink)
        #print usual.root.flink
        # that is node2
        self.assertEquals(usual.root.blink.flink, usual.root.flink.flink)
        # that is None (root.flink = root.blink)
        self.assertIsNone(usual.root.blink.blink)
        self.assertIsNone(usual.root.flink.blink)
        # that is None per design UT
        self.assertIsNone(usual.root.blink.flink.flink)

        # python 2 struct Node
        results, validated = haystack.search.api.load_record(self.memory_handler, self.node, self.address2)
        node1s = haystack.output_to_python(self.memory_handler, [(results, validated)])
        node1, validated = node1s[0]
        self.assertEquals(validated, True)
        self.assertEquals(node1.val1, 0xdeadbeef)
        self.assertEquals(node1.val2, 0xffffffff)

        results, validated = haystack.search.api.load_record(self.memory_handler, self.node, self.address3)
        node2s = haystack.output_to_python(self.memory_handler, [(results, validated)])
        node2, validated = node2s[0]
        self.assertEquals(validated, True)
        self.assertEquals(node2.val1, 0xdeadbabe)
        self.assertEquals(node2.val2, 0xffffffff)

        self.assertIsNotNone(usual.root.flink)

        # FIXME this was assertNotEquals. Why would the python obj be equals now ?
        # but we have different instances/references between calls to
        # show_dumpname
        self.assertEquals(usual.root.flink, node1.list)
        self.assertEquals(usual.root.blink.flink, node2.list)