Search in sources :

Example 11 with DexLabel

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

the class CodeWriter method visitTryCatch.

@Override
public void visitTryCatch(DexLabel start, DexLabel end, DexLabel[] handlers, String[] types) {
    CodeItem.TryItem tryItem = new CodeItem.TryItem();
    tryItem.start = getLabel(start);
    tryItem.end = getLabel(end);
    CodeItem.EncodedCatchHandler ech = new CodeItem.EncodedCatchHandler();
    tryItem.handler = ech;
    tryItems.add(tryItem);
    ech.addPairs = new ArrayList<>(types.length);
    for (int i = 0; i < types.length; i++) {
        String type = types[i];
        Label label = getLabel(handlers[i]);
        if (type == null) {
            ech.catchAll = label;
        } else {
            ech.addPairs.add(new CodeItem.EncodedCatchHandler.AddrPair(cp.uniqType(type), label));
        }
    }
}
Also used : DexLabel(com.googlecode.d2j.DexLabel)

Example 12 with DexLabel

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

the class CodeWriter method getLabel.

Label getLabel(DexLabel label) {
    Label mapped = labelMap.get(label);
    if (mapped == null) {
        mapped = new Label();
        labelMap.put(label, mapped);
    }
    return mapped;
}
Also used : DexLabel(com.googlecode.d2j.DexLabel)

Example 13 with DexLabel

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

the class EmptyTrapTest method m005_toJSONString.

