-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Early stop of IR CFG's Symbolic Execution (stops at SHR instruction) #1471
Comments
Hi @psyirius !
So the generate IR reflect this.
In miasm, the cmovz will generate the very same IR graph as the IF/then. |
Got any quick workaround for the sym exec to reach where RCX is assigned a const value? Btw se.run_at is not fully executed even after supplying lbl_stop! |
Hi
I didn't get your point with the lbl_stop stuff. Can you detail this? |
Okay, I get it now! It stops because of the non-deterministic branching caused by SHR which got unresolved dependencies. I was wondering why there is a break in control-flow when its not in ASM. Thank you for the answer. I wonder if there is any easier workaround to merge that extra generated branch into the states and pursue execution to reach the RCX assignment! |
I know this decision was made somewhere early in miasm's development, but I was still not able to find any motivation for it. When doing symbolic execution these IF statements are creating a major annoyance and you have to write your own IR pass that rewrites it into ternary statements. Obviously for things like |
Hi @mrexodia ! |
I do not think it is important information whether the flag was modified or not. The important information is usually the expression extracted from the flag at a later point in execution (usually a branch). Similarly with division, of course there is an edge case where you divide by zero but it is unlikely to happen in practice and we usually just assume it is non-zero (in fact I add that as a additional constraint). Of course I understand the correctness argument to some extent, but this part of miasm is hindering experimentation on “simple” obfuscation schemes for beginners in my experience… |
I agree with you on the division part: At an extend point, if one simplification decides that the memory lookup or write can be simplified (ie removed), it's here that we may remove a code that can potentially fail. So maybe the simplification engine has to take the decision. And the problem may be the same for example by wanting to swap 2 memory lookup for memory barriers. But for the "precision vs simple analyze", I find your point a bit more arbitrary: Masking the difficulty of such patterns, which transform a 'data dependency' into an 'execution flow problem' will still be there in those other cases even if we patch the Some times ago, on an old miasm version, a user reported a problem in the simplification engine. In his code snip from its backtrace, I saw that he did the following thing: def shr(ir, instr, dst, src):
return ExprAssign(dst, dst >> src) |
Can't we do the below to replace the extra generated IR block? # something like
# sym = affect(sym) if cond else sym
ExprCond(
cond=cond_used_in_the_branching,
src1=expr_that_is_in_the_generated_block,
src2=org_symbol,
) |
Hi @psyirius shr eax, cl and don't want to have an extra block, to generate the of = ExprCond(cond, new_value, of) which means "ok, if the condition it true, assign new_value to But it has it's limits. str r0, [r1] which will store r0 at memory pointed at address r1. If we have a code C like this: if (cond) {
tab[x] = a;
tab[y] = b;
} else {
tab[x] = c;
tab[y] = d;
} you may result with this code: STREQ R4, [R0]
STREQ R5, [R1]
STRNE R6, [R2]
STRNE R7, [R3] Question: What kind of IR will you generate? ExprMem(R0) = ExprCond(cond, R4, ExprMem(R0)) which will generate dummy read/write on memory. Using the current IR, miasm generates: Adding a custom simplification rule (to factor same condition code) you ends with; |
For shift/rotates, both approaches have their advantages and pitfalls. Maybe we could add an optional argument on the lifter to choose between ternary expression and ITE blocks for the flags? |
Hi @W0ni |
ASM Block
IR CFG
END of se.run_at with step=True
The text was updated successfully, but these errors were encountered: