| 12 | import java.util.concurrent.CompletableFuture; |
| 13 | |
| 14 | public class ContextMenu implements IContextMenuFactory { |
| 15 | private static final HashSet<Byte> availableToolFlag = new HashSet<>(); |
| 16 | |
| 17 | static { |
| 18 | availableToolFlag.add(IContextMenuInvocation.CONTEXT_PROXY_HISTORY); |
| 19 | availableToolFlag.add(IContextMenuInvocation.CONTEXT_MESSAGE_EDITOR_REQUEST); |
| 20 | availableToolFlag.add(IContextMenuInvocation.CONTEXT_MESSAGE_VIEWER_REQUEST); |
| 21 | } |
| 22 | |
| 23 | @Override |
| 24 | public List<JMenuItem> createMenuItems(IContextMenuInvocation invocation) { |
| 25 | if (availableToolFlag.contains(invocation.getInvocationContext())) { |
| 26 | ArrayList<JMenuItem> menuItemList = new ArrayList<>(); |
| 27 | JMenuItem menuItem = new JMenuItem("Do API scan"); |
| 28 | menuItem.addActionListener(new ContextMenuActionListener(invocation)); |
| 29 | menuItemList.add(menuItem); |
| 30 | return menuItemList; |
| 31 | } else { |
| 32 | return null; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | static class ContextMenuActionListener implements ActionListener { |
| 37 | IContextMenuInvocation invocation; |
| 38 | |
| 39 | public ContextMenuActionListener(IContextMenuInvocation invocation) { |
| 40 | this.invocation = invocation; |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public void actionPerformed(ActionEvent actionEvent) { |
| 45 | CompletableFuture.supplyAsync(() -> { |
| 46 | PassiveScanner passiveScanner = BurpExtender.getPassiveScanner(); |
| 47 | |
| 48 | IHttpRequestResponse[] httpRequestResponses = invocation.getSelectedMessages(); |
| 49 | |
| 50 | for (IHttpRequestResponse httpRequestResponse : httpRequestResponses) { |
| 51 | ArrayList<ApiType> apiTypes = passiveScanner.getApiScanner().detect(httpRequestResponse, false); |
| 52 | passiveScanner.parseApiDocument(apiTypes); |
| 53 | } |
| 54 | return null; |
| 55 | }, Executor.getExecutor()); |
| 56 | } |
| 57 | } |
| 58 | } |