类org.objectweb.asm.tree.AbstractInsnNode源码实例Demo

下面列出了怎么用org.objectweb.asm.tree.AbstractInsnNode的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: pitest   文件: ForEachLoopFilter.java
private static SequenceQuery<AbstractInsnNode> arrayConditionalAtEnd() {
  final Slot<LabelNode> loopStart = Slot.create(LabelNode.class);
  final Slot<LabelNode> loopEnd = Slot.create(LabelNode.class);
  final Slot<Integer> counter = Slot.create(Integer.class);
  return QueryStart
      .any(AbstractInsnNode.class)
      .zeroOrMore(QueryStart.match(anyInstruction()))
      .then(opCode(Opcodes.ARRAYLENGTH).and(mutationPoint()))
      .then(opCode(Opcodes.ISTORE))
      .then(opCode(Opcodes.ICONST_0).and(mutationPoint()))
      .then(anIStore(counter.write()).and(debug("store")))
      .then(gotoLabel(loopEnd.write()))
      .then(aLabelNode(loopStart.write()))
      .zeroOrMore(QueryStart.match(anyInstruction()))
      .then(incrementsVariable(counter.read()).and(mutationPoint()))
      .then(labelNode(loopEnd.read()))
      .then(opCode(Opcodes.ILOAD))
      .then(opCode(Opcodes.ILOAD))
      .then(aConditionalJumpTo(loopStart).and(mutationPoint()))
      .zeroOrMore(QueryStart.match(anyInstruction()));
}
 
源代码2 项目: NOVA-Core   文件: InstructionComparator.java
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;
}
 
源代码3 项目: radon   文件: ASMUtils.java
public static AbstractInsnNode getRandomValue(Type type) {
    switch (type.getSort()) {
        case Type.BOOLEAN:
            return ASMUtils.getNumberInsn(RandomUtils.getRandomInt(0, 2));
        case Type.CHAR:
            return ASMUtils.getNumberInsn(RandomUtils.getRandomInt(Character.MIN_VALUE, Character.MAX_VALUE));
        case Type.BYTE:
            return ASMUtils.getNumberInsn(RandomUtils.getRandomInt(Byte.MIN_VALUE, Byte.MAX_VALUE));
        case Type.SHORT:
            return ASMUtils.getNumberInsn(RandomUtils.getRandomInt(Short.MIN_VALUE, Short.MAX_VALUE));
        case Type.INT:
            return ASMUtils.getNumberInsn(RandomUtils.getRandomInt());
        case Type.FLOAT:
            return ASMUtils.getNumberInsn(RandomUtils.getRandomFloat());
        case Type.LONG:
            return ASMUtils.getNumberInsn(RandomUtils.getRandomLong());
        case Type.DOUBLE:
            return ASMUtils.getNumberInsn(RandomUtils.getRandomDouble());
        case Type.ARRAY:
        case Type.OBJECT:
            return new InsnNode(Opcodes.ACONST_NULL);
        default:
            throw new AssertionError();
    }
}
 
源代码4 项目: ForgeHax   文件: EntityPlayerSPPatch.java
@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);
}
 
@SuppressWarnings("unchecked") // ASM API
public static void scanForAndCheckSetOnTouchListenerCalls(
        ClassContext context,
        ClassNode classNode) {
    List<MethodNode> methods = classNode.methods;
    for (MethodNode methodNode : methods) {
        ListIterator<AbstractInsnNode> iterator = methodNode.instructions.iterator();
        while (iterator.hasNext()) {
            AbstractInsnNode abstractInsnNode = iterator.next();
            if (abstractInsnNode.getType() == AbstractInsnNode.METHOD_INSN) {
                MethodInsnNode methodInsnNode = (MethodInsnNode) abstractInsnNode;
                if (methodInsnNode.name.equals(SET_ON_TOUCH_LISTENER)
                        && methodInsnNode.desc.equals(SET_ON_TOUCH_LISTENER_SIG)) {
                    checkSetOnTouchListenerCall(context, methodNode, methodInsnNode);
                }
            }
        }
    }
}
 
源代码6 项目: javaide   文件: LintUtils.java
/**
 * Returns the previous instruction prior to the given node, ignoring label
 * and line number nodes.
 *
 * @param node the node to look up the previous instruction for
 * @return the previous instruction, or null if no previous node was found
 */
