Projects STRLCPY LoggerPlusPlus Commits ac8a4f7e
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/grepper/GrepResults.java
    skipped 2 lines
    3 3  import com.nccgroup.loggerplusplus.logentry.LogEntry;
    4 4   
    5 5  import java.util.ArrayList;
    6  -import java.util.regex.Matcher;
    7  -import java.util.regex.Pattern;
    8 6   
    9 7  public class GrepResults {
    10 8   private final LogEntry entry;
     9 + private final ArrayList<Match> results;
    11 10   private int requestMatches = 0;
    12 11   private int responseMatches = 0;
    13  - private ArrayList<Match> results;
    14 12   
    15 13   
    16  - public GrepResults(Pattern pattern, LogEntry entry) {
     14 + public GrepResults(LogEntry entry) {
    17 15   this.entry = entry;
    18 16   this.results = new ArrayList<>();
    19  - 
    20  - processEntry(pattern);
    21 17   }
    22 18   
    23 19   public ArrayList<Match> getMatches() {
    skipped 4 lines
    28 24   return this.entry;
    29 25   }
    30 26   
    31  - public int getRequestMatches() {
    32  - return requestMatches;
     27 + public void addRequestMatch(Match match) {
     28 + this.results.add(match);
     29 + this.requestMatches++;
    33 30   }
    34 31   
    35  - public int getResponseMatches() {
    36  - return responseMatches;
     32 + public void addResponseMatch(Match match) {
     33 + this.results.add(match);
     34 + this.responseMatches++;
    37 35   }
    38 36   
    39  - private void processEntry(Pattern pattern){
    40  - if(entry.requestResponse != null){
    41  - if(entry.requestResponse.getRequest() != null) {
    42  - processMatches(pattern, entry.requestResponse.getRequest(), true);
    43  - }
    44  - if(entry.requestResponse.getResponse() != null) {
    45  - processMatches(pattern, entry.requestResponse.getResponse(), false);
    46  - }
    47  - }
     37 + public int getRequestMatches() {
     38 + return requestMatches;
    48 39   }
    49 40   
    50  - private void processMatches(Pattern pattern, byte[] content, boolean isRequest){
    51  - final Matcher respMatcher = pattern.matcher(new String(content));
    52  - while(respMatcher.find() && !Thread.currentThread().isInterrupted()){
    53  - String[] groups = new String[respMatcher.groupCount()+1];
    54  - for (int i = 0; i < groups.length; i++) {
    55  - groups[i] = respMatcher.group(i);
    56  - }
    57  - 
    58  - if(isRequest) {
    59  - requestMatches++;
    60  - }else {
    61  - responseMatches++;
    62  - }
    63  - results.add(new Match(groups, isRequest, respMatcher.start(), respMatcher.end()));
    64  - }
     41 + public int getResponseMatches() {
     42 + return responseMatches;
    65 43   }
    66 44   
    67 45   public static class Match {
    skipped 14 lines
  • ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/grepper/GrepperController.java
    skipped 14 lines
    15 15  import java.util.concurrent.ExecutorService;
    16 16  import java.util.concurrent.Executors;
    17 17  import java.util.concurrent.atomic.AtomicInteger;
     18 +import java.util.regex.Matcher;
    18 19  import java.util.regex.Pattern;
    19 20   
    20 21  public class GrepperController {
    skipped 53 lines
    74 75   return LoggerPlusPlus.callbacks.applyMarkers(requestResponse, requestMarkers, responseMarkers);
    75 76   }
    76 77   
    77  - public void beginSearch(final Pattern pattern, final boolean inScopeOnly) {
     78 + public void beginSearch(final Pattern pattern, final boolean inScopeOnly, final boolean searchRequests, final boolean searchResponses) {
    78 79   int searchThreads = this.preferences.getSetting(Globals.PREF_SEARCH_THREADS);
    79 80   this.searchExecutor = Executors.newFixedThreadPool(searchThreads, new NamedThreadFactory("LPP-Grepper"));
    80 81   
    skipped 6 lines
    87 88   });
    88 89   
    89 90   for (LogEntry logEntry : logEntries) {
    90  - searchExecutor.submit(createProcessThread(logEntry, pattern, inScopeOnly));
     91 + searchExecutor.submit(createProcessThread(logEntry, pattern, inScopeOnly, searchRequests, searchResponses));
    91 92   }
    92 93   }).start();
    93 94   }
    94 95   
    95  - private Runnable createProcessThread(final LogEntry logEntry, final Pattern pattern, final boolean inScopeOnly){
     96 + private GrepResults processEntry(LogEntry entry, Pattern pattern, final boolean searchRequests, final boolean searchResponses) {
     97 + GrepResults grepResults = null;
     98 + if (entry.requestResponse != null) {
     99 + grepResults = new GrepResults(entry);
     100 + if (entry.requestResponse.getRequest() != null && searchRequests) {
     101 + processMatches(grepResults, pattern, entry.requestResponse.getRequest(), true);
     102 + }
     103 + if (entry.requestResponse.getResponse() != null && searchResponses) {
     104 + processMatches(grepResults, pattern, entry.requestResponse.getResponse(), false);
     105 + }
     106 + }
     107 + return grepResults;
     108 + }
     109 + 
     110 + private void processMatches(GrepResults grepResults, Pattern pattern, byte[] content, boolean isRequest) {
     111 + final Matcher respMatcher = pattern.matcher(new String(content));
     112 + while (respMatcher.find() && !Thread.currentThread().isInterrupted()) {
     113 + String[] groups = new String[respMatcher.groupCount() + 1];
     114 + for (int i = 0; i < groups.length; i++) {
     115 + groups[i] = respMatcher.group(i);
     116 + }
     117 + 
     118 + if (isRequest) {
     119 + grepResults.addRequestMatch(new GrepResults.Match(groups, true, respMatcher.start(), respMatcher.end()));
     120 + } else {
     121 + grepResults.addResponseMatch(new GrepResults.Match(groups, false, respMatcher.start(), respMatcher.end()));
     122 + }
     123 + }
     124 + }
     125 + 
     126 + private Runnable createProcessThread(final LogEntry logEntry, final Pattern pattern,
     127 + final boolean inScopeOnly, final boolean searchRequests, final boolean searchResponses) {
    96 128   return () -> {
    97  - if(Thread.currentThread().isInterrupted()) return;
     129 + if (Thread.currentThread().isInterrupted()) return;
    98 130   GrepResults grepResults = null;
    99 131   if (!inScopeOnly || LoggerPlusPlus.callbacks.isInScope(logEntry.url)) {
    100  - grepResults = new GrepResults(pattern, logEntry);
     132 + grepResults = processEntry(logEntry, pattern, searchRequests, searchResponses);
    101 133   }
    102 134   for (GrepperListener listener : this.listeners) {
    103 135   try {
    104 136   listener.onEntryProcessed(grepResults);
    105  - }catch (Exception e){
     137 + } catch (Exception e) {
    106 138   e.printStackTrace();
    107 139   }
    108 140   }
    skipped 54 lines
  • ■ ■ ■ ■ ■ ■
    src/main/java/com/nccgroup/loggerplusplus/grepper/GrepperPanel.java
    skipped 27 lines
    28 28   private final JButton searchButton;
    29 29   private final JButton resetButton;
    30 30   private final JProgressBar progressBar;
     31 + private final JCheckBox searchRequests;
     32 + private final JCheckBox searchResponses;
    31 33   private final JCheckBox inScopeOnly;
    32 34   private final JTabbedPane resultsPane;
    33 35   private final GrepResultsTable grepResultsTable;
    34 36   private final RequestViewerController requestViewerController;
    35 37   private final UniquePatternMatchTable uniqueTable;
    36 38   
    37  - GrepperPanel(GrepperController controller, Preferences preferences){
     39 + GrepperPanel(GrepperController controller, Preferences preferences) {
    38 40   this.controller = controller;
    39 41   this.preferences = preferences;
    40 42   
    skipped 1 lines
    42 44   searchField.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
    43 45   @Override
    44 46   public void keyPressed(KeyEvent e) {
    45  - if(e.getKeyChar() == KeyEvent.VK_ENTER){
     47 + if (e.getKeyChar() == KeyEvent.VK_ENTER) {
    46 48   startSearch();
    47 49   }
    48 50   }
    skipped 1 lines
    50 52   
    51 53   this.progressBar = new JProgressBar();
    52 54   this.inScopeOnly = new JCheckBox("In Scope Only");
     55 + this.searchRequests = new JCheckBox("Search Requests", true);
     56 + this.searchResponses = new JCheckBox("Search Responses", true);
    53 57   
    54 58   this.searchButton = new JButton(new AbstractAction("Search") {
    55 59   @Override
    skipped 47 lines
    103 107   this.resultsPane.addTab("Results", resultsSplitPane);
    104 108   this.resultsPane.addTab("Unique Results", new JScrollPane(uniqueTable));
    105 109   
     110 + JLabel regexLabel = new JLabel("Regex: ");
    106 111   JPanel wrapperPanel = PanelBuilder.build(new JComponent[][]{
    107  - new JComponent[]{new JLabel("Regex: "), searchField, inScopeOnly, searchButton, resetButton},
    108  - new JComponent[]{resultsPane, resultsPane, resultsPane, resultsPane, resultsPane},
    109  - new JComponent[]{progressBar, progressBar, progressBar, progressBar, progressBar}
     112 + new JComponent[]{regexLabel, searchField, searchRequests, searchResponses, inScopeOnly, searchButton, resetButton},
     113 + new JComponent[]{resultsPane, resultsPane, resultsPane, resultsPane, resultsPane, resultsPane, resultsPane},
     114 + new JComponent[]{progressBar, progressBar, progressBar, progressBar, progressBar, progressBar, progressBar}
    110 115   }, new int[][]{
    111  - new int[]{0, 1, 0, 0, 0},
    112  - new int[]{1, 100, 1, 1, 0},
    113  - new int[]{0, 0, 0, 0, 0}
     116 + new int[]{0, 1, 0, 0, 0, 0},
     117 + new int[]{1, 100, 1, 1, 1, 0},
     118 + new int[]{0, 0, 0, 0, 0, 0}
    114 119   }, Alignment.FILL, 1.0, 1.0);
    115 120   
    116 121   this.setLayout(new BorderLayout());
    skipped 2 lines
    119 124   this.controller.addListener(this);
    120 125   }
    121 126   
    122  - private void startSearch(){
     127 + private void startSearch() {
    123 128   String patternString = ((JTextField) this.searchField.getEditor().getEditorComponent()).getText();
    124 129   Pattern pattern;
    125 130   try {
    126 131   pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
    127  - }catch (PatternSyntaxException e){
     132 + } catch (PatternSyntaxException e) {
    128 133   JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(controller.getLoggerPlusPlus().getMainViewController().getUiComponent()), "Pattern Syntax Invalid", "Invalid Pattern", JOptionPane.ERROR_MESSAGE);
    129 134   return;
    130 135   }
    131 136   
    132  - this.controller.beginSearch(pattern, this.inScopeOnly.isSelected());
     137 + this.controller.beginSearch(pattern, this.inScopeOnly.isSelected(),
     138 + this.searchRequests.isSelected(), this.searchResponses.isSelected());
    133 139   }
    134 140   
    135 141   @Override
    136 142   public void onSearchStarted(Pattern pattern, int totalRequests) {
    137 143   SwingUtilities.invokeLater(() -> {
     144 + this.searchRequests.setEnabled(false);
     145 + this.searchResponses.setEnabled(false);
    138 146   this.searchField.setEnabled(false);
    139 147   this.resetButton.setEnabled(false);
    140 148   this.searchButton.setText("Cancel");
    skipped 11 lines
    152 160   
    153 161   @Override
    154 162   public void onSearchComplete() {
    155  - SwingUtilities.invokeLater(() -> {
    156  - this.searchButton.setText("Search");
    157  - this.progressBar.setValue(0);
    158  - this.searchField.setEnabled(true);
    159  - this.resetButton.setEnabled(true);
    160  - });
     163 + unlockUI();
    161 164   }
    162 165   
    163 166   @Override
    skipped 10 lines
    174 177   
    175 178   @Override
    176 179   public void onShutdownComplete() {
     180 + unlockUI();
     181 + }
     182 + 
     183 + private void unlockUI() {
    177 184   SwingUtilities.invokeLater(() -> {
    178 185   this.searchButton.setText("Search");
    179 186   this.progressBar.setValue(0);
    180 187   this.searchField.setEnabled(true);
    181 188   this.resetButton.setEnabled(true);
     189 + this.searchRequests.setEnabled(true);
     190 + this.searchResponses.setEnabled(true);
    182 191   });
    183 192   }
    184 193  }
    skipped 1 lines
Please wait...
Page is in error, reload to recover