From ce76d3c045c6d470b20b42d01eadebebd1f18196 Mon Sep 17 00:00:00 2001 From: Apo_Tek Date: Sat, 16 Sep 2023 20:53:58 +0200 Subject: [PATCH 01/12] Rework jar entries sorting in TreeView --- .../controllers/TreeController.java | 15 ++++---- .../sotasan/decompiler/models/BaseModel.java | 34 ++++++++++++------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/sotasan/decompiler/controllers/TreeController.java b/src/main/java/com/sotasan/decompiler/controllers/TreeController.java index 5d21722..f140131 100644 --- a/src/main/java/com/sotasan/decompiler/controllers/TreeController.java +++ b/src/main/java/com/sotasan/decompiler/controllers/TreeController.java @@ -2,14 +2,15 @@ import com.sotasan.decompiler.models.ArchiveModel; import com.sotasan.decompiler.models.BaseModel; -import com.sotasan.decompiler.models.FileModel; -import com.sotasan.decompiler.models.PackageModel; import com.sotasan.decompiler.views.TreeView; import lombok.Getter; import org.jetbrains.annotations.NotNull; + import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; +import java.util.Collections; +import java.util.List; public class TreeController extends BaseController { @@ -29,15 +30,11 @@ public void setArchive(ArchiveModel archiveModel) { getView().getTree().expandPath(new TreePath(treeNode.getPath())); } - // TODO: Update sorting (+ Alphabetic, Inside Loader) private @NotNull DefaultMutableTreeNode createTreeNode(BaseModel baseModel) { DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(baseModel); - for (BaseModel child : baseModel.getChildren()) - if (child instanceof PackageModel) - treeNode.add(createTreeNode(child)); - for (BaseModel child : baseModel.getChildren()) - if (child instanceof FileModel) - treeNode.add(createTreeNode(child)); + List children = baseModel.getChildren(); + Collections.sort(children); + children.forEach(child -> treeNode.add(createTreeNode(child))); return treeNode; } diff --git a/src/main/java/com/sotasan/decompiler/models/BaseModel.java b/src/main/java/com/sotasan/decompiler/models/BaseModel.java index 26d8c66..4fd7f2b 100644 --- a/src/main/java/com/sotasan/decompiler/models/BaseModel.java +++ b/src/main/java/com/sotasan/decompiler/models/BaseModel.java @@ -2,34 +2,44 @@ import lombok.Getter; import lombok.SneakyThrows; +import org.jetbrains.annotations.NotNull; + import java.awt.*; import java.util.ArrayList; import java.util.List; import java.util.Objects; -public abstract class BaseModel { +@Getter +public abstract class BaseModel implements Comparable { - @Getter private final List children = new ArrayList<>(); - @Getter private final String path; - @Getter private String name; - @Getter private Image icon; + private final List children = new ArrayList<>(); + private final String path; + private String name; + private Image icon; public BaseModel(String path, boolean directory) { this.path = path; name = path; - - if (directory) - name = path.substring(0, path.length() - 1); + if (directory) name = path.substring(0, path.length() - 1); name = name.substring(name.lastIndexOf('/') + 1); } - public boolean isClass() { - return name.toLowerCase().endsWith(".class"); - } - @SneakyThrows public void setIcon(String path) { icon = Toolkit.getDefaultToolkit().createImage(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(path)).readAllBytes()); } + @Override + public int compareTo(@NotNull BaseModel o) { + Class thisClazz = this.getClass(); + Class otherClazz = o.getClass(); + if (thisClazz.equals(otherClazz)) { + return this.getName().compareToIgnoreCase(o.getName()); + } else if (thisClazz.equals(FileModel.class)) { + return +1; + } else if (otherClazz.equals(FileModel.class)) { + return -1; + } + return 0; + } } \ No newline at end of file From ede2dd7f5facbeb26e1b510cb42a2a7ab48cc7de Mon Sep 17 00:00:00 2001 From: Apo_Tek Date: Sat, 16 Sep 2023 20:55:57 +0200 Subject: [PATCH 02/12] Add display for non class files - Files are displayed as plain text TODO: Find a way to deal with syntax highlighting --- .../decompiler/controllers/TabController.java | 10 +++++++- .../sotasan/decompiler/models/FileModel.java | 11 ++++++-- .../sotasan/decompiler/views/TreeView.java | 25 +++++++++++-------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/sotasan/decompiler/controllers/TabController.java b/src/main/java/com/sotasan/decompiler/controllers/TabController.java index e609d2e..3fccf8f 100644 --- a/src/main/java/com/sotasan/decompiler/controllers/TabController.java +++ b/src/main/java/com/sotasan/decompiler/controllers/TabController.java @@ -18,11 +18,19 @@ public TabController(FileModel fileModel) { public void update() { try { - getView().getTextArea().setText(TabsController.getINSTANCE().getTransformer().getInstance().transform(fileModel)); + String text = getText(fileModel); + getView().getTextArea().setText(text); getView().getTextArea().setCaretPosition(0); } catch (Exception e) { getView().getTextArea().setText(e.getMessage()); } } + private String getText(FileModel fileModel) throws Exception { + if (fileModel.isClass()) { + return TabsController.getINSTANCE().getTransformer().getInstance().transform(fileModel); + } + return new String(fileModel.getBytes()); + } + } \ No newline at end of file diff --git a/src/main/java/com/sotasan/decompiler/models/FileModel.java b/src/main/java/com/sotasan/decompiler/models/FileModel.java index f76f44e..f78b846 100644 --- a/src/main/java/com/sotasan/decompiler/models/FileModel.java +++ b/src/main/java/com/sotasan/decompiler/models/FileModel.java @@ -3,13 +3,16 @@ import lombok.Getter; import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; + +import java.util.Locale; import java.util.jar.JarEntry; import java.util.jar.JarFile; +@Getter public class FileModel extends BaseModel { - @Getter private final JarFile jarFile; - @Getter private final JarEntry jarEntry; + private final JarFile jarFile; + private final JarEntry jarEntry; public FileModel(JarFile jarFile, @NotNull JarEntry jarEntry) { super(jarEntry.getName(), false); @@ -18,6 +21,10 @@ public FileModel(JarFile jarFile, @NotNull JarEntry jarEntry) { setIcon(isClass() ? "icons/class.png" : "icons/file.png"); } + public boolean isClass() { + return this.getName().toLowerCase(Locale.ROOT).endsWith(".class"); + } + @SneakyThrows public byte[] getBytes() { return jarFile.getInputStream(jarEntry).readAllBytes(); diff --git a/src/main/java/com/sotasan/decompiler/views/TreeView.java b/src/main/java/com/sotasan/decompiler/views/TreeView.java index 1dd90e5..69df18c 100644 --- a/src/main/java/com/sotasan/decompiler/views/TreeView.java +++ b/src/main/java/com/sotasan/decompiler/views/TreeView.java @@ -57,17 +57,20 @@ private static class TreeMouseAdapter extends MouseAdapter { @Override public void mouseClicked(@NotNull MouseEvent event) { - if (event.getClickCount() == 2) { - TreePath path = ((JTree) event.getSource()).getSelectionPath(); - if (path != null) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); - if (node.getUserObject() != null) { - BaseModel model = (BaseModel) node.getUserObject(); - if (model instanceof FileModel && model.isClass()) { - TabsController.getINSTANCE().addTab((FileModel) model); - } - } - } + if (event.getClickCount() != 2) + return; + + TreePath path = ((JTree) event.getSource()).getSelectionPath(); + if (path == null) + return; + + DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); + if (node.getUserObject() == null) + return; + + BaseModel model = (BaseModel) node.getUserObject(); + if (model instanceof FileModel) { + TabsController.getINSTANCE().addTab((FileModel) model); } } From c71e9d1f399dcdb061e3e4472b29d202b8a3fc57 Mon Sep 17 00:00:00 2001 From: Apo_Tek Date: Sat, 16 Sep 2023 20:58:01 +0200 Subject: [PATCH 03/12] Clear file tabs on Transformer change to avoid bugs - CFR handles inner classes in such a way it seems to provoke an infinite loop if inner classes tabs were opened when switching to CFR --- .../sotasan/decompiler/controllers/TabsController.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sotasan/decompiler/controllers/TabsController.java b/src/main/java/com/sotasan/decompiler/controllers/TabsController.java index 4de98dd..9adae17 100644 --- a/src/main/java/com/sotasan/decompiler/controllers/TabsController.java +++ b/src/main/java/com/sotasan/decompiler/controllers/TabsController.java @@ -21,8 +21,13 @@ private TabsController() { @Override public void actionPerformed(ActionEvent event) { - for (int i = 0; i < getView().getTabCount(); i++) - ((TabView) getView().getComponentAt(i)).getController().update(); + clearTabs(); + for (int i = 0; i < getView().getTabCount(); i++) { + Object current = getView().getComponentAt(i); + if (!(current instanceof TabView)) + continue; + ((TabView) current).getController().update(); + } } public void addTab(@NotNull FileModel fileModel) { From f1314e4fdaeaec38aafa0abbbb6dbc2ab8511ba6 Mon Sep 17 00:00:00 2001 From: Apo_Tek Date: Sat, 16 Sep 2023 21:03:26 +0200 Subject: [PATCH 04/12] Minor change --- src/main/java/com/sotasan/decompiler/models/BaseModel.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sotasan/decompiler/models/BaseModel.java b/src/main/java/com/sotasan/decompiler/models/BaseModel.java index 4fd7f2b..ee3b9cc 100644 --- a/src/main/java/com/sotasan/decompiler/models/BaseModel.java +++ b/src/main/java/com/sotasan/decompiler/models/BaseModel.java @@ -19,9 +19,8 @@ public abstract class BaseModel implements Comparable { public BaseModel(String path, boolean directory) { this.path = path; - name = path; - if (directory) name = path.substring(0, path.length() - 1); - name = name.substring(name.lastIndexOf('/') + 1); + this.name = directory ? path.substring(0, path.length() - 1) + : path.substring(path.lastIndexOf('/') + 1); } @SneakyThrows From 212811f0bd7173ce4f523247b9bdf8cb1ffb7234 Mon Sep 17 00:00:00 2001 From: Apo_Tek Date: Sat, 16 Sep 2023 22:13:33 +0200 Subject: [PATCH 05/12] Add FR & NL locales --- src/main/resources/langs/language_fr.properties | 14 ++++++++++++++ src/main/resources/langs/language_nl.properties | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/main/resources/langs/language_fr.properties create mode 100644 src/main/resources/langs/language_nl.properties diff --git a/src/main/resources/langs/language_fr.properties b/src/main/resources/langs/language_fr.properties new file mode 100644 index 0000000..d5bff12 --- /dev/null +++ b/src/main/resources/langs/language_fr.properties @@ -0,0 +1,14 @@ +file=Fichier +file.openFile=Ouvrir un fichier +file.newInstance=Nouvelle instance +file.exit=Quitter + +help=Aide + +empty=Aucun fichier ouvert +empty.drag=Glisser-déposer pour ouvrir + +about=À propos +about.version=Version %s +about.vm=Machine Virtuelle +about.ok=OK \ No newline at end of file diff --git a/src/main/resources/langs/language_nl.properties b/src/main/resources/langs/language_nl.properties new file mode 100644 index 0000000..037a483 --- /dev/null +++ b/src/main/resources/langs/language_nl.properties @@ -0,0 +1,14 @@ +file=Bestand +file.openFile=Bestand openen +file.newInstance=Nieuwe Instantie +file.exit=Verlaten + +help=Hulp + +empty=Geen opende bestand +empty.drag=Slepen en neerzetten om te openen + +about=Over +about.version=Versie %s +about.vm=Virtuele Machine +about.ok=OK \ No newline at end of file From ed3c6679918948469158d070d137426ba34f3043 Mon Sep 17 00:00:00 2001 From: Apo_Tek Date: Sun, 17 Sep 2023 20:54:50 +0200 Subject: [PATCH 06/12] Minor change --- .../java/com/sotasan/decompiler/controllers/TabController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/sotasan/decompiler/controllers/TabController.java b/src/main/java/com/sotasan/decompiler/controllers/TabController.java index 3fccf8f..b36499f 100644 --- a/src/main/java/com/sotasan/decompiler/controllers/TabController.java +++ b/src/main/java/com/sotasan/decompiler/controllers/TabController.java @@ -18,8 +18,7 @@ public TabController(FileModel fileModel) { public void update() { try { - String text = getText(fileModel); - getView().getTextArea().setText(text); + getView().getTextArea().setText(getText(fileModel)); getView().getTextArea().setCaretPosition(0); } catch (Exception e) { getView().getTextArea().setText(e.getMessage()); From 7c0502d8c6f9fb7a2cec8d1405ca30de5cb82d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=8Dta?= Date: Sat, 30 Sep 2023 19:40:48 +0200 Subject: [PATCH 07/12] Fix name --- .../com/sotasan/decompiler/controllers/TreeController.java | 1 - src/main/java/com/sotasan/decompiler/models/BaseModel.java | 6 +++--- src/main/java/com/sotasan/decompiler/models/FileModel.java | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sotasan/decompiler/controllers/TreeController.java b/src/main/java/com/sotasan/decompiler/controllers/TreeController.java index f140131..9793070 100644 --- a/src/main/java/com/sotasan/decompiler/controllers/TreeController.java +++ b/src/main/java/com/sotasan/decompiler/controllers/TreeController.java @@ -5,7 +5,6 @@ import com.sotasan.decompiler.views.TreeView; import lombok.Getter; import org.jetbrains.annotations.NotNull; - import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; diff --git a/src/main/java/com/sotasan/decompiler/models/BaseModel.java b/src/main/java/com/sotasan/decompiler/models/BaseModel.java index ee3b9cc..5fb4d6c 100644 --- a/src/main/java/com/sotasan/decompiler/models/BaseModel.java +++ b/src/main/java/com/sotasan/decompiler/models/BaseModel.java @@ -3,7 +3,6 @@ import lombok.Getter; import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; - import java.awt.*; import java.util.ArrayList; import java.util.List; @@ -19,8 +18,8 @@ public abstract class BaseModel implements Comparable { public BaseModel(String path, boolean directory) { this.path = path; - this.name = directory ? path.substring(0, path.length() - 1) - : path.substring(path.lastIndexOf('/') + 1); + name = directory ? path.substring(0, path.length() - 1) : path; + name = name.substring(name.lastIndexOf('/') + 1); } @SneakyThrows @@ -41,4 +40,5 @@ public int compareTo(@NotNull BaseModel o) { } return 0; } + } \ No newline at end of file diff --git a/src/main/java/com/sotasan/decompiler/models/FileModel.java b/src/main/java/com/sotasan/decompiler/models/FileModel.java index f78b846..d4f5e4b 100644 --- a/src/main/java/com/sotasan/decompiler/models/FileModel.java +++ b/src/main/java/com/sotasan/decompiler/models/FileModel.java @@ -3,7 +3,6 @@ import lombok.Getter; import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; - import java.util.Locale; import java.util.jar.JarEntry; import java.util.jar.JarFile; From cd8be82ac6d00ef4c210f470d24950b53208bb3f Mon Sep 17 00:00:00 2001 From: apo-tek <77404596+apo-tek@users.noreply.github.com> Date: Sat, 30 Sep 2023 19:41:34 +0200 Subject: [PATCH 08/12] Update language_nl.properties --- src/main/resources/langs/language_nl.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/langs/language_nl.properties b/src/main/resources/langs/language_nl.properties index 037a483..0fa1630 100644 --- a/src/main/resources/langs/language_nl.properties +++ b/src/main/resources/langs/language_nl.properties @@ -1,6 +1,6 @@ file=Bestand file.openFile=Bestand openen -file.newInstance=Nieuwe Instantie +file.newInstance=Nieuwe instantie file.exit=Verlaten help=Hulp @@ -11,4 +11,4 @@ empty.drag=Slepen en neerzetten om te openen about=Over about.version=Versie %s about.vm=Virtuele Machine -about.ok=OK \ No newline at end of file +about.ok=OK From 836c733374358ca1558a246f08123bb643948389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=8Dta?= Date: Sat, 30 Sep 2023 19:55:50 +0200 Subject: [PATCH 09/12] Add languages --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b592544..c152629 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,9 @@ Java Decompiler Gui ## Languages +- [Dutch](https://github.com/sotasan/decompiler/blob/master/src/main/resources/langs/language_nl.properties) - [English](https://github.com/sotasan/decompiler/blob/master/src/main/resources/langs/language.properties) +- [French](https://github.com/sotasan/decompiler/blob/master/src/main/resources/langs/language_fr.properties) - [German](https://github.com/sotasan/decompiler/blob/master/src/main/resources/langs/language_de.properties) - [Japanese](https://github.com/sotasan/decompiler/blob/master/src/main/resources/langs/language_ja.properties) - [Russian](https://github.com/sotasan/decompiler/blob/master/src/main/resources/langs/language_ru.properties) From 67392197a5c16fe970f59c955a33a1c075d31121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=8Dta?= Date: Sat, 30 Sep 2023 20:14:55 +0200 Subject: [PATCH 10/12] Remove syntax highlighting for non class files --- .../com/sotasan/decompiler/controllers/TabController.java | 6 +++++- src/main/java/com/sotasan/decompiler/views/TabView.java | 2 -- src/main/java/com/sotasan/decompiler/views/TreeView.java | 3 +-- src/main/resources/langs/language_nl.properties | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sotasan/decompiler/controllers/TabController.java b/src/main/java/com/sotasan/decompiler/controllers/TabController.java index b36499f..419ebeb 100644 --- a/src/main/java/com/sotasan/decompiler/controllers/TabController.java +++ b/src/main/java/com/sotasan/decompiler/controllers/TabController.java @@ -3,15 +3,19 @@ import com.sotasan.decompiler.models.FileModel; import com.sotasan.decompiler.views.TabView; import lombok.Getter; +import org.fife.ui.rsyntaxtextarea.SyntaxConstants; +import org.jetbrains.annotations.NotNull; @Getter public class TabController extends BaseController { private final FileModel fileModel; - public TabController(FileModel fileModel) { + public TabController(@NotNull FileModel fileModel) { super(new TabView()); this.fileModel = fileModel; + if (fileModel.isClass()) + getView().getTextArea().setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); getView().setController(this); update(); } diff --git a/src/main/java/com/sotasan/decompiler/views/TabView.java b/src/main/java/com/sotasan/decompiler/views/TabView.java index b204dbc..4368bb9 100644 --- a/src/main/java/com/sotasan/decompiler/views/TabView.java +++ b/src/main/java/com/sotasan/decompiler/views/TabView.java @@ -5,7 +5,6 @@ import lombok.Setter; import lombok.SneakyThrows; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; -import org.fife.ui.rsyntaxtextarea.SyntaxConstants; import org.fife.ui.rsyntaxtextarea.Theme; import org.fife.ui.rtextarea.RTextScrollPane; import org.jetbrains.annotations.NotNull; @@ -35,7 +34,6 @@ public TabView() { textArea.setDropTarget(null); textArea.setEditable(false); textArea.setHighlightCurrentLine(false); - textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); scrollPane = new RTextScrollPane(textArea); theme.apply(textArea); diff --git a/src/main/java/com/sotasan/decompiler/views/TreeView.java b/src/main/java/com/sotasan/decompiler/views/TreeView.java index 69df18c..9416a7f 100644 --- a/src/main/java/com/sotasan/decompiler/views/TreeView.java +++ b/src/main/java/com/sotasan/decompiler/views/TreeView.java @@ -69,9 +69,8 @@ public void mouseClicked(@NotNull MouseEvent event) { return; BaseModel model = (BaseModel) node.getUserObject(); - if (model instanceof FileModel) { + if (model instanceof FileModel) TabsController.getINSTANCE().addTab((FileModel) model); - } } } diff --git a/src/main/resources/langs/language_nl.properties b/src/main/resources/langs/language_nl.properties index 0fa1630..b4189ce 100644 --- a/src/main/resources/langs/language_nl.properties +++ b/src/main/resources/langs/language_nl.properties @@ -11,4 +11,4 @@ empty.drag=Slepen en neerzetten om te openen about=Over about.version=Versie %s about.vm=Virtuele Machine -about.ok=OK +about.ok=OK \ No newline at end of file From 1571305ebebd2ac03392fbb2e0bbf5665be39100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=8Dta?= Date: Sat, 30 Sep 2023 22:03:05 +0200 Subject: [PATCH 11/12] Fix cfr inner classes --- build.gradle | 2 +- .../decompiler/controllers/TabController.java | 9 ++++----- .../decompiler/controllers/TabsController.java | 8 +++----- .../sotasan/decompiler/models/BaseModel.java | 18 +++++++----------- .../sotasan/decompiler/models/FileModel.java | 3 +-- .../transformers/CFRTransformer.java | 9 ++++++++- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index 8c442b3..569e330 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = "com.sotasan" -version = "0.8.9" +version = "0.9.0" repositories { mavenCentral() diff --git a/src/main/java/com/sotasan/decompiler/controllers/TabController.java b/src/main/java/com/sotasan/decompiler/controllers/TabController.java index 419ebeb..598660e 100644 --- a/src/main/java/com/sotasan/decompiler/controllers/TabController.java +++ b/src/main/java/com/sotasan/decompiler/controllers/TabController.java @@ -29,11 +29,10 @@ public void update() { } } - private String getText(FileModel fileModel) throws Exception { - if (fileModel.isClass()) { - return TabsController.getINSTANCE().getTransformer().getInstance().transform(fileModel); - } - return new String(fileModel.getBytes()); + private String getText(@NotNull FileModel fileModel) throws Exception { + return fileModel.isClass() + ? TabsController.getINSTANCE().getTransformer().getInstance().transform(fileModel) + : new String(fileModel.getBytes()); } } \ No newline at end of file diff --git a/src/main/java/com/sotasan/decompiler/controllers/TabsController.java b/src/main/java/com/sotasan/decompiler/controllers/TabsController.java index 9adae17..727b908 100644 --- a/src/main/java/com/sotasan/decompiler/controllers/TabsController.java +++ b/src/main/java/com/sotasan/decompiler/controllers/TabsController.java @@ -21,12 +21,10 @@ private TabsController() { @Override public void actionPerformed(ActionEvent event) { - clearTabs(); for (int i = 0; i < getView().getTabCount(); i++) { - Object current = getView().getComponentAt(i); - if (!(current instanceof TabView)) - continue; - ((TabView) current).getController().update(); + TabController controller = ((TabView) getView().getComponentAt(i)).getController(); + if (controller.getFileModel().isClass()) + controller.update(); } } diff --git a/src/main/java/com/sotasan/decompiler/models/BaseModel.java b/src/main/java/com/sotasan/decompiler/models/BaseModel.java index 5fb4d6c..90e77ad 100644 --- a/src/main/java/com/sotasan/decompiler/models/BaseModel.java +++ b/src/main/java/com/sotasan/decompiler/models/BaseModel.java @@ -28,17 +28,13 @@ public void setIcon(String path) { } @Override - public int compareTo(@NotNull BaseModel o) { - Class thisClazz = this.getClass(); - Class otherClazz = o.getClass(); - if (thisClazz.equals(otherClazz)) { - return this.getName().compareToIgnoreCase(o.getName()); - } else if (thisClazz.equals(FileModel.class)) { - return +1; - } else if (otherClazz.equals(FileModel.class)) { - return -1; - } - return 0; + public int compareTo(@NotNull BaseModel baseModel) { + Class class1 = getClass(); + Class class2 = baseModel.getClass(); + return class1.equals(class2) ? getName().compareToIgnoreCase(baseModel.getName()) + : class1.equals(FileModel.class) ? 1 + : class2.equals(FileModel.class) ? -1 + : 0; } } \ No newline at end of file diff --git a/src/main/java/com/sotasan/decompiler/models/FileModel.java b/src/main/java/com/sotasan/decompiler/models/FileModel.java index d4f5e4b..341ce44 100644 --- a/src/main/java/com/sotasan/decompiler/models/FileModel.java +++ b/src/main/java/com/sotasan/decompiler/models/FileModel.java @@ -3,7 +3,6 @@ import lombok.Getter; import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; -import java.util.Locale; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -21,7 +20,7 @@ public FileModel(JarFile jarFile, @NotNull JarEntry jarEntry) { } public boolean isClass() { - return this.getName().toLowerCase(Locale.ROOT).endsWith(".class"); + return getName().toLowerCase().endsWith(".class"); } @SneakyThrows diff --git a/src/main/java/com/sotasan/decompiler/transformers/CFRTransformer.java b/src/main/java/com/sotasan/decompiler/transformers/CFRTransformer.java index 8877e00..37b7bc6 100644 --- a/src/main/java/com/sotasan/decompiler/transformers/CFRTransformer.java +++ b/src/main/java/com/sotasan/decompiler/transformers/CFRTransformer.java @@ -5,18 +5,25 @@ import org.benf.cfr.reader.api.ClassFileSource; import org.benf.cfr.reader.api.OutputSinkFactory; import org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair; +import org.benf.cfr.reader.util.getopt.OptionsImpl; import org.jetbrains.annotations.NotNull; import java.util.*; public class CFRTransformer implements ITransformer, ClassFileSource, OutputSinkFactory, OutputSinkFactory.Sink { + private static final Map OPTIONS = Map.of( + OptionsImpl.DECOMPILE_INNER_CLASSES.getName(), String.valueOf(false), + OptionsImpl.RELINK_CONSTANT_STRINGS.getName(), String.valueOf(false), + OptionsImpl.REMOVE_INNER_CLASS_SYNTHETICS.getName(), String.valueOf(false) + ); + private FileModel fileModel; private String output; @Override public String transform(@NotNull FileModel fileModel) { this.fileModel = fileModel; - CfrDriver driver = new CfrDriver.Builder().withClassFileSource(this).withOutputSink(this).build(); + CfrDriver driver = new CfrDriver.Builder().withClassFileSource(this).withOptions(OPTIONS).withOutputSink(this).build(); driver.analyse(Collections.singletonList(fileModel.getPath())); if (output.startsWith("/")) output = output.substring(37); From 47c04f94de80de374765c2bf010296a428319c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=8Dta?= Date: Sat, 30 Sep 2023 22:26:31 +0200 Subject: [PATCH 12/12] Update recursion --- .../com/sotasan/decompiler/controllers/TreeController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sotasan/decompiler/controllers/TreeController.java b/src/main/java/com/sotasan/decompiler/controllers/TreeController.java index 9793070..847409d 100644 --- a/src/main/java/com/sotasan/decompiler/controllers/TreeController.java +++ b/src/main/java/com/sotasan/decompiler/controllers/TreeController.java @@ -33,7 +33,8 @@ public void setArchive(ArchiveModel archiveModel) { DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(baseModel); List children = baseModel.getChildren(); Collections.sort(children); - children.forEach(child -> treeNode.add(createTreeNode(child))); + for (BaseModel child : children) + treeNode.add(createTreeNode(child)); return treeNode; }