org.objectweb.asm.tree.AbstractInsnNode Java Examples
The following examples show how to use
org.objectweb.asm.tree.AbstractInsnNode.
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 Project: pitest Author: hcoles File: ForEachLoopFilter.java License: Apache License 2.0 | 6 votes |
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())); }
Example #2
Source Project: NOVA-Core Author: NOVA-Team File: InstructionComparator.java License: GNU Lesser General Public License v3.0 | 6 votes |
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 #3
Source Project: radon Author: ItzSomebody File: ASMUtils.java License: GNU General Public License v3.0 | 6 votes |
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(); } }
Example #4
Source Project: ForgeHax Author: fr1kin File: EntityPlayerSPPatch.java License: MIT License | 6 votes |
@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 #5
Source Project: javaide Author: tranleduy2000 File: ClickableViewAccessibilityDetector.java License: GNU General Public License v3.0 | 6 votes |
@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); } } } } }
Example #6
Source Project: javaide Author: tranleduy2000 File: LintUtils.java License: GNU General Public License v3.0 | 6 votes |
/** * 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; } } } }
Example #7
Source Project: Cafebabe Author: GraxCode File: SourceInterpreter.java License: GNU General Public License v3.0 | 6 votes |
@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); }
Example #8
Source Project: jumbune Author: Impetus File: BlockLogMethodAdapter.java License: GNU Lesser General Public License v3.0 | 6 votes |
/** * <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; }
Example #9
Source Project: Mixin Author: SpongePowered File: JumpInsnPoint.java License: MIT License | 6 votes |
@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; }
Example #10
Source Project: NOVA-Core Author: NOVA-Team File: InstructionComparator.java License: GNU Lesser General Public License v3.0 | 6 votes |
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 #11
Source Project: deobfuscator Author: java-deobfuscator File: InvocationStep.java License: Apache License 2.0 | 6 votes |
@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(); }
Example #12
Source Project: tascalate-javaflow Author: vsilaev File: CallSiteFinder.java License: Apache License 2.0 | 6 votes |
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; }
Example #13
Source Project: zelixkiller Author: GraxCode File: ReflectionObfuscationVMT11.java License: GNU General Public License v3.0 | 6 votes |
@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)); }
Example #14
Source Project: deobfuscator Author: java-deobfuscator File: OrStep.java License: Apache License 2.0 | 5 votes |
@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; }
Example #15
Source Project: radon Author: ItzSomebody File: ASMUtils.java License: GNU General Public License v3.0 | 5 votes |
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"); }
Example #16
Source Project: jaop Author: ltshddx File: ASMHelper.java License: Apache License 2.0 | 5 votes |
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)); } }
Example #17
Source Project: Cafebabe Author: GraxCode File: BlockVertex.java License: GNU General Public License v3.0 | 5 votes |
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; }
Example #18
Source Project: deobfuscator Author: java-deobfuscator File: NewArrayStep.java License: Apache License 2.0 | 5 votes |
@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; }
Example #19
Source Project: netbeans Author: apache File: Asm.java License: Apache License 2.0 | 5 votes |
/** * 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; } } }
Example #20
Source Project: pitest Author: hcoles File: InfiniteIteratorLoopFilter.java License: Apache License 2.0 | 5 votes |
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())); }
Example #21
Source Project: JByteMod-Beta Author: GraxCode File: Converter.java License: GNU General Public License v2.0 | 5 votes |
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; }
Example #22
Source Project: maple-ir Author: LLVM-but-worse File: VarInstructionFilter.java License: GNU General Public License v3.0 | 5 votes |
@Override public boolean accept(AbstractInsnNode t) { if (!(t instanceof VarInsnNode)) return false; VarInsnNode vin = (VarInsnNode) t; return opcodeFilter.accept(vin) && varFilter.accept(vin.var); }
Example #23
Source Project: pitest Author: hcoles File: MethodTree.java License: Apache License 2.0 | 5 votes |
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; }
Example #24
Source Project: NOVA-Core Author: NOVA-Team File: ASMHelper.java License: GNU Lesser General Public License v3.0 | 5 votes |
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; }
Example #25
Source Project: Concurnas Author: Concurnas File: BasicBlock.java License: MIT License | 5 votes |
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; }
Example #26
Source Project: javaide Author: tranleduy2000 File: InvalidPackageDetector.java License: GNU General Public License v3.0 | 5 votes |
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())); }
Example #27
Source Project: maple-ir Author: LLVM-but-worse File: IntInstructionFilter.java License: GNU General Public License v3.0 | 5 votes |
@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; }
Example #28
Source Project: pitest Author: hcoles File: ForEachLoopFilter.java License: Apache License 2.0 | 5 votes |
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); }; }
Example #29
Source Project: rscplus Author: OrN File: JClassPatcher.java License: GNU General Public License v3.0 | 5 votes |
private String decodeInstruction(AbstractInsnNode insnNode) { insnNode.accept(mp); StringWriter sw = new StringWriter(); printer.print(new PrintWriter(sw)); printer.getText().clear(); return sw.toString(); }
Example #30
Source Project: rembulan Author: mjanicek File: ConversionMethods.java License: Apache License 2.0 | 5 votes |
public static AbstractInsnNode booleanValueOf() { return new MethodInsnNode( INVOKESTATIC, Type.getInternalName(Conversions.class), "booleanValueOf", Type.getMethodDescriptor( Type.BOOLEAN_TYPE, Type.getType(Object.class)), false); }