示例#1
0
 def get_heap_pointers_from_allocated(self, heap_walker):
     """
     Search Heap pointers values in stack and heap.
         records values and pointers address in heap.
     :param dumpfilename:
     :param memory_handler:
     :param heap_walker:
     :return:
     """
     feedback = searchers.NoFeedback()
     matcher = matchers.PointerEnumerator(self.memory_handler)
     word_size = self.memory_handler.get_target_platform().get_word_size()
     enumerator = enumerators.AllocatedWordAlignedEnumerator(heap_walker, matcher, feedback, word_size)
     return utils.get_cache_heap_pointers(self, enumerator)
示例#2
0
    def get_heap_pointers(self):
        """
        @UNUSED

        Search Heap pointers values in stack and heap.
            records values and pointers address in heap.
        :param memory_handler:
        :param heap_walker:
        :return:
        """
        feedback = searchers.NoFeedback()
        matcher = matchers.PointerEnumerator(self.memory_handler)
        word_size = self.memory_handler.get_target_platform().get_word_size()
        enumerator = enumerators.WordAlignedEnumerator(self.heap, matcher, feedback, word_size)
        return utils.get_cache_heap_pointers(self, enumerator)
示例#3
0
    def test_pointer_enumerators_allocated_all(self):
        """
        Search pointers values in allocated chunks from all HEAP
        :return:
        """
        # prep the workers
        word_size = self._memory_handler.get_target_platform().get_word_size()
        feedback = searchers.NoFeedback()
        matcher = haystack.reverse.matchers.PointerEnumerator(
            self._memory_handler)
        finder = self._memory_handler.get_heap_finder()
        walkers = finder.list_heap_walkers()
        all_heaps_addrs = []
        for heap_walker in walkers:
            #if heap.start != 0x03360000:
            #    continue
            heap = heap_walker.get_heap_mapping()
            log.debug('heap is %s', heap)
            # create the enumerator on the allocated chunks mapping
            enumerator2 = haystack.reverse.enumerators.AllocatedWordAlignedEnumerator(
                heap_walker, matcher, feedback, word_size)
            # collect the pointers
            heap_enum2 = enumerator2.search()
            ts2 = 0.0
            if len(heap_enum2) == 0:
                logging.debug('Heap %s has no pointers in allocated blocks',
                              heap)
            else:
                heap_addrs2, heap_values2 = zip(*heap_enum2)
                logging.debug(
                    'AllocatedWordAlignedEnumerator: %d pointers, timeit %0.2f',
                    len(heap_addrs2), ts2)
                all_heaps_addrs.extend(heap_addrs2)
                ##
                if False:
                    print "Pointers:"
                    for k, v in heap_enum2:
                        print hex(k), hex(v)
                    print "Allocations:"
                    for addr, size in heap_walker.get_user_allocations():
                        print hex(addr), '->', hex(addr + size), '(%x)' % size
                    print "Free chunks:"
                    for addr, size in heap_walker.get_free_chunks():
                        print hex(addr), '->', hex(addr + size), '(%x)' % size

        self._stats(all_heaps_addrs)
示例#4
0
    def test_pointer_enumerators(self):
        """
        Search pointers values in one HEAP
        :return:
        """
        # prep the workers
        dumpfilename = self._memory_handler.get_name()
        word_size = self._memory_handler.get_target_platform().get_word_size()
        feedback = searchers.NoFeedback()
        matcher = haystack.reverse.matchers.PointerEnumerator(
            self._memory_handler)
        finder = self._memory_handler.get_heap_finder()
        walkers = finder.list_heap_walkers()
        walker = walkers[0]
        heap_addr = walker.get_heap_address()
        heap = walker.get_heap_mapping()
        # create the enumerator on the whole mapping
        enumerator1 = haystack.reverse.enumerators.WordAlignedEnumerator(
            heap, matcher, feedback, word_size)
        # collect the pointers
        if False:
            ###
            ts1 = timeit.timeit(enumerator1.search, number=3)
            import cProfile, pstats, StringIO
            pr = cProfile.Profile()
            pr.enable()
            # ... do something ...
            heap_enum = enumerator1.search()
            pr.disable()
            s = StringIO.StringIO()
            sortby = 'cumulative'
            ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
            ps.print_stats()
            print s.getvalue()
            ###
        else:
            heap_enum = enumerator1.search()
            ts1 = 0.0
        heap_addrs1, heap_values1 = zip(*heap_enum)
        print 'WordAlignedEnumerator: %d pointers, timeit %0.2f' % (
            len(heap_addrs1), ts1)

        self._stats(heap_addrs1)
示例#5
0
    def test_pointer_enumerators_allocated(self):
        """
        Search pointers values in allocated chunks from one HEAP
        :return:
        """
        # prep the workers
        word_size = self._memory_handler.get_target_platform().get_word_size()
        feedback = searchers.NoFeedback()
        matcher = haystack.reverse.matchers.PointerEnumerator(
            self._memory_handler)
        finder = self._memory_handler.get_heap_finder()
        heaps = finder.get_heap_mappings()
        heap = heaps[0]
        log.debug('heap is %s', heap)
        heap_walker = finder.get_heap_walker(heap)
        # create the enumerator on the allocated chunks mapping
        enumerator2 = haystack.reverse.enumerators.AllocatedWordAlignedEnumerator(
            heap_walker, matcher, feedback, word_size)
        # collect the pointers
        if False:
            ###
            ts2 = timeit.timeit(enumerator2.search, number=3)
            import cProfile, pstats, StringIO
            pr = cProfile.Profile()
            pr.enable()
            # ... do something ...
            heap_enum2 = enumerator2.search()
            pr.disable()
            s = StringIO.StringIO()
            sortby = 'cumulative'
            ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
            ps.print_stats()
            print s.getvalue()
            ###
        else:
            heap_enum2 = enumerator2.search()
            ts2 = 0.0
        heap_addrs2, heap_values2 = zip(*heap_enum2)
        logging.debug(
            'AllocatedWordAlignedEnumerator: %d pointers, timeit %0.2f',
            len(heap_addrs2), ts2)

        self._stats(heap_addrs2)
示例#6
0
 def setUp(self):
     super(TestPointer, self).setUp()
     self.mmap, self.values = self._make_mmap_with_values(self.seq)
     self.name = 'test_dump_1'
     self.feedback = searchers.NoFeedback()