Skip to content

Commit

Permalink
cleanups and perfs boost
Browse files Browse the repository at this point in the history
  • Loading branch information
aress31 committed Dec 25, 2023
1 parent 4c89563 commit abc46c8
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 71 deletions.
6 changes: 3 additions & 3 deletions src/main/java/burp/MyContextMenuItemsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/swurg/gui/MainTabGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,42 @@
@Data
public class MainTabGroup extends JTabbedPane implements ParserTableModelObserver {

private final transient MontoyaApi montoyaApi;
private final MontoyaApi montoyaApi;

private final List<MyHttpRequest> myHttpRequests;

private ParserPanel parserPanel;
private ParametersPanel parametersPanel;
private AboutPanel aboutPanel;

List<MyHttpRequest> 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);
}

@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));

}
}
4 changes: 2 additions & 2 deletions src/main/java/swurg/gui/components/CustomTextFieldEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/swurg/gui/components/FilterPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/swurg/gui/components/HistoryFileChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> fileHistory;

private final List<File> fileHistory;
private final Preferences preferences;

public HistoryFileChooser(String currentDirectoryPath) {
super(currentDirectoryPath);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/swurg/gui/components/StatusPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class StatusPanel extends JPanel {

private JLabel statusLabel;
private final JLabel statusLabel;

public StatusPanel() {
statusLabel = new JLabel(COPYRIGHT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class ParametersContextMenu extends JPopupMenu {

private JTable table;
private final JTable table;

public ParametersContextMenu(JTable table) {
this.table = table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
@Data
public class ParametersTableModel extends AbstractTableModel {

private Set<MyHttpParameter> 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<MyHttpParameter> myHttpParameters;

public ParametersTableModel(Set<MyHttpParameter> myHttpParameters) {
this.myHttpParameters = myHttpParameters;
public ParametersTableModel() {
this.myHttpParameters = new LinkedHashSet<MyHttpParameter>();
}

public MyHttpParameter getHttpParameterAt(int rowIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,13 +16,12 @@
@Data
public class ParserTableModel extends AbstractTableModel {

private List<MyHttpRequest> 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<MyHttpRequest> myHttpRequests;

// Add a list to hold the observers
private List<ParserTableModelObserver> observers = new ArrayList<>();
private List<ParametersPanelObserver> parametersPanelObservers = new ArrayList<>();
private final List<ParserTableModelObserver> observers = new ArrayList<>();
private final List<ParametersPanelObserver> parametersPanelObservers = new ArrayList<>();

public ParserTableModel(List<MyHttpRequest> myHttpRequests) {
this.myHttpRequests = myHttpRequests;
Expand Down Expand Up @@ -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();
}

Expand All @@ -76,9 +74,8 @@ public void unregisterParametersPanelObserver(ParametersPanelObserver observer)
}

private void notifyParametersPanelObservers() {
for (ParametersPanelObserver observer : parametersPanelObservers) {
for (ParametersPanelObserver observer : parametersPanelObservers)
observer.onRequestWithMetadatasUpdate();
}
}

@Override
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/swurg/gui/views/ParametersPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,30 @@
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<MyHttpRequest> myHttpRequests;
private final ParametersTableModel parametersTableModel;

private transient List<ToolType> toolsInScope = new ArrayList<>();
private List<ToolType> toolsMap = List.of(
private final List<ToolType> toolsInScope = new ArrayList<>();
private final List<ToolType> toolsMap = List.of(
ToolType.EXTENSIONS,
ToolType.INTRUDER,
ToolType.PROXY,
ToolType.REPEATER,
ToolType.SCANNER,
ToolType.SEQUENCER,
ToolType.TARGET);
private List<MyHttpRequest> myHttpRequests;

private JScrollPane scrollPane;

public ParametersPanel(MontoyaApi montoyaApi, List<MyHttpRequest> myHttpRequests) {
this.logging = montoyaApi.logging();
this.suiteFrame = montoyaApi.userInterface().swingUtils().suiteFrame();

this.myHttpRequests = myHttpRequests;

parametersTableModel = new ParametersTableModel();
this.parametersTableModel = new ParametersTableModel();

initComponents();

Expand Down
36 changes: 18 additions & 18 deletions src/main/java/swurg/gui/views/ParserPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<MyHttpRequest> myHttpRequests;

private JButton loadButton;
@Getter
private JTable table;
@Getter
private StatusPanel statusPanel = new StatusPanel();
@Getter
private ParserTableModel parserTableModel;

public ParserPanel(MontoyaApi montoyaApi, List<MyHttpRequest> 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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -246,7 +246,7 @@ public void actionPerformed(ActionEvent e) {
List<String> metadataList = worker.parseMetadata(worker.processOpenAPI(resource));
setMetadataLabel(metadataList);

List<MyHttpRequest> myHttpRequests = worker.parseOpenAPI(worker.processOpenAPI(resource));
myHttpRequests = worker.parseOpenAPI(worker.processOpenAPI(resource));
updateTableModel(myHttpRequests);

statusPanel.updateStatus(COPYRIGHT, UIManager.getLookAndFeelDefaults().getColor("TextField.foreground"));
Expand Down

0 comments on commit abc46c8

Please sign in to comment.