-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsynapse.py
More file actions
383 lines (356 loc) · 12.4 KB
/
synapse.py
File metadata and controls
383 lines (356 loc) · 12.4 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
from pymem import *
import re
import time
import ctypes
import time
class Synapse:
def __init__(self):
self.programName = None
self.memory = pymem.Pymem()
self.addresses = {
"clientReplicator": 0x0,
"dataModel": 0x0,
"localPlayer": 0x0
}
self.offsets = {
"classDescriptor": 0x18,
"name": 0x48,
"parent": 0x60,
"children": 0x50,
"localPlayer": 0x240
}
self.is64Bit = False
self.pid = None
def h2d(self, hz: str, bit: int = 16) -> int:
if type(hz) == int:
return hz
return int(hz, bit)
def d2h(self, dc: int, UseAuto=None) -> str:
if type(dc) == str:
return dc
if UseAuto:
if UseAuto == 32:
dc = hex(dc & (2**32 - 1)).replace("0x", "")
else:
dc = hex(dc & (2**64 - 1)).replace("0x", "")
else:
if abs(dc) > 4294967295:
dc = hex(dc & (2**64 - 1)).replace("0x", "")
else:
dc = hex(dc & (2**32 - 1)).replace("0x", "")
if len(dc) > 8:
while len(dc) < 16:
dc = "0" + dc
if len(dc) < 8:
while len(dc) < 8:
dc = "0" + dc
return dc
def aob2re(self, aob: str):
if type(aob) == bytes:
return aob
trueB = bytearray(b"")
aob = aob.replace(" ", "")
PLATlist = []
for i in range(0, len(aob), 2):
PLATlist.append(aob[i : i + 2])
for i in PLATlist:
if "?" in i:
trueB.extend(b".")
if "?" not in i:
trueB.extend(re.escape(bytes.fromhex(i)))
return bytes(trueB)
def aobScan(self, AOB_HexArray: str, xreturn_multiple=False):
return pymem.pattern.pattern_scan_all(
self.memory.process_handle,
self.aob2re(AOB_HexArray),
return_multiple=xreturn_multiple,
)
def gethexc(self, hex: str):
hex = hex.replace(" ", "")
hxlist = []
for i in range(0, len(hex), 2):
hxlist.append(hex[i : i + 2])
return len(hxlist)
def hex2le(self, hex: str):
lehex = hex.replace(" ", "")
lelist = []
if len(lehex) > 8:
while len(lehex) < 16:
lehex = "0" + lehex
for i in range(0, len(lehex), 2):
lelist.append(lehex[i : i + 2])
lelist.reverse()
return "".join(lelist)
if len(lehex) < 9:
while len(lehex) < 8:
lehex = "0" + lehex
for i in range(0, len(lehex), 2):
lelist.append(lehex[i : i + 2])
lelist.reverse()
return "".join(lelist)
def calcjmpop(self, des, cur):
jmpopc = (self.h2d(des) - self.h2d(cur)) - 5
jmpopc = hex(jmpopc & (2**32 - 1)).replace("0x", "")
if len(jmpopc) % 2 != 0:
jmpopc = "0" + str(jmpopc)
return jmpopc
def isProgramGameActive(self):
try:
self.memory.read_char(self.memory.base_address)
return True
except:
return False
def DRP(self, Address: int, is64Bit: bool = None) -> int:
Address = Address
if type(Address) == str:
Address = self.h2d(Address)
if is64Bit:
return int.from_bytes(self.memory.read_bytes(Address, 8), "little")
if self.is64bit:
return int.from_bytes(self.memory.read_bytes(Address, 8), "little")
return int.from_bytes(self.memory.read_bytes(Address, 4), "little")
def isValidPointer(self, Address: int, is64Bit: bool = None) -> bool:
try:
if type(Address) == str:
Address = self.h2d(Address)
self.memory.read_bytes(self.memory.read_longlong(Address, is64Bit), 1)
return True
except:
return False
def getAddressFromName(self, Address: str) -> int:
if type(Address) == int:
return Address
AddressBase = 0
AddressOffset = 0
for i in self.GetModules():
if i.name in Address:
AddressBase = i.lpBaseOfDll
AddressOffset = self.h2d(Address.replace(i.name + "+", ""))
AddressNamed = AddressBase + AddressOffset
return AddressNamed
print("Unable to find Address: " + Address)
return Address
def getNameFromAddress(self, Address: int) -> str:
memoryInfo = pymem.memory.virtual_query(self.memory.process_handle, Address)
BaseAddress = memoryInfo.BaseAddress
NameOfDLL = ""
AddressOffset = 0
for i in self.GetModules():
if i.lpBaseOfDll == BaseAddress:
NameOfDLL = i.name
AddressOffset = Address - BaseAddress
break
if NameOfDLL == "":
return Address
NameOfAddress = NameOfDLL + "+" + self.d2h(AddressOffset)
return NameOfAddress
def getRawProcesses(self):
toreturn = []
for i in pymem.process.list_processes():
toreturn.append(
[
i.cntThreads,
i.cntUsage,
i.dwFlags,
i.dwSize,
i.pcPriClassBase,
i.szExeFile,
i.th32DefaultHeapID,
i.th32ModuleID,
i.th32ParentProcessID,
i.th32ProcessID,
]
)
return toreturn
def simpleGetProcesses(self):
toreturn = []
for i in self.getRawProcesses():
toreturn.append({"Name": i[5].decode(), "Threads": i[0], "ProcessId": i[9]})
return toreturn
def yieldForProgram(self, programName, AutoOpen: bool = False, Limit=15):
Count = 0
while True:
if Count > Limit:
print("Yielded too long, failed!")
return False
ProcessesList = self.simpleGetProcesses()
for i in ProcessesList:
if i["Name"] == programName:
print(
"Found "
+ programName
+ " with Process ID: "
+ str(i["ProcessId"])
)
if AutoOpen:
self.memory.open_process_from_id(i["ProcessId"])
self.programName = programName
self.handle = self.memory.process_handle
self.is64bit = not pymem.process.is_64_bit(self.handle)
self.pid = self.memory.process_id
print("Successfully attached to Process.")
return True
time.sleep(1)
Count += 1
def readPointer(
self, BaseAddress: int, Offsets_L2R: list, is64Bit: bool = None
) -> int:
x = self.memory.read_longlong(BaseAddress, is64Bit)
y = Offsets_L2R
z = x
if y == None or len(y) == 0:
return z
count = 0
for i in y:
try:
print(self.d2h(x + i))
print(self.d2h(i))
z = self.memory.read_longlong(z + i, is64Bit)
count += 1
print(self.d2h(z))
except:
print("Failed to read Offset at Index: " + str(count))
return z
return z
def getMemoryInfo(self, Address: int, Handle: int = None):
if Handle:
return pymem.memory.virtual_query(Handle, Address)
else:
return pymem.memory.virtual_query(self.handle, Address)
def memoryInfoToDictionary(self, MemoryInfo):
return {
"BaseAddress": MemoryInfo.BaseAddress,
"AllocationBase": MemoryInfo.AllocationBase,
"AllocationProtect": MemoryInfo.AllocationProtect,
"RegionSize": MemoryInfo.RegionSize,
"State": MemoryInfo.State,
"Protect": MemoryInfo.Protect,
"Type": MemoryInfo.Type,
}
def setProtection(
self,
Address: int,
ProtectionType=0x40,
Size: int = 4,
OldProtect=ctypes.c_ulong(0),
):
pymem.resources.kernel32.VirtualProtectEx(
self.memory.process_handle,
Address,
Size,
ProtectionType,
ctypes.byref(OldProtect),
)
return OldProtect
def changeProtection(
self,
Address: int,
ProtectionType=0x40,
Size: int = 4,
OldProtect=ctypes.c_ulong(0),
):
return self.setProtection(Address, ProtectionType, Size, OldProtect)
def getProtection(self, Address: int):
return self.getMemoryInfo(Address).Protect
def knowProtection(self, Protection):
if Protection == 0x10:
return "PAGE_EXECUTE"
if Protection == 0x20:
return "PAGE_EXECUTE_READ"
if Protection == 0x40:
return "PAGE_EXECUTE_READWRITE"
if Protection == 0x80:
return "PAGE_EXECUTE_WRITECOPY"
if Protection == 0x01:
return "PAGE_NOACCESS"
if Protection == 0x02:
return "PAGE_READONLY"
if Protection == 0x04:
return "PAGE_READWRITE"
if Protection == 0x08:
return "PAGE_WRITECOPY"
if Protection == 0x100:
return "PAGE_GUARD"
if Protection == 0x200:
return "PAGE_NOCACHE"
if Protection == 0x400:
return "PAGE_WRITECOMBINE"
if Protection in ["PAGE_EXECUTE", "execute", "e"]:
return 0x10
if Protection in [
"PAGE_EXECUTE_READ",
"execute read",
"read execute",
"execute_read",
"read_execute",
"er",
"re",
]:
return 0x20
if Protection in [
"PAGE_EXECUTE_READWRITE",
"execute read write",
"execute write read",
"write execute read",
"write read execute",
"read write execute",
"read execute write",
"erw",
"ewr",
"wre",
"wer",
"rew",
"rwe",
]:
return 0x40
if Protection in [
"PAGE_EXECUTE_WRITECOPY",
"execute copy write",
"execute write copy",
"write execute copy",
"write copy execute",
"copy write execute",
"copy execute write",
"ecw",
"ewc",
"wce",
"wec",
"cew",
"cwe",
]:
return 0x80
if Protection in ["PAGE_NOACCESS", "noaccess", "na", "n"]:
return 0x01
if Protection in ["PAGE_READONLY", "readonly", "ro", "r"]:
return 0x02
if Protection in ["PAGE_READWRITE", "read write", "write read", "wr", "rw"]:
return 0x04
if Protection in ["PAGE_WRITECOPY", "write copy", "copy write", "wc", "cw"]:
return 0x08
if Protection in ["PAGE_GUARD", "pg", "guard", "g"]:
return 0x100
if Protection in ["PAGE_NOCACHE", "nc", "nocache"]:
return 0x200
if Protection in ["PAGE_WRITECOMBINE", "write combine", "combine write"]:
return 0x400
return Protection
def suspend(self, pid: int = None):
kernel32 = ctypes.WinDLL("kernel32.dll")
if pid:
kernel32.DebugActiveProcess(pid)
if self.PID:
kernel32.DebugActiveProcess(self.PID)
def resume(self, pid: int = None):
kernel32 = ctypes.WinDLL("kernel32.dll")
if pid:
kernel32.DebugActiveProcessStop(pid)
if self.PID:
kernel32.DebugActiveProcessStop(self.PID)
def readRobloxString(self, ExpectedAddress: int, ExpectedLength: int = 1024) -> str:
StringCount = self.memory.read_int(ExpectedAddress + 0x10)
length = (StringCount > 0 and StringCount < 16384) and StringCount or ExpectedLength
#if StringCount > 15:
# return self.memory.read_string(self.synapse.memory.read_longlong(ExpectedAddress), StringCount)
return self.memory.read_string(ExpectedAddress, length)
def readByte(self, addr: int) -> int:
return self.h2d(self.memory.read_bytes(addr, 0x1).hex())