use of org.mapleir.deob.intraproc.eval.LocalValueResolver in project maple-ir by LLVM-but-worse.
the class ConstantExpressionEvaluatorPass method evaluateConditional.
public Boolean evaluateConditional(IPConstAnalysisVisitor vis, ControlFlowGraph cfg, ConditionalJumpStmt cond) {
Expr l = cond.getLeft();
Expr r = cond.getRight();
if (!TypeUtils.isPrimitive(l.getType()) || !TypeUtils.isPrimitive(r.getType())) {
if (l instanceof ConstantExpr && r instanceof ConstantExpr && !TypeUtils.isPrimitive(l.getType()) && !TypeUtils.isPrimitive(r.getType())) {
ConstantExpr left = (ConstantExpr) l;
ConstantExpr right = (ConstantExpr) r;
if (left.getConstant() == null && right.getConstant() == null) {
return cond.getComparisonType() == ConditionalJumpStmt.ComparisonType.EQ;
}
if (cond.getComparisonType() == ConditionalJumpStmt.ComparisonType.EQ) {
if ((left.getConstant() == null) != (right.getConstant() == null)) {
return false;
}
}
return null;
}
return null;
}
LocalValueResolver resolver = new SemiConstantLocalValueResolver(vis);
TaintableSet<ConstantExpr> lSet = evaluator.evalPossibleValues(resolver, l);
TaintableSet<ConstantExpr> rSet = evaluator.evalPossibleValues(resolver, r);
/* can only evaluate branch if all vals are known. */
if (!lSet.isTainted() && !rSet.isTainted()) {
if (lSet.isEmpty() || rSet.isEmpty()) {
System.err.println("oim interested m89");
System.err.println("Empty:");
System.err.println(cfg);
System.err.println("inputs:");
int k = 0;
for (TaintableSet<ConstantExpr> s : vis.constParams.get(cfg)) {
System.err.printf("@%d:: %s%n", k++, s);
}
System.err.println(l + " -> " + lSet);
System.err.println(r + " -> " + rSet);
System.err.println(cfg);
System.exit(1);
throw new RuntimeException();
}
Boolean result = evaluator.evaluatePrimitiveConditional(cond, lSet, rSet);
if (result != null) {
return result;
}
}
return null;
}
Aggregations