org.objectweb.asm.tree.InsnList Java Examples

The following examples show how to use org.objectweb.asm.tree.InsnList. 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: InstructionComparator.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static InsnList getImportantList(InsnList list) {
	if (list.size() == 0) {
		return list;
	}

	HashMap<LabelNode, LabelNode> labels = new HashMap<LabelNode, LabelNode>();
	for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
		if (insn instanceof LabelNode) {
			labels.put((LabelNode) insn, (LabelNode) insn);
		}
	}

	InsnList importantNodeList = new InsnList();
	for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
		if (insn instanceof LabelNode || insn instanceof LineNumberNode) {
			continue;
		}

		importantNodeList.add(insn.clone(labels));
	}
	return importantNodeList;
}
 
Example #2
Source File: InstructionComparator.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static InsnListSection insnListMatchesL(InsnList haystack, InsnList needle, int start, HashSet<LabelNode> controlFlowLabels) {
	int h = start, n = 0;
	for (; h < haystack.size() && n < needle.size(); h++) {
		AbstractInsnNode insn = haystack.get(h);
		if (insn.getType() == 15) {
			continue;
		}
		if (insn.getType() == 8 && !controlFlowLabels.contains(insn)) {
			continue;
		}

		if (!insnEqual(haystack.get(h), needle.get(n))) {
			return null;
		}
		n++;
	}
	if (n != needle.size()) {
		return null;
	}

	return new InsnListSection(haystack, start, h - 1);
}
 
Example #3
Source File: BeforeReturn.java    From Mixin with MIT License 6 votes vote down vote up
@Override
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
    boolean found = false;
    
    // RETURN opcode varies based on return type, thus we calculate what opcode we're actually looking for by inspecting the target method
    int returnOpcode = Type.getReturnType(desc).getOpcode(Opcodes.IRETURN);
    int ordinal = 0;

    ListIterator<AbstractInsnNode> iter = insns.iterator();
    while (iter.hasNext()) {
        AbstractInsnNode insn = iter.next();

        if (insn instanceof InsnNode && insn.getOpcode() == returnOpcode) {
            if (this.ordinal == -1 || this.ordinal == ordinal) {
                nodes.add(insn);
                found = true;
            }

            ordinal++;
        }
    }

    return found;
}
 
Example #4
Source File: ASMMethodVariables.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
void loadArgsVar(final InsnList instructions) {
    if (this.argumentTypes.length == 0) {
        // null.
        loadNull(instructions);
        return;
    }

    push(instructions, this.argumentTypes.length);
    // new array
    newArray(instructions, OBJECT_TYPE);
    for (int i = 0; i < this.argumentTypes.length; i++) {
        Type type = this.argumentTypes[i];
        dup(instructions);
        push(instructions, i);
        // loadArg
        loadArg(instructions, this.argumentTypes, i);
        // box
        box(instructions, type);
        // arrayStore
        arrayStore(instructions, OBJECT_TYPE);
    }
}
 
Example #5
Source File: FeatureStructureClassGen.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private void addFeatureGetSet() {
  for (boolean isGet : GET_SET) {
    MethodNode mn = new MethodNode(ASM5, ACC_PUBLIC,    //  Get for non-array value
        fi.getGetterSetterName(isGet), 
        isGet ? ("()" + rangeJavaDescriptor) 
              : "(" + rangeJavaDescriptor + ")V", 
        null, null);
    InsnList il = mn.instructions;
    il.add(new VarInsnNode(ALOAD,  0));
    if (isGet) {
      il.add(new FieldInsnNode(GETFIELD, typeJavaClassName, featureFieldName, rangeJavaDescriptor));
      il.add(new InsnNode(getReturnInst(fi)));
    } else {
      il.add(new VarInsnNode(getLoadInst(fi), 1));        // load ref, or primitive value
      il.add(new FieldInsnNode(PUTFIELD, typeJavaClassName, featureFieldName, rangeJavaDescriptor));
      il.add(new InsnNode(RETURN));
    }
    final boolean is2slotValue = ((TypeImpl) fi.getRange()).isLongOrDouble();
    mn.maxStack  = isGet ? 1 : is2slotValue ? 3 : 2;
    mn.maxLocals = isGet ? 1 : is2slotValue ? 3 : 2;
    cn.methods.add(mn);    
  }    
}
 
