コード例 #1
0
ファイル: func.py プロジェクト: ksparakis/python-ptrace
def _poke(command, pid, address, word):
    if address % CPU_WORD_SIZE:
        raise PtraceError(
            "ptrace can't write a word to an unaligned address (%s)!" %
            formatAddress(address),
            pid=pid)
    ptrace(command, pid, address, word)
コード例 #2
0
ファイル: func.py プロジェクト: ksparakis/python-ptrace
def _peek(command, pid, address):
    if address % CPU_WORD_SIZE:
        raise PtraceError(
            "ptrace can't read a word from an unaligned address (%s)!" %
            formatAddress(address),
            pid=pid)
    return ptrace(command, pid, address, check_errno=True)
コード例 #3
0
 def disassembleOne(code, address=0x100):
     """
     Disassemble the first instruction of the byte string, where
     address is the address of the instruction.
     """
     for instr in disassemble(code, address):
         return instr
     raise PtraceError("Unable to disassemble %r" % code)
コード例 #4
0
ファイル: func.py プロジェクト: ksparakis/python-ptrace
def ptrace(command, pid=0, arg1=0, arg2=0, check_errno=False):
    if HAS_CPTRACE:
        try:
            result = _ptrace(command, pid, arg1, arg2, check_errno)
        except ValueError as errobj:
            message = str(errobj)
            errno = get_errno()
            raise PtraceError(message, errno=errno, pid=pid)
    else:
        result = _ptrace(command, pid, arg1, arg2)
        result_signed = c_long(result).value
        if result_signed == -1:
            errno = get_errno()
            # peek operations may returns -1 with errno=0:
            # it's not an error. For other operations, -1
            # is always an error
            if not (check_errno) or errno:
                message = "ptrace(cmd=%s, pid=%s, %r, %r) error #%s: %s" % (
                    command, pid, arg1, arg2, errno, strerror(errno))
                raise PtraceError(message, errno=errno, pid=pid)
    return result
コード例 #5
0
ファイル: func.py プロジェクト: thuylt83/darkc0de-old-stuff
def ptrace(command, pid=0, arg1=0, arg2=0, check_errno=False):
    result = _ptrace(command, pid, arg1, arg2)
    if c_long(result) == -1:
        errno = get_errno()
        # peek operations may returns -1 with errno=0:
        # it's not an error. For other operations, -1
        # is always an error
        if not (check_errno) or errno:
            message = "ptrace(cmd=%s, pid=%s, %r, %r) error #%s: %s" % (
                command, pid, arg1, arg2, errno, strerror(errno))
            raise PtraceError(message, errno=errno, pid=pid)
    return result
コード例 #6
0
    def _waitpid(self, wanted_pid):
        if wanted_pid:
            if wanted_pid not in self.dict:
                raise PtraceError("Unknown PID: %r" % wanted_pid, pid=wanted_pid)

            debug("Wait process %s" % wanted_pid)
            try:
                pid, status = waitpid(wanted_pid, 0)
            except OSError, err:
                if err.errno == ECHILD:
                    process = self[wanted_pid]
                    raise process.processTerminated()
                else:
                    raise err
コード例 #7
0
 def disassembleOne(code, address=0x100):
     for instr in disassemble(code, address):
         return instr
     raise PtraceError("Unable to disassemble %r" % code)
コード例 #8
0
            debug("Wait process %s" % wanted_pid)
            try:
                pid, status = waitpid(wanted_pid, 0)
            except OSError, err:
                if err.errno == ECHILD:
                    process = self[wanted_pid]
                    raise process.processTerminated()
                else:
                    raise err
        else:
            debug("Wait any process")
            pid, status = waitpid(-1, 0)

        if wanted_pid and pid != wanted_pid:
            raise PtraceError("Unwanted PID: %r (instead of %s)"
                % (pid, wanted_pid), pid=pid)
        return pid, status

    def _wait(self, wanted_pid):
        process = None
        while not process:
            pid, status = self._waitpid(wanted_pid)
            try:
                process = self.dict[pid]
            except KeyError:
                info("waitpid() warning: Unknown PID %r" % pid)
        return process.processStatus(status)

    def waitProcessEvent(self, pid=None):
        return self._wait(pid)