Search in sources :

Example 21 with DexCodeVisitor

use of com.googlecode.d2j.visitors.DexCodeVisitor in project dex2jar by pxb1988.

the class ArrayTypeTest method merge1.

@Test
public static void merge1(DexClassVisitor cv) {
    // obj = array
    DexMethodVisitor mv = cv.visitMethod(ACC_PUBLIC | ACC_STATIC, new Method("La;", "b", new String[] {}, "V"));
    DexCodeVisitor code = mv.visitCode();
    DexLabel L0 = new DexLabel();
    DexLabel L1 = new DexLabel();
    code.visitRegister(3);
    code.visitConstStmt(CONST, 0, 0);
    code.visitJumpStmt(GOTO, -1, -1, L1);
    code.visitLabel(L0);
    code.visitStmt2R(ARRAY_LENGTH, 1, 0);
    code.visitConstStmt(CONST, 1, 0);
    code.visitStmt3R(AGET, 2, 0, 1);
    code.visitStmt0R(RETURN_VOID);
    code.visitLabel(L1);
    code.visitConstStmt(CONST, 1, 1);
    code.visitTypeStmt(NEW_ARRAY, 0, 1, "[Ljava/security/cert/X509Certificate;");
    code.visitJumpStmt(GOTO, -1, -1, L0);
    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) Test(org.junit.Test)

Example 22 with DexCodeVisitor

use of com.googlecode.d2j.visitors.DexCodeVisitor in project dex2jar by pxb1988.

the class AutoCastTest method strict.

/**
     * generate code, it works fine on JVM, but fails on Dalvik VM
     * 
     * <pre>
     * class a {
     *     private static short theField;
     * 
     *     public a() {
     *         theField = 0xffFFffFF + theField;// the 0xffFFffFF is not casted
     *     }
     * }
     * </pre>
     * 
     * @param cv
     */
public static void strict(DexClassVisitor cv) {
    Field f = new Field("La;", "theField", "S");
    DexMethodVisitor mv = cv.visitMethod(ACC_PUBLIC, new Method("La;", "<init>", new String[] {}, "V"));
    if (mv != null) {
        DexCodeVisitor code = mv.visitCode();
        if (code != null) {
            code.visitRegister(3);
            code.visitMethodStmt(INVOKE_SUPER, new int[] { 2 }, new Method("Ljava/lang/Object;", "<init>", new String[] {}, "V"));
            code.visitFieldStmt(SGET_BOOLEAN, 0, -1, f);
            code.visitConstStmt(CONST, 1, 0xffFFffFF);
            code.visitStmt3R(ADD_INT, 0, 0, 1);
            code.visitFieldStmt(SPUT_SHORT, 0, -1, f);
            code.visitStmt0R(RETURN_VOID);
            code.visitEnd();
        }
        mv.visitEnd();
    }
    DexFieldVisitor fv = cv.visitField(ACC_PRIVATE | ACC_STATIC, f, 0);
    if (fv != null) {
        fv.visitEnd();
    }
}
Also used : Field(com.googlecode.d2j.Field) DexFieldVisitor(com.googlecode.d2j.visitors.DexFieldVisitor) DexCodeVisitor(com.googlecode.d2j.visitors.DexCodeVisitor) Method(com.googlecode.d2j.Method) DexMethodVisitor(com.googlecode.d2j.visitors.DexMethodVisitor)

Example 23 with DexCodeVisitor

use of com.googlecode.d2j.visitors.DexCodeVisitor in project dex2jar by pxb1988.

the class FTPClient__parsePassiveModeReply method m003___parsePassiveModeReply.

