This commit is contained in:
SuspiciousActivity committed 2021-03-11 19:05:26 +01:00
1 parent 5a5cb6425f
commit 71437eac81
12 files changed
+107 -159

No files matched your search

-1
View File
@@ -125,7 +125,6 @@ public class SearchBox extends JFrame {
public void replace() {
if (!Main.decompiler.isEditable())
return;
String txt = Main.txtByteEditView.getText();
int startPos = Main.txtByteEditView.getSelectionStart();
Main.txtByteEditView.replaceSelection(txtReplace.getText());
Main.txtByteEditView.select(startPos, startPos + txtReplace.getText().length());
+3 -39
View File
@@ -3,24 +3,13 @@ package me.ByteEdit.decompiler;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.benf.cfr.reader.PluginRunner;
import org.benf.cfr.reader.api.ClassFileSource;
import org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair;
import org.benf.cfr.reader.entities.ClassFile;
import org.benf.cfr.reader.entities.Method;
import org.benf.cfr.reader.entities.constantpool.ConstantPool;
import org.benf.cfr.reader.state.ClassFileSourceImpl;
import org.benf.cfr.reader.state.DCCommonState;
import org.benf.cfr.reader.util.bytestream.BaseByteData;
import org.benf.cfr.reader.util.getopt.OptionsImpl;
import org.benf.cfr.reader.util.output.ToStringDumper;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
public class CFRDecompiler implements IDecompiler {
@@ -83,10 +72,10 @@ public class CFRDecompiler implements IDecompiler {
@Override
public String decompile(ClassNode cn) {
return doDecompilation(cn, getBytes(cn), null);
return doDecompilation(cn, getBytes(cn));
}
private static String doDecompilation(ClassNode cn, byte[] b, MethodNode mn) {
private static String doDecompilation(ClassNode cn, byte[] b) {
try {
HashMap<String, String> ops = options;
ClassFileSource cfs = new ClassFileSource() {
@@ -114,24 +103,7 @@ public class CFRDecompiler implements IDecompiler {
throw new RuntimeException();
}
};
PluginRunner runner = new PluginRunner(ops, cfs);
if (mn != null) {
BaseByteData data = new BaseByteData(b);
ClassFile cf = new ClassFile(data, "", initDCState(ops, cfs));
Field cpf = Method.class.getDeclaredField("cp");
Field descI = Method.class.getDeclaredField("descriptorIndex");
descI.setAccessible(true);
cpf.setAccessible(true);
for (Method m : cf.getMethodByName(mn.name)) {
ConstantPool cp = (ConstantPool) cpf.get(m);
if (cp.getUTF8Entry(descI.getInt(m)).getValue().equals(mn.desc)) {
ToStringDumper tsd = new ToStringDumper();
m.dump(tsd, true);
return tsd.toString();
}
}
}
String decompilation = runner.getDecompilationFor(cn.name);
String decompilation = new PluginRunner(ops, cfs).getDecompilationFor(cn.name);
System.gc(); // cfr has a performance bug
return decompilation;
} catch (Exception e) {
@@ -142,12 +114,4 @@ public class CFRDecompiler implements IDecompiler {
return sw.toString();
}
}
private static DCCommonState initDCState(Map<String, String> optionsMap, ClassFileSource classFileSource) {
OptionsImpl options = new OptionsImpl(optionsMap);
if (classFileSource == null)
classFileSource = new ClassFileSourceImpl(options);
DCCommonState dcCommonState = new DCCommonState(options, classFileSource);
return dcCommonState;
}
}
@@ -17,7 +17,6 @@ import org.jetbrains.java.decompiler.struct.StructClass;
import org.jetbrains.java.decompiler.struct.StructContext;
import org.jetbrains.java.decompiler.struct.lazy.LazyLoader;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
public class FernflowerDecompiler implements IBytecodeProvider, IResultSaver, IDecompiler {
@@ -53,10 +52,10 @@ public class FernflowerDecompiler implements IBytecodeProvider, IResultSaver, ID
@Override
public String decompile(ClassNode cn) {
return doDecompilation(cn, getBytes(cn), null);
return doDecompilation(cn, getBytes(cn));
}
public String doDecompilation(ClassNode cn, byte[] b, MethodNode mn) {
public String doDecompilation(ClassNode cn, byte[] b) {
try {
// TODO decompile method only
this.bytes = b;
@@ -5,7 +5,6 @@ import java.io.StringWriter;
import java.lang.reflect.Field;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import com.strobel.assembler.InputTypeLoader;
import com.strobel.assembler.metadata.Buffer;
@@ -21,10 +20,10 @@ public class ProcyonDecompiler implements IDecompiler {
@Override
public String decompile(ClassNode cn) {
return doDecompilation(cn, getBytes(cn), null);
return doDecompilation(cn, getBytes(cn));
}
private static String doDecompilation(ClassNode cn, byte[] b, MethodNode mn) {
private static String doDecompilation(ClassNode cn, byte[] b) {
try {
// TODO decompile method only
DecompilerSettings settings = new DecompilerSettings();
@@ -48,9 +47,8 @@ public class ProcyonDecompiler implements IDecompiler {
buffer.putByteArray(b, 0, b.length);
buffer.position(0);
return true;
} else {
return backLoader.tryLoadType(s, buffer);
}
return backLoader.tryLoadType(s, buffer);
}
});
TypeReference type = metadataSystem.lookupType(cn.name);
+37 -27
View File
@@ -339,6 +339,8 @@ public class Assembler {
tryCatchBlocksToParse.clear();
stage = 0;
} else if (s.startsWith("// #Signature: ")) {
if (node == null)
throw new IllegalStateException("node is null");
node.signature = UnicodeUtils.unescape(hsr, s.substring(15));
} else if (s.equals("// #TryCatch:")) {
stage = 1;
@@ -352,6 +354,8 @@ public class Assembler {
localVarsToParse.add(s);
}
} else if (s.equals("}")) {
if (node == null)
throw new IllegalStateException("node is null");
if (!annotationsForNext.isEmpty()) {
if (node.visibleAnnotations == null) {
node.visibleAnnotations = new ArrayList<>();
@@ -404,6 +408,8 @@ public class Assembler {
}
clazz.methods.add(node);
} else if (!s.startsWith("\t")) {
if (node == null)
throw new IllegalStateException("node is null");
s = s.substring(0, s.length() - 2);
if (s.contains(" throws ")) {
String exceptions = s.substring(s.lastIndexOf(" throws ") + 8);
@@ -477,6 +483,8 @@ public class Assembler {
s = s.substring(1);
if (!temp.isEmpty()) {
if (s.equals("]")) {
if (node == null)
throw new IllegalStateException("node is null");
temp += s;
node.instructions.add(getNode(hsr, temp, methodLabelMap));
temp = "";
@@ -487,6 +495,8 @@ public class Assembler {
if (s.endsWith("[")) {
temp += s + "\n";
} else {
if (node == null)
throw new IllegalStateException("node is null");
node.instructions.add(getNode(hsr, s, methodLabelMap));
}
}
@@ -508,7 +518,8 @@ public class Assembler {
return null;
} finally {
try {
read.close();
if (read != null)
read.close();
} catch (Exception e) {
}
}
@@ -1559,38 +1570,37 @@ 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()) {
if (l.isEmpty())
return EMPTY_OBJECT_ARRAY;
} else {
for (String asd : l.split(", ")) {
if (!asd.startsWith("(")) {
int frameType = ClassUtil.getFrameTypeByName(asd);
if (frameType != -1)
list.add(Integer.valueOf(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;
}
for (String asd : l.split(", ")) {
if (!asd.startsWith("(")) {
int frameType = ClassUtil.getFrameTypeByName(asd);
if (frameType != -1)
list.add(Integer.valueOf(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)));
}
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)));
}
}
return list.toArray(new Object[list.size()]);
}
return list.toArray(new Object[list.size()]);
}
}
+51 -54
View File
@@ -127,7 +127,7 @@ public class Disassembler implements IDecompiler {
ctx.next("\n// #Fields\n");
ctx.next(doFields(classNode.fields, hs));
ctx.next("\n// #Methods\n");
ctx.next(doMethods(classNode.methods, classNode.name, hs));
ctx.next(doMethods(classNode.methods, hs));
ctx.next("}\n");
if (!hs.isEmpty())
@@ -154,48 +154,47 @@ public class Disassembler implements IDecompiler {
s += o + " = [";
valBefore = false;
continue;
} else {
if (o instanceof String[]) {
String[] arr = (String[]) o;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(hs, rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(hs, rofl) + "]";
}
if (o instanceof String[]) {
String[] arr = (String[]) o;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(hs, rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(hs, rofl) + "]";
}
}
s += ", ";
} else if (o instanceof List) {
List list = (List) o;
s += "{ ";
for (Object obj : list) {
if (obj instanceof String[]) {
String[] arr = (String[]) obj;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(hs, rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(hs, rofl);
}
}
} else {
s += "\"" + UnicodeUtils.escape(hs, String.valueOf(obj)) + "\"";
}
s += ", ";
} else if (o instanceof List) {
List list = (List) o;
s += "{ ";
for (Object obj : list) {
if (obj instanceof String[]) {
String[] arr = (String[]) obj;
boolean w8ing = false;
for (String rofl : arr) {
if (!w8ing) {
s += UnicodeUtils.escapeWithSpaces(hs, rofl) + "/";
w8ing = true;
} else {
s += UnicodeUtils.escapeWithSpaces(hs, rofl);
}
}
} else {
s += "\"" + UnicodeUtils.escape(hs, String.valueOf(obj)) + "\"";
}
s += ", ";
}
s = s.substring(0, s.length() - 2);
s += " }], ";
} else if (o instanceof String) {
s += "\"" + UnicodeUtils.escapeWithSpaces(hs, (String) o) + "\"], ";
} else {
s += "(" + o.getClass().getName().replace(".", "/") + ") " + o + "], ";
}
valBefore = true;
s = s.substring(0, s.length() - 2);
s += " }], ";
} else if (o instanceof String) {
s += "\"" + UnicodeUtils.escapeWithSpaces(hs, (String) o) + "\"], ";
} else {
s += "(" + o.getClass().getName().replace(".", "/") + ") " + o + "], ";
}
valBefore = true;
}
if (s.endsWith(", "))
s = s.substring(0, s.length() - 2);
@@ -207,7 +206,7 @@ public class Disassembler implements IDecompiler {
return ctx.finish();
}
private static String doMethods(List<MethodNode> methods, String className, HugeStrings hs)
private static String doMethods(List<MethodNode> methods, HugeStrings hs)
throws InterruptedException, ExecutionException {
boolean multithreaded = Main.INSTANCE.mntmMultithreaded.isSelected();
Future<String>[] futures = new Future[methods.size()];
@@ -221,7 +220,7 @@ public class Disassembler implements IDecompiler {
ms += "\t// #Max: l:" + mn.maxLocals + " s:" + mn.maxStack + "\n";
if (mn.signature != null)
ms += "\t// #Signature: " + UnicodeUtils.escapeWithSpaces(hs, mn.signature) + "\n";
String[] dis = disassembleMethod(className, mn, hs);
String[] dis = disassembleMethod(mn, hs);
ms += dis[2];
ms += dis[1];
if (mn.visibleAnnotations != null && !mn.visibleAnnotations.isEmpty())
@@ -286,7 +285,7 @@ public class Disassembler implements IDecompiler {
return ctx.finish();
}
private static String[] disassembleMethod(String className, MethodNode mn, HugeStrings hs) {
private static String[] disassembleMethod(MethodNode mn, HugeStrings hs) {
HashMap<Label, Integer> labels = new HashMap<Label, Integer>();
String localVarTable;
String tryCatchTable;
@@ -299,7 +298,7 @@ public class Disassembler implements IDecompiler {
for (AbstractInsnNode n = insnList.getFirst(); n != null; n = n.getNext()) {
if (n instanceof LabelNode) {
int id = labels.size() + 1;
if (deobfNumbers)
if (deobfNumbers && labelsReversed != null)
labelsReversed.add(((LabelNode) n).getLabel());
labels.put(((LabelNode) n).getLabel(), id);
}
@@ -336,7 +335,7 @@ public class Disassembler implements IDecompiler {
insnList = calc.get();
int i = 0;
for (AbstractInsnNode n = insnList.getFirst(); n != null; n = n.getNext()) {
if (n instanceof LabelNode) {
if (n instanceof LabelNode && labelsReversed != null) {
((LabelNode) n).setLabel(labelsReversed.get(i++));
}
}
@@ -359,9 +358,8 @@ public class Disassembler implements IDecompiler {
if (n.getOpcode() == Opcodes.NEWARRAY) {
return "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " "
+ ClassUtil.getArrayTypeByID(node.operand) + "\n";
} else {
return "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " " + node.operand + "\n";
}
return "\t\t" + OpcodesReverse.reverseOpcode(n.getOpcode()) + " " + node.operand + "\n";
}
case VAR_INSN: {
VarInsnNode node = (VarInsnNode) n;
@@ -443,16 +441,15 @@ public class Disassembler implements IDecompiler {
+ valueEnd + "\n\t\t\tbuf: " + ClassUtil.getDecompiledValue(buf, "", hs);
s += "\n\t\t]\n";
return s;
} else {
String decomp = ClassUtil.getDecompiledValue(node.cst, "", hs);
if (node.cst instanceof String) {
if (decomp.startsWith("\"#") && decomp.endsWith("\""))
decomp = decomp.substring(1, decomp.length() - 1);
else if (decomp.startsWith("\"\\u0023"))
decomp = "\"#" + decomp.substring(7);
}
return "\t\t" + OpcodesReverse.reverseOpcode(node.getOpcode()) + " " + decomp + "\n";
}
String decomp = ClassUtil.getDecompiledValue(node.cst, "", hs);
if (node.cst instanceof String) {
if (decomp.startsWith("\"#") && decomp.endsWith("\""))
decomp = decomp.substring(1, decomp.length() - 1);
else if (decomp.startsWith("\"\\u0023"))
decomp = "\"#" + decomp.substring(7);
}
return "\t\t" + OpcodesReverse.reverseOpcode(node.getOpcode()) + " " + decomp + "\n";
}
case IINC_INSN: {
IincInsnNode node = (IincInsnNode) n;
-1
View File
@@ -131,7 +131,6 @@ public class SearchBox extends JFrame {
}
public void replace() {
String txt = Main.txtByteEditView.getText();
int startPos = Main.txtByteEditView.getSelectionStart();
Main.txtByteEditView.replaceSelection(txtReplace.getText());
Main.txtByteEditView.select(startPos, startPos + txtReplace.getText().length());
+1 -1
View File
@@ -89,7 +89,7 @@ public class ArchiveTreeModel extends DefaultTreeModel {
}
}
private int getSlashCount(String s) {
private static int getSlashCount(String s) {
int count = 0;
for (char c : s.toCharArray()) {
if (c == '/')
@@ -85,9 +85,8 @@ public class HugeStringsToolTips implements ToolTipSupplier {
} catch (IOException e1) {
}
break;
} else {
len += asm.length();
}
len += asm.length();
}
} catch (Exception e1) {
}
+4 -16
View File
@@ -54,8 +54,6 @@ import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.BadLocationException;
import javax.swing.tree.DefaultTreeCellRenderer;
@@ -168,7 +166,7 @@ public class Main extends JFrame {
/**
* Create a simple provider that adds some Java-related completions.
*/
private CompletionProvider createCompletionProvider() {
private static CompletionProvider createCompletionProvider() {
DefaultCompletionProvider provider = new DefaultCompletionProvider();
for (int i = 0; i < 200; i++) {
String s = OpcodesReverse.reverseOpcode(i);
@@ -290,7 +288,6 @@ public class Main extends JFrame {
if (action == 0) {
final File file = fileChooser.getSelectedFile();
saveFolder = file.getParentFile();
boolean shouldSave = false;
if (file.exists()) {
synchronized (treeLock) {
jarFile = file;
@@ -515,17 +512,8 @@ public class Main extends JFrame {
}
});
scrollPane.setViewportView(tree);
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
synchronized (treeLock) {
if (!isChangingFile) {
SingleThreadedExecutor.execute(
() -> selectFile(((ByteEditTreeNode) e.getPath().getLastPathComponent()).path));
}
}
}
});
tree.addTreeSelectionListener(e -> SingleThreadedExecutor
.execute(() -> selectFile(((ByteEditTreeNode) e.getPath().getLastPathComponent()).path)));
new DropTarget(tree, new DropTargetListener() {
@Override
@@ -760,7 +748,7 @@ public class Main extends JFrame {
}
}
private void saveCurrentClassNode() {
private static void saveCurrentClassNode() {
String txt = txtByteEditView.getText();
for (String s : txt.split("\\/\\/ #Annotations:\n")) {
if (s.isEmpty())
+3 -6
View File
@@ -320,11 +320,9 @@ public class ClassUtil {
s += "enum ";
acc ^= ACC_ENUM;
}
if (acc == access) {
if (acc == access)
return s;
} else {
return "0x" + Integer.toHexString(access) + " ";
}
return "0x" + Integer.toHexString(access) + " ";
}
/**
@@ -544,8 +542,7 @@ public class ClassUtil {
DecompilationInterface di = diMap.get(o.getClass());
if (di != null)
return di.apply(o, desc, escapeSpaces, hs);
else
return o.toString();
return o.toString();
}
public static String getDecompiledValue(Object o, String desc, HugeStrings hs) {
+2 -4
View File
@@ -84,11 +84,9 @@ public class UnicodeUtils {
sb.append(c);
}
if (stage != 0) {
if (unicodeBuffer != 0) {
if (unicodeBuffer != 0)
throw new IllegalArgumentException("The unicode at the end is incomplete.");
} else {
throw new IllegalArgumentException("'\\' at the end is invalid.");
}
throw new IllegalArgumentException("'\\' at the end is invalid.");
}
return sb.toString();
}