Search in sources :

Example 11 with Local

use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.

the class SSATransformer method cleanTagsAndReIndex.

private void cleanTagsAndReIndex(IrMethod method) {
    int i = 0;
    for (Local local : method.locals) {
        local.tag = null;
        local._ls_index = i++;
    }
}
Also used : Local(com.googlecode.dex2jar.ir.expr.Local)

Example 12 with Local

use of com.googlecode.dex2jar.ir.expr.Local 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 13 with Local

use of com.googlecode.dex2jar.ir.expr.Local 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)

Example 14 with Local

use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.

the class AggTransformerTest method t002.

@Test
public void t002() {
    Local a = addLocal("a");
    Local b = addLocal("b");
    Local c = addLocal("c");
    addStmt(nAssign(a, nNewIntArray(nInt(5))));
    addStmt(nAssign(b, nInt(2)));
    addStmt(nAssign(c, nArray(a, b, "I")));
    addStmt(nReturn(c));
    transform();
    Assert.assertTrue(stmts.getSize() == 1);
    Assert.assertTrue(locals.size() == 0);
}
Also used : Local(com.googlecode.dex2jar.ir.expr.Local) Test(org.junit.Test)

Example 15 with Local

use of com.googlecode.dex2jar.ir.expr.Local in project dex2jar by pxb1988.

the class AggTransformerTest method test05.

@Test
public void test05() {
    String sbType = "Ljava/lang/StringBuilder;";
    String sType = "Ljava/lang/String;";
    Local b = addLocal("b");
    Local ex = addLocal("ex");
    Local c = addLocal("c");
    Local d = addLocal("d");
    Local e = addLocal("e");
    Local cst = addLocal("cst");
    addStmt(nAssign(b, nString("123")));
    addStmt(nAssign(c, Exprs.nInvokeNew(new Value[0], new String[0], sbType)));
    addStmt(nAssign(d, c));
    addStmt(nAssign(cst, nString("p1")));
    addStmt(nAssign(c, Exprs.nInvokeVirtual(new Value[] { d, cst }, sbType, "append", new String[] { sType }, sbType)));
    addStmt(nAssign(e, c));
    addStmt(nAssign(cst, nString("p2")));
    addStmt(nAssign(c, Exprs.nInvokeVirtual(new Value[] { e, cst }, sbType, "append", new String[] { sType }, sbType)));
    addStmt(nAssign(c, Exprs.nInvokeVirtual(new Value[] { c }, sbType, "toString", new String[0], sType)));
    addStmt(nReturn(c));
    new SSATransformer().transform(method);
    transform();
    Assert.assertTrue(stmts.getSize() == 1);
    Assert.assertTrue(locals.size() == 0);
}
Also used : SSATransformer(com.googlecode.dex2jar.ir.ts.SSATransformer) Local(com.googlecode.dex2jar.ir.expr.Local) Test(org.junit.Test)

Aggregations

Local (com.googlecode.dex2jar.ir.expr.Local)86 Test (org.junit.Test)44 LabelStmt (com.googlecode.dex2jar.ir.stmt.LabelStmt)28 Stmt (com.googlecode.dex2jar.ir.stmt.Stmt)23 Value (com.googlecode.dex2jar.ir.expr.Value)19 AssignStmt (com.googlecode.dex2jar.ir.stmt.AssignStmt)15 ArrayList (java.util.ArrayList)8 IrMethod (com.googlecode.dex2jar.ir.IrMethod)6 Exprs.nLocal (com.googlecode.dex2jar.ir.expr.Exprs.nLocal)6 UnopStmt (com.googlecode.dex2jar.ir.stmt.UnopStmt)6 JumpStmt (com.googlecode.dex2jar.ir.stmt.JumpStmt)5 ConstTransformer (com.googlecode.dex2jar.ir.ts.ConstTransformer)5 Exprs.nString (com.googlecode.dex2jar.ir.expr.Exprs.nString)4 StmtList (com.googlecode.dex2jar.ir.stmt.StmtList)4 Trap (com.googlecode.dex2jar.ir.Trap)3 Exprs.nArrayValue (com.googlecode.dex2jar.ir.expr.Exprs.nArrayValue)3 AnalyzeValue (com.googlecode.dex2jar.ir.ts.an.AnalyzeValue)3 List (java.util.List)3 DexLabel (com.googlecode.d2j.DexLabel)2 Op (com.googlecode.d2j.reader.Op)2