Added signatures, fixed accessm, enum and frame bugs

This commit is contained in:
SuspiciousActivity committed 2018-04-22 11:16:59 +02:00
1 parent 96cb81a8ac
commit b98750bae9
3 files changed
+151 -126

No files matched your search

+144 -123
View File
@@ -94,16 +94,18 @@ public class Assembler {
case "class": case "class":
break; break;
case "enum": case "enum":
clazz.access ^= ClassUtil.ACC_ABSTRACT;
clazz.access ^= ClassUtil.ACC_ENUM; clazz.access ^= ClassUtil.ACC_ENUM;
break; break;
case "interface": case "interface":
clazz.access = 0;
clazz.access ^= ClassUtil.ACC_ABSTRACT; clazz.access ^= ClassUtil.ACC_ABSTRACT;
clazz.access ^= ClassUtil.ACC_INTERFACE; clazz.access ^= ClassUtil.ACC_INTERFACE;
break; break;
case "@interface": case "@interface":
clazz.access = 0;
clazz.access ^= ClassUtil.ACC_ABSTRACT; clazz.access ^= ClassUtil.ACC_ABSTRACT;
clazz.access ^= ClassUtil.ACC_ANNOTATION; clazz.access ^= ClassUtil.ACC_ANNOTATION;
clazz.access ^= ClassUtil.ACC_INTERFACE;
break; break;
} }
@@ -134,6 +136,8 @@ public class Assembler {
clazz.fields = new ArrayList<>(); clazz.fields = new ArrayList<>();
clazz.methods = new ArrayList<>(); clazz.methods = new ArrayList<>();
String signature = null;
ArrayList<String> annotationsForNext = new ArrayList<>(); ArrayList<String> annotationsForNext = new ArrayList<>();
while (!(s = read.readLine()).equals("// #Methods")) { while (!(s = read.readLine()).equals("// #Methods")) {
s = s.trim(); s = s.trim();
@@ -142,84 +146,89 @@ public class Assembler {
if (s.startsWith("@")) { if (s.startsWith("@")) {
annotationsForNext.add(s); annotationsForNext.add(s);
} else { } else {
String[] split = s.split(" "); if (s.startsWith("// #Signature: ")) {
boolean hasValue = false; signature = s.substring(15);
if (s.contains(" = ")) { } else {
hasValue = true; String[] split = s.split(" ");
} boolean hasValue = false;
Object value = hasValue ? split[split.length - 1] : null; if (s.contains(" = ")) {
if (hasValue) { hasValue = true;
split = s.substring(0, s.indexOf(" = ")).split(" "); }
} Object value = hasValue ? split[split.length - 1] : null;
String name = split[split.length - 1]; if (hasValue) {
String desc = split[split.length - 2]; split = s.substring(0, s.indexOf(" = ")).split(" ");
}
String name = split[split.length - 1];
String desc = split[split.length - 2];
value = getValue((String) value, desc); value = getValue((String) value, desc);
int access = 0; int access = 0;
if (split.length > 2) { if (split.length > 2) {
String cons = consolidateStrings(split, 0, split.length - 2); String cons = consolidateStrings(split, 0, split.length - 2);
if (cons.contains("public")) { if (cons.contains("public")) {
access ^= ClassUtil.ACC_PUBLIC; access ^= ClassUtil.ACC_PUBLIC;
}
if (cons.contains("private")) {
access ^= ClassUtil.ACC_PRIVATE;
}
if (cons.contains("protected")) {
access ^= ClassUtil.ACC_PROTECTED;
}
if (cons.contains("static")) {
access ^= ClassUtil.ACC_STATIC;
}
if (cons.contains("final")) {
access ^= ClassUtil.ACC_FINAL;
}
if (cons.contains("synchronized")) {
access ^= ClassUtil.ACC_SYNCHRONIZED;
}
if (cons.contains("bridge")) {
access ^= ClassUtil.ACC_BRIDGE;
}
if (cons.contains("varargs")) {
access ^= ClassUtil.ACC_VARARGS;
}
if (cons.contains("native")) {
access ^= ClassUtil.ACC_NATIVE;
}
if (cons.contains("interface")) {
access ^= ClassUtil.ACC_INTERFACE;
}
if (cons.contains("abstract")) {
access ^= ClassUtil.ACC_ABSTRACT;
}
if (cons.contains("strictfp")) {
access ^= ClassUtil.ACC_STRICTFP;
}
if (cons.contains("synthetic")) {
access ^= ClassUtil.ACC_SYNTHETIC;
}
if (cons.contains("annotation")) {
access ^= ClassUtil.ACC_ANNOTATION;
}
if (cons.contains("enum")) {
access ^= ClassUtil.ACC_ENUM;
}
if (cons.contains("mandated")) {
access ^= ClassUtil.ACC_MANDATED;
}
} }
if (cons.contains("private")) { FieldNode node = new FieldNode(access, name, desc, signature, value);
access ^= ClassUtil.ACC_PRIVATE; if (!annotationsForNext.isEmpty()) {
} if (node.visibleAnnotations == null) {
if (cons.contains("protected")) { node.visibleAnnotations = new ArrayList<>();
access ^= ClassUtil.ACC_PROTECTED; }
} for (String anno : annotationsForNext) {
if (cons.contains("static")) { node.visibleAnnotations.add(parseAnnotation(anno));
access ^= ClassUtil.ACC_STATIC; }
} annotationsForNext.clear();
if (cons.contains("final")) {
access ^= ClassUtil.ACC_FINAL;
}
if (cons.contains("synchronized")) {
access ^= ClassUtil.ACC_SYNCHRONIZED;
}
if (cons.contains("bridge")) {
access ^= ClassUtil.ACC_BRIDGE;
}
if (cons.contains("varargs")) {
access ^= ClassUtil.ACC_VARARGS;
}
if (cons.contains("native")) {
access ^= ClassUtil.ACC_NATIVE;
}
if (cons.contains("interface")) {
access ^= ClassUtil.ACC_INTERFACE;
}
if (cons.contains("abstract")) {
access ^= ClassUtil.ACC_ABSTRACT;
}
if (cons.contains("strictfp")) {
access ^= ClassUtil.ACC_STRICTFP;
}
if (cons.contains("synthetic")) {
access ^= ClassUtil.ACC_SYNTHETIC;
}
if (cons.contains("annotation")) {
access ^= ClassUtil.ACC_ANNOTATION;
}
if (cons.contains("enum")) {
access ^= ClassUtil.ACC_ENUM;
}
if (cons.contains("mandated")) {
access ^= ClassUtil.ACC_MANDATED;
} }
clazz.fields.add(node);
signature = null;
} }
FieldNode node = new FieldNode(access, name, desc, null, value);
if (!annotationsForNext.isEmpty()) {
if (node.visibleAnnotations == null) {
node.visibleAnnotations = new ArrayList<>();
}
for (String anno : annotationsForNext) {
node.visibleAnnotations.add(parseAnnotation(anno));
}
annotationsForNext.clear();
}
clazz.fields.add(node);
} }
} }
@@ -253,6 +262,8 @@ public class Assembler {
localVarsToParse.clear(); localVarsToParse.clear();
tryCatchBlocksToParse.clear(); tryCatchBlocksToParse.clear();
stage = 0; stage = 0;
} else if (s.startsWith("// #Signature: ")) {
node.signature = s.substring(15);
} else if (s.equals("// #TryCatch:")) { } else if (s.equals("// #TryCatch:")) {
stage = 1; stage = 1;
} else if (s.equals("// #LocalVars:")) { } else if (s.equals("// #LocalVars:")) {
@@ -278,7 +289,8 @@ public class Assembler {
for (String st : localVarsToParse) { for (String st : localVarsToParse) {
String[] sp = st.split(":"); String[] sp = st.split(":");
int start = Integer.parseInt(sp[3].substring(0, sp[3].length() - 2)); int start = Integer.parseInt(sp[3].substring(0, sp[3].length() - 2));
int end = Integer.parseInt(sp[4]); int end = Integer.parseInt(sp[4].substring(0, sp[4].length() - 4));
String signat = sp[5].equals("null") ? null : sp[5];
LabelNode _start = null; LabelNode _start = null;
LabelNode _end = null; LabelNode _end = null;
for (Entry<Label, Integer> entry : methodLabelMap.entrySet()) { for (Entry<Label, Integer> entry : methodLabelMap.entrySet()) {
@@ -290,7 +302,7 @@ public class Assembler {
} }
} }
node.localVariables.add(new LocalVariableNode(sp[0], sp[1].substring(1, sp[1].length() - 2), node.localVariables.add(new LocalVariableNode(sp[0], sp[1].substring(1, sp[1].length() - 2),
null, _start, _end, Integer.parseInt(sp[2].substring(0, sp[2].length() - 2)))); signat, _start, _end, Integer.parseInt(sp[2].substring(0, sp[2].length() - 2))));
} }
for (String st : tryCatchBlocksToParse) { for (String st : tryCatchBlocksToParse) {
@@ -315,6 +327,7 @@ public class Assembler {
node.tryCatchBlocks.add(new TryCatchBlockNode(_start, _end, _handler, sp[0])); node.tryCatchBlocks.add(new TryCatchBlockNode(_start, _end, _handler, sp[0]));
} }
clazz.methods.add(node); clazz.methods.add(node);
// signature = null;
} else if (!s.startsWith("\t")) { } else if (!s.startsWith("\t")) {
s = s.substring(0, s.length() - 2); s = s.substring(0, s.length() - 2);
if (s.contains(" throws ")) { if (s.contains(" throws ")) {
@@ -554,34 +567,38 @@ public class Assembler {
local = new Object[0]; local = new Object[0];
} else { } else {
String l = str.substring(3, str.indexOf("s:") - 2); String l = str.substring(3, str.indexOf("s:") - 2);
for (String asd : l.split(", ")) { if (l.isEmpty()) {
if (!asd.startsWith("(")) { local = new Object[0];
arr.add(asd); } else {
} else { // anderer typ mit casten for (String asd : l.split(", ")) {
if (asd.startsWith("(label) ")) { if (!asd.startsWith("(")) {
int labelNr = Integer.parseInt(asd.split(" ")[1]); arr.add(asd);
boolean found = false; } else { // anderer typ mit casten
for (Map.Entry<Label, Integer> entry : labels.entrySet()) { if (asd.startsWith("(label) ")) {
if (entry.getValue() == labelNr) { int labelNr = Integer.parseInt(asd.split(" ")[1]);
arr.add(new LabelNode(entry.getKey())); boolean found = false;
found = true; for (Map.Entry<Label, Integer> entry : labels.entrySet()) {
if (entry.getValue() == labelNr) {
arr.add(new LabelNode(entry.getKey()));
found = true;
}
} }
if (!found) {
Label lb = new Label();
labels.put(lb, labelNr);
arr.add(new LabelNode(lb));
}
} else {
arr.add(ClassUtil.getCastedValue(asd.split(" ")[1], asd.split("\\) ")[0].substring(1)));
} }
if (!found) {
Label lb = new Label();
labels.put(lb, labelNr);
arr.add(new LabelNode(lb));
}
} else {
arr.add(ClassUtil.getCastedValue(asd.split(" ")[1], asd.split("\\) ")[0].substring(1)));
} }
} }
} local = new Object[arr.size()];
local = new Object[arr.size()]; int c = 0;
int c = 0; for (Object o : arr) {
for (Object o : arr) { local[c] = o;
local[c] = o; c++;
c++; }
} }
} }
arr.clear(); arr.clear();
@@ -589,34 +606,38 @@ public class Assembler {
stack = new Object[0]; stack = new Object[0];
} else { } else {
String st = str.substring(str.indexOf("s:") + 3, str.length() - 1); String st = str.substring(str.indexOf("s:") + 3, str.length() - 1);
for (String asd : st.split(", ")) { if (st.isEmpty()) {
if (!asd.startsWith("(")) { stack = new Object[0];
arr.add(asd); } else {
} else { // anderer typ mit casten for (String asd : st.split(", ")) {
if (asd.startsWith("(label) ")) { if (!asd.startsWith("(")) {
int labelNr = Integer.parseInt(asd.split(" ")[1]); arr.add(asd);
boolean found = false; } else { // anderer typ mit casten
for (Map.Entry<Label, Integer> entry : labels.entrySet()) { if (asd.startsWith("(label) ")) {
if (entry.getValue() == labelNr) { int labelNr = Integer.parseInt(asd.split(" ")[1]);
arr.add(new LabelNode(entry.getKey())); boolean found = false;
found = true; for (Map.Entry<Label, Integer> entry : labels.entrySet()) {
if (entry.getValue() == labelNr) {
arr.add(new LabelNode(entry.getKey()));
found = true;
}
} }
if (!found) {
Label l = new Label();
labels.put(l, labelNr);
arr.add(new LabelNode(l));
}
} else {
arr.add(ClassUtil.getCastedValue(asd.split(" ")[1], asd.split("\\) ")[0].substring(1)));
} }
if (!found) {
Label l = new Label();
labels.put(l, labelNr);
arr.add(new LabelNode(l));
}
} else {
arr.add(ClassUtil.getCastedValue(asd.split(" ")[1], asd.split("\\) ")[0].substring(1)));
} }
} }
} stack = new Object[arr.size()];
stack = new Object[arr.size()]; int c = 0;
int c = 0; for (Object o : arr) {
for (Object o : arr) { stack[c] = o;
stack[c] = o; c++;
c++; }
} }
} }
return new FrameNode(Integer.parseInt(str1.split(" ")[0]), local != null ? local.length : 0, local, return new FrameNode(Integer.parseInt(str1.split(" ")[0]), local != null ? local.length : 0, local,
+6 -1
View File
@@ -124,6 +124,8 @@ public class Disassembler {
+ "\n\n// #Fields\n"; + "\n\n// #Fields\n";
for (FieldNode fn : classNode.fields) { for (FieldNode fn : classNode.fields) {
if (fn.signature != null)
s += "\t// #Signature: " + fn.signature + "\n";
if (fn.visibleAnnotations != null && !fn.visibleAnnotations.isEmpty()) { if (fn.visibleAnnotations != null && !fn.visibleAnnotations.isEmpty()) {
for (AnnotationNode annotationNode : fn.visibleAnnotations) { for (AnnotationNode annotationNode : fn.visibleAnnotations) {
s += "\t@" + annotationNode.desc; s += "\t@" + annotationNode.desc;
@@ -191,6 +193,8 @@ public class Disassembler {
for (MethodNode mn : classNode.methods) { for (MethodNode mn : classNode.methods) {
try { try {
s += "\t// #Max: l:" + mn.maxLocals + " s:" + mn.maxStack + "\n"; s += "\t// #Max: l:" + mn.maxLocals + " s:" + mn.maxStack + "\n";
if (mn.signature != null)
s += "\t// #Signature: " + mn.signature + "\n";
String[] dis = disassembleMethod(classNode.name, mn); String[] dis = disassembleMethod(classNode.name, mn);
s += dis[2]; s += dis[2];
@@ -297,7 +301,8 @@ public class Disassembler {
if (mn.localVariables != null) { if (mn.localVariables != null) {
for (LocalVariableNode lvn : mn.localVariables) { for (LocalVariableNode lvn : mn.localVariables) {
localVarTable += "\t// " + lvn.name + ": " + lvn.desc + " i:" + lvn.index + " s:" localVarTable += "\t// " + lvn.name + ": " + lvn.desc + " i:" + lvn.index + " s:"
+ labels.get(lvn.start.getLabel()) + " e:" + labels.get(lvn.end.getLabel()) + "\n"; + labels.get(lvn.start.getLabel()) + " e:" + labels.get(lvn.end.getLabel()) + " sig:"
+ lvn.signature + "\n";
} }
} }
if (mn.tryCatchBlocks != null) { if (mn.tryCatchBlocks != null) {
+1 -2
View File
@@ -162,7 +162,7 @@ public class Main extends JFrame {
splitPane.setLeftComponent(scrollPane); splitPane.setLeftComponent(scrollPane);
textArea = new RSyntaxTextArea(); textArea = new RSyntaxTextArea();
CompletionProvider provider = createCompletionProvider(); CompletionProvider provider = createCompletionProvider();
AutoCompletion ac = new AutoCompletion(provider); AutoCompletion ac = new AutoCompletion(provider);
@@ -219,7 +219,6 @@ public class Main extends JFrame {
} }
} }
}, ctrlS, JComponent.WHEN_FOCUSED); }, ctrlS, JComponent.WHEN_FOCUSED);
textArea.setFont(new Font("Consolas", 0, 10));
textArea.setEditable(true); textArea.setEditable(true);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA_DISASSEMBLE); textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA_DISASSEMBLE);
textArea.setCodeFoldingEnabled(true); textArea.setCodeFoldingEnabled(true);