mirror of
https://github.com/SuspiciousActivity/ByteEdit.git
synced 2026-08-13 17:56:17 +00:00
Better frames
This commit is contained in:
1 parent
ad55d6793c
commit
d1710ea6a5
3 files changed
+125
-177
No files matched your search
@@ -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<Object> 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<LabelNode, Integer> 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<LabelNode, Integer> 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<LabelNode, Integer> labels) {
|
||||
ArrayList<Object> 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<LabelNode, Integer> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> 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<Object> list, HashMap<Label, Integer> labels) {
|
||||
ArrayList<String> 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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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, "<html><b><u>method</u></b><br>Creates an example method</html>"));
|
||||
provider.addCompletion(new ShorthandCompletion(provider, "frame", "frame FULL l:[] s:[]", null,
|
||||
"<html><b><u>frame</u></b><br>Creates a stack map frame</html>"));
|
||||
"<html><b><u>frame</u></b><br>Creates a stack map frame<br><br><b>Possible frames:</b><br><ul><li><code>SAME: same locals, empty stack</code></li><li><code>SAME1: same locals, stack has 1 entry</code></li><li><code>CHOP: same locals - k, empty stack</code></li><li><code>APPEND: same locals + k, empty stack</code></li><li><code>FULL: define locals, define stack</code></li></ul></html>"));
|
||||
provider.addCompletion(new BasicCompletion(provider, "SAME", null,
|
||||
"<html><b><u>Frames:</u></b><br><code>SAME</code><br><br><u>Locals:</u> same as previous<br><u>Stack:</u> empty</html>"));
|
||||
provider.addCompletion(new BasicCompletion(provider, "SAME1", null,
|
||||
"<html><b><u>Frames:</u></b><br><code>SAME1 [(type)]</code><br><br><u>Locals:</u> same as previous<br><u>Stack:</u> 1 entry</html>"));
|
||||
provider.addCompletion(new BasicCompletion(provider, "CHOP", null,
|
||||
"<html><b><u>Frames:</u></b><br><code>CHOP (int:k)</code><br><br><u>Locals:</u> removes the top <i>k</i> elements<br><u>Stack:</u> empty</html>"));
|
||||
provider.addCompletion(new BasicCompletion(provider, "APPEND", null,
|
||||
"<html><b><u>Frames:</u></b><br><code>APPEND [(type), (type), ...]</code><br><br><u>Locals:</u> adds the elements to the top<br><u>Stack:</u> empty</html>"));
|
||||
provider.addCompletion(new BasicCompletion(provider, "FULL", null,
|
||||
"<html><b><u>Frames:</u></b><br><code>FULL [(type), (type), ...] [(type), (type), ...]</code><br><i>first locals, then stack</i><br><br><u>Locals:</u> sets the elements<br><u>Stack:</u> sets the elements</html>"));
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user