Java Code Examples for org.objectweb.asm.tree.AbstractInsnNode#getNext()

The following examples show how to use org.objectweb.asm.tree.AbstractInsnNode#getNext() . 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: ClassContext.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Finds the line number closest to the given node
 *
 * @param node the instruction node to get a line number for
 * @return the closest line number, or -1 if not known
 */
public static int findLineNumber(@NonNull AbstractInsnNode node) {
    AbstractInsnNode curr = node;

    // First search backwards
    while (curr != null) {
        if (curr.getType() == AbstractInsnNode.LINE) {
            return ((LineNumberNode) curr).line;
        }
        curr = curr.getPrevious();
    }

    // Then search forwards
    curr = node;
    while (curr != null) {
        if (curr.getType() == AbstractInsnNode.LINE) {
            return ((LineNumberNode) curr).line;
        }
        curr = curr.getNext();
    }

    return -1;
}
 
Example 2
Source File: LintUtils.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the next instruction after to the given node, ignoring label and
 * line number nodes.
 *
 * @param node the node to look up the next node for
 * @return the next instruction, or null if no next node was found
 */
@Nullable
public static AbstractInsnNode getNextInstruction(@NonNull AbstractInsnNode node) {
    AbstractInsnNode next = node;
    while (true) {
        next = next.getNext();
        if (next == null) {
            return null;
        } else {
            int type = next.getType();
            if (type != AbstractInsnNode.LINE && type != AbstractInsnNode.LABEL
                    && type != AbstractInsnNode.FRAME) {
                return next;
            }
        }
    }
}
 
Example 3
Source File: InvocationStep.java    From deobfuscator with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: ControlFlowGraph.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/** Adds an exception try block node to this graph */
protected void exception(@NonNull AbstractInsnNode from, @NonNull TryCatchBlockNode tcb) {
    // Add tcb's to all instructions in the range
    LabelNode start = tcb.start;
    LabelNode end = tcb.end; // exclusive

    // Add exception edges for all method calls in the range
    AbstractInsnNode curr = start;
    Node handlerNode = getNode(tcb.handler);
    while (curr != end && curr != null) {
        if (curr.getType() == AbstractInsnNode.METHOD_INSN) {
            // Method call; add exception edge to handler
            if (tcb.type == null) {
                // finally block: not an exception path
                getNode(curr).addSuccessor(handlerNode);
            }
            getNode(curr).addExceptionPath(handlerNode);
        }
        curr = curr.getNext();
    }
}
 
Example 5
Source File: EntityPatch.java    From ForgeHax with MIT License 5 votes vote down vote up
@Inject(description = "Insert flag into statement that performs sneak movement")
public void inject(MethodNode main) {
  AbstractInsnNode sneakFlagNode =
    ASMHelper.findPattern(
      main.instructions.getFirst(),
      new int[]{IFEQ, ALOAD, INSTANCEOF, IFEQ, 0x00, 0x00, LDC, DSTORE},
      "xxxx??xx");
  
  Objects.requireNonNull(sneakFlagNode, "Find pattern failed for sneakFlagNode");
  
  AbstractInsnNode instanceofCheck = sneakFlagNode.getNext();
  for (int i = 0; i < 3; i++) {
    instanceofCheck = instanceofCheck.getNext();
    main.instructions.remove(instanceofCheck.getPrevious());
  }
  
  // the original label to the jump
  LabelNode jumpToLabel = ((JumpInsnNode) sneakFlagNode).label;
  // the or statement jump if isSneaking returns false
  LabelNode orJump = new LabelNode();
  
  InsnList insnList = new InsnList();
  insnList.add(
    new JumpInsnNode(
      IFNE, orJump)); // if not equal, jump past the ForgeHaxHooks.isSafeWalkActivated
  insnList.add(ASMHelper.call(GETSTATIC, TypesHook.Fields.ForgeHaxHooks_isSafeWalkActivated));
  insnList.add(new JumpInsnNode(IFEQ, jumpToLabel));
  insnList.add(orJump);
  
  AbstractInsnNode previousNode = sneakFlagNode.getPrevious();
  main.instructions.remove(sneakFlagNode); // delete IFEQ
  main.instructions.insert(previousNode, insnList); // insert new instructions
}
 
Example 6
Source File: ASMHelper.java    From ForgeHax with MIT License 5 votes vote down vote up
@Nullable
public static AbstractInsnNode forward(AbstractInsnNode start, int n) {
  AbstractInsnNode node = start;
  for (int i = 0;
    i < Math.abs(n) && node != null;
    ++i, node = n > 0 ? node.getNext() : node.getPrevious()) {
  }
  return node;
}
 
Example 7
Source File: PlayerTabOverlayPatch.java    From ForgeHax with MIT License 5 votes vote down vote up
@Inject(description = "Add hook to increase the size of the tab list")
public void inject(MethodNode main) {
  AbstractInsnNode subListNode =
    ASMHelper.findPattern(
      main.instructions.getFirst(),
      new int[]{
        ALOAD,
        ICONST_0,
        ALOAD,
        INVOKEINTERFACE,
        BIPUSH,
        INVOKESTATIC,
        INVOKEINTERFACE,
        ASTORE
      },
      "xxxxxxxx");
  
  AbstractInsnNode astoreNode = subListNode;
  for (int i = 0; i < 7; i++) {
    astoreNode = astoreNode.getNext();
  }
  
  Objects.requireNonNull(subListNode, "Find pattern failed for subList");
  Objects.requireNonNull(astoreNode, "Find pattern failed for subListPost");
  
  LabelNode jump = new LabelNode();
  
  InsnList insnList = new InsnList();
  insnList.add(ASMHelper.call(GETSTATIC, TypesHook.Fields.ForgeHaxHooks_doIncreaseTabListSize));
  insnList.add(new JumpInsnNode(IFNE, jump));
  
  main.instructions.insertBefore(subListNode, insnList);
  main.instructions.insert(astoreNode, jump);
}
 
Example 8
Source File: VisGraphPatch.java    From ForgeHax with MIT License 5 votes vote down vote up
@Inject(
  description =
    "Add hook that adds or logic to the jump that checks if setAllVisible(true) should be called"
)
public void inject(MethodNode main) {
  AbstractInsnNode node =
    ASMHelper.findPattern(main.instructions.getFirst(), new int[]{SIPUSH, IF_ICMPGE}, "xx");
  
  Objects.requireNonNull(node, "Find pattern failed for node");
  
  // gets opcode IF_ICMPGE
  JumpInsnNode greaterThanJump = (JumpInsnNode) node.getNext();
  LabelNode nextIfStatement = greaterThanJump.label;
  LabelNode orLabel = new LabelNode();
  
  // remove IF_ICMPGE
  main.instructions.remove(greaterThanJump);
  
  InsnList insnList = new InsnList();
  insnList.add(new JumpInsnNode(IF_ICMPLT, orLabel));
  insnList.add(
    ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_shouldDisableCaveCulling));
  insnList.add(new JumpInsnNode(IFEQ, nextIfStatement));
  insnList.add(orLabel);
  
  main.instructions.insert(node, insnList);
}
 
Example 9
Source File: ControlFlowGraph.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a human readable version of the graph
 *
 * @param start the starting instruction, or null if not known or to use the
 *            first instruction
 * @return a string version of the graph
 */
@NonNull
public String toString(@Nullable Node start) {
    StringBuilder sb = new StringBuilder(400);

    AbstractInsnNode curr;
    if (start != null) {
        curr = start.instruction;
    } else {
        if (mNodeMap.isEmpty()) {
            return "<empty>";
        } else {
            curr = mNodeMap.keySet().iterator().next();
            while (curr.getPrevious() != null) {
                curr = curr.getPrevious();
            }
        }
    }

    while (curr != null) {
        Node node = mNodeMap.get(curr);
        if (node != null) {
            sb.append(node.toString(true));
        }
        curr = curr.getNext();
    }

    return sb.toString();
}
 
