Candidate release of source code.

This commit is contained in:
Dan
2019-03-26 13:45:32 -04:00
parent db81e6b3b0
commit 79d8f164f8
12449 changed files with 2800756 additions and 16 deletions
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
#----------------------------------------
# Ghidra launch
#----------------------------------------
# Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
# the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
#MAXMEM=2G
# Resolve symbolic link if present and get the directory this script lives in.
# NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD
# contains the link you are calling (which is the best we can do on macOS), and the "echo" is the
# fallback, which doesn't attempt to do anything with links.
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Launch Ghidra
"${SCRIPT_DIR}"/support/launch.sh bg Ghidra "${MAXMEM}" "" ghidra.GhidraRun "$@"
+263
View File
@@ -0,0 +1,263 @@
#! /bin/bash
#---------------------------------------------------------------------------------------
# Ghidra Server Script (see svrREADME.html for usage details)
# Usage: ghidraSvr [ console | status | install | uninstall | start | stop | restart ]
#---------------------------------------------------------------------------------------
# The Java 11 (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:
# JAVA_HOME=
OPTION=$1
usage() {
# Only display abbreviated usage (encourage use of separate install/uninstall scripts)
echo
echo "Usage: $0 { console | start | stop | restart | status }"
echo
exit 1
}
adminFail() {
echo
echo "Command option \"$OPTION\" must be run as administrator (use elevated shell - see svrREADME.html)"
echo
exit 1
}
reportError() {
echo
echo "$1"
echo
echo "$1" >> "${GHIDRA_HOME}/wrapper.log"
exit 1
}
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
fi
fi
APP_NAME="ghidraSvr"
APP_LONG_NAME="Ghidra Server"
MODULE_DIR="Ghidra/Features/GhidraServer"
WRAPPER_NAME_PREFIX=yajsw
SERVICE_NAME=org.rzo.yajsw.$APP_NAME
# Resolve symbolic link if present and get the directory this script lives in.
# NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD
# contains the link you are calling (which is the best we can do on macOS), and the "echo" is the
# fallback, which doesn't attempt to do anything with links.
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
# YAJSW likes absolute paths
cd "${SCRIPT_DIR}"
SCRIPT_DIR="$(pwd)"
OS="$(uname -s)"
if [ "$OS" = "Darwin" ]; then
OS_DIRNAME="osx64"
else
OS_DIRNAME="linux64"
fi
if [ -d "${SCRIPT_DIR}/../Ghidra" ]; then
# Production Environment
GHIDRA_HOME="${SCRIPT_DIR}/.."
WRAPPER_CONF="${SCRIPT_DIR}/server.conf"
DATA_DIR="${GHIDRA_HOME}/${MODULE_DIR}/data"
OS_DIR="${GHIDRA_HOME}/${MODULE_DIR}/os/${OS_DIRNAME}"
CLASSPATH_FRAG="${GHIDRA_HOME}/${MODULE_DIR}/data/classpath.frag"
LS_CPATH="${GHIDRA_HOME}/support/LaunchSupport.jar"
else
# Development Environment
GHIDRA_HOME="${SCRIPT_DIR}/../../../.."
WRAPPER_CONF="${SCRIPT_DIR}/../../Common/server/server.conf"
DATA_DIR="${GHIDRA_HOME}/${MODULE_DIR}/build/data"
OS_DIR="${GHIDRA_HOME}/${MODULE_DIR}/os/${OS_DIRNAME}"
CLASSPATH_FRAG="${GHIDRA_HOME}/${MODULE_DIR}/build/dev-meta/classpath.frag"
LS_CPATH="${GHIDRA_HOME}/GhidraBuild/LaunchSupport/bin/main"
fi
WRAPPER_HOME=$(find "${DATA_DIR}" -maxdepth 1 -name "${WRAPPER_NAME_PREFIX}*" -type d | head -n 1)
if [ ! -d "${WRAPPER_HOME}" -o ! -f "${WRAPPER_HOME}/wrapper.jar" ]; then
echo
echo "${WRAPPER_NAME_PREFIX} not found"
echo
exit 1
fi
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"
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
# 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."
fi
JAVA_CMD="${JAVA_HOME}/bin/java"
enableForkHack() {
# use of fork_hack only needed for Mac OS X
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)
if [ "${HAS_FORK_HACK_LINE}" = "wrapper.fork_hack=true" ]; then
return 0
fi
if [ "${HAS_FORK_HACK_LINE}" = "" ]; then
echo "ERROR: server.conf does not have fork_hack line - unable to fix it!"
return 1
fi
# Enable fork_hack in server.conf
ed "${WRAPPER_CONF}" <<EOF > /dev/null
/wrapper.fork_hack=
d
i
wrapper.fork_hack=true
wrapper.posix_spawn=false
.
w
q
EOF
HAS_FORK_HACK_LINE=$(grep "^wrapper.fork_hack=true" "${WRAPPER_CONF}")
if [ "${HAS_FORK_HACK_LINE}" = "" ]; then
echo "ERROR: failed to install fork_hack in server.conf"
return 1
fi
return 0
}
checkInstall() {
# capture status text
RESULT=$(java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" os_dir="${OS_DIR}" "${JAVA_CMD}" -jar "${WRAPPER_HOME}/wrapper.jar" -q "${WRAPPER_CONF}" | grep "Installed :" | sed -E "s/Installed : //")
if [ "${RESULT}" = "true" ]; then
return 0
fi
echo "ERROR: ${APP_NAME} service is not installed"
return 1
}
console() {
echo "Running ${APP_LONG_NAME}..."
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" os_dir="${OS_DIR}" "${JAVA_CMD}" -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}" os_dir="${OS_DIR}" "${JAVA_CMD}" -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}" os_dir="${OS_DIR}" "${JAVA_CMD}" -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}" os_dir="${OS_DIR}" "${JAVA_CMD}" -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}" os_dir="${OS_DIR}" "${JAVA_CMD}" -jar "${WRAPPER_HOME}/wrapper.jar" -r "${WRAPPER_CONF}"
}
status() {
java="${JAVA_CMD}" ghidra_home="${GHIDRA_HOME}" classpath_frag="${CLASSPATH_FRAG}" os_dir="${OS_DIR}" "${JAVA_CMD}" -jar "${WRAPPER_HOME}/wrapper.jar" -q "${WRAPPER_CONF}"
}
case "$1" in
'console')
enableForkHack
console
;;
'status')
status
;;
'start')
checkInstall
if [ $? = 0 ]; then
start
fi
;;
'stop')
checkInstall
if [ $? = 0 ]; then
stopit
fi
;;
'restart')
checkInstall
if [ $? = 0 ]; then
stopit
start
fi
;;
'install')
enableForkHack
install
start
;;
'uninstall')
checkInstall
if [ $? = 0 ]; then
uninstall
fi
;;
*)
usage
;;
esac
+82
View File
@@ -0,0 +1,82 @@
#!/bin/bash
# ***********************************************************
# ** Arguments (each -argument option may be repeated):
# ** [-add <sid>] [-remove <sid>] [-reset <sid>] [-dn <sid> "<x500_distinguished_name>"]
# ** [-admin <sid> "<repository-name>"] [-list] [-migrate "<repository-name>"] [-migrate-all]
# **
# ** add - add a new user to the server with the default password 'changeme'
# ** remove - remove an existing user from the server
# ** reset - reset an existing user's password to 'changeme'
# ** dn - set a user's distinguished name for PKI authentication
# ** admin - set the specified existing user as an admin of the specified repository
# ** list - list all existing named repositories
# ** migrate - migrate the specified named repository to an indexed data storage
# ** migrate-all - migrate all named repositories to index data storage
# ***********************************************************
UMASK=027
# Preserve quoted arguments
ARGS=()
WHITESPACE="[[:space:]]"
for AA in "$@"; do
if [[ $AA =~ $WHITESPACE ]]; then
AA="\"$AA\""
fi
ARGS[${#ARGS[@]}]=$AA
done
# Resolve symbolic link if present and get the directory this script lives in.
# NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD
# contains the link you are calling (which is the best we can do on macOS), and the "echo" is the
# fallback, which doesn't attempt to do anything with links.
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
if [ -d "${SCRIPT_DIR}/../Ghidra" ]; then
# Production Environment
CONFIG="${SCRIPT_DIR}/server.conf"
GHIDRA_DIR="${SCRIPT_DIR}/../Ghidra"
CPATH="${GHIDRA_DIR}/Features/GhidraServer/lib/GhidraServer.jar:${GHIDRA_DIR}/Framework/FileSystem/lib/FileSystem.jar:${GHIDRA_DIR}/Framework/DB/lib/DB.jar:${GHIDRA_DIR}/Framework/Generic/lib/Generic.jar:${GHIDRA_DIR}/Framework/Utility/lib/Utility.jar:${GHIDRA_DIR}/Framework/Generic/lib/log4j-core-2.8.1.jar:${GHIDRA_DIR}/Framework/Generic/lib/log4j-api-2.8.1.jar"
LS_CPATH="${GHIDRA_DIR}/../support/LaunchSupport.jar"
else
# Development Environment
CONFIG="${SCRIPT_DIR}/../../Common/server/server.conf"
GHIDRA_DIR="${SCRIPT_DIR}/../../.."
GHIDRA_BIN_REPO="${GHIDRA_DIR}/../../ghidra.bin"
CPATH="${GHIDRA_DIR}/Features/GhidraServer/bin/main:${GHIDRA_DIR}/Framework/FileSystem/bin/main:${GHIDRA_DIR}/Framework/DB/bin/main:${GHIDRA_DIR}/Framework/Generic/bin/main:${GHIDRA_DIR}/Framework/Utility/bin/main:${GHIDRA_BIN_REPO}/ExternalLibraries/libsForRuntime/log4j-core-2.8.1.jar:${GHIDRA_BIN_REPO}/ExternalLibraries/libsForRuntime/log4j-api-2.8.1.jar"
LS_CPATH="${GHIDRA_DIR}/../GhidraBuild/LaunchSupport/bin/main"
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."
exit 1
fi
# Get the java that will be used to launch GhidraServer
JAVA_HOME=$(java -cp "${LS_CPATH}" LaunchSupport "${GHIDRA_DIR}/.." -java_home)
if [ ! $? -eq 0 ]; then
echo "Failed to find a supported Java runtime. Please refer to the Ghidra Installation Guide's Troubleshooting section."
exit 1
fi
JAVA_CMD="${JAVA_HOME}/bin/java"
VMARGS="-DUserAdmin.invocation=$(basename "${SCRIPT_FILE}") -DUserAdmin.config=\"${CONFIG}\""
OLD_UMASK=$(umask)
umask $UMASK
# Identify server process owner if set within server.conf
OWNER="$(grep '^wrapper.app.account=' "${CONFIG}" | sed -e 's/^.*=\(.*\)\s*.*$/\1/')"
if [ -z "${OWNER}" -o "${OWNER}" = "$(whoami)" ]; then
eval "\"${JAVA_CMD}\" ${VMARGS} -cp \"${CPATH}\" ghidra.server.UserAdmin ${ARGS[@]}"
else
echo "Running svrAdmin with sudo as ${OWNER} ..."
eval "sudo -u "${OWNER}" \"${JAVA_CMD}\" ${VMARGS} -cp \"${CPATH}\" ghidra.server.UserAdmin ${ARGS[@]}"
fi
umask $OLD_UMASK
+43
View File
@@ -0,0 +1,43 @@
#!/bin/bash
OS=`uname -s`
SCRIPT_DIR=`echo $0 | sed -e 's/[^\/]*$//'`
pushd $SCRIPT_DIR > /dev/null
SCRIPT_DIR=`pwd`
SFILE=$SCRIPT_DIR/ghidraSvr
if [ ! -x $SFILE ]; then
CHECK_FILE_PERM=`file $SFILE | grep 'Permission'`
if [ "$CHECK_FILE_PERM" != "" ]; then
echo "Ghidra Server file permissions prevent installation (see svrREADME.html)";
elif [ -e $SFILE ]; then
echo "Ghidra Server startup script $SFILE must be executable!";
else
echo "Ghidra Server startup script $SFILE not found!";
fi
exit 1
fi
success=1;
if [ "$OS" = "Linux" ]; then
$SFILE install
success=$?
elif [ "$OS" = "Darwin" ]; then
$SFILE install
success=$?
fi
popd > /dev/null
if [ $success -eq 0 ]; then
echo "Successfully installed Ghidra Server."
$SFILE start
exit $?
else
echo "Failed to install Ghidra Server!"
exit 1
fi
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
OS=`uname -s`
SCRIPT_DIR=`echo $0 | sed -e 's/[^\/]*$//'`
pushd $SCRIPT_DIR > /dev/null
SCRIPT_DIR=`pwd`
SFILE=$SCRIPT_DIR/ghidraSvr
success=1;
if [ "$OS" = "Linux" ]; then
$SFILE uninstall
success=$?
elif [ "$OS" = "Darwin" ]; then
$SFILE uninstall
success=$?
fi
popd > /dev/null
if [ $success -eq 0 ]; then
echo "Successfully uninstalled Ghidra Server."
exit 0
else
echo "Failed to uninstall Ghidra Server!"
exit 1
fi
+33
View File
@@ -0,0 +1,33 @@
#!/bin/bash
#----------------------------------------------------------------------
# Ghidra Headless Analyzer launch (see analyzeHeadlessREADME.html)
#----------------------------------------------------------------------
# Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
# the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
MAXMEM=2G
# Launch mode can be changed to one of the following: fg, debug, debug-suspend
LAUNCH_MODE=fg
# Set the debug address to listen on.
# NOTE: This variable is ignored if not launching in a debugging mode.
DEBUG_ADDRESS=127.0.0.1:13002
# Limit the # of garbage collection and JIT compiler threads in case many headless
# instances are run in parallel. By default, Java will assign one thread per core
# which does not scale well on servers with many cores.
VMARG_LIST="-XX:ParallelGCThreads=2 "
VMARG_LIST+="-XX:CICompilerCount=2 "
# Resolve symbolic link if present and get the directory this script lives in.
# NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD
# contains the link you are calling (which is the best we can do on macOS), and the "echo" is the
# fallback, which doesn't attempt to do anything with links.
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Launch HeadlessAnalyzer.
# DEBUG_ADDRESS set via environment for launch.sh
DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" Ghidra-Headless "${MAXMEM}" "${VMARG_LIST}" ghidra.app.util.headless.AnalyzeHeadless "$@"
+31
View File
@@ -0,0 +1,31 @@
#!/bin/bash
#----------------------------------------
# Build a Ghidra jar
#----------------------------------------
# Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
# the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
#MAXMEM=2G
# Launch mode can be changed to one of the following: fg, debug, debug-suspend
LAUNCH_MODE=fg
# Resolve symbolic link if present and get the directory this script lives in.
# NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD
# contains the link you are calling (which is the best we can do on macOS), and the "echo" is the
# fallback, which doesn't attempt to do anything with links.
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
GHIDRA_ROOT_DIR="${SCRIPT_DIR}"/../Ghidra
if [ ! -d "${GHIDRA_ROOT_DIR}" ]; then
echo "This script does not support development mode use"
exit 1
fi
# Set required VMARGS for jar builder application
APP_VMARGS="-DGhidraJarBuilder.Name=$(basename "${SCRIPT_FILE}") -DGhidra.Install.Root.Dir=\"${GHIDRA_ROOT_DIR}\" "
# Launch jar builder
"${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" Ghidra "${MAXMEM}" "${APP_VMARGS}" ghidra.util.GhidraJarBuilder -main ghidra.JarRun "$@"
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
#----------------------------------------
# Ghidra Filesystem Conversion launch
#----------------------------------------
# Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
# the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
MAXMEM=128M
# Resolve symbolic link if present and get the directory this script lives in.
# NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD
# contains the link you are calling (which is the best we can do on macOS), and the "echo" is the
# fallback, which doesn't attempt to do anything with links.
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Launch Filesystem Conversion
"${SCRIPT_DIR}"/launch.sh fg ConvertStorage "${MAXMEM}" "" ghidra.framework.data.ConvertFileSystem "$@"
+26
View File
@@ -0,0 +1,26 @@
#!/bin/bash
#----------------------------------------
# Ghidra Debug Thread Dumper launch
#----------------------------------------
# This script will only work if Ghidra is running in debug mode (i.e., launched from
# ghidraDebug shell script).
# Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
# the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
MAXMEM=64M
# Resolve symbolic link if present and get the directory this script lives in.
# NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD
# contains the link you are calling (which is the best we can do on macOS), and the "echo" is the
# fallback, which doesn't attempt to do anything with links.
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Assumes application is utilizing debug port 18001 (change if needed)
# NOTE: By default, ghidraDebug uses debug port 18001 and analyzeHeadless uses 13002
# Launch Thread Dumper
"${SCRIPT_DIR}"/launch.sh fg ThreadDump "${MAXMEM}" "" util.DebugThreadDumper 18001
read -p "Press Enter to continue..."
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
#----------------------------------------
# Ghidra debug launch
#----------------------------------------
# Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
# the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
#MAXMEM=2G
# Debug launch mode can be changed to one of the following: debug, debug-suspend
LAUNCH_MODE=debug
# Set the debug address to listen on.
# NOTE: This variable is ignored if not launching in a debugging mode.
DEBUG_ADDRESS=127.0.0.1:18001
# Resolve symbolic link if present and get the directory this script lives in.
# NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD
# contains the link you are calling (which is the best we can do on macOS), and the "echo" is the
# fallback, which doesn't attempt to do anything with links.
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Launch Ghidra in debug mode
# DEBUG_ADDRESS set via environment for launch.sh
DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" Ghidra "${MAXMEM}" "" ghidra.GhidraRun "$@"
+185
View File
@@ -0,0 +1,185 @@
#!/bin/bash
umask 027
function showUsage() {
echo "Usage: $0 <mode> <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 " <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 " <vmarg-list>: pass-thru args (e.g., \"-Xmx512M -Dmyvar=1 -DanotherVar=2\") - use"
echo " empty \"\" if vmargs not needed"
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 Ghidra 768M \"\" ghidra.GhidraRun"
exit 1
}
VMARG_LIST=
ARGS=()
INDEX=0
WHITESPACE="[[:space:]]"
for AA in "$@"
do
INDEX=$(expr $INDEX + 1)
case "$INDEX" in
1)
MODE=$AA
;;
2)
APPNAME=$AA
;;
3)
MAXMEM=$AA
;;
4)
if [ "$AA" != "" ]; then
VMARG_LIST=$AA
fi
;;
5)
CLASSNAME=$AA
;;
*)
# Preserve quoted arguments
if [[ $AA =~ $WHITESPACE ]]; then
AA="\"$AA\""
fi
ARGS[${#ARGS[@]}]=$AA
;;
esac
done
# Verify that required number of args were provided
if [[ ${INDEX} -lt 5 ]]; then
echo "Incorrect launch usage - missing argument(s)"
showUsage
exit 1
fi
SUPPORT_DIR="${0%/*}"
if [ -f "${SUPPORT_DIR}/launch.properties" ]; then
# Production Environment
INSTALL_DIR="${SUPPORT_DIR}/.."
CPATH="${INSTALL_DIR}/Ghidra/Framework/Utility/lib/Utility.jar"
LS_CPATH="${SUPPORT_DIR}/LaunchSupport.jar"
DEBUG_LOG4J="${SUPPORT_DIR}/debug.log4j.xml"
else
# Development Environment
INSTALL_DIR="${SUPPORT_DIR}/../../../.."
CPATH="${INSTALL_DIR}/Ghidra/Framework/Utility/bin/main"
LS_CPATH="${INSTALL_DIR}/GhidraBuild/LaunchSupport/bin/main"
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."
exit 1
fi
# Get the JDK that will be used to launch Ghidra
JAVA_HOME="$(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -jdk_home -save)"
if [ ! $? -eq 0 ]; then
# No JDK has been setup yet. Let the user choose one.
java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -jdk_home -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}" -jdk_home -save)"
if [ ! $? -eq 0 ]; then
echo
echo "Failed to find a supported JDK. Please refer to the Ghidra Installation Guide's Troubleshooting section."
exit 1
fi
fi
JAVA_CMD="${JAVA_HOME}/bin/java"
# Get the configurable VM arguments from the launch properties
VMARG_LIST+=" $(java -cp "${LS_CPATH}" LaunchSupport "${INSTALL_DIR}" -vmargs)"
# Add extra macOS VM arguments
if [ "$(uname -s)" = "Darwin" ]; then
VMARG_LIST+=" -Xdock:name=${APPNAME}"
VMARG_LIST+=" -Xdock:icon=\"${INSTALL_DIR}/Ghidra/Features/Base/os/osx64/ghidra.icns\""
# Eclipse on macOS (Darwin) can have file locking issues if the user home directory is
# networked. Therefore, we will disable file locking by default for macOS. Comment the
# following line out if Eclipse file locking is needed and known to work.
VMARG_LIST+=" -Declipse.filelock.disable=true"
fi
# Add extra Linux VM arguments
if [ "$(uname -s)" = "Linux" ]; then
VMARG_LIST+=" -Dawt.useSystemAAFontSettings=on"
fi
# Set Max Heap Size if specified
if [ "${MAXMEM}" != "" ]; then
VMARG_LIST+=" -Xmx${MAXMEM}"
fi
BACKGROUND=false
if [ "${MODE}" = "debug" ] || [ "${MODE}" = "debug-suspend" ]; then
SUSPEND=n
if [ "${DEBUG_ADDRESS}" = "" ]; then
DEBUG_ADDRESS=127.0.0.1:18001
fi
if [ "${MODE}" = "debug-suspend" ]; then
SUSPEND=y
fi
VMARG_LIST+=" -Xdebug"
VMARG_LIST+=" -Xnoagent"
VMARG_LIST+=" -Djava.compiler=NONE"
VMARG_LIST+=" -Dlog4j.configuration=\"${DEBUG_LOG4J}\""
VMARG_LIST+=" -Xrunjdwp:transport=dt_socket,server=y,suspend=${SUSPEND},address=${DEBUG_ADDRESS}"
elif [ "${MODE}" = "fg" ]; then
:
elif [ "${MODE}" = "bg" ]; then
BACKGROUND=true
else
echo "Incorrect launch usage - invalid launch mode: ${MODE}"
exit 1
fi
if [ "${BACKGROUND}" = true ]; then
eval "\"${JAVA_CMD}\" ${VMARG_LIST} -showversion -cp \"${CPATH}\" ghidra.GhidraLauncher ${CLASSNAME} ${ARGS[@]}" &>/dev/null &
# If our process dies immediately, output something so the user knows to run in debug mode.
# Otherwise they'll never see any error output from background mode.
# Doing a kill -0 sends a no-op signal, which can be used to see if the process is still alive.
PID=$!
sleep 1
if ! kill -0 ${PID} &>/dev/null; then
echo "Exited with error. Run in foreground (fg) mode for more details."
exit 1
fi
exit 0
else
eval "\"${JAVA_CMD}\" ${VMARG_LIST} -showversion -cp \"${CPATH}\" ghidra.GhidraLauncher ${CLASSNAME} ${ARGS[@]}"
exit $?
fi
+36
View File
@@ -0,0 +1,36 @@
#!/bin/bash
#----------------------------------------
# Ghidra Python launch
#----------------------------------------
# Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
# the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
#MAXMEM=2G
# Launch mode can be changed to one of the following: fg, debug, debug-suspend
LAUNCH_MODE=fg
# Set the debug address to listen on.
# NOTE: This variable is ignored if not launching in a debugging mode.
DEBUG_ADDRESS=127.0.0.1:13002
# Limit the # of garbage collection and JIT compiler threads in case many python
# instances are run in parallel. By default, Java will assign one thread per core
# which does not scale well on servers with many cores.
VMARG_LIST="-XX:ParallelGCThreads=2 "
VMARG_LIST+="-XX:CICompilerCount=2 "
# Prevent the shell losing focus when Ghidra initializes
VMARG_LIST+="-Djava.awt.headless=true "
# Resolve symbolic link if present and get the directory this script lives in.
# NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD
# contains the link you are calling (which is the best we can do on macOS), and the "echo" is the
# fallback, which doesn't attempt to do anything with links.
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
# Launch Ghidra Python
# DEBUG_ADDRESS set via environment for launch.sh
DEBUG_ADDRESS=${DEBUG_ADDRESS} "${SCRIPT_DIR}"/launch.sh "${LAUNCH_MODE}" "Ghidra-Python" "${MAXMEM}" "${VMARG_LIST}" ghidra.python.PythonRun "$@"
+18
View File
@@ -0,0 +1,18 @@
#!/bin/bash
#----------------------------------------
# Ghidra Sleigh language compiler launch
#----------------------------------------
# Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
# the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
#MAXMEM=1G
# Resolve symbolic link if present and get the directory this script lives in.
# NOTE: "readlink -f" is best but works on Linux only, "readlink" will only work if your PWD
# contains the link you are calling (which is the best we can do on macOS), and the "echo" is the
# fallback, which doesn't attempt to do anything with links.
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
"${SCRIPT_DIR}"/launch.sh fg Sleigh "$MAXMEM" "" ghidra.pcodeCPort.slgh_compile.SleighCompileLauncher "$@"