Can now specify type of value in LDC being inserted
@@ -18,6 +18,7 @@ import javax.swing.JScrollPane;
import javax.swing.JTextField;
import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
import me.coley.recaf.asm.OpcodeUtil;
@@ -31,7 +32,18 @@ public class OpcodeCreationBox extends BasicFrame {
private static final Map<String, Integer> nameToType = new LinkedHashMap<>();
private final Map<String, JComboBox<String>> typeToOpcodeSelector = new HashMap<>();
private final Map<String, Map<String, JTextField>> typeToMapOfThings = new HashMap<>();
+ /**
+ * List opcode is being inserted to.
+ */
private final OpcodeList list;
+ /**
+ * LDC type selector.
+ */
+ private final JComboBox<String> comboType = new JComboBox<>(new String[] { "String", "int", "long", "float", "double",
+ "Type" });
+ /**
+ * Current type of opcode being created.
+ */
private String currentType;
public OpcodeCreationBox(boolean insertBefore, OpcodeList list, MethodNode method, AbstractInsnNode target) {
@@ -69,7 +81,9 @@ public class OpcodeCreationBox extends BasicFrame {
typeToOpcodeSelector.put(key, comboCodes);
// Type specific content
switch (type) {
- case AbstractInsnNode.LDC_INSN:
+ case AbstractInsnNode.LDC_INSN: {
+ card.add(new LabeledComponent("Const Type: ", comboType));
+ }
case AbstractInsnNode.INT_INSN: {
JTextField text = new JTextField();
card.add(new LabeledComponent("Value: ", text));
@@ -202,7 +216,29 @@ public class OpcodeCreationBox extends BasicFrame {
case AbstractInsnNode.LABEL:
return new LabelNode();
case AbstractInsnNode.LDC_INSN:
- return new LdcInsnNode(get("value"));
+ String ldcStr = get("value");
+ Object cst = null;
+ switch (comboType.getSelectedItem().toString()) {
+ case "String":
+ cst = ldcStr;
+ break;
+ case "int":
+ cst = Integer.parseInt(ldcStr);
+ break;
+ case "long":
+ cst = Long.parseLong(ldcStr);
+ break;
+ case "float":
+ cst = Float.parseFloat(ldcStr);
+ break;
+ case "double":
+ cst = Double.parseDouble(ldcStr);
+ break;
+ case "Type":
+ cst = Type.getType(ldcStr);
+ break;
+ }
+ return new LdcInsnNode(cst);
case AbstractInsnNode.IINC_INSN:
return new IincInsnNode(getInt("var"), getInt("inc"));
case AbstractInsnNode.LINE:
