Search in sources :

Example 11 with Field

use of com.googlecode.d2j.Field 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 12 with Field

use of com.googlecode.d2j.Field 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

Field (com.googlecode.d2j.Field)12 Method (com.googlecode.d2j.Method)9 DexCodeVisitor (com.googlecode.d2j.visitors.DexCodeVisitor)8 DexMethodVisitor (com.googlecode.d2j.visitors.DexMethodVisitor)7 DexLabel (com.googlecode.d2j.DexLabel)6 Test (org.junit.Test)5 DexAnnotationVisitor (com.googlecode.d2j.visitors.DexAnnotationVisitor)3 Op (com.googlecode.d2j.reader.Op)2 DexClassVisitor (com.googlecode.d2j.visitors.DexClassVisitor)2 DexFieldVisitor (com.googlecode.d2j.visitors.DexFieldVisitor)2 HashMap (java.util.HashMap)2 DexType (com.googlecode.d2j.DexType)1 DexFileWriter (com.googlecode.d2j.dex.writer.DexFileWriter)1 DexFieldNode (com.googlecode.d2j.node.DexFieldNode)1 DexMethodNode (com.googlecode.d2j.node.DexMethodNode)1 DvmInterpreter (com.googlecode.d2j.node.analysis.DvmInterpreter)1 ASMifierFileV (com.googlecode.d2j.util.ASMifierFileV)1 DexAnnotationAble (com.googlecode.d2j.visitors.DexAnnotationAble)1 IrMethod (com.googlecode.dex2jar.ir.IrMethod)1 Local (com.googlecode.dex2jar.ir.expr.Local)1