import ctypes
import capstone

k32 = ctypes.WinDLL('kernel32', use_last_error=True)
h = k32.OpenProcess(0x1F0FFF, False, 37676)

def rpm(addr, sz):
    buf = (ctypes.c_ubyte * sz)()
    got = ctypes.c_size_t(0)
    k32.ReadProcessMemory(h, ctypes.c_void_p(addr), buf, sz, ctypes.byref(got))
    return bytes(buf[:got.value])

md = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_64)

print('=== Disassembly around 0x7ff6b24456a9 ===')
code1 = rpm(0x7ff6b2445650, 0xC0)
for insn in md.disasm(code1, 0x7ff6b2445650):
    hex_str = ' '.join(f'{b:02x}' for b in insn.bytes)
    print(f'{insn.address:#x}: {hex_str:24} {insn.mnemonic} {insn.op_str}')

print('\n=== Disassembly around 0x7ff6b2446927 ===')
code2 = rpm(0x7ff6b24468f0, 0x80)
for insn in md.disasm(code2, 0x7ff6b24468f0):
    hex_str = ' '.join(f'{b:02x}' for b in insn.bytes)
    print(f'{insn.address:#x}: {hex_str:24} {insn.mnemonic} {insn.op_str}')
