diff options
| author | Mark Rowe <mark@vector35.com> | 2026-03-18 22:58:20 -0700 |
|---|---|---|
| committer | Mark Rowe <mark@vector35.com> | 2026-03-19 08:43:51 -0700 |
| commit | cbc66f931da1046b3980c2c7c6b64c2f2ac358e2 (patch) | |
| tree | 3483e6c6d37ab18c7698c5148e61f6a715a6472c | |
| parent | eeceddfaf7c8d2ef4a9feed5dc2abb1dcc498b76 (diff) | |
Fix operand list iterators being validated when appending new instructions
The iterators now store an offset into the operand storage, rather than
a pointer. Deferencing the iterator retrieves the value at that offset
from the IL function.
This issue existed prior to the operand list storage refactor, but
became easier to hit after that change. The separate operand list vector
is smaller and thus more likely to reallocate when a new instruction is
appended.
| -rw-r--r-- | binaryninjacore.h | 10 | ||||
| -rw-r--r-- | highlevelilinstruction.cpp | 22 | ||||
| -rw-r--r-- | highlevelilinstruction.h | 2 | ||||
| -rw-r--r-- | lowlevelilinstruction.cpp | 22 | ||||
| -rw-r--r-- | lowlevelilinstruction.h | 2 | ||||
| -rw-r--r-- | mediumlevelilinstruction.cpp | 22 | ||||
| -rw-r--r-- | mediumlevelilinstruction.h | 2 |
7 files changed, 47 insertions, 35 deletions
diff --git a/binaryninjacore.h b/binaryninjacore.h index 20fe50e8..6404268c 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -37,14 +37,14 @@ // Current ABI version for linking to the core. This is incremented any time // there are changes to the API that affect linking, including new functions, // new types, or modifications to existing functions or types. -#define BN_CURRENT_CORE_ABI_VERSION 160 +#define BN_CURRENT_CORE_ABI_VERSION 161 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and // will require rebuilding. The minimum version is increased when there are // incompatible changes that break binary compatibility, such as changes to // existing types or functions. -#define BN_MINIMUM_CORE_ABI_VERSION 160 +#define BN_MINIMUM_CORE_ABI_VERSION 161 #ifdef __GNUC__ #ifdef BINARYNINJACORE_LIBRARY @@ -6445,7 +6445,7 @@ extern "C" BINARYNINJACOREAPI uint64_t* BNLowLevelILGetOperandList( BNLowLevelILFunction* func, size_t expr, size_t operand, size_t* count); BINARYNINJACOREAPI void BNLowLevelILFreeOperandList(uint64_t* operands); - BINARYNINJACOREAPI const uint64_t* BNLowLevelILGetOperandPointer( + BINARYNINJACOREAPI uint64_t BNLowLevelILGetOperand( BNLowLevelILFunction* func, size_t offset); BINARYNINJACOREAPI size_t BNCacheLowLevelILPossibleValueSet(BNLowLevelILFunction* func, BNPossibleValueSet* pvs); @@ -6604,7 +6604,7 @@ extern "C" BINARYNINJACOREAPI uint64_t* BNMediumLevelILGetOperandList( BNMediumLevelILFunction* func, size_t expr, size_t operand, size_t* count); BINARYNINJACOREAPI void BNMediumLevelILFreeOperandList(uint64_t* operands); - BINARYNINJACOREAPI const uint64_t* BNMediumLevelILGetOperandPointer( + BINARYNINJACOREAPI uint64_t BNMediumLevelILGetOperand( BNMediumLevelILFunction* func, size_t offset); BINARYNINJACOREAPI size_t BNCacheMediumLevelILPossibleValueSet(BNMediumLevelILFunction* func, BNPossibleValueSet* pvs); @@ -6767,7 +6767,7 @@ extern "C" BINARYNINJACOREAPI uint64_t* BNHighLevelILGetOperandList( BNHighLevelILFunction* func, size_t expr, size_t operand, size_t* count); BINARYNINJACOREAPI void BNHighLevelILFreeOperandList(uint64_t* operands); - BINARYNINJACOREAPI const uint64_t* BNHighLevelILGetOperandPointer( + BINARYNINJACOREAPI uint64_t BNHighLevelILGetOperand( BNHighLevelILFunction* func, size_t offset); BINARYNINJACOREAPI size_t BNCacheHighLevelILPossibleValueSet(BNHighLevelILFunction* func, BNPossibleValueSet* pvs); diff --git a/highlevelilinstruction.cpp b/highlevelilinstruction.cpp index ad8f416d..7f4bad39 100644 --- a/highlevelilinstruction.cpp +++ b/highlevelilinstruction.cpp @@ -288,14 +288,18 @@ bool HighLevelILIntegerList::ListIterator::operator<(const ListIterator& a) cons HighLevelILIntegerList::ListIterator& HighLevelILIntegerList::ListIterator::operator++() { count--; - cur++; + offset++; return *this; } uint64_t HighLevelILIntegerList::ListIterator::operator*() { - return *cur; +#ifdef BINARYNINJACORE_LIBRARY + return function->GetOperand(offset); +#else + return BNHighLevelILGetOperand(function->GetObject(), offset); +#endif } @@ -303,11 +307,7 @@ HighLevelILIntegerList::HighLevelILIntegerList( HighLevelILFunction* func, size_t offset, size_t count) { m_start.function = func; -#ifdef BINARYNINJACORE_LIBRARY - m_start.cur = func->GetOperandPointer(offset); -#else - m_start.cur = BNHighLevelILGetOperandPointer(func->GetObject(), offset); -#endif + m_start.offset = offset; m_start.count = count; } @@ -322,7 +322,7 @@ HighLevelILIntegerList::const_iterator HighLevelILIntegerList::end() const { const_iterator result; result.function = m_start.function; - result.cur = m_start.cur + m_start.count; + result.offset = m_start.offset + m_start.count; result.count = 0; return result; } @@ -338,7 +338,11 @@ uint64_t HighLevelILIntegerList::operator[](size_t i) const { if (i >= size()) throw HighLevelILInstructionAccessException(); - return m_start.cur[i]; +#ifdef BINARYNINJACORE_LIBRARY + return m_start.function->GetOperand(m_start.offset + i); +#else + return BNHighLevelILGetOperand(m_start.function->GetObject(), m_start.offset + i); +#endif } diff --git a/highlevelilinstruction.h b/highlevelilinstruction.h index 93152241..bf2b5162 100644 --- a/highlevelilinstruction.h +++ b/highlevelilinstruction.h @@ -196,7 +196,7 @@ namespace BinaryNinja #else Ref<HighLevelILFunction> function; #endif - const uint64_t* cur; + size_t offset; size_t count; bool operator==(const ListIterator& a) const; diff --git a/lowlevelilinstruction.cpp b/lowlevelilinstruction.cpp index 33c556bd..ba26b82e 100644 --- a/lowlevelilinstruction.cpp +++ b/lowlevelilinstruction.cpp @@ -597,14 +597,18 @@ bool LowLevelILIntegerList::ListIterator::operator<(const ListIterator& a) const LowLevelILIntegerList::ListIterator& LowLevelILIntegerList::ListIterator::operator++() { count--; - cur++; + offset++; return *this; } uint64_t LowLevelILIntegerList::ListIterator::operator*() { - return *cur; +#ifdef BINARYNINJACORE_LIBRARY + return function->GetOperand(offset); +#else + return BNLowLevelILGetOperand(function->GetObject(), offset); +#endif } @@ -612,11 +616,7 @@ LowLevelILIntegerList::LowLevelILIntegerList( LowLevelILFunction* func, size_t offset, size_t count) { m_start.function = func; -#ifdef BINARYNINJACORE_LIBRARY - m_start.cur = func->GetOperandPointer(offset); -#else - m_start.cur = BNLowLevelILGetOperandPointer(func->GetObject(), offset); -#endif + m_start.offset = offset; m_start.count = count; } @@ -631,7 +631,7 @@ LowLevelILIntegerList::const_iterator LowLevelILIntegerList::end() const { const_iterator result; result.function = m_start.function; - result.cur = m_start.cur + m_start.count; + result.offset = m_start.offset + m_start.count; result.count = 0; return result; } @@ -647,7 +647,11 @@ uint64_t LowLevelILIntegerList::operator[](size_t i) const { if (i >= size()) throw LowLevelILInstructionAccessException(); - return m_start.cur[i]; +#ifdef BINARYNINJACORE_LIBRARY + return m_start.function->GetOperand(m_start.offset + i); +#else + return BNLowLevelILGetOperand(m_start.function->GetObject(), m_start.offset + i); +#endif } diff --git a/lowlevelilinstruction.h b/lowlevelilinstruction.h index 5feef433..97f10c32 100644 --- a/lowlevelilinstruction.h +++ b/lowlevelilinstruction.h @@ -385,7 +385,7 @@ namespace BinaryNinja #else Ref<LowLevelILFunction> function; #endif - const uint64_t* cur; + size_t offset; size_t count; bool operator==(const ListIterator& a) const; diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index c7dc7a5a..0c89ace3 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -320,14 +320,18 @@ bool MediumLevelILIntegerList::ListIterator::operator<(const ListIterator& a) co MediumLevelILIntegerList::ListIterator& MediumLevelILIntegerList::ListIterator::operator++() { count--; - cur++; + offset++; return *this; } uint64_t MediumLevelILIntegerList::ListIterator::operator*() { - return *cur; +#ifdef BINARYNINJACORE_LIBRARY + return function->GetOperand(offset); +#else + return BNMediumLevelILGetOperand(function->GetObject(), offset); +#endif } @@ -335,11 +339,7 @@ MediumLevelILIntegerList::MediumLevelILIntegerList( MediumLevelILFunction* func, size_t offset, size_t count) { m_start.function = func; -#ifdef BINARYNINJACORE_LIBRARY - m_start.cur = func->GetOperandPointer(offset); -#else - m_start.cur = BNMediumLevelILGetOperandPointer(func->GetObject(), offset); -#endif + m_start.offset = offset; m_start.count = count; } @@ -354,7 +354,7 @@ MediumLevelILIntegerList::const_iterator MediumLevelILIntegerList::end() const { const_iterator result; result.function = m_start.function; - result.cur = m_start.cur + m_start.count; + result.offset = m_start.offset + m_start.count; result.count = 0; return result; } @@ -370,7 +370,11 @@ uint64_t MediumLevelILIntegerList::operator[](size_t i) const { if (i >= size()) throw MediumLevelILInstructionAccessException(); - return m_start.cur[i]; +#ifdef BINARYNINJACORE_LIBRARY + return m_start.function->GetOperand(m_start.offset + i); +#else + return BNMediumLevelILGetOperand(m_start.function->GetObject(), m_start.offset + i); +#endif } diff --git a/mediumlevelilinstruction.h b/mediumlevelilinstruction.h index bbc8f432..3d7da6b9 100644 --- a/mediumlevelilinstruction.h +++ b/mediumlevelilinstruction.h @@ -247,7 +247,7 @@ namespace BinaryNinja #else Ref<MediumLevelILFunction> function; #endif - const uint64_t* cur; + size_t offset; size_t count; bool operator==(const ListIterator& a) const; |
