feat: expose HLIL derived-string-reference (get/set/remove) parity#36
Merged
Conversation
Closes HIGH missing-capi gap #16. The binding declared the three derived-string P/Invokes (BNGet/BNSet/BNRemoveHighLevelILDerivedStringReferenceForExpr) but exposed no managed surface, so HLIL derived strings were unreachable vs Python (highlevelil.py:978 derived_string_reference, :3014 set_derived_string_reference_for_expr, :3023 remove_derived_string_reference_for_expr). Add: - HighLevelILInstruction.DerivedStringReference property (DerivedString?, null when the expression carries no reference). The getter owns the BNStringRef* core returns (Python uses owned=True; its StringRef frees on GC), so the binding frees it after the eager read. - HighLevelILFunction.SetDerivedStringReferenceForExpr(expr, DerivedString), rebuilding the value as a fresh BNStringRef* (the projection reads eagerly and does not retain the core handle) and freeing it after the call; core copies/add-refs the string, matching Python's owned=False borrow. - HighLevelILFunction.RemoveDerivedStringReferenceForExpr(expr). - DerivedString.ToNativeEx() + a public value-only ctor so callers can construct a reference to attach.
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
Closes HIGH-severity missing-capi gap #16. Three HLIL derived-string P/Invokes were declared but had no managed wrappers, leaving the surface unreachable vs Python.
HighLevelILInstruction.DerivedStringReferenceBNGetHighLevelILDerivedStringReferenceForExprderived_string_reference(highlevelil.py:978)HighLevelILFunction.SetDerivedStringReferenceForExprBNSetHighLevelILDerivedStringReferenceForExprset_derived_string_reference_for_expr(highlevelil.py:3014)HighLevelILFunction.RemoveDerivedStringReferenceForExprBNRemoveHighLevelILDerivedStringReferenceForExprremove_derived_string_reference_for_expr(highlevelil.py:3023)Ownership notes
_from_core_struct(str, owned=True)takes ownership of theBNStringRef*and frees it on GC. The C# projection reads the text eagerly, so it freesraw.valueitself viaBNFreeStringRef— closing the leak Python defers to GC.owned=False(itsStringRefoutlives the call). Core copies/add-refs the string, so the setter creates a freshBNStringRef*, hands the struct to core, and frees it immediately after — balancing its own allocation. The value is rebuilt becauseDerivedStringreads eagerly and does not retain the original handle.custom_typeis not surfaced (the C# projection drops the recognizer handle, matching Python's read shape); documented onDerivedString.ToNativeEx.E2E tests (harness repo)
HLILDerivedStringReferenceTests(2 tests):GetReadsRealDerivedStringsAndNullsAcrossEveryExpression— sweeps every HLIL expression; cat.bndb analysis produces a real derived string (code-string location), so thefound=truepath is exercised on genuine analysis output, not justSet-attached refs.SetGetRemoveRoundTripsOnFirstExpression— set"e2e_roundtrip"→ get returns it → remove → null.Full harness regression 58/58.