-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.py
100 lines (78 loc) · 2.54 KB
/
memory.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import json
class Meta:
def __init__(self, name, addr, size=4, typ="i"):
self.name = name
self.addr = addr
self.size = size
self.typ = typ
self.value = None
def __repr__(self):
return f"{self.name}: {self.value}"
PROCESS_WM_READ = 0x0010
from time import sleep
from pymem import Pymem
import traceback
class MemoryReader:
def __init__(self, exename, tables):
self.exename = exename
self.tables = tables
for name, table in self.tables.items():
self.tables[name] = self.loadTable(table)
self.attach()
def loadTable(self, table):
config = table.splitlines()
headerdata = config[0].split()
header = []
for column in headerdata:
splitcolumn = column.split(":")
name = splitcolumn[0]
size = splitcolumn[1]
if len(splitcolumn) >= 3:
typ = splitcolumn[2]
else:
typ = "i"
meta = [name, int(size), typ]
header.append(meta)
data = []
for row in config[1:]:
data.append([])
for column, value in enumerate(row.split()):
try:
addr = int(value, 16)
except ValueError:
addr = None
data[-1].append(Meta(header[column][0], addr, header[column][1], header[column][2]))
return data
def attach(self):
print("Searching for process...")
self.pm = Pymem(self.exename)
#print(dir(pm))
print("Attached.")
def run(self):
while True:
try:
self.update()
print(self.tables)
sleep(1)
except IndexError as e:
print(e)
sleep(0.1)
except Exception as e:
print(e)
traceback.print_exc()
def runOnce(self):
self.update()
return self.tables
def update(self):
for name, table in self.tables.items():
for row in table:
for column in row:
if column.addr is None:
continue
if column.typ == "i":
value = self.pm.read_int(column.addr)
elif column.typ == "s":
value = self.pm.read_string(column.addr)
else:
raise ValueError("Unknown column type:", column.typ)
column.value = value