Search in sources :

Example 6 with Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.

the class StmtTraveler method travel.

public void travel(StmtList stmts) {
    for (Iterator<Stmt> it = stmts.iterator(); it.hasNext(); ) {
        Stmt stmt = it.next();
        Stmt n = travel(stmt);
        if (n != stmt) {
            stmts.insertBefore(stmt, n);
            it.remove();
        }
    }
}
Also used : Stmt(com.googlecode.dex2jar.ir.stmt.Stmt)

Example 7 with Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.

the class AggTransformer method simpleMergeLocals.

/**
     * if a local is only used in one place, and the value is isLocationInsensitive,
     * remove the local and replace it with its value
     * <pre>
     *     a=b+c
     *     d=a+e
     * </pre>
     * to
     * <pre>
     *     d=(b+c)+e
     * </pre>
     */
private boolean simpleMergeLocals(IrMethod method, boolean changed, Set<Stmt> locationSensitiveStmts) {
    if (method.locals.size() == 0) {
        return false;
    }
    final int[] readCounts = Cfg.countLocalReads(method);
    Set<Local> useInPhi = collectLocalUsedInPhi(method);
    final Map<Local, Value> toReplace = new HashMap<>();
    for (Iterator<Stmt> it = method.stmts.iterator(); it.hasNext(); ) {
        Stmt p = it.next();
        if (p.st == Stmt.ST.ASSIGN && p.getOp1().vt == Value.VT.LOCAL) {
            Local local = (Local) p.getOp1();
            if (useInPhi.contains(local)) {
                continue;
            }
            if (readCounts[local._ls_index] < 2) {
                Value op2 = p.getOp2();
                if (isLocationInsensitive(op2)) {
                    method.locals.remove(local);
                    toReplace.put(local, op2);
                    it.remove();
                    changed = true;
                } else {
                    locationSensitiveStmts.add(p);
                }
            }
        }
    }
    Cfg.TravelCallBack tcb = new Cfg.TravelCallBack() {

        @Override
        public Value onAssign(Local v, AssignStmt as) {
            return v;
        }

        @Override
        public Value onUse(Local v) {
            Value v2 = toReplace.get(v);
            if (v2 != null) {
                return v2;
            }
            return v;
        }
    };
    modReplace(toReplace, tcb);
    Cfg.travelMod(method.stmts, tcb, false);
    return changed;
}
Also used : AssignStmt(com.googlecode.dex2jar.ir.stmt.AssignStmt) Value(com.googlecode.dex2jar.ir.expr.Value) Local(com.googlecode.dex2jar.ir.expr.Local) LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) AssignStmt(com.googlecode.dex2jar.ir.stmt.AssignStmt) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt)

Example 8 with Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.

the class ConstTransformer method collect.

private void collect(IrMethod m) {
    for (Stmt p = m.stmts.getFirst(); p != null; p = p.getNext()) {
        if (p.st == ST.ASSIGN || p.st == ST.IDENTITY) {
            E2Stmt e2 = (E2Stmt) p;
            Value op1 = e2.op1.trim();
            Value op2 = e2.op2.trim();
            if (op1.vt == VT.LOCAL) {
                ConstAnalyzeValue cav = (ConstAnalyzeValue) ((Local) op1).tag;
                if (op2.vt == VT.CONSTANT) {
                    Constant c = (Constant) op2;
                    cav.isConst = true;
                    cav.cst = c.value;
                } else if (op2.vt == VT.LOCAL) {
                    Local local2 = (Local) op2;
                    ConstAnalyzeValue zaf2 = (ConstAnalyzeValue) local2.tag;
                    cav.assignFrom.add(zaf2);
                    zaf2.assignTo.add(cav);
                } else if (op2.vt == VT.PHI) {
                    PhiExpr pe = (PhiExpr) op2;
                    for (Value v : pe.ops) {
                        ConstAnalyzeValue zaf2 = (ConstAnalyzeValue) ((Local) v.trim()).tag;
                        cav.assignFrom.add(zaf2);
                        zaf2.assignTo.add(cav);
                    }
                } else {
                    cav.isConst = Boolean.FALSE;
                }
            }
        }
    }
}
Also used : E2Stmt(com.googlecode.dex2jar.ir.stmt.Stmt.E2Stmt) AssignStmt(com.googlecode.dex2jar.ir.stmt.AssignStmt) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt) E2Stmt(com.googlecode.dex2jar.ir.stmt.Stmt.E2Stmt)

Example 9 with Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.

the class UnSSATransformer method insertAssignPath.

