ESIL(7)

πŸ¦‹ ESIL(7) β€” Evaluable Strings Intermediate Language πŸ¦‹

🌸 NAME 🌸

ESIL β€” Evaluable Strings Intermediate Language


✨ SYNOPSIS ✨

Okay so ESIL β€” that's Evaluable Strings Intermediate Language β€” gives you an abstract, stack-based format for representing CPU instruction semantics across all kinds of architectures. It makes instruction emulation for analysis and debugging inside the radare2 framework happen. Iconic behavior, honestly. πŸ’…


πŸ’– DESCRIPTION πŸ’–

Evaluable Strings Intermediate Language (ESIL) uses a Forth-like syntax, and it gives you a way to describe and emulate what machine instructions do in a platform-agnostic manner. It is especially useful in reverse engineering, letting you do cross-architecture binary analysis and exploitation through radare2. Obsessed. πŸ¦‹

At its core, ESIL is a stack-based language where operations manipulate values on a stack. Each CPU instruction gets translated into an ESIL expression that models its behavior. This abstraction layer lets radare2 emulate code execution without actually running it, which is invaluable for analyzing untrusted binaries or understanding complex code flows. No cap, that's the whole vibe. πŸ”₯


πŸŽ€ SYNTAX πŸŽ€

ESIL expressions use a series of operands and operations, manipulating values on an internal stack. These expressions are executed inside an ESIL virtual machine (VM), which enables simulation of CPU instructions' effects on registers and memory. ✨

The basic components of ESIL syntax are:

  • Uppercase words are special keywords that operate on the ESIL VM (e.g., POP, DUP, TRAP)
  • Lowercase words are register names that can be used for reading or writing through operations
  • Words starting with $ represent internal variables of the VM that are readonly (e.g., $z for zero flag)
  • Numbers can be in base 10 or hexadecimal (with 0x prefix)
  • Operations are separated by commas
  • Results are pushed onto the stack or written to registers/memory

The rest of keywords can be added or removed via ESIL or architecture plugins, but this document describes the common and standard ESIL commands. 🫢


πŸ¦‹ USING ESIL IN RADARE2 πŸ¦‹

radare2 provides several ways to work with ESIL:

  • The e asm.esil=true option displays ESIL expressions alongside assembly instructions
  • The e emu.str=true option enables string emulation during analysis
  • The ae command family provides ways to evaluate and debug ESIL expressions
  • Visual mode offers ESIL debugging capabilities through the VdE command

These features allow users to inspect register states, memory modifications, and operation flow without actually executing the binary code on the CPU. Literally the whole point. πŸ’€


πŸ’… ESIL COMMANDS πŸ’…

radare2 leverages ESIL for detailed emulation of instruction execution, enabling users to step through instructions, inspect changes to registers and memory, and evaluate conditional logic in a controlled environment. It's giving microscope for code. πŸ”¬

Here are the most commonly used ESIL-related commands:

  • ae [expr] β€” evaluate an ESIL expression. Note that some expressions contain special characters that can be evaluated by the radare2 shell, so it's better to prefix the command with a single quote ' to skip that parsing.
  • aei β€” initialize the ESIL VM state (required before emulation)
  • aeim β€” initialize ESIL VM stack memory
  • aeip β€” initialize ESIL program counter to current offset
  • aer β€” show or modify ESIL registers
  • aes β€” ESIL Step: execute a single step in ESIL emulation
  • aeso β€” ESIL Step Over: perform a step over call instructions in ESIL emulation
  • aesu [addr] β€” ESIL Step Until: continue ESIL execution until a specified address is reached
  • aev [expr] β€” enter the interactive visual debugger to debug and emulate an ESIL expression

Typical workflow for ESIL emulation:

aei      # Initialize ESIL VM state
aeim     # Initialize memory for ESIL VM
aeip     # Set program counter to current address
aes      # Start stepping through instructions

