<commit_before>/* 
 * Released as open source by NCC Group Plc - https://www.nccgroup.com/
 *
 * Developed by <NAME>, <EMAIL>
 * 
 * https://www.github.com/nccgroup/pcap-burp
 *
 * Licensed under the Affero General Public License 
 * https://github.com/nccgroup/pcap-burp/LICENSE
 */
package burp;

import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Collections;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import pcap.reconst.ex.PcapException;

import com.nccgroup.burp.pcap.HttpReconstructor;
import com.nccgroup.burp.pcap.PcapFileFilter;

public class BurpExtender implements IBurpExtender
{
	public static IBurpExtenderCallbacks callbacks;

	private static final class OpenPcapFileMenuAction extends AbstractAction {
		/**
		 * Generate by Eclipse
		 */
		private static final long serialVersionUID = 5003331249971440291L;
		
		//Create a file chooser
		private final JFileChooser fc = new JFileChooser();

		public OpenPcapFileMenuAction() {
			fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
			fc.setFileFilter(new PcapFileFilter());
			
			setEnabled(true);
			putValue("Name", "Open Pcap File...");
		}
		
		public void actionPerformed(ActionEvent e) {
			int returnVal = fc.showOpenDialog(null);

		    if (returnVal == JFileChooser.APPROVE_OPTION) {
		        File file = fc.getSelectedFile();
		        try
		        {
		        	HttpReconstructor.loadPcap(file);
		        }
		        catch(PcapException pce)
		        {
		        	JOptionPane.showMessageDialog(null,
		        		    pce.getLocalizedMessage(),
		        		    "Pcap Exception",
		        		    JOptionPane.ERROR_MESSAGE);
		        }
		        catch(UnsatisfiedLinkError ule)
		        {
		            // write a message to the Burp alerts tab
		            callbacks.issueAlert("Unable to load jNetPcap library from java.library.path");
            		callbacks.issueAlert("java.library.path is "+ System.getProperty("java.library.path"));
            		callbacks.issueAlert("Visit https://github.com/neonbunny/pcap-reconst/tree/master/lib for available libraries.");
		        }
		    }
		}
	}

    
	public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks)
    {
    	BurpExtender.callbacks = callbacks;
    	
    	callbacks.registerContextMenuFactory(new IContextMenuFactory() {<commit_msg>#3 Allow selection of multiple pcap files.<commit_after>/* 
 * Released as open source by NCC Group Plc - https://www.nccgroup.com/
 *
 * Developed by <NAME>, <EMAIL>
 * 
 * https://www.github.com/nccgroup/pcap-burp
 *
 * Licensed under the Affero General Public License 
 * https://github.com/nccgroup/pcap-burp/LICENSE
 */
package burp;

import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Collections;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import pcap.reconst.ex.PcapException;

import com.nccgroup.burp.pcap.HttpReconstructor;
import com.nccgroup.burp.pcap.PcapFileFilter;

public class BurpExtender implements IBurpExtender
{
	public static IBurpExtenderCallbacks callbacks;

	private static final class OpenPcapFileMenuAction extends AbstractAction {
		/**
		 * Generate by Eclipse
		 */
		private static final long serialVersionUID = 5003331249971440291L;
		
		//Create a file chooser
		private final JFileChooser fc = new JFileChooser();

		public OpenPcapFileMenuAction() {
			fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
			fc.setMultiSelectionEnabled(true);
			fc.setFileFilter(new PcapFileFilter());
			
			setEnabled(true);
			putValue("Name", "Open Pcap File...");
		}
		
		public void actionPerformed(ActionEvent e) {
			int returnVal = fc.showOpenDialog(null);

		    if (returnVal == JFileChooser.APPROVE_OPTION) {
		        File[] files = fc.getSelectedFiles();
		        try
		        {
		        	for (File file : files)
		        	{
		        		HttpReconstructor.loadPcap(file);
		        	}
		        }
		        catch(PcapException pce)
		        {
		        	JOptionPane.showMessageDialog(null,
		        		    pce.getLocalizedMessage(),
		        		    "Pcap Exception",
		        		    JOptionPane.ERROR_MESSAGE);
		        }
		        catch(UnsatisfiedLinkError ule)
		        {
		            // write a message to the Burp alerts tab
		            callbacks.issueAlert("Unable to load jNetPcap library from java.library.path");
            		callbacks.issueAlert("java.library.path is "+ System.getProperty("java.library.path"));
            		callbacks.issueAlert("Visit https://github.com/neonbunny/pcap-reconst/tree/master/lib for available libraries.");
		        }
		    }
		}
	}

    
	public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks)
    {
    	BurpExtender.callbacks = callbacks;
    	
    	callbacks.registerContextMenuFactory(new IContextMenuFactory() {
{'fraction_non_alphanumeric': 0.09576390283075688, 'fraction_numerical': 0.00782975306163421, 'mean_word_length': 2.9105180533751964, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6314167', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1505, 'n_words': 305}