fix: HLIL OperationOperands undercounts + ROR bogus Carry#26
Merged
Conversation
The OperationOperands count table in Struct/BNHighLevelILInstruction.cs sized the per-instruction RawOperands[] array too small for 21 operations, so accessing the affected typed-accessor properties threw IndexOutOfRangeException at runtime. The undercounts fell into groups: - TwoOperandWithCarry ops (ADC/SBB/RLC/RRC) omitted the carry operand (2->3) - SSA stores omitted the dest memory-version slot (VAR_INIT_SSA, ASSIGN_MEM_SSA, ASSIGN_UNPACK_MEM_SSA, CALL_SSA, INTRINSIC_SSA, SYSCALL_SSA) - SSAVariable-occupying ops omitted the version's second raw slot (FORCE_VER_SSA, ASSERT_SSA, VAR_PHI) - Phi/control ops omitted loop and phi operands (MEM_PHI, WHILE_SSA, DO_WHILE_SSA, FOR_SSA, CASE, ASSIGN_UNPACK) - Plain non-SSA force/assert omitted their second operand (FORCE_VER, ASSERT) HLIL_ROR additionally exposed a bogus Carry property that read operands[2] past its two operands -- C++ ROR is TwoOperandInstruction (no carry; only ADC/SBB/RLC/RRC are TwoOperandWithCarry). Removed. Counts verified 1:1 against binaryninja-api/highlevelilinstruction.h raw operand layouts; SSAVariable occupies two raw slots (variable, version).
This was referenced Jul 8, 2026
tinysec
added a commit
that referenced
this pull request
Jul 9, 2026
#41) Mirror Python HighLevelILInstruction.detailed_operands / operands / traverse (highlevelil.py:795/786/802). A static descriptor table (operation -> named, typed operands) drives a kind-dispatched reader; Operands and Traverse derive from it, exactly as in Python. - HighLevelILOperand: enum Kind + readonly Operand/Descriptor structs. - HighLevelILDetailedOperandsTable: 114-op descriptor table generated from the Python detailed_operands overrides, abstract bases expanded to concrete ops. - HighLevelILInstruction: GetOperandAsInteger, virtual DetailedOperands, ReadDetailedOperandByKind (SSA var + constant data occupy two raw slots), Operands, generic Traverse<T> (DFS, shallow blacklist matches Python). - HLILVariableDeclare: expose the .Variable accessor (the one missing accessor). Divergence from Python (intentional, documented in the table header): HLIL_ROR omits the "carry" operand -- Python's HighLevelILRor inherits CarryBase but the core (highlevelilinstruction.cpp:189) defines ROR with only {left,right}, so Python's Ror.carry reads a non-existent slot. C# follows the core (OperationOperands = 2, matching PR #26's removal of the bogus Carry accessor). E2E (harness, not in this repo): DetailedOperands parity vs the Python spec for ADD/STRUCT_FIELD/CONST(+PTR/FLOAT); Operands + Traverse; full cat.bndb sweep no-throw; static consistency test reflecting over the table + OperationOperands catches out-of-bounds indices (the ROR bug above was found + fixed by it). 76/76 pass.
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
The
OperationOperandscount table inStruct/BNHighLevelILInstruction.cssizes each instruction'sRawOperands[]array. 21 entries undercounted their operands, so accessing the affected typed-accessor property (e.g.DestMemoryVersion,SourceMemoryVersion,Carry,Loop,Cond) threwIndexOutOfRangeExceptionat runtime — the operand was never readable.HLIL_RORadditionally exposed a bogusCarryproperty readingoperands[2]past its two operands (C++RORisTwoOperandInstruction; onlyADC/SBB/RLC/RRCareTwoOperandWithCarry).Root cause
Counts verified 1:1 against
binaryninja-api/highlevelilinstruction.hraw operand layouts. The misses fall into groups:2→3This is the systematic-miscount cluster flagged from PR #24 (which fixed only STRUCT_FIELD/DEREF_FIELD/DEREF_FIELD_SSA).
Changes
Struct/BNHighLevelILInstruction.cs: 21 count bumps in theOperationOperandstable, each with an operand-list comment.HighLevelIL/HLILRotateRight.cs: removed bogusCarryproperty.Verification
dotnet build -c Releaseclean.crash_audit.py, op→accessor switch): NO OOB after the fix (was 22 OOB).cat.bndbviaMustGetExpression, invokes each declared operand-accessor getter, asserts none throwsIndexOutOfRangeException.Scope
Same bug class likely exists in the MLIL and LLIL operand-count tables — follow-up PRs will address those. (Also noted: the cross-IL mapping properties
MediumLevelILs/LowLevelILsthrowIndexOutOfRangefor unmapped instructions — a separate latent bug, out of scope here.)