fix: TypeArchive.AddTypes passed the wrong struct to BNAddTypeArchiveTypes#38
Merged
Merged
Conversation
…Types AddTypes marshaled a BNQualifiedNameTypeAndId (40 bytes: name, id, type) and passed it to BNAddTypeArchiveTypes, whose contract is BNQualifiedNameAndType (32 bytes: name, type). The 8-byte layout mismatch made core read the id pointer at offset 24 as the type handle, so no type was ever actually added (and multi-element arrays were fully mis-strided). Match Python TypeArchive.add_type/add_types (typearchive.py:225/222): callers supply only name and definition; the core assigns the id. AddTypes now takes QualifiedNameAndType[] and adds an AddType(name, type) convenience. The id-bearing QualifiedNameTypeAndId struct stays -- it is the correct model for the type-reading (BNGetTypeArchiveTypes) and analysis-definition (BNDefineAnalysisTypes) APIs. E2E: harness TypeArchiveAddTypesMarshalingTests (create archive, AddType, assert listable; AddTypes second, assert both persist).
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.
Problem
TypeArchive.AddTypesmarshaled aBNQualifiedNameTypeAndIdstruct (40 bytes:name,id,type) and passed it toBNAddTypeArchiveTypes, whose contract isBNQualifiedNameAndType(32 bytes:name,type).The 8-byte layout mismatch made core read the
idpointer at offset 24 as thetypehandle — so a single-element add dereferenced the id string as aBNType*(garbage/crash), and multi-element arrays were fully mis-strided. No type was ever actually added.The C# P/Invoke comment even said
BNQualifiedNameAndType* types— the wrapper just ignored it.Fix
Match Python
TypeArchive.add_type/add_types(typearchive.py:225/222): callers supply only name and definition; the core assigns the id.AddTypes(QualifiedNameAndType[])— builds the correct 32-byte struct.AddType(QualifiedName, Type)— convenience (Pythonadd_type).The id-bearing
QualifiedNameTypeAndIdstruct stays — it is the correct model for the type-reading (BNGetTypeArchiveTypes) and analysis-definition (BNDefineAnalysisTypes) APIs, which legitimately carry ids.E2E
sharp-binaryninja-testsharness:TypeArchiveAddTypesMarshalingTests— create archive,AddType, assert listable viaGetTypeNames;AddTypessecond, assert both persist. (Fails on the old 40-byte struct; passes on the fix.)Verified
dotnet build -c Release— 0 warnings, 0 errors.