Search in sources :

Example 11 with MethodInsnNode

use of org.objectweb.asm.tree.MethodInsnNode in project pinpoint by naver.

the class ASMMethodVariables method invokeConstructor.

void invokeConstructor(final InsnList instructions, final Type type, final Method method) {
    String owner = type.getSort() == Type.ARRAY ? type.getDescriptor() : type.getInternalName();
    instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, owner, method.getName(), method.getDescriptor(), false));
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Example 12 with MethodInsnNode

use of org.objectweb.asm.tree.MethodInsnNode in project pinpoint by naver.

the class ASMMethodVariables method initInterceptorVar.

private void initInterceptorVar(final InsnList instructions, final int interceptorId) {
    assertInitializedInterceptorLocalVariables();
    this.interceptorVarIndex = addInterceptorLocalVariable("_$PINPOINT$_interceptor", "Lcom/navercorp/pinpoint/bootstrap/interceptor/Interceptor;");
    push(instructions, interceptorId);
    instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(InterceptorRegistry.class), "getInterceptor", "(I)" + Type.getDescriptor(Interceptor.class), false));
    storeVar(instructions, this.interceptorVarIndex);
    this.resultVarIndex = addInterceptorLocalVariable("_$PINPOINT$_result", "Ljava/lang/Object;");
    loadNull(instructions);
    storeVar(instructions, this.resultVarIndex);
    this.throwableVarIndex = addInterceptorLocalVariable("_$PINPOINT$_throwable", "Ljava/lang/Throwable;");
    loadNull(instructions);
    storeVar(instructions, this.throwableVarIndex);
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) Interceptor(com.navercorp.pinpoint.bootstrap.interceptor.Interceptor)

Example 13 with MethodInsnNode

use of org.objectweb.asm.tree.MethodInsnNode in project bytecode-viewer by Konloch.

the class CodeSequenceDiagram method execute.

@Override
public void execute(ArrayList<ClassNode> classNodeList) {
    if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) {
        BytecodeViewer.showMessage("First open a class file.");
        return;
    }
    ClassNode c = BytecodeViewer.viewer.workPane.getCurrentViewer().cn;
    if (c == null) {
        BytecodeViewer.showMessage("ClassNode is null for CodeSequenceDiagram. Please report to @Konloch");
        return;
    }
    JFrame frame = null;
    if (c.name != null)
        frame = new JFrame("Code Sequence Diagram - " + c.name);
    else
        frame = new JFrame("Code Sequence Diagram - Unknown Name");
    frame.setIconImages(Resources.iconList);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(400, 320);
    mxGraph graph = new mxGraph();
    graph.setVertexLabelsMovable(false);
    graph.setGridEnabled(true);
    graph.setEnabled(false);
    graph.setCellsEditable(false);
    graph.setCellsSelectable(false);
    graph.setCellsMovable(false);
    graph.setCellsLocked(true);
    Object parent = graph.getDefaultParent();
    Font font = UIManager.getDefaults().getFont("TabbedPane.font");
    AffineTransform affinetransform = new AffineTransform();
    FontRenderContext frc = new FontRenderContext(affinetransform, true, true);
    graph.getModel().beginUpdate();
    try {
        int testX = 10;
        int testY = 0;
        double magicNumber = 5.8;
        for (MethodNode m : (ArrayList<MethodNode>) c.methods) {
            String mIdentifier = c.name + "." + m.name + m.desc;
            Object node = graph.insertVertex(parent, null, mIdentifier, testX, testY, mIdentifier.length() * magicNumber, 30);
            Object attach = node;
            testX += (int) (font.getStringBounds(mIdentifier, frc).getWidth()) + 60;
            for (AbstractInsnNode i : m.instructions.toArray()) {
                if (i instanceof MethodInsnNode) {
                    MethodInsnNode mi = (MethodInsnNode) i;
                    String identifier = mi.owner + "." + mi.name + mi.desc;
                    Object node2 = graph.insertVertex(parent, null, identifier, testX, testY, identifier.length() * 5, 30);
                    testX += (int) (font.getStringBounds(identifier, frc).getWidth()) + 60;
                    graph.insertEdge(parent, null, null, attach, node2);
                    attach = node2;
                }
            }
            testY += 60;
            testX = 10;
        }
    } finally {
        graph.getModel().endUpdate();
    }
    mxGraphComponent graphComponent = new mxGraphComponent(graph);
    frame.getContentPane().add(graphComponent);
    frame.setVisible(true);
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ArrayList(java.util.ArrayList) com.mxgraph.view.mxGraph(com.mxgraph.view.mxGraph) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) AffineTransform(java.awt.geom.AffineTransform) ClassViewer(the.bytecode.club.bytecodeviewer.gui.ClassViewer) FontRenderContext(java.awt.font.FontRenderContext) com.mxgraph.swing.mxGraphComponent(com.mxgraph.swing.mxGraphComponent)

Example 14 with MethodInsnNode

use of org.objectweb.asm.tree.MethodInsnNode in project bytecode-viewer by Konloch.

the class MemberQuery method matches.

@Override
public boolean matches(AbstractInsnNode ain) {
    if (!(ain instanceof FieldInsnNode) && !(ain instanceof MethodInsnNode))
        return false;
    int opcode = ain.opcode();
    String owner, name, desc;
    if (ain instanceof FieldInsnNode) {
        FieldInsnNode fin = (FieldInsnNode) ain;
        owner = fin.owner;
        name = fin.name;
        desc = fin.desc;
    } else {
        MethodInsnNode min = (MethodInsnNode) ain;
        owner = min.owner;
        name = min.name;
        desc = min.desc;
    }
    if (this.opcode == -1 || this.opcode == opcode) {
        if (this.owner == null || this.owner.equals(owner)) {
            if (this.name == null || this.name.equals(name)) {
                if (this.desc == null || this.desc.equals(desc) || desc.matches(this.desc)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode)

Example 15 with MethodInsnNode

use of org.objectweb.asm.tree.MethodInsnNode 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)

Aggregations

MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)26 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)12 MethodNode (org.objectweb.asm.tree.MethodNode)5 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)4 ArrayList (java.util.ArrayList)3 Type (org.objectweb.asm.Type)3 InsnList (org.objectweb.asm.tree.InsnList)3 InvokeDynamicInsnNode (org.objectweb.asm.tree.InvokeDynamicInsnNode)3 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)3 BasicValue (org.objectweb.asm.tree.analysis.BasicValue)3 List (java.util.List)2 AnnotationNode (org.objectweb.asm.tree.AnnotationNode)2 ClassNode (org.objectweb.asm.tree.ClassNode)2 FieldNode (org.objectweb.asm.tree.FieldNode)2 InsnNode (org.objectweb.asm.tree.InsnNode)2 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)2 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)2 Frame (org.objectweb.asm.tree.analysis.Frame)2 SuspendableType (co.paralleluniverse.fibers.instrument.MethodDatabase.SuspendableType)1 com.mxgraph.swing.mxGraphComponent (com.mxgraph.swing.mxGraphComponent)1