use of org.mapleir.ir.code.expr.ArithmeticExpr.Operator in project maple-ir by LLVM-but-worse.
the class ConstantExpressionReorderPass method transform.
private int transform(ControlFlowGraph ir) {
int i = 0;
for (BasicBlock b : ir.vertices()) {
for (Stmt stmt : b) {
if (stmt.getOpcode() == COND_JUMP) {
ConditionalJumpStmt cjs = (ConditionalJumpStmt) stmt;
Expr r = cjs.getRight();
Expr l = cjs.getLeft();
ComparisonType type = cjs.getComparisonType();
if (type == ComparisonType.EQ || type == ComparisonType.NE) {
if (shouldReorder(r, l)) {
cjs.setRight(null);
cjs.setLeft(null);
cjs.setLeft(r);
cjs.setRight(l);
i++;
}
}
}
for (Expr e : stmt.enumerateOnlyChildren()) {
if (e.getOpcode() == ARITHMETIC) {
ArithmeticExpr arith = (ArithmeticExpr) e;
Expr r = arith.getRight();
Expr l = arith.getLeft();
Operator op = arith.getOperator();
if (!op.doesOrderMatter()) {
if (shouldReorder(r, l)) {
arith.setRight(null);
arith.setLeft(null);
arith.setLeft(r);
arith.setRight(l);
i++;
}
}
}
}
}
}
return i;
}
use of org.mapleir.ir.code.expr.ArithmeticExpr.Operator in project maple-ir by LLVM-but-worse.
the class FieldRSADecryptionPass method bcheck1.
static boolean bcheck1(Expr e) {
if (e.getOpcode() == ARITHMETIC) {
ArithmeticExpr ar = (ArithmeticExpr) e;
Operator op = ar.getOperator();
return op != Operator.MUL && op != Operator.ADD;
} else {
return true;
}
}
use of org.mapleir.ir.code.expr.ArithmeticExpr.Operator in project maple-ir by LLVM-but-worse.
the class ExpressionEvaluator method reassociate.
private ArithmeticExpr reassociate(LocalsPool pool, ArithmeticExpr ae) {
ArithmeticExpr leftAe = (ArithmeticExpr) ae.getLeft();
Operator operatorA = leftAe.getOperator();
Operator operatorB = ae.getOperator();
Expr r1 = eval(pool, leftAe.getRight());
Expr r2 = eval(pool, ae.getRight());
if (r1 != null && r2 != null) {
ConstantExpr cr1 = (ConstantExpr) r1;
ConstantExpr cr2 = (ConstantExpr) r2;
int sign = 0;
if ((operatorA == MUL && operatorB == MUL)) {
sign = 1;
} else if (operatorA == ADD && (operatorB == ADD || operatorB == SUB)) {
// what about overflow?? integers mod 2^32 forms a group over addition...should be ok?
sign = 1;
} else if (operatorA == SUB && (operatorB == ADD || operatorB == SUB)) {
sign = -1;
}
if (sign != 0) {
ConstantExpr cr1r2 = eval(pool, new ArithmeticExpr(sign > 0 ? cr2 : new NegationExpr(cr2), cr1, operatorB));
Object associated = cr1r2.getConstant();
return new ArithmeticExpr(new ConstantExpr(associated, cr1r2.getType()), leftAe.getLeft().copy(), operatorA);
}
}
return null;
}
Aggregations