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

The following examples show how to use org.objectweb.asm.tree.AbstractInsnNode#LDC_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: 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 2
Source File: CorrelationMapper.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get's a member's class types from its description. Best for methods.
 * 
 * @param member
 * @param map
 * @return
 */
private static List<MappedClass> getTypesFromMember(MappedMember member, Map<String, MappedClass> map) {
	List<String> names = RegexUtils.matchDescriptionClasses(member.getDesc());
	if (member.isMethod()) {
		for (AbstractInsnNode ain : member.getMethodNode().instructions.toArray()) {
			if (ain.getType() == AbstractInsnNode.METHOD_INSN) {
				MethodInsnNode min = (MethodInsnNode) ain;
				names.addAll(RegexUtils.matchDescriptionClasses(min.desc));
				names.add(min.owner);
			} else if (ain.getType() == AbstractInsnNode.FIELD_INSN) {
				FieldInsnNode fin = (FieldInsnNode) ain;
				names.addAll(RegexUtils.matchDescriptionClasses(fin.desc));
				names.add(fin.owner);
			} else if (ain.getType() == AbstractInsnNode.TYPE_INSN) {
				TypeInsnNode tin = (TypeInsnNode) ain;
				names.addAll(RegexUtils.matchDescriptionClasses(tin.desc));
			} else if (ain.getType() == AbstractInsnNode.LDC_INSN) {
				LdcInsnNode ldc = (LdcInsnNode) ain;
				if (ldc.cst instanceof Type) {
					Type t = (Type) ldc.cst;
					names.add(t.getClassName().replace(".", "/"));
				}
			}
		}
	}
	if (names.size() == 0) {
		return null;
	}
	List<MappedClass> classes = new ArrayList<MappedClass>();
	for (String name : names) {
		if (!map.containsKey(name)) {
			continue;
		}
		classes.add(map.get(name));
	}
	return classes;
}
 
Example 3
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 4
Source File: InsnUtils.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
public static String getStringValue(AbstractInsnNode node) {
	if (node.getType() == AbstractInsnNode.LDC_INSN) {
		LdcInsnNode ldc = (LdcInsnNode) node;
		return ldc.cst.toString();
	}
	return "";
}
 
Example 5
Source File: LdcTask.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Void doInBackground() throws Exception {
  LazyListModel<SearchEntry> model = new LazyListModel<>();
  Collection<ClassNode> values = jbm.getFile().getClasses().values();
  double size = values.size();
  double i = 0;
  boolean exact = this.exact;
  boolean regex = this.pattern != null;
  for (ClassNode cn : values) {
    for (MethodNode mn : cn.methods) {
      for (AbstractInsnNode ain : mn.instructions) {
        if (ain.getType() == AbstractInsnNode.LDC_INSN) {
          LdcInsnNode lin = (LdcInsnNode) ain;
          String cst = lin.cst.toString();
          if (!caseSens) {
            cst = cst.toLowerCase();
          }
          if (regex ? pattern.matcher(cst).matches() : (exact ? cst.equals(ldc) : cst.contains(ldc))) {
            model.addElement(new SearchEntry(cn, mn, TextUtils.escape(TextUtils.max(lin.cst.toString(), 100))));
          }
        }
      }
    }
    publish(Math.min((int) (i++ / size * 100d) + 1, 100));
  }
  sl.setModel(model);
  publish(100);
  return null;
}
 
