What Is a Gadget?
- A gadget is a short sequence of instructions that ends in
ret(0xc3). - Examples: pop rdi ; ret pop rsi ; pop r15 ; ret add rax, rbx ; ret
retpops the next value off the stack intoRIP.- So a stack full of {gadget addr, data, gadget addr, data, ...} becomes a program whose "instruction pointer" is the stack pointer.
- Each
retadvances us to the next gadget: the stack drives control flow.
Key Takeaway
The stack becomes the instruction stream; ret is the "fetch next gadget" engine.