• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python ctypes_tools.formatAddress函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中ptrace.ctypes_tools.formatAddress函数的典型用法代码示例。如果您正苦于以下问题:Python formatAddress函数的具体用法?Python formatAddress怎么用?Python formatAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了formatAddress函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _dumpCode

    def _dumpCode(self, address, ip, manage_bp):
        if not HAS_DISASSEMBLER:
            code = self.readCode(address)
            text = " ".join( "%02x" % ord(byte) for byte in code )
            error("CODE: %s" % text)
            return

        if manage_bp:
            for line in xrange(10):
                bp = False
                if address in self.breakpoints:
                    bytes = self.breakpoints[address].old_bytes
                    instr = disassembleOne(bytes, address)
                    bp = True
                else:
                    instr = self.disassembleOne(address)
                text = "ASM %s: %s (%s)" % (formatAddress(instr.address), instr.text, instr.hexa)
                if instr.address == ip:
                    text += " <=="
                if bp:
                    text += "     * BREAKPOINT *"
                error(text)
                address = address+instr.size
        else:
            for instr in self.disassemble(address):
                text = "ASM %s: %s (%s)" % (formatAddress(instr.address), instr.text, instr.hexa)
                if instr.address == ip:
                    text += " <=="
                error(text)
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:29,代码来源:process.py


示例2: xray

 def xray(self):
     for process, procmap, address, term in self._xray():
         pointers = " ".join(formatAddress(ptr_addr)
             for ptr_addr in getPointers(process, address))
         print("term[%s] pid[%i] %s %s pointers: %s" % (
             repr(term), process.pid, procmap,
             formatAddress(address),
             pointers))
开发者ID:tjmaas,项目名称:cs373-idb,代码行数:8,代码来源:gdb.py


示例3: dumpStack

 def dumpStack(self):
     stack = self.findStack()
     if stack:
         error("STACK: %s..%s" % (
             formatAddress(stack[0]),
             formatAddress(stack[1])))
     try:
         self._dumpStack()
     except PtraceError, err:
         error("Unable to read stack: %s" % err)
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:10,代码来源:process.py


示例4: display

 def display(self):
     if self.address is not None:
         if isinstance(self.address, (list, tuple)):
             address = " or ".join( formatAddress(addr) for addr in self.address )
         else:
             address = formatAddress(self.address)
         message = self.prefix_addr % address
     else:
         message = self.prefix
     if self.text:
         message = "%s: %s" % (message, self.text)
     error(message)
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:12,代码来源:ptrace_signal.py


示例5: writeWord

 def writeWord(self, address, word):
     """
     Address have to be aligned!
     """
     debug("Write word %s at %s" % (
         formatWordHex(word), formatAddress(address)))
     ptrace_poketext(self.pid, address, word)
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:7,代码来源:process.py


示例6: readArray

 def readArray(self, address, basetype, count):
     debug("Read array %sx%s at %s" % (
         basetype.__name__, count, formatAddress(address)))
     bytes = self.readBytes(address, sizeof(basetype)*count)
     if not CPU_64BITS:
         bytes = c_char_p(bytes)
     return cast(bytes, POINTER(basetype))
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:7,代码来源:process.py


示例7: readStruct

 def readStruct(self, address, struct):
     debug("Read structure %s at %s" % (
         struct.__name__, formatAddress(address)))
     bytes = self.readBytes(address, sizeof(struct))
     if not CPU_64BITS:
         bytes = c_char_p(bytes)
     return cast(bytes, POINTER(struct))[0]
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:7,代码来源:process.py


示例8: exit

    def exit(self):
        if self.name in PREFORMAT_ARGUMENTS:
            preformat = set(PREFORMAT_ARGUMENTS[self.name])
        else:
            preformat = set()

        # Data pointed by arguments may have changed during the syscall
        # eg. uname() syscall
        for index, argument in enumerate(self.arguments):
            if index in preformat:
                # Don't lose preformatted arguments
                continue
            if argument.type and not argument.type.endswith("*"):
                continue
            argument.text = None

        self.result = self.process.getreg(RETURN_VALUE_REGISTER)

        if self.restype.endswith("*"):
            text = formatAddress(self.result)
        else:
            uresult = self.result
            self.result = ulong2long(self.result)
            if self.result < 0:
                text = "%s %s (%s)" % (
                    self.result, errorcode[-self.result], strerror(-self.result))
            elif not(0 <= self.result <= 9):
                text = "%s (%s)" % (self.result, formatWordHex(uresult))
            else:
                text = str(self.result)
        self.result_text = text
        return text
开发者ID:ksparakis,项目名称:python-ptrace,代码行数:32,代码来源:ptrace_syscall.py


