Java Code Examples for org.objectweb.asm.tree.MethodNode#visitMethodInsn()
The following examples show how to use
org.objectweb.asm.tree.MethodNode#visitMethodInsn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MarkerTransformer.java From obfuscator with MIT License | 6 votes |
private MethodNode createMethod() { final MethodNode methodNode = new MethodNode(ACC_PUBLIC | ACC_STATIC, methodName, "()V", null, null); methodNode.visitCode(); final Label label0 = new Label(); methodNode.visitLabel(label0); methodNode.visitLineNumber(10, label0); methodNode.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); methodNode.visitLdcInsn(text); methodNode.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); final Label label1 = new Label(); methodNode.visitLabel(label1); methodNode.visitLineNumber(11, label1); methodNode.visitInsn(RETURN); methodNode.visitMaxs(2, 0); methodNode.visitEnd(); return methodNode; }
Example 2
Source File: ConstructorThisInterpreterTest.java From AVM with MIT License | 5 votes |
private MethodNode buildTestConstructor() { MethodNode methodVisitor = new MethodNode(Opcodes.ACC_PUBLIC, "<init>", "(Lorg/aion/avm/core/persistence/ConstructorThisInterpreterTest;I)V", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); methodVisitor.visitInsn(Opcodes.ICONST_5); methodVisitor.visitVarInsn(Opcodes.ILOAD, 2); Label label2 = new Label(); methodVisitor.visitJumpInsn(Opcodes.IF_ICMPNE, label2); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); Label label3 = new Label(); methodVisitor.visitJumpInsn(Opcodes.GOTO, label3); methodVisitor.visitLabel(label2); methodVisitor.visitFrame(Opcodes.F_FULL, 3, new Object[] {"org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", Opcodes.INTEGER}, 0, new Object[] {}); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitLabel(label3); methodVisitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"org/aion/avm/core/persistence/ConstructorThisInterpreterTest"}); methodVisitor.visitVarInsn(Opcodes.ILOAD, 2); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "bar", "I"); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitInsn(Opcodes.ICONST_1); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "bar", "I"); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitInsn(Opcodes.ICONST_2); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "bar", "I"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(2, 3); methodVisitor.visitEnd(); return methodVisitor; }
Example 3
Source File: ConstructorThisInterpreterTest.java From AVM with MIT License | 5 votes |
private MethodNode buildSecondConstructor() { MethodNode methodVisitor = new MethodNode(Opcodes.ACC_PUBLIC, "<init>", "(Lorg/aion/avm/core/NonStaticInnerClassTarget$Inner;)V", null, null); methodVisitor.visitCode(); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/NonStaticInnerClassTarget$Inner$Deeper", "this$1", "Lorg/aion/avm/core/NonStaticInnerClassTarget$Inner;"); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(2, 2); methodVisitor.visitEnd(); return methodVisitor; }
Example 4
Source File: NbJShellAgent.java From netbeans with Apache License 2.0 | 5 votes |
/** * Transforms an existin <clinit> method. Adds bytecode before the return, if * exists. * @param className * @param target */ private void transformClassInit(String className, MethodNode target) { Type classType = Type.getObjectType(className); if (target.instructions.size() > 0) { if (target.instructions.getLast().getOpcode() == Opcodes.RETURN) { target.instructions.remove(target.instructions.getLast()); } } // ldc target.visitLdcInsn(classType); // invokevirtual --> classloader on stack target.visitMethodInsn( Opcodes.INVOKEVIRTUAL, JAVA_LANG_CLASS, CLASS_GET_CLASSLODER_METHOD, CLASS_GET_CLASSLOADER_DESC, false ); // putstatic target.visitFieldInsn( Opcodes.PUTSTATIC, AGENT_CLASS, AGENT_CLASSLOADER_FIELD, AGENT_CLASSLOADER_DESC ); target.visitInsn(Opcodes.RETURN); // ldc || classloader instance target.maxStack = Math.max(target.maxStack, 1); target.maxLocals = Math.max(target.maxLocals, 1); target.visitEnd(); }
Example 5
Source File: TransformerInvokerGenerator.java From Diorite with MIT License | 5 votes |
public static int generateFieldInjection(ControllerClassData classData, ControllerFieldData<?> fieldData, MethodNode mv, int lineNumber, PlaceholderType placeholderType) { AbstractInsnNode[] result = new AbstractInsnNode[2]; FieldDescription.InDefinedShape member = fieldData.getMember(); TypeDescription fieldType = member.getType().asErasure(); boolean isStatic = member.isStatic(); lineNumber = AsmUtils.printLineNumber(mv, lineNumber); if (isStatic) { mv.visitInsn(ACONST_NULL); } else { mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); } AsmUtils.storeInt(mv, classData.getIndex()); AsmUtils.storeInt(mv, fieldData.getIndex()); switch (placeholderType) { case INVALID: case UNKNOWN: default: throw new IllegalStateException("Can't generate injection for invalid placeholders."); case NONNULL: mv.visitInsn(ICONST_1); break; case NULLABLE: mv.visitInsn(ICONST_0); break; } mv.visitMethodInsn(INVOKESTATIC, INJECTOR_CLASS, INJECTOR_FIELD, INJECTOR_FIELD_DESC, false); return lineNumber; }
Example 6
Source File: TransformerInvokerGenerator.java From Diorite with MIT License | 5 votes |
public static int printMethod(MethodNode mv, String clazz, String method, boolean isStatic, int lineNumber) { lineNumber = AsmUtils.printLineNumber(mv, lineNumber); if (isStatic) { mv.visitMethodInsn(INVOKESTATIC, clazz, method, "()V", false); } else { mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, clazz, method, "()V", false); } return lineNumber; }
Example 7
Source File: AntiDebugTransformer.java From obfuscator with MIT License | 4 votes |
@NotNull private MethodNode createMethod(@NotNull ClassNode classNode) { final MethodNode methodNode = new MethodNode(ACC_PRIVATE | ACC_STATIC, "checkDebug", "()V", null, null); methodNode.visitCode(); final Label label0 = new Label(); methodNode.visitLabel(label0); methodNode.visitLineNumber(11, label0); methodNode.visitMethodInsn(INVOKESTATIC, "java/lang/management/ManagementFactory", "getRuntimeMXBean", "()Ljava/lang/management/RuntimeMXBean;", false); methodNode.visitMethodInsn(INVOKEINTERFACE, "java/lang/management/RuntimeMXBean", "getInputArguments", "()Ljava/util/List;", true); methodNode.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "iterator", "()Ljava/util/Iterator;", true); methodNode.visitVarInsn(ASTORE, 1); final Label label1 = new Label(); methodNode.visitLabel(label1); methodNode.visitFrame(F_APPEND, 1, new Object[]{"java/util/Iterator"}, 0, null); methodNode.visitVarInsn(ALOAD, 1); methodNode.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true); final Label label2 = new Label(); methodNode.visitJumpInsn(IFEQ, label2); methodNode.visitVarInsn(ALOAD, 1); methodNode.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;", true); methodNode.visitTypeInsn(CHECKCAST, "java/lang/String"); methodNode.visitVarInsn(ASTORE, 2); final Label label3 = new Label(); methodNode.visitLabel(label3); methodNode.visitLineNumber(12, label3); methodNode.visitVarInsn(ALOAD, 2); final String debugType = debugTypes[RandomUtil.nextInt(debugTypes.length)]; methodNode.visitLdcInsn(debugType == null ? debugTypes[0] : debugType); methodNode.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "startsWith", "(Ljava/lang/String;)Z", false); final Label label4 = new Label(); methodNode.visitJumpInsn(IFEQ, label4); final Label label5 = new Label(); methodNode.visitLabel(label5); methodNode.visitLineNumber(13, label5); methodNode.visitIntInsn(SIPUSH, 666); methodNode.visitMethodInsn(INVOKESTATIC, "java/lang/System", "exit", "(I)V", false); methodNode.visitLabel(label4); methodNode.visitLineNumber(15, label4); methodNode.visitFrame(F_SAME, 0, null, 0, null); methodNode.visitJumpInsn(GOTO, label1); methodNode.visitLabel(label2); methodNode.visitLineNumber(16, label2); methodNode.visitFrame(F_CHOP, 1, null, 0, null); methodNode.visitInsn(RETURN); final Label label6 = new Label(); methodNode.visitLabel(label6); methodNode.visitLocalVariable("string", "Ljava/lang/String;", null, label3, label4, 2); methodNode.visitLocalVariable("this", "L" + classNode.name + ";", null, label0, label6, 0); methodNode.visitMaxs(2, 3); methodNode.visitEnd(); return methodNode; }
Example 8
Source File: TransformerInvokerGenerator.java From Diorite with MIT License | 4 votes |
public static void generateMethodInjection(ControllerClassData classData, ControllerMethodData methodData, MethodNode mv, boolean printMethods, int lineNumber) { MethodDescription.InDefinedShape member = methodData.getMember(); boolean isStatic = member.isStatic(); if (printMethods) { lineNumber = printMethods(mv, classData.getType().getInternalName(), methodData.getBefore(), isStatic, lineNumber); } lineNumber = AsmUtils.printLineNumber(mv, lineNumber); if (! isStatic) { mv.visitVarInsn(ALOAD, 0); } for (InjectValueData<?, Generic> valueData : methodData.getInjectValues()) { if (isStatic) { mv.visitInsn(ACONST_NULL); } else { mv.visitVarInsn(ALOAD, 0); } AsmUtils.storeInt(mv, classData.getIndex()); AsmUtils.storeInt(mv, methodData.getIndex()); AsmUtils.storeInt(mv, valueData.getIndex()); mv.visitInsn(ICONST_0); // skip null checks in methods. lineNumber = AsmUtils.printLineNumber(mv, lineNumber); mv.visitMethodInsn(INVOKESTATIC, INJECTOR_CLASS, INJECTOR_METHOD, INJECTOR_METHOD_DESC, false); TypeDescription paramType = valueData.getType().asErasure(); mv.visitTypeInsn(CHECKCAST, paramType.getInternalName()); // skip cast check? } lineNumber = AsmUtils.printLineNumber(mv, lineNumber); if (isStatic) { mv.visitMethodInsn(INVOKESTATIC, classData.getType().getInternalName(), member.getName(), member.getDescriptor(), false); } else { mv.visitMethodInsn(INVOKESPECIAL, classData.getType().getInternalName(), member.getName(), member.getDescriptor(), false); } if (printMethods) { printMethods(mv, classData.getType().getInternalName(), methodData.getAfter(), isStatic, lineNumber); } }