False, pid) if not handler: input("could not open process" + endl) exit() # find the python library python_version = "python{0}{1}.dll".format(sys.version_info.major, sys.version_info.minor) python_lib = process.module_from_name(python_version).filename # Find or inject python module python_module = process.module_from_name(python_version, handler) if python_module: python_lib_h = python_module.lpBaseOfDll else: python_lib_h = process.inject_dll(bytes(python_lib, 'ascii'), handler) if not python_lib_h: print("inject failed" + endl) exit() local_handle = kernel32.GetModuleHandleW(python_version) dif = python_lib_h - local_handle funcs = { k: dif + kernel32.GetProcAddress(local_handle, k) for k in [b'Py_InitializeEx', b'PyRun_SimpleString', b'Py_FinalizeEx'] } param_addr = memory.allocate_memory(4, handler) memory.write_memory(ctypes.c_int, param_addr, 1, handler) process.start_thread(funcs[b'Py_InitializeEx'], param_addr, handler)
print(f"process {pid} has been injected") pid = None continue break check_time += 1 time.sleep(1) else: handler = kernel32.OpenProcess(structure.PROCESS.PROCESS_ALL_ACCESS.value, False, pid) if not handler: input(f"could not open process {pid}" + endl) exit() print("game process pid: %s" % pid) if check_time: time.sleep(3) python_lib_h = process.inject_dll(bytes(python_lib, 'utf-8'), handler) if not python_lib_h: input("inject failed" + endl) exit() print("inject python environment success") local_handle = kernel32.GetModuleHandleW(python_version) dif = python_lib_h - local_handle funcs = {k: dif + kernel32.GetProcAddress(local_handle, k) for k in [b'Py_InitializeEx', b'PyRun_SimpleString', b'Py_FinalizeEx']} print("search calling address success") param_addr = memory.allocate_memory(4, handler) memory.write_memory(ctypes.c_int, param_addr, 1, handler) process.start_thread(funcs[b'Py_InitializeEx'], param_addr, handler)