Merge remote-tracking branch 'origin/GP-5161_ghidra1_GhidraServerCME--SQUASHED'

This commit is contained in:
Ryan Kurtz
2025-01-03 13:32:43 -05:00
9 changed files with 444 additions and 249 deletions

View File

@@ -60,6 +60,7 @@ typewriter {
<UL>
<LI><a href="#checkinFailures">Failures Creating Repository Folders / Checking in Files</a></LI>
<LI><a href="#connectErrors">Client/Server connection errors</a></LI>
<LI><a href="#windowsWatchService">MS Windows - ERROR Incorrect function (WindowsWatchService)</a></LI>
<LI><a href="#windowsMissingTempDirectory">MS Windows - ERROR Missing Temp Directory</a></LI>
<LI><a href="#windows7and8_scriptErrors">MS Windows 7 and 8 - ghidraSvr.bat, svrInstall.bat,
or svrUninstall.bat Error</a></LI>
@@ -95,13 +96,7 @@ run a second concurrent instance may lead to difficulties and is not supported.
<b>NOTE</b>: It is highly recommended that the installation files for Ghidra reside on a local drive
and that the intended Ghidra Server process owner is granted full access to the Ghidra installation
directory (this is frequently not the case for NFS/SMB mounted home directories).
</P>
<P>
<b>NOTE</b>: It is highly recommended that you establish a repositories directory outside of your
Ghidra installation directory so that it may be re-used more easily with future upgraded
installations of Ghidra.
</P>
</P>
<P>
You may also refer to the <typewriter>InstallationGuide.html</typewriter> file within the
@@ -137,8 +132,20 @@ location and other associated options.
</P>
<P>
You should generally avoid using the default repositories location and specify a location outside
your installation directory using an absolute path specification.
It is highly recommended that you specify a repositories directory outside of your
Ghidra installation directory with an absolute path so that it may be re-used more easily with
future upgraded installations of Ghidra. Due to the use of a filesystem
watcher service the use of a locally attached storage device is preferred and will also ensure
the best performance.
</P>
<P>
<b>NOTE:</b> The server may fail to start if the repository native filesystem does
not support the use of a filesystem watcher service. This could occur if attempting to use a
remotely-mounted filesystem which may lack the required event support. The watcher service is used
in conjunction with command processing associated with the <b>svrAdmin</b> command. If a running
server fails to process queued <b>svrAdmin</b> command requests, the repository native filesystem
may be the cause.
</P>
<P>
@@ -401,7 +408,7 @@ are not currently supported.
<LI><typewriter>-autoProvision</typewriter><br>Enable the auto-creation of new Ghidra Server
users when they successfully authenticate to the server (-a1 and -a4 modes only).
Users removed from the authentication provider (e.g., Active Directory) will need to be
deleted manually from the Ghidra Server using svrAdmin command.</LI>
deleted manually from the Ghidra Server using <b>svrAdmin</b> command.</LI>
<br>
<LI><typewriter>-anonymous</typewriter><br>Enable anonymous access support for Ghidra Server
and its repositories. Only those repositories which specifically enable anonymous access will be
@@ -555,8 +562,26 @@ are not currently supported.
<P>
The Ghidra Server may be installed as an automatic service by executing the
<typewriter>svrInstall</typewriter> script. Once installed, the server will start automatically
when the system is booted.
when the system is booted. If performing an upgrade to an existing Ghidra Server installation
you must uninstall the existing Ghidra Server first (see
<a href="#linux_mac_uninstall">Uninstall Service</a>).
</P>
<P>
In order for the installed service script to survive Java system updates, which may change
the installed Java version, it is highly recommended that the GHIDRA_JAVA_HOME variable be set
properly at the top of the <typewriter>ghidraSvr</typewriter> script prior to the server install.
GHIDRA_JAVA_HOME should refer to a non-changing path where Java is installed. For a system-installed
Java the major-version symblic-link path should be specified in favor of a
full-version path which stipulates minor-version information. In addition, it is important
that the Ghidra Server service be restarted anytime the installed Java version is updated where
this symbolic link has been modified to reference a newly installed Java version. Failure to
use this approach may result in the Ghidra Server service script referring to an invalid Java
path following an update.
</P>
<P>Example setting of GHIDRA_JAVA_HOME within <typewriter>ghidraSvr</typewriter> script:
<PRE>
GHIDRA_JAVA_HOME=/usr/lib/jvm/java-21-openjdk
</PRE>
<P>
If it is preferred to run the service with a dedicated local user account, the following
entry may be added to the <i>server.conf</i> file with the appropriate account specified in
@@ -567,7 +592,7 @@ are not currently supported.
installation of the Ghidra Server service.
</P>
<PRE>
wrapper.app.account=&lt;uid&gt;
wrapper.app.account=&lt;uid&gt;
</PRE>
<P>
It is also important that the repositories directory and Ghidra installation files
@@ -582,14 +607,20 @@ to run as <i>root</i> and monitor/manage the Java process.
<typewriter>svrUninstall</typewriter> script.
</P>
<P>
<b>NOTE</b>: It is very important that you uninstall the service prior to doing any of the following
activities:
<b>IMPORTANT</b>: It is very important that you uninstall the Ghidra Server service using the
original Ghidra software installation. Use of a newer Ghidra software install may not properly
uninstall a different service version. This is particularly true if uninstalling
a Ghidra Server version prior to 11.2. Such an uninstall will be required when:
<UL>
<LI>deleting or upgrading the Ghidra installation</LI>
<LI>moving/renaming the Ghidra installation directory</LI>
</UL>
</P>
<P>
<b>NOTE</b>: The service control mechanism for Linux changed with the Ghidra 11.2 release.
The <typewriter>init.d</typewriter> mechanism was previously used in all cases, whereas the
<typewriter>systemd</typewriter> service mechanism may now used based upon YAJSW preference.
</P>
(<a href="#top">Back to Top</a>)
<div style="border-top: 4px double; margin-top: 1em; padding-top: 1em;"> </div>
@@ -1007,6 +1038,14 @@ newer SSL/TLS enabled Ghidra Server registry, the following connection error wil
<PRE>
non-JRMP server at remote endpoint
</PRE>
</P>
<br>
<a name="windowsWatchService"><h3><u>MS Windows - ERROR Incorrect function (WindowsWatchService)</u></h3></a>
<P>
The Ghidra Server employs a file system watcher service for the repositories directory which must
reside within a locally mounted NTFS or ReFS filesystem.
</P>
<br>
<a name="windowsMissingTempDirectory"><h3><u>MS Windows - ERROR Missing Temp Directory</u></h3></a>

View File

@@ -5,13 +5,24 @@
# Usage: ghidraSvr [ console | status | install | uninstall | start | stop | restart ]
#---------------------------------------------------------------------------------------
# The Java 21 (or later) runtime installation must either be on the system path or identified
# by setting the JAVA_HOME environment variable. If not using a formally installed Java
# runtime which has been configured into the system PATH ahead of other Java installations
# it may be necessary to explicitly specify the path to the installation by setting JAVA_HOME
# below:
# The Java 21 (or later) runtime installation must either be on the system path, specified by the
# JAVA_HOME environment variable or preferably set explicitly with the GHIDRA_JAVA_HOME variable
# below. Since this script may be used during service initialization, reliance on environmental
# settings such as JAVA_HOME may be problematic. It is also important to note that once installed
# as a service, changes to this file or environmental settings may not have an affect on any service
# scripts that was generated at the time of service installation.
#
# When specifying GHIDRA_JAVA_HOME below it is recommended that a symbolic link path be specified
# which only includes the major java version so that any system Java updates will allow for this
# path to remain valid. In the case of Linux, this is important since once the Ghidra Server is
# installed as a systemd service the Java path will be locked-in to the generated ghidra.service
# script.
#
# Example: The symbolic link "/usr/lib/jvm/java-21-openjdk" should be specified in favor of a
# version-specific path such as "/usr/lib/jvm/java-21-openjdk-21.0.5.0.10-3.el8.x86_64".
# JAVA_HOME=
# Uncomment the following line and set JAVA_HOME before installing as a service
# GHIDRA_JAVA_HOME=/usr/lib/jvm/java-21-openjdk
OPTION=$1
@@ -25,29 +36,30 @@ usage() {
adminFail() {
echo
echo "Command option \"$OPTION\" must be run as administrator (use elevated shell - see svrREADME.html)"
echo "Command option \"${OPTION}\" must be run as administrator (use elevated shell - see svrREADME.html)"
echo
exit 1
}
reportError() {
echo
echo "$1"
echo -e "ERROR: $1"
echo "Please refer to the svrREADME documentation."
echo
echo "$1" >> "${GHIDRA_HOME}/wrapper.log"
echo -e "ERROR: $1" >> "${GHIDRA_HOME}/wrapper.log"
exit 1
}
if [ "$OPTION" == "" ]; then
if [ "${OPTION}" == "" ]; then
usage
fi
if [ "$EUID" != "0" ]; then
if [ "$OPTION" == "start" ]; then adminFail
elif [ "$OPTION" == "stop" ]; then adminFail
elif [ "$OPTION" == "install" ]; then adminFail
elif [ "$OPTION" == "uninstall" ]; then adminFail
elif [ "$OPTION" == "restart" ]; then adminFail
if [ "${EUID}" != "0" ]; then
if [ "${OPTION}" == "start" ]; then adminFail
elif [ "${OPTION}" == "stop" ]; then adminFail
elif [ "${OPTION}" == "install" ]; then adminFail
elif [ "${OPTION}" == "uninstall" ]; then adminFail
elif [ "${OPTION}" == "restart" ]; then adminFail
fi
fi
@@ -55,7 +67,7 @@ APP_NAME="ghidraSvr"
APP_LONG_NAME="Ghidra Server"
MODULE_DIR="Ghidra/Features/GhidraServer"
WRAPPER_NAME_PREFIX=yajsw
SERVICE_NAME=org.rzo.yajsw.$APP_NAME
SERVICE_NAME=org.rzo.yajsw.${APP_NAME}
WRAPPER_TMPDIR="${TMPDIR:-/tmp}"
# Resolve symbolic link if present and get the directory this script lives in.
@@ -66,7 +78,7 @@ SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo
SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Ensure Ghidra path doesn't contain illegal characters
if [[ "$SCRIPT_DIR" = *"!"* ]]; then
if [[ "${SCRIPT_DIR}" = *"!"* ]]; then
echo "Ghidra path cannot contain a \"!\" character."
exit 1
fi
@@ -76,7 +88,7 @@ cd "${SCRIPT_DIR}"
SCRIPT_DIR="$(pwd)"
OS="$(uname -s)"
if [ "$OS" = "Darwin" ]; then
if [ "${OS}" = "Darwin" ]; then
OS_DIRNAME="osx64"
else
OS_DIRNAME="linux64"
@@ -117,33 +129,48 @@ if [ ! -d "${WRAPPER_HOME}" -o ! -f "${WRAPPER_HOME}/wrapper.jar" ]; then
exit 1
fi
echo "Using service wrapper: $(basename "$WRAPPER_HOME")"
echo "Using service wrapper: $(basename "${WRAPPER_HOME}")"
# Determine the Java command to use to start the JVM.
JAVA_CMD=java
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVA_CMD="$JAVA_HOME/jre/sh/java"
else
JAVA_CMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVA_CMD" ] ; then
reportError "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME"
JAVA_CMD=
if [ -n "${GHIDRA_JAVA_HOME}" ] ; then
# Identify java command from GHIDRA_JAVA_HOME
JAVA_CMD="${GHIDRA_JAVA_HOME}/bin/java"
if [ ! -x "${JAVA_CMD}" ] ; then
reportError "The ghidraSvr script GHIDRA_JAVA_HOME variable is set to an invalid directory: ${GHIDRA_JAVA_HOME}"
fi
$("${JAVA_CMD}" -cp "${LS_CPATH}" LaunchSupport "${GHIDRA_HOME}" -java_home_check "${GHIDRA_JAVA_HOME}")
if [ ! $? -eq 0 ] ; then
reportError "The ghidraSvr script GHIDRA_JAVA_HOME variable specifies an invalid or unsupported Java runtime: ${GHIDRA_JAVA_HOME}"
fi
else
JAVA_CMD="java"
which java >/dev/null 2>&1 || reportError "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH."
fi
# Identify java command from either JAVA_HOME or PATH, try PATH first
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}"
JAVA_CMD=
fi
fi
if [ "${JAVA_CMD}" == "" ]; then
reportError "The 'java' command could not be found in your PATH or with JAVA_HOME."
fi
# Get the java that will be used to launch GhidraServer
# Ensure that locally-set JAVA_HOME environment variable passes thru to LaunchSupport
LS_JAVA_HOME=$("${JAVA_CMD}" -cp "${LS_CPATH}" LaunchSupport "${GHIDRA_HOME}" -java_home)
if [ ! $? -eq 0 ] ; then
reportError "Unable to find a supported Java runtime on your system."
fi
# Get the java that will be used to launch GhidraServer
JAVA_HOME=$($JAVA_CMD -cp "${LS_CPATH}" LaunchSupport "${GHIDRA_HOME}" -java_home)
if [ ! $? -eq 0 ]; then
reportError "Failed to find a supported Java runtime. Please refer to the Ghidra Installation Guide's Troubleshooting section."
JAVA_CMD="${LS_JAVA_HOME}/bin/java"
fi
JAVA_CMD="${JAVA_HOME}/bin/java"
VMARGS=()
VMARGS+=("-Djna_tmpdir=${WRAPPER_TMPDIR}")
VMARGS+=("-Djava.io.tmpdir=${WRAPPER_TMPDIR}")
@@ -151,14 +178,14 @@ VMARGS+=("-Djava.io.tmpdir=${WRAPPER_TMPDIR}")
enableForkHack() {
# use of fork_hack only needed for Mac OS X
if [ "$OS" != "Darwin" ]; then
if [ "${OS}" != "Darwin" ]; then
return 0
fi
# watch out for revisions to the associated fork_hack comment in server.conf
# that could throw this off
HAS_FORK_HACK_LINE="$(grep "wrapper.fork_hack=" "${WRAPPER_CONF}")"
HAS_FORK_HACK_LINE=$(echo $HAS_FORK_HACK_LINE)
HAS_FORK_HACK_LINE=$(echo ${HAS_FORK_HACK_LINE})
if [ "${HAS_FORK_HACK_LINE}" = "wrapper.fork_hack=true" ]; then
return 0
fi
@@ -200,81 +227,81 @@ checkInstall() {
}
console() {
echo "Running ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -c "${WRAPPER_CONF}"
echo "Running ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -c "${WRAPPER_CONF}"
}
start() {
echo "Starting ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -t "${WRAPPER_CONF}"
echo "Starting ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -t "${WRAPPER_CONF}"
}
stopit() {
echo "Stopping ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -p "${WRAPPER_CONF}"
echo "Stopping ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -p "${WRAPPER_CONF}"
}
install() {
echo "Installing ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -i "${WRAPPER_CONF}"
echo "Installing ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -i "${WRAPPER_CONF}"
}
uninstall() {
echo "Uninstalling ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -r "${WRAPPER_CONF}"
echo "Uninstalling ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -r "${WRAPPER_CONF}"
}
status() {
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -q "${WRAPPER_CONF}"
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" wrapper_tmpdir="${WRAPPER_TMPDIR}" "${JAVA_CMD}" "${VMARGS[@]}" -jar "${WRAPPER_HOME}/wrapper.jar" -q "${WRAPPER_CONF}"
}
case "$1" in
'console')
enableForkHack
console
;;
'status')
status
;;
'console')
enableForkHack
console
;;
'status')
status
;;
'start')
checkInstall
if [ $? = 0 ]; then
start
fi
;;
'start')
checkInstall
if [ $? = 0 ]; then
start
fi
;;
'stop')
checkInstall
if [ $? = 0 ]; then
stopit
fi
;;
'stop')
checkInstall
if [ $? = 0 ]; then
stopit
fi
;;
'restart')
checkInstall
if [ $? = 0 ]; then
stopit
start
fi
;;
'restart')
checkInstall
if [ $? = 0 ]; then
stopit
start
fi
;;
'install')
enableForkHack
install
start
;;
'install')
enableForkHack
install
start
;;
'uninstall')
checkInstall
if [ $? = 0 ]; then
uninstall
fi
;;
'uninstall')
checkInstall
if [ $? = 0 ]; then
uninstall
fi
;;
*)
usage
;;
*)
usage
;;
esac

View File

@@ -1,18 +1,18 @@
#!/usr/bin/env bash
## ###
# IP: GHIDRA
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# IP: GHIDRA
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
umask 027
@@ -21,31 +21,30 @@ function showUsage() {
echo "Usage: $0 <mode> <java-type> <name> <max-memory> \"<vmarg-list>\" <app-classname> <app-args>... "
echo " <mode>: fg run as foreground process in current shell"
echo " bg run as background process in new shell"
echo " debug run as foreground process in current shell in debug mode (suspend=n)"
echo " debug-suspend run as foreground process in current shell in debug mode (suspend=y)"
echo " NOTE: for all debug modes environment variable DEBUG_ADDRESS may be set to "
echo " override default debug address of 127.0.0.1:18001"
echo " bg run as background process in new shell"
echo " debug run as foreground process in current shell in debug mode (suspend=n)"
echo " debug-suspend run as foreground process in current shell in debug mode (suspend=y)"
echo " NOTE: for all debug modes environment variable DEBUG_ADDRESS may be set to "
echo " override default debug address of 127.0.0.1:18001"
echo " <java-type>: jdk requires JDK to run"
echo " jre JRE is sufficient to run (JDK works too)"
echo " jre JRE is sufficient to run (JDK works too)"
echo " <name>: application name used for naming console window"
echo " <max-memory>: maximum memory heap size in MB (e.g., 768M or 2G). Use empty \"\" if default"
echo " should be used. This will generally be upto 1/4 of the physical memory available"
echo " to the OS."
echo " should be used. This will generally be upto 1/4 of the physical memory available"
echo " to the OS."
echo " <vmarg-list>: pass-thru args (e.g., \"-Xmx512M -Dmyvar=1 -DanotherVar=2\"). Use"
echo " empty \"\" if vmargs not needed. Spaces are not supported."
echo " empty \"\" if vmargs not needed. Spaces are not supported."
echo " <app-classname>: application classname (e.g., ghidra.GhidraRun )"
echo " <app-args>...: arguments to be passed to the application"
echo " "
echo " Example:"
echo " \"$0\" debug jdk Ghidra 4G \"\" ghidra.GhidraRun"
echo " \"$0\" debug jdk Ghidra 4G \"\" ghidra.GhidraRun"
exit 1
}
VMARGS_FROM_CALLER= # Passed in from the outer script as one long string, no spaces
VMARGS_FROM_LAUNCH_SH=() # Defined in this script, added to array
VMARGS_FROM_CALLER= # Passed in from the outer script as one long string, no spaces
VMARGS_FROM_LAUNCH_SH=() # Defined in this script, added to array
VMARGS_FROM_LAUNCH_PROPS=() # Retrieved from LaunchSupport, added to array
ARGS=()
@@ -97,7 +96,7 @@ fi
SUPPORT_DIR="${0%/*}"
# Ensure Ghidra path doesn't contain illegal characters
if [[ "$SUPPORT_DIR" = *"!"* ]]; then
if [[ "${SUPPORT_DIR}" = *"!"* ]]; then
echo "Ghidra path cannot contain a \"!\" character."
exit 1
fi
@@ -119,46 +118,61 @@ else
CPATH="${INSTALL_DIR}/Ghidra/Framework/Utility/build/libs/Utility.jar"
LS_CPATH="${INSTALL_DIR}/GhidraBuild/LaunchSupport/build/libs/LaunchSupport.jar"
if ! [ -f "${LS_CPATH}" ]; then
echo "Cannot launch from repo because Ghidra has not been compiled with Eclipse or Gradle."
echo "ERROR: Cannot launch from repo because Ghidra has not been compiled with Eclipse or Gradle."
exit 1
fi
fi
DEBUG_LOG4J="${INSTALL_DIR}/Ghidra/RuntimeScripts/Common/support/debug.log4j.xml"
fi
# Make sure some kind of java is on the path. It's required to run the LaunchSupport program.
if ! [ -x "$(command -v java)" ] ; then
echo "Java runtime not found. Please refer to the Ghidra Installation Guide's Troubleshooting section."
# Identify java command from either JAVA_HOME or PATH, try PATH first
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}"
JAVA_CMD=
fi
fi
if [ "${JAVA_CMD}" == "" ]; then
echo
echo "ERROR: The 'java' command could not be found in your PATH or with JAVA_HOME."
echo "Please refer to the Ghidra Installation Guide's Troubleshooting section."
exit 1
fi
# Get the JDK that will be used to launch Ghidra
JAVA_HOME="$(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" ${JAVA_TYPE_ARG} -save)"
LS_JAVA_HOME="$("${JAVA_CMD}" -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" ${JAVA_TYPE_ARG} -save)"
if [ ! $? -eq 0 ]; then
# If fd 0 (stdin) isn't a tty, fail because we can't prompt the user
if [ ! -t 0 ]; then
echo
echo "Unable to prompt user for JDK path, no TTY detected. Please refer to the Ghidra Installation Guide's Troubleshooting section."
echo "ERROR: Unable to prompt user for JDK path, no TTY detected."
echo "Please refer to the Ghidra Installation Guide's Troubleshooting section."
exit 1
fi
# No JDK has been setup yet. Let the user choose one.
java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" ${JAVA_TYPE_ARG} -ask
"${JAVA_CMD}" -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" ${JAVA_TYPE_ARG} -ask
# Now that the user chose one, try again to get the JDK that will be used to launch Ghidra
JAVA_HOME="$(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" ${JAVA_TYPE_ARG} -save)"
LS_JAVA_HOME="$("${JAVA_CMD}" -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" ${JAVA_TYPE_ARG} -save)"
if [ ! $? -eq 0 ]; then
echo
echo "Failed to find a supported JDK. Please refer to the Ghidra Installation Guide's Troubleshooting section."
echo "ERROR: Failed to find a supported JDK."
echo "Please refer to the Ghidra Installation Guide's Troubleshooting section."
exit 1
fi
fi
JAVA_CMD="${JAVA_HOME}/bin/java"
JAVA_CMD="${LS_JAVA_HOME}/bin/java"
# Get the configurable VM arguments from the launch properties
while IFS=$'\r\n' read -r line; do
VMARGS_FROM_LAUNCH_PROPS+=("$line")
done < <(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -vmargs)
done < <("${JAVA_CMD}" -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -vmargs)
# Add extra macOS VM arguments
if [ "$(uname -s)" = "Darwin" ]; then
@@ -194,7 +208,7 @@ elif [ "${MODE}" = "bg" ]; then
BACKGROUND=true
else
echo "Incorrect launch usage - invalid launch mode: ${MODE}"
echo "ERROR: Incorrect launch usage - invalid launch mode: ${MODE}"
exit 1
fi

