Java????ASM??????????Field value???????о?
???????????? ???????[ 2013/2/21 9:45:13 ] ????????
?????????????????????????????????????????Щ??final?????????????????????????λ?????????????????????????google???????ps??????????google?????????????????ASM??????????????????????????????????о?????????????????У?????????????????????????MethodVisitor??????????????????????????????????FieldNode????MethodNode??????????????class?????????????????????′???
/**
* @param args
* @author lihzh
* @date 2012-4-21 ????10:17:22
*/
public static void main(String[] args) {
try {
ClassReader reader = new ClassReader(
"cn.home.practice.bean.ForReadClass");
ClassNode cn = new ClassNode();
reader.accept(cn?? 0);
List<MethodNode> methodList = cn.methods;
for (MethodNode md : methodList) {
System.out.println(md.name);
System.out.println(md.access);
System.out.println(md.desc);
System.out.println(md.signature);
List<LocalVariableNode> lvNodeList = md.localVariables;
for (LocalVariableNode lvn : lvNodeList) {
System.out.println("Local name: " + lvn.name);
System.out.println("Local name: " + lvn.start.getLabel());
System.out.println("Local name: " + lvn.desc);
System.out.println("Local name: " + lvn.signature);
}
Iterator<AbstractInsnNode> instraIter = md.instructions.iterator();
while (instraIter.hasNext()) {
AbstractInsnNode abi = instraIter.next();
if (abi instanceof LdcInsnNode) {
LdcInsnNode ldcI = (LdcInsnNode) abi;
System.out.println("LDC node value: " + ldcI.cst);
}
}
}
MethodVisitor mv = cn.visitMethod(Opcodes.AALOAD?? "<init>"?? Type
.getType(String.class).toString()?? null?? null);
mv.visitFieldInsn(Opcodes.GETFIELD?? Type.getInternalName(String.class)?? "str"?? Type
.getType(String.class).toString());
System.out.println(cn.name);
List<FieldNode> fieldList = cn.fields;
for (FieldNode fieldNode : fieldList) {
System.out.println("Field name: " + fieldNode.name);
System.out.println("Field desc: " + fieldNode.desc);
System.out.println("Filed value: " + fieldNode.value);
System.out.println("Filed access: " + fieldNode.access);
if (fieldNode.visibleAnnotations != null) {
for (AnnotationNode anNode : fieldNode.visibleAnnotations) {
System.out.println(anNode.desc);
}
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
??????AbstractInsnNode?У?????????????????????????
????--------------------------------------------------------------------------------
?????????????????£??????????????Class??????????????????????????????????????????????????????????ó??????????????????????????????????ASM????????????????????????????????????
????????????????????????????????黹?????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11