mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
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:
parent
61096c5fdf
commit
95b37d2ce1
10 changed files with 47 additions and 65 deletions
|
@ -20,6 +20,7 @@ import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.jar.*;
|
import java.util.jar.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.*;
|
import java.util.zip.*;
|
||||||
|
|
||||||
import generic.jar.*;
|
import generic.jar.*;
|
||||||
|
@ -44,7 +45,6 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
||||||
private static final String LIBS_FILE_MODULE_KEY = "Module: ";
|
private static final String LIBS_FILE_MODULE_KEY = "Module: ";
|
||||||
|
|
||||||
// this is set in the buildGhidraJar batch/script files
|
// 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 final String INVOCATION_NAME_PROPERTY = "GhidraJarBuilder.Name";
|
||||||
private static HashMap<String, List<String>> libsMap = new HashMap<>();
|
private static HashMap<String, List<String>> libsMap = new HashMap<>();
|
||||||
private List<File> rootGhidraDirs = new ArrayList<>();
|
private List<File> rootGhidraDirs = new ArrayList<>();
|
||||||
|
@ -961,14 +961,10 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
||||||
System.err.println("arg " + i + ": " + args[i]);
|
System.err.println("arg " + i + ": " + args[i]);
|
||||||
}
|
}
|
||||||
String invocationName = System.getProperty(INVOCATION_NAME_PROPERTY);
|
String invocationName = System.getProperty(INVOCATION_NAME_PROPERTY);
|
||||||
String property = System.getProperty(GHIDRA_DIR);
|
|
||||||
|
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
buf.append("\nUsage: ");
|
buf.append("\nUsage: ");
|
||||||
buf.append(invocationName != null ? invocationName : "GhidraJarBuilder ");
|
buf.append(invocationName != null ? invocationName : "GhidraJarBuilder ");
|
||||||
if (property == null) {
|
|
||||||
buf.append("<Installation Root Directory> [<Installation Root Directory> ...] ");
|
|
||||||
}
|
|
||||||
buf.append(
|
buf.append(
|
||||||
" [-output <output file>] [-srczip <src zip output file>] [-bin <compiled classes dir>] [-main <main-class>]\n");
|
" [-output <output file>] [-srczip <src zip output file>] [-bin <compiled classes dir>] [-main <main-class>]\n");
|
||||||
System.err.println(buf.toString());
|
System.err.println(buf.toString());
|
||||||
|
@ -992,18 +988,16 @@ public class GhidraJarBuilder implements GhidraLaunchable {
|
||||||
usage(args);
|
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 outputFile = null;
|
||||||
File srczip = null;
|
File srczip = null;
|
||||||
File extraBinDir = null;
|
File extraBinDir = null;
|
||||||
String mainClassArg = null;
|
String mainClassArg = null;
|
||||||
boolean usingGradle = false;
|
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++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
String arg = args[i];
|
String arg = args[i];
|
||||||
if (arg.equals("-output")) {
|
if (arg.equals("-output")) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class ServerAdmin implements GhidraLaunchable {
|
||||||
* The following properties may be set:
|
* The following properties may be set:
|
||||||
* <pre>
|
* <pre>
|
||||||
* UserAdmin.invocation - identifies the name of the application used when displaying usage text.
|
* 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>
|
* </pre>
|
||||||
* @param args command line arguments
|
* @param args command line arguments
|
||||||
*/
|
*/
|
||||||
|
@ -75,22 +75,19 @@ public class ServerAdmin implements GhidraLaunchable {
|
||||||
* The following properties may be set:
|
* The following properties may be set:
|
||||||
* <pre>
|
* <pre>
|
||||||
* UserAdmin.invocation - identifies the name of the application used when displaying usage text.
|
* 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>
|
* </pre>
|
||||||
* @param args command line arguments
|
* @param args command line arguments
|
||||||
*/
|
*/
|
||||||
public void execute(String[] args) {
|
public void execute(String[] args) {
|
||||||
|
|
||||||
File serverDir = null;
|
File serverDir = null;
|
||||||
|
|
||||||
int ix = 0;
|
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) {
|
if (serverDir == null || (args.length - ix) == 0) {
|
||||||
displayUsage("");
|
displayUsage("");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
|
@ -423,13 +420,12 @@ public class ServerAdmin implements GhidraLaunchable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getServerDirFromConfig() {
|
private File getServerDirFromConfig(String configFilePath) {
|
||||||
String p = System.getProperty(CONFIG_FILE_PROPERTY);
|
if (configFilePath == null) {
|
||||||
if (p == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
propertyUsed = true;
|
|
||||||
File configFile = new File(p);
|
File configFile = new File(configFilePath);
|
||||||
|
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
System.out.println("Config file not found: " + configFile.getAbsolutePath());
|
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) {
|
if (p == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 it may be necessary to explicitly specify the path to the installation by setting JAVA_HOME
|
||||||
rem below:
|
rem below:
|
||||||
|
|
||||||
rem set JAVA_HOME=
|
rem set "JAVA_HOME="
|
||||||
|
|
||||||
setlocal enabledelayedexpansion
|
setlocal enabledelayedexpansion
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ if "%IS_ADMIN%"=="NO" (
|
||||||
|
|
||||||
rem Find the script directory
|
rem Find the script directory
|
||||||
rem %~dsp0 is location of current script under NT
|
rem %~dsp0 is location of current script under NT
|
||||||
set _REALPATH=%~dp0
|
set "_REALPATH=%~dp0"
|
||||||
|
|
||||||
set APP_NAME=ghidraSvr
|
set APP_NAME=ghidraSvr
|
||||||
set APP_LONG_NAME=Ghidra Server
|
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 NOTE: If adjusting JAVA command assignment - do not attempt to add parameters (e.g., -d64, -version:1.7, etc.)
|
||||||
|
|
||||||
rem Development Environment
|
rem Development Environment
|
||||||
set GHIDRA_HOME=%_REALPATH%..\..\..\..
|
set "GHIDRA_HOME=%_REALPATH%..\..\..\.."
|
||||||
set WRAPPER_CONF=%_REALPATH%..\..\Common\server\server.conf
|
set "WRAPPER_CONF=%_REALPATH%..\..\Common\server\server.conf"
|
||||||
set DATA_DIR=%GHIDRA_HOME%\%MODULE_DIR%\build\data
|
set "DATA_DIR=%GHIDRA_HOME%\%MODULE_DIR%\build\data"
|
||||||
set CLASSPATH_FRAG=%GHIDRA_HOME%\%MODULE_DIR%\build\dev-meta\classpath.frag
|
set "CLASSPATH_FRAG=%GHIDRA_HOME%\%MODULE_DIR%\build\dev-meta\classpath.frag"
|
||||||
set LS_CPATH=%GHIDRA_HOME%\GhidraBuild\LaunchSupport\bin\main
|
set "LS_CPATH=%GHIDRA_HOME%\GhidraBuild\LaunchSupport\bin\main"
|
||||||
|
|
||||||
goto lab1
|
goto lab1
|
||||||
|
|
||||||
:normal
|
:normal
|
||||||
set GHIDRA_HOME=%_REALPATH%..
|
set "GHIDRA_HOME=%_REALPATH%.."
|
||||||
set WRAPPER_CONF=%_REALPATH%server.conf
|
set "WRAPPER_CONF=%_REALPATH%server.conf"
|
||||||
set DATA_DIR=%GHIDRA_HOME%\%MODULE_DIR%\data
|
set "DATA_DIR=%GHIDRA_HOME%\%MODULE_DIR%\data"
|
||||||
set CLASSPATH_FRAG=%GHIDRA_HOME%\%MODULE_DIR%\data\classpath.frag
|
set "CLASSPATH_FRAG=%GHIDRA_HOME%\%MODULE_DIR%\data\classpath.frag"
|
||||||
set LS_CPATH=%GHIDRA_HOME%\support\LaunchSupport.jar
|
set "LS_CPATH=%GHIDRA_HOME%\support\LaunchSupport.jar"
|
||||||
|
|
||||||
:lab1
|
:lab1
|
||||||
|
|
||||||
rem set WRAPPER_HOME to unpacked yajsw location (crazy FOR syntax to set variable from command output)
|
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
|
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%\" (
|
if not exist "%WRAPPER_HOME%\" (
|
||||||
echo.
|
echo.
|
||||||
|
@ -104,8 +104,8 @@ set ERROR=ERROR: JAVA_HOME is not set and no 'java' command could be found in yo
|
||||||
goto reportError
|
goto reportError
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
:findJavaFromJavaHome
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
set "JAVA_HOME=%JAVA_HOME:"=%"
|
||||||
set JAVA=%JAVA_HOME%\bin\java.exe
|
set "JAVA=%JAVA_HOME%\bin\java.exe"
|
||||||
|
|
||||||
if exist "%JAVA%" goto lab2
|
if exist "%JAVA%" goto lab2
|
||||||
set ERROR=ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
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
|
rem reestablish JAVA path based upon final JAVA_HOME
|
||||||
set JAVA=%JAVA_HOME%\bin\java.exe
|
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 DEBUG=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:18888
|
:: set DEBUG=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:18888
|
||||||
|
|
||||||
|
|
|
@ -31,18 +31,18 @@ set MAXMEM=128M
|
||||||
:: '% ~' dereferences the value in param 0
|
:: '% ~' dereferences the value in param 0
|
||||||
:: 'd' - drive
|
:: 'd' - drive
|
||||||
:: 'p' - path (without filename)
|
:: 'p' - path (without filename)
|
||||||
set SCRIPT_DIR=%~dp0
|
set "SCRIPT_DIR=%~dp0"
|
||||||
|
|
||||||
:: Production Environment
|
:: Production Environment
|
||||||
set CONFIG=%SCRIPT_DIR%.\server.conf
|
set "CONFIG=%SCRIPT_DIR%.\server.conf"
|
||||||
|
|
||||||
if exist "%CONFIG%" goto continue
|
if exist "%CONFIG%" goto continue
|
||||||
|
|
||||||
:: Development Environment
|
:: Development Environment
|
||||||
set CONFIG=%SCRIPT_DIR%..\..\Common\server\server.conf
|
set "CONFIG=%SCRIPT_DIR%..\..\Common\server\server.conf"
|
||||||
|
|
||||||
:continue
|
: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%" %*
|
||||||
|
|
|
@ -3,7 +3,7 @@ setlocal
|
||||||
|
|
||||||
rem Find the script directory
|
rem Find the script directory
|
||||||
rem %~dsp0 is location of current script under NT
|
rem %~dsp0 is location of current script under NT
|
||||||
set _REALPATH=%~dp0
|
set "_REALPATH=%~dp0"
|
||||||
|
|
||||||
call "%_REALPATH%\ghidraSvr" install
|
call "%_REALPATH%\ghidraSvr" install
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ setlocal
|
||||||
|
|
||||||
rem Find the script directory
|
rem Find the script directory
|
||||||
rem %~dsp0 is location of current script under NT
|
rem %~dsp0 is location of current script under NT
|
||||||
set _REALPATH=%~dp0
|
set "_REALPATH=%~dp0"
|
||||||
|
|
||||||
call "%_REALPATH%\ghidraSvr" uninstall
|
call "%_REALPATH%\ghidraSvr" uninstall
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ set VMARG_LIST=-XX:ParallelGCThreads=2
|
||||||
set VMARG_LIST=%VMARG_LIST% -XX:CICompilerCount=2
|
set VMARG_LIST=%VMARG_LIST% -XX:CICompilerCount=2
|
||||||
|
|
||||||
:: store current path
|
:: store current path
|
||||||
set filepath=%~dp0
|
set "filepath=%~dp0"
|
||||||
|
|
||||||
:: Loop through parameters (if there aren't any, just continue) and store
|
:: Loop through parameters (if there aren't any, just continue) and store
|
||||||
:: in params variable.
|
:: in params variable.
|
||||||
|
|
|
@ -8,9 +8,9 @@ setlocal
|
||||||
set LAUNCH_MODE=fg
|
set LAUNCH_MODE=fg
|
||||||
|
|
||||||
:: Sets SCRIPT_DIR to the directory that contains this file (ends with '\')
|
:: 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
|
if exist "%GHIDRA_ROOT_DIR%" goto continue
|
||||||
|
|
||||||
echo This script does not support development mode use
|
echo This script does not support development mode use
|
||||||
|
|
|
@ -11,16 +11,16 @@
|
||||||
setlocal
|
setlocal
|
||||||
|
|
||||||
REM Get parent of current folder
|
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
|
set OS_DIR=os
|
||||||
|
|
||||||
REM Production Environment
|
REM Production Environment
|
||||||
if exist "%GHIDRA_DIR%" goto continue
|
if exist "%GHIDRA_DIR%" goto continue
|
||||||
|
|
||||||
REM Development Environment
|
REM Development Environment
|
||||||
set GHIDRA_DIR=%SCRIPT_DIR%..\..\..
|
set "GHIDRA_DIR=%SCRIPT_DIR%..\..\.."
|
||||||
set OS_DIR=build\os
|
set OS_DIR=build\os
|
||||||
|
|
||||||
:continue
|
:continue
|
||||||
|
@ -35,7 +35,7 @@ if exist "%PROGRAMFILES(X86)%" (
|
||||||
set OS_TYPE=win32
|
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%" (
|
if not exist "%PDB_EXE%" (
|
||||||
echo "%PDB_EXE% not found"
|
echo "%PDB_EXE% not found"
|
||||||
|
|
|
@ -26,6 +26,6 @@ set VMARG_LIST=-XX:ParallelGCThreads=2
|
||||||
set VMARG_LIST=%VMARG_LIST% -XX:CICompilerCount=2
|
set VMARG_LIST=%VMARG_LIST% -XX:CICompilerCount=2
|
||||||
|
|
||||||
:: store current path
|
:: store current path
|
||||||
set filepath=%~dp0
|
set "filepath=%~dp0"
|
||||||
|
|
||||||
call "%filepath%launch.bat" %LAUNCH_MODE% Ghidra-Python "%MAXMEM%" "%VMARG_LIST%" ghidra.python.PythonRun %params%
|
call "%filepath%launch.bat" %LAUNCH_MODE% Ghidra-Python "%MAXMEM%" "%VMARG_LIST%" ghidra.python.PythonRun %params%
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue