0

In ghidra script you can just println("to the console");

However I need to print to the ghidra console from a ghidra plugin (a real jar plugin, not a script).

I found that I can get an instance of ConsoleService via:

 ConsoleService consoleService = pluginTool.getService(ConsoleService.class);
 consoleService.print("hello");

my plugin looks like the following:

public class MyPlugin extends AbstractAnalyzer {
    public MyPlugin() {
        setSupportsOneTimeAnalysis(true);
    }
}

How do I get an instance of a PluginTool so that I could get the ConsoleService?

Ilya Kharlamov
  • 3,698
  • 1
  • 31
  • 33

2 Answers2

1

Every Ghidra plugin that is loaded in a tool should have the tool available as field called tool, see https://ghidra.re/ghidra_docs/api/ghidra/framework/plugintool/Plugin.html#tool

Florian Magin
  • 576
  • 3
  • 6
0

This is a very late answer, but better late than never.

Analyzers aren't Plugins.

Plugins, and the PluginTool they live in, are a GUI concept. Analyzers are decoupled from the GUI and need to work independently of that. (think headless analyzer)

Analyzers can use (ghidra.util.)Msg.info(), Msg.warn(), Msg.error() to log messages to ghidra's log. Also, the Analyzer.added() method has a MessageLog param that you can use to alert the user about issues that during analysis.

Trevor Harrison
  • 1,744
  • 1
  • 14
  • 20