Alright so I'm trying to create a getter inside ClassA that returns a static field inside ClassB using Objectweb ASM. The classes I start out with look like this:
ClassA:
public class ClassA {
}
ClassB:
public class ClassB {
static int secret = 123;
}
And I'm trying to dump ClassA to look like this once decompiled:
public class ClassA {
public int getSecretInt(){
return ClassB.secret;
}
}
So far I have been able to return fields inside ClassA itself but I'm not sure how to go about returning static fields inside other classes.
What I can do: (this adds a method to ClassA that returns a variable inside its self)
MethodNode mn = new MethodNode(ACC_PUBLIC, getterName, "()" + fieldDescriptor, signature, null);
mn.instructions.add(new VarInsnNode(ALOAD, 0));
mn.instructions.add(new FieldInsnNode(isStatic ? GETSTATIC : GETFIELD, cn.name, fieldName, fieldDescriptor));
mn.instructions.add(new InsnNode(retInsn));
mn.visitMaxs(3, 3);
mn.visitEnd();
cn.methods.add(mn);
What i want to do is make this method I generate return a static value from ClassB.
basically make it:
return ClassB.secret;