Java Code Examples for org.objectweb.asm.tree.MethodNode#visitVarInsn()
The following examples show how to use
org.objectweb.asm.tree.MethodNode#visitVarInsn() .
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: EngineExtender.java From 07kit with GNU General Public License v3.0 | 6 votes |
public MethodNode createGetter(GetterDefinition getter) { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, getter.name, "()" + getter.signature, null, null); if (getter.member) { method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, getter.fieldClass, getter.fieldName, getter.actualSig); } else { method.visitFieldInsn(Opcodes.GETSTATIC, getter.fieldClass, getter.fieldName, getter.actualSig); } if (getter.multiplier != 0) { method.visitLdcInsn((int) getter.multiplier); method.visitInsn(Opcodes.IMUL); } method.visitInsn(Type.getType(getter.actualSig).getOpcode(Opcodes.IRETURN)); method.visitMaxs(1, 1); method.visitEnd(); return method; }
Example 2
Source File: EngineExtender.java From 07kit with GNU General Public License v3.0 | 6 votes |
public MethodNode createSetter(GetterDefinition getter) { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, getter.name.replaceFirst("get", "set"), "(" + getter.signature + ")V", null, null); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Type.getType(getter.actualSig).getOpcode(Opcodes.ILOAD), 1); if (getter.actualSig.equals("I") && getter.multiplier != 0) { method.visitLdcInsn((int) modInverse(getter.multiplier)); method.visitInsn(Opcodes.IMUL); } if (getter.member) { method.visitFieldInsn(Opcodes.PUTFIELD, getter.fieldClass, getter.fieldName, getter.actualSig); } else { method.visitFieldInsn(Opcodes.PUTSTATIC, getter.fieldClass, getter.fieldName, getter.actualSig); } method.visitInsn(Opcodes.RETURN); method.visitMaxs(1, 1); method.visitEnd(); return method; }
Example 3
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 4
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 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: InstrumentUtil.java From jumbune with GNU Lesser General Public License v3.0 | 5 votes |
/** * This method inserts a LogUtil method call in class. This LogUtil method * calls PatternMatcher.match(Writable) method. The match method takes only * writable object since the regEx given by user is null. So it doesn't * requires Pattern object. * * @param logBean * LogInfoBean object that contains information related to * logging * @param variableIndex * index of writable object to be matched against null * @param methodNode * - method which holds context.write either map/reduce * @param logKeyValues * check if user wants to log unmatched key/values * @return InstructionList containing instructions for inserting statement * LogUtil.getRegexInfo("msg" + PatternMatcher.match(writableVal)); */ public static InsnList addRegExMatcherClassCall(LogInfoBean logBean, int variableIndex, MethodNode methodNode, boolean logKeyValues) { // If using context use this else not String logMethodDesc; if (logKeyValues) { logMethodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, Type.BOOLEAN_TYPE, TYPE_OBJECT, TYPE_OBJECT); } else { logMethodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, Type.BOOLEAN_TYPE); } InsnList il = createBasicLoggerInsns(logBean); il.add(new VarInsnNode(Opcodes.ALOAD, variableIndex)); // Calling the method PatternMatcher.match il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, InstrumentConstants.CLASSNAME_PATTERNMATCHER, InstrumentConstants.REGEX_METHOD_NAME, InstrumentConstants.REGEX_NULL_METHOD_DESC)); if (logKeyValues) { il.add(new VarInsnNode(Opcodes.ALOAD, variableIndex)); methodNode.visitVarInsn(Opcodes.ASTORE, 1); il.add(new VarInsnNode(Opcodes.ALOAD, 1)); } il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, InstrumentConstants.CLASSNAME_LOGUTIL, InstrumentConstants.REGEX_LOG_METHOD, logMethodDesc)); return il; }
Example 8
Source File: TrashCodeTransformer.java From obfuscator with MIT License | 4 votes |
@NotNull private MethodNode createMethod() { final MethodNode methodNode = new MethodNode((RandomUtil.nextInt(2) == 1 ? ACC_PUBLIC | ACC_STATIC : ACC_PRIVATE | ACC_STATIC), StringUtil.generateString(RandomUtil.nextInt(16) + 2), "()V", null, null); methodNode.visitCode(); final Label label0 = new Label(); methodNode.visitLabel(label0); methodNode.visitLineNumber(8, label0); methodNode.visitInsn(ICONST_0); methodNode.visitVarInsn(ISTORE, 0); final AtomicInteger index = new AtomicInteger(10); final Label label1 = new Label(); methodNode.visitLabel(label1); methodNode.visitLineNumber(index.getAndIncrement(), label1); methodNode.visitVarInsn(ILOAD, 0); methodNode.visitLdcInsn(300000); methodNode.visitInsn(IADD); methodNode.visitVarInsn(ISTORE, 0); IntStream.range(0, RandomUtil.nextInt(216) + 1).mapToObj(i -> new Label()).forEachOrdered(label2 -> { methodNode.visitLabel(label2); methodNode.visitLineNumber(index.getAndIncrement(), label2); methodNode.visitVarInsn(ILOAD, 0); methodNode.visitLdcInsn(300000); methodNode.visitInsn(IADD); methodNode.visitVarInsn(ISTORE, 0); }); final Label label3 = new Label(); methodNode.visitLabel(label3); methodNode.visitLineNumber(66, label3); methodNode.visitInsn(RETURN); final Label label58 = new Label(); methodNode.visitLabel(label58); methodNode.visitLocalVariable("i", "I", null, label1, label58, 0); methodNode.visitMaxs(2, 1); methodNode.visitEnd(); return methodNode; }
Example 9
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 10
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); } }
Example 11
Source File: InstrumentUtil.java From jumbune with GNU Lesser General Public License v3.0 | 4 votes |
/** * This method creates a LogUtil.getRegExInfo() method call which takes in * parameter a boolean. To get this boolean user's validator class * isPatternValid method is called which takes in input the the * variableIndex defined. So below instruction is constructed: * * LogUtil.getRegExInfo(callingClass, callingMethod, logLevel, message, * keyValidator.isPatternValid(tempKey)); * * LogUtil.getRegExInfo(callingClass, callingMethod, logLevel, message, * valueValidator.isPatternValid(tempValue)); * * @param logBean * - Bean containing information to be used for logging like * callingClass, methodName, message * * @param variableIndex * - index of the temporary variable which stores value of either * key/value to be matched * @param validatorFieldName * - name of the field which is of type Validator class and is to * be used to call the isPatternValidate * @param validatorClass * - validator class * @param classQualifiedName the classQualifiedName * @param methodNode method which is currently being traversed * @return InstructionList to add instructions for calling * LogUtil.getRegExinfo(..) */ public static InsnList addLoggerWithClassMethodCall(LogInfoBean logBean, int variableIndex, String validatorFieldName, String validatorClass, String classQualifiedName, MethodNode methodNode, boolean logKeyValues) { String logMethodDesc; if (logKeyValues) { logMethodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, Type.BOOLEAN_TYPE, TYPE_OBJECT, TYPE_OBJECT); } else { logMethodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, Type.BOOLEAN_TYPE); } InsnList il = new InsnList(); il.add(createBasicLoggerInsns(logBean)); il.add(new VarInsnNode(Opcodes.ALOAD, 0)); // Loading field of type of the class specified for validating key/value il.add(new FieldInsnNode(Opcodes.GETFIELD, ConfigurationUtil .convertQualifiedClassNameToInternalName(classQualifiedName), validatorFieldName, InstrumentConstants.DESCRIPTOR_PATTERNVALIDATOR)); il.add(new VarInsnNode(Opcodes.ALOAD, variableIndex)); // Calling the method PatternMatcher.match il.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, InstrumentConstants.CLASSNAME_PATTERNVALIDATOR, InstrumentConstants.USER_PATTERN_VALIDATOR_METHOD_NAME, InstrumentConstants.DESCRIPTOR_PATTERNVALIDATOR_ISPATTERNVALID)); if (logKeyValues) { il.add(new VarInsnNode(Opcodes.ALOAD, variableIndex)); methodNode.visitVarInsn(Opcodes.ASTORE, 1); il.add(new VarInsnNode(Opcodes.ALOAD, 1)); } il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, CLASSNAME_LOGUTIL, InstrumentConstants.REGEX_LOG_METHOD, logMethodDesc)); return il; }
Example 12
Source File: InstrumentUtil.java From jumbune with GNU Lesser General Public License v3.0 | 4 votes |
/** * This method calls a method match of class PatternMatcher to match * key/value against given pattern. The call to class method and printing * the result is done in log statement. i.e. the resultant method call is * Logger.info("Result " + PatternMatcher.match(valueToBeCompared, * regularExpression) + " "); These strings are appended in StringBuilder * and this StringBuilder is passed in Logger. * * @param mn * @param regEx * @param variableIndex * @param variableType * - The type of variable against which regular expression has to * be done. It should be a fully qualified name of class of * variable. E.g. if String value is to be matched then * variableType should be "java/lang/String;" * @return */ public static InsnList addRegExMatcherClassCall(LogInfoBean logBean, int variableIndex, String pattern, String classQualifiedName, MethodNode methodNode, boolean logKeyValues) { // If using context use this else not String logMethodDesc; if (logKeyValues) { logMethodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, Type.BOOLEAN_TYPE, TYPE_OBJECT, TYPE_OBJECT); } else { logMethodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, Type.BOOLEAN_TYPE); } InsnList il = createBasicLoggerInsns(logBean); il.add(new VarInsnNode(Opcodes.ALOAD, variableIndex)); il.add(new VarInsnNode(Opcodes.ALOAD, 0)); il.add(new FieldInsnNode(Opcodes.GETFIELD, ConfigurationUtil .convertQualifiedClassNameToInternalName(classQualifiedName), pattern, InstrumentConstants.DESCRIPTOR_PATTERN)); // Calling the method PatternMatcher.match il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, InstrumentConstants.CLASSNAME_PATTERNMATCHER, InstrumentConstants.REGEX_METHOD_NAME, InstrumentConstants.REGEX_METHOD_DESC)); if (logKeyValues) { il.add(new VarInsnNode(Opcodes.ALOAD, variableIndex)); methodNode.visitVarInsn(Opcodes.ASTORE, 1); il.add(new VarInsnNode(Opcodes.ALOAD, 1)); } il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, InstrumentConstants.CLASSNAME_LOGUTIL, InstrumentConstants.REGEX_LOG_METHOD, logMethodDesc)); return il; }