Skip to content

Commit

Permalink
improve error display for POKEDATA
Browse files Browse the repository at this point in the history
  • Loading branch information
n1nj4sec committed Apr 11, 2017
1 parent 64376ed commit b84ae89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions memorpy/LinProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ def close(self):
def _open(self):
self.isProcessOpen = True
self.check_ptrace_scope()
#to raise an exception if ptrace is not allowed
self.ptrace_attach()
self.ptrace_detach()
if os.getuid()!=0:
#to raise an exception if ptrace is not allowed
self.ptrace_attach()
self.ptrace_detach()

@staticmethod
def list():
Expand Down Expand Up @@ -243,14 +244,17 @@ def write_bytes(self, address, data):
#mprotect(address, len(data)+(len(data)%word_size), PROT_WRITE|PROT_READ)
for i in range(0, len(data), word_size):
word=data[i:i+word_size]
if len(word)<word_size: #we need to let some data untouched, so let's read at given offset to complete or 8 bytes
if len(word)<word_size: #we need to let some data untouched, so let's read at given offset to complete our 8 bytes
existing_data=self.read_bytes(int(address)+i+len(word), bytes=(word_size-len(word)))
word+=existing_data
if sys.byteorder=="little":
word=word[::-1]

attempt=0
err = c_ptrace(ctypes.c_int(PTRACE_POKEDATA), c_pid, int(address)+i, int(word.encode("hex"), 16))
if err != 0:
raise OSError("%s : Error using ptrace PTRACE_POKEDATA"%err)
error=errno.errorcode.get(ctypes.get_errno(), 'UNKNOWN')
raise OSError("Error using PTRACE_POKEDATA: %s"%error)

self.ptrace_detach()
return True
Expand Down
2 changes: 1 addition & 1 deletion memorpy/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: UTF8 -*-

version=(1,4)
version=(1,5)
version_string="%s.%s"%version

0 comments on commit b84ae89

Please sign in to comment.