From abc46c8587260f475ae56cb6d77807f6a6307e23 Mon Sep 17 00:00:00 2001 From: unknown <11601622+aress31@users.noreply.github.com> Date: Mon, 25 Dec 2023 00:02:50 +0000 Subject: [PATCH] cleanups and perfs boost --- .../java/burp/MyContextMenuItemsProvider.java | 6 ++-- src/main/java/swurg/gui/MainTabGroup.java | 26 +++++++------- .../gui/components/CustomTextFieldEditor.java | 4 +-- .../swurg/gui/components/FilterPanel.java | 5 +-- .../gui/components/HistoryFileChooser.java | 5 +-- .../swurg/gui/components/StatusPanel.java | 2 +- .../menus/ParametersContextMenu.java | 2 +- .../components/menus/ParserContextMenu.java | 5 +-- .../tables/models/ParametersTableModel.java | 11 +++--- .../tables/models/ParserTableModel.java | 17 ++++----- .../java/swurg/gui/views/ParametersPanel.java | 19 +++++----- .../java/swurg/gui/views/ParserPanel.java | 36 +++++++++---------- 12 files changed, 67 insertions(+), 71 deletions(-) diff --git a/src/main/java/burp/MyContextMenuItemsProvider.java b/src/main/java/burp/MyContextMenuItemsProvider.java index 8c90206..346dd67 100644 --- a/src/main/java/burp/MyContextMenuItemsProvider.java +++ b/src/main/java/burp/MyContextMenuItemsProvider.java @@ -23,9 +23,9 @@ import burp.http.MyHttpRequest; public class MyContextMenuItemsProvider implements ContextMenuItemsProvider { - private MontoyaApi montoyaApi; - private ParserPanel parserPanel; - private Logging logging; + private final MontoyaApi montoyaApi; + private final ParserPanel parserPanel; + private final Logging logging; public MyContextMenuItemsProvider(MontoyaApi montoyaApi, ParserPanel parserPanel) { this.montoyaApi = montoyaApi; diff --git a/src/main/java/swurg/gui/MainTabGroup.java b/src/main/java/swurg/gui/MainTabGroup.java index e49a552..9a5e46a 100644 --- a/src/main/java/swurg/gui/MainTabGroup.java +++ b/src/main/java/swurg/gui/MainTabGroup.java @@ -17,29 +17,29 @@ @Data public class MainTabGroup extends JTabbedPane implements ParserTableModelObserver { - private final transient MontoyaApi montoyaApi; + private final MontoyaApi montoyaApi; + + private final List myHttpRequests; private ParserPanel parserPanel; private ParametersPanel parametersPanel; private AboutPanel aboutPanel; - List myHttpRequests; - public MainTabGroup(MontoyaApi montoyaApi) { this.montoyaApi = montoyaApi; this.myHttpRequests = new ArrayList<>(); initComponents(); - parserPanel.getParserTableModel().registerObserver(this); - parserPanel.getParserTableModel().registerParametersPanelObserver(parametersPanel); + this.parserPanel.getParserTableModel().registerObserver(this); + this.parserPanel.getParserTableModel().registerParametersPanelObserver(this.parametersPanel); } private void initComponents() { - parserPanel = new ParserPanel(montoyaApi, myHttpRequests); + parserPanel = new ParserPanel(this.montoyaApi, this.myHttpRequests); aboutPanel = new AboutPanel(); - parametersPanel = new ParametersPanel(montoyaApi, myHttpRequests); + parametersPanel = new ParametersPanel(this.montoyaApi, this.myHttpRequests); addTab("Parser", parserPanel); addTab("About", aboutPanel); @@ -47,12 +47,12 @@ private void initComponents() { @Override public void onRequestWithMetadatasUpdate() { - if (indexOfComponent(parametersPanel) == -1 && !myHttpRequests.isEmpty()) { - removeTabAt(indexOfComponent(aboutPanel)); - addTab("Parameters", parametersPanel); - addTab("About", aboutPanel); - } else if (indexOfComponent(parametersPanel) != -1 && myHttpRequests.isEmpty()) - removeTabAt(indexOfComponent(parametersPanel)); + if (indexOfComponent(this.parametersPanel) == -1 && !this.myHttpRequests.isEmpty()) { + removeTabAt(indexOfComponent(this.aboutPanel)); + addTab("Parameters", this.parametersPanel); + addTab("About", this.aboutPanel); + } else if (indexOfComponent(this.parametersPanel) != -1 && this.myHttpRequests.isEmpty()) + removeTabAt(indexOfComponent(this.parametersPanel)); } } \ No newline at end of file diff --git a/src/main/java/swurg/gui/components/CustomTextFieldEditor.java b/src/main/java/swurg/gui/components/CustomTextFieldEditor.java index 8e90575..946c94b 100644 --- a/src/main/java/swurg/gui/components/CustomTextFieldEditor.java +++ b/src/main/java/swurg/gui/components/CustomTextFieldEditor.java @@ -15,8 +15,8 @@ // TO FIX: Need to press enter then escape to commit the edit public class CustomTextFieldEditor extends AbstractCellEditor implements TableCellEditor, ActionListener { - private static final long serialVersionUID = 1L; - private JTextField textField; + + private final JTextField textField; public CustomTextFieldEditor() { textField = new JTextField(); diff --git a/src/main/java/swurg/gui/components/FilterPanel.java b/src/main/java/swurg/gui/components/FilterPanel.java index 062e536..2f14e45 100644 --- a/src/main/java/swurg/gui/components/FilterPanel.java +++ b/src/main/java/swurg/gui/components/FilterPanel.java @@ -13,10 +13,11 @@ import javax.swing.table.TableRowSorter; public class FilterPanel extends JPanel { - private final JTextField filterTextField = new JTextField(32); + private final TableRowSorter tableRowSorter; - private JLabel eastLabel = new JLabel("0 hits"); + private final JLabel eastLabel = new JLabel("0 hits"); + private final JTextField filterTextField = new JTextField(32); public FilterPanel(TableRowSorter tableRowSorter) { this.tableRowSorter = tableRowSorter; diff --git a/src/main/java/swurg/gui/components/HistoryFileChooser.java b/src/main/java/swurg/gui/components/HistoryFileChooser.java index 5b3234c..986c1f9 100644 --- a/src/main/java/swurg/gui/components/HistoryFileChooser.java +++ b/src/main/java/swurg/gui/components/HistoryFileChooser.java @@ -13,8 +13,9 @@ public class HistoryFileChooser extends JFileChooser { private static final String FILE_HISTORY_KEY = "fileHistory"; private static final int MAX_HISTORY_SIZE = 10; - private Preferences preferences; - private List fileHistory; + + private final List fileHistory; + private final Preferences preferences; public HistoryFileChooser(String currentDirectoryPath) { super(currentDirectoryPath); diff --git a/src/main/java/swurg/gui/components/StatusPanel.java b/src/main/java/swurg/gui/components/StatusPanel.java index 7af33fb..e55f046 100644 --- a/src/main/java/swurg/gui/components/StatusPanel.java +++ b/src/main/java/swurg/gui/components/StatusPanel.java @@ -8,7 +8,7 @@ public class StatusPanel extends JPanel { - private JLabel statusLabel; + private final JLabel statusLabel; public StatusPanel() { statusLabel = new JLabel(COPYRIGHT); diff --git a/src/main/java/swurg/gui/components/menus/ParametersContextMenu.java b/src/main/java/swurg/gui/components/menus/ParametersContextMenu.java index f24b436..e3b0193 100644 --- a/src/main/java/swurg/gui/components/menus/ParametersContextMenu.java +++ b/src/main/java/swurg/gui/components/menus/ParametersContextMenu.java @@ -15,7 +15,7 @@ public class ParametersContextMenu extends JPopupMenu { - private JTable table; + private final JTable table; public ParametersContextMenu(JTable table) { this.table = table; diff --git a/src/main/java/swurg/gui/components/menus/ParserContextMenu.java b/src/main/java/swurg/gui/components/menus/ParserContextMenu.java index ac34354..19c1b66 100644 --- a/src/main/java/swurg/gui/components/menus/ParserContextMenu.java +++ b/src/main/java/swurg/gui/components/menus/ParserContextMenu.java @@ -30,8 +30,9 @@ public class ParserContextMenu extends JPopupMenu { - private MontoyaApi montoyaApi; - private JTable table; + private final MontoyaApi montoyaApi; + + private final JTable table; public ParserContextMenu(MontoyaApi montoyaApi, JTable table) { this.montoyaApi = montoyaApi; diff --git a/src/main/java/swurg/gui/components/tables/models/ParametersTableModel.java b/src/main/java/swurg/gui/components/tables/models/ParametersTableModel.java index 8b98e03..d9c9838 100644 --- a/src/main/java/swurg/gui/components/tables/models/ParametersTableModel.java +++ b/src/main/java/swurg/gui/components/tables/models/ParametersTableModel.java @@ -11,16 +11,13 @@ @Data public class ParametersTableModel extends AbstractTableModel { - private Set myHttpParameters; - private String[] columnNames = { "#", "Parameter", "Type (BODY, COOKIE, URL)", + private final String[] columnNames = { "#", "Parameter", "Type (BODY, COOKIE, URL)", "Parsed Value (Example Value or Data type)", "Edited Value" }; - public ParametersTableModel() { - this.myHttpParameters = new LinkedHashSet<>(); - } + private Set myHttpParameters; - public ParametersTableModel(Set myHttpParameters) { - this.myHttpParameters = myHttpParameters; + public ParametersTableModel() { + this.myHttpParameters = new LinkedHashSet(); } public MyHttpParameter getHttpParameterAt(int rowIndex) { diff --git a/src/main/java/swurg/gui/components/tables/models/ParserTableModel.java b/src/main/java/swurg/gui/components/tables/models/ParserTableModel.java index 926184c..c12e9a1 100644 --- a/src/main/java/swurg/gui/components/tables/models/ParserTableModel.java +++ b/src/main/java/swurg/gui/components/tables/models/ParserTableModel.java @@ -8,7 +8,6 @@ import burp.api.montoya.http.message.params.HttpParameterType; import burp.api.montoya.http.message.params.ParsedHttpParameter; -import burp.api.montoya.http.message.requests.HttpRequest; import burp.http.MyHttpRequest; import lombok.Data; import swurg.observers.ParserTableModelObserver; @@ -17,13 +16,12 @@ @Data public class ParserTableModel extends AbstractTableModel { - private List myHttpRequests; - private String[] columnNames = { "#", "Scheme", "Method", "Server", "Path", "Parameters (COOKIE, URL)", + private final String[] columnNames = { "#", "Scheme", "Method", "Server", "Path", "Parameters (COOKIE, URL)", "Description" }; + private final List myHttpRequests; - // Add a list to hold the observers - private List observers = new ArrayList<>(); - private List parametersPanelObservers = new ArrayList<>(); + private final List observers = new ArrayList<>(); + private final List parametersPanelObservers = new ArrayList<>(); public ParserTableModel(List myHttpRequests) { this.myHttpRequests = myHttpRequests; @@ -60,9 +58,9 @@ public void unregisterObserver(ParserTableModelObserver observer) { // Add a method to notify the observers private void notifyObservers() { - for (ParserTableModelObserver observer : observers) { + for (ParserTableModelObserver observer : observers) observer.onRequestWithMetadatasUpdate(); - } + notifyParametersPanelObservers(); } @@ -76,9 +74,8 @@ public void unregisterParametersPanelObserver(ParametersPanelObserver observer) } private void notifyParametersPanelObservers() { - for (ParametersPanelObserver observer : parametersPanelObservers) { + for (ParametersPanelObserver observer : parametersPanelObservers) observer.onRequestWithMetadatasUpdate(); - } } @Override diff --git a/src/main/java/swurg/gui/views/ParametersPanel.java b/src/main/java/swurg/gui/views/ParametersPanel.java index fee07b6..ed66f93 100644 --- a/src/main/java/swurg/gui/views/ParametersPanel.java +++ b/src/main/java/swurg/gui/views/ParametersPanel.java @@ -44,15 +44,14 @@ public class ParametersPanel extends JPanel implements HttpHandler, ParametersPanelObserver { - private Frame suiteFrame; - private Logging logging; + private final Logging logging; + private final Frame suiteFrame; - private JScrollPane scrollPane; - - private ParametersTableModel parametersTableModel; + private final List myHttpRequests; + private final ParametersTableModel parametersTableModel; - private transient List toolsInScope = new ArrayList<>(); - private List toolsMap = List.of( + private final List toolsInScope = new ArrayList<>(); + private final List toolsMap = List.of( ToolType.EXTENSIONS, ToolType.INTRUDER, ToolType.PROXY, @@ -60,15 +59,15 @@ public class ParametersPanel extends JPanel ToolType.SCANNER, ToolType.SEQUENCER, ToolType.TARGET); - private List myHttpRequests; + + private JScrollPane scrollPane; public ParametersPanel(MontoyaApi montoyaApi, List myHttpRequests) { this.logging = montoyaApi.logging(); this.suiteFrame = montoyaApi.userInterface().swingUtils().suiteFrame(); this.myHttpRequests = myHttpRequests; - - parametersTableModel = new ParametersTableModel(); + this.parametersTableModel = new ParametersTableModel(); initComponents(); diff --git a/src/main/java/swurg/gui/views/ParserPanel.java b/src/main/java/swurg/gui/views/ParserPanel.java index 316dc24..2034f7f 100644 --- a/src/main/java/swurg/gui/views/ParserPanel.java +++ b/src/main/java/swurg/gui/views/ParserPanel.java @@ -31,7 +31,6 @@ import javax.swing.SwingUtilities; import javax.swing.ToolTipManager; import javax.swing.UIManager; -import javax.swing.border.MatteBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -50,29 +49,32 @@ public class ParserPanel extends JPanel { - private MontoyaApi montoyaApi; - private Logging logging; + private final MontoyaApi montoyaApi; + private final Logging logging; - private HttpRequestEditor requestViewer; + @Getter + private final ParserTableModel parserTableModel; + @Getter + private final StatusPanel statusPanel = new StatusPanel(); + private final JLabel metadataLabel = new JLabel(); @Getter - private JTextField resourceTextField = new JTextField(); - private JLabel metadataLabel = new JLabel(); - private JButton loadButton; + private final JTextField resourceTextField = new JTextField(); + + private HttpRequestEditor requestViewer; + private List myHttpRequests; + + private JButton loadButton; @Getter private JTable table; - @Getter - private StatusPanel statusPanel = new StatusPanel(); - @Getter - private ParserTableModel parserTableModel; public ParserPanel(MontoyaApi montoyaApi, List myHttpRequests) { this.montoyaApi = montoyaApi; this.logging = montoyaApi.logging(); - ParserTableModel parserTableModel = new ParserTableModel(myHttpRequests); - this.parserTableModel = parserTableModel; + this.myHttpRequests = myHttpRequests; + this.parserTableModel = new ParserTableModel(myHttpRequests); initComponents(); @@ -110,10 +112,8 @@ private void initComponents() { public JPanel createNorthPanel() { JPanel resourcePanel = new JPanel(new GridBagLayout()); - MatteBorder matteBorder = BorderFactory.createMatteBorder(0, 0, 1, 0, - UIManager.getLookAndFeelDefaults().getColor("Separator.foreground")); - - resourcePanel.setBorder(matteBorder); + resourcePanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, + UIManager.getLookAndFeelDefaults().getColor("Separator.foreground"))); loadButton = createButton("Load", new LoadButtonListener()); loadButton.setEnabled(false); @@ -246,7 +246,7 @@ public void actionPerformed(ActionEvent e) { List metadataList = worker.parseMetadata(worker.processOpenAPI(resource)); setMetadataLabel(metadataList); - List myHttpRequests = worker.parseOpenAPI(worker.processOpenAPI(resource)); + myHttpRequests = worker.parseOpenAPI(worker.processOpenAPI(resource)); updateTableModel(myHttpRequests); statusPanel.updateStatus(COPYRIGHT, UIManager.getLookAndFeelDefaults().getColor("TextField.foreground"));