Search in sources :

Example 36 with LabelStmt

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

the class UnSSATransformerTransformerTest method test05OneInPhiLoop.

@Test
public void test05OneInPhiLoop() {
    initMethod(true, "V");
    Local a = addLocal("a");
    Local b = addLocal("b");
    Local phi = addLocal("p");
    Stmt s1 = addStmt(nAssign(a, nString("123")));
    LabelStmt L1 = newLabel();
    addStmt(L1);
    attachPhi(L1, nAssign(phi, nPhi(a)));
    addStmt(nVoidInvoke(nInvokeStatic(new Value[] { phi }, "LAAA;", "bMethod", new String[] { "Ljava/lang/String;" }, "V")));
    addStmt(nAssign(b, nString("456")));
    // phi is still live here
    Stmt s2 = addStmt(nVoidInvoke(nInvokeStatic(new Value[] { b }, "LBBB;", "cMethod", new String[] { "Ljava/lang/String;" }, "V")));
    addStmt(nIf(niGt(nInt(100), nInt(0)), L1));
    addStmt(nReturnVoid());
    transform();
    Assert.assertTrue("p=a should inserted", s1.getPre() != L1);
}
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 37 with LabelStmt

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

the class Dex2IrAdapter method visitPackedSwitchStmt.

@Override
public void visitPackedSwitchStmt(Op op, int aA, int first_case, DexLabel[] labels) {
    LabelStmt[] lss = new LabelStmt[labels.length];
    for (int i = 0; i < labels.length; i++) {
        lss[i] = toLabelStmt(labels[i]);
    }
    LabelStmt d = new LabelStmt();
    x(nTableSwitch(locals[aA], first_case, lss, d));
    x(d);
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt)

Example 38 with LabelStmt

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

the class Dex2IrAdapter method toLabelStmt.

private LabelStmt toLabelStmt(DexLabel label) {
    LabelStmt ls = labelStmtMap.get(label);
    if (ls == null) {
        ls = new LabelStmt();
        labelStmtMap.put(label, ls);
    }
    return ls;
}
Also used : LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt)

Example 39 with LabelStmt

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

the class Dex2jar method doTranslate.

private void doTranslate(final Path dist) throws IOException {
    DexFileNode fileNode = new DexFileNode();
    try {
        reader.accept(fileNode, readerConfig | DexFileReader.IGNORE_READ_EXCEPTION);
    } catch (Exception ex) {
        exceptionHandler.handleFileException(ex);
    }
    ClassVisitorFactory cvf = new ClassVisitorFactory() {

        @Override
        public ClassVisitor create(final String name) {
            return new ClassVisitor(Opcodes.ASM4, new ClassWriter(ClassWriter.COMPUTE_MAXS)) {

                @Override
                public void visitEnd() {
                    super.visitEnd();
                    ClassWriter cw = (ClassWriter) super.cv;
                    byte[] data;
                    try {
                        // FIXME handle 'java.lang.RuntimeException: Method code too large!'
                        data = cw.toByteArray();
                    } catch (Exception ex) {
                        System.err.println(String.format("ASM fail to generate .class file: %s", name));
                        exceptionHandler.handleFileException(ex);
                        return;
                    }
                    try {
                        Path dist1 = dist.resolve(name + ".class");
                        Path parent = dist1.getParent();
                        if (parent != null && !Files.exists(parent)) {
                            Files.createDirectories(parent);
                        }
                        Files.write(dist1, data);
                    } catch (IOException e) {
                        e.printStackTrace(System.err);
                    }
                }
            };
        }
    };
    new ExDex2Asm(exceptionHandler) {

        public void convertCode(DexMethodNode methodNode, MethodVisitor mv) {
            if ((readerConfig & DexFileReader.SKIP_CODE) != 0 && methodNode.method.getName().equals("<clinit>")) {
                // also skip clinit
                return;
            }
            super.convertCode(methodNode, mv);
        }

        @Override
        public void optimize(IrMethod irMethod) {
            T_cleanLabel.transform(irMethod);
            if (0 != (v3Config & V3.TOPOLOGICAL_SORT)) {
            // T_topologicalSort.transform(irMethod);
            }
            T_deadCode.transform(irMethod);
            T_removeLocal.transform(irMethod);
            T_removeConst.transform(irMethod);
            T_zero.transform(irMethod);
            if (T_npe.transformReportChanged(irMethod)) {
                T_deadCode.transform(irMethod);
                T_removeLocal.transform(irMethod);
                T_removeConst.transform(irMethod);
            }
            T_new.transform(irMethod);
            T_fillArray.transform(irMethod);
            T_agg.transform(irMethod);
            T_multiArray.transform(irMethod);
            T_voidInvoke.transform(irMethod);
            if (0 != (v3Config & V3.PRINT_IR)) {
                int i = 0;
                for (Stmt p : irMethod.stmts) {
                    if (p.st == Stmt.ST.LABEL) {
                        LabelStmt labelStmt = (LabelStmt) p;
                        labelStmt.displayName = "L" + i++;
                    }
                }
                System.out.println(irMethod);
            }
            T_type.transform(irMethod);
            T_unssa.transform(irMethod);
            T_ir2jRegAssign.transform(irMethod);
            T_trimEx.transform(irMethod);
        }

        @Override
        public void ir2j(IrMethod irMethod, MethodVisitor mv) {
            new IR2JConverter(0 != (V3.OPTIMIZE_SYNCHRONIZED & v3Config)).convert(irMethod, mv);
        }
    }.convertDex(fileNode, cvf);
}
Also used : Path(java.nio.file.Path) LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) ClassVisitor(org.objectweb.asm.ClassVisitor) IOException(java.io.IOException) IrMethod(com.googlecode.dex2jar.ir.IrMethod) IOException(java.io.IOException) ClassWriter(org.objectweb.asm.ClassWriter) MethodVisitor(org.objectweb.asm.MethodVisitor) LabelStmt(com.googlecode.dex2jar.ir.stmt.LabelStmt) Stmt(com.googlecode.dex2jar.ir.stmt.Stmt) DexMethodNode(com.googlecode.d2j.node.DexMethodNode) DexFileNode(com.googlecode.d2j.node.DexFileNode) IR2JConverter(com.googlecode.d2j.converter.IR2JConverter)

Aggregations

LabelStmt (com.googlecode.dex2jar.ir.stmt.LabelStmt)39 Local (com.googlecode.dex2jar.ir.expr.Local)26 Stmt (com.googlecode.dex2jar.ir.stmt.Stmt)22 AssignStmt (com.googlecode.dex2jar.ir.stmt.AssignStmt)17 Test (org.junit.Test)14 Value (com.googlecode.dex2jar.ir.expr.Value)8 ArrayList (java.util.ArrayList)7 Trap (com.googlecode.dex2jar.ir.Trap)4 JumpStmt (com.googlecode.dex2jar.ir.stmt.JumpStmt)4 StmtList (com.googlecode.dex2jar.ir.stmt.StmtList)4 List (java.util.List)3 StmtTraveler (com.googlecode.dex2jar.ir.StmtTraveler)2 PhiExpr (com.googlecode.dex2jar.ir.expr.PhiExpr)2 Cfg (com.googlecode.dex2jar.ir.ts.Cfg)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 IrMethod (com.googlecode.dex2jar.ir.IrMethod)1 LabelAndLocalMapper (com.googlecode.dex2jar.ir.LabelAndLocalMapper)1