@Test
public static void m003___parsePassiveModeReply(DexClassVisitor cv) {
    DexMethodVisitor mv = cv.visitMethod(ACC_PRIVATE, new Method("Lorg/apache/commons/net/ftp/FTPClient;", "__parsePassiveModeReply", new String[] { "Ljava/lang/String;" }, "V"));
    if (mv != null) {
        {
            DexAnnotationVisitor av00 = mv.visitAnnotation("Ldalvik/annotation/Throws;", Visibility.RUNTIME);
            if (av00 != null) {
                {
                    DexAnnotationVisitor av01 = av00.visitArray("value");
                    if (av01 != null) {
                        av01.visit(null, new DexType("Lorg/apache/commons/net/MalformedServerReplyException;"));
                        av01.visitEnd();
                    }
                }
                av00.visitEnd();
            }
        }
        DexCodeVisitor code = mv.visitCode();
        if (code != null) {
            code.visitRegister(11);
            DexLabel L0 = new DexLabel();
            DexLabel L1 = new DexLabel();
            DexLabel L2 = new DexLabel();
            code.visitTryCatch(L0, L1, new DexLabel[] { L2 }, new String[] { "Ljava/lang/NumberFormatException;" });
            // int: 0x0000002e float:0.000000
            code.visitConstStmt(CONST, 7, Integer.valueOf(46));
            code.visitConstStmt(CONST_STRING, 8, "Could not parse passive host information.\nServer Reply: ");
            code.visitFieldStmt(SGET_OBJECT, 5, -1, new Field("Lorg/apache/commons/net/ftp/FTPClient;", "__parms_pat", "Ljava/util/regex/Pattern;"));
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 5, 10 }, new Method("Ljava/util/regex/Pattern;", "matcher", new String[] { "Ljava/lang/CharSequence;" }, "Ljava/util/regex/Matcher;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 1);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 1 }, new Method("Ljava/util/regex/Matcher;", "find", new String[] {}, "Z"));
            code.visitStmt1R(MOVE_RESULT, 5);
            DexLabel L13 = new DexLabel();
            code.visitJumpStmt(IF_NEZ, 5, -1, L13);
            code.visitTypeStmt(NEW_INSTANCE, 5, -1, "Lorg/apache/commons/net/MalformedServerReplyException;");
            code.visitTypeStmt(NEW_INSTANCE, 6, -1, "Ljava/lang/StringBuilder;");
            code.visitMethodStmt(INVOKE_DIRECT, new int[] { 6 }, new Method("Ljava/lang/StringBuilder;", "<init>", new String[] {}, "V"));
            code.visitConstStmt(CONST_STRING, 7, "Could not parse passive host information.\nServer Reply: ");
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 6, 8 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "Ljava/lang/String;" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 6);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 6, 10 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "Ljava/lang/String;" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 6);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 6 }, new Method("Ljava/lang/StringBuilder;", "toString", new String[] {}, "Ljava/lang/String;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 6);
            code.visitMethodStmt(INVOKE_DIRECT, new int[] { 5, 6 }, new Method("Lorg/apache/commons/net/MalformedServerReplyException;", "<init>", new String[] { "Ljava/lang/String;" }, "V"));
            code.visitStmt1R(THROW, 5);
            code.visitLabel(L13);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 1 }, new Method("Ljava/util/regex/Matcher;", "group", new String[] {}, "Ljava/lang/String;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 10);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 1 }, new Method("Ljava/util/regex/Matcher;", "group", new String[] {}, "Ljava/lang/String;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 5);
            code.visitConstStmt(CONST_STRING, 6, ",");
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 5, 6 }, new Method("Ljava/lang/String;", "split", new String[] { "Ljava/lang/String;" }, "[Ljava/lang/String;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 4);
            code.visitTypeStmt(NEW_INSTANCE, 5, -1, "Ljava/lang/StringBuilder;");
            code.visitMethodStmt(INVOKE_DIRECT, new int[] { 5 }, new Method("Ljava/lang/StringBuilder;", "<init>", new String[] {}, "V"));
            // int: 0x00000000 float:0.000000
            code.visitConstStmt(CONST, 6, Integer.valueOf(0));
            code.visitStmt3R(AGET_OBJECT, 6, 4, 6);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 5, 6 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "Ljava/lang/String;" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 5);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 5, 7 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "C" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 5);
            // int: 0x00000001 float:0.000000
            code.visitConstStmt(CONST, 6, Integer.valueOf(1));
            code.visitStmt3R(AGET_OBJECT, 6, 4, 6);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 5, 6 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "Ljava/lang/String;" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 5);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 5, 7 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "C" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 5);
            // int: 0x00000002 float:0.000000
            code.visitConstStmt(CONST, 6, Integer.valueOf(2));
            code.visitStmt3R(AGET_OBJECT, 6, 4, 6);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 5, 6 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "Ljava/lang/String;" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT, 5);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 5, 7 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "C" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 5);
            // int: 0x00000003 float:0.000000
            code.visitConstStmt(CONST, 6, Integer.valueOf(3));
            code.visitStmt3R(AGET_OBJECT, 6, 4, 6);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 5, 6 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "Ljava/lang/String;" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT, 5);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 5 }, new Method("Ljava/lang/StringBuilder;", "toString", new String[] {}, "Ljava/lang/String;"));
            code.visitStmt1R(MOVE_RESULT, 5);
            code.visitFieldStmt(IPUT, 5, 9, new Field("Lorg/apache/commons/net/ftp/FTPClient;", "__passiveHost", "Ljava/lang/String;"));
            // int: 0x00000004 float:0.000000
            code.visitConstStmt(CONST, 5, Integer.valueOf(4));
            code.visitLabel(L0);
            code.visitStmt3R(AGET_OBJECT, 5, 4, 5);
            code.visitMethodStmt(INVOKE_STATIC, new int[] { 5 }, new Method("Ljava/lang/Integer;", "parseInt", new String[] { "Ljava/lang/String;" }, "I"));
            code.visitStmt1R(MOVE_RESULT, 2);
            // int: 0x00000005 float:0.000000
            code.visitConstStmt(CONST, 5, Integer.valueOf(5));
            code.visitStmt3R(AGET_OBJECT, 5, 4, 5);
            code.visitMethodStmt(INVOKE_STATIC, new int[] { 5 }, new Method("Ljava/lang/Integer;", "parseInt", new String[] { "Ljava/lang/String;" }, "I"));
            code.visitStmt1R(MOVE_RESULT, 3);
            code.visitStmt2R1N(Op.SHL_INT_LIT8, 5, 2, 8);
            code.visitStmt3R(OR_INT, 5, 5, 3);
            code.visitFieldStmt(IPUT, 5, 9, new Field("Lorg/apache/commons/net/ftp/FTPClient;", "__passivePort", "I"));
            code.visitLabel(L1);
            code.visitStmt0R(RETURN_VOID);
            code.visitLabel(L2);
            code.visitStmt1R(MOVE_EXCEPTION, 5);
            code.visitStmt2R(MOVE, 0, 5);
            code.visitTypeStmt(NEW_INSTANCE, 5, -1, "Lorg/apache/commons/net/MalformedServerReplyException;");
            code.visitTypeStmt(NEW_INSTANCE, 6, -1, "Ljava/lang/StringBuilder;");
            code.visitMethodStmt(INVOKE_DIRECT, new int[] { 6 }, new Method("Ljava/lang/StringBuilder;", "<init>", new String[] {}, "V"));
            code.visitConstStmt(CONST_STRING, 7, "Could not parse passive host information.\nServer Reply: ");
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 6, 8 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "Ljava/lang/String;" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 6);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 6, 10 }, new Method("Ljava/lang/StringBuilder;", "append", new String[] { "Ljava/lang/String;" }, "Ljava/lang/StringBuilder;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 6);
            code.visitMethodStmt(INVOKE_VIRTUAL, new int[] { 6 }, new Method("Ljava/lang/StringBuilder;", "toString", new String[] {}, "Ljava/lang/String;"));
            code.visitStmt1R(MOVE_RESULT_OBJECT, 6);
            code.visitMethodStmt(INVOKE_DIRECT, new int[] { 5, 6 }, new Method("Lorg/apache/commons/net/MalformedServerReplyException;", "<init>", new String[] { "Ljava/lang/String;" }, "V"));
            code.visitStmt1R(THROW, 5);
            code.visitEnd();
        }
        mv.visitEnd();
    }
}
Also used : DexAnnotationVisitor(com.googlecode.d2j.visitors.DexAnnotationVisitor) DexCodeVisitor(com.googlecode.d2j.visitors.DexCodeVisitor) DexMethodVisitor(com.googlecode.d2j.visitors.DexMethodVisitor) Test(org.junit.Test)

