import struct, sys # Set TEST_MODE=True to use dwExStyle=0 (original), False for WS_EX_APPWINDOW TEST_MODE = True exe = bytearray(open("HAVOC_NOCD.EXE", "rb").read()) BASE = 0x400000 # ---- Locate .text section header ------------------------------------------- e_lfanew = struct.unpack_from(' IP after jmp = 0x{cave_va+CAVE_SIZE:07x}, " f"target = 0x{cave_va+CAVE_SIZE+jmp_back:07x}") # ---- Patch (12 bytes at 0x4260c7) ----------------------------------------- jmp_cave = cave_va - (PATCH_VA + 1 + 5) patch = bytearray() patch += b'\x51' # push ecx (title) (1b) patch += b'\xE9' + struct.pack(' IP after jmp = 0x{PATCH_VA+6:07x}, " f"target = 0x{PATCH_VA+6+jmp_cave:07x}") # Confirm jump targets assert PATCH_VA + 6 + jmp_cave == cave_va, "jmp_cave target mismatch" assert cave_va + CAVE_SIZE + jmp_back == BACK_VA, "jmp_back target mismatch" print("Jump target assertions: OK") # ---- Apply ----------------------------------------------------------------- new_vsiz = TEXT_RAWSIZ # expose all raw data as executable struct.pack_into(' 0x{new_vsiz:x}") exe[cave_fo:cave_fo+CAVE_SIZE] = cave_code exe[patch_fo:patch_fo+12] = patch open("HAVOC_NOCD.EXE", "wb").write(exe) print("Patch R applied.")