fix(tools/reversing): tolerate extra Ghidra fields; brace-safe script templates; drop dead return#422
Open
VoidChecksum wants to merge 2 commits into
Open
fix(tools/reversing): tolerate extra Ghidra fields; brace-safe script templates; drop dead return#422VoidChecksum wants to merge 2 commits into
VoidChecksum wants to merge 2 commits into
Conversation
… templates; drop dead return
ghidra.py: real-world Ghidra MCP/headless output includes keys beyond
the five in GhidraFunction (e.g. thunk, namespace). Constructing
GhidraFunction(**f) would raise TypeError on any such dict. Added
_GHIDRA_FUNC_KEYS (frozenset derived from dataclasses.fields) and
filter each dict to known keys before unpacking. Applied to both the
MCP path and the headless path in ghidra_analyze_binary.
scripts.py: ghidra_recon_script and r2_recon_script called .format()
with caller-supplied binary/script_name. A path containing { or }
raised KeyError/ValueError. Replaced .format() with chained .replace()
calls so untrusted content is never treated as a format spec. The
emitted script text is identical for normal paths.
tools.py: bin_r2_script had two identical consecutive return statements;
the second was unreachable dead code. Removed the duplicate.
tests: added test_reversing_robustness.py covering all three fixes with
no real binary or Ghidra instance required.
…cript Folds in the crash fix from #395: the Ghidra recon template iterated 'for a in f.getEntryPoint()', but Function.getEntryPoint() returns a single non-iterable Address, so the generated script raised at runtime. The line was also dead (addrs unused). Removes it; the entry point is still printed. Adds a regression test. Consolidates #395 into this PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GhidraFunction(**f)crashed withTypeErrorwhen Ghidra MCP/headless JSON included keys beyond the dataclass's five fields (e.g.thunk,namespace). Added_GHIDRA_FUNC_KEYS = frozenset(f.name for f in dataclasses.fields(GhidraFunction))and filter each dict to known keys before unpacking — applied to both the MCP path and the headless path inghidra_analyze_binary.ghidra_recon_script/r2_recon_scriptcalled.format()with caller-suppliedbinaryandscript_name. A path containing{or}raisedKeyError/ValueError. Replaced.format()with chained.replace()calls; emitted script text is identical for normal paths.bin_r2_scripthad two consecutive identicalreturnstatements; the second was unreachable dead code. Removed the duplicate.Test plan
TestGhidraFunctionExtraKeys.test_extra_keys_do_not_raise— constructsGhidraFunctionfrom a dict with extra keys (thunk,namespace, unknown field); asserts no raise and known fields populatedTestGhidraFunctionExtraKeys.test_ghidra_analysis_with_extra_function_fields— exercises the full list-comprehension path inghidra_analyze_binarywith extra-keyed dictsTestScriptsBracePath.test_ghidra_recon_script_brace_in_binary— binary path/tmp/{evil}/target{x}does not raiseTestScriptsBracePath.test_r2_recon_script_brace_in_binary— same for r2 templateTestScriptsBracePath.test_scripts_normal_path_preserved— normal paths still appear in outputTestBinR2ScriptNoDeadReturn.test_returns_json_with_source_key—bin_r2_scriptreturns valid JSON withsourcekeyuv run pytest packages/decepticon/tests/unit/reversing -q→ 36 passed