Example #6
Source File: GenericGenerators.java    From coroutines with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Compares two objects and performs some action if the objects are NOT the same (uses != to check if not same).
 * @param lhs left hand side instruction list -- must leave an object on the stack
 * @param rhs right hand side instruction list -- must leave an object on the stack
 * @param action action to perform if results of {@code lhs} and {@code rhs} are not equal
 * @return instructions instruction list to perform some action if two objects are not equal
 * @throws NullPointerException if any argument is {@code null}
 */
public static InsnList ifObjectsNotEqual(InsnList lhs, InsnList rhs, InsnList action) {
    Validate.notNull(lhs);
    Validate.notNull(rhs);
    Validate.notNull(action);
    
    
    InsnList ret = new InsnList();
    
    LabelNode equalLabelNode = new LabelNode();
    
    ret.add(lhs);
    ret.add(rhs);
    ret.add(new JumpInsnNode(Opcodes.IF_ACMPEQ, equalLabelNode));
    ret.add(action);
    ret.add(equalLabelNode);
    
    return ret;
}
 
Example #7
Source File: ASMMethodVariables.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public void storeResultVar(final InsnList instructions, final int opcode) {
    assertInitializedInterceptorLocalVariables();
    if (opcode == Opcodes.RETURN) {
        // void.
        loadNull(instructions);
    } else if (opcode == Opcodes.ARETURN) {
        // object.
        dup(instructions);
    } else {
        if (opcode == Opcodes.LRETURN || opcode == Opcodes.DRETURN) {
            // long or double.
            dup2(instructions);
        } else {
            dup(instructions);
        }
        final Type type = Type.getReturnType(this.methodNode.desc);
        box(instructions, type);
    }
    storeVar(instructions, this.resultVarIndex);
    loadNull(instructions);
    storeVar(instructions, this.throwableVarIndex);
}
 
Example #8
Source File: ModifyConstantInjector.java    From Mixin with MIT License 6 votes vote down vote up
/**
 * Injects a constant modifier at an implied-zero
 * 
 * @param target target method
 * @param jumpNode jump instruction (must be IFLT, IFGE, IFGT or IFLE)
 */
private void injectExpandedConstantModifier(Target target, JumpInsnNode jumpNode) {
    int opcode = jumpNode.getOpcode();
    if (opcode < Opcodes.IFLT || opcode > Opcodes.IFLE) {
        throw new InvalidInjectionException(this.info, String.format("%s annotation selected an invalid opcode %s in %s in %s",
                this.annotationType, Bytecode.getOpcodeName(opcode), target, this)); 
    }
    
    Extension extraStack = target.extendStack();
    final InsnList insns = new InsnList();
    insns.add(new InsnNode(Opcodes.ICONST_0));
    AbstractInsnNode invoke = this.invokeConstantHandler(Type.getType("I"), target, extraStack, insns, insns);
    insns.add(new JumpInsnNode(opcode + ModifyConstantInjector.OPCODE_OFFSET, jumpNode.label));
    extraStack.add(1).apply();
    target.replaceNode(jumpNode, invoke, insns);
}
 
Example #9
Source File: BeforeFinalReturn.java    From Mixin with MIT License 6 votes vote down vote up
@Override
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
    AbstractInsnNode ret = null;
    
    // RETURN opcode varies based on return type, thus we calculate what opcode we're actually looking for by inspecting the target method
    int returnOpcode = Type.getReturnType(desc).getOpcode(Opcodes.IRETURN);

    ListIterator<AbstractInsnNode> iter = insns.iterator();
    while (iter.hasNext()) {
        AbstractInsnNode insn = iter.next();
        if (insn instanceof InsnNode && insn.getOpcode() == returnOpcode) {
            ret = insn;
        }
    }

    // WAT?
    if (ret == null) {
        throw new InvalidInjectionException(this.context, "TAIL could not locate a valid RETURN in the target method!");
    }
    
    nodes.add(ret);
    return true;
}
 
Example #10
Source File: EntityPlayerSPPatch.java    From ForgeHax with MIT License 6 votes vote down vote up
@Inject(description = "Add hook to override returned value of isRowingBoat")
public void inject(MethodNode main) {
  AbstractInsnNode preNode = main.instructions.getFirst();
  
  Objects.requireNonNull(preNode, "Find pattern failed for pre node");
  
  LabelNode jump = new LabelNode();
  
  InsnList insnPre = new InsnList();
  // insnPre.add(ASMHelper.call(GETSTATIC,
  // TypesHook.Fields.ForgeHaxHooks_isNotRowingBoatActivated));
  // insnPre.add(new JumpInsnNode(IFEQ, jump));
  
  insnPre.add(new InsnNode(ICONST_0));
  insnPre.add(new InsnNode(IRETURN)); // return false
  // insnPre.add(jump);
  
  main.instructions.insert(insnPre);
}
 
