From 152957c128694a999e08d4bc81cbb0e3980ed8f4 Mon Sep 17 00:00:00 2001 From: Konloch Date: Sun, 27 Jun 2021 18:10:29 -0700 Subject: [PATCH] Fixed Synchronized Scrolling & Import Directory --- .../club/bytecodeviewer/BytecodeViewer.java | 2 +- .../gui/resourceviewer/ResourceViewPanel.java | 2 +- ...hread.java => ResourceViewProcessing.java} | 4 +-- .../resourceviewer/viewer/ClassViewer.java | 11 ------- .../gui/util/PaneUpdaterThread.java | 20 +++++++++---- .../impl/DirectoryResourceImporter.java | 30 +++++++++++++++---- .../bytecodeviewer/util/MethodParser.java | 6 ++-- 7 files changed, 47 insertions(+), 28 deletions(-) rename src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/{ResourceProcessClassToViewThread.java => ResourceViewProcessing.java} (95%) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index dd271bc8..95e00a5f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -71,7 +71,7 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * http://the.bytecode.club * * TODO BUGS: - * + Synchronized scrolling is broken + * + The compile mode inside the ResourceViewPanel for Krakatau and Smali assembly needs to be changed when opened with those specific decompilers * + Spam-clicking the refresh button will cause the swing thread to deadlock (Quickly opening resources used to also do this) * This is caused by the ctrlMouseWheelZoom code, a temporary patch is just removing it worst case * + Fix classfile searcher diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewPanel.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewPanel.java index 713e1709..b44c079b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewPanel.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewPanel.java @@ -56,6 +56,6 @@ public class ResourceViewPanel public void updatePane(ClassViewer cv, byte[] b, JButton button, boolean isPanelEditable) { - updateThread = new ResourceProcessClassToViewThread(this, cv, b, isPanelEditable, button); + updateThread = new ResourceViewProcessing(this, cv, b, isPanelEditable, button); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceProcessClassToViewThread.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewProcessing.java similarity index 95% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceProcessClassToViewThread.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewProcessing.java index d61918a0..46085409 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceProcessClassToViewThread.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceViewProcessing.java @@ -38,7 +38,7 @@ import java.awt.*; * @since 6/27/2021 */ -public class ResourceProcessClassToViewThread extends PaneUpdaterThread +public class ResourceViewProcessing extends PaneUpdaterThread { private final ResourceViewPanel resourceViewPanel; private final ClassViewer cv; @@ -47,7 +47,7 @@ public class ResourceProcessClassToViewThread extends PaneUpdaterThread private final JButton button; public boolean waitingFor; - public ResourceProcessClassToViewThread(ResourceViewPanel resourceViewPanel, ClassViewer cv, byte[] b, boolean isPanelEditable, JButton button) + public ResourceViewProcessing(ResourceViewPanel resourceViewPanel, ClassViewer cv, byte[] b, boolean isPanelEditable, JButton button) { super(resourceViewPanel.panelIndex, resourceViewPanel.decompilerViewIndex); this.resourceViewPanel = resourceViewPanel; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java index 3598f8c8..61d42568 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java @@ -336,17 +336,6 @@ public class ClassViewer extends ResourceViewer } } - public static String getLineText(RSyntaxTextArea area, int line) { - try { - if (line < area.getLineCount()) { - int start = area.getLineStartOffset(line); - int end = area.getLineEndOffset(line); - return area.getText(start, end - start).trim(); - } - } catch (BadLocationException ignored) { } - return ""; - } - public static int getMaxViewLine(RSyntaxTextArea area) { Container parent = area.getParent(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/PaneUpdaterThread.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/PaneUpdaterThread.java index 2ecb20a8..532896d3 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/PaneUpdaterThread.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/PaneUpdaterThread.java @@ -104,12 +104,18 @@ public abstract class PaneUpdaterThread implements Runnable }); } - public final CaretListener caretListener = new CaretListener() { + public final CaretListener caretListener = new CaretListener() + { @Override - public void caretUpdate(CaretEvent e) { + public void caretUpdate(CaretEvent e) + { MethodParser methods = viewer.methods.get(paneIndex); - if (methods != null) { + if (methods != null) + { int methodLine = methods.findActiveMethod(updateUpdaterTextArea.getCaretLineNumber()); + + System.out.println("LINE: " + methodLine); + if (methodLine != -1) { if (BytecodeViewer.viewer.showClassMethods.isSelected()) { if (methodsList != null) { @@ -212,10 +218,12 @@ public abstract class PaneUpdaterThread implements Runnable updateUpdaterTextArea.addCaretListener(caretListener); final MethodParser methods = viewer.methods.get(paneIndex); - for (int i = 0; i < updateUpdaterTextArea.getLineCount(); i++) { - String lineText = ClassViewer.getLineText(updateUpdaterTextArea, i); + for (int i = 0; i < updateUpdaterTextArea.getLineCount(); i++) + { + String lineText = updateUpdaterTextArea.getLineText(i); Matcher regexMatcher = MethodParser.regex.matcher(lineText); - if (regexMatcher.find()) { + if (regexMatcher.find()) + { String methodName = regexMatcher.group("name"); String methodParams = regexMatcher.group("params"); methods.addMethod(i, methodName, methodParams); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java index 72249011..d6b5a0bd 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java @@ -1,9 +1,11 @@ package the.bytecode.club.bytecodeviewer.resources.importing.impl; +import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.resources.importing.Import; import the.bytecode.club.bytecodeviewer.resources.importing.Importer; import the.bytecode.club.bytecodeviewer.util.FileContainer; +import the.bytecode.club.bytecodeviewer.util.JarUtils; import java.io.File; import java.nio.file.Files; @@ -22,12 +24,13 @@ public class DirectoryResourceImporter implements Importer public boolean open(File file) throws Exception { FileContainer container = new FileContainer(file); - HashMap files1 = new HashMap<>(); + HashMap allDirectoryFiles = new HashMap<>(); + HashMap allDirectoryClasses = new HashMap<>(); + boolean finished = false; ArrayList totalFiles = new ArrayList<>(); totalFiles.add(file); - String dir = file.getAbsolutePath();//f.getAbsolutePath().substring(0, f.getAbsolutePath - // ().length()-f.getName().length()); + String dir = file.getAbsolutePath(); while (!finished) { @@ -68,10 +71,26 @@ public class DirectoryResourceImporter implements Importer { Import.DEX.getImporter().open(child); } + else if (fileName.endsWith(".class")) + { + byte[] bytes = Files.readAllBytes(Paths.get(child.getAbsolutePath())); + + String cafebabe = String.format("%02X", bytes[0]) + + String.format("%02X", bytes[1]) + + String.format("%02X", bytes[2]) + + String.format("%02X", bytes[3]); + + //check the header for cafebabe + if (cafebabe.equalsIgnoreCase("cafebabe")) + { + final ClassNode cn = JarUtils.getNode(bytes); + allDirectoryClasses.put(trimmedPath, cn); + } + } else { //pack files into a single container - files1.put(trimmedPath, Files.readAllBytes(Paths.get(child.getAbsolutePath()))); + allDirectoryFiles.put(trimmedPath, Files.readAllBytes(Paths.get(child.getAbsolutePath()))); } } @@ -79,7 +98,8 @@ public class DirectoryResourceImporter implements Importer } } - container.files = files1; + container.classes.addAll(allDirectoryClasses.values()); + container.files = allDirectoryFiles; BytecodeViewer.files.add(container); return true; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/MethodParser.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/MethodParser.java index 9d2027e1..774ec0e9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/MethodParser.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/MethodParser.java @@ -117,8 +117,10 @@ public class MethodParser { return -1; } - public int findActiveMethod(int line) { - if (!methods.isEmpty()) { + public int findActiveMethod(int line) + { + if (!methods.isEmpty()) + { Map.Entry low = methods.floorEntry(line); if (low != null) { return low.getKey();