import ctypes def arb_read(addr, size=4): return bytes((ctypes.c_byte*size).from_address(addr)) def arb_write(addr, byts): (ctypes.c_byte*len(byts)).from_address(addr)[:] = byts def rough_addr_of(a): """address of the object, not the value""" return id(a) def win_arb_exec(sc): OldProtect = ctypes.wintypes.PDWORD(ctypes.c_ulong(0)) ctypes.windll.kernel32.VirtualProtect.argtypes = [ctypes.wintypes.LPVOID, ctypes.c_size_t, ctypes.wintypes.DWORD, ctypes.wintypes.LPVOID] sc_page = id(sc) & ~0xfff x = ctypes.windll.kernel32.VirtualProtect(sc_page, 0x1000, 0x40, OldProtect) offset_to_sc = bytes((ctypes.c_byte*(128+len(sc))).from_address(id(sc))).find(sc) func = ctypes.CFUNCTYPE(None)(id(sc)+offset_to_sc) func()