@Nullable
public static AbstractInsnNode getPrevInstruction(@NonNull AbstractInsnNode node) {
    AbstractInsnNode prev = node;
    while (true) {
        prev = prev.getPrevious();
        if (prev == null) {
            return null;
        } else {
            int type = prev.getType();
            if (type != AbstractInsnNode.LINE && type != AbstractInsnNode.LABEL
                    && type != AbstractInsnNode.FRAME) {
                return prev;
            }
        }
    }
}
 
源代码7 项目: Cafebabe   文件: SourceInterpreter.java
@Override
public SourceValue newOperation(final AbstractInsnNode insn) {
	int size;
	switch (insn.getOpcode()) {
	case LCONST_0:
	case LCONST_1:
	case DCONST_0:
	case DCONST_1:
		size = 2;
		break;
	case LDC:
		Object value = ((LdcInsnNode) insn).cst;
		size = value instanceof Long || value instanceof Double ? 2 : 1;
		break;
	case GETSTATIC:
		size = Type.getType(((FieldInsnNode) insn).desc).getSize();
		break;
	default:
		size = 1;
		break;
	}
	return new SourceValue(size, insn);
}
 
源代码8 项目: jumbune   文件: BlockLogMethodAdapter.java
/**
 * <p>
 * This method gets the end index for the provided Jump instruction
 * </p>
 * 
 * @param ain
 *            The given jump node
 * @return int end index
 */
private int getEndIndexForBlock(AbstractInsnNode ain) {
	int retIndex = 0;
	if (ain instanceof JumpInsnNode) {
		JumpInsnNode jin = (JumpInsnNode) ain;
		LabelNode targetAIN = jin.label;
		if (targetAIN.getPrevious() instanceof JumpInsnNode
				&& Opcodes.GOTO == targetAIN.getPrevious().getOpcode()) {
			retIndex = CollectionUtil.getObjectIndexInArray(this.insnArr, targetAIN
					.getPrevious().getPrevious());
		} else {
			retIndex = CollectionUtil.getObjectIndexInArray(this.insnArr,
					targetAIN.getPrevious());
		}
	}
	return retIndex;
}
 
源代码9 项目: Mixin   文件: JumpInsnPoint.java
@Override
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
    boolean found = false;
    int ordinal = 0;

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

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

            ordinal++;
        }
    }

    return found;
}
 
源代码10 项目: NOVA-Core   文件: InstructionComparator.java
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);
}
 
源代码11 项目: deobfuscator   文件: InvocationStep.java
@Override
public AbstractInsnNode tryMatch(InstructionMatcher matcher, AbstractInsnNode now) {
    if (opcode != -1 && now.getOpcode() != opcode) {
        return null;
    }
    if (!(now instanceof MethodInsnNode)) {
        return null;
    }
    MethodInsnNode methodInsnNode = (MethodInsnNode) now;
    boolean ownerMatches = owner == null || methodInsnNode.owner.equals(owner);
    boolean nameMatches = name == null || methodInsnNode.name.equals(name);
    boolean descMatches = desc == null || (basic ? TransformerHelper.basicType(methodInsnNode.desc) : methodInsnNode.desc).equals(desc);
    if (!ownerMatches || !nameMatches || !descMatches) {
        return null;
    }
    return now.getNext();
}
 
源代码12 项目: tascalate-javaflow   文件: CallSiteFinder.java
private boolean isVarBetweenBounds(AbstractInsnNode var, LabelNode lo, LabelNode hi) {
    AbstractInsnNode x;
    boolean loFound = false;
    for (x = var; !(x == null || loFound); x = x.getPrevious()) {
        loFound = x == lo;
    }
    if (!loFound)
        return false;

    boolean hiFound = false;
    for (x = var; !(x == null || hiFound); x = x.getNext()) {
        hiFound = x == hi;
    }

    return hiFound;

}
 
源代码13 项目: zelixkiller   文件: ReflectionObfuscationVMT11.java
@Override
public void transform(JarArchive ja, ClassNode node) {
	if (twoLongType) {
		// init surroundings before decryption
		Outer: for (ClassNode cn : ja.getClasses().values()) {
			for (MethodNode mn : cn.methods) {
				for (AbstractInsnNode ain : mn.instructions.toArray()) {
					if (ain.getOpcode() == INVOKESPECIAL) {
						MethodInsnNode min = (MethodInsnNode) ain;
						if (min.owner.equals(node.name) && min.name.equals("<init>")) {
							try {
								Class.forName(cn.name.replace("/", "."), true, vm);
							} catch (ClassNotFoundException e) {
							}
							continue Outer;
						}
					}
				}
			}
		}
	}
	node.methods.forEach(mn -> removeDynamicCalls(node, mn));
}
 