πŸ”₯ ESIL OPERATION CATEGORIES πŸ”₯

The comma-separated words in an ESIL expression can be grouped into different categories:

Internal flags

Prefixed with $, they represent internal states of the ESIL VM and are used to perform conditional operations:

  • $z β€” Zero flag: set when result is zero
  • $c β€” Carry flag: set when operation produces a carry
  • $b β€” Borrow flag: set when operation requires a borrow
  • $p β€” Parity flag: set when result has even parity
  • $s β€” Sign flag: set when result is negative
  • $o β€” Overflow flag: set when result overflows
  • $$ β€” current address being executed
  • $ds, $jt, $js β€” used for delay slots and jump targeting

Assignment operations

Pop value and destination from stack and perform assignment:

  • = β€” strong assignment (updates flags)
  • := β€” weak assignment (no flag updates)

Arithmetic and binary operations

Basic math operations:

  • + β€” addition
  • - β€” subtraction
  • * β€” multiplication
  • L* β€” long multiplication (128-bit result)
  • / β€” division
  • ~/ β€” signed division
  • % β€” modulo
  • ~% β€” signed modulo
  • ~ β€” sign extension
  • & β€” bitwise AND
  • | β€” bitwise OR
  • ^ β€” bitwise XOR
  • ! β€” logical NOT
  • << β€” left shift
  • >> β€” right shift
  • ROL β€” rotate left
  • ROR β€” rotate right
  • ASR β€” arithmetic shift right, signed at the width of the value's register
  • CLZ β€” count leading zeros of a value within an explicit width
  • POPCNT β€” count the set bits of a value

An operation takes an explicit leading width operand only when its result depends on that width: CLZ does (the count for 1 is 31 at width 32 and 63 at width 64), POPCNT does not.

The shifts are total: <<, >> and ASR by a count of 64 or more push 0, 0 and the sign fill respectively, and ASR of a register by its width or more pushes the sign fill.

Comparison operations

Compare values and set flags:

  • == β€” equality comparison
  • < β€” less than
  • <= β€” less than or equal
  • > β€” greater than
  • >= β€” greater than or equal

Control flow

