use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class Instrumenter method instrumentGETXXXFieldAccesses.
private void instrumentGETXXXFieldAccesses(final ClassNode cn, final String internalClassName, final MethodNode methodNode) {
final InsnList instructions = methodNode.instructions;
AbstractInsnNode ins = null;
FieldInsnNode fieldIns = null;
for (int i = 0; i < instructions.size(); i++) {
ins = instructions.get(i);
if (ins instanceof FieldInsnNode) {
fieldIns = (FieldInsnNode) ins;
/*
* Is field referencing outermost instance? if yes, ignore it
* http://tns-www.lcs.mit.edu/manuals/java-1.1.1/guide/innerclasses/spec/innerclasses.doc10.html
*/
if (fieldIns.name.endsWith("$0")) {
continue;
}
final int opcode = ins.getOpcode();
if (opcode == Opcodes.GETFIELD || opcode == Opcodes.GETSTATIC) {
final InsnList il = new InsnList();
if (opcode == Opcodes.GETFIELD) {
Type fieldType = Type.getType(fieldIns.desc);
if (fieldType.getSize() == 1) {
instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP));
il.add(new InsnNode(Opcodes.SWAP));
} else if (fieldType.getSize() == 2) {
instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP));
// v
// GETFIELD
// v, w
il.add(new InsnNode(Opcodes.DUP2_X1));
// w, v, w
il.add(new InsnNode(Opcodes.POP2));
// w, v
// -> Call
// w
}
} else
il.add(new InsnNode(Opcodes.ACONST_NULL));
il.add(new LdcInsnNode(this.captureId));
il.add(new LdcInsnNode(fieldIns.owner));
il.add(new LdcInsnNode(fieldIns.name));
il.add(new LdcInsnNode(fieldIns.desc));
il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(org.evosuite.testcarver.capture.FieldRegistry.class), "notifyReadAccess", "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"));
i += il.size();
instructions.insert(fieldIns, il);
this.captureId++;
}
}
}
}
use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class Instrumenter method instrumentPUTXXXFieldAccesses.
private void instrumentPUTXXXFieldAccesses(final ClassNode cn, final String internalClassName, final MethodNode methodNode) {
final InsnList instructions = methodNode.instructions;
AbstractInsnNode ins = null;
FieldInsnNode fieldIns = null;
for (int i = 0; i < instructions.size(); i++) {
ins = instructions.get(i);
if (ins instanceof FieldInsnNode) {
fieldIns = (FieldInsnNode) ins;
/*
* Is field referencing outermost instance? if yes, ignore it
* http://tns-www.lcs.mit.edu/manuals/java-1.1.1/guide/innerclasses/spec/innerclasses.doc10.html
*/
if (fieldIns.name.endsWith("$0")) {
continue;
}
final int opcode = ins.getOpcode();
if (opcode == Opcodes.PUTFIELD || opcode == Opcodes.PUTSTATIC) {
// construction of
// Capturer.capture(final Object receiver, final String methodName, final Object[] methodParams)
// call
final InsnList il = new InsnList();
if (opcode == Opcodes.PUTFIELD) {
Type fieldType = Type.getType(fieldIns.desc);
if (fieldType.getSize() == 1) {
instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP2));
il.add(new InsnNode(Opcodes.POP));
} else if (fieldType.getSize() == 2) {
InsnList uglyList = new InsnList();
// v, w
uglyList.add(new InsnNode(Opcodes.DUP2_X1));
// w, v, w
uglyList.add(new InsnNode(Opcodes.POP2));
// w, v
uglyList.add(new InsnNode(Opcodes.DUP));
// w, v, v
uglyList.add(new InsnNode(Opcodes.DUP2_X2));
// v, v, w, v, v
uglyList.add(new InsnNode(Opcodes.POP2));
// v, v, w
instructions.insertBefore(fieldIns, uglyList);
// PUTFIELD
// v
}
} else
il.add(new InsnNode(Opcodes.ACONST_NULL));
il.add(new LdcInsnNode(this.captureId));
il.add(new LdcInsnNode(fieldIns.owner));
il.add(new LdcInsnNode(fieldIns.name));
il.add(new LdcInsnNode(fieldIns.desc));
il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(FieldRegistry.class), "notifyModification", "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"));
// PUTFIELDRegistry.notifyModification also adds corresponding GETFIELD capture instructions
this.captureId++;
i += il.size();
instructions.insert(fieldIns, il);
this.captureId++;
}
}
}
}
use of org.objectweb.asm.tree.FieldInsnNode in project Random-Things by lumien231.
the class ClassTransformer method patchMovementInput.
private byte[] patchMovementInput(byte[] basicClass) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
logger.log(Level.DEBUG, "Found MovementInputFromOptions Class: " + classNode.name);
MethodNode updatePlayerMoveState = null;
for (MethodNode mn : classNode.methods) {
if (mn.name.equals(MCPNames.method("func_78898_a"))) {
updatePlayerMoveState = mn;
break;
}
}
if (updatePlayerMoveState != null) {
logger.log(Level.DEBUG, " - Found updatePlayerMoveState");
for (int i = 0; i < updatePlayerMoveState.instructions.size(); i++) {
AbstractInsnNode ain = updatePlayerMoveState.instructions.get(i);
if (ain instanceof FieldInsnNode) {
FieldInsnNode fin = (FieldInsnNode) ain;
if (fin.name.equals(MCPNames.field("field_78899_d"))) {
logger.log(Level.DEBUG, " - Found insert point");
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 0));
toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "modifyInput", "(Lnet/minecraft/util/MovementInputFromOptions;)V", false));
updatePlayerMoveState.instructions.insert(fin, toInsert);
break;
}
}
}
}
CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
use of org.objectweb.asm.tree.FieldInsnNode in project spring-loaded by spring-projects.
the class TypeDiffComputer method sameFieldInsn.
private static boolean sameFieldInsn(AbstractInsnNode o, AbstractInsnNode n) {
FieldInsnNode oi = (FieldInsnNode) o;
if (!(n instanceof FieldInsnNode)) {
return false;
}
FieldInsnNode ni = (FieldInsnNode) n;
return oi.name.equals(ni.name) && oi.desc.equals(ni.desc) && oi.owner.equals(ni.owner);
}
use of org.objectweb.asm.tree.FieldInsnNode in project pinpoint by naver.
the class ASMClassNodeAdapter method addGetterMethod.
public void addGetterMethod(final String methodName, final ASMFieldNodeAdapter fieldNode) {
Objects.requireNonNull(methodName, "methodName");
Objects.requireNonNull(fieldNode, "fieldNode");
// no argument is ().
final String desc = "()" + fieldNode.getDesc();
final MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, methodName, desc, null, null);
final InsnList instructions = getInsnList(methodNode);
// load this.
instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
// get fieldNode.
instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldNode.getName(), fieldNode.getDesc()));
// return of type.
final Type type = Type.getType(fieldNode.getDesc());
instructions.add(new InsnNode(type.getOpcode(Opcodes.IRETURN)));
addMethodNode0(methodNode);
}
Aggregations