Search in sources :

Example 76 with AbstractInsnNode

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()");
                    }
                }
            }
        }
    }
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 77 with AbstractInsnNode

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());
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) Test(org.junit.Test)

Example 78 with AbstractInsnNode

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());
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Label(org.objectweb.asm.Label) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) Test(org.junit.Test)

Example 79 with AbstractInsnNode

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());
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) Test(org.junit.Test)

Example 80 with AbstractInsnNode

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());
}
Also used : AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Label(org.objectweb.asm.Label) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) Test(org.junit.Test)

Aggregations

AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)185 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)68 MethodNode (org.objectweb.asm.tree.MethodNode)54 InsnList (org.objectweb.asm.tree.InsnList)53 InsnNode (org.objectweb.asm.tree.InsnNode)41 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)38 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)37 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)35 ClassNode (org.objectweb.asm.tree.ClassNode)33 LabelNode (org.objectweb.asm.tree.LabelNode)27 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)26 Test (org.junit.Test)25 Label (org.objectweb.asm.Label)25 ClassReader (org.objectweb.asm.ClassReader)23 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)23 HashSet (java.util.HashSet)16 Type (org.objectweb.asm.Type)15 Frame (org.objectweb.asm.tree.analysis.Frame)13 ArrayList (java.util.ArrayList)12 TryCatchBlockNode (org.objectweb.asm.tree.TryCatchBlockNode)11