Ghidra-Cpp-Class-Analyzer
Ghidra-Cpp-Class-Analyzer copied to clipboard
Installing the plugin in HeadlessMode
How is it possible to install the plugin in the Headless Mode - meaning without the use of GUI for the installation?
How is it possible to install the plugin in the Headless Mode - meaning without the use of GUI for the installation?
I'm not 100% sure. I did recently make changes to allow it to work in headless mode though so it should be possible. Try extracting the plugin to the extensions folder. Either of the two locations should work {ghidra_root}/Ghidra/Extensions or the .ghidra/{ghidra_version}/Extensions. Paths are not fully accurate since this response came from my phone.
I tried it both in Unix and Windows and it doesn't work. it looks like the installation is partial - I am able to call:
from cppclassanalyzer.utils import CppClassAnalyzerUtils
but
CppClassAnalyzerUtils.getManager(currentProgram)
Returns None.
Only if installing through the GUI, and through the dialog prompted by Ghidra:
"New extension plugins detected. Would you like to configure them?"
it is fully installed.
I did it at 2.5 tag.
As a sanity check, what does ghidra.util.SystemUtilities.isInHeadlessMode() return? Here is the relevant code for getting the manager which depends on said result:
https://github.com/astrelsky/Ghidra-Cpp-Class-Analyzer/blob/c712bc1f46ac59582e546d451b1afe0cccca15c6/src/main/java/cppclassanalyzer/utils/CppClassAnalyzerUtils.java#L139-L147
Yes, it returns True.
Yes, it returns True.
This shouldn't be possible then. You confirmed that you are able to retrieve a manager for the same program in the GUI but not in headless mode? The only way for it to return null is if no RttiManagerProvider supports the program.
I suggest the following scenario to reproduce the issue (Windows machine):
- Download and extract a fresh copy of Ghidra.
- Rename
<home>\.ghidrato<home>\.ghidra_bup - Copy the plugin to
<ghidra_home>\Ghidra\Extensions - Create the following script file:
from cppclassanalyzer.utils import CppClassAnalyzerUtils
CppClassAnalyzerUtils.getManager(currentProgram).getTypeCount()
- Save the file in
<home>\script.py - Run the following from the command line:
<ghidra_home>\support\analyzeHeadless <home> myproject -import <path_to_any_file> -overwrite -postscript <home>\script.py - You will see in the console output:
Traceback (most recent call last):
File <home>\script.py, line 14, in <module>
CppClassAnalyzerUtils.getManager(currentProgram).getTypeCount()
AttributeError: 'NoneType' object has no attribute 'getTypeCount'
If I install it once from the GUI - it will work afterward from the Headless mode too. But without GUI it never works.
I will take a look tonight to see what is going on. This shouldn't be occurring.
Edit: something came up and I won't get to this until the weekend.
Edit again, I forgot :rofl: I will get to it sometime soon though.
If I install it once from the GUI - it will work afterward from the Headless mode too. But without GUI it never works.
When I try this I end up with an import error. It seems that when running analyzeHeadless it isn't loading the extensions in <ghidra_home>\Ghidra\Extensions. Considering you didn't get the import error I suspect you have a lingering version where the headless support either didn't exist or was incomplete. The old version would be located in %UserProfile%/.ghidra/.ghidra_<VERSION>/Extensions which is where they now get installed when done through the GUI. Both locations are supposed to work though.
The extensions not being loaded from Ghidra/Extensions in headless mode is probably something that should be delegated back to the Ghidra team.
If you place it in the "new" location it should work.