Search in sources :

Example 1 with DexLabel

use of com.googlecode.d2j.DexLabel in project dex2jar by pxb1988.

the class BaksmaliCodeDumper method visitSparseSwitchStmt.

@Override
public void visitSparseSwitchStmt(Op op, int ra, int[] cases, DexLabel[] labels) {
    DexLabel dx = new DexLabel();
    dx.displayName = "L" + nextLabelNumber++;
    usedLabel.add(dx);
    out.s(op.displayName + " " + reg(ra) + ", " + xLabel(dx));
    appendLast.add(new AbstractMap.SimpleEntry<DexLabel, Object>(dx, new SparseSwitchStmt(cases, labels)));
}
Also used : DexLabel(com.googlecode.d2j.DexLabel)

Example 2 with DexLabel

use of com.googlecode.d2j.DexLabel in project dex2jar by pxb1988.

the class BaksmaliCodeDumper method visitPackedSwitchStmt.

@Override
public void visitPackedSwitchStmt(Op op, int ra, int first_case, DexLabel[] labels) {
    DexLabel dx = new DexLabel();
    dx.displayName = "L" + nextLabelNumber++;
    usedLabel.add(dx);
    out.s(op.displayName + " " + reg(ra) + ", " + xLabel(dx));
    appendLast.add(new AbstractMap.SimpleEntry<DexLabel, Object>(dx, new PackedSwitchStmt(first_case, labels)));
}
Also used : DexLabel(com.googlecode.d2j.DexLabel)

Example 3 with DexLabel

use of com.googlecode.d2j.DexLabel in project dex2jar by pxb1988.

the class BaksmaliCodeDumper method visitFillArrayDataStmt.

@Override
public void visitFillArrayDataStmt(Op op, int ra, Object array) {
    DexLabel dx = new DexLabel();
    dx.displayName = "L" + nextLabelNumber++;
    usedLabel.add(dx);
    out.s("%s %s, %s", op.displayName, reg(ra), xLabel(dx));
    appendLast.add(new AbstractMap.SimpleEntry<DexLabel, Object>(dx, array));
}
Also used : DexLabel(com.googlecode.d2j.DexLabel)

Example 4 with DexLabel

use of com.googlecode.d2j.DexLabel in project dex2jar by pxb1988.

the class DexWeaver method buildInvocationClz.

