ESIL
Evaluable Strings Intermediate Language
- Provided by: radare2 (Version: 6.0.7+ds-1)
- Report a bug
Evaluable Strings Intermediate Language
ESIL (Evaluable Strings Intermediate Language) provides an abstract, stack-based format for representing CPU instruction semantics across various architectures, facilitating instruction emulation for analysis and debugging within the radare2 framework.
Evaluable Strings Intermediate Language (ESIL) adopts a Forth-like syntax, offering a method to describe and emulate the behavior of machine instructions in a platform-agnostic manner. It is particularly useful in reverse engineering, allowing for cross-architecture binary analysis and exploitation through radare2.
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 allows radare2 to emulate code execution without actually running it, making it invaluable for analyzing untrusted binaries or understanding complex code flows.
ESIL expressions use a series of operands and operations, manipulating values on an internal stack. These expressions are executed within an ESIL virtual machine (VM), enabling the simulation of CPU instructions' effects on registers and memory.
The basic components of ESIL syntax are:
The rest of keywords can be added or removed via ESIL or architecture plugins, but this document describes the common and standard ESIL commands.
Radare2 provides several ways to work with ESIL:
These features allow users to inspect register states, memory modifications, and operation flow without actually executing the binary code on the CPU.
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.
Here are the most commonly used ESIL-related commands:
ae
[expr]aeiaeimaeipaeraesaesoaesu
[addr]aev
[expr]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
The comma-separated words in an ESIL expression can be grouped into different categories:
Internal
flagsAssignment
operationsArithmetic
and binary operationsComparison
operationsControl
flowMemory
accessStack
manipulationSpecial
operationsFloating
point operationsESIL 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,
0x33,eax,=
add ebx,
eaxeax,ebx,+=
eax,ebx,+,ebx,=
xor eax,
eaxeax,eax,^=
mov byte
[ebx], 0x33,ebx,=[1]
test eax,
eaxeax,eax,&,zf,=
jz
0x123456zf,?{,0x123456,eip,=,}
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:
When using the visual ESIL debugger, you can use the following controls:
This tool is particularly useful for understanding complex instructions or when debugging emulation issues.
Here are some practical ways to use ESIL in radare2 for analysis and debugging:
Basic ESIL
evaluation[0x00000000]> ae 1,1,+ 2
Step-by-step
emulation[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
ESIL
debugging of an expression[0x00000000]> aev 1,5,+,eax,=
Conditional
emulation[0x00000000]> aecu 0x4000 # Continue until address 0x4000
A code-wars like game implemented on top of ESIL used in the r2con conference. Players write small programs that compete in a virtual arena, with the ESIL VM executing and evaluating their behavior.
More information: https://github.com/radareorg/r2wars
https://www.radare.org/
pancake <pancake@nopcode.org>