List of usage examples for org.objectweb.asm Opcodes INVOKEVIRTUAL
int INVOKEVIRTUAL
To view the source code for org.objectweb.asm Opcodes INVOKEVIRTUAL.
Click Source Link
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformArmorTexture(MethodNode method) { InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_HORSE_FUNC110241CB, false)); needle.add(new VarInsnNode(Opcodes.ISTORE, 3)); AbstractInsnNode node = ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); LabelNode l17 = new LabelNode(); newInstr.add(l17);/* w w w .j a v a 2s .co m*/ newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_SAP_GET_CUSTOM_ARMOR_ITEM, false)); newInstr.add(new VarInsnNode(Opcodes.ASTORE, 4)); LabelNode l18 = new LabelNode(); newInstr.add(l18); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false)); newInstr.add(new TypeInsnNode(Opcodes.INSTANCEOF, ASMNames.CL_ITEM_HORSE_ARMOR)); LabelNode l19 = new LabelNode(); newInstr.add(new JumpInsnNode(Opcodes.IFEQ, l19)); LabelNode l20 = new LabelNode(); newInstr.add(l20); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_FIELD110280BR)); newInstr.add(new InsnNode(Opcodes.ICONST_2)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false)); newInstr.add(new TypeInsnNode(Opcodes.CHECKCAST, ASMNames.CL_ITEM_HORSE_ARMOR)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_SAP_GET_ARMOR_TEXTURE, false)); newInstr.add(new InsnNode(Opcodes.AASTORE)); LabelNode l21 = new LabelNode(); newInstr.add(l21); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_STRING_BUILDER)); newInstr.add(new InsnNode(Opcodes.DUP)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_FIELD110286BQ)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_STRING_VALUE_OF, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_STRINGBUILDER_INIT, false)); newInstr.add(new LdcInsnNode("cst-")); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_APPEND, false)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_UNLOC_NAME, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_APPEND, false)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_TO_STRING, false)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.PUTFIELD, ASMNames.FD_HORSE_FIELD110286BQ)); newInstr.add(new InsnNode(Opcodes.RETURN)); newInstr.add(l19); method.instructions.insert(node, newInstr); }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformUpdateHorseSlots(MethodNode method) { InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_CHEST)); needle.add(new InsnNode(Opcodes.ICONST_1)); AbstractInsnNode pointer = ASMHelper.findFirstNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_CHEST)); newInstr.add(new InsnNode(Opcodes.ICONST_1)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ANIMALCHEST_GET_STACK_IN_SLOT, false));// ww w . j a va 2 s. c o m newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_SAP_SET_CUSTOM_ARMOR_ITEM, false)); newInstr.add(new LabelNode()); method.instructions.insertBefore(pointer, newInstr); }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformEntityInit(MethodNode method) { InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER)); needle.add(new IntInsnNode(Opcodes.BIPUSH, 22)); needle.add(new InsnNode(Opcodes.ICONST_0)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_INTEGER_VALUE_OF, false)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_ADD_OBJECT, false)); AbstractInsnNode pointer = ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); newInstr.add(new LabelNode()); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER)); newInstr.add(new IntInsnNode(Opcodes.BIPUSH, 23)); newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_ITEM_STACK)); newInstr.add(new InsnNode(Opcodes.DUP)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL)); newInstr.add(new InsnNode(Opcodes.ICONST_0)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_ADD_OBJECT, false)); method.instructions.insert(pointer, newInstr); }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformInteract(MethodNode method) { InsnList needle = new InsnList(); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETSTATIC, ASMNames.FD_ITEMS_DIAMOND_HORSE_ARMOR)); needle.add(new JumpInsnNode(Opcodes.IF_ACMPNE, new LabelNode())); needle.add(new LabelNode()); needle.add(new LineNumberNode(-1, new LabelNode())); needle.add(new InsnNode(Opcodes.ICONST_3)); needle.add(new VarInsnNode(Opcodes.ISTORE, 4)); needle.add(new LabelNode()); needle.add(new LineNumberNode(-1, new LabelNode())); needle.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null)); AbstractInsnNode node = ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); newInstr.add(new LabelNode()); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 2)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false)); newInstr.add(new TypeInsnNode(Opcodes.INSTANCEOF, ASMNames.CL_ITEM_HORSE_ARMOR)); LabelNode l8 = new LabelNode(); newInstr.add(new JumpInsnNode(Opcodes.IFEQ, l8)); newInstr.add(new LabelNode()); newInstr.add(new InsnNode(Opcodes.ICONST_4)); newInstr.add(new VarInsnNode(Opcodes.ISTORE, 4)); newInstr.add(l8);/*from www . j a v a2 s . com*/ newInstr.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null)); method.instructions.insert(node, newInstr); }
From source file:de.sanandrew.core.manpack.transformer.TransformPlayerDismountCtrl.java
License:Creative Commons License
/** * Transforms the EntityPlayer.class by hooking into the updateRidden method and adding a call to _SAP_canDismountOnInput * in order for the ridden entity to control whether or not the rider can dismount via sneaking. * * @param bytes the class bytes to be transformed * @return the transformed class bytes/* w w w . j av a 2s.c o m*/ */ private static byte[] transformPlayer(byte[] bytes) { ClassNode clazz = ASMHelper.createClassNode(bytes); MethodNode method = ASMHelper.findMethod(clazz, ASMNames.MD_PLAYER_UPDATE_RIDDEN); InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_PLAYER_WORLD_OBJ)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_WORLD_IS_REMOTE)); LabelNode ln1 = new LabelNode(); needle.add(new JumpInsnNode(Opcodes.IFNE, ln1)); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_PLAYER_IS_SNEAKING, false)); needle.add(new JumpInsnNode(Opcodes.IFEQ, ln1)); AbstractInsnNode insertPoint = ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList injectList = new InsnList(); injectList.add(new VarInsnNode(Opcodes.ALOAD, 0)); injectList.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_PLAYER_RIDING_ENTITY)); injectList.add(new VarInsnNode(Opcodes.ALOAD, 0)); injectList.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_SAP_CAN_DISMOUNT_ON_INPUT, false)); injectList.add(new JumpInsnNode(Opcodes.IFEQ, ((JumpInsnNode) insertPoint).label)); method.instructions.insert(insertPoint, injectList); bytes = ASMHelper.createBytes(clazz, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS); return bytes; }
From source file:de.tuberlin.uebb.jbop.access.ConstructorBuilder.java
License:Open Source License
/** * Gets the unboxing node./*from ww w .j a v a2 s . c om*/ * * @param field * the field * @return the unboxing node */ public static AbstractInsnNode getUnboxingNode(final FieldNode field) { final AbstractInsnNode unboxing; final Type type = Type.getType(field.desc); final int sort = type.getSort(); if (sort == Type.INT) { unboxing = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Integer.class), "intValue", "()I"); } else if (sort == Type.LONG) { unboxing = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Long.class), "longValue", "()J"); } else if (sort == Type.FLOAT) { unboxing = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Float.class), "intValue", "()F"); } else if (sort == Type.DOUBLE) { unboxing = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Double.class), "doubleValue", "()D"); } else if (sort == Type.BOOLEAN) { unboxing = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Boolean.class), "booleanValue", "()Z"); } else if (sort == Type.SHORT) { unboxing = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Short.class), "shortValue", "()S"); } else if (sort == Type.CHAR) { unboxing = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Character.class), "charValue", "()C"); } else if (sort == Type.BYTE) { unboxing = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Byte.class), "byteValue", "()B"); } else { unboxing = null; } return unboxing; }
From source file:de.tuberlin.uebb.jbop.optimizer.methodsplitter.Block.java
License:Open Source License
/** * Objects that are not parameters and not written before * these can be:/*from ww w . j a va 2 s. c o m*/ * getField * getStatic * new * new array * new multi array * return type of method call */ private Type resolveType(final AbstractInsnNode node) { int arrayCount = 0; AbstractInsnNode currentNode = NodeHelper.getPrevious(node); while (currentNode != null) { final int opcode2 = currentNode.getOpcode(); if (opcode2 == Opcodes.NEWARRAY) { final int operand = ((IntInsnNode) currentNode).operand; return getObjectType(operand); } else if (opcode2 == Opcodes.ANEWARRAY) { return getObjectType(((TypeInsnNode) currentNode).desc); } else if (opcode2 == Opcodes.MULTIANEWARRAY) { return getObjectType(((MultiANewArrayInsnNode) currentNode).desc); } else if (opcode2 == Opcodes.NEW) { final String desc = ((TypeInsnNode) currentNode).desc; return getObjectType(desc); } else if ((opcode2 >= Opcodes.IALOAD) && (opcode2 <= Opcodes.AALOAD)) { arrayCount++; } else if ((opcode2 == Opcodes.GETFIELD) || (opcode2 == Opcodes.GETSTATIC)) { final String desc = ((FieldInsnNode) currentNode).desc; return getObjectType(removeArrayType(desc, arrayCount)); } else if ((opcode2 == Opcodes.ALOAD)) { final Type type2 = readers.getFirstVar(((VarInsnNode) currentNode).var).getParameterType(); return getObjectType(removeArrayType(type2.getDescriptor(), arrayCount)); } else if ((opcode2 >= Opcodes.INVOKEVIRTUAL) && (opcode2 <= Opcodes.INVOKEDYNAMIC)) { return Type.getReturnType(((MethodInsnNode) currentNode).desc); } currentNode = NodeHelper.getPrevious(currentNode); } return Type.VOID_TYPE; }
From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java
License:Open Source License
public void visitCode() { if (!methodName.equals("<clinit>") && (instrumentLine || instrumentReturns)) { // System.out.println(className + "." + methodName); this.visitMethodInsn(Opcodes.INVOKESTATIC, CoverageProperties.TRACER_CLASS_NAME, "getInstance", "()L" + CoverageProperties.TRACER_CLASS_NAME + ";"); this.visitLdcInsn(className); this.visitLdcInsn(methodName); this.visitLdcInsn(instrumentLine); this.visitLdcInsn(instrumentReturns); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CoverageProperties.TRACER_CLASS_NAME, "begin", "(Ljava/lang/String;Ljava/lang/String;ZZ)V"); }//from ww w. jav a 2 s . c o m super.visitCode(); }
From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java
License:Open Source License
public void visitLineNumber(int line, Label start) { if (!methodName.equals("<clinit>") && instrumentLine) { this.visitMethodInsn(Opcodes.INVOKESTATIC, CoverageProperties.TRACER_CLASS_NAME, "getInstance", "()L" + CoverageProperties.TRACER_CLASS_NAME + ";"); this.visitLdcInsn(line); this.visitLdcInsn(className); this.visitLdcInsn(methodName); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CoverageProperties.TRACER_CLASS_NAME, "logLineNumber", "(ILjava/lang/String;Ljava/lang/String;)V"); }/*from www. jav a 2s . c o m*/ super.visitLineNumber(line, start); }
From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java
License:Open Source License
private void callLogPrototype(String traceMethod, PDType type) { if (type != PDType.LONG && type != PDType.DOUBLE) { this.visitInsn(Opcodes.DUP); if (type == PDType.FLOAT) { this.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "floatToRawIntBits", "(F)I"); }/* ww w . j a v a 2 s.c o m*/ } else { this.visitInsn(Opcodes.DUP2); if (type == PDType.DOUBLE) { this.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "doubleToRawLongBits", "(D)J"); } this.visitInsn(Opcodes.DUP2); this.visitIntInsn(Opcodes.BIPUSH, 32); this.visitInsn(Opcodes.LSHR); this.visitInsn(Opcodes.LXOR); this.visitInsn(Opcodes.L2I); } this.visitMethodInsn(Opcodes.INVOKESTATIC, CoverageProperties.TRACER_CLASS_NAME, "getInstance", "()L" + CoverageProperties.TRACER_CLASS_NAME + ";"); this.visitInsn(Opcodes.SWAP); this.visitLdcInsn(className); this.visitLdcInsn(methodName); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CoverageProperties.TRACER_CLASS_NAME, traceMethod, "(ILjava/lang/String;Ljava/lang/String;)V"); }