本文整理汇总了Python中ptrace.ctypes_tools.formatAddress函数的典型用法代码示例。如果您正苦于以下问题:Python formatAddress函数的具体用法?Python formatAddress怎么用?Python formatAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了formatAddress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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))
示例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)
示例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)
示例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)
示例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))
示例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]
示例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
示例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
示例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
示例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
示例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})
示例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)
示例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)
示例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)