Search in sources :

Example 61 with Local

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

the class UnSSATransformer method genRegGraph.

private void genRegGraph(IrMethod method, LiveA liveA) {
    for (Local local : method.locals) {
        local.tag = new RegAssign();
    }
    Set<Stmt> tos = new HashSet<>();
    for (Stmt stmt : method.stmts) {
        if ((stmt.st == ST.ASSIGN || stmt.st == ST.IDENTITY) && stmt.getOp1().vt == VT.LOCAL) {
            Local localAssignTo = (Local) stmt.getOp1();
            RegAssign regAssignTo = (RegAssign) localAssignTo.tag;
            Set<Integer> excludeIdx = new HashSet<>();
            Cfg.collectTos(stmt, tos);
            for (Stmt target : tos) {
                LiveV[] frame = (LiveV[]) target.frame;
                if (frame == null) {
                    continue;
                }
                // exclude thisReg and phiReg
                excludeIdx.clear();
                excludeIdx.add(localAssignTo._ls_index);
                if (target.st == ST.LABEL) {
                    LabelStmt label = (LabelStmt) target;
                    if (label.phis != null) {
                        for (AssignStmt phiAssignStmt : (List<AssignStmt>) label.phis) {
                            Local phiLocal = (Local) phiAssignStmt.getOp1();
                            excludeIdx.add(phiLocal._ls_index);
                        }
                    }
                }
                for (int i = 0; i < frame.length; i++) {
                    if (excludeIdx.contains(i)) {
                        continue;
                    }
                    LiveV v = frame[i];
                    if (v != null && v.used) {
                        RegAssign b = (RegAssign) v.local.tag;
                        regAssignTo.excludes.add(b);
                        b.excludes.add(regAssignTo);
                    }
                }
            }
            tos.clear();
        } else if (stmt.st == ST.LABEL) {
            //
            LabelStmt label = (LabelStmt) stmt;
            if (label.phis != null) {
                for (AssignStmt phiAssignStmt : (List<AssignStmt>) label.phis) {
                    Local phiLocal = (Local) phiAssignStmt.getOp1();
                    RegAssign a = (RegAssign) phiLocal.tag;
                    LiveV[] frame = (LiveV[]) stmt.frame;
                    for (LiveV v : frame) {
                        if (v != null && v.used) {
                            RegAssign b = (RegAssign) v.local.tag;
                            a.excludes.add(b);
                            b.excludes.add(a);
                        }
                    }
                }
            }
        }
    }
    if (DEBUG) {
        System.out.println(liveA.toString());
    }
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) AssignStmt(com.googlecode.dex2jar.ir.stmt.AssignStmt) Local(com.googlecode.dex2jar.ir.expr.Local) 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) StmtList(com.googlecode.dex2jar.ir.stmt.StmtList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 62 with Local

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

the class VoidInvokeTransformer method transformReportChanged.

@Override
public boolean transformReportChanged(IrMethod method) {
    if (method.locals.size() == 0) {
        return false;
    }
    int[] reads = Cfg.countLocalReads(method);
    boolean changed = false;
    for (Stmt p = method.stmts.getFirst(); p != null; p = p.getNext()) {
        if (p.st == Stmt.ST.ASSIGN && p.getOp1().vt == Value.VT.LOCAL) {
            Local left = (Local) p.getOp1();
            if (reads[left._ls_index] == 0) {
                switch(p.getOp2().vt) {
                    case INVOKE_INTERFACE:
                    case INVOKE_NEW:
                    case INVOKE_SPECIAL:
                    case INVOKE_STATIC:
                    case INVOKE_VIRTUAL:
                        method.locals.remove(left);
                        Stmt nVoidInvoke = Stmts.nVoidInvoke(p.getOp2());
                        method.stmts.replace(p, nVoidInvoke);
                        p = nVoidInvoke;
                        changed = true;
                        break;
                    default:
                        break;
                }
            }
        }
    }
    return changed;
}
Also used : Local(com.googlecode.dex2jar.ir.expr.Local) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt)

Example 63 with Local

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

the class BaseAnalyze method init.

protected void init() {
    if (reindexLocal) {
        int index = 0;
        for (Local local : method.locals) {
            local._ls_index = index;
            index++;
        }
    }
    if (DEBUG) {
        int idx = 0;
        for (Stmt s : method.stmts) {
            if (s.st == Stmt.ST.LABEL) {
                LabelStmt label = (LabelStmt) s;
                label.displayName = "L" + idx++;
            }
        }
    }
    initCFG();
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) 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 64 with Local

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

the class UnSSATransformerTransformerTest method test01SSAProblem.

@Test
public void test01SSAProblem() {
    initMethod(true, "I");
    Local a = addLocal("a");
    Local b = addLocal("b");
    Local phi = addLocal("p");
    LabelStmt L0 = newLabel();
    addStmt(nAssign(a, nInt(2)));
    addStmt(L0);
    attachPhi(L0, nAssign(phi, nPhi(a, b)));
    Stmt stmt = addStmt(nAssign(b, niAdd(phi, nInt(0))));
    addStmt(nIf(niGt(nInt(100), nInt(0)), L0));
    addStmt(nReturn(phi));
    transform();
    Assert.assertTrue("a new local should introduced to solve the problem", stmt.getPre() != L0);
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) Local(com.googlecode.dex2jar.ir.expr.Local) LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt) Test(org.junit.Test)

Example 65 with Local

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

the class SSATransformerTest method test11NotDeleteAssignWherePhiIsConfused.

/**
     * for
     * 
     * <pre>
     *     a=12;
     *     b=34;
     *     c=a;
     *     if c1=0 goto L1:
     *     c=b;
     *     L1:
     *     return c;
     * 
     * </pre>
     * 
     */
@Test
public void test11NotDeleteAssignWherePhiIsConfused() {
    Local a = addLocal("a");
    Local b = addLocal("b");
    Local c = addLocal("c");
    LabelStmt L1 = nLabel();
    addStmt(nAssign(a, nString("12")));
    addStmt(nAssign(b, nString("34")));
    addStmt(nAssign(c, a));
    Stmt jmp = addStmt(nIf(njGt(c, nInt(0)), L1));
    addStmt(nAssign(c, b));
    addStmt(L1);
    addStmt(Stmts.nReturn(c));
    transform();
    Assert.assertNotSame("the c=b should not deleted", jmp.getNext(), L1);
}
Also used : 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