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



We can see that this corresponds to the x86 instruction push ebp! Isn't that cool? The aim is to be able to express most of the common operations performed by CPUs, like binary arithmetic operations, memory loads and stores, processing syscalls. This way if we can transform the instructions to ESIL we can see what a program does while it is running even for the most cryptic architectures you definitely don't have a device to debug on for.

r2's visual mode is great to inspect the ESIL evaluations.

There are 3 environment variables that are important for watching what a program does:

[0x00000000]> e emu.str = true

asm.emu tells r2 if you want ESIL information to be displayed. If it is set to true, you will see comments appear to the right of your disassembly that tell you how the contents of registers and memory addresses are changed by the current instruction. For example, if you have an instruction that subtracts a value from a register it tells you what the value was before and what it becomes after. This is super useful so you don't have to sit there yourself and track which value goes where.

One problem with this is that it is a lot of information to take in at once and sometimes you simply don't need it. r2 has a nice compromise for this. That is what the emu.str variable is for (asm.emustr on <= 2.2). Instead of this super verbose output with every register value, this only adds really useful information to the output, e.g., strings that are found at addresses a program uses or whether a jump is likely to be taken or not.

The third important variable is asm.esil. This switches your disassembly to no longer show you the actual disassembled instructions, but instead now shows you corresponding ESIL expressions that describe what the instruction does. So if you want to take a look at how instructions are expressed in ESIL simply set "asm.esil" to true.

[0x00000000]> e asm.esil = true

In visual mode you can also toggle this by simply typing O.

   • "ae" : Evaluate ESIL expression.

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

0x2

[0x00000000]>

   • "aes" : ESIL Step.

[0x00000000]> aes

[0x00000000]>10aes

   • "aeso" : ESIL Step Over.

[0x00000000]> aeso

[0x00000000]>10aeso

   • "aesu" : ESIL Step Until.

[0x00001000]> aesu 0x1035

ADDR BREAK

[0x00001019]>

   • "ar" : Show/modify ESIL registry.

[0x00001ec7]> ar r_00 = 0x1035

[0x00001ec7]> ar r_00

0x00001035

[0x00001019]>