List of usage examples for org.objectweb.asm.tree MethodNode visitLocalVariable
@Override public void visitLocalVariable(final String name, final String descriptor, final String signature, final Label start, final Label end, final int index)
From source file:com.triage.bytecodemaster.TestObjectReferenceSwitches.java
public void testReplacingThisWithOtherVariable() throws Exception { final String FIELDPROXYWORKED = "FIELDPROXYWORKED"; //set up the proxy object. this is the object that will receive //the proxied calls TestSubClass tcc = new TestSubClass(); tcc.setBaseString(FIELDPROXYWORKED); TestBaseClassHolder.setTestBase(tcc); //get the dynamic source that has the donor body in it ClassNode donorSource = loadGroovyTestClassAsBytecode(GROOVY_CLASS_FIELDREF); MethodNode donorMethod = findMethod(donorSource, "before_whatDoIThinkAbout"); System.out.println("Donor"); printMethodNode(donorMethod);/*ww w .j a va2 s . c o m*/ //alright here's the strategy: (1) inject a new local variable that points // to our remote instance, // (2) inject code that sets this local to the value of a method call, // (3) change references to 'this' ( ALOAD0 or ALOAD 0 ) to ALOAD1 InsnList instructionsToInject = donorMethod.instructions; //make a new local variable LabelNode begin = new LabelNode(); LabelNode end = new LabelNode(); instructionsToInject.insertBefore(instructionsToInject.getFirst(), begin); instructionsToInject.add(end); Type type = Type.getObjectType("com/triage/bytecodemaster/fortesting/TestBaseClass"); int variableIndex = donorMethod.maxLocals; donorMethod.maxLocals += type.getSize(); donorMethod.visitLocalVariable("proxy", type.getDescriptor(), null, begin.getLabel(), end.getLabel(), variableIndex); //set the value of the local variable with a new instruction at the top //fetch a reference to our proxy object MethodInsnNode getTestBase = new MethodInsnNode(Opcodes.INVOKESTATIC, "com/triage/bytecodemaster/fortesting/TestBaseClassHolder", "getTestBase", "()Lcom/triage/bytecodemaster/fortesting/TestBaseClass;"); //insert after begin label instructionsToInject.insert(begin, getTestBase); //store reference VarInsnNode setRef = new VarInsnNode(Opcodes.ASTORE, variableIndex); //insert store after fetch instructionsToInject.insert(getTestBase, setRef); //replace all references to 'this' with the new variable for (int currentIndex = 0; currentIndex < instructionsToInject.size(); currentIndex++) { AbstractInsnNode node = instructionsToInject.get(currentIndex); if (node.getOpcode() == Opcodes.ALOAD) { VarInsnNode vin = (VarInsnNode) node; //'this' is var index 0. ours is var index varindex if (vin.var == 0) { vin.var = variableIndex; } } } System.out.println(">>>>>>>>>Finished Modifying<<<<<<<<"); printMethodNode(donorMethod); String NEWCLASSNAME = "ScriptTestClass"; //write a class Class c = createClassFromClassNode(donorSource, NEWCLASSNAME); Object o = c.newInstance(); Method m = o.getClass().getDeclaredMethod("before_whatDoIThinkAbout", String.class); //should return HAHAHA not baseStringValue String result = (String) m.invoke(o, new Object[] { "AAAA" }); System.out.println("TestDonorClass.whatDoIThinkAbout Result: " + result); assertTrue(result.equals(FIELDPROXYWORKED + "AAAA")); }
From source file:com.triage.bytecodemaster.TestObjectReferenceSwitches.java
@Test public void testInjectingIntoMethodWithLotsOfParameters() throws Exception { final String FIELDPROXYWORKED = "FIELDPROXYWORKED"; //set up the proxy object. this is the object that will receive //the proxied calls TestSubClass tcc = new TestSubClass(); tcc.setBaseString(FIELDPROXYWORKED); TestBaseClassHolder.setTestBase(tcc); //get the dynamic source that has the donor body in it ClassNode donorSource = loadGroovyTestClassAsBytecode(GROOVY_CLASS_FIELDREF2); MethodNode donorMethod = findMethod(donorSource, "before_whatDoIThinkAbout"); System.out.println("Donor Method Before Modifications:"); printMethodNode(donorMethod);//from w w w.ja va 2s. c o m String TARGETCLASSNAME = "com.triage.bytecodemaster.fortesting.Concatenator"; ClassNode targetSource = loadLocalClass(TARGETCLASSNAME); ClassNode exampleSource = loadLocalClass("com.triage.bytecodemaster.fortesting.JustLikeGroovyClass"); MethodNode exampleMethod = findMethod(exampleSource, "before_whatDoIThinkAbout"); System.out.println("Example Method-- Should be just like the Donor Source"); printMethodNode(exampleMethod); MethodNode targetMethod = findMethod(targetSource, "concat"); System.out.println("Target Method <Before Mods>"); printMethodNode(targetMethod); //alright here's the strategy: (1) inject a new local variable that points // to our remote instance, // (2) inject code that sets this local to the value of a method call, // (3) change references to 'this' ( ALOAD0 or ALOAD 0 ) to ALOAD1 InsnList instructionsToInject = donorMethod.instructions; InsnList targetInstructions = targetMethod.instructions; //make a new local variable in the donor method. //this variable needs to have a slot high enough that it doesnt //conflict with either the target or the source method //it will hold references to the objects we replace with 'this' LabelNode begin = new LabelNode(); LabelNode end = new LabelNode(); targetInstructions.insertBefore(targetInstructions.getFirst(), begin); targetInstructions.add(end); Type type = Type.getObjectType("com/triage/bytecodemaster/fortesting/TestBaseClass"); int variableIndex = targetMethod.maxLocals; targetMethod.maxLocals += type.getSize(); targetMethod.visitLocalVariable("proxy", type.getDescriptor(), null, begin.getLabel(), end.getLabel(), variableIndex); //set the value of the local variable with a new instruction at the top //fetch a reference to our proxy object MethodInsnNode getTestBase = new MethodInsnNode(Opcodes.INVOKESTATIC, "com/triage/bytecodemaster/fortesting/TestBaseClassHolder", "getTestBase", "()Lcom/triage/bytecodemaster/fortesting/TestBaseClass;"); //insert after begin label targetInstructions.insert(begin, getTestBase); //store reference VarInsnNode setRef = new VarInsnNode(Opcodes.ASTORE, variableIndex); //insert store after fetch targetInstructions.insert(getTestBase, setRef); //replace all references to 'this' in the DONOR method with the new variable //in the TARGET code for (int currentIndex = 0; currentIndex < instructionsToInject.size(); currentIndex++) { AbstractInsnNode node = instructionsToInject.get(currentIndex); if (node.getOpcode() == Opcodes.ALOAD) { VarInsnNode vin = (VarInsnNode) node; //'this' is var index 0. ours is var index varindex if (vin.var == 0) { vin.var = variableIndex; } } //remove return methods. this will prevent a return. it should cause the donor //method to have parameters that overlap with the target, which has more parameters if (node.getOpcode() == Opcodes.RETURN || node.getOpcode() == Opcodes.ARETURN) { instructionsToInject.remove(node); } } System.out.println(">>>>>>>>>Finished Modifying Donor Method <<<<<<<<"); printMethodNode(donorMethod); String NEWCLASSNAME = "ScriptTestClass"; //stash instructions at the beginning of the original method, //but after populating the new variable targetInstructions.insert(setRef, instructionsToInject); System.out.println("Modified Target:"); printMethodNode(targetMethod); //write a class Class c = createClassFromClassNode(targetSource, TARGETCLASSNAME); Object o = c.newInstance(); Method m = o.getClass().getDeclaredMethod("concat", String.class, String.class, String.class, String.class); //should return HAHAHA not baseStringValue String result = (String) m.invoke(o, new Object[] { "A", "B", "C", "D" }); System.out.println("Concatenator.concat Result: " + result); assertTrue(result.equals("ABCD")); }
From source file:com.triage.bytecodemaster.TestObjectReferenceSwitches.java
public void testMergedInReplacingThisWithOtherVariable() throws Exception { final String FIELDPROXYWORKED = "FIELDPROXYWORKED"; //set up the proxy object. this is the object that will receive //the proxied calls TestSubClass tcc = new TestSubClass(); tcc.setBaseString(FIELDPROXYWORKED); TestBaseClassHolder.setTestBase(tcc); //get the dynamic source that has the donor body in it ClassNode donorSource = loadGroovyTestClassAsBytecode(GROOVY_CLASS_FIELDREF); MethodNode donorMethod = findMethod(donorSource, "before_whatDoIThinkAbout"); //load the target class String TARGETCLASSNAME = "com.triage.bytecodemaster.fortesting.TestFriend"; ClassNode targetSource = loadLocalClass(TARGETCLASSNAME); MethodNode targetMethod = findMethod(targetSource, "whatDoIThinkAbout"); System.out.println("Target"); printMethodNode(targetMethod);// w w w . j a v a 2s . c om System.out.println("Donor"); printMethodNode(donorMethod); //alright here's the strategy: (1) inject a new local variable that points // to our remote instance, // (2) inject code that sets this local to the value of a method call, // (3) change references to 'this' ( ALOAD0 or ALOAD 0 ) to ALOAD1 InsnList instructionsToInject = donorMethod.instructions; //make a new local variable LabelNode begin = new LabelNode(); LabelNode end = new LabelNode(); instructionsToInject.insertBefore(instructionsToInject.getFirst(), begin); instructionsToInject.add(end); Type type = Type.getObjectType("com/triage/bytecodemaster/fortesting/TestBaseClass"); int variableIndex = donorMethod.maxLocals; donorMethod.maxLocals += type.getSize(); donorMethod.visitLocalVariable("proxy", type.getDescriptor(), null, begin.getLabel(), end.getLabel(), variableIndex); //set the value of the local variable with a new instruction at the top //fetch a reference to our proxy object MethodInsnNode getTestBase = new MethodInsnNode(Opcodes.INVOKESTATIC, "com/triage/bytecodemaster/fortesting/TestBaseClassHolder", "getTestBase", "()Lcom/triage/bytecodemaster/fortesting/TestBaseClass;"); //insert after begin label instructionsToInject.insert(begin, getTestBase); //store reference VarInsnNode setRef = new VarInsnNode(Opcodes.ASTORE, variableIndex); //insert store after fetch instructionsToInject.insert(getTestBase, setRef); //replace all references to 'this' with the new variable for (int currentIndex = 0; currentIndex < instructionsToInject.size(); currentIndex++) { AbstractInsnNode node = instructionsToInject.get(currentIndex); if (node.getOpcode() == Opcodes.ALOAD) { VarInsnNode vin = (VarInsnNode) node; //'this' is var index 0. ours is var index varindex if (vin.var == 0) { vin.var = variableIndex; } } } System.out.println(">>>>>>>>>Finished Modifying<<<<<<<<"); printMethodNode(donorMethod); //insert the donorMethod targetMethod.instructions.insert(instructionsToInject); System.out.println(">>>>>>>>>Final Method<<<<<<<<"); printMethodNode(targetMethod); //write a class Class c = createClassFromClassNode(targetSource, TARGETCLASSNAME); Object o = c.newInstance(); Method m = o.getClass().getDeclaredMethod("whatDoIThinkAbout", TestPerson.class); TestPerson testPerson = new TestPerson(); testPerson.setName("AAAA"); //should return HAHAHA not baseStringValue String result = (String) m.invoke(o, new Object[] { testPerson }); System.out.println("TestFriend.whatDoIThinkAbout Result: " + result); assertTrue(result.equals(FIELDPROXYWORKED + "AAAA")); }
From source file:de.sanandrew.core.manpack.transformer.TransformBadPotionsATN.java
License:Creative Commons License
private byte[] transformPotion(byte[] bytes) { ClassNode cn = ASMHelper.createClassNode(bytes); if (ASMHelper.hasClassMethodName(cn, ASMNames.M_isBadEffect)) { return bytes; }/* w w w.j a v a2 s .c o m*/ MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, ASMNames.M_isBadEffect, "()Z", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/potion/Potion", ASMNames.F_isBadEffect, "Z"); method.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/potion/Potion;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); cn.methods.add(method); bytes = ASMHelper.createBytes(cn, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); return bytes; }
From source file:de.sanandrew.core.manpack.transformer.TransformELBAttackingPlayer.java
License:Creative Commons License
private static byte[] transformAccessors(byte[] bytes) { ClassNode clazz = ASMHelper.createClassNode(bytes); int complete = 0; for (MethodNode method : clazz.methods) { switch (method.name) { case "getELAttackingPlayer": { method.instructions.clear(); method.visitCode();/* w ww . ja v a 2 s . c om*/ Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "net/minecraft/entity/EntityLivingBase", "_SAP_getAttackingPlayer", "()Lnet/minecraft/entity/player/EntityPlayer;", false); method.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("entity", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); complete++; continue; } case "setELAttackingPlayer": { method.instructions.clear(); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "net/minecraft/entity/EntityLivingBase", "_SAP_setAttackingPlayer", "(Lnet/minecraft/entity/player/EntityPlayer;)V", false); Label l1 = new Label(); method.visitLabel(l1); method.visitInsn(Opcodes.RETURN); Label l2 = new Label(); method.visitLabel(l2); method.visitLocalVariable("player", "Lnet/minecraft/entity/player/EntityPlayer;", null, l0, l2, 0); method.visitLocalVariable("entity", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l2, 1); method.visitMaxs(0, 0); method.visitEnd(); complete++; continue; } case "getELRecentlyHit": { method.instructions.clear(); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "net/minecraft/entity/EntityLivingBase", "_SAP_getRecentlyHit", "()I", false); method.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("entity", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); complete++; continue; } case "setELRecentlyHit": { method.instructions.clear(); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitVarInsn(Opcodes.ILOAD, 0); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "net/minecraft/entity/EntityLivingBase", "_SAP_setRecentlyHit", "(I)V", false); Label l1 = new Label(); method.visitLabel(l1); method.visitInsn(Opcodes.RETURN); Label l2 = new Label(); method.visitLabel(l2); method.visitLocalVariable("hit", "I", null, l0, l2, 0); method.visitLocalVariable("entity", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l2, 1); method.visitMaxs(0, 0); method.visitEnd(); complete++; continue; } } if (complete >= 4) { break; } } bytes = ASMHelper.createBytes(clazz, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); return bytes; }
From source file:de.sanandrew.core.manpack.transformer.TransformELBAttackingPlayer.java
License:Creative Commons License
private static byte[] transformAttackingPlayer(byte[] bytes) { ClassNode clazz = ASMHelper.createClassNode(bytes); /** ADD GETTER FOR ATTACKING PLAYER **/ {//w w w.j a v a 2 s . c o m MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_getAttackingPlayer", "()Lnet/minecraft/entity/player/EntityPlayer;", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_attackingPlayer, "Lnet/minecraft/entity/player/EntityPlayer;"); method.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD SETTER FOR ATTACKING PLAYER **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_setAttackingPlayer", "(Lnet/minecraft/entity/player/EntityPlayer;)V", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitFieldInsn(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_attackingPlayer, "Lnet/minecraft/entity/player/EntityPlayer;"); Label l1 = new Label(); method.visitLabel(l1); method.visitInsn(Opcodes.RETURN); Label l2 = new Label(); method.visitLabel(l2); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l2, 0); method.visitLocalVariable("player", "Lnet/minecraft/entity/player/EntityPlayer;", null, l0, l2, 1); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD GETTER FOR RECENTLY HIT **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_getRecentlyHit", "()I", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_recentlyHit, "I"); method.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD SETTER FOR RECENTLY HIT **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_setRecentlyHit", "(I)V", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ILOAD, 1); method.visitFieldInsn(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_recentlyHit, "I"); Label l1 = new Label(); method.visitLabel(l1); method.visitInsn(Opcodes.RETURN); Label l2 = new Label(); method.visitLabel(l2); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l2, 0); method.visitLocalVariable("hit", "I", null, l0, l2, 1); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } bytes = ASMHelper.createBytes(clazz, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS); return bytes; }
From source file:de.sanandrew.core.manpack.transformer.TransformEntityCollision.java
License:Creative Commons License
private static byte[] transformEntity(byte[] bytes) { ClassNode clazz = ASMHelper.createClassNode(bytes); MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PUBLIC, ASMNames.MD_SAP_ENTITY_GET_BOUNDING_BOX); method.visitCode();// ww w .j a v a 2 s. c o m Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 2); method.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", ASMNames.CL_T_ENTITY, null, l0, l1, 0); method.visitLocalVariable("entity", ASMNames.CL_T_ENTITY, null, l0, l1, 1); method.visitLocalVariable("oldAABB", ASMNames.CL_T_AXIS_ALIGNED_BB, null, l0, l1, 2); method.visitMaxs(1, 2); method.visitEnd(); clazz.methods.add(method); bytes = ASMHelper.createBytes(clazz, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS); return bytes; }
From source file:de.sanandrew.core.manpack.transformer.TransformEntityThrowable.java
License:Creative Commons License
private static byte[] transformLqThrowable(byte[] bytes) { ClassNode classNode = ASMHelper.createClassNode(bytes); MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PUBLIC, ASMNames.MD_SAP_CAN_IMPACT_ON_LIQUID); method.visitCode();/*from w w w. j av a2 s.c om*/ Label label1 = new Label(); method.visitLabel(label1); method.visitInsn(Opcodes.ICONST_0); method.visitInsn(Opcodes.IRETURN); Label label2 = new Label(); method.visitLabel(label2); method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_THROWABLE, null, label1, label2, 0); method.visitMaxs(0, 0); method.visitEnd(); classNode.methods.add(method); method = ASMHelper.findMethod(classNode, ASMNames.MD_THROWABLE_ON_UPDATE); InsnList needle = new InsnList(); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_THROWABLE_MOTION_Z)); needle.add(new InsnNode(Opcodes.DADD)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_VEC3_CREATE_VECTOR_HELPER, false)); needle.add(new VarInsnNode(Opcodes.ASTORE, 2)); needle.add(new LabelNode()); needle.add(new LineNumberNode(-1, new LabelNode())); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_THROWABLE_WORLD_OBJ)); needle.add(new VarInsnNode(Opcodes.ALOAD, 1)); needle.add(new VarInsnNode(Opcodes.ALOAD, 2)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_WORLD_RAY_TRACE_BLOCKS, false)); needle.add(new VarInsnNode(Opcodes.ASTORE, -1)); VarInsnNode insertPoint = (VarInsnNode) ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList injectList = new InsnList(); injectList.add(new LabelNode()); injectList.add(new VarInsnNode(Opcodes.ALOAD, 0)); injectList.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_THROWABLE_WORLD_OBJ)); injectList.add(new VarInsnNode(Opcodes.ALOAD, 1)); injectList.add(new VarInsnNode(Opcodes.ALOAD, 2)); injectList.add(new VarInsnNode(Opcodes.ALOAD, 0)); injectList.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_SAP_CAN_IMPACT_ON_LIQUID, false)); injectList.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_WORLD_RAY_TRACE_BLOCKS_Z, false)); injectList.add(new VarInsnNode(Opcodes.ASTORE, insertPoint.var)); method.instructions.insert(insertPoint, injectList); return ASMHelper.createBytes(classNode, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS); }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static MethodNode injectMethodGetCustomArmorItem() { MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_GET_CUSTOM_ARMOR_ITEM); method.visitCode();//from ww w .j a v a 2 s. com Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER); method.visitIntInsn(Opcodes.BIPUSH, 23); ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_GET_OBJ_STACK, false); method.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l1, 0); method.visitMaxs(2, 1); method.visitEnd(); return method; }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static MethodNode injectMethodSetCustomArmorItem() { MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_SET_CUSTOM_ARMOR_ITEM); method.visitCode();//from www.j a va2s . c o m Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 1); Label l1 = new Label(); method.visitJumpInsn(Opcodes.IFNONNULL, l1); method.visitTypeInsn(Opcodes.NEW, ASMNames.CL_ITEM_STACK); method.visitInsn(Opcodes.DUP); ASMHelper.visitFieldInsn(method, Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL); method.visitInsn(Opcodes.ICONST_0); ASMHelper.visitMethodInsn(method, Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false); method.visitVarInsn(Opcodes.ASTORE, 1); method.visitLabel(l1); method.visitFrame(Opcodes.F_SAME, 0, null, 0, null); method.visitVarInsn(Opcodes.ALOAD, 0); ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER); method.visitIntInsn(Opcodes.BIPUSH, 23); method.visitVarInsn(Opcodes.ALOAD, 1); ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_UPDATE_OBJ, false); Label l3 = new Label(); method.visitLabel(l3); method.visitInsn(Opcodes.RETURN); Label l4 = new Label(); method.visitLabel(l4); method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l3, 0); method.visitLocalVariable("stack", ASMNames.CL_T_ITEM_STACK, null, l0, l3, 1); method.visitMaxs(5, 2); method.visitEnd(); return method; }