Search in sources :

Example 31 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project MineCamera by PorPit.

the class CamTransformer method initTransformers.

protected void initTransformers() {
    addTransformer(new Transformer("net.minecraft.client.entity.EntityPlayerSP") {

        @Override
        public void transform(ClassNode node) {
            MethodNode m = findMethod(node, "isCurrentViewEntity", "()Z");
            m.instructions.clear();
            m.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/porpit/minecamera/transform/CamEventHandler", "shouldPlayerTakeInput", "()Z", false));
            m.instructions.add(new InsnNode(Opcodes.IRETURN));
        }
    });
    addTransformer(new Transformer("net.minecraft.client.renderer.EntityRenderer") {

        @Override
        public void transform(ClassNode node) {
            MethodNode m = findMethod(node, "getMouseOver", "(F)V");
            m.instructions.insert(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/porpit/minecamera/transform/CamEventHandler", "setupMouseHandlerBefore", "()V", false));
            AbstractInsnNode currentNode = null;
            @SuppressWarnings("unchecked") Iterator<AbstractInsnNode> iter = m.instructions.iterator();
            while (iter.hasNext()) {
                currentNode = iter.next();
                if (currentNode instanceof InsnNode && ((InsnNode) currentNode).getOpcode() == RETURN) {
                    m.instructions.insertBefore(currentNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "com/porpit/minecamera/transform/CamEventHandler", "setupMouseHandlerAfter", "()V", false));
                }
            }
        }
    });
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) IClassTransformer(net.minecraft.launchwrapper.IClassTransformer) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) Iterator(java.util.Iterator) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 32 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project MineCamera by PorPit.

the class Transformer method findMethod.

public MethodNode findMethod(ClassNode node, String name, String desc) {
    if (TransformerNames.obfuscated) {
        name = patchMethodName(name, desc);
        desc = patchDESC(desc);
    }
    Iterator<MethodNode> methods = node.methods.iterator();
    while (methods.hasNext()) {
        MethodNode m = methods.next();
        if (m.name.equals(name) && m.desc.equals(desc))
            return m;
    }
    return null;
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode)

Example 33 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project evosuite by EvoSuite.

the class AnnotatedClassNode method visitMethod.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) {
    MethodNode mn = new AnnotatedMethodNode(access, name, desc, signature, exceptions);
    methods.add(mn);
    return mn;
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode)

Example 34 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project evosuite by EvoSuite.

the class BooleanTestabilityTransformation method processMethods.

/**
 * Handle transformation of methods defined in this class
 */
@SuppressWarnings("unchecked")
private void processMethods() {
    List<MethodNode> methodNodes = cn.methods;
    for (MethodNode mn : methodNodes) {
        if ((mn.access & Opcodes.ACC_NATIVE) == Opcodes.ACC_NATIVE)
            continue;
        if (DescriptorMapping.getInstance().isTransformedMethod(className, mn.name, mn.desc)) {
            logger.info("Transforming signature of method " + mn.name + mn.desc);
            transformMethodSignature(mn);
            logger.info("Transformed signature to " + mn.name + mn.desc);
        }
        transformMethod(mn);
    }
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode)

Example 35 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project evosuite by EvoSuite.

the class ErrorConditionMethodAdapter method visitEnd.

/*
	public Frame currentFrame = null;
	
	@Override
	public void visitFrame(int type, int nLocal, Object[] local, int nStack,
			Object[] stack) {
		super.visitFrame(type, nLocal, local, nStack, stack);
		// this.currentFrame = frames[numFrame++];
	}
	
	
	protected int numFrame = 0;
	
	protected Frame[] frames;

	@Override
	public void visitCode() {
		MethodNode mn = (MethodNode) mv;
		try {
			Analyzer a = new Analyzer(new ThisInterpreter());
			a.analyze(className, mn);
			frames = a.getFrames();
			logger.info("Computed frames: "+frames.length);
		} catch (Exception e) {
			logger.info("Error during frame analysis: "+e);
			frames = new Frame[0];
		}
		super.visitCode();
	}
	*/
/* (non-Javadoc)
	 * @see org.objectweb.asm.MethodVisitor#visitEnd()
	 */
/**
 * {@inheritDoc}
 */
@Override
public void visitEnd() {
    MethodNode mn = (MethodNode) mv;
    mn.accept(next);
}
Also used : AnnotatedMethodNode(org.evosuite.runtime.instrumentation.AnnotatedMethodNode) MethodNode(org.objectweb.asm.tree.MethodNode)

Aggregations

MethodNode (org.objectweb.asm.tree.MethodNode)322 ClassNode (org.objectweb.asm.tree.ClassNode)123 Test (org.junit.Test)94 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)59 ClassReader (org.objectweb.asm.ClassReader)57 InsnList (org.objectweb.asm.tree.InsnList)49 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)47 Label (org.objectweb.asm.Label)44 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)41 InsnNode (org.objectweb.asm.tree.InsnNode)34 ClassWriter (org.objectweb.asm.ClassWriter)26 FieldNode (org.objectweb.asm.tree.FieldNode)26 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)26 ArrayList (java.util.ArrayList)24 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)24 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)21 LabelNode (org.objectweb.asm.tree.LabelNode)19 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)19 List (java.util.List)17 Type (org.objectweb.asm.Type)17