Class 07 · KP 08 / 18
Why "pop rdi ; ret" Is the Star Gadget
A ROP chain: each 'ret' launches the next gadget already present in the code.pop rdi takes the next 8 bytes off the stack into RDI; ret then jumps to the value after it.- So placing
[&(pop rdi;ret)][value][&next] on the stack means: "set RDI = value, then continue to next." - Analogous gadgets fill the other argument registers:
pop rsi ; ret → arg2pop rdx ; ret → arg3- Real binaries rarely have clean single-register pops; you often get
pop rsi ; pop r15 ; ret and must supply a junk value for r15.