Example 10
Source File: InsnPattern.java    From ForgeHax with MIT License 5 votes vote down vote up
public <T extends AbstractInsnNode> T getIndex(final int index) {
  AbstractInsnNode node = this.first;
  for (int i = 0; i < index; i++) {
    node = node.getNext();
    // if (node == this.last && i < index)
    //    throw new ArrayIndexOutOfBoundsException(String.valueOf(index));
  }
  return (T) node;
}
 
Example 11
Source File: ASMHelper.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void removeBlock(InsnList insns, InstructionComparator.InsnListSection block) {
	AbstractInsnNode insn = block.first;
	while (true) {
		AbstractInsnNode next = insn.getNext();
		insns.remove(insn);
		if (insn == block.last) {
			break;
		}
		insn = next;
	}
}
 
Example 12
Source File: MergeClassVisitor.java    From EasyRouter with Apache License 2.0 5 votes vote down vote up
private void insertMethod(MethodNode methodNode, MethodVisitor mv){
    AbstractInsnNode insnNode = methodNode.instructions.getFirst();
    while (insnNode!=null && insnNode.getOpcode() != Opcodes.RETURN){
        insnNode.accept(mv);
        insnNode = insnNode.getNext();
    }
}
 
Example 13
Source File: LightFlowObfuscationTransformer.java    From deobfuscator with Apache License 2.0 5 votes vote down vote up
@Override 
   public boolean transform() throws Throwable {
   	DelegatingProvider provider = new DelegatingProvider();
       provider.register(new JVMMethodProvider());
       provider.register(new JVMComparisonProvider());
       provider.register(new MappedMethodProvider(classes));
       provider.register(new MappedFieldProvider());

       AtomicInteger fixed = new AtomicInteger();

       System.out.println("[Allatori] [LightFlowObfuscationTransformer] Starting");
       for(ClassNode classNode : classNodes())
       	for(MethodNode method : classNode.methods)
       	{
       		boolean modified;
       		do
       		{
       			modified = false;
        		for(AbstractInsnNode ain : method.instructions.toArray())
        			if((willPush(ain) || ain.getOpcode() == Opcodes.DUP) && ain.getNext() != null 
        			&& (willPush(ain.getNext()) || ain.getNext().getOpcode() == Opcodes.DUP)
        				&& ain.getNext().getNext() != null && ain.getNext().getNext().getOpcode() == Opcodes.POP2)
        			{
        				method.instructions.remove(ain.getNext().getNext());
        				method.instructions.remove(ain.getNext());
        				method.instructions.remove(ain);
        				modified = true;
        				fixed.incrementAndGet();
        			}
       		}while(modified);
       	}
       System.out.println("[Allatori] [LightFlowObfuscationTransformer] Removed " + fixed + " dead instructions");
       System.out.println("[Allatori] [LightFlowObfuscationTransformer] Done");
       return true;
}
 
Example 14
Source File: ASMMethodNodeAdapter.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public int getLineNumber() {
    AbstractInsnNode node = this.methodNode.instructions.getFirst();
    while (node != null) {
        if (node.getType() == AbstractInsnNode.LINE) {
            return ((LineNumberNode) node).line;
        }
        node = node.getNext();
    }

    return 0;
}
 
Example 15
Source File: InsnUtils.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
public static boolean callsField(InsnList il) {
	AbstractInsnNode ain = il.getFirst();
	while (ain != null) {
		if (ain instanceof MethodInsnNode) {
			return true;
		}
		ain = ain.getNext();
	}
	return false;
}
 
Example 16
Source File: ASMMethodNodeAdapter.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void remapMethodInsnNode(final ASMMethodInsnNodeRemapper remapper) {
    AbstractInsnNode insnNode = this.methodNode.instructions.getFirst();
    while (insnNode != null) {
        if (insnNode instanceof MethodInsnNode) {
            final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode;
            remapper.mapping(methodInsnNode);
        }
        insnNode = insnNode.getNext();
    }
}
 