Example #11
Source File: ConfigureMapReduceAdapter.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Adds the partitioner logging.
 *
 * @param methodName the method name
 * @param isSetup the is setup
 * @return the insn list
 */
private InsnList addPartitionerLogging(String methodName, boolean isSetup) {

	LOGGER.debug("Add logging of partitioner !!! ");

	InsnList il = new InsnList();

	if (!isSetup) {
		il.add(new LabelNode());
		String cSymbol = env.getClassSymbol(getClassName());
		String mSymbol = Environment.getMethodSymbol(getClassName(), cSymbol, methodName);

		LogInfoBean logBean = new LogInfoBean(cSymbol,
				mSymbol,InstrumentationMessageLoader
						.getMessage(MessageConstants.MSG_PARTITION_INFO),
				null);

		il.add(InstrumentUtil.addLoggingForPartitioner(logBean));

	}

	return il;
}
 
Example #12
Source File: Instrumentator.java    From instrumentation with Apache License 2.0 6 votes vote down vote up
private InsnList getThrowTraceInstructions() {
    InsnList il = new InsnList();

    int exceptionVariablePosition = getFistAvailablePosition();
    il.add(new VarInsnNode(Opcodes.ASTORE, exceptionVariablePosition));

    this.methodOffset++; // Actualizamos el offset
    addGetCallback(il);
    il.add(new VarInsnNode(Opcodes.ALOAD, this.methodVarIndex));
    il.add(new VarInsnNode(Opcodes.ALOAD, exceptionVariablePosition));
    il.add(new VarInsnNode(Opcodes.ALOAD, this.executionIdIndex));
    il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
            "org/brutusin/instrumentation/Callback", "onThrowableThrown",
            "(Ljava/lang/Object;Ljava/lang/Throwable;Ljava/lang/String;)V", false));

    il.add(new VarInsnNode(Opcodes.ALOAD, exceptionVariablePosition));

    return il;
}
 
Example #13
Source File: IForgeRegistryEntryTransformer.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void transform(ClassNode cnode) {
	Game.logger().info("Transforming IForgeRegistryEntry class for correct NOVA mod id mapping.");

	ObfMapping mapping = new ObfMapping("net/minecraftforge/fml/common/registry/IForgeRegistryEntry$Impl", "setRegistryName", "(Ljava/lang/String;)Lnet/minecraftforge/fml/common/registry/IForgeRegistryEntry;");
	MethodNode method = ASMHelper.findMethod(mapping, cnode);

	if (method == null) {
		throw new IllegalStateException("[NOVA] Lookup " + mapping + " failed!");
	}

	Game.logger().info("Transforming method {}", method.name);

	InsnList list = new InsnList();
	list.add(new VarInsnNode(ALOAD, 5));
	list.add(new MethodInsnNode(INVOKESTATIC, "nova/core/wrapper/mc/forge/v1_11_2/asm/StaticForwarder", "isNovaPrefix", "(Ljava/lang/String;)Z", false));
	list.add(new JumpInsnNode(IFNE, (LabelNode) method.instructions.get(120)));

	method.instructions.insert(method.instructions.get(101), list);

	Game.logger().info("Injected instruction to method: {}", method.name);
}
 
Example #14
Source File: InstrumentUtil.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * <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 logMethod
 *            log method
 * @param logMsgPrefix
 *            log message
 * @param field
 *            field which store the counter
 * @return Instructions
 */
public static InsnList addCounterLoggingOldApi(String className,
		String methodName, String logMethod, String logMsgPrefix,
		String field) {
	String method = "getMapReduceExecutionInfoOldApi";

	InsnList il = new InsnList();
	il.add(new LabelNode());
	il.add(new LdcInsnNode(className));
	il.add(new LdcInsnNode(methodName));
	il.add(new LdcInsnNode(logMethod));
	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_STRING,
					TYPE_STRING, TYPE_STRING, TYPE_STRING, Type.INT_TYPE)));
	return il;
}
 