View File

@@ -1,17 +1,18 @@
@echo off
rem ---------------------------------------------------------------------------------------
rem Ghidra Server Script (see svrREADME.html for usage details)
rem Usage: ghidraSvr [ console | status | install | uninstall | start | stop | restart ]
rem ---------------------------------------------------------------------------------------
:: ---------------------------------------------------------------------------------------
:: Ghidra Server Script (see svrREADME.html for usage details)
:: Usage: ghidraSvr [ console | status | install | uninstall | start | stop | restart ]
:: ---------------------------------------------------------------------------------------
rem The Java 21 (or later) runtime installation must either be on the system path or identified
rem by setting the JAVA_HOME environment variable. If not using a formally installed Java
rem runtime which has been configured into the system PATH ahead of other Java installations
rem it may be necessary to explicitly specify the path to the installation by setting JAVA_HOME
rem below:
:: The Java 21 (or later) runtime installation must either be on the system path, specified by the
:: JAVA_HOME environment variable or preferably set explicitly with the GHIDRA_JAVA_HOME variable
:: below. Since this script may be used during service initialization, reliance on environmental
:: settings such as JAVA_HOME may be problematic. It is also important to note that once installed
:: as a service, changes to this file or environmental settings may not have an affect on any service
:: registration that was generated at the time of service installation.
rem set "JAVA_HOME="
:: set "GHIDRA_JAVA_HOME="
:: Sets SERVER_DIR to the directory that contains this file (ghidraSvr.bat).
:: SERVER_DIR will not contain a trailing slash.
@@ -23,7 +24,7 @@ rem set "JAVA_HOME="
set "SERVER_DIR=%~dp0"
set "SERVER_DIR=%SERVER_DIR:~0,-1%"
rem Ensure Ghidra path doesn't contain illegal characters
:: Ensure Ghidra path doesn't contain illegal characters
if not "%SERVER_DIR:!=%"=="%SERVER_DIR%" (
echo Ghidra path cannot contain a "!" character.
exit /B 1
@@ -56,7 +57,7 @@ set IS_ADMIN=NO
whoami /groups | findstr "S-1-16-12288 " >NUL && set IS_ADMIN=YES
if "%IS_ADMIN%"=="NO" (
rem The following command options require admin
:: The following command options require admin
if "%OPTION%"=="start" goto adminFail
if "%OPTION%"=="stop" goto adminFail
if "%OPTION%"=="install" goto adminFail
@@ -72,11 +73,11 @@ set "WRAPPER_TMPDIR=%TEMP%"
if exist "%SERVER_DIR%\..\Ghidra\" goto normal
rem NOTE: If adjusting JAVA command assignment - do not attempt to add parameters (e.g., -d64, -version:1.7, etc.)
:: NOTE: If adjusting JAVA command assignment - do not attempt to add parameters (e.g., -d64, -version:1.7, etc.)
rem NOTE: Variables that get accessed in server.conf must be lowercase
:: NOTE: Variables that get accessed in server.conf must be lowercase
rem Development Environment (Eclipse classes or "gradle jar")
:: Development Environment (Eclipse classes or "gradle jar")
set "GHIDRA_HOME=%SERVER_DIR%\..\..\..\.."
set "WRAPPER_CONF=%SERVER_DIR%\..\..\Common\server\server.conf"
set "DATA_DIR=%GHIDRA_HOME%\%MODULE_DIR%\build\data"
@@ -86,7 +87,7 @@ if not exist "%LS_CPATH%" (
set "LS_CPATH=%GHIDRA_HOME%\GhidraBuild\LaunchSupport\build\libs\LaunchSupport.jar"
)
if not exist "%LS_CPATH%" (
set ERROR=ERROR: Cannot launch from repo because Ghidra has not been compiled with Eclipse or Gradle.
set ERROR=Cannot launch from repo because Ghidra has not been compiled with Eclipse or Gradle.
goto reportError
)
@@ -101,7 +102,7 @@ set "LS_CPATH=%GHIDRA_HOME%\support\LaunchSupport.jar"
:lab1
rem set WRAPPER_HOME to unpacked yajsw location (crazy FOR syntax to set variable from command output)
:: set WRAPPER_HOME to unpacked yajsw location (crazy FOR syntax to set variable from command output)
for /F "usebackq delims=" %%p in (`dir "%DATA_DIR%" /ad /b ^| findstr "^%WRAPPER_NAME_PREFIX%"`) do set WRAPPER_DIRNAME=%%p
set "WRAPPER_HOME=%DATA_DIR%\%WRAPPER_DIRNAME%"
@@ -114,34 +115,60 @@ if not exist "%WRAPPER_HOME%\" (
echo Using service wrapper: %WRAPPER_DIRNAME%
rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
:: Check for use of GHIDRA_JAVA_HOME
if not defined GHIDRA_JAVA_HOME goto findJava
set "java=%GHIDRA_JAVA_HOME%\bin\java.exe"
"%java%" -version >NUL 2>&1
if %ERRORLEVEL% neq 0 (
set ERROR=The ghidraSvr.bat script GHIDRA_JAVA_HOME variable is set to an invalid directory: %GHIDRA_JAVA_HOME%
goto reportError
)
:: Check specified GHIDRA_JAVA_HOME
"%java%" -cp "%LS_CPATH%" LaunchSupport "%GHIDRA_HOME%" -java_home_check "%GHIDRA_JAVA_HOME%"
if %ERRORLEVEL% neq 0 (
set ERROR=The ghidraSvr script GHIDRA_JAVA_HOME variable specifies an invalid or unsupported Java runtime: %GHIDRA_JAVA_HOME%
goto reportError
)
:: Bypass LaunchSupport java search when GHIDRA_JAVA_HOME is specified
goto lab3
:findJava
:: check for java based upon PATH
set java=java.exe
%java% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto lab2
set ERROR=ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
goto reportError
java.exe -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto lab2
:findJavaFromJavaHome
:: check for java based upon JAVA_HOME environment variable
if not defined JAVA_HOME goto javaNotFound
set "java=%JAVA_HOME%\bin\java.exe"
"%java%" -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto lab2
echo WARNING: JAVA_HOME environment variable is set to an invalid directory: %JAVA_HOME%
if exist "%java%" goto lab2
set ERROR=ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
:javaNotFound
set ERROR=The ghidraSvr.bat script GHIDRA_JAVA_HOME variable is not set and 'java' command could not be found in your PATH or with JAVA_HOME.
goto reportError
:: Use LaunchSupport to locate supported java runtime
:lab2
:: Get the java that will be used to launch GhidraServer
set JAVA_HOME=
for /f "delims=*" %%i in ('call "%java%" -cp "%LS_CPATH%" LaunchSupport "%GHIDRA_HOME%" -java_home') do set JAVA_HOME=%%i
if "%JAVA_HOME%" == "" (
set ERROR=Failed to find a supported Java runtime. Please refer to the Ghidra Installation Guide's Troubleshooting section.
set LS_JAVA_HOME=
for /f "delims=*" %%i in ('call "%java%" -cp "%LS_CPATH%" LaunchSupport "%GHIDRA_HOME%" -java_home') do set LS_JAVA_HOME=%%i
if "%LS_JAVA_HOME%" == "" (
set ERROR=Unable to find a supported Java runtime on your system.
goto reportError
)
rem reestablish JAVA path based upon final JAVA_HOME
set "java=%JAVA_HOME%\bin\java.exe"
:: reestablish JAVA path based upon LS_JAVA_HOME
set "java=%LS_JAVA_HOME%\bin\java.exe"
:: execute command OPTION
:lab3
set VMARGS=-Djava.io.tmpdir="%WRAPPER_TMPDIR%"
set VMARGS=%VMARGS% -Djna_tmpdir="%WRAPPER_TMPDIR%"
@@ -186,9 +213,10 @@ goto eof
:reportError
echo.
echo %ERROR%
echo ERROR: %ERROR%
echo Please refer to the svrREADME documentation.
echo.
echo %ERROR% >> %GHIDRA_HOME%\wrapper.log
echo ERROR: %ERROR% >> %GHIDRA_HOME%\wrapper.log
exit /B 1
:eof

View File

@@ -42,7 +42,7 @@ set "SUPPORT_DIR=%SUPPORT_DIR:~0,-1%"
:: Ensure Ghidra path doesn't contain illegal characters
if not "%SUPPORT_DIR:!=%"=="%SUPPORT_DIR%" (
echo Ghidra path cannot contain a "!" character.
echo ERROR: Ghidra path cannot contain a "!" character.
set ERRORLEVEL=1
goto exit1
)
@@ -73,7 +73,7 @@ IF DEFINED ARG (
)
if not "%CLASSNAME%" == "" (goto continue1)
echo Incorrect launch usage - missing argument^(s^)
echo ERROR: Incorrect launch usage - missing argument^(s^)
goto showUsage
:continue1
@@ -99,7 +99,7 @@ if not exist "%LS_CPATH%" (
set "LS_CPATH=%INSTALL_DIR%\GhidraBuild\LaunchSupport\build\libs\LaunchSupport.jar"
)
if not exist "%LS_CPATH%" (
echo Cannot launch from repo because Ghidra has not been compiled with Eclipse or Gradle.
echo ERROR: Cannot launch from repo because Ghidra has not been compiled with Eclipse or Gradle.
set ERRORLEVEL=1
goto exit1
)
@@ -112,33 +112,49 @@ if exist "%USERPROFILE%" (
set VMARG_LIST=%VMARG_LIST% -Duser.home="%USERPROFILE%"
)
:: Make sure some kind of java is on the path. It's required to run the LaunchSupport program.
java -version >nul 2>nul
if not %ERRORLEVEL% == 0 (
echo Java runtime not found. Please refer to the Ghidra Installation Guide's Troubleshooting section.
goto exit1
)
:: check for java based upon PATH
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"
"%JAVA_CMD%" -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto continue3
echo WARNING: JAVA_HOME environment variable is set to an invalid directory: %JAVA_HOME%
:javaNotFound
echo.
echo ERROR: The 'java' command could not be found in your PATH or with JAVA_HOME.
echo Please refer to the Ghidra Installation Guide's Troubleshooting section.
set ERRORLEVEL=1
goto exit1
:: Use LaunchSupport to locate supported java runtime
:continue3
:: Get the JDK that will be used to launch Ghidra
set JAVA_HOME=
for /f "delims=*" %%i in ('java -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" %JAVA_TYPE_ARG% -save') do set JAVA_HOME=%%i
if "%JAVA_HOME%" == "" (
set LS_JAVA_HOME=
for /f "delims=*" %%i in ('call "%JAVA_CMD%" -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" %JAVA_TYPE_ARG% -save') do set LS_JAVA_HOME=%%i
if "%LS_JAVA_HOME%" == "" (
:: No JDK has been setup yet. Let the user choose one.
java -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" %JAVA_TYPE_ARG% -ask
"%JAVA_CMD%" -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" %JAVA_TYPE_ARG% -ask
:: Now that the user chose one, try again to get the JDK that will be used to launch Ghidra
for /f "delims=*" %%i in ('java -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" %JAVA_TYPE_ARG% -save') do set JAVA_HOME=%%i
if "!JAVA_HOME!" == "" (
for /f "delims=*" %%i in ('call "%JAVA_CMD%" -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" %JAVA_TYPE_ARG% -save') do set LS_JAVA_HOME=%%i
if "!LS_JAVA_HOME!" == "" (
echo.
echo Failed to find a supported JDK. Please refer to the Ghidra Installation Guide's Troubleshooting section.
echo ERROR: Failed to find a supported JDK.
echo Please refer to the Ghidra Installation Guide's Troubleshooting section.
set ERRORLEVEL=1
goto exit1
)
)
set "JAVA_CMD=%JAVA_HOME%\bin\java"
set "JAVA_CMD=%LS_JAVA_HOME%\bin\java"
:: Get the configurable VM arguments from the launch properties
for /f "delims=*" %%i in ('java -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" -vmargs') do set VMARG_LIST=!VMARG_LIST! %%i
for /f "delims=*" %%i in ('call "%JAVA_CMD%" -cp "%LS_CPATH%" LaunchSupport "%INSTALL_DIR%" -vmargs') do set VMARG_LIST=!VMARG_LIST! %%i
:: Set Max Heap Size if specified
if not "%MAXMEM%"=="" (
@@ -165,22 +181,22 @@ if "%DEBUG%"=="y" (
set VMARG_LIST=!VMARG_LIST! -Dlog4j.configurationFile="!DEBUG_LOG4J!"
set VMARG_LIST=!VMARG_LIST! -agentlib:jdwp=transport=dt_socket,server=y,suspend=!SUSPEND!,address=!DEBUG_ADDRESS!
goto continue3
goto continue4
)
if "%MODE%"=="fg" (
goto continue3
goto continue4
)
if "%MODE%"=="bg" (
set BACKGROUND=y
goto continue3
goto continue4
)
echo "Incorrect launch usage - invalid launch mode: %MODE%"
echo "ERROR: Incorrect launch usage - invalid launch mode: %MODE%"
exit /B 1
:continue3
:continue4
set CMD_ARGS=%FORCE_JAVA_VERSION% %JAVA_USER_HOME_DIR_OVERRIDE% %VMARG_LIST% -cp "%CPATH%" ghidra.Ghidra %CLASSNAME% %ARGS%