# Path: haystack/allocators/win32/win7heapwalker.py
# class Win7HeapWalker(winheapwalker.WinHeapWalker):
# class Win7HeapFinder(winheapwalker.WinHeapFinder):
#     def _create_validator(self):
#     def _validator_type(self):
#     def _walker_type(self):
#     def _make_dual_arch_ctypes(self):
#     def _get_heap_possible_kernel_pointer_from_heap(self, target_platform, heap):
# 
# Path: haystack/mappings/folder.py
# MMAP_HACK_ACTIVE = True
# MAX_MAPPING_SIZE_FOR_MMAP = 1024 * 1024 * 20
# class LazyLoadingException(Exception):
# class MemoryDumpLoader(interfaces.IMemoryLoader):
# class ProcessMemoryDumpLoader(MemoryDumpLoader):
# class LazyProcessMemoryDumpLoader(ProcessMemoryDumpLoader):
# class VeryLazyProcessMemoryDumpLoader(LazyProcessMemoryDumpLoader):
# class FolderLoader(interfaces.IMemoryLoader):
#     def __init__(self, filename):
#     def __init__(self, dumpname, bits=None, os_name=None):
#     def make_memory_handler(self):
#     def _is_valid(self):
#     def _load_mappings(self):
#     def _is_valid(self):
#     def _test_dir(self):
#     def _protected_open_file(self, mmap_fname, mmap_pathname):
#     def _load_mappings(self):
#     def _load_metadata(self):
#     def _load_memory_mappings(self):
#     def __init__(self, dumpname, maps_to_load=None, bits=None, os_name=None):
#     def _protected_open_file(self, mmap_fname, mmap_pathname):
#     def _load_memory_mappings(self):
# def load(dumpname, bits=None, os_name=None):
#     def __init__(self, opts):
#     def make_memory_handler(self):


import logging
import sys
import unittest
from haystack.allocators.win32 import win7heapwalker
from haystack.mappings import folder
from test.testfiles import putty_1_win7

        # FIXME: the sum calculation is per segment, not per mapping.

        self.assertNotEqual(self._memory_handler, None)
        # test the heaps
        walkers = self._heap_finder.list_heap_walkers()
        heap_sums = dict([(walker.get_heap_mapping(), list()) for walker in walkers])
        child_heaps = dict()
        for heap_walker in walkers:
            heap_addr = heap_walker.get_heap_address()
            heap = heap_walker.get_heap_mapping()
            log.debug(
                '==== walking heap num: %0.2d @ %0.8x',
                heap_walker.get_heap().ProcessHeapsListIndex, heap_addr)
            walker = self._heap_finder.get_heap_walker(heap)
            for x, s in walker._get_freelists():
                m = self._memory_handler.get_mapping_for_address(x)
                # Found new mmap outside of heaps mmaps
                if m not in heap_sums:
                    heap_sums[m] = []
                heap_sums[m].append((x, s))
            #self.assertEqual( free_size, walker.HEAP().TotalFreeSize)
            # save mmap hierarchy
            child_heaps[heap] = walker.list_used_mappings()

        # calcul cumulates
        for heap, children in child_heaps.items():
            # for each heap, look at all children
            freeblocks = map(lambda x: x[0], heap_sums[heap])
            free_size = sum(map(lambda x: x[1], heap_sums[heap]))

# Path: haystack/allocators/win32/win7heapwalker.py
# class Win7HeapWalker(winheapwalker.WinHeapWalker):
# class Win7HeapFinder(winheapwalker.WinHeapFinder):
#     def _create_validator(self):
#     def _validator_type(self):
#     def _walker_type(self):
#     def _make_dual_arch_ctypes(self):
#     def _get_heap_possible_kernel_pointer_from_heap(self, target_platform, heap):
# 
# Path: haystack/mappings/folder.py
# MMAP_HACK_ACTIVE = True
# MAX_MAPPING_SIZE_FOR_MMAP = 1024 * 1024 * 20
# class LazyLoadingException(Exception):
# class MemoryDumpLoader(interfaces.IMemoryLoader):
# class ProcessMemoryDumpLoader(MemoryDumpLoader):
# class LazyProcessMemoryDumpLoader(ProcessMemoryDumpLoader):
# class VeryLazyProcessMemoryDumpLoader(LazyProcessMemoryDumpLoader):
# class FolderLoader(interfaces.IMemoryLoader):
#     def __init__(self, filename):
#     def __init__(self, dumpname, bits=None, os_name=None):
#     def make_memory_handler(self):
#     def _is_valid(self):
#     def _load_mappings(self):
#     def _is_valid(self):
#     def _test_dir(self):
#     def _protected_open_file(self, mmap_fname, mmap_pathname):
#     def _load_mappings(self):
#     def _load_metadata(self):
#     def _load_memory_mappings(self):
#     def __init__(self, dumpname, maps_to_load=None, bits=None, os_name=None):
#     def _protected_open_file(self, mmap_fname, mmap_pathname):
#     def _load_memory_mappings(self):
# def load(dumpname, bits=None, os_name=None):
#     def __init__(self, opts):
#     def make_memory_handler(self):


# Path: test/haystack/allocators/win32/test_win7walker.py
import logging
import sys
import unittest
from haystack.allocators.win32 import win7heapwalker
from haystack.mappings import folder
from test.testfiles import putty_1_win7


        # FIXME: the sum calculation is per segment, not per mapping.

        self.assertNotEqual(self._memory_handler, None)
        # test the heaps
        walkers = self._heap_finder.list_heap_walkers()
        heap_sums = dict([(walker.get_heap_mapping(), list()) for walker in walkers])
        child_heaps = dict()
        for heap_walker in walkers:
            heap_addr = heap_walker.get_heap_address()
            heap = heap_walker.get_heap_mapping()
            log.debug(
                '==== walking heap num: %0.2d @ %0.8x',
                heap_walker.get_heap().ProcessHeapsListIndex, heap_addr)
            walker = self._heap_finder.get_heap_walker(heap)
            for x, s in walker._get_freelists():
                m = self._memory_handler.get_mapping_for_address(x)
                # Found new mmap outside of heaps mmaps
                if m not in heap_sums:
                    heap_sums[m] = []
                heap_sums[m].append((x, s))
            #self.assertEqual( free_size, walker.HEAP().TotalFreeSize)
            # save mmap hierarchy
            child_heaps[heap] = walker.list_used_mappings()

        # calcul cumulates
        for heap, children in child_heaps.items():
            # for each heap, look at all children
            freeblocks = map(lambda x: x[0], heap_sums[heap])
            free_size = sum(map(lambda x: x[1], heap_sums[heap]))

            finder = win7heapwalker.Win7HeapFinder(self._memory_handler)