Java Code Examples for org.objectweb.asm.tree.AbstractInsnNode#JUMP_INSN

The following examples show how to use org.objectweb.asm.tree.AbstractInsnNode#JUMP_INSN . 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: ApiDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static boolean containsSimpleSdkCheck(@NonNull MethodNode method) {
    // Look for a compiled version of "if (Build.VERSION.SDK_INT op N) {"
    InsnList nodes = method.instructions;
    for (int i = 0, n = nodes.size(); i < n; i++) {
        AbstractInsnNode instruction = nodes.get(i);
        if (isSdkVersionLookup(instruction)) {
            AbstractInsnNode bipush = getNextInstruction(instruction);
            if (bipush != null && bipush.getOpcode() == Opcodes.BIPUSH) {
                AbstractInsnNode ifNode = getNextInstruction(bipush);
                if (ifNode != null && ifNode.getType() == AbstractInsnNode.JUMP_INSN) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example 2
Source File: OpcodeFormatting.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
public static String toString(AbstractInsnNode ain) {
	String s = getOpcodeText(ain.getOpcode());
	switch (ain.getType()) {
	case AbstractInsnNode.FIELD_INSN:
		FieldInsnNode fin = (FieldInsnNode) ain;
		return s + " " + fin.owner + "#" + fin.name + " " + fin.desc;
	case AbstractInsnNode.METHOD_INSN:
		MethodInsnNode min = (MethodInsnNode) ain;
		return s + " " + min.owner + "#" + min.name + min.desc;
	case AbstractInsnNode.VAR_INSN:
		VarInsnNode vin = (VarInsnNode) ain;
		return s + " " + vin.var;
	case AbstractInsnNode.TYPE_INSN:
		TypeInsnNode tin = (TypeInsnNode) ain;
		return s + " " + tin.desc;
	case AbstractInsnNode.MULTIANEWARRAY_INSN:
		MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain;
		return s + " " + mnin.dims + " " + mnin.desc;
	case AbstractInsnNode.JUMP_INSN:
		JumpInsnNode jin = (JumpInsnNode) ain;
		return s + " " + getIndex(jin.label);
	case AbstractInsnNode.LDC_INSN:
		LdcInsnNode ldc = (LdcInsnNode) ain;
		return s + " " + ldc.cst.toString();
	case AbstractInsnNode.INT_INSN:
		return s + " " + getIntValue(ain);
	case AbstractInsnNode.IINC_INSN:
		IincInsnNode iinc = (IincInsnNode) ain;
		return s + " " + iinc.var + " +" + iinc.incr;
	case AbstractInsnNode.FRAME:
		FrameNode fn = (FrameNode) ain;
		return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size();
	case AbstractInsnNode.LABEL:
		LabelNode ln = (LabelNode) ain;
		return s + " " + getIndex(ln);
	}
	return s;
}
 
Example 3
Source File: Converter.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
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 4
Source File: AdressList.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {
	double size = il.getModel().getSize();
	if (size > 1000) {
		super.paintComponent(g);
		return;
	}
	super.paintComponent(g);
	HashMap<Integer, Integer> mvout = new HashMap<>();
	for (AbstractInsnNode ain : il.mn.instructions.toArray()) {
		if (ain.getType() == AbstractInsnNode.JUMP_INSN) {
			int moveOut = 0;
			int from = ((LazyListModel<InstructionNode>) il.getModel()).indexOf(ain);
			int to = ((LazyListModel<InstructionNode>) il.getModel()).indexOf(((JumpInsnNode) ain).label);
			for (int j = from; j < to; j++) {
				moveOut = Math.max(mvout.getOrDefault(j, 0) + 4, moveOut);
			}
			for (int j = from; j < to; j++) {
				mvout.put(j, moveOut);
			}
			int start = (from * getFixedCellHeight() + getFixedCellHeight() / 2);
			int end = (to * getFixedCellHeight() + getFixedCellHeight() / 2);
			Color c = Color.getHSBColor(getHue(moveOut), 1, 0.6f);
			g.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 127));
			g.drawLine(getWidth() - moveOut, start, getWidth() - moveOut, end);
			g.drawLine(getWidth() - moveOut, start, getWidth(), start);
			g.drawLine(getWidth() - moveOut, end, getWidth(), end);
		}
	}
}
 
Example 5
Source File: OpUtils.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
public static String toString(AbstractInsnNode ain) {
	String s = getOpcodeText(ain.getOpcode());
	switch (ain.getType()) {
	case AbstractInsnNode.FIELD_INSN:
		FieldInsnNode fin = (FieldInsnNode) ain;
		return s + " " + fin.owner + "#" + fin.name + " " + fin.desc;
	case AbstractInsnNode.METHOD_INSN:
		MethodInsnNode min = (MethodInsnNode) ain;
		return s + " " + min.owner + "#" + min.name + min.desc;
	case AbstractInsnNode.VAR_INSN:
		VarInsnNode vin = (VarInsnNode) ain;
		return s + " " + vin.var;
	case AbstractInsnNode.TYPE_INSN:
		TypeInsnNode tin = (TypeInsnNode) ain;
		return s + " " + tin.desc;
	case AbstractInsnNode.JUMP_INSN:
		JumpInsnNode jin = (JumpInsnNode) ain;
		return s + " " + getIndex(jin.label);
	case AbstractInsnNode.LDC_INSN:
		LdcInsnNode ldc = (LdcInsnNode) ain;
		return s + " " + ldc.cst.toString();
	case AbstractInsnNode.INT_INSN:
		return s + " " + getIntValue(ain);
	case AbstractInsnNode.IINC_INSN:
		IincInsnNode iinc = (IincInsnNode) ain;
		return s + " " + iinc.var + " +" + iinc.incr;
	case AbstractInsnNode.FRAME:
		FrameNode fn = (FrameNode) ain;
		return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size();
	case AbstractInsnNode.LABEL:
		LabelNode ln = (LabelNode) ain;
		return s + " " + getIndex(ln);
	}
	return s;
}
 
Example 6
Source File: ApiDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void add(@NonNull AbstractInsnNode from, @NonNull AbstractInsnNode to) {
    if (from.getType() == AbstractInsnNode.JUMP_INSN &&
            from.getPrevious() != null &&
            from.getPrevious().getType() == AbstractInsnNode.INT_INSN) {
        IntInsnNode intNode = (IntInsnNode) from.getPrevious();
        if (intNode.getPrevious() != null && isSdkVersionLookup(intNode.getPrevious())) {
            JumpInsnNode jumpNode = (JumpInsnNode) from;
            int api = intNode.operand;
            boolean isJumpEdge = to == jumpNode.label;
            boolean includeEdge;
            switch (from.getOpcode()) {
                case Opcodes.IF_ICMPNE:
                    includeEdge = api < mRequiredApi || isJumpEdge;
                    break;
                case Opcodes.IF_ICMPLE:
                    includeEdge = api < mRequiredApi - 1 || isJumpEdge;
                    break;
                case Opcodes.IF_ICMPLT:
                    includeEdge = api < mRequiredApi || isJumpEdge;
                    break;

                case Opcodes.IF_ICMPGE:
                    includeEdge = api < mRequiredApi || !isJumpEdge;
                    break;
                case Opcodes.IF_ICMPGT:
                    includeEdge = api < mRequiredApi - 1 || !isJumpEdge;
                    break;
                default:
                    // unexpected comparison for int API level
                    includeEdge = true;
            }
            if (!includeEdge) {
                return;
            }
        }
    }

    super.add(from, to);
}
 
Example 7
Source File: Converter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: OpUtils.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
public static String toString(AbstractInsnNode ain) {
  String s = getOpcodeText(ain.getOpcode());
  switch (ain.getType()) {
  case AbstractInsnNode.FIELD_INSN:
    FieldInsnNode fin = (FieldInsnNode) ain;
    return s + " " + fin.owner + "#" + fin.name + " " + fin.desc;
  case AbstractInsnNode.METHOD_INSN:
    MethodInsnNode min = (MethodInsnNode) ain;
    return s + " " + min.owner + "#" + min.name + min.desc;
  case AbstractInsnNode.VAR_INSN:
    VarInsnNode vin = (VarInsnNode) ain;
    return s + " " + vin.var;
  case AbstractInsnNode.TYPE_INSN:
    TypeInsnNode tin = (TypeInsnNode) ain;
    return s + " " + tin.desc;
  case AbstractInsnNode.MULTIANEWARRAY_INSN:
    MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain;
    return s + " " + mnin.dims + " " + mnin.desc;
  case AbstractInsnNode.JUMP_INSN:
    JumpInsnNode jin = (JumpInsnNode) ain;
    return s + " " + getIndex(jin.label);
  case AbstractInsnNode.LDC_INSN:
    LdcInsnNode ldc = (LdcInsnNode) ain;
    return s + " " + ldc.cst.toString();
  case AbstractInsnNode.INT_INSN:
    return s + " " + getIntValue(ain);
  case AbstractInsnNode.IINC_INSN:
    IincInsnNode iinc = (IincInsnNode) ain;
    return s + " " + iinc.var + " +" + iinc.incr;
  case AbstractInsnNode.FRAME:
    FrameNode fn = (FrameNode) ain;
    return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size();
  case AbstractInsnNode.LABEL:
    LabelNode ln = (LabelNode) ain;
    return s + " " + getIndex(ln);
  }
  return s;
}
 
Example 9
Source File: Colors.java    From Cafebabe with GNU General Public License v3.0 4 votes vote down vote up
public static String getColor(int type, int opcode) {
	switch (opcode) {
	case ATHROW:
	case IRETURN:
	case LRETURN:
	case FRETURN:
	case DRETURN:
	case ARETURN:
	case RETURN:
		return "#4d0000";
	case ACONST_NULL:
	case ICONST_M1:
	case ICONST_0:
	case ICONST_1:
	case ICONST_2:
	case ICONST_3:
	case ICONST_4:
	case ICONST_5:
	case LCONST_0:
	case LCONST_1:
	case FCONST_0:
	case FCONST_1:
	case FCONST_2:
	case DCONST_0:
	case DCONST_1:
		return "#005733";
	}
	switch (type) {
	case AbstractInsnNode.FIELD_INSN:
		return "#44004d";
	case AbstractInsnNode.METHOD_INSN:
		return "#14004d";
	case AbstractInsnNode.INT_INSN:
	case AbstractInsnNode.LDC_INSN:
		return "#004d40";
	case AbstractInsnNode.VAR_INSN:
		return "#6a3e3e";
	case AbstractInsnNode.JUMP_INSN:
		return "#003d4d";
	case AbstractInsnNode.TYPE_INSN:
		return "#474d00";
	default:
		return "#000";
	}
}
 
Example 10
Source File: InstrUtils.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public static String toString(AbstractInsnNode ain) {
	String opc = TextUtils.toBold(OpUtils.getOpcodeText(ain.getOpcode()).toLowerCase()) + " ";
	switch (ain.getType()) {
	case AbstractInsnNode.LABEL:
		opc = TextUtils.toLight("label " + OpUtils.getLabelIndex((LabelNode) ain));
		break;
	case AbstractInsnNode.LINE:
		opc = TextUtils.toLight("line " + ((LineNumberNode) ain).line);
		break;
	case AbstractInsnNode.FIELD_INSN:
		FieldInsnNode fin = (FieldInsnNode) ain;
		opc += getDisplayType(TextUtils.escape(fin.desc), true) + " " + getDisplayClassRed(TextUtils.escape(fin.owner))
				+ "." + fin.name;
		break;
	case AbstractInsnNode.METHOD_INSN:
		MethodInsnNode min = (MethodInsnNode) ain;
		if (min.desc.contains(")")) {
			opc += getDisplayType(min.desc.split("\\)")[1], true);
		} else {
			opc += min.desc;
		}
		opc += " " + getDisplayClassRed(TextUtils.escape(min.owner)) + "." + TextUtils.escape(min.name) + "("
				+ getDisplayArgs(TextUtils.escape(min.desc)) + ")";
		break;
	case AbstractInsnNode.VAR_INSN:
		VarInsnNode vin = (VarInsnNode) ain;
		opc += vin.var;
		break;
	case AbstractInsnNode.TYPE_INSN:
		TypeInsnNode tin = (TypeInsnNode) ain;
		String esc = TextUtils.escape(tin.desc);
		if (esc.endsWith(";") && esc.startsWith("L")) {
			opc += TextUtils.addTag(esc, "font color=" + primColor.getString());
		} else {
			opc += getDisplayClass(esc);
		}
		break;
	case AbstractInsnNode.MULTIANEWARRAY_INSN:
		MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain;
		opc += mnin.dims + " " + getDisplayType(TextUtils.escape(mnin.desc), true);
		break;
	case AbstractInsnNode.JUMP_INSN:
		JumpInsnNode jin = (JumpInsnNode) ain;
		opc += OpUtils.getLabelIndex(jin.label);
		break;
	case AbstractInsnNode.LDC_INSN:
		LdcInsnNode ldc = (LdcInsnNode) ain;
		opc += TextUtils.addTag(ldc.cst.getClass().getSimpleName(), "font color=" + primColor.getString()) + " ";
		if (ldc.cst instanceof String)
			opc += TextUtils.addTag("\"" + TextUtils.escape(ldc.cst.toString()) + "\"", "font color=#559955");
		else {
			opc += ldc.cst.toString();
		}
		break;
	case AbstractInsnNode.INT_INSN:
		opc += OpUtils.getIntValue(ain);
		break;
	case AbstractInsnNode.IINC_INSN:
		IincInsnNode iinc = (IincInsnNode) ain;
		opc += iinc.var + " " + iinc.incr;
		break;
	case AbstractInsnNode.FRAME:
		FrameNode fn = (FrameNode) ain;
		opc = TextUtils
				.toLight(OpUtils.getFrameType(fn.type).toLowerCase() + " " + fn.local.size() + " " + fn.stack.size());
		break;
	case AbstractInsnNode.TABLESWITCH_INSN:
		TableSwitchInsnNode tsin = (TableSwitchInsnNode) ain;
		if (tsin.dflt != null) {
			opc += TextUtils.addTag("L" + OpUtils.getLabelIndex(tsin.dflt), "font color=" + secColor.getString());
		}
		if (tsin.labels.size() < 20) {
			for (LabelNode l : tsin.labels) {
				opc += " " + TextUtils.addTag("L" + OpUtils.getLabelIndex(l), "font color=" + primColor.getString());
			}
		} else {
			opc += " " + TextUtils.addTag(tsin.labels.size() + " cases", "font color=" + primColor.getString());
		}
		break;
	case AbstractInsnNode.INVOKE_DYNAMIC_INSN:
		InvokeDynamicInsnNode idin = (InvokeDynamicInsnNode) ain;
		Object[] arr = idin.bsmArgs;
		if (arr.length > 1) {
			Object o = arr[1];
			if (o instanceof Handle) {
				Handle h = (Handle) o;
				opc += getDisplayType(h.getDesc().split("\\)")[1], true) + " "
						+ getDisplayClassRed(TextUtils.escape(h.getOwner())) + "." + TextUtils.escape(h.getName()) + "("
						+ getDisplayArgs(TextUtils.escape(h.getDesc())) + ")";

			}
		} else {
			opc += TextUtils.addTag(TextUtils.escape(idin.name), "font color=" + primColor.getString()) + " "
					+ TextUtils.escape(idin.desc);
		}
		break;
	}
	return opc;
}
 
Example 11
Source File: InstrUtils.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public static String toEasyString(AbstractInsnNode ain) {
	String opc = OpUtils.getOpcodeText(ain.getOpcode()).toLowerCase() + " ";
	switch (ain.getType()) {
	case AbstractInsnNode.LABEL:
		opc = "label " + OpUtils.getLabelIndex((LabelNode) ain);
		break;
	case AbstractInsnNode.LINE:
		opc = "line " + ((LineNumberNode) ain).line;
		break;
	case AbstractInsnNode.FIELD_INSN:
		FieldInsnNode fin = (FieldInsnNode) ain;
		opc += getDisplayType(fin.desc, false) + " " + getDisplayClassEasy(fin.owner) + "." + fin.name;
		break;
	case AbstractInsnNode.METHOD_INSN:
		MethodInsnNode min = (MethodInsnNode) ain;
		opc += getDisplayType(min.desc.split("\\)")[1], false) + " " + getDisplayClassEasy(min.owner) + "." + min.name
				+ "(" + getDisplayArgsEasy(min.desc) + ")";
		break;
	case AbstractInsnNode.VAR_INSN:
		VarInsnNode vin = (VarInsnNode) ain;
		opc += vin.var;
		break;
	case AbstractInsnNode.MULTIANEWARRAY_INSN:
		MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain;
		opc += mnin.dims + " " + getDisplayType(mnin.desc, false);
		break;
	case AbstractInsnNode.TYPE_INSN:
		TypeInsnNode tin = (TypeInsnNode) ain;
		String esc = tin.desc;
		if (esc.endsWith(";") && esc.startsWith("L")) {
			opc += esc;
		} else {
			opc += getDisplayClassEasy(esc);
		}
		break;
	case AbstractInsnNode.JUMP_INSN:
		JumpInsnNode jin = (JumpInsnNode) ain;
		opc += OpUtils.getLabelIndex(jin.label);
		break;
	case AbstractInsnNode.LDC_INSN:
		LdcInsnNode ldc = (LdcInsnNode) ain;
		opc += ldc.cst.getClass().getSimpleName() + " ";
		if (ldc.cst instanceof String)
			opc += "\"" + ldc.cst.toString() + "\"";
		else {
			opc += ldc.cst.toString();
		}
		break;
	case AbstractInsnNode.INT_INSN:
		opc += OpUtils.getIntValue(ain);
		break;
	case AbstractInsnNode.IINC_INSN:
		IincInsnNode iinc = (IincInsnNode) ain;
		opc += iinc.var + " " + iinc.incr;
		break;
	case AbstractInsnNode.FRAME:
		FrameNode fn = (FrameNode) ain;
		opc = OpUtils.getOpcodeText(fn.type).toLowerCase() + " " + fn.local.size() + " " + fn.stack.size();
		break;
	case AbstractInsnNode.TABLESWITCH_INSN:
		TableSwitchInsnNode tsin = (TableSwitchInsnNode) ain;
		if (tsin.dflt != null) {
			opc += "L" + OpUtils.getLabelIndex(tsin.dflt);
		}
		if (tsin.labels.size() < 20) {
			for (LabelNode l : tsin.labels) {
				opc += " " + "L" + OpUtils.getLabelIndex(l);
			}
		} else {
			opc += " " + tsin.labels.size() + " cases";
		}
		break;
	case AbstractInsnNode.INVOKE_DYNAMIC_INSN:
		InvokeDynamicInsnNode idin = (InvokeDynamicInsnNode) ain;
		opc += idin.name + " " + idin.desc;
		break;
	}
	return opc;
}
 
Example 12
Source File: RuleMethodInterpreter.java    From grappa with Apache License 2.0 4 votes vote down vote up
private static boolean isLabelOrJump(final AbstractInsnNode node)
{
    return node.getType() == AbstractInsnNode.LABEL
        || node.getType() == AbstractInsnNode.JUMP_INSN;
}