Search in sources :

Example 1 with DexFieldVisitor

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

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

the class DexFieldNode method accept.

public void accept(DexClassVisitor dcv) {
    DexFieldVisitor fv = dcv.visitField(access, field, cst);
    if (fv != null) {
        accept(fv);
        fv.visitEnd();
    }
}
Also used : DexFieldVisitor(com.googlecode.d2j.visitors.DexFieldVisitor)

Example 3 with DexFieldVisitor

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

Aggregations

DexFieldVisitor (com.googlecode.d2j.visitors.DexFieldVisitor)3 Field (com.googlecode.d2j.Field)2 Method (com.googlecode.d2j.Method)2 DexCodeVisitor (com.googlecode.d2j.visitors.DexCodeVisitor)2 DexMethodVisitor (com.googlecode.d2j.visitors.DexMethodVisitor)2 ASMifierFileV (com.googlecode.d2j.util.ASMifierFileV)1 DexAnnotationAble (com.googlecode.d2j.visitors.DexAnnotationAble)1 DexAnnotationVisitor (com.googlecode.d2j.visitors.DexAnnotationVisitor)1 DexClassVisitor (com.googlecode.d2j.visitors.DexClassVisitor)1 File (java.io.File)1 Test (org.junit.Test)1