Example #15
Source File: BlockLogMethodAdapter.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * <p>
 * This method injects instructions for add logging for if blocks
 * </p>
 * 
 * @param il
 *            list of instruction lists
 * @param nodes
 *            list of nodes where these instructions needed to be injected
 * @param nestingLevel
 *            nesting level
 */
private void addInsnForIfBlock(InsnList[] il, AbstractInsnNode[] nodes,
		int nestingLevel) {
	// messages for before, after and within if blocks
	int[] msgs = new int[] { MessageConstants.LOG_BEFORE_IF,
			MessageConstants.LOG_AFTER_IF, MessageConstants.LOG_IN_IF };

	int index = 0;
	for (int msg : msgs) {
		logger.debug(MessageFormat.format(
				InstrumentationMessageLoader.getMessage(msg),
				getClassName() + "##" + name, currentIfCount[nestingLevel]));

		// for BEFORE_IF, the logging to be injected at the respective label
		// node
		AbstractInsnNode prevNode = nodes[index];
		if (index == 0) {
			while (!(prevNode instanceof LabelNode)) {
				prevNode = prevNode.getPrevious();
			}
		}
		instructions.insert(prevNode, il[index]);
		index++;
	}
}
 
Example #16
Source File: DefaultMethodClassFixer.java    From bazel with Apache License 2.0 6 votes vote down vote up
private void desugarClinitToTriggerInterfaceInitializers(
    ImmutableList<String> companionsToTriggerInterfaceClinit) {
  if (isClinitAlreadyDesugared(companionsToTriggerInterfaceClinit)) {
    return;
  }
  InsnList desugarInsts = new InsnList();
  for (String companionClass : companionsToTriggerInterfaceClinit) {
    desugarInsts.add(
        new MethodInsnNode(
            Opcodes.INVOKESTATIC,
            companionClass,
            InterfaceDesugaring.COMPANION_METHOD_TO_TRIGGER_INTERFACE_CLINIT_NAME,
            InterfaceDesugaring.COMPANION_METHOD_TO_TRIGGER_INTERFACE_CLINIT_DESC,
            false));
  }
  if (clInitMethodNode.instructions.size() == 0) {
    clInitMethodNode.instructions.insert(new InsnNode(Opcodes.RETURN));
  }
  clInitMethodNode.instructions.insertBefore(
      clInitMethodNode.instructions.getFirst(), desugarInsts);
}
 