示例9: _readBytes

    def _readBytes(self, address, size):
        debug("Read %s bytes at %s" % (size, formatAddress(address)))

        offset = address % CPU_WORD_SIZE
        if offset:
            # Read word
            address -= offset
            word = self.readWord(address)
            bytes = word2bytes(word)

            # Read some bytes from the word
            subsize = min(CPU_WORD_SIZE - offset, size)
            data = bytes[offset:offset+subsize]   # <-- FIXME: Big endian!

            # Move cursor
            size -= subsize
            address += CPU_WORD_SIZE
        else:
            data = ''

        while size:
            # Read word
            word = self.readWord(address)
            bytes = word2bytes(word)

            # Read bytes from the word
            if size < CPU_WORD_SIZE:
                data += bytes[:size]   # <-- FIXME: Big endian!
                break
            data += bytes

            # Move cursor
            size -= CPU_WORD_SIZE
            address += CPU_WORD_SIZE
        return data
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:35,代码来源:process.py


示例10: readBytes

        def readBytes(self, address, size):
            if not self.read_mem_file:
                filename = '/proc/%u/mem' % self.pid
                try:
                    self.read_mem_file = open(filename, 'rb', 0)
                except IOError as err:
                    message = "Unable to open %s: fallback to ptrace implementation" % filename
                    if err.errno != EACCES:
                        error(message)
                    else:
                        info(message)
                    self.readBytes = self._readBytes
                    return self.readBytes(address, size)

            try:
                mem = self.read_mem_file
                mem.seek(address)
                data = mem.read(size)
            except (IOError, ValueError) as err:
                raise ProcessError(self, "readBytes(%s, %s) error: %s" % (
                    formatAddress(address), size, err))
            if len(data) == 0 and size:
                # Issue #10: If the process was not created by the debugger
                # (ex: fork), the kernel may deny reading private mappings of
                # /proc/pid/mem to the debugger, depending on the kernel
                # version and kernel config (ex: SELinux enabled or not).
                #
                # Fallback to PTRACE_PEEKTEXT. It is slower but a debugger
                # tracing the process is always allowed to use it.
                self.readBytes = self._readBytes
                return self.readBytes(address, size)
            return data
开发者ID:pavlix,项目名称:python-ptrace,代码行数:32,代码来源:process.py


示例11: step

    def step(self, enter_call, address=None):
        if address is None:
            self.displayInstr("Execute")
        if (not HAS_PTRACE_SINGLESTEP) or (not enter_call):
            if address is None:
                address = self.process.getInstrPointer()
                size = self.readInstrSize(address, default_size=None)
                if not size:
                    return "Unable to read instruction size at %s" \
                        % formatAddress(address)
                address += size
            size = self.readInstrSize(address)

            # Set a breakpoint
            breakpoint = self.process.createBreakpoint(address, size)

            # Continue the process
            self.process.cont()
        else:
            # Use ptrace single step command
            self.process.singleStep()
            breakpoint = None

        # Execute processus until next TRAP
        try:
            self.process.waitSignals(SIGTRAP)
            if breakpoint:
                breakpoint.desinstall(set_ip=True)
        except:
            if breakpoint:
                breakpoint.desinstall()
            raise
        return None
开发者ID:tjmaas,项目名称:cs373-idb,代码行数:33,代码来源:gdb.py


示例12: __init__

 def __init__(self, address, process=None):
     SignalInfo.__init__(self, "instr_error",
                         "UNABLE TO EXECUTE CODE AT %s (SEGMENTATION FAULT)" % formatAddress(
                             address),
                         address=address,
                         process=process,
                         registers={'<instr pointer>': address})
开发者ID:pavlix,项目名称:python-ptrace,代码行数:7,代码来源:signal_reason.py


示例13: createText

    def createText(self):
        value = self.value
        argtype = self.type
        name = self.name
        if not argtype or not name:
            return formatWordHex(self.value)

        syscall = self.function.name

        # Special cases
        try:
            return SYSCALL_ARG_DICT[syscall][name][value]
        except KeyError:
            pass
        try:
            callback = ARGUMENT_CALLBACK[syscall][name]
        except KeyError:
            callback = None
        if callback:
            return callback(value)
        if syscall == "execve":
            if name in ("argv", "envp"):
                return self.readCStringArray(value)
        if syscall == "socketcall":
            if name == "call":
                try:
                    return SOCKETCALL[value][0]
                except KeyError:
                    return str(value)
            if name == "args":
                func_call = FunctionCall("socketcall", self.options)
                setupSocketCall(func_call, self.function.process, self.function[0], self.value)
                text = "<%s>" % func_call.format()
                return self.formatPointer(text, self.value)
        if syscall == "write" and name == "buf":
            fd = self.function[0].value
            if fd < 3:
                length = self.function[2].value
                return self.readString(value, length)
        if name == "signum":
            return signalName(value)
        if name in FILENAME_ARGUMENTS:
            return self.readCString(value)

        # Remove "const " prefix
        if argtype.startswith("const "):
            argtype = argtype[6:]

        # Format depending on the type
        if argtype.endswith("*"):
            try:
                text = self.formatValuePointer(argtype[:-1])
                if text:
                    return text
            except PTRACE_ERRORS, err:
                writeError(getLogger(), err, "Format argument value error")
                value = None
            return formatAddress(self.value)
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:58,代码来源:syscall_argument.py