Aggregations

DexCodeVisitor (com.googlecode.d2j.visitors.DexCodeVisitor)23 DexMethodVisitor (com.googlecode.d2j.visitors.DexMethodVisitor)19 Method (com.googlecode.d2j.Method)18 Test (org.junit.Test)13 DexLabel (com.googlecode.d2j.DexLabel)9 Field (com.googlecode.d2j.Field)8 Op (com.googlecode.d2j.reader.Op)4 DexClassVisitor (com.googlecode.d2j.visitors.DexClassVisitor)4 HashMap (java.util.HashMap)4 DexMethodNode (com.googlecode.d2j.node.DexMethodNode)2 DexAnnotationVisitor (com.googlecode.d2j.visitors.DexAnnotationVisitor)2 DexFieldVisitor (com.googlecode.d2j.visitors.DexFieldVisitor)2 File (java.io.File)2 DexFileWriter (com.googlecode.d2j.dex.writer.DexFileWriter)1 DexCodeNode (com.googlecode.d2j.node.DexCodeNode)1 DexFieldNode (com.googlecode.d2j.node.DexFieldNode)1 DexStmtNode (com.googlecode.d2j.node.insn.DexStmtNode)1 DexFileReader (com.googlecode.d2j.reader.DexFileReader)1 ASMifierFileV (com.googlecode.d2j.util.ASMifierFileV)1 DexAnnotationAble (com.googlecode.d2j.visitors.DexAnnotationAble)1