# Path: haystack/dbg.py
# class IProcessDebugger(object):
# class IProcess(object):
# class MyPTraceDebugger(IProcessDebugger):
# class MyWinAppDebugger(IProcessDebugger):
# class MyPTraceProcess(IProcess):
# class MyWinAppDbgProcess(IProcess):
#     def get_process(self):
#     def quit(self):
#     def get_pid(self):
#     def get_mappings_line(self):
#     def read_word(self, address):
#     def read_bytes(self, address, size):
#     def read_struct(self, address, struct):
#     def read_array(self, address, basetype, count):
#     def __init__(self, pid):
#     def get_process(self):
#     def quit(self):
#     def __init__(self, pid):
#     def get_process(self):
#     def quit(self):
#     def __init__(self, pid, ptrace_process):
#     def get_pid(self):
#     def resume(self):
#     def get_mappings_line(self):
#     def read_word(self, address):
#     def read_bytes(self, address, size):
#     def read_struct(self, address, struct):
#     def read_array(self, address, basetype, count):
#     def __init__(self, pid, winapp_process):
#     def get_pid(self):
#     def resume(self):
#     def get_mappings_line(self):
#     def read_word(self, address):
#     def read_bytes(self, address, size):
#     def read_struct(self, address, struct):
#     def read_array(self, address, basetype, count):
# def get_debugger(pid):
# def make_local_process_memory_handler(pid, use_mmap=True):
# 
# Path: haystack/mappings/process.py
# def make_process_memory_handler(process):
#     """
#     Read all memory mappings of the specified process.
# 
#     Return a list of MemoryMapping objects, or empty list if it's not possible
#     to read the memory mappings.
# 
#     May raise a ProcessError.
#     """
#     if not isinstance(process, dbg.IProcess):
#         raise TypeError('dbg.IProcess expected')
#     mapsfile = process.get_mappings_line()
# 
#     mappings = []
#     is_64 = False
#     # read the mappings
#     for line in mapsfile:
#         line = line.rstrip()
#         match = PROC_MAP_REGEX.match(line)
#         if not match:
#             raise IOError(process, "Unable to parse memory mapping: %r" % line)
#         if not is_64 and len(match.group(1)) > 8:
#             is_64 = True
#         #
#         log.debug('readProcessMappings %s' % (str(match.groups())))
#         _map = ProcessMemoryMapping(process, int(match.group(1), 16), int(match.group(2), 16),
#                                     match.group(3), int(match.group(4), 16), int(match.group(5), 16),
#                                     int(match.group(6), 16), int(match.group(7)), match.group(8))
#         mappings.append(_map)
#     # create the memory_handler for self
#     import sys
#     if 'linux' in sys.platform:
#         os_name = target.TargetPlatform.LINUX
#     else: # sys.platform.startswith('win'):
#         os_name = target.TargetPlatform.WIN7
#     _target_platform = None
#     if is_64:
#         if os_name in [target.TargetPlatform.WINXP, target.TargetPlatform.WIN7]:
#             _target_platform = target.TargetPlatform.make_target_win_64(os_name)
#         elif os_name == target.TargetPlatform.LINUX:
#             _target_platform = target.TargetPlatform.make_target_linux_64()
#     else:
#         if os_name in [target.TargetPlatform.WINXP, target.TargetPlatform.WIN7]:
#             _target_platform = target.TargetPlatform.make_target_win_32(os_name)
#         elif os_name == target.TargetPlatform.LINUX:
#             _target_platform = target.TargetPlatform.make_target_linux_32()
#     _memory_handler = MemoryHandler(mappings, _target_platform, 'localhost-%d' % process.get_pid())
#     return _memory_handler


import logging
import argparse
import shutil
import sys
import tempfile
import os
from haystack import dbg
from haystack.mappings.process import make_process_memory_handler
        self.dbg = None
        self._memory_handler = None

    def make_mappings(self):
        """Connect the debugguer to the process and gets the memory mappings
        metadata."""
        self.dbg = dbg.get_debugger(self._pid)
        self._memory_handler = make_process_memory_handler(self.dbg.get_process())
        log.debug('Memory Mappings read. Dropping ptrace on pid.')
        return

    def dump(self, dest=None):
        """Dumps the source memory mapping to the target dump place."""
        if dest is not None:
            self._dest = os.path.normpath(dest)
        if os.path.isfile(self._dest):
            raise TypeError('target is a file. You asked for a directory dump. '
                            'Please delete the file.')
        if not os.access(self._dest, os.X_OK | os.F_OK):
            os.mkdir(self._dest)
        self._dump_all_mappings(self._dest)
        self._free_process()
        return

    def _dump_all_mappings_winapp(self, destdir):
        # TODO TEST
        # winappdbg
        self.index = open(os.path.join(destdir, 'mappings'), 'w+')
        # test dump only the heap
        err = 0