源代码14 项目: deobfuscator   文件: OrStep.java
@Override
public AbstractInsnNode tryMatch(InstructionMatcher matcher, AbstractInsnNode now) {
    for (Step step : steps) {
        AbstractInsnNode next = step.tryMatch(matcher, now);
        if (next != null) {
            return next;
        }
    }
    return null;
}
 
源代码15 项目: radon   文件: ASMUtils.java
public static long getLongFromInsn(AbstractInsnNode insn) {
    int opcode = insn.getOpcode();

    if (opcode >= Opcodes.LCONST_0 && opcode <= Opcodes.LCONST_1) {
        return opcode - 9;
    } else if (insn instanceof LdcInsnNode
            && ((LdcInsnNode) insn).cst instanceof Long) {
        return (Long) ((LdcInsnNode) insn).cst;
    }

    throw new RadonException("Unexpected instruction");
}
 
源代码16 项目: jaop   文件: ASMHelper.java
public static void loadNode(ListIterator<AbstractInsnNode> iterator, Object paramType, int index) {
    if (Opcodes.INTEGER.equals(paramType)) {
        iterator.add(new VarInsnNode(Opcodes.ILOAD, index));
    } else if (Opcodes.LONG.equals(paramType)) {
        iterator.add(new VarInsnNode(Opcodes.LLOAD, index));
    } else if (Opcodes.FLOAT.equals(paramType)) {
        iterator.add(new VarInsnNode(Opcodes.FLOAD, index));
    } else if (Opcodes.DOUBLE.equals(paramType)) {
        iterator.add(new VarInsnNode(Opcodes.DLOAD, index));
    } else {
        iterator.add(new VarInsnNode(Opcodes.ALOAD, index));
    }
}
 
源代码17 项目: Cafebabe   文件: BlockVertex.java
public BlockVertex(MethodNode mn, Block block, ArrayList<AbstractInsnNode> nodes, LabelNode label, int listIndex) {
	super();
	this.mn = mn;
	this.block = block;
	this.nodes = nodes;
	this.label = label;
	this.listIndex = listIndex;
}
 
源代码18 项目: deobfuscator   文件: NewArrayStep.java
@Override
public AbstractInsnNode tryMatch(InstructionMatcher matcher, AbstractInsnNode now) {
    if (now.getOpcode() == Opcodes.NEWARRAY && now instanceof IntInsnNode) {
        if (this.sorts.contains(((IntInsnNode) now).operand)) {
            return now.getNext();
        }
    }
    return null;
}
 
源代码19 项目: netbeans   文件: Asm.java
/**
 * Replaces class references in super constructor invocations.
 * Must not replace references in this() constructor invocations.
 * 
 * @param theClass the class being patched
 * @param extenderClass the injected superclass
 * @param mn method to process
 */
private static void replaceSuperCtorCalls(final ClassNode theClass, final ClassNode extenderClass, MethodNode mn) {
    for (Iterator<AbstractInsnNode> it = mn.instructions.iterator(); it.hasNext(); ) {
        AbstractInsnNode aIns = it.next();
        if (aIns.getOpcode() == Opcodes.INVOKESPECIAL) {
            MethodInsnNode mins = (MethodInsnNode)aIns;
            if (CONSTRUCTOR_NAME.equals(mins.name) && mins.owner.equals(extenderClass.superName)) {
                // replace with the extender class name
                mins.owner = extenderClass.name;
            }
            break;
        }
    }
}
 
源代码20 项目: pitest   文件: InfiniteIteratorLoopFilter.java
private static SequenceQuery<AbstractInsnNode> inifniteIteratorLoop() {
  final Slot<LabelNode> loopStart = Slot.create(LabelNode.class);

  return QueryStart
      .any(AbstractInsnNode.class)
      .then(methodCallThatReturns(ClassName.fromString("java/util/Iterator")))
      .then(opCode(Opcodes.ASTORE))
      .zeroOrMore(QueryStart.match(anyInstruction()))
      .then(aJump())
      .then(aLabelNode(loopStart.write()))
      .oneOrMore(doesNotBreakIteratorLoop())
      .then(jumpsTo(loopStart.read()))
      // can't currently deal with loops with conditionals that cause additional jumps back
      .zeroOrMore(QueryStart.match(jumpsTo(loopStart.read()).negate()));
}
 
