# 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
                st = m.read_struct(chunk_addr, win7heap.HEAP_ENTRY) # HEAP_ENTRY
                # st.UnusedBytes == 0x5    ?
                if st._0._1.UnusedBytes == 0x05:
                    prev_header_addr -= 8 * st._0._1._0.SegmentOffset
                    log.debug('UnusedBytes == 0x5, SegmentOffset == %d' % st._0._1._0.SegmentOffset)

                # FIXME, in child of 0x005c0000. LFH. What are the flags already ?
                print(hex(chunk_addr))
                self.assertTrue(st._0._1.UnusedBytes & 0x80, 'UnusedBytes said this is a BACKEND chunk , Flags | 2')
                allocs.append((chunk_addr, chunk_size))  # with header

            # FIXME - UNITTEST- you need to validate that NextOffset in
            # userblock gives same answer
            oracle = committed[0]  # TODO
            for chunk_addr, chunk_size in committed:
                m = self._memory_handler.get_mapping_for_address(chunk_addr)
                if m != heap:
                    self.assertIn(m, heap_children)
                # should be aligned
                self.assertEqual(chunk_addr & 7, 0)  # page 40
                st = m.read_struct(chunk_addr, win7heap.HEAP_ENTRY)
                # NextOffset in userblock gives same answer

            for addr, s in allocs:
                m = self._memory_handler.get_mapping_for_address(addr)
                if addr + s > m.end:
                    self.fail('OVERFLOW @%0.8x-@%0.8x, @%0.8x size:%d end:@%0.8x' % (m.start, m.end, addr, s, addr + s))
        return

    def test_get_chunks(self):

# 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

                st = m.read_struct(chunk_addr, win7heap.HEAP_ENTRY) # HEAP_ENTRY
                # st.UnusedBytes == 0x5    ?
                if st._0._1.UnusedBytes == 0x05:
                    prev_header_addr -= 8 * st._0._1._0.SegmentOffset
                    log.debug('UnusedBytes == 0x5, SegmentOffset == %d' % st._0._1._0.SegmentOffset)

                # FIXME, in child of 0x005c0000. LFH. What are the flags already ?
                print(hex(chunk_addr))
                self.assertTrue(st._0._1.UnusedBytes & 0x80, 'UnusedBytes said this is a BACKEND chunk , Flags | 2')
                allocs.append((chunk_addr, chunk_size))  # with header

            # FIXME - UNITTEST- you need to validate that NextOffset in
            # userblock gives same answer
            oracle = committed[0]  # TODO
            for chunk_addr, chunk_size in committed:
                m = self._memory_handler.get_mapping_for_address(chunk_addr)
                if m != heap:
                    self.assertIn(m, heap_children)
                # should be aligned
                self.assertEqual(chunk_addr & 7, 0)  # page 40
                st = m.read_struct(chunk_addr, win7heap.HEAP_ENTRY)
                # NextOffset in userblock gives same answer

            for addr, s in allocs:
                m = self._memory_handler.get_mapping_for_address(addr)
                if addr + s > m.end:
                    self.fail('OVERFLOW @%0.8x-@%0.8x, @%0.8x size:%d end:@%0.8x' % (m.start, m.end, addr, s, addr + s))
        return

    def test_get_chunks(self):

        finder = win7heapwalker.Win7HeapFinder(self._memory_handler)