Code caves let you inject and execute custom shellcode inside a target process. MemDBG provides the full pipeline — remote allocation, shellcode writing, memory protection, and an optional detour mechanism — all through the MDBG wire protocol and the desktop frontend's Code Cave panel.
- Open the Debugger screen and select a target process.
- Switch to the Code Cave tab.
- Click Allocate Cave to reserve 4 KB of RW memory inside the target.
- Enter your shellcode as hex bytes and click Write & Protect RX.
- (Optional) Enter a target address and click Install Detour to redirect execution from the target address into your cave.
The Allocate Cave button sends PROCESS_ALLOC (0x0109) with
protection = READ | WRITE. The payload allocates virtual memory inside the
target process using the platform's remote-syscall bridge and returns the
allocated address and size. The default size is 4 KB; you can adjust it
before allocating.
Enter raw hex bytes in the shellcode input field (e.g. B8 EF BE 00 00 CC for
mov eax, 0xBEEF; int3). Click Write & Protect RX to:
- Send
MEMORY_WRITE(0x0201) with your bytes to the cave address. - Send
PROCESS_PROTECT(0x0108) to change the cave from RW to RX (read + execute), making it executable.
Tip: You can compose shellcode with the Patch Studio tab and copy the hex bytes into the Code Cave panel.
If you want execution to automatically reach your cave, enter the target address where you want to install the jump. Click Install Detour:
- Reads 12 original bytes at the target address.
- Changes the target page to RW via
PROCESS_PROTECT. - Writes a 12-byte absolute jump (
mov rax, cave; jmp rax) viaMEMORY_WRITE. - Restores the target page to RX via
PROCESS_PROTECT.
Your shellcode should include the original bytes and a jump back to
target + 12 to preserve the original program flow.
Click Remove Detour to restore the original bytes and clean up.
| Step | Command | Notes |
|---|---|---|
| Allocate | PROCESS_ALLOC (0x0109) |
Gated by MEMDBG_CAP_MEMORY_ALLOC. Returns {address, length}. |
| Write | MEMORY_WRITE (0x0201) |
Gated by MEMDBG_CAP_MEMORY_WRITE. Request: pid + addr + len + data. |
| Protect | PROCESS_PROTECT (0x0108) |
Gated by MEMDBG_CAP_MEMORY_PROTECT. Changes RW → RX (or back). |
| Assemble | ASM_ENCODE (0x0A00) |
Gated by MEMDBG_CAP_DISASSEMBLY. Server-side Keystone assembler. Raw response: ok(4) + byte_count(4) + insn_count(4) + code(N). |
See protocol.md for the full wire format and
archive/feature_research.md for platform capability status.
B8 EF BE 00 00 mov eax, 0xBEEF
CC int3
Useful for testing: attach the debugger, set RIP to the cave, continue, and
verify that RAX equals 0xBEEF when the breakpoint hits.
48 B8 EF BE 00 00 00 00 00 00 mov rax, 0xBEEF ; marker
<original 12 bytes> ; execute replaced code
48 B8 <return_addr> mov rax, retaddr
FF E0 jmp rax ; return to target+12
CC int3 ; safety
Build the return address as target + 12 and assemble the full stub manually
or with ASM_ENCODE.
90 90 90 90 90 nop × 5
B8 14 00 00 00 mov eax, 20 ; SYS_getpid
0F 05 syscall
CC int3
For syscall-based payloads, note that syscall clobbers rcx and r11 on
x86-64. Save and restore any registers your shellcode depends on.
- W^X enforcement: The PS5 hypervisor may prevent changing a page from RW
to RX. If
PROCESS_PROTECTfails withMEMDBG_ERR_IO, the cave cannot be made executable. In that case, use the debugger'sSET_REGS(RIP=cave)approach instead of a detour. - PTWALK bypass:
MEMORY_WRITEto RX pages via the page-table walk path (PTWALK_WRITE) can trigger a hypervisor security violation and kernel panic. Always usePROCESS_PROTECTto change protection to RW before writing, then back to RX — especially when installing detours into.textpages. - ALLOC works via the remote
mmapsyscall bridge (PROCESS_ALLOC). - ASM_ENCODE uses Keystone cross-compiled with
prospero-clang(-DMEMDBG_HAS_KEYSTONE=1in the PS5 Makefile).
- Remote allocation is not currently supported. Use
PROCESS_HIJACKorPROCESS_ELF_LOADfor code injection instead. MEMDBG_CAP_MEMORY_ALLOCis not advertised.
PROCESS_ALLOCandPROCESS_FREEreturnMEMDBG_ERR_UNSUPPORTED.- Use the debugger and
SET_REGSfor testing shellcode execution. - ASM_ENCODE and DISASM are fully functional on host builds (Zydis + Keystone).