源代码21 项目: JByteMod-Beta   文件: Converter.java
private boolean isJumpBlock(Block b) {
  for (AbstractInsnNode ain : b.getNodes()) {
    int type = ain.getType();
    if (type != AbstractInsnNode.LABEL && type != AbstractInsnNode.LINE && type != AbstractInsnNode.FRAME && type != AbstractInsnNode.JUMP_INSN) {
      return false;
    }
  }
  return true;
}
 
源代码22 项目: maple-ir   文件: VarInstructionFilter.java
@Override
public boolean accept(AbstractInsnNode t) {
	if (!(t instanceof VarInsnNode))
		return false;
	VarInsnNode vin = (VarInsnNode) t;
	return opcodeFilter.accept(vin) && varFilter.accept(vin.var);
}
 
源代码23 项目: pitest   文件: MethodTree.java
private List<AbstractInsnNode> createInstructionList() {
  final List<AbstractInsnNode> list = new ArrayList<>();
  for (AbstractInsnNode abstractInsnNode : this.rawNode.instructions) {
    list.add(abstractInsnNode);
  }
  this.lazyInstructions = list;
  return this.lazyInstructions;
}
 
源代码24 项目: NOVA-Core   文件: ASMHelper.java
public static Map<LabelNode, LabelNode> cloneLabels(InsnList insns) {
	HashMap<LabelNode, LabelNode> labelMap = new HashMap<>();
	for (AbstractInsnNode insn = insns.getFirst(); insn != null; insn = insn.getNext()) {
		if (insn.getType() == 8) {
			labelMap.put((LabelNode) insn, new LabelNode());
		}
	}
	return labelMap;
}
 
源代码25 项目: Concurnas   文件: BasicBlock.java
public boolean isGetCurrentTask() {
    AbstractInsnNode ain = getInstruction(startPos);
    if (ain.getOpcode() == INVOKESTATIC) {
        MethodInsnNode min = (MethodInsnNode)ain;
        return min.owner.equals(TASK_CLASS) && min.name.equals("getCurrentTask");
    }
    return false;
}
 
源代码26 项目: javaide   文件: InvalidPackageDetector.java
private void record(ClassContext context, MethodNode method,
        AbstractInsnNode instruction, String owner) {
    if (owner.indexOf('$') != -1) {
        // Don't report inner classes too; there will pretty much always be an outer class
        // reference as well
        return;
    }

    if (mCandidates == null) {
        mCandidates = Lists.newArrayList();
    }
    mCandidates.add(new Candidate(owner, context.getClassNode().name, context.getJarFile()));
}
 
源代码27 项目: maple-ir   文件: IntInstructionFilter.java
@Override
public boolean accept(AbstractInsnNode t) {
	if (!(t instanceof IntInsnNode))
		return false;
	if (!opcodeFilter.accept(t))
		return false;
	IntInsnNode fin = (IntInsnNode) t;
	if (!numberFilter.accept(fin.operand))
		return false;
	return true;
}
 
源代码28 项目: pitest   文件: ForEachLoopFilter.java
private Predicate<MutationDetails> mutatesIteratorLoopPlumbing() {
  return a -> {
    final int instruction = a.getInstructionIndex();
    final MethodTree method = ForEachLoopFilter.this.currentClass.methods().stream()
        .filter(MethodMatchers.forLocation(a.getId().getLocation()))
        .findFirst()
        .get();
    final AbstractInsnNode mutatedInstruction = method.instruction(instruction);

    final Context<AbstractInsnNode> context = Context.start(method.instructions(), DEBUG);
    context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction);
    return ITERATOR_LOOP.matches(method.instructions(), context);
  };
}
 
源代码29 项目: rscplus   文件: JClassPatcher.java
private String decodeInstruction(AbstractInsnNode insnNode) {
  insnNode.accept(mp);
  StringWriter sw = new StringWriter();
  printer.print(new PrintWriter(sw));
  printer.getText().clear();
  return sw.toString();
}
 
源代码30 项目: rembulan   文件: ConversionMethods.java
public static AbstractInsnNode booleanValueOf() {
	return new MethodInsnNode(
			INVOKESTATIC,
			Type.getInternalName(Conversions.class),
			"booleanValueOf",
			Type.getMethodDescriptor(
					Type.BOOLEAN_TYPE,
					Type.getType(Object.class)),
			false);
}
 
 类所在包
 同包方法