Repository navigation
Conversation
…tion
Type creators gain an optional category_path. Struct and union members
keep their comments, accept an explicit size that must match a fixed
type's natural size, and accept array and pointer types. Enum creation
also accepts an array of {name,value} objects. Field JSON is parsed with
Gson instead of by splitting on commas and colons, so a comment with
punctuation survives, and a member with a bad type fails the call
instead of being skipped. Replacing a 1-byte placeholder happens inside
the creation transaction, so a failed replacement leaves it intact.
Function signatures keep parameter names, take an optional calling
convention and update an existing definition in place instead of
replacing it; an invalid parameter rolls the whole update back.
Creating an identical typedef is a no-op and a conflicting one is
rejected instead of silently replacing the existing type.
Type resolution resolves qualified /Category/Name paths, sizes pointers
and well-known C types for the target ABI, handles arrays of pointers and
multi-dimensional arrays, and no longer turns an unknown pointer target
into void *.
add_struct_field accepts a bulk "fields" array that is applied in one transaction and rolled back if any field fails. Placing a field at an explicit offset reuses undefined padding but refuses to overwrite a defined field unless overwrite=true; padding is cleared in reverse ordinal order because clearing a component renumbers the ones after it. remove_struct_field now clears the field to undefined bytes so later offsets stay put, and only shifts the rest of the structure with shrink=true; packed structures still repack. Both it and modify_struct_field accept a hex offset or offset:N in place of a name, and default field names such as field0_0x0 resolve. Growing a field through modify_struct_field consumes padding after it instead of moving its neighbours, and keeps the field's name and comment.
delete_data_type relied on DataTypeManager.remove() to refuse a type that is still referenced, but remove() succeeds and takes the type's users with it: applied data is cleared and parent types lose their fields. Collect the users first: composite types that reference it, including through pointer and array wrappers; defined data whose type resolves to it through arrays, typedefs or pointers; and function return types and variables. Refuse the deletion and list them unless force=true.
search_data_types takes an optional kind (struct, union, enum, typedef, pointer, array, function_definition or primitive) and an empty pattern, so it can list every type of one kind. "query" is accepted as an alias for "pattern". get_type_size additionally reports the kind and, depending on it, the members of a composite, the return type, convention and parameters of a function definition, or the base type and element count of a typedef, pointer or array.
Add type=struct and a struct_name selector to the existing comment tool, preserving the tool count and listing-comment behavior. Store descriptions transactionally and expose them through get_struct_layout. Cover setting, replacing, clearing, qualified lookup, input validation, schema defaults, and bridge dispatch. Gradle extension build and Java tests pass; Python unit suite reports 1190 passed, 13 skipped, and one unrelated default-branch mismatch (dev versus main).
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
What this changes
The data type editing tools no longer silently lose data or reshape structures. Type creators take a
category_path, struct and union members keep their comments,add_struct_fieldandremove_struct_fieldkeep the layout intact, anddelete_data_typerefuses to delete a type that is still in use unlessforce=true. It also adds a kind filter tosearch_data_typesand letsset_commentread and write a structure's description.Fixes #
Why
Several of these tools did something surprising and unrecoverable:
remove_struct_fieldshifted every later field down, which moves all the offsets in code that already references the struct.DataTypeManager.remove()succeeds on a type that is still referenced and takes its users with it. Applied data is cleared and parent types lose their fields. The old code assumedremove()would refuse.void *. Qualified/Category/Namepaths didn't resolve, and ABI sizes were assumed.What changed, one commit per item:
category_path.sizethat must match.{name,value}array for enums.add_struct_fieldaccepts a bulkfieldsarray applied in one transaction, with rollback.overwrite=true.remove_struct_fieldclears to undefined bytes and only shifts withshrink=true.offset:N, or a default name likefield0_0x0.force=true.search_data_typestakes an optionalkindand an empty pattern, withqueryas an alias forpattern.get_type_sizealso reports members, signatures and base types.set_comment(type="struct", struct_name=..., comment=...)sets, replaces or clears a structure's description transactionally.get_struct_layoutreturns it.Behaviour changes callers will notice:
remove_struct_fieldno longer shifts later fields by default.delete_data_typeon a type in use is refused withoutforce.No tool is added or removed, so the catalog stays at 220.
Tests you ran
uv run pytest tests/unit/— Python unit tier, no Ghidra needed./gradlew test --tests 'com.xebyte.offline.*' "-PGHIDRA_INSTALL_DIR=<dir>"— offline Java tier, needs a Ghidra install but no running server and no
Maven (
mvn test -Dtest='com.xebyte.offline.*Test'is the Maven equivalent)powershell -File tests\pester\Run-Tests.ps1— only if you touchedghidra-mcp-setup.ps1pytest tests/ -m readonly,./gradlew test) — needs Ghidrarunning on port 8089 with a program loaded
If you touched an @mcptool or @PARAM annotation
New parameters:
fieldsandoverwriteonadd_struct_field,category_pathon the type creators,calling_conventiononcreate_function_signature,forceondelete_data_type,shrinkonremove_struct_field,kindonsearch_data_types, andstruct_nameonset_comment.mvn test -Dtest=RegenerateEndpointsJson -Dregenerate=true— Mavenonly; Gradle cannot pass the
-Dregenerateflag into the forked testJVM and exits BUILD SUCCESSFUL having regenerated nothing. No Maven? Say
so here and leave the catalog alone — a maintainer will regenerate it.
python -m tools.audit_server_scope --writepython -m tools.gen_readme_api_reference --writeI did not run
RegenerateEndpointsJson(no Maven here).tests/endpoints.jsonwas edited to add the new parameter names and theset_commentdescription. The parity tests in the offline Java tier andtests/unit(includingtest_project_consistency.pyandtest_audit_server_scope.py) pass against it. A maintainer should still regenerate it with Maven to confirm there is no drift.Checklist
devand targetingdevCHANGELOG.mdupdated, if this is user-visible