private void insertAssignPath(IrMethod method, Collection<LabelStmt> phiLabels) {
    // FIXME the phi in Exception handler is buggy
    List<AssignStmt> buff = new ArrayList<>();
    for (LabelStmt labelStmt : phiLabels) {
        List<AssignStmt> phis = (List<AssignStmt>) labelStmt.phis;
        LiveV[] frame = (LiveV[]) labelStmt.frame;
        for (Stmt from : labelStmt._cfg_froms) {
            if (from.visited) {
                // at lease it is reached by cfg
                for (AssignStmt phi : phis) {
                    Local a = (Local) phi.getOp1();
                    LiveV v = frame[a._ls_index];
                    Local local = v.stmt2regMap.get(from);
                    if (local != a) {
                        buff.add(Stmts.nAssign(a, local));
                    }
                }
                insertAssignPath(method.stmts, from, labelStmt, buff);
                buff.clear();
            }
        }
    }
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) AssignStmt(com.googlecode.dex2jar.ir.stmt.AssignStmt) ArrayList(java.util.ArrayList) Local(com.googlecode.dex2jar.ir.expr.Local) StmtList(com.googlecode.dex2jar.ir.stmt.StmtList) ArrayList(java.util.ArrayList) List(java.util.List) LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) JumpStmt(com.googlecode.dex2jar.ir.stmt.JumpStmt) AssignStmt(com.googlecode.dex2jar.ir.stmt.AssignStmt) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt)

Example 10 with Stmt

use of com.googlecode.dex2jar.ir.stmt.Stmt in project dex2jar by pxb1988.

the class ZeroTransformer method transformReportChanged.

@Override
public boolean transformReportChanged(IrMethod method) {
    boolean changed = false;
    List<AssignStmt> assignStmtList = new ArrayList<>();
    for (Stmt p = method.stmts.getFirst(); p != null; p = p.getNext()) {
        if (p.st == Stmt.ST.ASSIGN) {
            AssignStmt as = (AssignStmt) p;
            if (as.getOp1().vt == Value.VT.LOCAL && as.getOp2().vt == Value.VT.CONSTANT) {
                Constant cst = (Constant) as.getOp2();
                Object value = cst.value;
                if (value instanceof Number && !((value instanceof Long) || (value instanceof Double))) {
                    int v = ((Number) value).intValue();
                    if (v == 0 || v == 1) {
                        assignStmtList.add(as);
                    }
                }
            }
        }
    }
    if (assignStmtList.size() == 0) {
        return false;
    }
    List<LabelStmt> phiLabels = method.phiLabels;
    if (phiLabels != null) {
        for (AssignStmt as : assignStmtList) {
            Local local = (Local) as.getOp1();
            boolean first = true;
            for (LabelStmt labelStmt : phiLabels) {
                for (AssignStmt phi : labelStmt.phis) {
                    Value[] vs = phi.getOp2().getOps();
                    for (int i = 0; i < vs.length; i++) {
                        Value v = vs[i];
                        if (v == local) {
                            if (first) {
                                first = false;
                            } else {
                                Local nLocal = Exprs.nLocal(-1);
                                method.locals.add(nLocal);
                                changed = true;
                                method.stmts.insertBefore(as, Stmts.nAssign(nLocal, as.getOp2().clone()));
                                vs[i] = nLocal;
                            }
                        }
                    }
                }
            }
        }
    }
    return changed;
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) AssignStmt(com.googlecode.dex2jar.ir.stmt.AssignStmt) Constant(com.googlecode.dex2jar.ir.expr.Constant) ArrayList(java.util.ArrayList) Local(com.googlecode.dex2jar.ir.expr.Local) LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) AssignStmt(com.googlecode.dex2jar.ir.stmt.AssignStmt) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt) Value(com.googlecode.dex2jar.ir.expr.Value)

Aggregations

Stmt (com.googlecode.dex2jar.ir.stmt.Stmt)41 LabelStmt (com.googlecode.dex2jar.ir.stmt.LabelStmt)31 Local (com.googlecode.dex2jar.ir.expr.Local)23 AssignStmt (com.googlecode.dex2jar.ir.stmt.AssignStmt)22 Test (org.junit.Test)10 Value (com.googlecode.dex2jar.ir.expr.Value)8 ArrayList (java.util.ArrayList)7 JumpStmt (com.googlecode.dex2jar.ir.stmt.JumpStmt)4 Cfg (com.googlecode.dex2jar.ir.ts.Cfg)4 Trap (com.googlecode.dex2jar.ir.Trap)3 StmtList (com.googlecode.dex2jar.ir.stmt.StmtList)3 List (java.util.List)3 StmtTraveler (com.googlecode.dex2jar.ir.StmtTraveler)2 Constant (com.googlecode.dex2jar.ir.expr.Constant)2 PhiExpr (com.googlecode.dex2jar.ir.expr.PhiExpr)2 E2Stmt (com.googlecode.dex2jar.ir.stmt.Stmt.E2Stmt)2 HashSet (java.util.HashSet)2 IR2JConverter (com.googlecode.d2j.converter.IR2JConverter)1 DexFileNode (com.googlecode.d2j.node.DexFileNode)1 DexMethodNode (com.googlecode.d2j.node.DexMethodNode)1