I'm developing a Burp Suite extension.
I have a class BurpExtender, it has public static field.
public class BurpExtender implements IBurpExtender, IContextMenuFactory{
private IBurpExtenderCallbacks callbacks;
public static PrintWriter stdout;
public static IExtensionHelpers helpers;
...
@Override
public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) {
this.callbacks = callbacks;
this.helpers = callbacks.getHelpers();
PrintWriter stdout = new PrintWriter(callbacks.getStdout(), true);
callbacks.setExtensionName("REQUESTSENDER");
callbacks.registerContextMenuFactory(BurpExtender.this);
stdout.println("Registered");
}
public List<JMenuItem> createMenuItems(final IContextMenuInvocation invocation) {
List<JMenuItem> menuItemList = new ArrayList<JMenuItem>();
JMenuItem item = new JMenuItem(new MyAction());
menuItemList.add(item);
return menuItemList;
}
and in this file i have another class MyAction:
private class MyAction extends AbstractAction{
public MyAction(){
super("Name");
}
public void actionPerformed(ActionEvent e) {
//Here i want to use BurpExtender.helpers, but i cant figure out, how to.
//BurpExtender.stdout doesnt work here. Dunno why, NullPoinerException.
}
}
I had another solution, when i tryed to do smth like JMenuItem item = new JMenuItem(new AbstractAction("123") {...} result it the same
You will need need to initialize the
helper
andstdout
objects in yourBurpExtender
class.Since these are static fields, an appropriate place would be to initialize them when declaring them or inside a static block in your class.
For Example:
Without this initialization, the
stdout
andhelpers
references will be pointing tonull
. This causes a NullPointerException when you try to useBurpExtender.stdout
orBurpExtender.helpers
in your other classes.In your
MyAction
class declare a reference to hold theIContextMenuInvocation invocation
object. Some thing like this:Then inside your outer class, change the
createMenuItems
method like this:Hope this helps!