Search in sources :

Example 61 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project Galacticraft by micdoodle8.

the class TweakTransformer method load.

public static void load() {
    CodeChickenCoreModContainer.loadConfig();
    tweaks = CodeChickenCoreModContainer.config.getTag("tweaks").setComment("Various tweaks that can be applied to game mechanics.").useBraces();
    tweaks.removeTag("persistantLava");
    if (tweaks.getTag("environmentallyFriendlyCreepers").setComment("If set to true, creepers will not destroy landscape. (A version of mobGriefing setting just for creepers)").getBooleanValue(false)) {
        transformer.add(new MethodReplacer(new ObfMapping("net/minecraft/entity/monster/EntityCreeper", "func_146077_cc", "()V"), blocks.get("d_environmentallyFriendlyCreepers"), blocks.get("environmentallyFriendlyCreepers")));
    }
    if (tweaks.getTag("finiteWater").setComment("If set to true two adjacent water source blocks will not generate a third.").getBooleanValue(false)) {
        transformer.add(new MethodTransformer(new ObfMapping("net/minecraft/block/BlockDynamicLiquid", "func_149674_a", "(Lnet/minecraft/world/World;IIILjava/util/Random;)V")) {

            @Override
            public void transform(MethodNode mv) {
                InsnListSection key = findOnce(mv.instructions, blocks.get("finiteWater").list);
                key.setLast(((JumpInsnNode) key.getLast()).label);
                key.remove();
            }
        });
    }
}
Also used : MethodTransformer(codechicken.lib.asm.ModularASMTransformer.MethodTransformer) MethodNode(org.objectweb.asm.tree.MethodNode) MethodReplacer(codechicken.lib.asm.ModularASMTransformer.MethodReplacer) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode)

Example 62 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project openj9 by eclipse.

the class ClassFileCompare method isValidInvokeVirtualConversion.

