Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Installing the plugin in HeadlessMode #43

Closed
HexRoman opened this issue Aug 19, 2021 · 9 comments
Closed

Installing the plugin in HeadlessMode #43

HexRoman opened this issue Aug 19, 2021 · 9 comments

Comments

@HexRoman
Copy link

How is it possible to install the plugin in the Headless Mode - meaning without the use of GUI for the installation?

@astrelsky
Copy link
Owner

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.

@HexRoman
Copy link
Author

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.

@astrelsky
Copy link
Owner

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:

public static ProgramClassTypeInfoManager getManager(Program program) {
ClassTypeInfoManagerService service;
if (isInHeadlessMode()) {
service = HeadlessClassTypeInfoManagerService.getInstance();
} else {
service = getService(program);
}
return service != null ? service.getManager(program) : null;
}

@HexRoman
Copy link
Author

Yes, it returns True.

@astrelsky
Copy link
Owner

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.

@HexRoman
Copy link
Author

HexRoman commented Aug 19, 2021

I suggest the following scenario to reproduce the issue (Windows machine):

  1. Download and extract a fresh copy of Ghidra.
  2. Rename <home>\.ghidra to <home>\.ghidra_bup
  3. Copy the plugin to <ghidra_home>\Ghidra\Extensions
  4. Create the following script file:
from cppclassanalyzer.utils import CppClassAnalyzerUtils
 
CppClassAnalyzerUtils.getManager(currentProgram).getTypeCount()
  1. Save the file in <home>\script.py
  2. Run the following from the command line:
    <ghidra_home>\support\analyzeHeadless <home> myproject -import <path_to_any_file> -overwrite -postscript <home>\script.py
  3. 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'

@HexRoman
Copy link
Author

If I install it once from the GUI - it will work afterward from the Headless mode too. But without GUI it never works.

@astrelsky
Copy link
Owner

astrelsky commented Aug 19, 2021

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 🤣 I will get to it sometime soon though.

@astrelsky
Copy link
Owner

astrelsky commented Aug 27, 2021

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants