Search in sources :

Example 1 with DexAnnotationVisitor

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

the class AsmfierTest method test.

@Test
public void test() {
    ASMifierFileV fv = new ASMifierFileV(new File("target/asmftest").toPath(), "a.b");
    DexClassVisitor cv = fv.visit(ACC_PUBLIC, "La/f;", "Ljava/lang/Object;", null);
    DexFieldVisitor f2v = cv.visitField(ACC_PUBLIC, new Field("La/f;", "abc", "I"), null);
    f2v.visitEnd();
    DexMethodVisitor mv = cv.visitMethod(ACC_PUBLIC | ACC_STATIC, new Method("La/f;", "zz", new String[0], "I"));
    DexAnnotationAble pv = mv.visitParameterAnnotation(2);
    DexAnnotationVisitor dav = pv.visitAnnotation("Leeeff;", Visibility.BUILD);
    dav.visitEnd();
    DexCodeVisitor dcv = mv.visitCode();
    dcv.visitConstStmt(Op.FILL_ARRAY_DATA, 0, new int[] { 1, 2, 3 });
    dcv.visitStmt0R(Op.RETURN_VOID);
    dcv.visitEnd();
    mv.visitEnd();
    cv.visitEnd();
    fv.visitEnd();
}
Also used : Field(com.googlecode.d2j.Field) ASMifierFileV(com.googlecode.d2j.util.ASMifierFileV) DexAnnotationAble(com.googlecode.d2j.visitors.DexAnnotationAble) DexFieldVisitor(com.googlecode.d2j.visitors.DexFieldVisitor) DexAnnotationVisitor(com.googlecode.d2j.visitors.DexAnnotationVisitor) DexCodeVisitor(com.googlecode.d2j.visitors.DexCodeVisitor) Method(com.googlecode.d2j.Method) DexClassVisitor(com.googlecode.d2j.visitors.DexClassVisitor) File(java.io.File) DexMethodVisitor(com.googlecode.d2j.visitors.DexMethodVisitor) Test(org.junit.Test)

Example 2 with DexAnnotationVisitor

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

the class DexAnnotationNode method acceptAnnotationItem.

public static void acceptAnnotationItem(DexAnnotationVisitor dav, String name, Object o) {
    if (o instanceof Object[]) {
        DexAnnotationVisitor arrayVisitor = dav.visitArray(name);
        if (arrayVisitor != null) {
            Object[] array = (Object[]) o;
            for (Object e : array) {
                acceptAnnotationItem(arrayVisitor, null, e);
            }
            arrayVisitor.visitEnd();
        }
    } else if (o instanceof DexAnnotationNode) {
        DexAnnotationNode ann = (DexAnnotationNode) o;
        DexAnnotationVisitor av = dav.visitAnnotation(name, ann.type);
        if (av != null) {
            for (DexAnnotationNode.Item item : ann.items) {
                acceptAnnotationItem(av, item.name, item.value);
            }
            av.visitEnd();
        }
    } else if (o instanceof Field) {
        Field f = (Field) o;
        dav.visitEnum(name, f.getType(), f.getName());
    } else {
        dav.visit(name, o);
    }
}
Also used : Field(com.googlecode.d2j.Field) DexAnnotationVisitor(com.googlecode.d2j.visitors.DexAnnotationVisitor)

Example 3 with DexAnnotationVisitor

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

the class Utils method doAccept.

public static void doAccept(DexAnnotationVisitor dexAnnotationVisitor, String k, Object value) {
    if (value instanceof ArrayList) {
        DexAnnotationVisitor a = dexAnnotationVisitor.visitArray(k);
        for (Object o : (ArrayList) value) {
            doAccept(a, null, o);
        }
        a.visitEnd();
    } else if (value instanceof Ann) {
        Ann ann = (Ann) value;
        DexAnnotationVisitor a = dexAnnotationVisitor.visitAnnotation(k, ann.name);
        for (Map.Entry<String, Object> e : ann.elements) {
            doAccept(a, e.getKey(), e.getValue());
        }
        a.visitEnd();
    } else if (value instanceof Field) {
        Field f = (Field) value;
        dexAnnotationVisitor.visitEnum(k, f.getOwner(), f.getName());
    } else {
        dexAnnotationVisitor.visit(k, value);
    }
}
Also used : Field(com.googlecode.d2j.Field) DexAnnotationVisitor(com.googlecode.d2j.visitors.DexAnnotationVisitor) ArrayList(java.util.ArrayList)

Example 4 with DexAnnotationVisitor

use of com.googlecode.d2j.visitors.DexAnnotationVisitor 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)

Example 5 with DexAnnotationVisitor

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

the class AnnotationWriter method visit.

// int,int long
public void visit(String name, Object value) {
    if (value instanceof Object[]) {
        DexAnnotationVisitor s = visitArray(name);
        if (s != null) {
            for (Object v : (Object[]) value) {
                s.visit(null, v);
            }
            s.visitEnd();
        }
    } else {
        AnnotationElement ae = newAnnotationElement(name);
        ae.value = EncodedValue.wrap(cp.wrapEncodedItem(value));
    }
}
Also used : AnnotationElement(com.googlecode.d2j.dex.writer.ev.EncodedAnnotation.AnnotationElement) DexAnnotationVisitor(com.googlecode.d2j.visitors.DexAnnotationVisitor)

Aggregations

DexAnnotationVisitor (com.googlecode.d2j.visitors.DexAnnotationVisitor)5 Field (com.googlecode.d2j.Field)3 DexCodeVisitor (com.googlecode.d2j.visitors.DexCodeVisitor)2 DexMethodVisitor (com.googlecode.d2j.visitors.DexMethodVisitor)2 Test (org.junit.Test)2 Method (com.googlecode.d2j.Method)1 AnnotationElement (com.googlecode.d2j.dex.writer.ev.EncodedAnnotation.AnnotationElement)1 ASMifierFileV (com.googlecode.d2j.util.ASMifierFileV)1 DexAnnotationAble (com.googlecode.d2j.visitors.DexAnnotationAble)1 DexClassVisitor (com.googlecode.d2j.visitors.DexClassVisitor)1 DexFieldVisitor (com.googlecode.d2j.visitors.DexFieldVisitor)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1