示例#1
0
# 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)

wdir = os.path.abspath('.')
log_path = os.path.join(wdir, 'out.log').replace("\\", "\\\\")
err_path = os.path.join(wdir, 'err.log').replace("\\", "\\\\")
shellcode = """
import sys
from os import chdir
from traceback import format_exc
init_modules = sys.modules.copy()
示例#2
0
        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)

print("initialize ingame python environment success")
application_path = ""
if getattr(sys, 'frozen', False):
    application_path = os.path.dirname(sys.executable)
elif __file__:
    application_path = os.path.dirname(__file__)
else:
    input("application_path not found" + endl)
    exit()