From 85197c97397b9ab3d2edadeadbfe4d4a7d852e05 Mon Sep 17 00:00:00 2001 From: Konloch Date: Mon, 21 Jun 2021 17:46:57 -0700 Subject: [PATCH] Code Cleanup --- .../club/bytecodeviewer/BytecodeViewer.java | 3 +- .../bytecodeviewer/gui/MainViewerGUI.java | 1 + .../bytecodeviewer/gui/PaneUpdaterThread.java | 5 +- .../bytecodeviewer/gui/SearchBoxPane.java | 1 + .../club/bytecodeviewer/gui/TabbedPane.java | 114 ++++++++------ .../gui/extras/AboutWindow.java | 37 ++--- .../bytecodeviewer/gui/extras/ExportJar.java | 17 +-- .../gui/extras/JTextAreaOutputStream.java | 31 ++++ .../bytecodeviewer/gui/extras/RunOptions.java | 18 +-- .../gui/extras/SystemErrConsole.java | 47 ++---- .../gui/plugins/GraphicalReflectionKit.java | 6 +- .../plugins/MaliciousCodeScannerOptions.java | 28 ++-- .../gui/plugins/ReplaceStringsOptions.java | 53 +++---- .../gui/resourceviewer/ImageRenderer.java | 141 ++++++++++++++++++ .../ResourceListPane.java | 107 +------------ .../club/bytecodeviewer/util/OpenFile.java | 2 +- 16 files changed, 340 insertions(+), 271 deletions(-) create mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/JTextAreaOutputStream.java create mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ImageRenderer.java rename src/main/java/the/bytecode/club/bytecodeviewer/gui/{ => resourceviewer}/ResourceListPane.java (84%) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 3c5a1a6d..d904c3fd 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -24,7 +24,7 @@ import the.bytecode.club.bootloader.Boot; import the.bytecode.club.bytecodeviewer.api.ClassNodeLoader; import the.bytecode.club.bytecodeviewer.compilers.Compilers; import the.bytecode.club.bytecodeviewer.gui.ClassViewer; -import the.bytecode.club.bytecodeviewer.gui.ResourceListPane; +import the.bytecode.club.bytecodeviewer.gui.resourceviewer.ResourceListPane; import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; import the.bytecode.club.bytecodeviewer.gui.extras.RunOptions; import the.bytecode.club.bytecodeviewer.gui.SearchBoxPane; @@ -104,6 +104,7 @@ public class BytecodeViewer public static Refactorer refactorer = new Refactorer(); public static List files = new ArrayList<>(); //all of BCV's loaded files/classes/etc public static List createdProcesses = new ArrayList<>(); + public static final boolean EXPERIMENTAL_DRAG_TABS = false; /** * The version checker thread diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index 1f72411a..0828e3d3 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -32,6 +32,7 @@ import the.bytecode.club.bytecodeviewer.gui.extras.AboutWindow; import the.bytecode.club.bytecodeviewer.gui.extras.RunOptions; import the.bytecode.club.bytecodeviewer.gui.plugins.MaliciousCodeScannerOptions; import the.bytecode.club.bytecodeviewer.gui.plugins.ReplaceStringsOptions; +import the.bytecode.club.bytecodeviewer.gui.resourceviewer.ResourceListPane; import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameClasses; import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameFields; import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameMethods; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/PaneUpdaterThread.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/PaneUpdaterThread.java index 7631357d..cf8537cf 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/PaneUpdaterThread.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/PaneUpdaterThread.java @@ -47,7 +47,6 @@ import static the.bytecode.club.bytecodeviewer.gui.TabbedPane.BLANK; * @author Konloch * @author DreamSworK */ - public abstract class PaneUpdaterThread extends Thread { public ClassViewer viewer; public RSyntaxTextArea panelArea; @@ -62,8 +61,8 @@ public abstract class PaneUpdaterThread extends Thread { public void run() { doShit(); synchronizePane(); - attachCtrlMouseWheelZoom(scrollPane, panelArea); //freezes the UI for some reason, probably cause BCV is - // doing dumb shit with the swing thread + attachCtrlMouseWheelZoom(scrollPane, panelArea); //freezes the UI for some reason + //probably cause BCV is doing dumb shit with the swing thread } public void attachCtrlMouseWheelZoom(RTextScrollPane scrollPane, RSyntaxTextArea panelArea) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/SearchBoxPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/SearchBoxPane.java index 1876492d..3b6b3b69 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/SearchBoxPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/SearchBoxPane.java @@ -18,6 +18,7 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.gui.resourceviewer.ResourceListPane; import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread; import the.bytecode.club.bytecodeviewer.searching.FieldCallSearch; import the.bytecode.club.bytecodeviewer.searching.LDCSearch; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/TabbedPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/TabbedPane.java index 0db652c8..b53c6f07 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/TabbedPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/TabbedPane.java @@ -14,14 +14,7 @@ import java.awt.event.InputEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import javax.swing.AbstractButton; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JTabbedPane; +import javax.swing.*; import javax.swing.plaf.basic.BasicButtonUI; import the.bytecode.club.bytecodeviewer.BytecodeViewer; @@ -55,6 +48,8 @@ public class TabbedPane extends JPanel { public static final Color BLANK = new Color(0, 0, 0, 0); private final JTabbedPane pane; public final JLabel label; + private DelayTabbedPaneThread probablyABadIdea; + private long startedDragging = 0; private static long zero = System.currentTimeMillis(); public String tabName; public String fileContainerName; @@ -159,48 +154,40 @@ public class TabbedPane extends JPanel { public void mouseReleased(MouseEvent e) { } }); - /*this.addMouseListener(new MouseListener() { - @Override public void mouseClicked(MouseEvent e) {} - @Override public void mouseEntered(MouseEvent arg0) { - } - @Override public void mouseExited(MouseEvent arg0) { - } - @Override public void mousePressed(MouseEvent e) { - if(e.getButton() == 1) - { - startedDragging = System.currentTimeMillis(); - dragging = true; - if (probablyABadIdea != null) - { - probablyABadIdea.stopped = true; - } - probablyABadIdea = new DelayTabbedPaneThread(THIS); - probablyABadIdea.start(); - repaint(); - System.out.println(e.getX()+", "+e.getY()); - Rectangle bounds = new Rectangle(1, 1, e.getX(), e.getY()); - for(int i = 0; i < BytecodeViewer.viewer.workPane.tabs.getTabCount(); i++) - { - Component c = BytecodeViewer.viewer.workPane.tabs.getTabComponentAt(i); - if(c != null && bounds.intersects(c.getBounds())) - { - BytecodeViewer.viewer.workPane.tabs.setSelectedIndex(i); - } - } + + if(BytecodeViewer.EXPERIMENTAL_DRAG_TABS) + { + /*label.addMouseListener(new MouseListener() { + @Override public void mouseClicked(MouseEvent e) {} + @Override public void mouseEntered(MouseEvent arg0) { } - else - { + @Override public void mouseExited(MouseEvent arg0) { + } + @Override public void mousePressed(MouseEvent e) { + onMousePressed(e); + } + @Override public void mouseReleased(MouseEvent e) { stopDragging(e.getX(), e.getY()); } - } - @Override public void mouseReleased(MouseEvent e) { - stopDragging(e.getX(), e.getY()); - } - });*/ + });*/ + + this.addMouseListener(new MouseListener() { + @Override public void mouseClicked(MouseEvent e) {} + @Override public void mouseEntered(MouseEvent arg0) { + } + @Override public void mouseExited(MouseEvent arg0) { + } + @Override public void mousePressed(MouseEvent e) { + onMousePressed(e); + } + @Override public void mouseReleased(MouseEvent e) { + stopDragging(e.getX(), e.getY()); + } + }); + } } private void stopDragging(int mouseX, int mouseY) { - long startedDragging = 0; if (System.currentTimeMillis() - startedDragging >= 210) { Rectangle bounds = new Rectangle(1, 1, mouseX, mouseY); System.out.println("debug-5: " + mouseX + ", " + mouseY); @@ -228,8 +215,43 @@ public class TabbedPane extends JPanel { BytecodeViewer.viewer.workPane.tabs.setTabComponentAt(index, this); } } - label.setBackground(BLANK); - label.updateUI(); + SwingUtilities.invokeLater(() -> + { + label.setBackground(BLANK); + label.updateUI(); + }); + } + + public void onMousePressed(MouseEvent e) + { + BytecodeViewer.viewer.workPane.tabs.dispatchEvent(e); + + if(e.getButton() == 1) + { + startedDragging = System.currentTimeMillis(); + //dragging = true; + if (probablyABadIdea != null) + { + probablyABadIdea.stopped = true; + } + probablyABadIdea = new DelayTabbedPaneThread(TabbedPane.this); + probablyABadIdea.start(); + repaint(); + System.out.println(e.getX()+", "+e.getY()); + Rectangle bounds = new Rectangle(1, 1, e.getX(), e.getY()); + for(int i = 0; i < BytecodeViewer.viewer.workPane.tabs.getTabCount(); i++) + { + Component c = BytecodeViewer.viewer.workPane.tabs.getTabComponentAt(i); + if(c != null && bounds.intersects(c.getBounds())) + { + BytecodeViewer.viewer.workPane.tabs.setSelectedIndex(i); + } + } + } + else + { + stopDragging(e.getX(), e.getY()); + } } private class TabButton extends JButton implements ActionListener { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/AboutWindow.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/AboutWindow.java index 3ad418e7..1d67e4a9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/AboutWindow.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/AboutWindow.java @@ -37,10 +37,12 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * @author Konloch */ -public class AboutWindow extends JFrame { +public class AboutWindow extends JFrame +{ JTextArea textArea = new JTextArea(); - public AboutWindow() { + public AboutWindow() + { this.setIconImages(Resources.iconList); setSize(Toolkit.getDefaultToolkit().getScreenSize()); setType(Type.UTILITY); @@ -57,12 +59,13 @@ public class AboutWindow extends JFrame { } @Override - public void setVisible(boolean b) { + public void setVisible(boolean b) + { super.setVisible(b); textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue())); - textArea.setText("Bytecode Viewer " + VERSION + " is an open source program developed and " - + "maintained by Konloch (konloch@gmail.com) 100% free and open sourced licensed under GPL v3 " - + "CopyLeft\r\n\r\n" + + textArea.setText("Bytecode Viewer " + VERSION + " is an open source program developed and " + + "maintained by Konloch (konloch@gmail.com) 100% free and open sourced licensed under GPL v3 " + + "CopyLeft" + nl + nl + "Settings:" + nl + " Preview Copy: " + PREVIEW_COPY + nl + " Fat Jar: " + FAT_JAR + nl + @@ -81,11 +84,11 @@ public class AboutWindow extends JFrame { " -help Displays the help menu" + nl + " -list Displays the available decompilers" + nl + " -decompiler Selects the decompiler, procyon by default" + nl + - " -i Selects the input file (Jar, Class, APK, ZIP, DEX all work " - + "automatically)" + nl + + " -i Selects the input file (Jar, Class, APK, ZIP, DEX all work " + + "automatically)" + nl + " -o Selects the output file (Java or Java-Bytecode)" + nl + - " -t Must either be the fully qualified classname or \"all\" to decompile" - + " all as zip" + nl + + " -t Must either be the fully qualified classname or \"all\" to decompile" + + " all as zip" + nl + " -nowait Doesn't wait for the user to read the CLI messages" + nl + nl + "Keybinds:" + nl + " CTRL + O: Open/add new jar/class/apk" + nl + @@ -94,13 +97,13 @@ public class AboutWindow extends JFrame { " CTRL + T: Compile" + nl + " CTRL + S: Save classes as zip" + nl + " CTRL + R: Run (EZ-Inject) - dynamically load the classes and invoke a main class" + - "\r\n\r\nCode from various projects has been used, including but not limited to:\r\n J-RET by " - + "WaterWolf\r\n JHexPane by Sam Koivu\r\n RSynaxPane by Robert Futrell\r\n Commons IO by " - + "Apache\r\n ASM by OW2\r\n FernFlower by Stiver\r\n Procyon by Mstrobel\r\n CFR by Lee " - + "Benfield\r\n CFIDE by Bibl\r\n Smali by JesusFreke\r\n Dex2Jar by pxb1..?\r\n Krakatau by " - + "Storyyeller\r\n JD-GUI + JD-Core by The Java-Decompiler Team\r\n Enjarify by " - + "Storyyeller\r\n\r\nIf you're interested in Java Reverse Engineering, join The Bytecode Club - " - + "https://the.bytecode.club"); + "\r\n\r\nCode from various projects has been used, including but not limited to:\r\n J-RET by " + + "WaterWolf\r\n JHexPane by Sam Koivu\r\n RSynaxPane by Robert Futrell\r\n Commons IO by " + + "Apache\r\n ASM by OW2\r\n FernFlower by Stiver\r\n Procyon by Mstrobel\r\n CFR by Lee " + + "Benfield\r\n CFIDE by Bibl\r\n Smali by JesusFreke\r\n Dex2Jar by pxb1..?\r\n Krakatau by " + + "Storyyeller\r\n JD-GUI + JD-Core by The Java-Decompiler Team\r\n Enjarify by " + + "Storyyeller\r\n\r\nIf you're interested in Java Reverse Engineering, join The Bytecode Club - " + + "https://the.bytecode.club"); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/ExportJar.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/ExportJar.java index 5e368be9..8cdf28cc 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/ExportJar.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/ExportJar.java @@ -34,8 +34,10 @@ import the.bytecode.club.bytecodeviewer.util.JarUtils; * @author Konloch */ -public class ExportJar extends JFrame { - public ExportJar(final String jarPath) { +public class ExportJar extends JFrame +{ + public ExportJar(final String jarPath) + { setSize(new Dimension(250, 277)); setResizable(false); setTitle("Save As Jar.."); @@ -44,14 +46,12 @@ public class ExportJar extends JFrame { btnNewButton.setMaximumSize(new Dimension(999, 23)); btnNewButton.setMinimumSize(new Dimension(999, 23)); btnNewButton.setSize(new Dimension(999, 0)); - getContentPane().setLayout( - new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); + getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(); getContentPane().add(scrollPane); - JLabel lblMetainfmanifestmf = new JLabel("META-INF/MANIFEST.MF:"); - scrollPane.setColumnHeaderView(lblMetainfmanifestmf); + scrollPane.setColumnHeaderView(new JLabel("META-INF/MANIFEST.MF:")); final JTextArea mani = new JTextArea(); mani.setText("Manifest-Version: 1.0\r\nClass-Path: .\r\nMain-Class: "); @@ -61,8 +61,7 @@ public class ExportJar extends JFrame { btnNewButton.addActionListener(arg0 -> { BytecodeViewer.viewer.updateBusyStatus(true); Thread t = new Thread(() -> { - JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), jarPath, - mani.getText()); + JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), jarPath, mani.getText()); BytecodeViewer.viewer.updateBusyStatus(false); }); t.start(); @@ -73,4 +72,4 @@ public class ExportJar extends JFrame { } private static final long serialVersionUID = -2662514582647810868L; -} +} \ No newline at end of file diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/JTextAreaOutputStream.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/JTextAreaOutputStream.java new file mode 100644 index 00000000..b9575d13 --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/JTextAreaOutputStream.java @@ -0,0 +1,31 @@ +package the.bytecode.club.bytecodeviewer.gui.extras; + +import javax.swing.*; +import java.io.IOException; +import java.io.OutputStream; + +/** + * @author Konloch + * @since 6/21/2021 + */ +public class JTextAreaOutputStream extends OutputStream +{ + private final StringBuilder sb = new StringBuilder(); + private final JTextArea textArea; + + public JTextAreaOutputStream(JTextArea textArea) + { + this.textArea = textArea; + } + + public void update() + { + textArea.append(sb.toString()); + } + + @Override + public void write(int b) throws IOException + { + sb.append((char) b); + } +} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/RunOptions.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/RunOptions.java index 2436e127..9600428f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/RunOptions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/RunOptions.java @@ -45,8 +45,7 @@ public class RunOptions extends JFrame { setTitle("Run Options"); getContentPane().setLayout(null); - final JCheckBox accessModifiers = new JCheckBox( - "Set All Access Modifiers Public"); + final JCheckBox accessModifiers = new JCheckBox("Set All Access Modifiers Public"); accessModifiers.setBounds(6, 7, 232, 23); getContentPane().add(accessModifiers); @@ -74,8 +73,7 @@ public class RunOptions extends JFrame { for (Object o : classNode.methods.toArray()) { MethodNode m = (MethodNode) o; - if (m.name.equals("main") - && m.desc.equals("([Ljava/lang/String;)V")) { + if (m.name.equals("main") && m.desc.equals("([Ljava/lang/String;)V")) { if (!b) { b = true; txtThebytecodeclubexamplemainlstring @@ -86,8 +84,7 @@ public class RunOptions extends JFrame { } if (!b) - txtThebytecodeclubexamplemainlstring - .setText("the/bytecode/club/Example.main"); + txtThebytecodeclubexamplemainlstring.setText("the/bytecode/club/Example.main"); txtThebytecodeclubexamplemainlstring.setBounds(6, 233, 232, 20); getContentPane().add(txtThebytecodeclubexamplemainlstring); @@ -109,13 +106,11 @@ public class RunOptions extends JFrame { textField_1.setBounds(6, 172, 232, 20); getContentPane().add(textField_1); - final JCheckBox forceProxy = new JCheckBox( - "Force Proxy (socks5, host:port):"); + final JCheckBox forceProxy = new JCheckBox("Force Proxy (socks5, host:port):"); forceProxy.setBounds(6, 142, 232, 23); getContentPane().add(forceProxy); - final JCheckBox launchReflectionKit = new JCheckBox( - "Launch Reflection Kit On Successful Invoke"); + final JCheckBox launchReflectionKit = new JCheckBox("Launch Reflection Kit On Successful Invoke"); launchReflectionKit.setEnabled(false); launchReflectionKit.setBounds(6, 260, 232, 23); getContentPane().add(launchReflectionKit); @@ -125,8 +120,7 @@ public class RunOptions extends JFrame { console.setSelected(true); getContentPane().add(console); - final JCheckBox chckbxPrintToTerminal = new JCheckBox( - "Print To Command Line"); + final JCheckBox chckbxPrintToTerminal = new JCheckBox("Print To Command Line"); chckbxPrintToTerminal.setSelected(true); chckbxPrintToTerminal.setBounds(6, 315, 232, 23); getContentPane().add(chckbxPrintToTerminal); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/SystemErrConsole.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/SystemErrConsole.java index 6f661221..744cee0a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/SystemErrConsole.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/extras/SystemErrConsole.java @@ -5,8 +5,6 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; -import java.io.IOException; -import java.io.OutputStream; import java.io.PrintStream; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -47,16 +45,18 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * @author Konloch */ -public class SystemErrConsole extends JFrame { - - JTextArea textArea = new JTextArea(); - JPanel panel = new JPanel(new BorderLayout()); - JScrollPane scrollPane = new JScrollPane(); - public JCheckBox check = new JCheckBox("Exact"); - final JTextField field = new JTextField(); +public class SystemErrConsole extends JFrame +{ + private final JTextArea textArea = new JTextArea(); + private final JPanel panel = new JPanel(new BorderLayout()); + private final JScrollPane scrollPane = new JScrollPane(); + private final JCheckBox check = new JCheckBox("Exact"); + private final JTextField field = new JTextField(); private final PrintStream originalOut; + private final JTextAreaOutputStream s; - public SystemErrConsole(String title) { + public SystemErrConsole(String title) + { this.setIconImages(Resources.iconList); setTitle(title); setSize(new Dimension(542, 316)); @@ -64,7 +64,8 @@ public class SystemErrConsole extends JFrame { getContentPane().add(scrollPane, BorderLayout.CENTER); scrollPane.setViewportView(textArea); - textArea.addKeyListener(new KeyListener() { + textArea.addKeyListener(new KeyListener() + { @Override public void keyPressed(KeyEvent e) { if ((e.getKeyCode() == KeyEvent.VK_F) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { @@ -113,14 +114,12 @@ public class SystemErrConsole extends JFrame { }); scrollPane.setColumnHeaderView(panel); this.setLocationRelativeTo(null); - s = new CustomOutputStream(textArea); + s = new JTextAreaOutputStream(textArea); PrintStream printStream = new PrintStream(s); originalOut = System.err; System.setErr(printStream); } - CustomOutputStream s; - public void finished() { if (originalOut != null) System.setErr(originalOut); @@ -294,24 +293,6 @@ public class SystemErrConsole extends JFrame { textArea.setText(t); textArea.setCaretPosition(0); } - - static class CustomOutputStream extends OutputStream { - private final StringBuilder sb = new StringBuilder(); - private final JTextArea textArea; - - public CustomOutputStream(JTextArea textArea) { - this.textArea = textArea; - } - - public void update() { - textArea.append(sb.toString()); - } - - @Override - public void write(int b) throws IOException { - sb.append((char) b); - } - } - + private static final long serialVersionUID = -6556940545421437508L; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/GraphicalReflectionKit.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/GraphicalReflectionKit.java index 5b4a0786..1f2a8a0b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/GraphicalReflectionKit.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/GraphicalReflectionKit.java @@ -31,8 +31,10 @@ import the.bytecode.club.bytecodeviewer.Resources; * @author Konloch */ -public class GraphicalReflectionKit extends JFrame { - public GraphicalReflectionKit() { +public class GraphicalReflectionKit extends JFrame +{ + public GraphicalReflectionKit() + { this.setIconImages(Resources.iconList); setSize(new Dimension(382, 356)); setTitle("Graphical Reflection Kit"); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java index d4edb3e7..84689871 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/MaliciousCodeScannerOptions.java @@ -35,7 +35,8 @@ import the.bytecode.club.bytecodeviewer.plugin.preinstalled.MaliciousCodeScanner * @author Adrianherrera */ -public class MaliciousCodeScannerOptions extends JFrame { +public class MaliciousCodeScannerOptions extends JFrame +{ public static void open() { if (BytecodeViewer.getLoadedClasses().isEmpty()) { @@ -44,15 +45,16 @@ public class MaliciousCodeScannerOptions extends JFrame { } new MaliciousCodeScannerOptions().setVisible(true); } - public MaliciousCodeScannerOptions() { + + public MaliciousCodeScannerOptions() + { this.setIconImages(Resources.iconList); setSize(new Dimension(250, 323)); setResizable(false); setTitle("Malicious Code Scanner Options"); getContentPane().setLayout(null); - final JCheckBox chckbxJavalangreflection = new JCheckBox( - "java/lang/reflection"); + final JCheckBox chckbxJavalangreflection = new JCheckBox("java/lang/reflection"); chckbxJavalangreflection.setSelected(true); chckbxJavalangreflection.setBounds(6, 7, 232, 23); getContentPane().add(chckbxJavalangreflection); @@ -66,38 +68,32 @@ public class MaliciousCodeScannerOptions extends JFrame { chckbxJavaio.setBounds(6, 104, 232, 23); getContentPane().add(chckbxJavaio); - final JCheckBox chckbxJavalangruntime = new JCheckBox( - "java/lang/Runtime"); + final JCheckBox chckbxJavalangruntime = new JCheckBox("java/lang/Runtime"); chckbxJavalangruntime.setSelected(true); chckbxJavalangruntime.setBounds(6, 33, 232, 23); getContentPane().add(chckbxJavalangruntime); - final JCheckBox chckbxLdcContainswww = new JCheckBox( - "LDC contains 'www.'"); + final JCheckBox chckbxLdcContainswww = new JCheckBox("LDC contains 'www.'"); chckbxLdcContainswww.setSelected(true); chckbxLdcContainswww.setBounds(6, 130, 232, 23); getContentPane().add(chckbxLdcContainswww); - final JCheckBox chckbxLdcContainshttp = new JCheckBox( - "LDC contains 'http://'"); + final JCheckBox chckbxLdcContainshttp = new JCheckBox("LDC contains 'http://'"); chckbxLdcContainshttp.setSelected(true); chckbxLdcContainshttp.setBounds(6, 156, 232, 23); getContentPane().add(chckbxLdcContainshttp); - final JCheckBox chckbxLdcContainshttps = new JCheckBox( - "LDC contains 'https://'"); + final JCheckBox chckbxLdcContainshttps = new JCheckBox("LDC contains 'https://'"); chckbxLdcContainshttps.setSelected(true); chckbxLdcContainshttps.setBounds(6, 182, 232, 23); getContentPane().add(chckbxLdcContainshttps); - final JCheckBox chckbxLdcMatchesIp = new JCheckBox( - "LDC matches IP regex"); + final JCheckBox chckbxLdcMatchesIp = new JCheckBox("LDC matches IP regex"); chckbxLdcMatchesIp.setSelected(true); chckbxLdcMatchesIp.setBounds(6, 208, 232, 23); getContentPane().add(chckbxLdcMatchesIp); - final JCheckBox chckbxNullSecMan = new JCheckBox( - "SecurityManager set to null"); + final JCheckBox chckbxNullSecMan = new JCheckBox("SecurityManager set to null"); chckbxNullSecMan.setSelected(true); chckbxNullSecMan.setBounds(6, 234, 232, 23); getContentPane().add(chckbxNullSecMan); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java index 75d14ea7..4c8f52d5 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/plugins/ReplaceStringsOptions.java @@ -36,17 +36,19 @@ import the.bytecode.club.bytecodeviewer.plugin.preinstalled.ReplaceStrings; * @author Konloch */ -public class ReplaceStringsOptions extends JFrame { +public class ReplaceStringsOptions extends JFrame +{ public static void open() { - if (BytecodeViewer.getLoadedClasses().isEmpty()) { BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file."); return; } new ReplaceStringsOptions().setVisible(true); } - public ReplaceStringsOptions() { + + public ReplaceStringsOptions() + { this.setIconImages(Resources.iconList); setSize(new Dimension(250, 176)); setResizable(false); @@ -61,49 +63,48 @@ public class ReplaceStringsOptions extends JFrame { lblNewLabel.setBounds(6, 40, 67, 14); getContentPane().add(lblNewLabel); - textField = new JTextField(); - textField.setBounds(80, 37, 158, 20); - getContentPane().add(textField); - textField.setColumns(10); + originalLDC = new JTextField(); + originalLDC.setBounds(80, 37, 158, 20); + getContentPane().add(originalLDC); + originalLDC.setColumns(10); JLabel lblNewLabel_1 = new JLabel("New LDC:"); lblNewLabel_1.setBounds(6, 65, 77, 14); getContentPane().add(lblNewLabel_1); - textField_1 = new JTextField(); - textField_1.setColumns(10); - textField_1.setBounds(80, 62, 158, 20); - getContentPane().add(textField_1); + newLDC = new JTextField(); + newLDC.setColumns(10); + newLDC.setBounds(80, 62, 158, 20); + getContentPane().add(newLDC); JLabel lblNewLabel_2 = new JLabel("Class:"); lblNewLabel_2.setBounds(6, 90, 46, 14); getContentPane().add(lblNewLabel_2); - textField_2 = new JTextField(); - textField_2.setToolTipText("* will search all classes"); - textField_2.setText("*"); - textField_2.setBounds(80, 87, 158, 20); - getContentPane().add(textField_2); - textField_2.setColumns(10); + classToReplaceIn = new JTextField(); + classToReplaceIn.setToolTipText("* will search all classes"); + classToReplaceIn.setText("*"); + classToReplaceIn.setBounds(80, 87, 158, 20); + getContentPane().add(classToReplaceIn); + classToReplaceIn.setColumns(10); - final JCheckBox chckbxNewCheckBox = new JCheckBox( - "Replace All Contains"); - chckbxNewCheckBox - .setToolTipText("If it's unticked, it will check if the string equals, if its ticked it will check if" + final JCheckBox chckbxNewCheckBox = new JCheckBox("Replace All Contains"); + chckbxNewCheckBox.setToolTipText("If it's unticked, it will check if the string equals, if its ticked it will check if" + " it contains, then replace the original LDC part of the string."); chckbxNewCheckBox.setBounds(6, 7, 232, 23); getContentPane().add(chckbxNewCheckBox); btnNewButton.addActionListener(arg0 -> { - PluginManager.runPlugin(new ReplaceStrings(textField.getText(), - textField_1.getText(), textField_2.getText(), + PluginManager.runPlugin(new ReplaceStrings(originalLDC.getText(), + newLDC.getText(), classToReplaceIn.getText(), chckbxNewCheckBox.isSelected())); dispose(); }); + this.setLocationRelativeTo(null); } private static final long serialVersionUID = -2662514582647810868L; - private final JTextField textField; - private final JTextField textField_1; - private final JTextField textField_2; + private final JTextField originalLDC; + private final JTextField newLDC; + private final JTextField classToReplaceIn; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ImageRenderer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ImageRenderer.java new file mode 100644 index 00000000..35c87e2e --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ImageRenderer.java @@ -0,0 +1,141 @@ +package the.bytecode.club.bytecodeviewer.gui.resourceviewer; + +import the.bytecode.club.bytecodeviewer.Resources; + +import javax.swing.*; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.TreeNode; +import java.awt.*; +import java.util.ArrayList; + +/** + * @author http://stackoverflow.com/questions/14968005 + * @author Konloch + */ +public class ImageRenderer extends DefaultTreeCellRenderer +{ + //called every time there is a pane update, I.E. whenever you expand a folder + @Override + public Component getTreeCellRendererComponent( + JTree tree, Object value, + boolean sel, boolean expanded, boolean leaf, + int row, boolean hasFocus) + { + + Component ret = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); + + if (value instanceof ResourceListPane.MyTreeNode) + { + ResourceListPane.MyTreeNode node = (ResourceListPane.MyTreeNode) value; + String name = node.toString().toLowerCase(); + + if (name.endsWith(".jar") || name.endsWith(".war")) + { + setIcon(Resources.jarIcon); + } + else if (name.endsWith(".zip")) + { + setIcon(Resources.zipIcon); + } + else if (name.endsWith(".bat")) + { + setIcon(Resources.batIcon); + } + else if (name.endsWith(".sh")) + { + setIcon(Resources.shIcon); + } + else if (name.endsWith(".cs")) + { + setIcon(Resources.csharpIcon); + } + else if (name.endsWith(".c") || name.endsWith(".cpp") || name.endsWith(".h")) + { + setIcon(Resources.cplusplusIcon); + } + else if (name.endsWith(".apk") || name.endsWith(".dex")) + { + setIcon(Resources.androidIcon); + } + else if (name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".jpeg") + || name.endsWith(".bmp") || name.endsWith(".gif")) + { + setIcon(Resources.imageIcon); + } + else if (name.endsWith(".class")) + { + setIcon(Resources.classIcon); + } + else if (name.endsWith(".java")) + { + setIcon(Resources.javaIcon); + } + else if (name.endsWith(".txt") || name.endsWith(".md")) + { + setIcon(Resources.textIcon); + } + else if (name.equals("decoded resources")) + { + setIcon(Resources.decodedIcon); + } + else if (name.endsWith(".properties") || name.endsWith(".xml") || name.endsWith(".jsp") + || name.endsWith(".mf") || name.endsWith(".config") || name.endsWith(".cfg")) + { + setIcon(Resources.configIcon); + } + else if (node.getChildCount() <= 0) + { //random file + setIcon(Resources.fileIcon); + } + else + { //folder + ArrayList nodes = new ArrayList<>(); + ArrayList totalNodes = new ArrayList<>(); + + nodes.add(node); + totalNodes.add(node); + + boolean isJava = false; + boolean finished = false; + + while (!finished) + { //may cause a clusterfuck with huge files + if (nodes.isEmpty()) + finished = true; + else + { + TreeNode treeNode = nodes.get(0); + nodes.remove(treeNode); + int children = treeNode.getChildCount(); + if (children >= 1) + for (int i = 0; i < children; i++) + { + TreeNode child = treeNode.getChildAt(i); + + if (!totalNodes.contains(child)) + { + nodes.add(child); + totalNodes.add(child); + } + + if (child.toString().endsWith(".class")) + isJava = true; + } + + if (isJava) + nodes.clear(); + } + } + + if (isJava) + setIcon(Resources.packagesIcon); + else + { + setIcon(Resources.folderIcon); + } + } + } + + return ret; + } +} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/ResourceListPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceListPane.java similarity index 84% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/ResourceListPane.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceListPane.java index ebfd64ad..b98e64fd 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/ResourceListPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/ResourceListPane.java @@ -1,10 +1,9 @@ -package the.bytecode.club.bytecodeviewer.gui; +package the.bytecode.club.bytecodeviewer.gui.resourceviewer; //TODO fix for Java 9+ import com.sun.java.swing.plaf.windows.WindowsTreeUI; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; @@ -19,7 +18,6 @@ import java.awt.event.MouseEvent; import java.awt.font.FontRenderContext; import java.awt.geom.Rectangle2D; import java.io.File; -import java.util.ArrayList; import java.util.Comparator; import java.util.Enumeration; import java.util.Map.Entry; @@ -33,13 +31,12 @@ import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Resources; +import the.bytecode.club.bytecodeviewer.gui.VisibleComponent; import the.bytecode.club.bytecodeviewer.util.FileContainer; import the.bytecode.club.bytecodeviewer.util.FileDrop; import the.bytecode.club.bytecodeviewer.util.LazyNameUtil; @@ -641,104 +638,4 @@ public class ResourceListPane extends VisibleComponent implements FileDrop.Liste BytecodeViewer.getFileContents(nameBuffer.toString())); } } - - /** - * @author http://stackoverflow.com/questions/14968005 - * @author Konloch - */ - public static class ImageRenderer extends DefaultTreeCellRenderer { - - @Override - public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) { //called every time there is a pane update, I.E. whenever you expand a folder - - Component ret = super.getTreeCellRendererComponent(tree, value, - selected, expanded, leaf, row, hasFocus); - - if (value instanceof MyTreeNode) { - ResourceListPane.MyTreeNode node = - (ResourceListPane.MyTreeNode) value; - String name = node.toString().toLowerCase(); - - if (name.endsWith(".jar") || name.endsWith(".war")) { - setIcon(Resources.jarIcon); - } else if (name.endsWith(".zip")) { - setIcon(Resources.zipIcon); - } else if (name.endsWith(".bat")) { - setIcon(Resources.batIcon); - } else if (name.endsWith(".sh")) { - setIcon(Resources.shIcon); - } else if (name.endsWith(".cs")) { - setIcon(Resources.csharpIcon); - } else if (name.endsWith(".c") || name.endsWith(".cpp") || name.endsWith(".h")) { - setIcon(Resources.cplusplusIcon); - } else if (name.endsWith(".apk") || name.endsWith(".dex")) { - setIcon(Resources.androidIcon); - } else if (name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith( - ".bmp") || name.endsWith(".gif")) { - setIcon(Resources.imageIcon); - } else if (name.endsWith(".class")) { - setIcon(Resources.classIcon); - } else if (name.endsWith(".java")) { - setIcon(Resources.javaIcon); - } else if (name.endsWith(".txt") || name.endsWith(".md")) { - setIcon(Resources.textIcon); - } else if (name.equals("decoded resources")) { - setIcon(Resources.decodedIcon); - } else if (name.endsWith(".properties") || name.endsWith(".xml") || name.endsWith(".jsp") || name.endsWith(".mf") || name.endsWith(".config") || name.endsWith(".cfg")) { - setIcon(Resources.configIcon); - } else if (node.getChildCount() <= 0) { //random file - setIcon(Resources.fileIcon); - } else { //folder - ArrayList nodes = new ArrayList<>(); - ArrayList totalNodes = new ArrayList<>(); - - nodes.add(node); - totalNodes.add(node); - - boolean isJava = false; - boolean finished = false; - - while (!finished) { //may cause a clusterfuck with huge files - if (nodes.isEmpty()) - finished = true; - else { - TreeNode treeNode = nodes.get(0); - nodes.remove(treeNode); - int children = treeNode.getChildCount(); - if (children >= 1) - for (int i = 0; i < children; i++) { - TreeNode child = treeNode.getChildAt(i); - - if (!totalNodes.contains(child)) { - nodes.add(child); - totalNodes.add(child); - } - - if (child.toString().endsWith(".class")) - isJava = true; - } - - if (isJava) - nodes.clear(); - } - } - - if (isJava) - setIcon(Resources.packagesIcon); - else { - setIcon(Resources.folderIcon); - } - } - } - - return ret; - } - } } \ No newline at end of file diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/OpenFile.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/OpenFile.java index 6f33dadc..24ef9763 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/OpenFile.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/OpenFile.java @@ -4,7 +4,7 @@ import org.apache.commons.io.FileUtils; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; -import the.bytecode.club.bytecodeviewer.gui.ResourceListPane; +import the.bytecode.club.bytecodeviewer.gui.resourceviewer.ResourceListPane; import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; import java.io.File;