This commit is contained in:
Ryan Kurtz 2024-11-18 11:00:12 -05:00
parent 4cbc94d960
commit 69d6495b60
2 changed files with 40 additions and 2 deletions

View File

@ -107,6 +107,7 @@ public class VSCodeProjectScript extends GhidraScript {
File settingsFile = new File(vscodeDir, "settings.json"); File settingsFile = new File(vscodeDir, "settings.json");
String gradleVersion = Application String gradleVersion = Application
.getApplicationProperty(ApplicationProperties.APPLICATION_GRADLE_MIN_PROPERTY); .getApplicationProperty(ApplicationProperties.APPLICATION_GRADLE_MIN_PROPERTY);
String pythonInterpreterPath = System.getProperty("pyghidra.sys.prefix", null);
// Build settings json object // Build settings json object
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
@ -138,6 +139,9 @@ public class VSCodeProjectScript extends GhidraScript {
json.addProperty("python.analysis.stubPath", json.addProperty("python.analysis.stubPath",
new File(installDir, "docs/ghidra_stubs/typestubs").getAbsolutePath()); new File(installDir, "docs/ghidra_stubs/typestubs").getAbsolutePath());
if (pythonInterpreterPath != null) {
json.addProperty("python.defaultInterpreterPath", pythonInterpreterPath);
}
// Write settings json object // Write settings json object
if (!FileUtilities.mkdirs(settingsFile.getParentFile())) { if (!FileUtilities.mkdirs(settingsFile.getParentFile())) {
@ -183,6 +187,8 @@ public class VSCodeProjectScript extends GhidraScript {
json.addProperty("version", "0.2.0"); json.addProperty("version", "0.2.0");
JsonArray configurationsArray = new JsonArray(); JsonArray configurationsArray = new JsonArray();
json.add("configurations", configurationsArray); json.add("configurations", configurationsArray);
// Ghidra launcher
JsonObject ghidraConfigObject = new JsonObject(); JsonObject ghidraConfigObject = new JsonObject();
configurationsArray.add(ghidraConfigObject); configurationsArray.add(ghidraConfigObject);
ghidraConfigObject.addProperty("type", "java"); ghidraConfigObject.addProperty("type", "java");
@ -198,6 +204,33 @@ public class VSCodeProjectScript extends GhidraScript {
vmArgsArray.add("-Dghidra.external.modules=${workspaceFolder}"); vmArgsArray.add("-Dghidra.external.modules=${workspaceFolder}");
vmArgs.forEach(vmArgsArray::add); vmArgs.forEach(vmArgsArray::add);
// PyGhidra launcher
JsonObject pyghidraConfigObject = new JsonObject();
configurationsArray.add(pyghidraConfigObject);
pyghidraConfigObject.addProperty("type", "debugpy");
pyghidraConfigObject.addProperty("name", "PyGhidra");
pyghidraConfigObject.addProperty("request", "launch");
pyghidraConfigObject.addProperty("module", "pyghidra.ghidra_launch");
pyghidraConfigObject.addProperty("args", GhidraRun.class.getName());
JsonArray argsArray = new JsonArray();
pyghidraConfigObject.add("args", argsArray);
argsArray.add("--install-dir");
argsArray.add(installDir.getAbsolutePath());
argsArray.add("-g");
argsArray.add(GhidraRun.class.getName());
JsonObject envObject = new JsonObject();
pyghidraConfigObject.add("env", envObject);
envObject.addProperty("PYGHIDRA_DEBUG", "1");
// PyGhidra Java Attach
JsonObject pyghidraAttachObject = new JsonObject();
configurationsArray.add(pyghidraAttachObject);
pyghidraAttachObject.addProperty("type", "java");
pyghidraAttachObject.addProperty("name", "PyGhidra Java Attach");
pyghidraAttachObject.addProperty("request", "attach");
pyghidraAttachObject.addProperty("hostName", "localhost");
pyghidraAttachObject.addProperty("port", 18001);
// Write launch json object // Write launch json object
if (!FileUtilities.mkdirs(launchFile.getParentFile())) { if (!FileUtilities.mkdirs(launchFile.getParentFile())) {
throw new IOException("Failed to create: " + launchFile.getParentFile()); throw new IOException("Failed to create: " + launchFile.getParentFile());

View File

@ -216,14 +216,19 @@ class PyGhidraLauncher:
raise Exception("org.eclipse.jdt.launching.VM_ARGUMENTS not found") raise Exception("org.eclipse.jdt.launching.VM_ARGUMENTS not found")
def _jvm_args(self) -> List[str]: def _jvm_args(self) -> List[str]:
properties = [
f"-Dpyghidra.sys.prefix={sys.prefix}",
f"-Dpyghidra.sys.executable={sys.executable}"
]
if self._dev_mode and self._java_home: if self._dev_mode and self._java_home:
return self._parse_dev_args() return properties + self._parse_dev_args()
suffix = "_" + platform.system().upper() suffix = "_" + platform.system().upper()
if suffix == "_DARWIN": if suffix == "_DARWIN":
suffix = "_MACOS" suffix = "_MACOS"
option_pattern: re.Pattern = re.compile(fr"VMARGS(?:{suffix})?=(.+)") option_pattern: re.Pattern = re.compile(fr"VMARGS(?:{suffix})?=(.+)")
properties = []
root = self._install_dir root = self._install_dir