asm 设置读取字段值,asm读取字段值,获得静态字段的值:mv.
分享于 点击 28532 次 点评:225
asm 设置读取字段值,asm读取字段值,获得静态字段的值:mv.
获得静态字段的值:
mv.visitFieldInsn(GETSTATIC, "sample/FieldReadWrite", // classname "len", //static field name "I"); // the type of field.//return a value in the stack
给静态字段赋值:
mv.visitIntInsn(BIPUSH, 10); // put a constant integer onto the stackmv.visitFieldInsn(PUTSTATIC, "sample/FieldReadWrite", //classname "len", // field name "I"); // field type
获得实例字段的值:
mv.visitVarInsn(ALOAD, 0); //from object onto the stackmv.visitFieldInsn(GETFIELD, "sample/FieldReadWrite", //the type of object "name", // field name "Ljava/lang/String;" // field type);mv.visitInsn(ARETURN); // pop the top value of the stack and return.
设置实例字段的值
mv.visitVarInsn(ALOAD, 0);//push the object mv.visitVarInsn(ALOAD, 1);//push the value from which assign to the fieldmv.visitFieldInsn(PUTFIELD, "sample/FieldReadWrite", // the class"name", // the field name"Ljava/lang/String;"//the field type);
用户点评