public String buildInvocationClz(DexFileVisitor dfv) {
    String typeName = getCurrentInvocationName();
    String typeNameDesc = "L" + typeName + ";";
    DexClassVisitor dcv = dfv.visit(DexConstants.ACC_PUBLIC, typeNameDesc, "Ljava/lang/Object;", new String[] { invocationInterfaceDesc });
    dcv.visitField(DexConstants.ACC_PRIVATE | DexConstants.ACC_FINAL, new Field(typeNameDesc, "thiz", "Ljava/lang/Object;"), null).visitEnd();
    dcv.visitField(DexConstants.ACC_PRIVATE | DexConstants.ACC_FINAL, new Field(typeNameDesc, "args", "[Ljava/lang/Object;"), null).visitEnd();
    dcv.visitField(DexConstants.ACC_PRIVATE | DexConstants.ACC_FINAL, new Field(typeNameDesc, "idx", "I"), null).visitEnd();
    {
        DexMethodVisitor mv = dcv.visitMethod(DexConstants.ACC_PUBLIC | DexConstants.ACC_CONSTRUCTOR, new Method(typeNameDesc, "<init>", new String[] { "Ljava/lang/Object;", "[Ljava/lang/Object;", "I" }, "V"));
        DexCodeVisitor codeVisitor = mv.visitCode();
        codeVisitor.visitRegister(4);
        codeVisitor.visitFieldStmt(Op.IPUT_OBJECT, 1, 0, new Field(typeNameDesc, "thiz", "Ljava/lang/Object;"));
        codeVisitor.visitFieldStmt(Op.IPUT_OBJECT, 2, 0, new Field(typeNameDesc, "args", "[Ljava/lang/Object;"));
        codeVisitor.visitFieldStmt(Op.IPUT, 3, 0, new Field(typeNameDesc, "idx", "I"));
        codeVisitor.visitStmt0R(Op.RETURN_VOID);
        codeVisitor.visitEnd();
        mv.visitEnd();
    }
    {
        genSwitchMethod(dcv, typeNameDesc, "getMethodOwner", new CB() {

            @Override
            public String getKey(Method mtd) {
                return toInternal(mtd.getOwner());
            }
        });
        genSwitchMethod(dcv, typeNameDesc, "getMethodName", new CB() {

            @Override
            public String getKey(Method mtd) {
                return mtd.getName();
            }
        });
        genSwitchMethod(dcv, typeNameDesc, "getMethodDesc", new CB() {

            @Override
            public String getKey(Method mtd) {
                return mtd.getDesc();
            }
        });
    }
    {
        DexMethodVisitor mv = dcv.visitMethod(DexConstants.ACC_PUBLIC, new Method(typeNameDesc, "getArguments", new String[0], "[Ljava/lang/Object;"));
        DexCodeVisitor code = mv.visitCode();
        code.visitRegister(2);
        code.visitFieldStmt(Op.IGET, 0, 1, new Field(typeNameDesc, "args", "[Ljava/lang/Object;"));
        code.visitStmt1R(Op.RETURN_OBJECT, 0);
        code.visitEnd();
        mv.visitEnd();
    }
    {
        DexMethodVisitor mv = dcv.visitMethod(DexConstants.ACC_PUBLIC, new Method(typeNameDesc, "getThis", new String[0], "Ljava/lang/Object;"));
        DexCodeVisitor code = mv.visitCode();
        code.visitRegister(2);
        code.visitFieldStmt(Op.IGET, 0, 1, new Field(typeNameDesc, "thiz", "Ljava/lang/Object;"));
        code.visitStmt1R(Op.RETURN_OBJECT, 0);
        code.visitEnd();
        mv.visitEnd();
    }
    {
        DexMethodVisitor mv = dcv.visitMethod(DexConstants.ACC_PUBLIC, new Method(typeNameDesc, "proceed", new String[0], "Ljava/lang/Object;"));
        DexCodeVisitor code = mv.visitCode();
        code.visitRegister(4);
        code.visitFieldStmt(Op.IGET, 0, 3, new Field(typeNameDesc, "thiz", "Ljava/lang/Object;"));
        code.visitFieldStmt(Op.IGET, 1, 3, new Field(typeNameDesc, "args", "[Ljava/lang/Object;"));
        code.visitFieldStmt(Op.IGET, 2, 3, new Field(typeNameDesc, "idx", "I"));
        DexLabel[] labels = new DexLabel[callbacks.size()];
        for (int i = 0; i < labels.length; i++) {
            labels[i] = new DexLabel();
        }
        code.visitPackedSwitchStmt(Op.PACKED_SWITCH, 2, 0, labels);
        code.visitTypeStmt(Op.NEW_INSTANCE, 0, 0, "Ljava/lang/RuntimeException;");
        code.visitConstStmt(Op.CONST_STRING, 1, "invalid idx");
        code.visitMethodStmt(Op.INVOKE_DIRECT, new int[] { 0, 1 }, new Method("Ljava/lang/RuntimeException;", "<init>", new String[] { "Ljava/lang/String;" }, "V"));
        code.visitStmt1R(Op.THROW, 0);
        for (int i = 0; i < labels.length; i++) {
            code.visitLabel(labels[i]);
            Callback callback = callbacks.get(i);
            Method mCallback = (Method) callback.callback;
            if (callback.isStatic) {
                code.visitMethodStmt(Op.INVOKE_STATIC, new int[] { 1 }, mCallback);
            } else if (callback.isSpecial) {
                code.visitTypeStmt(Op.CHECK_CAST, 0, -1, mCallback.getOwner());
                code.visitMethodStmt(Op.INVOKE_VIRTUAL, new int[] { 0, 1 }, mCallback);
            } else {
                code.visitMethodStmt(Op.INVOKE_STATIC, new int[] { 0, 1 }, mCallback);
            }
            code.visitStmt1R(Op.MOVE_RESULT_OBJECT, 0);
            code.visitStmt1R(Op.RETURN_OBJECT, 0);
        }
        code.visitEnd();
        mv.visitEnd();
    }
    dcv.visitEnd();
    return typeName;
}
Also used : Field(com.googlecode.d2j.Field) DexCodeVisitor(com.googlecode.d2j.visitors.DexCodeVisitor) DexLabel(com.googlecode.d2j.DexLabel) Method(com.googlecode.d2j.Method) DexClassVisitor(com.googlecode.d2j.visitors.DexClassVisitor) DexMethodVisitor(com.googlecode.d2j.visitors.DexMethodVisitor)

Example 5 with DexLabel

use of com.googlecode.d2j.DexLabel in project dex2jar by pxb1988.

the class ASMifierCodeV method v.

public String v(DexLabel[] labels) {
    StringBuilder sb = new StringBuilder("new DexLabel[]{");
    boolean first = true;
    for (DexLabel dexLabel : labels) {
        if (first) {
            first = false;
        } else {
            sb.append(",");
        }
        sb.append(v(dexLabel));
    }
    return sb.append("}").toString();
}
Also used : DexLabel(com.googlecode.d2j.DexLabel)

Aggregations

DexLabel (com.googlecode.d2j.DexLabel)21 Method (com.googlecode.d2j.Method)10 DexCodeVisitor (com.googlecode.d2j.visitors.DexCodeVisitor)9 DexMethodVisitor (com.googlecode.d2j.visitors.DexMethodVisitor)9 Field (com.googlecode.d2j.Field)6 Test (org.junit.Test)6 Op (com.googlecode.d2j.reader.Op)3 TryCatchNode (com.googlecode.d2j.node.TryCatchNode)2 Local (com.googlecode.dex2jar.ir.expr.Local)2 ByteBuffer (java.nio.ByteBuffer)2 DexType (com.googlecode.d2j.DexType)1 DvmInterpreter (com.googlecode.d2j.node.analysis.DvmInterpreter)1 DexClassVisitor (com.googlecode.d2j.visitors.DexClassVisitor)1 IrMethod (com.googlecode.dex2jar.ir.IrMethod)1 Trap (com.googlecode.dex2jar.ir.Trap)1 Value (com.googlecode.dex2jar.ir.expr.Value)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1