def print_segments_analysis(self, heap, walker, ucrs): # heap is a segment segments = self.get_segment_list(heap) overhead_size = self._memory_handler.get_target_platform( ).get_target_ctypes().sizeof(self.win_heap.struct__HEAP_ENTRY) # get allocated/free stats by segment occupied_res2 = self.count_by_segment(segments, walker.get_backend_allocations(), overhead_size) free_res2 = self.count_by_segment(segments, walker.get_backend_free_chunks(), overhead_size) print("\tSegmentList: %d" % len(segments)) for segment in segments: p_segment = winheap.Segment(self._memory_handler, walker, segment) # add segments's ucr ucrsegments = self.SEGMENT_get_UCR_list(segment) ucrs.extend(ucrsegments) ucr_list = winheap.UCR_List(ucrs) p_segment.set_ucr(ucr_list) p_segment.set_resource_usage(occupied_res2, free_res2) print(p_segment.to_string('\t\t')) # if UCR, then # in XP, UCR segments are in HEAP. # ucrsegments = validator.get_UCR_segment_list(segment) ucrsegments = self.SEGMENT_get_UCR_list(segment) print("\t\t\tUCRSegments: %d {%s}" % (len(ucrsegments), ','.join( sorted([hex(s._orig_address_) for s in ucrsegments])))) for ucr_segment in ucrsegments: print("\t\t\t\tUCRSegment: 0x%0.8x-0x%0.8x size:0x%x" % (ucr_segment.Address, ucr_segment.Address + ucr_segment.Size, ucr_segment.Size))
def print_segments_analysis(self, heap, walker, ucrs): # heap is a segment segments = self.get_segment_list(heap) nb_segments = heap.Counters.TotalSegments ucr_list = winheap.UCR_List(ucrs) overhead_size = self._ctypes.sizeof(self.win_heap.struct__HEAP_ENTRY) # get allocated/free stats by segment occupied_res2 = self.count_by_segment(segments, walker.get_backend_allocations(), overhead_size) free_res2 = self.count_by_segment(segments, walker.get_backend_free_chunks(), overhead_size) print "\tSegmentList: %d/%d" % (len(segments), nb_segments) for segment in segments: p_segment = winheap.Segment(self._memory_handler, walker, segment) p_segment.set_ucr(ucr_list) p_segment.set_resource_usage(occupied_res2, free_res2) print p_segment.to_string('\t\t') # if UCR, then ucrsegments = self.get_UCR_segment_list(heap) #print "\t\t\tUCRSegmentList: %d {%s}" % (len(ucrsegments), ','.join(sorted([hex(s._orig_address_) for s in ucrsegments]))) print "\t\t\tUCRSegmentList: %d " % len(ucrsegments) for ucr in ucrsegments: _addr = self._utils.get_pointee_address(ucr.Address) end = _addr + ucr.Size print "\t\t\t\tUCRSegment 0x%0.8x-0x%0.8x size:0x%x" % ( _addr, end, ucr.Size)
def print_heap_analysis_details(self, heap): # size & space calculated from heap info # winXP # Heap's unuseduncommitted ranges # Heap.UnusedUnCommittedRanges # size & space calculated from heap info print(' Backend:') ucrs = self.HEAP_get_UCRanges_list(heap) ucr_list = winheap.UCR_List(ucrs) print('\tUnused UCR: %d' % (len(ucrs))) print(ucr_list.to_string('\t\t')) # Heap.UCRSegments ucrsegments = self.get_UCR_segment_list(heap) print("\t\t\tUCRSegments: %d {%s}" % (len(ucrsegments), ','.join( sorted([hex(s._orig_address_) for s in ucrsegments])))) for ucr_segment in ucrsegments: print("\t\t\t\tUCRSegment: 0x%0.8x-0x%0.8x size:0x%x" % (ucr_segment.Address, ucr_segment.Address + ucr_segment.Size, ucr_segment.Size)) # print "\t\t\t\t.Segment.Next", hex(ucr_segment.Next.value) # Virtual Allocations vallocs = self.HEAP_get_virtual_allocated_blocks_list(heap) print('\tVAllocations: %d' % len(vallocs)) for addr, c_size, r_size in vallocs: diff = '' if c_size == r_size else '!!' # print "vallocBlock: @0x%0.8x commit: 0x%x reserved: 0x%x" % ( print("\t\t%svalloc: 0x%0.8x-0x%0.8x size:0x%x requested:0x%x " % (diff, addr, addr + c_size, c_size, r_size)) return ucrs
def print_heap_analysis_details(self, heap): # size & space calculated from heap info print ' Backend:' ucrs = self.HEAP_get_UCRanges_list(heap) ucr_list = winheap.UCR_List(ucrs) # heap.Counters.TotalMemoryReserved.value == heap.LastValidEntry.value - heap.BaseAddress.value nb_ucr = heap.Counters.TotalUCRs print '\tUCRList: %d/%d' % (len(ucrs), nb_ucr) print ucr_list.to_string('\t\t') # Virtual Allocations vallocs = self.HEAP_get_virtual_allocated_blocks_list(heap) print '\tVAllocations: %d' % len(vallocs) for addr, c_size, r_size in vallocs: diff = '' if c_size == r_size else '!!' # print "vallocBlock: @0x%0.8x commit: 0x%x reserved: 0x%x" % ( print "\t\t%svalloc: 0x%0.8x-0x%0.8x size:0x%x requested:0x%x " % ( diff, addr, addr + c_size, c_size, r_size) return ucrs