List of usage examples for org.objectweb.asm Opcodes INVOKESTATIC
int INVOKESTATIC
To view the source code for org.objectweb.asm Opcodes INVOKESTATIC.
Click Source Link
From source file:eu.activelogic.instrumentor.thread.vm.ThreadConstructorAdviceCreator.java
License:Apache License
@Override protected void onMethodExit(int opCode) { if (opCode == Opcodes.ATHROW) return;/*from ww w . ja v a2s.co m*/ mv.visitVarInsn(Opcodes.ALOAD, 0); if (runnableIndex < 0) mv.visitInsn(Opcodes.ACONST_NULL); else mv.visitVarInsn(Opcodes.ALOAD, runnableIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(ThreadInterceptor.class), CREATE_THREAD_METHOD, CREATE_THREAD_METHOD_SIG, false); }
From source file:eu.activelogic.instrumentor.thread.vm.ThreadStartAdviceCreator.java
License:Apache License
@Override protected void onMethodEnter() { mv.visitVarInsn(Opcodes.ALOAD, 0);//from ww w. j a va2 s . c om mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(ThreadInterceptor.class), START_METHOD, START_METHOD_SIG, false); }
From source file:fr.insalyon.telecom.jooflux.InvokeMethodTransformer.java
License:Mozilla Public License
private boolean isInvokeStatic(MethodInsnNode methodInsnNode) { return methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC; }
From source file:fr.theshark34.feelcraft.FeelcraftClassTransformer.java
License:Apache License
/** * Patchs the Minecraft class/*from w w w.j av a 2s .c o m*/ * * @param name * The class name * @param bytes * The initial class bytes * @param obfuscated * If the class is obfuscated * @return The modified bytes */ public byte[] patchClassASM(String name, byte[] bytes, boolean obfuscated) { // Starting the pre init Feelcraft.preInit(); // Printing messages logger.info("[Feelcraft] Starting patching Minecraft"); logger.info("[Feelcraft] Target class : " + name); // Getting the target method if the game is obfuscated or not String targetMethod; if (obfuscated) targetMethod = "ag"; else targetMethod = "startGame"; // Getting the class nod and reading the initial class ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(bytes); classReader.accept(classNode, 0); // Just a boolean that will be true if the patch will be done to check // if it was done boolean patchDone = false; // Getting the class methods Iterator<MethodNode> methods = classNode.methods.iterator(); // For each method in the class while (methods.hasNext()) { // Getting the method MethodNode m = methods.next(); // If the method is our target method if ((m.name.equals(targetMethod) && m.desc.equals("()V"))) { // Printing a message logger.info("[Feelcraft] Patching method : " + m.name + m.desc); // Insert a line that will call Feelcraft.start at the top of // the method m.instructions.insertBefore(m.instructions.getFirst(), new MethodInsnNode(Opcodes.INVOKESTATIC, "fr/theshark34/feelcraft/Feelcraft", "start", "()V", false)); // Setting patchDone to true patchDone = true; // Stopping the loop break; } } // If the patch wasn't done if (!patchDone) // Printing a warning message logger.warn("[Feelcraft] Warning the patch wasn't done ! Some things will not going to work !"); // Writing the patched class logger.info("[Feelcraft] Writing the patched class"); ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); // Printing a done message if (patchDone) logger.info("[Feelcraft] Successfully patched Minecraft !"); else logger.info("[Feelcraft] Done"); // Returning the modified bytes return writer.toByteArray(); }
From source file:gemlite.core.internal.measurement.MeasureHelper.java
License:Apache License
public final static void instrumentCheckPoint(String className, MethodNode mn) { if (LogUtil.getCoreLog().isTraceEnabled()) LogUtil.getCoreLog().trace("Found check point, class:" + className + " method:" + mn.name); InsnList insn = mn.instructions;// w w w . ja v a2 s.c o m List<AbstractInsnNode> returnIndex = new ArrayList<>(); // return int localVarCount = mn.localVariables.size(); for (int i = 0; i < insn.size(); i++) { AbstractInsnNode insnNode = (AbstractInsnNode) insn.get(i); switch (insnNode.getOpcode()) { case Opcodes.ARETURN: case Opcodes.IRETURN: case Opcodes.DRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: returnIndex.add(insnNode.getPrevious()); break; case Opcodes.RETURN: returnIndex.add(insnNode); break; } } // insn.insert(new VarInsnNode(Opcodes.LSTORE, localVarCount + 2)); insn.insert( new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false)); // ? for (AbstractInsnNode insnNode : returnIndex) { insn.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false)); insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LSTORE, localVarCount + 4)); insn.insertBefore(insnNode, new LdcInsnNode(className)); insn.insertBefore(insnNode, new LdcInsnNode(mn.name)); insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LLOAD, localVarCount + 2)); insn.insertBefore(insnNode, new VarInsnNode(Opcodes.LLOAD, localVarCount + 4)); insn.insertBefore(insnNode, new MethodInsnNode(Opcodes.INVOKESTATIC, "gemlite/core/internal/measurement/MeasureHelper", "recordCheckPoint", "(Ljava/lang/String;Ljava/lang/String;JJ)V", false)); } }
From source file:gnu.classpath.tools.rmic.ClassRmicCompiler.java
License:Open Source License
private static void generateClassForNamer(ClassVisitor cls) { MethodVisitor cv = cls.visitMethod(Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC, forName,//w w w.ja v a 2 s .com Type.getMethodDescriptor(Type.getType(Class.class), new Type[] { Type.getType(String.class) }), null, null); Label start = new Label(); cv.visitLabel(start); cv.visitVarInsn(Opcodes.ALOAD, 0); cv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Class.class), "forName", Type.getMethodDescriptor(Type.getType(Class.class), new Type[] { Type.getType(String.class) })); cv.visitInsn(Opcodes.ARETURN); Label handler = new Label(); cv.visitLabel(handler); cv.visitVarInsn(Opcodes.ASTORE, 1); cv.visitTypeInsn(Opcodes.NEW, typeArg(NoClassDefFoundError.class)); cv.visitInsn(Opcodes.DUP); cv.visitVarInsn(Opcodes.ALOAD, 1); cv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(ClassNotFoundException.class), "getMessage", Type.getMethodDescriptor(Type.getType(String.class), new Type[] {})); cv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(NoClassDefFoundError.class), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(String.class) })); cv.visitInsn(Opcodes.ATHROW); cv.visitTryCatchBlock(start, handler, handler, Type.getInternalName(ClassNotFoundException.class)); cv.visitMaxs(-1, -1); }
From source file:gnu.classpath.tools.rmic.ClassRmicCompiler.java
License:Open Source License
private void generateClassConstant(MethodVisitor cv, Class cls) { if (cls.isPrimitive()) { Class boxCls;/*from w ww .j a v a 2 s . c o m*/ if (cls.equals(Boolean.TYPE)) boxCls = Boolean.class; else if (cls.equals(Character.TYPE)) boxCls = Character.class; else if (cls.equals(Byte.TYPE)) boxCls = Byte.class; else if (cls.equals(Short.TYPE)) boxCls = Short.class; else if (cls.equals(Integer.TYPE)) boxCls = Integer.class; else if (cls.equals(Long.TYPE)) boxCls = Long.class; else if (cls.equals(Float.TYPE)) boxCls = Float.class; else if (cls.equals(Double.TYPE)) boxCls = Double.class; else if (cls.equals(Void.TYPE)) boxCls = Void.class; else throw new IllegalArgumentException("unknown primitive type " + cls); cv.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(boxCls), "TYPE", Type.getDescriptor(Class.class)); return; } cv.visitLdcInsn(cls.getName()); cv.visitMethodInsn(Opcodes.INVOKESTATIC, classInternalName, forName, Type.getMethodDescriptor(Type.getType(Class.class), new Type[] { Type.getType(String.class) })); }
From source file:hellfirepvp.astralsorcery.core.patch.fix.CraftingTableFix.java
License:Open Source License
@Override public void patch(ClassNode cn) { MethodNode mn = getMethod(cn, "onBlockActivated", "func_180639_a", "(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/util/EnumHand;Lnet/minecraft/util/EnumFacing;FFF)Z"); AbstractInsnNode newNode = findFirstInstruction(mn, Opcodes.NEW).getPrevious(); int index = mn.instructions.indexOf(newNode); //for (int i = 0; i < 7; i++) { // mn.instructions.remove(mn.instructions.get(index)); //}/* w ww . ja va2 s. c o m*/ AbstractInsnNode insertPrev = mn.instructions.get(index); mn.instructions.insertBefore(insertPrev, new VarInsnNode(Opcodes.ALOAD, 4)); mn.instructions.insertBefore(insertPrev, new VarInsnNode(Opcodes.ALOAD, 2)); mn.instructions.insertBefore(insertPrev, new MethodInsnNode(Opcodes.INVOKESTATIC, "hellfirepvp/astralsorcery/common/network/packet/server/PktCraftingTableFix", "sendOpenCraftingTable", "(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/util/math/BlockPos;)V", false)); }
From source file:hellfirepvp.astralsorcery.core.patch.helper.PatchCatchCustomPayload.java
License:Open Source License
@Override public void patch(ClassNode cn) { //MethodNode mn = getMethod(cn, "handleCustomPayload", "func_147240_a", "(Lnet/minecraft/network/play/server/SPacketCustomPayload;)V"); //AbstractInsnNode aisn = findFirstInstruction(mn, Opcodes.ALOAD); //Skip the first few setup label things, however still be before everything. MethodNode mn = getMethod(cn, "handleCustomPayload", "func_147240_a", "(Lnet/minecraft/network/play/server/SPacketCustomPayload;)V"); AbstractInsnNode asisn = findFirstInstruction(mn, Opcodes.INVOKESTATIC).getNext(); mn.instructions.insertBefore(asisn, new VarInsnNode(Opcodes.ALOAD, 1)); mn.instructions.insertBefore(asisn,//from w w w.j a va 2 s. c o m new MethodInsnNode(Opcodes.INVOKESTATIC, "hellfirepvp/astralsorcery/common/event/listener/EventHandlerNetwork", "clientCatchWorldHandlerPayload", "(Lnet/minecraft/network/play/server/SPacketCustomPayload;)V", false)); //mn.instructions.insert(asisn, new MethodInsnNode(Opcodes.INVOKESTATIC, "hellfirepvp/astralsorcery/common/event/listener/EventHandlerNetwork", "clientCatchWorldHandlerPayload", "(Lnet/minecraft/network/play/server/SPacketCustomPayload;)V", false)); }
From source file:hellfirepvp.astralsorcery.core.patch.helper.PatchKeyboardEvent.java
License:Open Source License
@Override public void patch(ClassNode cn) { MethodNode mn = getMethod(cn, "runTick", "func_71407_l", "()V"); MethodInsnNode m = getFirstMethodCall(mn, "net/minecraft/client/Minecraft", "runTickKeyboard", "func_184118_az", "()V"); m.setOpcode(Opcodes.INVOKESTATIC); m.owner = "hellfirepvp/astralsorcery/common/event/ClientKeyboardInputEvent"; m.name = "fireKeyboardEvent"; m.desc = "(Lnet/minecraft/client/Minecraft;)V"; }