Search in sources :

Example 6 with DexFileWriter

use of com.googlecode.d2j.dex.writer.DexFileWriter in project dex2jar by pxb1988.

the class AppWriterTest method test3.

@Test
public void test3() {
    DexFileWriter w = new DexFileWriter();
    DexClassVisitor cv = w.visit(0x1, "La/c;", null, new String[] { "Ljava/lang/Comparable;" });
    cv.visitSource("c.java");
    cv.visitAnnotation("LAnn;", Visibility.SYSTEM).visitEnd();
    DexFieldVisitor fv = cv.visitField(ACC_PUBLIC | ACC_STATIC, new Field("La/c;", "a", "I"), 55);
    fv.visitAnnotation("LE;", Visibility.RUNTIME).visitEnd();
    fv.visitEnd();
    DexMethodVisitor mv = cv.visitMethod(ACC_STATIC, new Method("La/c;", "bb", new String[] { "I" }, "V"));
    mv.visitAnnotation("Laaa;", Visibility.RUNTIME).visitEnd();
    DexAnnotationVisitor dav = mv.visitParameterAnnotation(0).visitAnnotation("Laaa;", Visibility.RUNTIME);
    dav.visit("abc", true);
    DexAnnotationVisitor dav2 = dav.visitArray("efg");
    dav2.visit("", "123");
    dav2.visit("", "456");
    dav2.visitEnd();
    dav.visitEnd();
    DexCodeVisitor code = mv.visitCode();
    code.visitRegister(2);
    code.visitStmt0R(Op.RETURN_VOID);
    code.visitEnd();
    mv.visitEnd();
    cv.visitEnd();
    w.visitEnd();
    w.toByteArray();
}
Also used : Field(com.googlecode.d2j.Field) DexFileWriter(com.googlecode.d2j.dex.writer.DexFileWriter) Method(com.googlecode.d2j.Method) Test(org.junit.Test)

Aggregations

DexFileWriter (com.googlecode.d2j.dex.writer.DexFileWriter)6 File (java.io.File)3 Test (org.junit.Test)3 Method (com.googlecode.d2j.Method)2 DexFileReader (com.googlecode.d2j.reader.DexFileReader)2 DexFileVisitor (com.googlecode.d2j.visitors.DexFileVisitor)2 Field (com.googlecode.d2j.Field)1 Op (com.googlecode.d2j.reader.Op)1 DexClassVisitor (com.googlecode.d2j.visitors.DexClassVisitor)1 DexCodeVisitor (com.googlecode.d2j.visitors.DexCodeVisitor)1 DexMethodVisitor (com.googlecode.d2j.visitors.DexMethodVisitor)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1