def get_multi_level_offset(game: pymem.Pymem, offset_list: List[int]) -> int: """Get the address result of [base+A]+B]+...]+C, [X] means the value at address X. :param game: a pymem.Pymem object, to load memory and get base address :param offset_list: a list contains a sequence of hex offset values :return: the address result """ if not isinstance(offset_list, list): raise TypeError("offset list must be 'list'") if len(offset_list) == 0: raise ValueError("offset list must not be empty") base_address = game.process_base.lpBaseOfDll address = base_address for offset in offset_list[:-1]: address = game.read_uint(address + offset) address += offset_list[-1] return address
class Darknet(Thread): def __init__(self, path, executable, args): Thread.__init__(self) self.path = path self.executable = executable self.args = args self.addresses = {} self.isDarknetRunning = False self.darknetProc = None self.mw = Pymem() self.objects = b'{}' def start_darknet(self): self.addresses = {} os.chdir(DARKNET_PATH) self.darknetProc = subprocess.Popen([self.executable] + self.args, stdout=subprocess.PIPE) while 1: try: self.mw.open_process_from_id(int(self.darknetProc.pid)) break except (pymem.exception.CouldNotOpenProcess, TypeError): time.sleep(0.5) self.load_addresses() os.chdir(LOCAL_PATH) self.isDarknetRunning = True def stop_darknet(self): self.isDarknetRunning = False self.addresses = {} self.darknetProc.kill() def get_darknet_output(self): return darknetProc.communicate()[0] def run(self): try: while self.isDarknetRunning: length = self.mw.read_uint( int(self.addresses['detectedObjectsLength'][0], 0)) pointer = self.mw.read_bytes( int(self.addresses['detectedObjects'][0], 0), 8) try: #sometimes memory reads error here self.objects = self.mw.read_bytes( int.from_bytes(pointer, 'little'), length) except: pass time.sleep(0.01) except: print("Darknet has stopped running!") self.isDarknetRunning = False self.addresses = {} def load_addresses(self): os.chdir(DARKNET_PATH) fName = self.executable + "-" + str( self.darknetProc.pid) + "-streamedFile.data" while not os.path.exists(fName): time.sleep(0.5) if os.path.isfile(fName): with open(fName, 'r') as f: self.addresses = json.load(f) os.remove(fName) os.chdir(LOCAL_PATH) def get_objects(self): #print(self.objects.decode()) try: return json.loads(self.objects.decode()) except: return None
from pymem import Pymem fileStruct = (0x6d9100) bufferOffset = (3 - 1) * 4 pm = Pymem('Rebels.exe') bufferPtr = pm.read_uint(fileStruct + bufferOffset) content = [] idx = 0 while True: ch = pm.read_uchar(bufferPtr + idx) if ch in [0x0D, 0xF0, 0xAD, 0xBA]: break content.append(ch) idx += 1 print(''.join([chr(x) for x in content]))