Java Code Examples for org.objectweb.asm.tree.InsnList#add()
The following examples show how to use
org.objectweb.asm.tree.InsnList#add() .
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: ChunkRenderDispatcherPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Insert hook before buffer is uploaded") public void inject(MethodNode main) { AbstractInsnNode node = ASMHelper.findPattern( main.instructions.getFirst(), new int[]{ INVOKESTATIC, IFEQ, 0x00, 0x00, ALOAD, }, "xx??x"); Objects.requireNonNull(node, "Find pattern failed for node"); InsnList insnList = new InsnList(); insnList.add(new VarInsnNode(ALOAD, 3)); insnList.add(new VarInsnNode(ALOAD, 2)); insnList.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onChunkUploaded)); main.instructions.insertBefore(node, insnList); }
Example 2
Source File: InstrumentUtil.java From jumbune with GNU Lesser General Public License v3.0 | 6 votes |
/** * <p> * This method provides instruction to log counter information * </p> * * @param className * Class which has called the logger * @param methodName * Method in which the logger has been called * @param logMsgPrefix * log message * @param field * field which store the counter * @return Instructions */ public static InsnList addCounterLogging(String className, String methodName, String logMsgPrefix, String field) { String method = "getMapReduceExecutionInfo"; InsnList il = new InsnList(); il.add(new LabelNode()); il.add(new VarInsnNode(Opcodes.ALOAD, CONTEXT_VARIABLE_IN_CLEANUP_SETUP)); il.add(new LdcInsnNode(className)); il.add(new LdcInsnNode(methodName)); il.add(new LdcInsnNode(logMsgPrefix)); il.add(new VarInsnNode(Opcodes.ALOAD, 0)); il.add(new FieldInsnNode(Opcodes.GETFIELD, ConfigurationUtil .convertQualifiedClassNameToInternalName(className), field, Type.INT_TYPE.getDescriptor())); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, CLASSNAME_LOGUTIL, method, Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_TASKINPUTOUTPUTCONTEXT, TYPE_STRING, TYPE_STRING, TYPE_STRING, Type.INT_TYPE))); return il; }
Example 3
Source File: EntityRendererPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Add hook that allows the method to be canceled") public void inject(MethodNode main) { AbstractInsnNode preNode = main.instructions.getFirst(); AbstractInsnNode postNode = ASMHelper.findPattern(main.instructions.getFirst(), new int[]{RETURN}, "x"); Objects.requireNonNull(preNode, "Find pattern failed for preNode"); Objects.requireNonNull(postNode, "Find pattern failed for postNode"); LabelNode endJump = new LabelNode(); InsnList insnPre = new InsnList(); insnPre.add(new VarInsnNode(FLOAD, 1)); insnPre.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onHurtcamEffect)); insnPre.add(new JumpInsnNode(IFNE, endJump)); main.instructions.insertBefore(preNode, insnPre); main.instructions.insertBefore(postNode, endJump); }
Example 4
Source File: Instrumentator.java From instrumentation with Apache License 2.0 | 6 votes |
private void addTraceStart() { InsnList il = new InsnList(); int methodParametersIndex = addMethodParametersVariable(il); addGetMethodInvocation(il); addStoreMethod(il); addGetCallback(il); il.add(new VarInsnNode(Opcodes.ALOAD, this.methodVarIndex)); il.add(new VarInsnNode(Opcodes.ALOAD, methodParametersIndex)); il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "org/brutusin/instrumentation/Callback", "onStart", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/String;", false)); this.executionIdIndex = getFistAvailablePosition(); il.add(new VarInsnNode(Opcodes.ASTORE, this.executionIdIndex)); this.mn.maxLocals++; this.startNode = new LabelNode(); this.mn.instructions.insert(startNode); this.mn.instructions.insert(il); }
Example 5
Source File: VisGraphPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Add hook at the end that can override the return value") public void inject(MethodNode main) { AbstractInsnNode top = main.instructions.getFirst(); AbstractInsnNode bottom = ASMHelper.findPattern(main.instructions.getFirst(), new int[]{RETURN}, "x"); Objects.requireNonNull(top, "Find pattern failed for top"); Objects.requireNonNull(bottom, "Find pattern failed for bottom"); LabelNode cancelNode = new LabelNode(); InsnList insnList = new InsnList(); insnList.add( ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_shouldDisableCaveCulling)); insnList.add(new JumpInsnNode(IFNE, cancelNode)); main.instructions.insertBefore(top, insnList); main.instructions.insertBefore(bottom, cancelNode); }
Example 6
Source File: ConstructorGenerator.java From grappa with Apache License 2.0 | 6 votes |
private static void createConstuctor(final ParserClassNode classNode, final MethodNode constructor) { final List<String> exceptions = constructor.exceptions; final MethodNode newConstructor = new MethodNode(ACC_PUBLIC, constructor.name, constructor.desc, constructor.signature, exceptions.toArray(new String[exceptions.size()]) ); final InsnList instructions = newConstructor.instructions; final CodeBlock block = CodeBlock.newCodeBlock() .aload(0) .addAll(createArgumentLoaders(constructor.desc)) .invokespecial(classNode.getParentType().getInternalName(), "<init>", constructor.desc) .rawReturn(); instructions.add(block.getInstructionList()); classNode.methods.add(newConstructor); }
Example 7
Source File: InstrumentUtil.java From jumbune with GNU Lesser General Public License v3.0 | 6 votes |
/** * <p> * This method provides instruction to log method entry/exit information * </p> * * @param className * Class which has called the logger * @param methodName * Method in which the logger has been called * @param logMsg * log message * @return InsnList Instructions */ public static InsnList addLogMessage(Object... objects) { String method = "addLogMsg"; InsnList il = getBasicInstructions(objects); Type[] types = new Type[objects.length]; for (int i = 0; i < objects.length; i++) { types[i] = TYPE_OBJECT; } String methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, types); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, CLASSNAME_LOGUTIL, method, methodDesc)); return il; }
Example 8
Source File: ASMMethodVariables.java From pinpoint with Apache License 2.0 | 5 votes |
void push(InsnList insnList, final String value) { if (value == null) { insnList.add(new InsnNode(Opcodes.ACONST_NULL)); } else { insnList.add(new LdcInsnNode(value)); } }
Example 9
Source File: MinecraftPatch.java From ForgeHax with MIT License | 5 votes |
@Inject(description = "Add hook to set left click") public void inject(MethodNode method) { InsnList list = new InsnList(); list.add(new VarInsnNode(ALOAD, 0)); list.add(new VarInsnNode(ILOAD, 1)); list.add( ASMHelper.call( INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onSendClickBlockToController)); list.add(new VarInsnNode(ISTORE, 1)); method.instructions.insert(list); }
Example 10
Source File: ContextWriteValidationAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 5 votes |
private void addRegexValidations(InsnList patternValidationInsnList, InstructionsBean insBean, MethodNode methodNode, boolean instrumentMapreduceRegex, boolean[] isValidated) { JobConfig jobConfig = (JobConfig)getConfig(); String keyRegex = jobConfig.getMapReduceKeyRegex(getClassName()); String valueRegex = jobConfig.getMapReduceValueRegex(getClassName()); int keyIndex = 0; int valueIndex = 1; if (instrumentMapreduceRegex && validateRegexValidationClass(jobConfig.getRegex(), getClassName())) { // Fetching regEx for validating key/value String[] validators=new String[2]; validators[keyIndex] = keyRegex; validators[valueIndex] = valueRegex; int index = 0; for (boolean isValidationPerformed : isValidated) { boolean isKey = true; // Validation of key/value was not done using // PatternValidator, so we will check if corresponding regEx // is given apply that if (!isValidationPerformed) { if (index == valueIndex) { isKey = false; } patternValidationInsnList.add(addCallForPatternMatcher( methodNode, insBean, isKey, validators[index])); } index++; } } }
Example 11
Source File: JobAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 5 votes |
/** * Handle submit case. * * @param jobVariableIndex the job variable index * @param type the type * @return the insn list */ public static InsnList handleSubmitCase(int jobVariableIndex, Type type) { InsnList il = new InsnList(); il.add(new LabelNode()); il.add(new VarInsnNode(Opcodes.ALOAD, jobVariableIndex)); il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, CLASSNAME_JOB_UTIL, "handleSubmitCase", Type.getMethodDescriptor(Type.VOID_TYPE, type))); return il; }
Example 12
Source File: MethodUtils.java From zelixkiller with GNU General Public License v3.0 | 5 votes |
/** * copy InsnList start included, end excluded * * @param list * @param start * @param end * @return */ public static InsnList copy(InsnList list, AbstractInsnNode start, AbstractInsnNode end) { InsnList newList = new InsnList(); Map<LabelNode, LabelNode> labelMap = getLabelMap(list); AbstractInsnNode ain = start == null ? list.getFirst() : start; while (ain != null && ain != end) { newList.add(ain.clone(labelMap)); ain = ain.getNext(); } return newList; }
Example 13
Source File: GenericGenerators.java From coroutines with GNU Lesser General Public License v3.0 | 5 votes |
/** * Pops the stack in to the the local variable table. You may run in to problems if the item on top of the stack isn't of the same type * as the variable it's being put in to. * @param variable variable within the local variable table to save to * @return instructions to pop an item off the top of the stack and save it to {@code variable} * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if {@code variable} has been released */ public static InsnList saveVar(Variable variable) { Validate.notNull(variable); InsnList ret = new InsnList(); switch (variable.getType().getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.CHAR: case Type.SHORT: case Type.INT: ret.add(new VarInsnNode(Opcodes.ISTORE, variable.getIndex())); break; case Type.LONG: ret.add(new VarInsnNode(Opcodes.LSTORE, variable.getIndex())); break; case Type.FLOAT: ret.add(new VarInsnNode(Opcodes.FSTORE, variable.getIndex())); break; case Type.DOUBLE: ret.add(new VarInsnNode(Opcodes.DSTORE, variable.getIndex())); break; case Type.OBJECT: case Type.ARRAY: ret.add(new VarInsnNode(Opcodes.ASTORE, variable.getIndex())); break; default: throw new IllegalStateException(); // should never happen, there is code in Variable/VariableTable to make sure invalid // types aren't set } return ret; }
Example 14
Source File: ConfigureMapReduceAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 4 votes |
/** * This method will add code for setting Partitioner in threadLocal so that * it can be accessed inside map method. If its cleanup method then code is * added to remove partitioner from thread local * * @param isSetup * - set true if its setup method * @return - Instruction list containing code for setting/removing * partitioner */ private InsnList addRemovePartitionerFromThreadLocal(boolean isSetup) { InsnList il = new InsnList(); il.add(new LabelNode()); String methodDesc = null; if (isSetup) { if (isOldApiClazz()) { methodDesc = InstrumentConstants.METHOD_DESC_PARAM_CONF_RETURN_VOID; } else { methodDesc = METHOD_DESC_PARAM_CONTEXT_RETURN_VOID; } // Load context variable il.add(new VarInsnNode(Opcodes.ALOAD, 1)); // adding partitioner to ThreadLocal il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, CLASSNAME_MAPREDUCEEXECUTIL, SET_PARTITIONER_METHOD, methodDesc)); } else { LOGGER.debug("Remvoing partitioner from ThreadLocal in cleanup method !!"); String methodName = null; if (isOldApiClazz()) { methodName = REMOVE_OLD_PARTITIONER_METHOD; } else { methodName = REMOVE_PARTITIONER_METHOD; } // removing partitioner from ThreadLocal il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, CLASSNAME_MAPREDUCEEXECUTIL, methodName, InstrumentConstants.EMPTY_PARAMETER_VOID_RETURN)); // Also remove PartitonerTime and partitionerSample count il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, CLASSNAME_MAPREDUCEEXECUTIL, InstrumentConstants.REMOVE_PARTITONER_TIME_SAMPLE_COUNT, InstrumentConstants.EMPTY_PARAMETER_VOID_RETURN)); } return il; }
Example 15
Source File: ArithmeticObfuscator.java From radon with GNU General Public License v3.0 | 4 votes |
private InsnList obfuscateNumber(long originalNum) { long current = randomLong(originalNum); InsnList insns = new InsnList(); insns.add(ASMUtils.getNumberInsn(current)); for (int i = 0; i < RandomUtils.getRandomInt(2, 6); i++) { long operand; switch (RandomUtils.getRandomInt(6)) { case 0: operand = randomLong(current); insns.add(ASMUtils.getNumberInsn(operand)); insns.add(new InsnNode(LADD)); current += operand; break; case 1: operand = randomLong(current); insns.add(ASMUtils.getNumberInsn(operand)); insns.add(new InsnNode(LSUB)); current -= operand; break; case 2: operand = RandomUtils.getRandomInt(1, 65535); insns.add(ASMUtils.getNumberInsn(operand)); insns.add(new InsnNode(LMUL)); current *= operand; break; case 3: operand = RandomUtils.getRandomInt(1, 65535); insns.add(ASMUtils.getNumberInsn(operand)); insns.add(new InsnNode(LDIV)); current /= operand; break; case 4: default: operand = RandomUtils.getRandomInt(1, 255); insns.add(ASMUtils.getNumberInsn(operand)); insns.add(new InsnNode(LREM)); current %= operand; break; } } long correctionOperand = originalNum - current; insns.add(ASMUtils.getNumberInsn(correctionOperand)); insns.add(new InsnNode(LADD)); return insns; }
Example 16
Source File: ASMMethodVariables.java From pinpoint with Apache License 2.0 | 4 votes |
void loadArg(final InsnList instructions, Type[] argumentTypes, int i) { final int index = getArgIndex(argumentTypes, i); final Type type = argumentTypes[i]; instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), index)); }
Example 17
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 18
Source File: ASMMethodVariables.java From pinpoint with Apache License 2.0 | 4 votes |
public void loadInterceptorLocalVariables(final InsnList instructions, final InterceptorDefinition interceptorDefinition, final boolean after) { assertInitializedInterceptorLocalVariables(); loadVar(instructions, this.interceptorVarIndex); instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(interceptorDefinition.getInterceptorBaseClass()))); // target(this) object. loadThis(instructions); final InterceptorType interceptorType = interceptorDefinition.getInterceptorType(); if (interceptorType == InterceptorType.ARRAY_ARGS) { // Object target, Object[] args loadVar(instructions, this.argsVarIndex); } else if (interceptorType == InterceptorType.STATIC) { // Object target, String declaringClassInternalName, String methodName, String parameterDescription, Object[] args loadVar(instructions, this.classNameVarIndex); loadVar(instructions, this.methodNameVarIndex); loadVar(instructions, this.parameterDescriptionVarIndex); loadVar(instructions, this.argsVarIndex); } else if (interceptorType == InterceptorType.API_ID_AWARE) { // Object target, int apiId, Object[] args loadInt(instructions, this.apiIdVarIndex); loadVar(instructions, this.argsVarIndex); } else if (interceptorType == InterceptorType.BASIC) { int interceptorMethodParameterCount = getInterceptorParameterCount(interceptorDefinition); int argumentCount = Math.min(this.argumentTypes.length, interceptorMethodParameterCount); int i = 1; for (; i <= argumentCount; i++) { // Object target, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4 if (i == 1) loadVar(instructions, this.arg0VarIndex); else if (i == 2) loadVar(instructions, this.arg1VarIndex); else if (i == 3) loadVar(instructions, this.arg2VarIndex); else if (i == 4) loadVar(instructions, this.arg3VarIndex); else if (i == 5) loadVar(instructions, this.arg4VarIndex); else loadNull(instructions); } for (; i <= interceptorMethodParameterCount; i++) { loadNull(instructions); } } if (after) { loadVar(instructions, this.resultVarIndex); loadVar(instructions, this.throwableVarIndex); } }
Example 19
Source File: ChunkTransformer.java From NOVA-Core with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void transform(ClassNode cnode) { Game.logger().info("Transforming Chunk class for chunkModified event."); //obf name: func_177436_a ObfMapping obfMap = new ObfMapping("bfh", "a", "(Ldt;Lbec;)Lbec;"); ObfMapping deobfMap = new ObfMapping("net/minecraft/world/chunk/Chunk", "setBlockState", "(Lnet/minecraft/util/BlockPos;Lnet/minecraft/block/state/IBlockState;)Lnet/minecraft/block/state/IBlockState;"); MethodNode method = ASMHelper.findMethod(obfMap, cnode); if (method == null) { Game.logger().warn("Lookup {} failed. You are probably in a deobf environment.", obfMap); method = ASMHelper.findMethod(deobfMap, cnode); if (method == null) { throw new IllegalStateException("[NOVA] Lookup " + deobfMap + " failed!"); } } Game.logger().info("Found method {}", method.name); InsnList list = new InsnList(); list.add(new VarInsnNode(ALOAD, 0)); //this list.add(new VarInsnNode(ALOAD, 1)); //BlockPos list.add(new VarInsnNode(ALOAD, 8)); //oldBlock IBlockState list.add(new VarInsnNode(ALOAD, 2)); //newBlock IBlockState list.add(new MethodInsnNode(INVOKESTATIC, "nova/core/wrapper/mc/forge/v18/asm/StaticForwarder", "chunkSetBlockEvent", "(Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/util/BlockPos;Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/block/state/IBlockState;)V", false)); AbstractInsnNode lastInsn = method.instructions.getLast(); while (lastInsn instanceof LabelNode || lastInsn instanceof LineNumberNode) { lastInsn = lastInsn.getPrevious(); } if (ASMHelper.isReturn(lastInsn)) { method.instructions.insertBefore(lastInsn, list); } else { method.instructions.insert(list); } Game.logger().info("Injected instruction to method: {}", method.name); }
Example 20
Source File: InstrumentUtil.java From jumbune with GNU Lesser General Public License v3.0 | 3 votes |
/** * <p> * This method provides instructions to be included before various logging * </p> * * @param String * [] values values to be passed as parameters in logging method * @return Instructions */ private static InsnList getBasicInstructions(Object... values) { InsnList il = new InsnList(); il.add(new LabelNode()); for (Object value : values) { il.add(new LdcInsnNode(value)); } return il; }