@Test
public static void m005_toJSONString(DexClassVisitor cv) {
    DexMethodVisitor mv = cv.visitMethod(0, new Method("LJSResponseTest;", "toJSONString", new String[] {}, "Ljava/lang/String;"));
    if (mv != null) {
        DexCodeVisitor code = mv.visitCode();
        if (code != null) {
            code.visitRegister(6);
            DexLabel L8 = new DexLabel();
            DexLabel L9 = new DexLabel();
            DexLabel L10 = new DexLabel();
            DexLabel L0 = new DexLabel();
            DexLabel L1 = new DexLabel();
            DexLabel L2 = new DexLabel();
            code.visitTryCatch(L0, L1, new DexLabel[] { L2 }, new String[] { "Lorg/json/JSONException;" });
            DexLabel L3 = new DexLabel();
            DexLabel L4 = new DexLabel();
            code.visitTryCatch(L3, L4, new DexLabel[] { L2 }, new String[] { "Lorg/json/JSONException;" });
            DexLabel L5 = new DexLabel();
            DexLabel L6 = new DexLabel();
            code.visitTryCatch(L5, L6, new DexLabel[] { L2 }, new String[] { "Lorg/json/JSONException;" });
            code.visitConstStmt(CONST_STRING, 2, "response");
            code.visitConstStmt(CONST_STRING, 4, "");
            code.visitLabel(L0);
            code.visitFieldStmt(IGET, 2, 5, new Field("LJSResponseTest;", "className", "Ljava/lang/String;"));
            code.visitJumpStmt(IF_EQZ, 2, -1, L8);
            code.visitFieldStmt(IGET, 2, 5, new Field("LJSResponseTest;", "methodName", "Ljava/lang/String;"));
            code.visitJumpStmt(IF_NEZ, 2, -1, L10);
            code.visitLabel(L8);
            code.visitConstStmt(CONST_STRING, 2, "");
            code.visitStmt2R(MOVE, 2, 4);
            code.visitLabel(L9);
            code.visitStmt1R(RETURN_OBJECT, 2);
            code.visitLabel(L10);
            code.visitTypeStmt(NEW_INSTANCE, 1, -1, "Lorg/json/JSONObject;");
            code.visitMethodStmt(INVOKE_DIRECT, new int[] { 1 }, new Method("Lorg/json/JSONObject;", "<init>", new String[] {}, "V"));
            code.visitConstStmt(CONST_STRING, 2, "class");
            code.visitFieldStmt(IGET, 3, 5, new Field("LJSResponseTest;", "className", "Ljava/lang/String;"));
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 1, 2, 3 }, new Method("Lorg/json/JSONObject;", "put", new String[] { "Ljava/lang/String;", "Ljava/lang/Object;" }, "Lorg/json/JSONObject;"));
            code.visitConstStmt(CONST_STRING, 2, "call");
            code.visitFieldStmt(IGET, 3, 5, new Field("LJSResponseTest;", "methodName", "Ljava/lang/String;"));
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 1, 2, 3 }, new Method("Lorg/json/JSONObject;", "put", new String[] { "Ljava/lang/String;", "Ljava/lang/Object;" }, "Lorg/json/JSONObject;"));
            code.visitConstStmt(CONST_STRING, 2, "result");
            code.visitFieldStmt(IGET, 3, 5, new Field("LJSResponseTest;", "result", "I"));
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 1, 2, 3 }, new Method("Lorg/json/JSONObject;", "put", new String[] { "Ljava/lang/String;", "I" }, "Lorg/json/JSONObject;"));
            code.visitFieldStmt(IGET, 2, 5, new Field("LJSResponseTest;", "response", "Ljava/lang/Object;"));
            code.visitJumpStmt(IF_EQZ, 2, -1, L3);
            code.visitConstStmt(CONST_STRING, 2, "response");
            code.visitFieldStmt(IGET, 3, 5, new Field("LJSResponseTest;", "response", "Ljava/lang/Object;"));
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 1, 2, 3 }, new Method("Lorg/json/JSONObject;", "put", new String[] { "Ljava/lang/String;", "Ljava/lang/Object;" }, "Lorg/json/JSONObject;"));
            code.visitLabel(L1);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 1 }, new Method("Lorg/json/JSONObject;", "toString", new String[] {}, "Ljava/lang/String;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 2);
            code.visitJumpStmt(GOTO, -1, -1, L9);
            code.visitLabel(L3);
            code.visitFieldStmt(IGET, 2, 5, new Field("LJSResponseTest;", "dataResponse", "[B"));
            code.visitJumpStmt(IF_EQZ, 2, -1, L5);
            code.visitConstStmt(CONST_STRING, 2, "response");
            code.visitFieldStmt(IGET, 3, 5, new Field("LJSResponseTest;", "dataResponse", "[B"));
            code.visitMethodStmt(INVOKE_STATIC, new int[] { 3 }, new Method("LBase64;", "encode", new String[] { "[B" }, "Ljava/lang/String;"));
            code.visitStmt1R(MOVE_RESULT, 3);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 1, 2, 3 }, new Method("Lorg/json/JSONObject;", "put", new String[] { "Ljava/lang/String;", "Ljava/lang/Object;" }, "Lorg/json/JSONObject;"));
            code.visitLabel(L4);
            code.visitJumpStmt(GOTO, -1, -1, L1);
            code.visitLabel(L2);
            code.visitStmt1R(MOVE_EXCEPTION, 2);
            code.visitStmt2R(MOVE, 0, 2);
            code.visitConstStmt(CONST_STRING, 2, "MillennialMediaSDK");
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 0 }, new Method("Lorg/json/JSONException;", "getMessage", new String[] {}, "Ljava/lang/String;"));
            code.visitStmt1R(MOVE_RESULT, 3);
            code.visitMethodStmt(INVOKE_STATIC, new int[] { 2, 3 }, new Method("Landroid/util/Log;", "e", new String[] { "Ljava/lang/String;", "Ljava/lang/String;" }, "I"));
            code.visitConstStmt(CONST_STRING, 2, "");
            code.visitStmt2R(MOVE, 2, 4);
            code.visitJumpStmt(GOTO, -1, -1, L9);
            code.visitLabel(L5);
            code.visitConstStmt(CONST_STRING, 2, "");
            code.visitLabel(L6);
            code.visitStmt2R(MOVE, 2, 4);
            code.visitJumpStmt(GOTO, -1, -1, L9);
            code.visitEnd();
        }
        mv.visitEnd();
    }
}
Also used : Field(com.googlecode.d2j.Field) DexCodeVisitor(com.googlecode.d2j.visitors.DexCodeVisitor) DexLabel(com.googlecode.d2j.DexLabel) Method(com.googlecode.d2j.Method) DexMethodVisitor(com.googlecode.d2j.visitors.DexMethodVisitor) Test(org.junit.Test)