示例14: _dumpCode

    def _dumpCode(self, start, stop, ip, manage_bp, log):
        if stop is not None:
            stop = max(start, stop)
            stop = min(stop, start + MAX_CODE_SIZE - 1)

        if not HAS_DISASSEMBLER:
            if stop is not None:
                size = stop - start + 1
            else:
                size = MIN_CODE_SIZE
            code = self.readBytes(start, size)
            if RUNNING_PYTHON3:
                text = " ".join("%02x" % byte for byte in code)
            else:
                text = " ".join("%02x" % ord(byte) for byte in code)
            log("CODE: %s" % text)
            return

        if manage_bp:
            address = start
            for line in range(10):
                bp = False
                if address in self.breakpoints:
                    bytes = self.breakpoints[address].old_bytes
                    instr = disassembleOne(bytes, address)
                    bp = True
                else:
                    instr = self.disassembleOne(address)
                text = "%s| %s (%s)" % (formatAddress(
                    instr.address), instr.text, instr.hexa)
                if instr.address == ip:
                    text += " <=="
                if bp:
                    text += "     * BREAKPOINT *"
                log(text)
                address = address + instr.size
                if stop is not None and stop <= address:
                    break
        else:
            for instr in self.disassemble(start, stop):
                text = "%s| %s (%s)" % (formatAddress(
                    instr.address), instr.text, instr.hexa)
                if instr.address == ip:
                    text += " <=="
                log(text)
开发者ID:pavlix,项目名称:python-ptrace,代码行数:45,代码来源:process.py


示例15: displayInstr

 def displayInstr(self, prefix):
     try:
         if HAS_DISASSEMBLER:
             instr = self.process.disassembleOne()
             error("%s %s: %s" % (
                 prefix, formatAddress(instr.address), instr.text))
         else:
             self.process.dumpCode()
     except PtraceError as err:
         error("Unable to read current instruction: %s" % err)
开发者ID:tjmaas,项目名称:cs373-idb,代码行数:10,代码来源:gdb.py


示例16: readBytes

 def readBytes(self, address, size):
     debug("Read %s bytes at %s" % (size, formatAddress(address)))
     buffer = create_string_buffer(size)
     io_desc = ptrace_io_desc(
         piod_op=PIOD_READ_D,
         piod_offs=address,
         piod_addr=addressof(buffer),
         piod_len=size)
     ptrace_io(self.pid, io_desc)
     return buffer.raw
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:10,代码来源:process.py


示例17: readInstrSize

 def readInstrSize(self, address, default_size=None):
     if not HAS_DISASSEMBLER:
         return default_size
     try:
         # Get address and size of instruction at specified address
         instr = self.process.disassembleOne(address)
         return instr.size
     except PtraceError as err:
         warning("Warning: Unable to read instruction size at %s: %s" % (
             formatAddress(address), err))
         return default_size
开发者ID:tjmaas,项目名称:cs373-idb,代码行数:11,代码来源:gdb.py


示例18: __init__

 def __init__(self, address=None, size=None, instr=None, registers=None, process=None):
     """
     address is an integer or a list of integer
     """
     if address is not None:
         if isinstance(address, (list, tuple)):
             arguments = " or ".join(formatAddress(addr) for addr in address)
         else:
             arguments = formatAddress(address)
         message = self.PREFIX_ADDR % arguments
     else:
         message = self.PREFIX
     if size:
         message += " (size=%s bytes)" % size
     name = self.NAME
     if address is not None:
         name += "-" + formatAddress(address).lower()
     SignalInfo.__init__(
         self, name, message, address=address, size=size, instr=instr, process=process, registers=registers
     )
开发者ID:GarrusRiflle,项目名称:fuck_github,代码行数:20,代码来源:signal_reason.py


示例19: writeBytes

 def writeBytes(self, address, bytes):
     size = len(bytes)
     debug("Write %s bytes at %s" % (
         size, formatAddress(address)))
     bytes = create_string_buffer(bytes)
     io_desc = ptrace_io_desc(
         piod_op=PIOD_WRITE_D,
         piod_offs=address,
         piod_addr=addressof(bytes),
         piod_len=size)
     ptrace_io(self.pid, io_desc)
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:11,代码来源:process.py


示例20: breakpoint

    def breakpoint(self, address):

        # Create breakpoint
        size = self.readInstrSize(address)
        try:
            bp = self.process.createBreakpoint(address, size)
        except PtraceError as err:
            return "Unable to set breakpoint at %s: %s" % (
                formatAddress(address), err)
        #error("New breakpoint: %s" % bp)
        return None
开发者ID:CIFASIS,项目名称:VDiscover,代码行数:11,代码来源:Process.py



注:本文中的ptrace.ctypes_tools.formatAddress函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python configuration.parse_arguments函数代码示例发布时间:2022-05-25
下一篇:
Python repl.embed函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap