# Path: haystack/allocators/win32/winxpheapwalker.py
# class WinXPHeapWalker(winheapwalker.WinHeapWalker):
# class WinXPHeapFinder(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/outputters/python.py
# class PythonOutputter(Outputter):
# class pyObj(object):
# class _pyObjBuilder:
#     def parse(self, obj, prefix='', depth=50):
#     def _attrToPyObject(self, attr, field, attrtype):
# def json_encode_pyobj(obj):
#     def toString(self, prefix='', maxDepth=10):
#     def _attrToString(self, attr, attrname, typ, prefix, maxDepth):
#     def __len__(self):
#     def findCtypes(self, cache=None):
#     def _attrFindCtypes(self, attr, attrname, typ, cache):
#     def __iter__(self):
#     def __getstate__(self):
#     def __reduce__(self):
#     def __call__(self, modulename, classname):
# def findCtypesInPyObj(memory_handler, obj):
# 
# Path: haystack/outputters/text.py
# class RecursiveTextOutputter(Outputter):
#     def parse(self, obj, prefix='', depth=10, addr_was=None):
#     def _attrToString(self, attr, field, attrtype, prefix, addr, depth=-1):
# 
# 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 unittest
from builtins import map
from haystack.allocators.win32 import winxpheapwalker
from haystack.outputters import python
from haystack.outputters import text
from haystack.mappings import folder
from test.testfiles import zeus_1668_vmtoolsd_exe
            #log.debug(
            #    'heap: 0x%0.8x free: %0.5x    expected: %0.5x    mmap len:%0.5x',
            #    heap.start, total, cheap.TotalFreeSize, maxlen)

        return

    def test_sorted_heaps(self):
        """
        check if memory_mapping gives heaps sorted by index.
        FIXME: is HEAP.ProcessHeapsListIndex supposed to be consecutive ?
        """
        # self.skipTest('known_ok')
        finder = winxpheapwalker.WinXPHeapFinder(self._memory_handler)
        walkers = finder.list_heap_walkers()
        #print [hex(x.start) for x in heaps]
        #print [hex(x) for x,y in zeus_1668_vmtoolsd_exe.known_heaps]
        self.assertEqual(len(walkers), len(zeus_1668_vmtoolsd_exe.known_heaps))
        last = 0
        for i, heap_walker in enumerate(walkers):
            heap_addr = heap_walker.get_heap_address()
            # this = heap_walker.get_heap().ProcessHeapsListIndex
            # log.debug('%d @%0.8x', this, heap_addr)
            this = heap_addr
            # self.assertEqual(finder._read_heap(m).ProcessHeapsListIndex, i + 1,
            self.assertGreaterEqual(this, last,'heaps are sorted by base address')
            last = this
        return

    @unittest.expectedFailure
    def test_get_frontendheap(self):

# Path: haystack/allocators/win32/winxpheapwalker.py
# class WinXPHeapWalker(winheapwalker.WinHeapWalker):
# class WinXPHeapFinder(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/outputters/python.py
# class PythonOutputter(Outputter):
# class pyObj(object):
# class _pyObjBuilder:
#     def parse(self, obj, prefix='', depth=50):
#     def _attrToPyObject(self, attr, field, attrtype):
# def json_encode_pyobj(obj):
#     def toString(self, prefix='', maxDepth=10):
#     def _attrToString(self, attr, attrname, typ, prefix, maxDepth):
#     def __len__(self):
#     def findCtypes(self, cache=None):
#     def _attrFindCtypes(self, attr, attrname, typ, cache):
#     def __iter__(self):
#     def __getstate__(self):
#     def __reduce__(self):
#     def __call__(self, modulename, classname):
# def findCtypesInPyObj(memory_handler, obj):
# 
# Path: haystack/outputters/text.py
# class RecursiveTextOutputter(Outputter):
#     def parse(self, obj, prefix='', depth=10, addr_was=None):
#     def _attrToString(self, attr, field, attrtype, prefix, addr, depth=-1):
# 
# 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_winxpwalker.py
import logging
import unittest
from builtins import map
from haystack.allocators.win32 import winxpheapwalker
from haystack.outputters import python
from haystack.outputters import text
from haystack.mappings import folder
from test.testfiles import zeus_1668_vmtoolsd_exe

            #log.debug(
            #    'heap: 0x%0.8x free: %0.5x    expected: %0.5x    mmap len:%0.5x',
            #    heap.start, total, cheap.TotalFreeSize, maxlen)

        return

    def test_sorted_heaps(self):
        """
        check if memory_mapping gives heaps sorted by index.
        FIXME: is HEAP.ProcessHeapsListIndex supposed to be consecutive ?
        """
        # self.skipTest('known_ok')
        finder = winxpheapwalker.WinXPHeapFinder(self._memory_handler)
        walkers = finder.list_heap_walkers()
        #print [hex(x.start) for x in heaps]
        #print [hex(x) for x,y in zeus_1668_vmtoolsd_exe.known_heaps]
        self.assertEqual(len(walkers), len(zeus_1668_vmtoolsd_exe.known_heaps))
        last = 0
        for i, heap_walker in enumerate(walkers):
            heap_addr = heap_walker.get_heap_address()
            # this = heap_walker.get_heap().ProcessHeapsListIndex
            # log.debug('%d @%0.8x', this, heap_addr)
            this = heap_addr
            # self.assertEqual(finder._read_heap(m).ProcessHeapsListIndex, i + 1,
            self.assertGreaterEqual(this, last,'heaps are sorted by base address')
            last = this
        return

    @unittest.expectedFailure
    def test_get_frontendheap(self):

        finder = winxpheapwalker.WinXPHeapFinder(self._memory_handler)