Example 14 with DexLabel

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

the class I101Test method a.

public static void a(DexClassVisitor cv) {
    DexMethodVisitor mv = cv.visitMethod(ACC_PUBLIC | ACC_STATIC, new Method("La;", "b", new String[] {}, "V"));
    DexCodeVisitor code = mv.visitCode();
    code.visitRegister(2);
    DexLabel L0 = new DexLabel();
    DexLabel L1 = new DexLabel();
    DexLabel L2 = new DexLabel();
    code.visitTryCatch(L0, L1, new DexLabel[] { L2 }, new String[] { "Lsome/Exception;" });
    code.visitLabel(L0);
    code.visitConstStmt(CONST_STRING, 0, "abc");
    code.visitLabel(L1);
    code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 0 }, new Method("Ljava/lang/String;", "toString", new String[] {}, "Ljava/lang/String;"));
    code.visitStmt0R(RETURN_VOID);
    code.visitLabel(L2);
    code.visitStmt1R(MOVE_EXCEPTION, 1);
    code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 1 }, new Method("Ljava/lang/String;", "toString", new String[] {}, "Ljava/lang/String;"));
    code.visitStmt0R(RETURN_VOID);
    code.visitEnd();
    mv.visitEnd();
}
Also used : DexCodeVisitor(com.googlecode.d2j.visitors.DexCodeVisitor) DexLabel(com.googlecode.d2j.DexLabel) Method(com.googlecode.d2j.Method) DexMethodVisitor(com.googlecode.d2j.visitors.DexMethodVisitor)

Example 15 with DexLabel

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

the class DexWeaver method genSwitchMethod.

private void genSwitchMethod(DexClassVisitor dcv, String typeNameDesc, String methodName, CB callback) {
    DexMethodVisitor dmv = dcv.visitMethod(DexConstants.ACC_PUBLIC, new Method(typeNameDesc, methodName, new String[0], "Ljava/lang/String;"));
    DexCodeVisitor code = dmv.visitCode();
    code.visitRegister(3);
    code.visitFieldStmt(Op.IGET, 0, 2, new Field(typeNameDesc, "idx", "I"));
    DexLabel[] labels = new DexLabel[callbacks.size()];
    Map<String, DexLabel> strMap = new TreeMap<>();
    for (int i = 0; i < labels.length; i++) {
        Callback cb = callbacks.get(i);
        String key = callback.getKey((Method) cb.target);
        DexLabel label = strMap.get(key);
        if (label == null) {
            label = new DexLabel();
            strMap.put(key, label);
        }
        labels[i] = label;
    }
    code.visitPackedSwitchStmt(Op.PACKED_SWITCH, 0, 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 (Map.Entry<String, DexLabel> e : strMap.entrySet()) {
        code.visitLabel(e.getValue());
        code.visitConstStmt(Op.CONST_STRING, 0, e.getKey());
        code.visitStmt1R(Op.RETURN_OBJECT, 0);
    }
    code.visitEnd();
    dmv.visitEnd();
}
Also used : Method(com.googlecode.d2j.Method) TreeMap(java.util.TreeMap) Field(com.googlecode.d2j.Field) DexCodeVisitor(com.googlecode.d2j.visitors.DexCodeVisitor) DexLabel(com.googlecode.d2j.DexLabel) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) DexMethodVisitor(com.googlecode.d2j.visitors.DexMethodVisitor)

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