private boolean isValidInvokeVirtualConversion(ClassNode clazz, MethodNode method, AbstractInsnNode insn1, AbstractInsnNode insn2) {
    if (Opcodes.INVOKEVIRTUAL == insn1.getOpcode() && Opcodes.INVOKESPECIAL == insn2.getOpcode()) {
        MethodInsnNode methodInsn1 = (MethodInsnNode) insn1;
        MethodInsnNode methodInsn2 = (MethodInsnNode) insn2;
        /*
			 * The class name as well as the method name involved are checked by
			 * comparing their method owner name(the internal name of the
			 * method's class) and name (the method's name)
			 */
        if (methodInsn1.owner.equals(methodInsn2.owner) && methodInsn1.name.equals(methodInsn2.name) && methodInsn1.desc.equals(methodInsn2.desc)) {
            /*
				 * Both methods should be compared further in terms of their
				 * access flag(has to be private) if they are not the 6 final
				 * methods of Object listed as follows: 
				 * name     descriptor 
				 * wait      ()V
				 * wait      (J)V 
				 * wait      (JI)V 
				 * notify    ()V 
				 * notifyAll ()V 
				 * getClass  ()Ljava/lang/Class;
				 */
            if (methodInsn1.owner.equals("java/lang/Object") && specialObjectMethods.contains(methodInsn1.name + methodInsn1.desc)) {
                return true;
            }
            @SuppressWarnings("unchecked") List<MethodNode> methodNodes1 = new ArrayList<>(clazz.methods);
            for (MethodNode mn : methodNodes1) {
                if (mn.name.equals(methodInsn1.name) && mn.desc.equals(methodInsn1.desc)) {
                    return Opcodes.ACC_PRIVATE == mn.access;
                }
            }
        }
    }
    return false;
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ArrayList(java.util.ArrayList)

Example 63 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project phosphor by gmu-swe.

the class CallGraphBuildingClassVisitor method visitMethod.

@Override
public MethodVisitor visitMethod(int access, final String name, final String desc, String signature, String[] exceptions) {
    final MethodInformation thisMIN = graph.getMethodNode(className, name, desc);
    Instrumenter.classes.get(className).methods.add(new MethodNode(access, name, desc, signature, exceptions));
    thisMIN.setVisited(true);
    if ((access & Opcodes.ACC_NATIVE) != 0)
        thisMIN.setPure(false);
    return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {

        @Override
        public void visitMethodInsn(int opcode, String _owner, String _name, String _desc, boolean intfc) {
            super.visitMethodInsn(opcode, _owner, _name, _desc, intfc);
            if (!(opcode == Opcodes.INVOKESPECIAL && _owner.equals("java/lang/Object")))
                graph.addEdge(className, name, desc, _owner, _name, _desc);
            if (_owner.equals("java/lang/reflect/Method") && name.equals("invoke"))
                thisMIN.setCallsTaintedMethods(true);
            if (opcode == Opcodes.INVOKESTATIC)
                graph.addEdge(className, name, desc, _owner, "<clinit>", "()V");
        }

        @Override
        public void visitFieldInsn(int opcode, String owner, String name, String desc) {
            super.visitFieldInsn(opcode, owner, name, desc);
            thisMIN.setPure(false);
            if (opcode == Opcodes.GETSTATIC || opcode == Opcodes.PUTSTATIC)
                graph.addEdge(className, name, desc, owner, "<clinit>", "()V");
        }

        @Override
        public void visitTypeInsn(int opcode, String type) {
            super.visitTypeInsn(opcode, type);
            if (opcode == Opcodes.NEW)
                graph.addEdge(className, name, desc, type, "<clinit>", "()V");
        }
    };
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode) MethodInformation(edu.columbia.cs.psl.phosphor.struct.MethodInformation) MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 64 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project DynamicSurroundings by OreCruncher.

the class PatchSoundManagerClampVolume method transmorgrify.

@Override
public boolean transmorgrify(final ClassNode cn) {
    final String[] names = { "getClampedVolume", "func_188770_e" };
    final String sig = "(Lnet/minecraft/client/audio/ISound;)F";
    final MethodNode m = findMethod(cn, sig, names);
    if (m != null) {
        logMethod(Transformer.log(), m, "Found!");
        final String owner = "org/blockartistry/DynSurround/client/sound/SoundEngine";
        final String targetName = "getClampedVolume";
        final String sig1 = "(Lnet/minecraft/client/audio/ISound;)F";
        final InsnList list = new InsnList();
        list.add(new VarInsnNode(ALOAD, 1));
        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, targetName, sig1, false));
        list.add(new InsnNode(Opcodes.FRETURN));
        m.instructions = list;
        return true;
    } else {
        Transformer.log().error("Unable to locate method {}{}", names[0], sig);
    }
    Transformer.log().info("Unable to patch [{}]!", getClassName());
    return false;
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 65 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project DynamicSurroundings by OreCruncher.

the class PatchSoundManager method transmorgrify.

@Override
public boolean transmorgrify(final ClassNode cn) {
    final String[] names = { "getURLForSoundResource", "func_148612_a" };
    final String sig = "(Lnet/minecraft/util/ResourceLocation;)Ljava/net/URL;";
    final MethodNode m = findMethod(cn, sig, names);
    if (m != null) {
        logMethod(Transformer.log(), m, "Found!");
        final InsnList list = new InsnList();
        list.add(new VarInsnNode(ALOAD, 0));
        final String owner = "org/blockartistry/lib/sound/SoundCache";
        final String targetName = "getURLForSoundResource";
        final String sig1 = "(Lnet/minecraft/util/ResourceLocation;)Ljava/net/URL;";
        list.add(new MethodInsnNode(INVOKESTATIC, owner, targetName, sig1, false));
        list.add(new InsnNode(ARETURN));
        m.instructions.insert(m.instructions.getFirst(), list);
        return true;
    } else {
        Transformer.log().error("Unable to locate method {}{}", names[0], sig);
    }
    Transformer.log().info("Unable to patch [{}]!", getClassName());
    return false;
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

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