Skip to content

Commit

Permalink
fix JMenu bug caused by failed JFrame retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
tsc-awardle committed Nov 30, 2022
1 parent c935344 commit 8cc7e60
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/main/java/com/nccgroup/loggerplusplus/LoggerPlusPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static com.nccgroup.loggerplusplus.util.Globals.PREF_RESTRICT_TO_SCOPE;

Expand Down Expand Up @@ -53,6 +54,21 @@ public LoggerPlusPlus(){
this.gsonProvider = new DefaultGsonProvider();
}

private JFrame getBurpFrame() throws Exception {
// Get all frames
Frame[] allFrames = JFrame.getFrames();
// Filter the stream find the main burp window frame, and convert to a list
List<Frame> filteredFrames = Arrays.stream(allFrames).filter(f ->
f.getTitle().startsWith("Burp Suite") && f.isVisible()
).collect(Collectors.toList());
// If size is 1, we have the main burp frame. Otherwise fails
if (filteredFrames.size() == 1) {
return (JFrame) filteredFrames.get(0);
} else {
throw new Exception("Expected one burp pane, but found " + filteredFrames.size());
}
}

@Override
public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks)
{
Expand Down Expand Up @@ -98,7 +114,13 @@ public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks)
LoggerPlusPlus.callbacks.addSuiteTab(mainViewController);

//Add menu item to Burp's frame menu.
JFrame rootFrame = (JFrame) SwingUtilities.getWindowAncestor(mainViewController.getUiComponent());
JFrame rootFrame = null;
try {
rootFrame = getBurpFrame();
} catch (Exception e) {
callbacks.printError("Could not find root frame. Window JMenu will not be added");
throw new RuntimeException(e);
}
try{
JMenuBar menuBar = rootFrame.getJMenuBar();
loggerMenu = new LoggerMenu(LoggerPlusPlus.this);
Expand Down

0 comments on commit 8cc7e60

Please sign in to comment.