0

我正在开发一个 Burp Suite 扩展。

我有一个 BurpExtender 类,它有公共静态字段。

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;
    }

在这个文件中我有另一个类 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.
    }
}

我有另一个解决方案,当我尝试像 JMenuItem item = new JMenuItem(new AbstractAction("123") {...} 那样做时,结果是一样的

4

1 回答 1

1

您需要初始化类中的helperstdout对象BurpExtender

由于这些是静态字段,因此适当的位置是在声明它们时或在类中的静态块内初始化它们。

例如:

  1. 在声明它们时:
public static PrintWriter stdout = System.out;
public static IExtensionHelpers helpers = new ExtensionHelperImpl();// something like this.
  1. 或在静态块内
public static PrintWriter stdout;
public static IExtensionHelpers helpers;

static {
    stdout = System.out;
    helpers = new ExtensionHelperImpl();// something like this.
}

如果没有这个初始化,stdouthelpers引用将指向null。当您尝试使用 BurpExtender.stdoutBurpExtender.helpers在其他类中时,这会导致 NullPointerException。

更新

在你的MyAction类中声明一个引用来保存IContextMenuInvocation invocation对象。像这样的一些事情:

private class MyAction extends AbstractAction{
    private IContextMenuInvocation invocation;

    public MyAction(IContextMenuInvocation invocation){
        super("Name");
        this.invocation = invocation;
    }


    public void actionPerformed(ActionEvent e) {
        //Here you can use BurpExtender.helpers and IContextMenuInvocation invocation also.
        BurpExtender.helpers.doSomething();
        invocation.invoke();// for example..
    }
}

然后在你的外部类中,createMenuItems像这样更改方法:

public List<JMenuItem> createMenuItems(final IContextMenuInvocation invocation) {
    List<JMenuItem> menuItemList = new ArrayList<JMenuItem>();
    JMenuItem item = new JMenuItem(new MyAction(invocation));// this is the change
    menuItemList.add(item);
    return menuItemList;
}

希望这可以帮助!

于 2016-12-30T09:06:06.693 回答