# 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 ctypes
import logging
import os
import pickle
    import pickle
from haystack.mappings.process import make_process_memory_handler
# Copyright (C) 2011 Loic Jaquemet loic.jaquemet+python@gmail.com
#

from __future__ import print_function



log = logging.getLogger('libdl')


class Dl_info(ctypes.Structure):
    _fields_ = [
        # Pathname of shared object that contains address
        ('dli_fname', ctypes.c_char_p),
        # Address at which shared object is loaded
        ('dli_fbase', ctypes.c_void_p),
        # Name of nearest symbol with address lower than addr
        ('dli_sname', ctypes.c_char_p),
        # Exact address of symbol named in dli_sname
        ('dli_saddr', ctypes.c_void_p)
    ]


class Dummy():
    pass


def getMappings():
    me = Dummy()
    me.pid = os.getpid()

# 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/allocators/libc/libdl.py
import ctypes
import logging
import os
import pickle
    import pickle
from haystack.mappings.process import make_process_memory_handler

# Copyright (C) 2011 Loic Jaquemet loic.jaquemet+python@gmail.com
#

from __future__ import print_function



log = logging.getLogger('libdl')


class Dl_info(ctypes.Structure):
    _fields_ = [
        # Pathname of shared object that contains address
        ('dli_fname', ctypes.c_char_p),
        # Address at which shared object is loaded
        ('dli_fbase', ctypes.c_void_p),
        # Name of nearest symbol with address lower than addr
        ('dli_sname', ctypes.c_char_p),
        # Exact address of symbol named in dli_sname
        ('dli_saddr', ctypes.c_void_p)
    ]


class Dummy():
    pass


def getMappings():
    me = Dummy()
    me.pid = os.getpid()

    return make_process_memory_handler(me)