# Path: haystack/dbg.py
# class IProcessDebugger(object):
# class IProcess(object):
# class MyPTraceDebugger(IProcessDebugger):
# class MyWinAppDebugger(IProcessDebugger):
# class MyPTraceProcess(IProcess):
# class MyWinAppDbgProcess(IProcess):
#     def get_process(self):
#     def quit(self):
#     def get_pid(self):
#     def get_mappings_line(self):
#     def read_word(self, address):
#     def read_bytes(self, address, size):
#     def read_struct(self, address, struct):
#     def read_array(self, address, basetype, count):
#     def __init__(self, pid):
#     def get_process(self):
#     def quit(self):
#     def __init__(self, pid):
#     def get_process(self):
#     def quit(self):
#     def __init__(self, pid, ptrace_process):
#     def get_pid(self):
#     def resume(self):
#     def get_mappings_line(self):
#     def read_word(self, address):
#     def read_bytes(self, address, size):
#     def read_struct(self, address, struct):
#     def read_array(self, address, basetype, count):
#     def __init__(self, pid, winapp_process):
#     def get_pid(self):
#     def resume(self):
#     def get_mappings_line(self):
#     def read_word(self, address):
#     def read_bytes(self, address, size):
#     def read_struct(self, address, struct):
#     def read_array(self, address, basetype, count):
# def get_debugger(pid):
# def make_local_process_memory_handler(pid, use_mmap=True):
# 
# Path: haystack/mappings/process.py
# def make_process_memory_handler(process):
#     """
#     Read all memory mappings of the specified process.
# 
#     Return a list of MemoryMapping objects, or empty list if it's not possible
#     to read the memory mappings.
# 
#     May raise a ProcessError.
#     """
#     if not isinstance(process, dbg.IProcess):
#         raise TypeError('dbg.IProcess expected')
#     mapsfile = process.get_mappings_line()
# 
#     mappings = []
#     is_64 = False
#     # read the mappings
#     for line in mapsfile:
#         line = line.rstrip()
#         match = PROC_MAP_REGEX.match(line)
#         if not match:
#             raise IOError(process, "Unable to parse memory mapping: %r" % line)
#         if not is_64 and len(match.group(1)) > 8:
#             is_64 = True
#         #
#         log.debug('readProcessMappings %s' % (str(match.groups())))
#         _map = ProcessMemoryMapping(process, int(match.group(1), 16), int(match.group(2), 16),
#                                     match.group(3), int(match.group(4), 16), int(match.group(5), 16),
#                                     int(match.group(6), 16), int(match.group(7)), match.group(8))
#         mappings.append(_map)
#     # create the memory_handler for self
#     import sys
#     if 'linux' in sys.platform:
#         os_name = target.TargetPlatform.LINUX
#     else: # sys.platform.startswith('win'):
#         os_name = target.TargetPlatform.WIN7
#     _target_platform = None
#     if is_64:
#         if os_name in [target.TargetPlatform.WINXP, target.TargetPlatform.WIN7]:
#             _target_platform = target.TargetPlatform.make_target_win_64(os_name)
#         elif os_name == target.TargetPlatform.LINUX:
#             _target_platform = target.TargetPlatform.make_target_linux_64()
#     else:
#         if os_name in [target.TargetPlatform.WINXP, target.TargetPlatform.WIN7]:
#             _target_platform = target.TargetPlatform.make_target_win_32(os_name)
#         elif os_name == target.TargetPlatform.LINUX:
#             _target_platform = target.TargetPlatform.make_target_linux_32()
#     _memory_handler = MemoryHandler(mappings, _target_platform, 'localhost-%d' % process.get_pid())
#     return _memory_handler


# Path: haystack/memory_dumper.py
import logging
import argparse
import shutil
import sys
import tempfile
import os
from haystack import dbg
from haystack.mappings.process import make_process_memory_handler

        self.dbg = None
        self._memory_handler = None

    def make_mappings(self):
        """Connect the debugguer to the process and gets the memory mappings
        metadata."""
        self.dbg = dbg.get_debugger(self._pid)
        self._memory_handler = make_process_memory_handler(self.dbg.get_process())
        log.debug('Memory Mappings read. Dropping ptrace on pid.')
        return

    def dump(self, dest=None):
        """Dumps the source memory mapping to the target dump place."""
        if dest is not None:
            self._dest = os.path.normpath(dest)
        if os.path.isfile(self._dest):
            raise TypeError('target is a file. You asked for a directory dump. '
                            'Please delete the file.')
        if not os.access(self._dest, os.X_OK | os.F_OK):
            os.mkdir(self._dest)
        self._dump_all_mappings(self._dest)
        self._free_process()
        return

    def _dump_all_mappings_winapp(self, destdir):
        # TODO TEST
        # winappdbg
        self.index = open(os.path.join(destdir, 'mappings'), 'w+')
        # test dump only the heap
        err = 0

        memory_maps = self.dbg.get_process().generate_memory_snaphost()