Created
March 2, 2024 15:56
-
-
Save flounderK/a2d09e2afb20fde6b55abc85e67b58d5 to your computer and use it in GitHub Desktop.
python ctypes primitives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment