forked from teamnsrg/erays
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memorymodel.py
33 lines (25 loc) · 1.03 KB
/
memorymodel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from ceptions import MemoryException
ARRAY_SIZE_MAGIC = 1024 # enough for most cases
ZERO_WORD = "0000000000000000000000000000000000000000000000000000000000000000"
class MemoryModel:
def __init__(self, chunk):
# print(chunk)
self.__array = bytearray(chunk + ZERO_WORD * ARRAY_SIZE_MAGIC)
def load_as_str(self, offset, size):
return str(self.load(offset, size))
def load_as_int(self, offset):
return int(str(self.load(offset)), 16)
def load(self, offset, size=32):
begin, end = offset * 2, (offset + size) * 2
if end > len(self.__array):
# print(end, len(self.__array))
raise MemoryException("out of bound access")
return self.__array[begin:end]
def store(self, offset, size, value):
begin, end = offset * 2, (offset + size) * 2
self.__array[begin:end] = value
def debug_memory(self):
arr = str(self.__array)
arr = [arr[i:i + 64] for i in range(0, len(arr), 64)]
for i in arr:
print(i)