Skip to content

Commit

Permalink
WIP - Add specific exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Makman2 committed Jan 14, 2018
1 parent fcf671c commit 7a3ba29
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions memaccess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@
_PROCESS_VM_WRITE = 0x0020


class MemoryReadIncompleteError(RuntimeError):
def __init__(self, data=None):
"""
:param data:
Data read until fail occurred.
"""
super().__init__('Memory read incomplete')

self.data = data


class MemoryWriteIncompleteError(RuntimeError):
def __init__(self, bytes_written=None):
"""
:param bytes_written:
Number of bytes written until fail occurred.
"""
super().__init__('Memory write incomplete')

self.bytes_written = bytes_written


class MemoryView:
def __init__(self, pid, mode='r'):
"""
Expand Down Expand Up @@ -116,7 +138,7 @@ def read(self, size, address):

# Check if read size and desired size fit together.
if read_size.value != size:
raise RuntimeError('Memory read incomplete')
raise MemoryReadIncompleteError(buffer[:read_size.value])

return buffer.raw

Expand Down Expand Up @@ -222,7 +244,7 @@ def write(self, values, address):

# Check if written size and desired size fit together.
if written_size.value != len(values):
raise RuntimeError('Memory write incomplete')
raise MemoryWriteIncompleteError(written_size.value)

def write_int(self, value, address):
"""
Expand Down

0 comments on commit 7a3ba29

Please sign in to comment.