ワンクリックで
pyghidra
Use when writing Python scripts that read disassembly, read decompilation output, or modify Ghidra program state using PyGhidra.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Use when writing Python scripts that read disassembly, read decompilation output, or modify Ghidra program state using PyGhidra.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | pyghidra |
| description | Use when writing Python scripts that read disassembly, read decompilation output, or modify Ghidra program state using PyGhidra. |
scripts/apply_analysis_json_to_ghidra.py.For scripts that mutate the Ghidra database, open the program through PyGhidra's normal project/program context:
import pyghidra
# Start the JVM (once per process)
pyghidra.start()
# Open a project and program
project = pyghidra.open_project("/path/to/project_dir", "project_name")
with pyghidra.program_context(project, "/program_name") as program:
# work with program here
pass
For read-only scripts, open the Ghidra project read-only. PyGhidra's
open_project() wrapper does not currently expose this option; use the
underlying Ghidra project manager:
import pyghidra
def open_read_only_project(project_path, project_name):
from ghidra.framework.model import ProjectLocator
from ghidra.pyghidra import PyGhidraProjectManager
project_locator = ProjectLocator(str(project_path), project_name)
project_manager = PyGhidraProjectManager()
return project_manager.openProject(project_locator, True, False)
pyghidra.start()
project = open_read_only_project("/path/to/project_dir", "project_name")
with pyghidra.program_context(project, "/program_name") as program:
# read-only inspection here
pass
All writes to the program state must be wrapped in a transaction:
with pyghidra.transaction(program, "Rename variables"):
# any writes here
pass
DecompInterface, call openProgram(), then decompileFunction(func, timeout, monitor)result.getDecompiledFunction().getC() returns the C pseudocode as a stringresult.getHighFunction() returns the structured HighFunction representationdecomp.dispose() when doneprogram.getListing() returns the listing used to inspect instructions and datalisting.getInstructionAt(address) gets one instruction at an addresslisting.getInstructions(address_set_view, True) iterates instructions forward over a function body or address setinstruction.getFallThrough() and instruction.getReferencesFrom() when following control flow beyond a simple sequential dumpSee examples/iterate_functions.py.
func_mgr.getFunctions(True) iterates all functionsfunc_mgr.getFunctionContaining(address_space.getAddress(0x1234)) finds a function by addressSee examples/rename_variables.py.
hf.getLocalSymbolMap().getSymbols() to inspect candidate locals, including their storage via symbol.getStorage()HighFunctionDBUtil.updateDBVariable(sym, new_name, new_type, SourceType.USER_DEFINED) inside a transactionHighFunction is stale — re-decompile to get updated namesSee examples/rename_parameters.py.
sym_map.getParamSymbol(i) to access parameters by indexHighFunctionDBUtil.commitParamsToDatabase() to commit all params at onceSee examples/commit_locals.py.
HighFunctionDBUtil.commitLocalNamesToDatabase(hf, SourceType.USER_DEFINED) persists all local variable namesSee examples/create_struct.py.
StructureDataType("Name", 0, dtm), add fields with .add(type, size, name, comment)dtm.resolve(s, DataTypeConflictHandler.REPLACE_HANDLER)REPLACE_HANDLER to overwrite existing types; use DEFAULT_HANDLER to keep existingSee examples/apply_datatype.py.
dtm.getDataType("/MyStruct") or use the resolved object from creationHighFunctionDBUtil.updateDBVariable(sym, None, resolved_type, SourceType.USER_DEFINED)When a decompiler local is really multiple lifetimes merged into one HighVariable, use
/Users/phulin/Documents/Projects/reaper/scripts/split_ghidra_variable.py
instead of hand-rolling the merge-group logic each time.
--pc-address and --representative filters.HighFunction.splitOutMergeGroup() and can optionally rename both the original and split variables, then saves and re-decompiles to confirm persistence.--merge-group plus either --symbol-name or --storage.--storage; name-based selection is mainly a convenience for one-off interactive useSee examples/lookup_datatypes.py.
dtm.getDataType("/CategoryName/TypeName")dtm.findDataTypes("MyStruct", results)IntegerDataType, PointerDataType, etc.) can be imported directly from ghidra.program.model.datapyghidra.transaction(program, ...) context.PyGhidraProjectManager().openProject(project_locator, True, False) for scripts that only inspect disassembly, decompilation, functions, symbols, data types, or bytes.HighFunctionDBUtil write, the HighFunction object is stale — call decompileFunction() again to get fresh results.open_program() is deprecated; use open_project() + program_context() instead.HighFunctionDBUtil.updateDBVariable() can flush all parameters if a type inconsistency is detected (not just the one you renamed).DataTypeConflictHandler.REPLACE_HANDLER replaces an existing type with the same name; use DEFAULT_HANDLER to keep the existing one.