Skip to main content
This guide covers advanced ROP chain composition techniques including register preservation, sigreturn frames, memory writes combined with function calls, and complex multi-stage exploits.

Register Preservation

When building complex chains, you often need to set up multiple registers without clobbering values you’ve already set.

Basic Register Preservation

Preserving Multiple Registers

Function Calls with Register Preservation

From the Python API docs and real examples:
Output:
Note: When you specify preserve_regs={'rdi'}, angrop will:
  1. Ignore the first argument (0x41414141) since rdi is preserved
  2. Only set registers that are not in the preserve set
  3. Keep the existing value in rdi intact

Real-World Example: Kernel Chain

From examples/linux_escape_chain/solve.py:38-44:
Why preserve_regs matters here:
  • move_regs(rdi='rax') puts the task_struct pointer in rdi
  • set_regs(rsi=init_nsproxy, preserve_regs={'rdi'}) sets rsi without destroying rdi
  • func_call("switch_task_namespaces", [], preserve_regs={'rdi', 'rsi'}) keeps both arguments

Sigreturn (SROP) Chains

Signal return frames let you set all registers at once, including RIP and RSP.

Basic Sigreturn

Sigreturn for Syscalls

From docs/pythonapi.md:61-62:

When to Use Sigreturn

Use SROP when:
  • You have very few gadgets available
  • You need to set many registers at once
  • You want to control both code and stack pointers
  • You have a sigreturn gadget (or syscall 15 on x86_64)
Typical pattern:

Memory Write + Function Call Chains

Complex exploits often require writing data to memory before calling functions.

Write String Then Call Function

From docs/pythonapi.md:45-46, 77:

Complete File Read Chain

Memory Manipulation Chains

Memory Arithmetic Operations

From docs/pythonapi.md:39-42:

Practical Use: Bypassing Canary

Register Movement Patterns

Moving Return Values

Complex Register Shuffling

Stack Pivoting

Pivot to Controlled Region

From docs/pythonapi.md:49-50:

Complete Pivot Example

Syscall Chains

Direct Syscall Invocation

From docs/pythonapi.md:56:

execve() via Syscall

Advanced Chain Techniques

Ret Sled

From docs/pythonapi.md:69-70:
Use cases:
  • Align stack before calling functions
  • Delay execution for timing attacks
  • Pad chain to avoid detection

Stack Shifting

From docs/pythonapi.md:67:

Badbyte Avoidance

From docs/pythonapi.md:72-74:

Multi-Stage Exploit Example

Debugging Complex Chains

Pretty Print with Comments

Generate Python Code

From docs/pythonapi.md:80-87:
Output:

Validate Chain Length

Common Patterns

Pattern: Open-Read-Write

Pattern: Privilege Escalation

Pattern: Socket Reuse