Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistency across ghidra application settings paths (portability) #7505

Open
bukowa opened this issue Feb 14, 2025 · 11 comments
Open

Consistency across ghidra application settings paths (portability) #7505

bukowa opened this issue Feb 14, 2025 · 11 comments
Assignees
Labels
Feature: Launch Status: Prioritize This is currently being prioritized

Comments

@bukowa
Copy link

bukowa commented Feb 14, 2025

Is your feature request related to a problem? Please describe.

Ghidra is not consistent when it comes to application settings path. Lets take a look at application.settingsdir that you can declare in launch.properties file and application.version that you declare in application.properties.

# Settings directory used by the application to store application settings and data that persist
# between application sessions, system reboots, and periodic system cleanup. Overridden values
# are required to be absolute paths. The current user name may be incorporated into the settings
# directory's name if the settings directory lives outside of the user's home directory. The
# settings directory will be selected based on the following rules, in order of precedence:
# 1. System.getProperty("application.settingsdir")/[user-]<application>/<application>_<version>
# 2. System.getenv("XDG_CONFIG_HOME")/[user-]<application>/<application>_<version>
# 3. A platform specific default location:
# - Windows: %APPDATA%\<application>\<application>_<version>
# - Linux: $HOME/.config/<application>/<application>_<version>
# - macOS: $HOME/Library/<application>/<application>_<version>
#VMARGS=-Dapplication.settingsdir=

application.version=11.4

Given my username buk:

Example 1:

#VMARGS=-Dapplication.settingsdir=
C:\Users\buk\AppData\Roaming\AppData\ghidra_11.3_PUBLIC

Example 2:

VMARGS=-Dapplication.settingsdir=C:\ghidra\ghidra_11.3\Contrib\APPDATA
C:\ghidra\ghidra_11.3\Contrib\APPDATA\buk-ghidra\ghidra_11.3_PUBLIC

Result:

  • ghidra creates subdirectories inside settingsdir path (hard to know what will be final path)
  • ghidra creates directory based on application.version (setting that comes from totally different file which also requires changing when your trying to make the installation portable)
  • ghidra doesn't allow relative paths in these settings (harder to make it portable)

Extra:

Describe the solution you'd like
Consistent way that allows for portability.

@ryanmkurtz
Copy link
Collaborator

I don't really see any bugs here regarding inconsistency, but would something like VMARGS=-Dapplication.portable=true, where it puts the user settings/cache/temp directory inside the installation directory solve all of your problems?

@bukowa
Copy link
Author

bukowa commented Feb 14, 2025

but would something like VMARGS=-Dapplication.portable=true, where it puts the user settings/cache/temp directory inside the installation directory solve all of your problems?

I hope so ^^

@ryanmkurtz
Copy link
Collaborator

What would get you to an "I know so?" I ask because I don't want to potentially implement something that won't actually address the problem you are having. You are just trying to prevent Ghidra from using any files outside of its installation directory, correct?

@bukowa
Copy link
Author

bukowa commented Feb 14, 2025

What would get you to an "I know so?" I ask because I don't want to potentially implement something that won't actually address the problem you are having. You are just trying to prevent Ghidra from using any files outside of its installation directory, correct?

Oh right, I can't know ahead of time that everything is gonna work and that it will solve all my problems.

You are just trying to prevent Ghidra from using any files outside of its installation directory, correct?

Yes, portability. So in the end you can copy / paste ghidra directory anywhere and it should work just fine.
I think JAVA_HOME_OVERRIDE may be also important here.

@ryanmkurtz
Copy link
Collaborator

I think JAVA_HOME_OVERRIDE may be also important here.

We could potentially make that support relative paths from the root of the installation, but currently Ghidra requires at least Java 1.8 to be on the PATH or on JAVA_HOME, so Ghidra can run enough Java to find a supported JDK (21, currently).

@bukowa
Copy link
Author

bukowa commented Feb 14, 2025

I think JAVA_HOME_OVERRIDE may be also important here.

We could potentially make that support relative paths from the root of the installation, but currently Ghidra requires at least Java 1.8 to be on the PATH or on JAVA_HOME, so Ghidra can run enough Java to find a supported JDK (21, currently).

Is this doable to rewrite? You mean these?

JAVA_CMD=
if [ -x "$(command -v java)" ] ; then
JAVA_CMD=java
elif [ -n "${JAVA_HOME}" ] ; then
JAVA_CMD="${JAVA_HOME}/bin/java"
if [ ! -x "${JAVA_CMD}" ] ; then
echo "WARNING: JAVA_HOME environment variable is set to an invalid directory: ${JAVA_HOME}"

set JAVA_CMD=java.exe
java.exe -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto continue3
:: check for java based upon JAVA_HOME environment variable
if not defined JAVA_HOME goto javaNotFound
set "JAVA_CMD=%JAVA_HOME%\bin\java.exe"

@ryanmkurtz
Copy link
Collaborator

Yea, code would have to be added to those 2 files to parse the launch.properties file, get that override value, and use it. Definitely doable, but doing anything in a batch file is super annoying. That's why most of the logic is offloaded to the LaunchSupport java component.

@ryanmkurtz
Copy link
Collaborator

However, if instead of using that property, it instead just looked inside of say, <install_dir>/java, that would be super easy.

@bukowa
Copy link
Author

bukowa commented Feb 14, 2025

However, if instead of using that property, it instead just looked inside of say, <install_dir>/java, that would be super easy.

Seems like a good solution to not touch any batch files :D

@bukowa
Copy link
Author

bukowa commented Feb 14, 2025

I wonder if instead of <instrall_dir>/java they (all portable definitions like appdata,cachedata) could be place in a <install_dir>/portable instead ex.:

<install_dir>/portable/java
<install_dir>/portable/appdata
<install_dir>/portable/cachedata
<install_dir>/portable/projects

If Ghidra detects portable mode it could automatically default here to that directory (to save time)
Image

@ryanmkurtz
Copy link
Collaborator

Yes, I think that's a good idea. I will bring this up to the team next week. It should be trivial to implement.

@ryanmkurtz ryanmkurtz self-assigned this Feb 14, 2025
@ryanmkurtz ryanmkurtz added Status: Prioritize This is currently being prioritized Feature: Launch labels Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Launch Status: Prioritize This is currently being prioritized
Projects
None yet
Development

No branches or pull requests

2 participants