Ghidra is a software reverse engineering (SRE) framework
GP-6021: PyGhidra stdout/stderr scripting console fixes
Ryan Kurtz951f5a5daa02
diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.pyindex fd5bc6ce8d..385b63bfbd 100644--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py@@ -658,6 +658,7 @@ class _PyGhidraStdOut:def __init__(self, stream):self._stream = stream+ self.is_error = stream == sys.stderrdef _get_current_script(self) -> "PyGhidraScript":for entry in inspect.stack():@@ -668,7 +669,7 @@ class _PyGhidraStdOut:def flush(self):script = self._get_current_script()if script is not None:- writer = script._script.writer+ writer = script._script.errorWriter if self.is_error else script._script.writerif writer is not None:writer.flush()return@@ -678,7 +679,7 @@ class _PyGhidraStdOut:def write(self, s: str) -> int:script = self._get_current_script()if script is not None:- writer = script._script.writer+ writer = script._script.errorWriter if self.is_error else script._script.writerif writer is not None:writer.write(s)return len(s)diff --git a/Ghidra/Features/PyGhidra/support/pyghidra_launcher.py b/Ghidra/Features/PyGhidra/support/pyghidra_launcher.pyindex 8f1c302020..acb9572601 100644--- a/Ghidra/Features/PyGhidra/support/pyghidra_launcher.py+++ b/Ghidra/Features/PyGhidra/support/pyghidra_launcher.py@@ -279,11 +279,11 @@ def main() -> None:# Launch PyGhidrasave_python_cmd(install_dir, python_cmd, args.dev)- py_args: List[str] = python_cmd + ['-m', 'pyghidra.ghidra_launch', '--install-dir', str(install_dir)]+ py_args: List[str] = python_cmd + ['-m']if args.headless:- py_args += ['ghidra.app.util.headless.AnalyzeHeadless']+ py_args += ['pyghidra.ghidra_launch', '--install-dir', str(install_dir), 'ghidra.app.util.headless.AnalyzeHeadless']else:- py_args += ['-g', 'ghidra.GhidraRun']+ py_args += ['pyghidra', '-g', '--install-dir', str(install_dir)]if args.console:subprocess.call(py_args + remaining)else: