Beispiel #1
0
def readProcessMappings(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 mappings.

    May raise a ProcessError.
    """
    maps = []
    if not HAS_PROC:
        return maps
    try:
        mapsfile = openProc(process.pid)
    except ProcError as err:
        raise ProcessError(process, "Unable to read process maps: %s" % err)

    before = None
    # save the current ctypes module.
    mappings = Mappings(None)
    # FIXME Debug, but probably useless now that ctypes is in config
    if True:
        import ctypes
        before = ctypes
    try:
        for line in mapsfile:
            line = line.rstrip()
            match = PROC_MAP_REGEX.match(line)
            if not match:
                raise ProcessError(
                    process,
                    "Unable to parse memory mapping: %r" %
                    line)
            log.debug('readProcessMappings %s' % (str(match.groups())))
            _map = ProcessMemoryMapping(
                # cfg,
                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)
    finally:
        if isinstance(mapsfile, file):
            mapsfile.close()
    # reposition the previous ctypes module.
    if True:
        ctypes = types.set_ctypes(before)
    return mappings
Beispiel #2
0
def readProcessMappings(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.
    """
    maps = []
    if not dbg.HAS_PROC:
        return maps
    try:
        mapsfile = dbg.openProc(process.pid)
    except dbg.ProcError as err:
        raise dbg.ProcessError(process,
                               "Unable to read process maps: %s" % err)

    mappings = []
    try:
        # read the mappings
        for line in mapsfile:
            line = line.rstrip()
            match = PROC_MAP_REGEX.match(line)
            if not match:
                raise dbg.ProcessError(
                    process, "Unable to parse memory mapping: %r" % line)
            log.debug('readProcessMappings %s' % (str(match.groups())))
            _map = ProcessMemoryMapping(
                # cfg,
                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)
    finally:
        if isinstance(mapsfile, file):
            mapsfile.close()
    # create the memory_handler for self
    _target_platform = target.TargetPlatform.make_target_platform_local()
    _memory_handler = MemoryHandler(mappings, _target_platform,
                                    'localhost-%d' % process.pid)
    return _memory_handler
Beispiel #3
0
def readProcessMappings(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 mappings.

  May raise a ProcessError.
  """
    maps = []
    if not HAS_PROC:
        return maps
    try:
        mapsfile = openProc(process.pid)
    except ProcError, err:
        raise ProcessError(process, "Unable to read process maps: %s" % err)
def readProcessMappings(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 mappings.

  May raise a ProcessError.
  """
  maps = []
  if not HAS_PROC:
    return maps
  try:
    mapsfile = openProc(process.pid)
  except ProcError, err:
    raise ProcessError(process, "Unable to read process maps: %s" % err)
Beispiel #5
0
def readProcessMappings(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.
    """
    maps = []
    if not dbg.HAS_PROC:
        return maps
    try:
        mapsfile = dbg.openProc(process.pid)
    except dbg.ProcError as err:
        raise dbg.ProcessError(process, "Unable to read process maps: %s" % err)

    mappings = []
    try:
        # read the mappings
        for line in mapsfile:
            line = line.rstrip()
            match = PROC_MAP_REGEX.match(line)
            if not match:
                raise dbg.ProcessError(process, "Unable to parse memory mapping: %r" % line)
            log.debug("readProcessMappings %s" % (str(match.groups())))
            _map = ProcessMemoryMapping(
                # cfg,
                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)
    finally:
        if isinstance(mapsfile, file):
            mapsfile.close()
    # create the memory_handler for self
    _target_platform = target.TargetPlatform.make_target_platform_local()
    _memory_handler = MemoryHandler(mappings, _target_platform, "localhost-%d" % process.pid)
    return _memory_handler