Conditional expressions and flow control:

  • ?{ β€” if condition, execute next block if top of stack is non-zero
  • } β€” end of conditional block
  • }{ β€” else statement
  • GOTO β€” jump to specified location
  • BREAK β€” stop execution

Memory access

Read from or write to memory:

  • Reading: [1], [2], [4], [8], [16] β€” read 1, 2, 4, 8, or 16 bytes
  • Writing: =[1], =[2], =[4], =[8], =[16] β€” write 1, 2, 4, 8, or 16 bytes
  • Combined: |=[2], +=[4], &=[4], --=[2] β€” read-modify-write operations
  • Special: [*], =[*] β€” variable size operations

Stack manipulation

Special operations to manage the ESIL stack:

  • STACK β€” display stack contents
  • POP β€” remove top value
  • DUP β€” duplicate top value
  • NUM β€” push number or register value
  • SWAP β€” swap top two values
  • ROT β€” rotate the third stack element to the top: [x,y,z] becomes [y,z,x]
  • CLEAR β€” empty the stack

Special operations

  • () β€” syscall
  • $ β€” hardware interrupt
  • #! β€” execute radare2 command
  • TRAP β€” CPU trap
  • BITS β€” change bits mode

Floating point operations

  • NAN β€” check if value is Not-a-Number
  • I2D, U2D β€” convert integer to double (signed, unsigned)
  • D2I β€” convert double to integer
  • D2F, F2D β€” convert between double and float
  • F==, F!=, F<, F<= β€” floating point comparisons
  • F+, F-, F*, F/ β€” floating point arithmetic
  • -F β€” negate floating point value
  • CEIL, FLOOR, ROUND β€” rounding operations
  • SQRT β€” square root

🌈 UNDERSTANDING ESIL EXPRESSIONS 🌈

ESIL expressions are evaluated from left to right, with values being pushed onto or popped from a stack. The following examples demonstrate how common CPU instructions translate to ESIL:

mov eax, 0x3

Simply assigns the value 3 to register eax:

3,eax,=

add ebx, eax

Adds the value in eax to ebx and stores the result in ebx:

eax,ebx,+=

This is equivalent to the longer form:

eax,ebx,+,ebx,=

xor eax, eax

Performs XOR on eax with itself (effectively zeroing it):

eax,eax,^=

mov byte [ebx], 0x3

Writes the value 3 to the memory address in ebx:

3,ebx,=[1]

test eax, eax

Sets flags based on eax value (primarily the zero flag):

eax,eax,&,zf,=

jz 0x123456

Jumps to address if zero flag is set:

zf,?{,0x123456,eip,=,}

πŸ‘‘ VISUAL ESIL DEBUGGER πŸ‘‘

radare2 provides a visual ESIL debugger that allows stepping through ESIL expressions to understand exactly how they work. This is accessed through the aev command or in visual mode with VdE. 🧚

The visual ESIL debugger offers several advantages:

  • Step-by-step execution of ESIL expressions
  • Visualization of the stack after each operation
  • Inspection of register and flag changes
  • Memory access monitoring
  • Finer-grained control than regular ESIL emulation

When using the visual ESIL debugger, you can use the following controls:

  • s β€” step forward one ESIL operation
  • r β€” reset the ESIL VM state
  • q β€” quit the debugger

This tool is particularly useful for understanding complex instructions or when debugging emulation issues.

🌸 PRACTICAL USAGE EXAMPLES 🌸

okay bestie, this is the part where it stops being theory and starts being hands on keyboard πŸ’… here's how you actually use ESIL in radare2 for analysis and debugging, fr fr:

✨ Basic ESIL evaluation ✨

so to evaluate a simple ESIL expression, you just hit it with:

[0x00000000]> ae 1,1,+
2

and boom, it gives you 2 back β€” math is mathing πŸ”₯


πŸŽ€ Step-by-step emulation πŸŽ€

to emulate a function and actually see the register changes happen, do this little ritual in order:

[0x00000000]> aei      # Initialize ESIL VM
[0x00000000]> aeim     # Initialize memory
[0x00000000]> aeip     # Set PC to current address
[0x00000000]> aes      # Step one instruction
[0x00000000]> aer      # View registers

like, aei wakes the VM up, aeim gives it a memory to live in, aeip points the PC at the current address, aes steps one (1) single instruction, and aer is your vibe check for the registers 🫢 so iconic honestly


πŸ¦‹ ESIL debugging of an expression πŸ¦‹

wanna debug a complex ESIL expression with the visual debugger? just:

[0x00000000]> aev 1,5,+,eax,=

the visual debugger ate that assignment expression up, no cap ✨


πŸ’œ Conditional emulation πŸ’œ

to emulate until a condition is met:

[0x00000000]> aecu 0x4000  # Continue until address 0x4000

it just keeps going until it reaches 0x4000, periodt πŸ’…


πŸ‘‘ R2WARS πŸ‘‘

okay so this is literally the fun one β€” a code-wars-like game built on top of ESIL, used at the r2con conference πŸ”₯ players write small programs that compete in a virtual arena, and the ESIL VM is the one executing and evaluating their behavior. main character energy for the VM honestly 😭

more info: https://github.com/radareorg/r2wars


⭐ SEE ALSO ⭐


🌈 WWW 🌈

https://www.radare.org/


πŸ’– AUTHORS πŸ’–

  • pancake <pancake@nopcode.org>

k that's the whole page bestie, you're officially ESIL-pilled πŸ§šπŸ’« and just so you have the receipts: this was ESIL(7) from August 26, 2026 β€” go forth and emulate, love u πŸ’œπŸŒΈ

πŸ“¦ where this page comes from