Example 6
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 7
Source File: InsnComparator.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Respects {@link #INT_WILDCARD} and {@link #WILDCARD} instruction properties.
 * Always returns true if {@code a} and {@code b} are label, line number, or frame instructions.
 * 
 * @return Whether or not the given instructions are equivalent.
 */
public boolean areInsnsEqual(AbstractInsnNode a, AbstractInsnNode b)
{
	if (a == b)
		return true;

	if (a == null || b == null)
		return false;

	if (a.equals(b))
		return true;

	if (a.getOpcode() != b.getOpcode())
		return false;

	switch (a.getType())
	{
		case AbstractInsnNode.VAR_INSN:
			return areVarInsnsEqual((VarInsnNode) a, (VarInsnNode) b);
		case AbstractInsnNode.TYPE_INSN:
			return areTypeInsnsEqual((TypeInsnNode) a, (TypeInsnNode) b);
		case AbstractInsnNode.FIELD_INSN:
			return areFieldInsnsEqual((FieldInsnNode) a, (FieldInsnNode) b);
		case AbstractInsnNode.METHOD_INSN:
			return areMethodInsnsEqual((MethodInsnNode) a, (MethodInsnNode) b);
		case AbstractInsnNode.LDC_INSN:
			return areLdcInsnsEqual((LdcInsnNode) a, (LdcInsnNode) b);
		case AbstractInsnNode.IINC_INSN:
			return areIincInsnsEqual((IincInsnNode) a, (IincInsnNode) b);
		case AbstractInsnNode.INT_INSN:
			return areIntInsnsEqual((IntInsnNode) a, (IntInsnNode) b);
		default:
			return true;
	}
}
 
Example 8
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 9
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 10
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 11
Source File: MyMenuBar.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
protected void replaceLDC() {
	final JPanel panel = new JPanel(new BorderLayout(5, 5));
	final JPanel input = new JPanel(new GridLayout(0, 1));
	final JPanel labels = new JPanel(new GridLayout(0, 1));
	panel.add(labels, "West");
	panel.add(input, "Center");
	panel.add(new JLabel(JByteMod.res.getResource("big_string_warn")), "South");
	labels.add(new JLabel("Find: "));
	JTextField find = new JTextField();
	input.add(find);
	labels.add(new JLabel("Replace with: "));
	JTextField with = new JTextField();
	input.add(with);
	JComboBox<String> ldctype = new JComboBox<String>(new String[] { "String", "float", "double", "int", "long" });
	ldctype.setSelectedIndex(0);
	labels.add(new JLabel("Ldc Type: "));
	input.add(ldctype);
	JCheckBox exact = new JCheckBox(JByteMod.res.getResource("exact"));
	JCheckBox cases = new JCheckBox(JByteMod.res.getResource("case_sens"));
	labels.add(exact);
	input.add(cases);
	if (JOptionPane.showConfirmDialog(this.jbm, panel, "Replace LDC", JOptionPane.OK_CANCEL_OPTION,
			JOptionPane.PLAIN_MESSAGE, searchIcon) == JOptionPane.OK_OPTION && !find.getText().isEmpty()) {
		int expectedType = ldctype.getSelectedIndex();
		boolean equal = exact.isSelected();
		boolean ignoreCase = !cases.isSelected();
		String findCst = find.getText();
		if (ignoreCase) {
			findCst = findCst.toLowerCase();
		}
		String replaceWith = with.getText();
		int i = 0;
		for (ClassNode cn : jbm.getFile().getClasses().values()) {
			for (MethodNode mn : cn.methods) {
				for (AbstractInsnNode ain : mn.instructions) {
					if (ain.getType() == AbstractInsnNode.LDC_INSN) {
						LdcInsnNode lin = (LdcInsnNode) ain;
						Object cst = lin.cst;
						int type;
						if (cst instanceof String) {
							type = 0;
						} else if (cst instanceof Float) {
							type = 1;
						} else if (cst instanceof Double) {
							type = 2;
						} else if (cst instanceof Long) {
							type = 3;
						} else if (cst instanceof Integer) {
							type = 4;
						} else {
							type = -1;
						}
						String cstStr = cst.toString();
						if (ignoreCase) {
							cstStr = cstStr.toLowerCase();
						}
						if (type == expectedType) {
							if (equal ? cstStr.equals(findCst) : cstStr.contains(findCst)) {
								switch (type) {
								case 0:
									lin.cst = replaceWith;
									break;
								case 1:
									lin.cst = Float.parseFloat(replaceWith);
									break;
								case 2:
									lin.cst = Double.parseDouble(replaceWith);
									break;
								case 3:
									lin.cst = Long.parseLong(replaceWith);
									break;
								case 4:
									lin.cst = Integer.parseInt(replaceWith);
									break;
								}
								i++;
							}
						}
					}
				}
			}
		}
		JByteMod.LOGGER.log(i + " ldc's replaced");
	}
}