Skip to content

Commit

Permalink
refactor: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
beryxz committed Apr 5, 2024
1 parent e703eb1 commit 48df30f
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 81 deletions.
1 change: 0 additions & 1 deletion src/main/java/burp/BurpExtender.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package burp;

import burp.api.montoya.BurpExtension;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/cys4/sensitivediscoverer/MainUI.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package com.cys4.sensitivediscoverer;

import burp.api.montoya.MontoyaApi;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/cys4/sensitivediscoverer/RegexScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ public void analyzeProxyHistory(Function<Integer, Runnable> progressBarCallbackS
// removing items from the list allows the GC to clean up just after the task is executed
// instead of waiting until the whole analysis finishes.
List<ProxyHttpRequestResponse> proxyEntries = this.burpApi.proxy().history();

if (proxyEntries.isEmpty())
return;
if (proxyEntries.isEmpty()) return;

Runnable itemAnalyzedCallback = progressBarCallbackSetup.apply(proxyEntries.size());
for (int entryIndex = proxyEntries.size() - 1; entryIndex >= 0; entryIndex--) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public static int getSize() {
return columns.size();
}

public String getLocaleKey() {
return localeKey;
}

public String getNameFormatted() {
return formattedName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package com.cys4.sensitivediscoverer.model;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.cys4.sensitivediscoverer.ui;

import com.cys4.sensitivediscoverer.MainUI;
import com.cys4.sensitivediscoverer.model.LogEntity;
import com.cys4.sensitivediscoverer.model.RegexEntity;
import com.cys4.sensitivediscoverer.model.RegexListContext;
import com.cys4.sensitivediscoverer.model.RegexListViewerTableModel;
Expand Down Expand Up @@ -233,9 +232,9 @@ private JMenuItem createEditRegexMenuItem(RegexListContext ctx,
* @param tableModel
*/
private void editSelectedRegex(RegexListContext ctx,
JTable optionsRegexTable,
JPanel tabPaneOptions,
RegexListViewerTableModel tableModel) {
JTable optionsRegexTable,
JPanel tabPaneOptions,
RegexListViewerTableModel tableModel) {
int rowIndex;
int realRow;

Expand Down Expand Up @@ -283,9 +282,9 @@ private JMenuItem createDeleteRegexMenuItem(RegexListContext ctx,
* @param tableModel
*/
private void deleteSelectedRegex(RegexListContext ctx,
JTable optionsRegexTable,
JPanel tabPaneOptions,
RegexListViewerTableModel tableModel) {
JTable optionsRegexTable,
JPanel tabPaneOptions,
RegexListViewerTableModel tableModel) {
int rowIndex = optionsRegexTable.getSelectedRow();
if (rowIndex == -1) return;
int realRow = optionsRegexTable.convertRowIndexToModel(rowIndex);
Expand Down
153 changes: 85 additions & 68 deletions src/main/java/com/cys4/sensitivediscoverer/ui/tab/LoggerTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private JPanel createPanel() {

box = new JPanel();
box.setLayout(new BorderLayout(0, 0));
boxHeader = createHeaderBar(logEntriesPane);
boxHeader = createHeaderBox(logEntriesPane);
box.add(boxHeader, BorderLayout.NORTH);
boxCenter = createCenterBox(logEntriesPane);
box.add(boxCenter, BorderLayout.CENTER);
Expand Down Expand Up @@ -165,114 +165,131 @@ private JPanel createCenterBox(JScrollPane logEntriesPane) {
return boxCenter;
}

private JPanel createHeaderBar(JScrollPane logEntriesPane) {
JPanel rightSidePanel;
JPanel boxHeader;
JPanel leftSidePanel;
JPanel searchBarPanel;
private JPanel createHeaderBox(JScrollPane logEntriesPane) {
JPanel headerBox;
GridBagConstraints gbc;

boxHeader = new JPanel();
boxHeader.setLayout(new GridBagLayout());
headerBox = new JPanel();
headerBox.setLayout(new GridBagLayout());

JProgressBar progressBar = new JProgressBar(0, 1);
progressBar.setStringPainted(true);
gbc = createGridConstraints(1, 0, 0.0, 0.0, GridBagConstraints.HORIZONTAL);
gbc.insets = new Insets(0, 10, 0, 10);
boxHeader.add(progressBar, gbc);
JPanel analysisBar = createAnalysisBar(logEntriesPane);
gbc = createGridConstraints(0, 0, 1.0, 0.0, GridBagConstraints.HORIZONTAL);
headerBox.add(analysisBar, gbc);

leftSidePanel = new JPanel();
leftSidePanel.setLayout(new GridBagLayout());
leftSidePanel.setPreferredSize(new Dimension(0, 40));
boxHeader.add(leftSidePanel, createGridConstraints(0, 0, 1.0, 0.0, GridBagConstraints.BOTH));
JButton analysisButton = createAnalysisButton(progressBar);
leftSidePanel.add(analysisButton, createGridConstraints(1, 0, 0.0, 0.0, GridBagConstraints.HORIZONTAL));
final JPanel spacer2 = new JPanel();
leftSidePanel.add(spacer2, createGridConstraints(0, 0, 1.0, 0.0, GridBagConstraints.HORIZONTAL));

rightSidePanel = new JPanel();
rightSidePanel.setLayout(new GridBagLayout());
rightSidePanel.setPreferredSize(new Dimension(0, 40));
boxHeader.add(rightSidePanel, createGridConstraints(2, 0, 1.0, 0.0, GridBagConstraints.BOTH));
JButton clearLogsButton = createClearLogsButton(logEntriesPane);
gbc = createGridConstraints(0, 0, 0.0, 0.0, GridBagConstraints.HORIZONTAL);
gbc.insets = new Insets(0, 0, 0, 5);
rightSidePanel.add(clearLogsButton, gbc);
final JPanel spacer1 = new JPanel();
rightSidePanel.add(spacer1, createGridConstraints(2, 0, 1.0, 0.0, GridBagConstraints.HORIZONTAL));
JToggleButton exportLogsButton = createExportLogsButton();
rightSidePanel.add(exportLogsButton, createGridConstraints(1, 0, 0.0, 0.0, GridBagConstraints.HORIZONTAL));

searchBarPanel = new JPanel();
searchBarPanel.setLayout(new GridBagLayout());
JPanel resultsFilterBar = createResultsFilterBar();
gbc = createGridConstraints(0, 1, 1.0, 0.0, GridBagConstraints.HORIZONTAL);
gbc.insets = new Insets(2, 10, 5, 10);
gbc.gridwidth = 3;
boxHeader.add(searchBarPanel, gbc);
headerBox.add(resultsFilterBar, gbc);

return headerBox;
}

private JPanel createResultsFilterBar() {
JPanel resultsFilterBar;
GridBagConstraints gbc;

resultsFilterBar = new JPanel();
resultsFilterBar.setLayout(new GridBagLayout());

JLabel searchLabel = new JLabel(getLocaleString("logger-searchBar-label"));
gbc = createGridConstraints(0, 0, 0, 0, GridBagConstraints.HORIZONTAL);
gbc.insets = new Insets(0, 0, 0, 5);
searchBarPanel.add(searchLabel, gbc);
resultsFilterBar.add(searchLabel, gbc);

JTextField searchField = new JTextField();
gbc = createGridConstraints(1, 0, 1, 0, GridBagConstraints.HORIZONTAL);
searchBarPanel.add(searchField, gbc);
resultsFilterBar.add(searchField, gbc);

JCheckBox regexCheckBox = new JCheckBox();
regexCheckBox.setText("Regex");
regexCheckBox.setSelected(true);
JCheckBox regexCheckbox = new JCheckBox(getLocaleString(LogsTableModel.Column.REGEX.getLocaleKey()));
regexCheckbox.setSelected(true);
gbc = createGridConstraints(2, 0, 0, 0, GridBagConstraints.HORIZONTAL);
gbc.insets = new Insets(0, 10, 0, 0);
searchBarPanel.add(regexCheckBox, gbc);
resultsFilterBar.add(regexCheckbox, gbc);

JCheckBox matchCheckBox = new JCheckBox();
matchCheckBox.setText("Match");
matchCheckBox.setSelected(true);
JCheckBox matchCheckbox = new JCheckBox(getLocaleString(LogsTableModel.Column.MATCH.getLocaleKey()));
matchCheckbox.setSelected(true);
gbc = createGridConstraints(3, 0, 0, 0, GridBagConstraints.HORIZONTAL);
gbc.insets = new Insets(0, 10, 0, 0);
searchBarPanel.add(matchCheckBox, gbc);
resultsFilterBar.add(matchCheckbox, gbc);

JCheckBox URLCheckBox = new JCheckBox();
URLCheckBox.setText("URL");
URLCheckBox.setSelected(true);
JCheckBox URLCheckbox = new JCheckBox(getLocaleString(LogsTableModel.Column.URL.getLocaleKey()));
URLCheckbox.setSelected(true);
gbc = createGridConstraints(4, 0, 0, 0, GridBagConstraints.HORIZONTAL);
gbc.insets = new Insets(0, 10, 0, 0);
searchBarPanel.add(URLCheckBox, gbc);
resultsFilterBar.add(URLCheckbox, gbc);

ActionListener checkBoxListener = e -> {
updateRowFilter(searchField.getText(), regexCheckBox.isSelected(), matchCheckBox.isSelected(), URLCheckBox.isSelected());
};
regexCheckBox.addActionListener(checkBoxListener);
matchCheckBox.addActionListener(checkBoxListener);
URLCheckBox.addActionListener(checkBoxListener);
ActionListener checkBoxListener = e -> updateRowFilter(searchField.getText(), regexCheckbox.isSelected(), matchCheckbox.isSelected(), URLCheckbox.isSelected());
regexCheckbox.addActionListener(checkBoxListener);
matchCheckbox.addActionListener(checkBoxListener);
URLCheckbox.addActionListener(checkBoxListener);

searchField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent documentEvent) {
updateRowFilter(searchField.getText(), regexCheckBox.isSelected(), matchCheckBox.isSelected(), URLCheckBox.isSelected());
updateRowFilter(searchField.getText(), regexCheckbox.isSelected(), matchCheckbox.isSelected(), URLCheckbox.isSelected());
}

@Override
public void removeUpdate(DocumentEvent documentEvent) {
updateRowFilter(searchField.getText(), regexCheckBox.isSelected(), matchCheckBox.isSelected(), URLCheckBox.isSelected());
updateRowFilter(searchField.getText(), regexCheckbox.isSelected(), matchCheckbox.isSelected(), URLCheckbox.isSelected());
}

@Override
public void changedUpdate(DocumentEvent documentEvent) {
updateRowFilter(searchField.getText(), regexCheckBox.isSelected(), matchCheckBox.isSelected(), URLCheckBox.isSelected());
updateRowFilter(searchField.getText(), regexCheckbox.isSelected(), matchCheckbox.isSelected(), URLCheckbox.isSelected());
}
});

return boxHeader;
return resultsFilterBar;
}

private JPanel createAnalysisBar(JScrollPane logEntriesPane) {
JPanel leftSidePanel;
JPanel rightSidePanel;
JPanel analysisBar;
GridBagConstraints gbc;

analysisBar = new JPanel();
analysisBar.setLayout(new GridBagLayout());

JProgressBar progressBar = new JProgressBar(0, 1);
progressBar.setStringPainted(true);
gbc = createGridConstraints(1, 0, 0.0, 0.0, GridBagConstraints.HORIZONTAL);
gbc.insets = new Insets(0, 10, 0, 10);
analysisBar.add(progressBar, gbc);

leftSidePanel = new JPanel();
leftSidePanel.setLayout(new GridBagLayout());
leftSidePanel.setPreferredSize(new Dimension(0, 40));
analysisBar.add(leftSidePanel, createGridConstraints(0, 0, 1.0, 0.0, GridBagConstraints.BOTH));
JButton analysisButton = createAnalysisButton(progressBar);
leftSidePanel.add(analysisButton, createGridConstraints(1, 0, 0.0, 0.0, GridBagConstraints.HORIZONTAL));
final JPanel spacer2 = new JPanel();
leftSidePanel.add(spacer2, createGridConstraints(0, 0, 1.0, 0.0, GridBagConstraints.HORIZONTAL));

rightSidePanel = new JPanel();
rightSidePanel.setLayout(new GridBagLayout());
rightSidePanel.setPreferredSize(new Dimension(0, 40));
analysisBar.add(rightSidePanel, createGridConstraints(2, 0, 1.0, 0.0, GridBagConstraints.BOTH));
JButton clearLogsButton = createClearLogsButton(logEntriesPane);
gbc = createGridConstraints(0, 0, 0.0, 0.0, GridBagConstraints.HORIZONTAL);
gbc.insets = new Insets(0, 0, 0, 5);
rightSidePanel.add(clearLogsButton, gbc);
final JPanel spacer1 = new JPanel();
rightSidePanel.add(spacer1, createGridConstraints(2, 0, 1.0, 0.0, GridBagConstraints.HORIZONTAL));
JToggleButton exportLogsButton = createExportLogsButton();
rightSidePanel.add(exportLogsButton, createGridConstraints(1, 0, 0.0, 0.0, GridBagConstraints.HORIZONTAL));

return analysisBar;
}

/**
* Filter rows of LogsTable that contains text string
*
* @param text To search
* @param includeRegex To search also in Regex column
* @param includeMatch To search also in Match column
* @param includeURL To search also in URL column
* @param text text to search
* @param includeRegex if true, also search in Regex column
* @param includeMatch if true, also search in Match column
* @param includeURL if true, also search in URL column
*/
private void updateRowFilter(String text, boolean includeRegex, boolean includeMatch, boolean includeURL) {
if (text.isBlank()) {
Expand All @@ -281,7 +298,7 @@ private void updateRowFilter(String text, boolean includeRegex, boolean includeM
logsTableRowSorter.setRowFilter(new RowFilter<>() {
@Override
public boolean include(Entry<? extends LogsTableModel, ? extends Integer> entry) {
List<LogsTableModel.Column> places = new ArrayList<>(List.of());
List<LogsTableModel.Column> places = new ArrayList<>();
if (includeRegex) places.add(LogsTableModel.Column.REGEX);
if (includeMatch) places.add(LogsTableModel.Column.MATCH);
if (includeURL) places.add(LogsTableModel.Column.URL);
Expand Down

0 comments on commit 48df30f

Please sign in to comment.