use of org.objectweb.asm.tree.AbstractInsnNode in project malmo by Microsoft.
the class OverclockingClassTransformer method overclockRenderer.
private static void overclockRenderer(ClassNode node, boolean isObfuscated) {
// We're attempting to turn this line from Minecraft.runGameLoop:
// this.updateDisplay();
// into this:
// TimeHelper.updateDisplay();
// TimeHelper's method then decides whether or not to pass the call on to Minecraft.updateDisplay().
final String methodName = isObfuscated ? "as" : "runGameLoop";
// No params, returns void.
final String methodDescriptor = "()V";
System.out.println("MALMO: Found Minecraft, attempting to transform it");
for (MethodNode method : node.methods) {
if (method.name.equals(methodName) && method.desc.equals(methodDescriptor)) {
System.out.println("MALMO: Found Minecraft.runGameLoop() method, attempting to transform it");
for (AbstractInsnNode instruction : method.instructions.toArray()) {
if (instruction.getOpcode() == Opcodes.INVOKEVIRTUAL) {
MethodInsnNode visitMethodNode = (MethodInsnNode) instruction;
if (visitMethodNode.name.equals(isObfuscated ? "h" : "updateDisplay")) {
visitMethodNode.owner = "com/microsoft/Malmo/Utils/TimeHelper";
if (isObfuscated) {
visitMethodNode.name = "updateDisplay";
}
visitMethodNode.setOpcode(Opcodes.INVOKESTATIC);
// ALOAD 0 not needed for static invocation.
method.instructions.remove(visitMethodNode.getPrevious());
System.out.println("MALMO: Hooked into call to Minecraft.updateDisplay()");
}
}
}
}
}
}
use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.
the class InstructionsBuilderTest method subsequent_instructions_should_not_be_linked_when_noSuccessor_was_called.
@Test
public void subsequent_instructions_should_not_be_linked_when_noSuccessor_was_called() {
InsnNode i1 = new InsnNode(Opcodes.NOP);
builder.addInstruction(i1);
builder.noSuccessor();
InsnNode i2 = new InsnNode(Opcodes.NOP);
builder.addInstruction(i2);
// mark i2 as covered
builder.addProbe(1, 0);
// coverage should not be propagated to i1
Map<AbstractInsnNode, Instruction> map = builder.getInstructions();
assertEquals(CounterImpl.COUNTER_1_0, map.get(i1).getInstructionCounter());
}
use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.
the class InstructionsBuilderTest method subsequent_instructions_should_be_linked_after_label_marked_as_successor.
@Test
public void subsequent_instructions_should_be_linked_after_label_marked_as_successor() {
InsnNode i1 = new InsnNode(Opcodes.NOP);
builder.addInstruction(i1);
Label l = new Label();
LabelInfo.setSuccessor(l);
builder.addLabel(l);
InsnNode i2 = new InsnNode(Opcodes.NOP);
builder.addInstruction(i2);
// mark i2 as covered
builder.addProbe(1, 0);
// coverage should be propagated to i1
Map<AbstractInsnNode, Instruction> map = builder.getInstructions();
assertEquals(CounterImpl.COUNTER_0_1, map.get(i1).getInstructionCounter());
}
use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.
the class InstructionsBuilderTest method null_probearray_should_not_mark_instruction_as_covered.
@Test
public void null_probearray_should_not_mark_instruction_as_covered() {
builder = new InstructionsBuilder(null);
InsnNode i1 = new InsnNode(Opcodes.NOP);
builder.addInstruction(i1);
builder.addProbe(5, 0);
Map<AbstractInsnNode, Instruction> map = builder.getInstructions();
assertEquals(CounterImpl.COUNTER_1_0, map.get(i1).getInstructionCounter());
}
use of org.objectweb.asm.tree.AbstractInsnNode in project jacoco by jacoco.
the class InstructionsBuilderTest method subsequent_instructions_should_not_be_linked_after_label_not_marked_as_successor.
@Test
public void subsequent_instructions_should_not_be_linked_after_label_not_marked_as_successor() {
InsnNode i1 = new InsnNode(Opcodes.NOP);
builder.addInstruction(i1);
builder.addLabel(new Label());
InsnNode i2 = new InsnNode(Opcodes.NOP);
builder.addInstruction(i2);
// mark i2 as covered
builder.addProbe(1, 0);
// coverage should not be propagated to i1
Map<AbstractInsnNode, Instruction> map = builder.getInstructions();
assertEquals(CounterImpl.COUNTER_1_0, map.get(i1).getInstructionCounter());
}
Aggregations