The Official Radare2 Book | страница 97



Swap two top elementsSWAP
DUPDuplicateDuplicate top element in stackDUP
NUMNumericIf top element is a reference (register name, label, etc), dereference it and push its real valueNUM
CLEARClearClear stackCLEAR
BREAKBreakStops ESIL emulationBREAK
GOTOnGotoJumps to Nth ESIL wordGOTO 5
TODOTo DoStops execution (reason: ESIL expression not completed)TODO

ESIL VM provides by default a set of helper operations for calculating flags. They fulfill their purpose by comparing the old and the new value of the dst operand of the last performed eq-operation. On every eq-operation (e.g. =) ESIL saves the old and new value of the dst operand. Note, that there also exist weak eq operations (e.g. :=), which do not affect flag operations. The == operation affects flag operations, despite not being an eq operation. Flag operations are prefixed with $ character.

z - zero flag, only set if the result of an operation is 0

b - borrow, this requires to specify from which bit (example: 4,$b - checks if borrow from bit 4)

c - carry, same like above (example: 7,$c - checks if carry from bit 7)

o - overflow

p - parity

r - regsize ( asm.bits/8 )

s - sign

ds - delay slot state

jt - jump target

js - jump target set

A target opcode is translated into a comma separated list of ESIL expressions.

xor eax, eax -> 0,eax,=,1,zf,=

Memory access is defined by brackets operation:

mov eax, [0x80480] -> 0x80480,[],eax,=

Default operand size is determined by size of operation destination.

movb $0, 0x80480 -> 0,0x80480,=[1]

The ? operator uses the value of its argument to decide whether to evaluate the expression in curly braces.

   1. Is the value zero? -> Skip it.

   2. Is the value non-zero? -> Evaluate it.

cmp eax, 123 -> 123,eax,==,$z,zf,=

jz eax -> zf,?{,eax,eip,=,}

If you want to run several expressions under a conditional, put them in curly braces:

zf,?{,eip,esp,=[],eax,eip,=,$r,esp,-=,}

Whitespaces, newlines and other chars are ignored. So the first thing when processing a ESIL program is to remove spaces:

esil = r_str_replace (esil, " ", "", R_TRUE);

Syscalls need special treatment. They are indicated by '$' at the beginning of an expression. You can pass an optional numeric value to specify a number of syscall. An ESIL emulator must handle syscalls. See (r_esil_syscall).

As discussed on IRC, the current implementation works like this: