GP-693: Fixed additional issues with Ghidra and its supporting launch

scripts not being able to run correctly on Windows when an ampersand was
in the path. Also fixed an issue with svrAdmin.bat and
buildGhidraJar.bat not working if the Ghidra path contained a space.
This commit is contained in:
Ryan Kurtz 2021-02-19 10:46:20 -05:00
parent 61096c5fdf
commit 95b37d2ce1
10 changed files with 47 additions and 65 deletions

View file

@ -20,6 +20,7 @@ import java.nio.file.Path;
import java.util.*;
import java.util.jar.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.*;
import generic.jar.*;
@ -44,7 +45,6 @@ public class GhidraJarBuilder implements GhidraLaunchable {
private static final String LIBS_FILE_MODULE_KEY = "Module: ";
// this is set in the buildGhidraJar batch/script files
private static final String GHIDRA_DIR = "Ghidra.Install.Root.Dir";
private static final String INVOCATION_NAME_PROPERTY = "GhidraJarBuilder.Name";
private static HashMap<String, List<String>> libsMap = new HashMap<>();
private List<File> rootGhidraDirs = new ArrayList<>();
@ -961,14 +961,10 @@ public class GhidraJarBuilder implements GhidraLaunchable {
System.err.println("arg " + i + ": " + args[i]);
}
String invocationName = System.getProperty(INVOCATION_NAME_PROPERTY);
String property = System.getProperty(GHIDRA_DIR);
StringBuffer buf = new StringBuffer();
buf.append("\nUsage: ");
buf.append(invocationName != null ? invocationName : "GhidraJarBuilder ");
if (property == null) {
buf.append("<Installation Root Directory> [<Installation Root Directory> ...] ");
}
buf.append(
" [-output <output file>] [-srczip <src zip output file>] [-bin <compiled classes dir>] [-main <main-class>]\n");
System.err.println(buf.toString());
@ -992,18 +988,16 @@ public class GhidraJarBuilder implements GhidraLaunchable {
usage(args);
}
List<File> ghidraDirs = new ArrayList<>();
List<File> ghidraDirs = layout.getApplicationRootDirs()
.stream()
.map(f -> f.getFile(false))
.collect(Collectors.toCollection(ArrayList::new));
File outputFile = null;
File srczip = null;
File extraBinDir = null;
String mainClassArg = null;
boolean usingGradle = false;
String property = System.getProperty(GHIDRA_DIR);
if (property != null) {
ghidraDirs.add(new File(property));
}
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if (arg.equals("-output")) {

View file

@ -52,7 +52,7 @@ public class ServerAdmin implements GhidraLaunchable {
* The following properties may be set:
* <pre>
* UserAdmin.invocation - identifies the name of the application used when displaying usage text.
* UserAdmin.serverDir - identifies the server directory instead of passing on command line.
* UserAdmin.config - identifies the config file instead of passing on command line.
* </pre>
* @param args command line arguments
*/
@ -75,22 +75,19 @@ public class ServerAdmin implements GhidraLaunchable {
* The following properties may be set:
* <pre>
* UserAdmin.invocation - identifies the name of the application used when displaying usage text.
* UserAdmin.serverDir - identifies the server directory instead of passing on command line.
* UserAdmin.config - identifies the config file instead of passing on command line.
* </pre>
* @param args command line arguments
*/
public void execute(String[] args) {
File serverDir = null;
int ix = 0;
if (args.length != 0 && !args[0].startsWith("-")) {
serverDir = new File(args[ix++]);
}
else {
serverDir = getServerDirFromConfig();
}
String configFilePath = args.length != 0 && !args[0].startsWith("-") ? args[ix++]
: System.getProperty(CONFIG_FILE_PROPERTY);
serverDir = getServerDirFromConfig(configFilePath);
if (serverDir == null || (args.length - ix) == 0) {
displayUsage("");
System.exit(-1);
@ -423,13 +420,12 @@ public class ServerAdmin implements GhidraLaunchable {
}
}
private File getServerDirFromConfig() {
String p = System.getProperty(CONFIG_FILE_PROPERTY);
if (p == null) {
private File getServerDirFromConfig(String configFilePath) {
if (configFilePath == null) {
return null;
}
propertyUsed = true;
File configFile = new File(p);
File configFile = new File(configFilePath);
if (!configFile.exists()) {
System.out.println("Config file not found: " + configFile.getAbsolutePath());
@ -455,7 +451,7 @@ public class ServerAdmin implements GhidraLaunchable {
}
}
p = config.getProperty(SERVER_DIR_CONFIG_PROPERTY);
String p = config.getProperty(SERVER_DIR_CONFIG_PROPERTY);
if (p == null) {
return null;
}

View file

@ -11,7 +11,7 @@ rem runtime which has been configured into the system PATH ahead of other Java
rem it may be necessary to explicitly specify the path to the installation by setting JAVA_HOME
rem below:
rem set JAVA_HOME=
rem set "JAVA_HOME="
setlocal enabledelayedexpansion
@ -50,7 +50,7 @@ if "%IS_ADMIN%"=="NO" (
rem Find the script directory
rem %~dsp0 is location of current script under NT
set _REALPATH=%~dp0
set "_REALPATH=%~dp0"
set APP_NAME=ghidraSvr
set APP_LONG_NAME=Ghidra Server
@ -64,26 +64,26 @@ if exist "%_REALPATH%..\Ghidra\" goto normal
rem NOTE: If adjusting JAVA command assignment - do not attempt to add parameters (e.g., -d64, -version:1.7, etc.)
rem Development Environment
set GHIDRA_HOME=%_REALPATH%..\..\..\..
set WRAPPER_CONF=%_REALPATH%..\..\Common\server\server.conf
set DATA_DIR=%GHIDRA_HOME%\%MODULE_DIR%\build\data
set CLASSPATH_FRAG=%GHIDRA_HOME%\%MODULE_DIR%\build\dev-meta\classpath.frag
set LS_CPATH=%GHIDRA_HOME%\GhidraBuild\LaunchSupport\bin\main
set "GHIDRA_HOME=%_REALPATH%..\..\..\.."
set "WRAPPER_CONF=%_REALPATH%..\..\Common\server\server.conf"
set "DATA_DIR=%GHIDRA_HOME%\%MODULE_DIR%\build\data"
set "CLASSPATH_FRAG=%GHIDRA_HOME%\%MODULE_DIR%\build\dev-meta\classpath.frag"
set "LS_CPATH=%GHIDRA_HOME%\GhidraBuild\LaunchSupport\bin\main"
goto lab1
:normal
set GHIDRA_HOME=%_REALPATH%..
set WRAPPER_CONF=%_REALPATH%server.conf
set DATA_DIR=%GHIDRA_HOME%\%MODULE_DIR%\data
set CLASSPATH_FRAG=%GHIDRA_HOME%\%MODULE_DIR%\data\classpath.frag
set LS_CPATH=%GHIDRA_HOME%\support\LaunchSupport.jar
set "GHIDRA_HOME=%_REALPATH%.."
set "WRAPPER_CONF=%_REALPATH%server.conf"
set "DATA_DIR=%GHIDRA_HOME%\%MODULE_DIR%\data"
set "CLASSPATH_FRAG=%GHIDRA_HOME%\%MODULE_DIR%\data\classpath.frag"
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)
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%
set "WRAPPER_HOME=%DATA_DIR%\%WRAPPER_DIRNAME%"
if not exist "%WRAPPER_HOME%\" (
echo.
@ -104,8 +104,8 @@ set ERROR=ERROR: JAVA_HOME is not set and no 'java' command could be found in yo
goto reportError
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA=%JAVA_HOME%\bin\java.exe
set "JAVA_HOME=%JAVA_HOME:"=%"
set "JAVA=%JAVA_HOME%\bin\java.exe"
if exist "%JAVA%" goto lab2
set ERROR=ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@ -122,15 +122,7 @@ if "%JAVA_HOME%" == "" (
)
rem reestablish JAVA path based upon final JAVA_HOME
set JAVA=%JAVA_HOME%\bin\java.exe
set OS_NAME=win32
"%JAVA%" -version 2>&1 | findstr /I " 64-Bit " >NUL
if errorlevel 0 (
set OS_NAME=win64
)
set OS_DIR=%GHIDRA_HOME%\%MODULE_DIR%\os\%OS_NAME%
set "JAVA=%JAVA_HOME%\bin\java.exe"
:: set DEBUG=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:18888

View file

@ -31,18 +31,18 @@ set MAXMEM=128M
:: '% ~' dereferences the value in param 0
:: 'd' - drive
:: 'p' - path (without filename)
set SCRIPT_DIR=%~dp0
set "SCRIPT_DIR=%~dp0"
:: Production Environment
set CONFIG=%SCRIPT_DIR%.\server.conf
set "CONFIG=%SCRIPT_DIR%.\server.conf"
if exist "%CONFIG%" goto continue
:: Development Environment
set CONFIG=%SCRIPT_DIR%..\..\Common\server\server.conf
set "CONFIG=%SCRIPT_DIR%..\..\Common\server\server.conf"
:continue
set VMARGS=-DUserAdmin.invocation="%0" -DUserAdmin.config="%CONFIG%"
set VMARGS=-DUserAdmin.invocation="%0"
call "%~dp0\..\support\launch.bat" fg svrAdmin "%MAXMEM%" "%VMARGS%" ghidra.server.ServerAdmin %*
call "%~dp0\..\support\launch.bat" fg svrAdmin "%MAXMEM%" "%VMARGS%" ghidra.server.ServerAdmin "%CONFIG%" %*

View file

@ -3,7 +3,7 @@ setlocal
rem Find the script directory
rem %~dsp0 is location of current script under NT
set _REALPATH=%~dp0
set "_REALPATH=%~dp0"
call "%_REALPATH%\ghidraSvr" install

View file

@ -3,7 +3,7 @@ setlocal
rem Find the script directory
rem %~dsp0 is location of current script under NT
set _REALPATH=%~dp0
set "_REALPATH=%~dp0"
call "%_REALPATH%\ghidraSvr" uninstall

View file

@ -24,7 +24,7 @@ set VMARG_LIST=-XX:ParallelGCThreads=2
set VMARG_LIST=%VMARG_LIST% -XX:CICompilerCount=2
:: store current path
set filepath=%~dp0
set "filepath=%~dp0"
:: Loop through parameters (if there aren't any, just continue) and store
:: in params variable.

View file

@ -8,9 +8,9 @@ setlocal
set LAUNCH_MODE=fg
:: Sets SCRIPT_DIR to the directory that contains this file (ends with '\')
set SCRIPT_DIR=%~dp0
set "SCRIPT_DIR=%~dp0"
set GHIDRA_ROOT_DIR=%SCRIPT_DIR%..\Ghidra
set "GHIDRA_ROOT_DIR=%SCRIPT_DIR%..\Ghidra"
if exist "%GHIDRA_ROOT_DIR%" goto continue
echo This script does not support development mode use

View file

@ -11,16 +11,16 @@
setlocal
REM Get parent of current folder
set SCRIPT_DIR=%~dp0
set "SCRIPT_DIR=%~dp0"
set GHIDRA_DIR=%SCRIPT_DIR%..\Ghidra
set "GHIDRA_DIR=%SCRIPT_DIR%..\Ghidra"
set OS_DIR=os
REM Production Environment
if exist "%GHIDRA_DIR%" goto continue
REM Development Environment
set GHIDRA_DIR=%SCRIPT_DIR%..\..\..
set "GHIDRA_DIR=%SCRIPT_DIR%..\..\.."
set OS_DIR=build\os
:continue
@ -35,7 +35,7 @@ if exist "%PROGRAMFILES(X86)%" (
set OS_TYPE=win32
)
set PDB_EXE=%GHIDRA_DIR%\Features\PDB\%OS_DIR%\%OS_TYPE%\pdb.exe
set "PDB_EXE=%GHIDRA_DIR%\Features\PDB\%OS_DIR%\%OS_TYPE%\pdb.exe"
if not exist "%PDB_EXE%" (
echo "%PDB_EXE% not found"

View file

@ -26,6 +26,6 @@ set VMARG_LIST=-XX:ParallelGCThreads=2
set VMARG_LIST=%VMARG_LIST% -XX:CICompilerCount=2
:: store current path
set filepath=%~dp0
set "filepath=%~dp0"
call "%filepath%launch.bat" %LAUNCH_MODE% Ghidra-Python "%MAXMEM%" "%VMARG_LIST%" ghidra.python.PythonRun %params%