diff --git a/src/me/ByteEdit/edit/Assembler.java b/src/me/ByteEdit/edit/Assembler.java index 19ff247..3081875 100644 --- a/src/me/ByteEdit/edit/Assembler.java +++ b/src/me/ByteEdit/edit/Assembler.java @@ -674,118 +674,41 @@ public class Assembler { labels.put(ln, labelNr); return new LineNumberNode(Integer.parseInt(s.split(" ")[0]), ln); } else if (s.startsWith("// frame ")) { - String str1 = s.substring(7); - String str = str1.substring(str1.indexOf(' ', 3) + 1); - Object[] local; - Object[] stack; - ArrayList arr = new ArrayList<>(); - if (str.startsWith("l:null")) { - local = new Object[0]; - } else { - String l = str.substring(3, str.indexOf("s:") - 2); - if (l.isEmpty()) { - local = new Object[0]; - } else { - for (String asd : l.split(", ")) { - if (!asd.startsWith("(")) { - int frameType = ClassUtil.getFrameTypeByName(asd); - if (frameType != -1) - arr.add(new Integer(frameType)); - else - arr.add(UnicodeUtils.unescape(hsr, asd.substring(1, asd.length() - 1))); - } else { - if (asd.startsWith("(label) ")) { - int labelNr = Integer.parseInt(asd.split(" ")[1]); - boolean found = false; - for (Map.Entry entry : labels.entrySet()) { - if (entry.getValue() == labelNr) { - arr.add(entry.getKey()); - found = true; - } - } - if (!found) { - LabelNode ln = new LabelNode(new Label()); - labels.put(ln, labelNr); - arr.add(ln); - } - } else { - arr.add(ClassUtil.getCastedValue(asd.split(" ")[1], asd.split("\\) ")[0].substring(1))); - } - } - } - local = new Object[arr.size()]; - int c = 0; - for (Object o : arr) { - local[c] = o; - c++; - } - } - } - arr.clear(); - if (str.endsWith("s:null")) { - stack = new Object[0]; - } else { - String st = str.substring(str.indexOf("s:") + 3, str.length() - 1); - if (st.isEmpty()) { - stack = new Object[0]; - } else { - for (String asd : st.split(", ")) { - if (!asd.startsWith("(")) { - int frameType = ClassUtil.getFrameTypeByName(asd); - if (frameType != -1) - arr.add(new Integer(frameType)); - else - arr.add(UnicodeUtils.unescape(hsr, asd.substring(1, asd.length() - 1))); - } else { - if (asd.startsWith("(label) ")) { - int labelNr = Integer.parseInt(asd.split(" ")[1]); - boolean found = false; - for (Map.Entry entry : labels.entrySet()) { - if (entry.getValue() == labelNr) { - arr.add(entry.getKey()); - found = true; - } - } - if (!found) { - LabelNode ln = new LabelNode(new Label()); - labels.put(ln, labelNr); - arr.add(ln); - } - } else { - arr.add(ClassUtil.getCastedValue(asd.split(" ")[1], asd.split("\\) ")[0].substring(1))); - } - } - } - stack = new Object[arr.size()]; - int c = 0; - for (Object o : arr) { - stack[c] = o; - c++; - } - } - } + String str1 = s.substring(9); + String[] split = str1.split(" ", 2); int type = 0; - switch (str1.substring(str1.indexOf(' ', 1) + 1, str1.indexOf(' ', 3))) { - case "NEW": - type = Opcodes.F_NEW; - break; - case "FULL": - type = Opcodes.F_FULL; - break; - case "APPEND": - type = Opcodes.F_APPEND; - break; - case "CHOP": - type = Opcodes.F_CHOP; - break; + Object[] local = null; + Object[] stack = null; + int localLen = 0; + int stackLen = 0; + switch (split[0].toUpperCase()) { case "SAME": type = Opcodes.F_SAME; break; case "SAME1": type = Opcodes.F_SAME1; + stack = parseFrameList(hsr, split[1], labels); + stackLen = stack.length; + break; + case "CHOP": + type = Opcodes.F_CHOP; + localLen = Integer.parseInt(split[1]); + break; + case "APPEND": + type = Opcodes.F_APPEND; + local = parseFrameList(hsr, split[1], labels); + localLen = local.length; + break; + case "FULL": + type = Opcodes.F_FULL; + split = split[1].split("\\] \\[", 2); + local = parseFrameList(hsr, split[0] + "]", labels); + localLen = local.length; + stack = parseFrameList(hsr, "[" + split[1], labels); + stackLen = stack.length; break; } - return new FrameNode(type, local.length, local, stack.length, stack); + return new FrameNode(type, localLen, local, stackLen, stack); } else { String[] split = s.split(" "); String command = split[0]; @@ -1633,4 +1556,48 @@ public class Assembler { } } } + + private static Object[] parseFrameList(HugeStringsRev hsr, String str, HashMap labels) { + ArrayList list = new ArrayList<>(); + String l = str.substring(1, str.length() - 1); + if (l.isEmpty()) { + return new Object[0]; + } else { + for (String asd : l.split(", ")) { + if (!asd.startsWith("(")) { + int frameType = ClassUtil.getFrameTypeByName(asd); + if (frameType != -1) + list.add(new Integer(frameType)); + else + list.add(UnicodeUtils.unescape(hsr, asd.substring(1, asd.length() - 1))); + } else { + if (asd.startsWith("(label) ")) { + int labelNr = Integer.parseInt(asd.split(" ")[1]); + boolean found = false; + for (Map.Entry entry : labels.entrySet()) { + if (entry.getValue() == labelNr) { + list.add(entry.getKey()); + found = true; + } + } + if (!found) { + LabelNode ln = new LabelNode(new Label()); + labels.put(ln, labelNr); + list.add(ln); + } + } else { + list.add(ClassUtil.getCastedValue(asd.split(" ")[1], asd.split("\\) ")[0].substring(1))); + } + } + } + Object[] arr = new Object[list.size()]; + int c = 0; + for (Object o : list) { + arr[c] = o; + c++; + } + return arr; + } + } + } diff --git a/src/me/ByteEdit/edit/Disassembler.java b/src/me/ByteEdit/edit/Disassembler.java index fb9d7a8..4fa9423 100644 --- a/src/me/ByteEdit/edit/Disassembler.java +++ b/src/me/ByteEdit/edit/Disassembler.java @@ -636,81 +636,25 @@ public class Disassembler { } case FRAME: { FrameNode node = (FrameNode) n; - String type = ""; + String out = ""; switch (node.type) { - case Opcodes.F_NEW: - type = "NEW"; - break; - case Opcodes.F_FULL: - type = "FULL"; - break; - case Opcodes.F_APPEND: - type = "APPEND"; - break; - case Opcodes.F_CHOP: - type = "CHOP"; - break; case Opcodes.F_SAME: - type = "SAME"; + out = "SAME"; break; case Opcodes.F_SAME1: - type = "SAME1"; + out = "SAME1 " + getFrameArray(hs, node.stack, labels); + break; + case Opcodes.F_CHOP: + out = "CHOP " + Integer.toString(node.local.size()); + break; + case Opcodes.F_APPEND: + out = "APPEND " + getFrameArray(hs, node.local, labels); + break; + case Opcodes.F_FULL: + out = "FULL " + getFrameArray(hs, node.local, labels) + " " + getFrameArray(hs, node.stack, labels); break; } - String s = "\t\t// frame " + type + " l:"; - ArrayList arr = new ArrayList<>(); - if (node.local != null) { - for (Object o : node.local) { - if (o == null) { - arr.add(null); - } else { - if (o instanceof String) { - arr.add("\"" + UnicodeUtils.escapeWithSpaces(hs, (String) o) + "\""); - } else if (o instanceof LabelNode) { - arr.add("(label) " + labels.get(((LabelNode) o).getLabel())); - } else if (o instanceof Integer) { - String frameType = ClassUtil.getFrameTypeByID(((Integer) o).intValue()); - if (frameType != null) - arr.add(frameType); - else - arr.add("(" + o.getClass().getName().replace(".", "/") + ") " + o); - } else { - arr.add("(" + o.getClass().getName().replace(".", "/") + ") " + o); - } - } - } - s += arr.toString(); - } else { - s += "null"; - } - arr.clear(); - s += " s:"; - if (node.stack != null) { - for (Object o : node.stack) { - if (o == null) { - arr.add(null); - } else { - if (o instanceof String) { - arr.add("\"" + UnicodeUtils.escapeWithSpaces(hs, (String) o) + "\""); - } else if (o instanceof LabelNode) { - arr.add("(label) " + labels.get(((LabelNode) o).getLabel())); - } else if (o instanceof Integer) { - String frameType = ClassUtil.getFrameTypeByID(((Integer) o).intValue()); - if (frameType != null) - arr.add(frameType); - else - arr.add("(" + o.getClass().getName().replace(".", "/") + ") " + o); - } else { - arr.add("(" + o.getClass().getName().replace(".", "/") + ") " + o); - } - } - } - s += arr.toString(); - } else { - s += "null"; - } - s += "\n"; - return s; + return "\t\t// frame " + out + "\n"; } case LINE: { LineNumberNode node = (LineNumberNode) n; @@ -723,4 +667,31 @@ public class Disassembler { } } + private static String getFrameArray(HugeStrings hs, List list, HashMap labels) { + ArrayList arr = new ArrayList<>(); + if (list != null) { + for (Object o : list) { + if (o == null) { + arr.add(null); + } else { + if (o instanceof String) { + arr.add("\"" + UnicodeUtils.escapeWithSpaces(hs, (String) o) + "\""); + } else if (o instanceof LabelNode) { + arr.add("(label) " + labels.get(((LabelNode) o).getLabel())); + } else if (o instanceof Integer) { + String frameType = ClassUtil.getFrameTypeByID(((Integer) o).intValue()); + if (frameType != null) + arr.add(frameType); + else + arr.add("(" + o.getClass().getName().replace(".", "/") + ") " + o); + } else { + arr.add("(" + o.getClass().getName().replace(".", "/") + ") " + o); + } + } + } + return arr.toString(); + } + return "null"; + } + } diff --git a/src/me/ByteEdit/main/Main.java b/src/me/ByteEdit/main/Main.java index 35d3d0f..29d8078 100644 --- a/src/me/ByteEdit/main/Main.java +++ b/src/me/ByteEdit/main/Main.java @@ -231,7 +231,17 @@ public class Main extends JFrame { "// #Max: l:0 s:0\n\t// #TryCatch:\n\t// #LocalVars:\n\tpublic static method ()V {\n\t\treturn\n\t}", null, "method
Creates an example method")); provider.addCompletion(new ShorthandCompletion(provider, "frame", "frame FULL l:[] s:[]", null, - "frame
Creates a stack map frame")); + "frame
Creates a stack map frame

Possible frames:
  • SAME: same locals, empty stack
  • SAME1: same locals, stack has 1 entry
  • CHOP: same locals - k, empty stack
  • APPEND: same locals + k, empty stack
  • FULL: define locals, define stack
")); + provider.addCompletion(new BasicCompletion(provider, "SAME", null, + "Frames:
SAME

Locals: same as previous
Stack: empty")); + provider.addCompletion(new BasicCompletion(provider, "SAME1", null, + "Frames:
SAME1 [(type)]

Locals: same as previous
Stack: 1 entry")); + provider.addCompletion(new BasicCompletion(provider, "CHOP", null, + "Frames:
CHOP (int:k)

Locals: removes the top k elements
Stack: empty")); + provider.addCompletion(new BasicCompletion(provider, "APPEND", null, + "Frames:
APPEND [(type), (type), ...]

Locals: adds the elements to the top
Stack: empty")); + provider.addCompletion(new BasicCompletion(provider, "FULL", null, + "Frames:
FULL [(type), (type), ...] [(type), (type), ...]
first locals, then stack

Locals: sets the elements
Stack: sets the elements")); return provider; } @@ -417,10 +427,10 @@ public class Main extends JFrame { group.add(rdbtnmntm1000); group.add(rdbtnmntm5000); group.add(rdbtnmntm10000); - + mnDeobfuscation = new JMenu("Deobfuscation"); menuBar.add(mnDeobfuscation); - + mntmNumbers = new JCheckBoxMenuItem("Numbers"); mnDeobfuscation.add(mntmNumbers); @@ -680,7 +690,7 @@ public class Main extends JFrame { len += asm.length(); } } - } catch (BadLocationException e1) { + } catch (Exception e1) { } return null; }