vtil-project / VTIL-Core

Virtual-machine Translation Intermediate Language
BSD 3-Clause "New" or "Revised" License
1.31k stars 165 forks source link

How to extract an expression from a block ? #76

Closed idkreally785 closed 1 year ago

idkreally785 commented 1 year ago

For example, I have this block, how do I correctly generate an expression for reg_ax

vtil::register_desc reg_ax(vtil::register_physical, registers::ax, vtil::arch::bit_count, 0);

auto block = vtil::basic_block::begin(0x1337);

block->mov(reg_ax, 0x10);
block->add(reg_ax, 0x1);
block->vexit(0ull);

I tried using the tracer like this, but to no avail. Regardless of whether I use tracer or not, I get the result "rax#0x1337", the same will happen without tracing if I just use variable.to_expression()

vtil::tracer tracer;
auto expression = tracer.rtrace_p({ block->begin(), reg_ax });

vtil::logger::log("%s\n", expression.to_string());
can1357 commented 1 year ago

The tracer takes a point of reference as to where to read the value at, since you specify block begin, this results in rax#1337, aka value at the beginning of the routine.

Give block->end() a try. Feel free to reopen if that does not solve it.