Repository navigation
feat(ghidra): define function-pointer members and typedefs - #14889
Conversation
define_native_data_types refused every parenthesis in a definition, so vtables, ops tables and callback structs could not be defined. Admit ret (*name)(parameters) as a struct or union member or a typedef, with (**name), (*name[N]) and a calling convention written before the parenthesis. Ghidra 12.2 stores these as written. The tokenizer still refuses, at its position, every form Ghidra stores differently: an empty parameter list (stored as (void)), a calling convention inside the parenthesis, _Noreturn, a nested function-pointer parameter, grouped declarators and function types. A parameter Ghidra leaves untyped, such as a K&R identifier list, is refused after parsing. Ghidra names these function types by a per-parse counter, which would collide across calls. Each is stored in /rea_caller_defined as owner.member, or typedef.target, so a repeat is idempotent and a changed prototype is refused. Arrays keep the element name they were built with, so arrays of function pointers are rebuilt around the renamed type. inspect_native_data_type reports a function type with kind function and its function_definition: return type, parameters, varargs and calling convention. Refs #14887
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a3d0cbc042
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
[Medium impact] The reviewed changes appear safe to merge; no new actionable defect was established. SummaryAdds function-pointer members and typedefs to
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A["Caller C declarations"] --> B["Tokenizer admits supported forms"]
B --> C["Ghidra parses inside a transaction"]
C --> D["Check parameters and name function types"]
D --> E["Store equivalent types or roll back"]
E --> F["Inspect stored prototype"]
F --> G["Bounded parameters and omission counts"]
Reviews (2) · Last reviewed commit: "fix(ghidra): share caller parameter chec..." · Reviewed by Greptile |
|
Upstream fix for the array-name crash this PR works around: NationalSecurityAgency/ghidra#10317. |
Review of #14889: - A function pointer after a comma, as in int (*open)(int), (*close)(int); or typedef int (*a)(int), (*b)(int);, was refused because its parenthesis followed ",". Ghidra 12.2 stores each declarator with the shared return type and calling convention, so the declarator check now admits "," before the parenthesis. - A signature and a function-pointer member or typedef checked their parameter lists separately, so a function pointer accepted a repeated parameter name. requireCallerParameters is now the one check for both: repeated names, and a parameter written as a bare name that is not a type (a K&R identifier list), which Ghidra stores as undefined. The tokenizer records which identifiers fill a whole parameter slot, so an explicit undefined parameter type is not mistaken for one. This also refuses a K&R signature, which was previously applied with undefined parameters. - inspect_native_data_type serialized every parameter of a function type without a bound or cancellation check. It now uses the same 20000-entry bound as fields and enum members, checks cancellation per parameter, and reports total_parameters and parameters_truncated. Refs #14887
…pgp-633-20261127 * commit '3097263763611eb0c32c502d5a222060cf02f468': fix(cli): describe universal Mach-O slice selection without a single-dash flag (#14912) fix(iso9660): read Joliet trees whose .. records name their own directory (#14817) feat(gpu)!: add per-call object, work, report, metadata, structure, and parser budgets to inspect_gpu_code_objects (#14882) fix(macho)!: select arm64e.x1 slices of universal Mach-O files by exact subtype (#14881) refactor(views): share bounded parent and report limitations (#14902) refactor(desktop): share XML parent pointers in task drafts (#14905) feat(ghidra): define function-pointer members and typedefs (#14889) refactor(setup): share publication destination checks (#14904) perf(ci): skip unused test runtime uploads (#14903) fix(nuget): preserve explicitly spaced publisher metadata (#14906) fix(artifacts): keep uImage coverage unknown when bytes follow the declared payload (#14896) fix(artifacts): report incomplete Android sparse coverage (#14883) fix(tar): require both end-of-archive blocks for complete coverage (#14884) refactor(views): centralize indexed row paging (#14878) refactor(views): reuse optional filters in report projections (#14877)
Summary
Fixes #14887.
define_native_data_typesrefused every parenthesis in a definition, so a struct or union with a function-pointer member (vtables, ops tables, callback structs) and function-pointer typedefs could not be defined. This admits the plain function-pointer forms Ghidra 12.2 stores as written, and reports the stored prototype throughinspect_native_data_type.Problem and expected behavior
Before:
After: the struct is stored with
openas a pointer to/rea_caller_defined/ops.open, a function type whose prototype is readable:{ "kind": "function", "source": "caller-defined", "function_definition": { "return_type": "/int", "parameters": [ { "name": "path", "type": "/char *" }, { "name": "flags", "type": "/int" } ], "varargs": false, "calling_convention": "unknown" } }Change and scope
ret (*name)(parameters), with(**name),(*name[N])and a calling convention written before the parenthesis (int __stdcall (*name)(int)). The parameters use the existing grammar, so qualifiers in them are reported indropped_qualifiersand array sizes stay literal-only. Forms Ghidra 12.2 stores differently from the text are refused at their position, each found with a headlessCParserprobe and C.jj:(): stored as(void); write(void).(__stdcall *f): dropped by Ghidra._Noreturn: not stored on a function-pointer type.int (x);and function typestypedef int f(int);.undefinedplaceholder (a K&R identifier list or unknown name), refused after parsing._func_Nby a per-parse counter, which would collide across calls and make repeats non-idempotent. Each is stored in/rea_caller_definedasowner.member, ortypedef.targetfor a typedef; a repeat reportsunchangedand a changed prototype is refused withdata_type_conflict. Ghidra'sArrayDataTypekeeps the element name it was built with (and resolving it then threwStringIndexOutOfBoundsExceptionon real Ghidra), so arrays of function pointers are rebuilt around the renamed type.inspect_native_data_typeaddskind: "function"and an optionalfunction_definition(return type, parameters,varargs,calling_convention).__thiscall(not a C.jj token), andannotate_native_functionsignatures, which still refuse function-pointer declarators.Contract and boundary impact
admitCallerCin the bridge owns which forms reach Ghidra's parser;callerFunctionTypesowns naming and the untyped-parameter check after parsing. The previous blanket refusal of(and ofparser.getFunctions()is removed.define_native_data_typesedit within the same authority (session analysis database, no target bytes); not applicable.inspect_native_data_typeoutput gains thefunctionkind and optionalfunction_definition; thedeclarationsdescription names the admitted form. No input schema change.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
scripts/verify-real-ghidra-type-edits.mjs: new phase "function-pointer members and typedefs are stored with their prototypes". It defines a typedef and an 11-member struct (plain,(void), pointer return, varargs,__cdecl,(*table[4]),(**indirect), typedef member, typedef parameter, self-referential parameter) and checks every offset, size and member type, each function type's prototype,unchangedon repeat, and refusal of a changed prototype without change. The refusal list now covers(), a convention inside the parenthesis, a nested function-pointer parameter, an identifier list,_Noreturnand a function type, each at its column.tests/boundary/mcp/ghidraTypeEditsMcp.test.ts: a function type's prototype passes the MCP output contract, and a malformed one is refused asunreadable_output.(indeclarationsis refused, includingstruct rea_callbacks { int (*fn)(int); };, which the verifier previously expected. During development, an array of function pointers followed by another member failed on real Ghidra withStringIndexOutOfBoundsExceptionuntil the array was rebuilt.For evidence-bearing changes:
Validation performed
node scripts/verify-real-ghidra-type-edits.mjs(Ghidra 12.2, arm64 macOS) — verified, all 10 phases including the new one; process cleanup verified.javacofbridge/ghidra/*.javaagainst the Ghidra 12.2 jars (JDK 25) — success.npm run test:focused -- tests/boundary/mcp/ghidraTypeEditsMcp.test.ts tests/boundary/cli/analysisSelectorCli.test.ts tests/boundary/providers/ghidra/ghidraCheckpointLifecycle.test.ts tests/boundary/mcp/ghidraEvidenceMcp.test.ts— 4 files, 81 tests passed.npm run test:local -- src/ghidra/GhidraProvider.behavior.test.ts src/ghidra/GhidraSessionValues.test.ts src/ghidra/GhidraSnapshotCache.test.ts— 382 passed.npm run check:fast— passed.oxfmt --check .— passed.npm run docs:check— passed.npm run verify:advertised-schemas -- --update-summary— no summary changes (Rust validators not installed locally).Review follow-up (9667f18)
int (*open)(int), (*close)(int);, and the typedef form) are admitted; Ghidra 12.2 stores each with the shared return type and calling convention.requireCallerParameters, serves signatures and function pointers: repeated names and bare K&R names (stored by Ghidra asundefined) are refused in both. Behavior change: a K&R signature such asdouble total(s, mask)was previously applied withundefinedparameters and is now refused.function_definitionparameters share the 20000-entry readback bound with fields and members, check cancellation, and reporttotal_parametersandparameters_truncated.Compatibility, safety, and release
declarations_max_utf16and the 256-level type-depth ceiling.Author readiness
Human owner:
Author checklist (completed by the PR author before requesting review)
type(scope): outcome.REA_runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.