Example 17
Source File: InsnUtils.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
public static boolean matches(InsnList il, int[] pattern) {
	AbstractInsnNode ain = il.getFirst();
	for (int i = 0; i < pattern.length; i++) {
		if (ain == null) {
			return false;
		}
		if (ain.getOpcode() != pattern[i]) {
			return false;
		}
		ain = ain.getNext();
	}
	return true;
}
 
Example 18
Source File: BoatPatch.java    From ForgeHax with MIT License 4 votes vote down vote up
@Inject(description = "Add hooks to disable boat rotation")
public void inject(MethodNode main) {
  AbstractInsnNode rotationLeftNode =
    ASMHelper.findPattern(
      main.instructions.getFirst(),
      new int[]{ALOAD, DUP, GETFIELD, LDC, FADD, PUTFIELD},
      "xxxxxx");
  AbstractInsnNode rotationRightNode =
    ASMHelper.findPattern(
      main.instructions.getFirst(),
      new int[]{ALOAD, DUP, GETFIELD, FCONST_1, FADD, PUTFIELD},
      "xxxxxx");
  
  Objects.requireNonNull(rotationLeftNode, "Find pattern failed for leftNode");
  Objects.requireNonNull(rotationRightNode, "Find pattern failed for rightNode");
  
  AbstractInsnNode putFieldNodeLeft = rotationLeftNode; // get last instruction for left
  for (int i = 0; i < 5; i++) {
    putFieldNodeLeft = putFieldNodeLeft.getNext();
  }
  
  AbstractInsnNode putFieldNodeRight = rotationRightNode; // get last instruction for right
  for (int i = 0; i < 5; i++) {
    putFieldNodeRight = putFieldNodeRight.getNext();
  }
  
  /*
   * disable updating deltaRotation for strafing left
   */
  LabelNode newLabelNodeLeft = new LabelNode();
  
  InsnList insnListLeft = new InsnList();
  insnListLeft.add(
    ASMHelper.call(GETSTATIC, TypesHook.Fields.ForgeHaxHooks_isBoatSetYawActivated));
  insnListLeft.add(new JumpInsnNode(IFNE, newLabelNodeLeft)); // if nogravity is enabled
  
  main.instructions.insertBefore(rotationLeftNode, insnListLeft); // insert if
  main.instructions.insert(putFieldNodeLeft, newLabelNodeLeft); // end if
  
  /*
   * disable updating deltaRotation for strafing right
   */
  LabelNode newLabelNodeRight = new LabelNode();
  
  InsnList insnListRight = new InsnList();
  insnListRight.add(
    ASMHelper.call(GETSTATIC, TypesHook.Fields.ForgeHaxHooks_isBoatSetYawActivated));
  insnListRight.add(new JumpInsnNode(IFNE, newLabelNodeRight)); // if nogravity is enabled
  
  main.instructions.insertBefore(rotationRightNode, insnListRight); // insert if
  main.instructions.insert(putFieldNodeRight, newLabelNodeRight); // end if
}
 
Example 19
Source File: BaseAdapter.java    From jumbune with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * <p>
 * Gets the next line number node for the given node
 * </p>
 * 
 * @param ain
 *            node
 * @return ain line number node
 */
public AbstractInsnNode getNextLineNode(AbstractInsnNode ain) {
	AbstractInsnNode lineNode = ain.getNext();
	while (!(lineNode instanceof LineNumberNode)) {
		lineNode = lineNode.getNext();
	}
	return lineNode;
}
 
Example 20
Source File: BaseAdapter.java    From jumbune with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * <p>
 * Gets the next line number for the given node
 * </p>
 * 
 * @param ain
 *            node
 * @return int line number
 */
public int getNextLineNumber(AbstractInsnNode ain) {
	AbstractInsnNode lineNode = ain.getNext();
	while (!(lineNode instanceof LineNumberNode)) {
		lineNode = lineNode.getNext();
	}
	return ((LineNumberNode) lineNode).line;
}