Example #17
Source File: ContinuationGenerators.java    From coroutines with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Generates instructions to pop the result of the method off the stack. This will only generate instructions if the method being
 * invoked generates a return value.
 * @param invokeInsnNode instruction for the method that was invoked (can either be of type {@link MethodInsnNode} or
 * {@link InvokeDynamicInsnNode} -- this is used to determine how many items to pop off the stack
 * @return instructions for a pop (only if the method being invoked generates a return value)
 * @throws IllegalArgumentException if {@code invokeInsnNode} isn't of type {@link MethodInsnNode} or {@link InvokeDynamicInsnNode}
 * @throws NullPointerException if any argument is {@code null}
 */
private static InsnList popMethodResult(AbstractInsnNode invokeInsnNode) {
    Validate.notNull(invokeInsnNode);
    
    Type returnType = getReturnTypeOfInvocation(invokeInsnNode);
    
    InsnList ret = new InsnList();
    switch (returnType.getSort()) {
        case Type.LONG:
        case Type.DOUBLE:
            ret.add(new InsnNode(Opcodes.POP2));
            break;
        case Type.VOID:
            break;
        case Type.METHOD:
            throw new IllegalStateException(); // this should never happen
        default:
            ret.add(new InsnNode(Opcodes.POP));
            break;
    }

    return ret;
}
 
Example #18
Source File: ControlFlowAnalyser.java    From pitest with Apache License 2.0 6 votes vote down vote up
private static Set<LabelNode> findJumpTargets(final InsnList instructions) {
  final Set<LabelNode> jumpTargets = new HashSet<>();
  for (AbstractInsnNode o : instructions) {
    if (o instanceof JumpInsnNode) {
      jumpTargets.add(((JumpInsnNode) o).label);
    } else if (o instanceof TableSwitchInsnNode) {
      final TableSwitchInsnNode twn = (TableSwitchInsnNode) o;
      jumpTargets.add(twn.dflt);
      jumpTargets.addAll(twn.labels);
    } else if (o instanceof LookupSwitchInsnNode) {
      final LookupSwitchInsnNode lsn = (LookupSwitchInsnNode) o;
      jumpTargets.add(lsn.dflt);
      jumpTargets.addAll(lsn.labels);
    }
  }
  return jumpTargets;
}
 
Example #19
Source File: Instrumentator.java    From instrumentation with Apache License 2.0 6 votes vote down vote up
private int addMethodParametersVariable(InsnList il) {
    il.add(TreeInstructions.getPushInstruction(this.methodArguments.length));
    il.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object"));
    int methodParametersIndex = getFistAvailablePosition();
    il.add(new VarInsnNode(Opcodes.ASTORE, methodParametersIndex));
    this.mn.maxLocals++;
    for (int i = 0; i < this.methodArguments.length; i++) {
        il.add(new VarInsnNode(Opcodes.ALOAD, methodParametersIndex));
        il.add(TreeInstructions.getPushInstruction(i));
        il.add(TreeInstructions.getLoadInst(methodArguments[i],
                getArgumentPosition(i)));
        MethodInsnNode mNode = TreeInstructions
                .getWrapperContructionInst(methodArguments[i]);
        if (mNode != null) {
            il.add(mNode);
        }
        il.add(new InsnNode(Opcodes.AASTORE));
    }
    return methodParametersIndex;
}
 
Example #20
Source File: ASMMethodVariables.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public void initLocalVariables(final InsnList instructions) {
    // find enter & exit instruction.
    final LabelNode variableStartLabelNode = new LabelNode();
    final LabelNode variableEndLabelNode = new LabelNode();
    if(instructions.getFirst() != null) {
        instructions.insertBefore(instructions.getFirst(), variableStartLabelNode);
    } else {
        instructions.insert(variableStartLabelNode);
    }
    instructions.insert(instructions.getLast(), variableEndLabelNode);

    if (!isStatic()) {
        addLocalVariable("this", Type.getObjectType(this.declaringClassInternalName).getDescriptor(), variableStartLabelNode, variableEndLabelNode);
    }

    for (Type type : this.argumentTypes) {
        addLocalVariable(JavaAssistUtils.javaClassNameToVariableName(type.getClassName()), type.getDescriptor(), variableStartLabelNode, variableEndLabelNode);
    }
}
 
Example #21
Source File: Expiration.java    From radon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void transform() {
    AtomicInteger counter = new AtomicInteger();

    getClassWrappers().stream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> {
        ClassNode classNode = classWrapper.getClassNode();

        classNode.methods.stream().filter(methodNode -> "<init>".equals(methodNode.name)).forEach(methodNode -> {
            InsnList expirationCode = createExpirationInstructions();
            methodNode.instructions.insertBefore(methodNode.instructions.getFirst(), expirationCode);
            counter.incrementAndGet();
        });
    });

    Main.info(String.format("Added %d expiration code blocks.", counter.get()));
}
 
Example #22
Source File: ASMMethodVariables.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
void box(final InsnList instructions, Type type) {
    if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
        return;
    }

    if (type == Type.VOID_TYPE) {
        // push null
        instructions.add(new InsnNode(Opcodes.ACONST_NULL));
    } else {
        Type boxed = getBoxedType(type);
        // new instance.
        newInstance(instructions, boxed);
        if (type.getSize() == 2) {
            // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o
            // dupX2
            dupX2(instructions);
            // dupX2
            dupX2(instructions);
            // pop
            pop(instructions);
        } else {
            // p -> po -> opo -> oop -> o
            // dupX1
            dupX1(instructions);
            // swap
            swap(instructions);
        }
        invokeConstructor(instructions, boxed, new Method("<init>", Type.VOID_TYPE, new Type[]{type}));
    }
}
 
Example #23
Source File: ASMMethodVariables.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private void initArg1Var(InsnList instructions) {
    assertInitializedInterceptorLocalVariables();
    this.arg1VarIndex = addInterceptorLocalVariable("_$PINPOINT$_arg1", "Ljava/lang/String;");
    loadArg(instructions, this.argumentTypes, 1);
    box(instructions, this.argumentTypes[1]);
    storeVar(instructions, this.arg1VarIndex);
}
 
Example #24
Source File: ConfigureMapReduceAdapter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Adds the chain info.
 *
 * @return the insn list
 */
private InsnList addChainInfo() {
	InsnList list = new InsnList();
	list.add(new VarInsnNode(Opcodes.ALOAD, 1));
	list.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
			CLASSNAME_MAPREDUCEEXECUTIL, "addChainInfo", Type
					.getMethodDescriptor(Type.VOID_TYPE, TYPE_JOBCONF)));

	return list;
}
 
Example #25
Source File: JobAdapter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 #26
Source File: ASMHelper.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Map<LabelNode, LabelNode> cloneLabels(InsnList insns) {
	HashMap<LabelNode, LabelNode> labelMap = new HashMap<LabelNode, LabelNode>();
	for (AbstractInsnNode insn = insns.getFirst(); insn != null; insn = insn.getNext()) {
		if (insn.getType() == 8) {
			labelMap.put((LabelNode) insn, new LabelNode());
		}
	}
	return labelMap;
}
 
Example #27
Source File: InstructionComparator.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean insnListMatches(InsnList haystack, InsnList needle, int start) {
	if (haystack.size() - start < needle.size()) {
		return false;
	}

	for (int i = 0; i < needle.size(); i++) {
		if (!insnEqual(haystack.get(i + start), needle.get(i))) {
			return false;
		}
	}
	return true;
}
 
Example #28
Source File: AntiDebug.java    From radon with GNU General Public License v3.0 5 votes vote down vote up
private InsnList generateCheck() {
    LabelNode notDebugLabel = new LabelNode();
    InsnList insnList = new InsnList();
    insnList.add(createIsDebugList());
    insnList.add(new JumpInsnNode(IFEQ, notDebugLabel));

    if (RandomUtils.getRandomBoolean()) {
        if (getMessage() != null) {
            insnList.add(new FieldInsnNode(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"));
            insnList.add(new LdcInsnNode(getMessage()));
            insnList.add(new MethodInsnNode(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false));
        }
        if (RandomUtils.getRandomBoolean()) {
            insnList.add(new LdcInsnNode(RandomUtils.getRandomInt()));
            insnList.add(new MethodInsnNode(INVOKESTATIC, "java/lang/System", "exit", "(I)V", false));
        } else {
            insnList.add(new MethodInsnNode(INVOKESTATIC, "java/lang/Runtime", "getRuntime", "()Ljava/lang/Runtime;", false));
            insnList.add(new LdcInsnNode(RandomUtils.getRandomInt()));
            insnList.add(new MethodInsnNode(INVOKEVIRTUAL, "java/lang/Runtime", "halt", "(I)V", false));
        }
    } else {
        String message = getMessage();
        if (message == null)
            message = randomString();

        insnList.add(new TypeInsnNode(NEW, "java/lang/RuntimeException"));
        insnList.add(new InsnNode(DUP));
        insnList.add(new LdcInsnNode(message));
        insnList.add(new MethodInsnNode(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V", false));
        insnList.add(new InsnNode(ATHROW));
    }
    insnList.add(notDebugLabel);
    return insnList;
}
 
Example #29
Source File: CallSiteFinder.java    From tascalate-javaflow with Apache License 2.0 5 votes vote down vote up
List<Result> findMatchingCallSites(InsnList instructions, List<LocalVariableAnnotationNode> varAnnotations, Map<Integer, List<AnnotationNode>> paramAnnotations) {
    List<Result> result = new ArrayList<Result>();
    for (@SuppressWarnings("unchecked") Iterator<AbstractInsnNode> i = instructions.iterator(); i.hasNext(); ) {
        AbstractInsnNode ins = i.next();
        if (ins instanceof MethodInsnNode) {
            MethodInsnNode mins = (MethodInsnNode)ins;
            Result entry = findMatchingCallSite(mins, varAnnotations, paramAnnotations);
            if (entry != null) {
                result.add(entry);
            }
        }
    }
    return result;
}
 
Example #30
Source File: GenericGenerators.java    From coroutines with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new object array on the stack.
 * @param size instructions to calculate the size of the new array -- must leave an int on the stack
 * @return instructions to create a new object array -- will leave the object array on the stack
 * @throws NullPointerException if any argument is {@code null}
 */
public static InsnList createNewObjectArray(InsnList size) {
    Validate.notNull(size);
    
    InsnList ret = new InsnList();
    
    ret.add(size);
    ret.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object"));
    
    return ret;
}