Ghidra is a software reverse engineering (SRE) framework
GP-4876: JShell launcher for Ghidra
Dan42b73252f152
diff --git a/Ghidra/Features/Base/.launch/JShell.launch b/Ghidra/Features/Base/.launch/JShell.launchnew file mode 100644index 0000000000..c657097019--- /dev/null+++ b/Ghidra/Features/Base/.launch/JShell.launch@@ -0,0 +1,34 @@+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">+ <stringAttribute key="bad_container_name" value="/_Ghidra Support/eclipse"/>+ <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">+ <listEntry value="/Framework Utility/src/main/java/ghidra/Ghidra.java"/>+ </listAttribute>+ <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">+ <listEntry value="1"/>+ </listAttribute>+ <mapAttribute key="org.eclipse.debug.core.preferred_launchers">+ <mapEntry key="[debug]" value="org.eclipse.jdt.launching.localJavaApplication"/>+ <mapEntry key="[run]" value="org.eclipse.jdt.launching.localJavaApplication"/>+ </mapAttribute>+ <stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>+ <stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sourceLookupDirector> <sourceContainers duplicates="false"> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;classpathContainer path=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot;/&gt;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.classpathContainer"/> </sourceContainers> </sourceLookupDirector> "/>+ <listAttribute key="org.eclipse.debug.ui.favoriteGroups">+ <listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>+ <listEntry value="org.eclipse.debug.ui.launchGroup.run"/>+ </listAttribute>+ <booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>+ <booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>+ <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>+ <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>+ <listAttribute key="org.eclipse.jdt.launching.CLASSPATH">+ <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry path="5" projectName="Framework Utility" type="1"/> "/>+ </listAttribute>+ <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>+ <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="ghidra.Ghidra"/>+ <listAttribute key="org.eclipse.jdt.launching.MODULEPATH"/>+ <stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="Framework Utility"/>+ <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="ghidra.JShellRun"/>+ <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Framework Utility"/>+ <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XX:+IgnoreUnrecognizedVMOptions -Djava.system.class.loader=ghidra.GhidraClassLoader -Xshare:off -Dfile.encoding=UTF8 -Duser.country=US -Duser.language=en -Dsun.java2d.pmoffscreen=false -Dsun.java2d.xrender=true -Dsun.java2d.d3d=false -Xdock:name="Ghidra" -Dvisualvm.display.name=Ghidra -Dpython.console.encoding=UTF-8"/>+</launchConfiguration>diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifestindex 8f6c07bb61..c053587a20 100644--- a/Ghidra/Features/Base/certification.manifest+++ b/Ghidra/Features/Base/certification.manifest@@ -12,6 +12,7 @@.launch/Ghidra Code Coverage.launch||GHIDRA||||END|.launch/Ghidra.launch||GHIDRA||||END|.launch/Headless.launch||GHIDRA||||END|+.launch/JShell.launch||GHIDRA||||END|Module.manifest||GHIDRA||||END|data/ElfFunctionsThatDoNotReturn||GHIDRA||||END|data/ExtensionPoint.manifest||GHIDRA||||END|diff --git a/Ghidra/Features/Base/src/main/java/ghidra/JShellRun.java b/Ghidra/Features/Base/src/main/java/ghidra/JShellRun.javanew file mode 100644index 0000000000..c8ccbf5afb--- /dev/null+++ b/Ghidra/Features/Base/src/main/java/ghidra/JShellRun.java@@ -0,0 +1,49 @@+/* ###+ * 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.+ */+package ghidra;++import java.util.ArrayList;+import java.util.Arrays;+import java.util.stream.Stream;++import ghidra.framework.*;+import jdk.jshell.tool.JavaShellToolBuilder;++public class JShellRun implements GhidraLaunchable {+ @Override+ public void launch(GhidraApplicationLayout layout, String[] args) throws Exception {+ if (Stream.of(args).anyMatch(a -> a.startsWith("--execution"))) {+ System.err.println("Ignoring --execution option. Overridden to local");+ }++ ArrayList<String> fullArgs = new ArrayList<>();+ fullArgs.addAll(Arrays.asList(args));++ ApplicationConfiguration configuration;+ if (fullArgs.remove("--headless")) {+ configuration = new HeadlessGhidraApplicationConfiguration();+ }+ else {+ GhidraApplicationConfiguration gac = new GhidraApplicationConfiguration();+ gac.setShowSplashScreen(false);+ configuration = gac;+ }+ Application.initializeApplication(layout, configuration);++ fullArgs.add("--execution=local");+ JavaShellToolBuilder.builder().start(fullArgs.toArray(String[]::new));+ }+}diff --git a/Ghidra/RuntimeScripts/Linux/support/jshellRun b/Ghidra/RuntimeScripts/Linux/support/jshellRunnew file mode 100755index 0000000000..c9a5a1a3f8--- /dev/null+++ b/Ghidra/RuntimeScripts/Linux/support/jshellRun@@ -0,0 +1,19 @@+#!/usr/bin/env bash++#----------------------------------------+# Ghidra JShell 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}"/launch.sh fg jdk Ghidra-JShell "${MAXMEM}" "" ghidra.JShellRun "$@"diff --git a/Ghidra/RuntimeScripts/Windows/support/jshellRun.bat b/Ghidra/RuntimeScripts/Windows/support/jshellRun.batnew file mode 100644index 0000000000..37238450c0--- /dev/null+++ b/Ghidra/RuntimeScripts/Windows/support/jshellRun.bat@@ -0,0 +1,11 @@+:: Ghidra JShell launch++@echo off+setlocal++:: 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.+::set MAXMEM=2G++call "%~dp0launch.bat" fg jdk Ghidra-JShell "%MAXMEM%" "" ghidra.JShellRun %*+diff --git a/Ghidra/RuntimeScripts/certification.manifest b/Ghidra/RuntimeScripts/certification.manifestindex be6ade10e3..860d43bd8e 100644--- a/Ghidra/RuntimeScripts/certification.manifest+++ b/Ghidra/RuntimeScripts/certification.manifest@@ -26,6 +26,7 @@ Linux/support/convertStorage||GHIDRA||||END|Linux/support/gdbGADPServerRun||GHIDRA||||END|Linux/support/ghidraClean||GHIDRA||||END|Linux/support/ghidraDebug||GHIDRA||||END|+Linux/support/jshellRun||GHIDRA||||END|Linux/support/pythonRun||GHIDRA||||END|Linux/support/sleigh||GHIDRA||||END|Windows/ghidraRun.bat||GHIDRA||||END|@@ -45,6 +46,7 @@ Windows/support/dbgmodelGADPServerRun.bat||GHIDRA||||END|Windows/support/ghidra.ico||GHIDRA||||END|Windows/support/ghidraClean.bat||GHIDRA||||END|Windows/support/ghidraDebug.bat||GHIDRA||||END|+Windows/support/jshellRun.bat||GHIDRA||||END|Windows/support/launch.bat||GHIDRA||||END|Windows/support/pythonRun.bat||GHIDRA||||END|Windows/support/sleigh.bat||GHIDRA||||END|