GP-5637: The ghidra_script() function now accepts an optional

"script_args" parameter
This commit is contained in:
Ryan Kurtz
2025-07-15 06:13:06 -04:00
parent 7d26a65e31
commit 295f71472a

View File

@@ -15,7 +15,7 @@
##
import sys
import contextlib
from typing import Union, TYPE_CHECKING, Tuple, Callable, Any
from typing import Union, TYPE_CHECKING, Tuple, List, Callable, Any
from pyghidra.converters import * # pylint: disable=wildcard-import, unused-wildcard-import
@@ -155,6 +155,7 @@ def ghidra_script(
path: Union[str, Path],
project: "Project",
program: "Program" = None,
script_args: List[str] = [],
echo_stdout = True,
echo_stderr = True
) -> Tuple[str, str]:
@@ -164,6 +165,7 @@ def ghidra_script(
:param path: The GhidraScript's path.
:param project: The Ghidra project to run the GhidraScript in.
:param program: An optional Ghidra program that the GhidraScript will see as its "currentProgram".
:param script_args An optional list of arguments to pass to the GhidraScript.
:param echo_stdout: Whether or not to echo the GhidraScript's standard output.
:param echo_stderr: Whether or not to echo the GhidraScript's standard error.
:return: A 2 element tuple consisting of the GhidraScript's standard output and standard error.
@@ -192,6 +194,7 @@ def ghidra_script(
PrintWriter(stderr_string_writer, True),
dummy_monitor()
)
script.setScriptArgs(script_args)
script.execute(state, controls)
stdout_str = str(stdout_string_writer)
stderr_str = str(stderr_string_writer)