diff options
| author | Brian Potchik <brian@vector35.com> | 2025-06-16 17:20:26 -0400 |
|---|---|---|
| committer | Brian Potchik <brian@vector35.com> | 2025-06-16 17:20:26 -0400 |
| commit | 5cab99afa06eb32265fee4798cbfc83bd6a8ae4d (patch) | |
| tree | a641c9e2f86c29aa78dc50598477cc861e22df6e | |
| parent | 979515fb42365fbe6f000086ef13c125150f36c3 (diff) | |
Update SymbolQueue API to support types with confidence.
| -rw-r--r-- | binaryninjaapi.h | 10 | ||||
| -rw-r--r-- | binaryninjacore.h | 8 | ||||
| -rw-r--r-- | binaryview.cpp | 20 | ||||
| -rw-r--r-- | rust/src/binary_view.rs | 13 |
4 files changed, 28 insertions, 23 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 650fa8a2..23b14797 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -5758,7 +5758,7 @@ namespace BinaryNinja { \param type Type being defined \return The defined symbol */ - Ref<Symbol> DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, Ref<Type> type); + Ref<Symbol> DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, const Confidence<Ref<Type>>& type); /*! Undefine an automatically defined symbol @@ -18819,14 +18819,14 @@ namespace BinaryNinja { { BNSymbolQueue* m_object; - static void ResolveCallback(void* ctxt, BNSymbol** symbol, BNType** type); - static void AddCallback(void* ctxt, BNSymbol* symbol, BNType* type); + static void ResolveCallback(void* ctxt, BNSymbol** symbol, BNTypeWithConfidence* type); + static void AddCallback(void* ctxt, BNSymbol* symbol, BNTypeWithConfidence* type); public: SymbolQueue(); ~SymbolQueue(); - void Append(const std::function<std::pair<Ref<Symbol>, Ref<Type>>()>& resolve, - const std::function<void(Symbol*, Type*)>& add); + void Append(const std::function<std::pair<Ref<Symbol>, Confidence<Ref<Type>>>()>& resolve, + const std::function<void(Symbol*, const Confidence<Ref<Type>>&)>& add); void Process(); }; diff --git a/binaryninjacore.h b/binaryninjacore.h index b4cd54d2..fc98a10d 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -37,7 +37,7 @@ // 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 111 +#define BN_CURRENT_CORE_ABI_VERSION 112 // 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 @@ -5807,7 +5807,7 @@ extern "C" BINARYNINJACOREAPI void BNDefineImportedFunction( BNBinaryView* view, BNSymbol* importAddressSym, BNFunction* func, BNType* type); BINARYNINJACOREAPI BNSymbol* BNDefineAutoSymbolAndVariableOrFunction( - BNBinaryView* view, BNPlatform* platform, BNSymbol* sym, BNType* type); + BNBinaryView* view, BNPlatform* platform, BNSymbol* sym, BNTypeWithConfidence* type); BINARYNINJACOREAPI void BNBeginBulkModifySymbols(BNBinaryView* view); BINARYNINJACOREAPI void BNEndBulkModifySymbols(BNBinaryView* view); @@ -7721,8 +7721,8 @@ extern "C" BINARYNINJACOREAPI BNSymbolQueue* BNCreateSymbolQueue(void); BINARYNINJACOREAPI void BNDestroySymbolQueue(BNSymbolQueue* queue); BINARYNINJACOREAPI void BNAppendSymbolQueue(BNSymbolQueue* queue, - void (*resolve)(void* ctxt, BNSymbol** symbol, BNType** type), void* resolveContext, - void (*add)(void* ctxt, BNSymbol* symbol, BNType* type), void* addContext); + void (*resolve)(void* ctxt, BNSymbol** symbol, BNTypeWithConfidence* type), void* resolveContext, + void (*add)(void* ctxt, BNSymbol* symbol, BNTypeWithConfidence* type), void* addContext); BINARYNINJACOREAPI void BNProcessSymbolQueue(BNSymbolQueue* queue); BINARYNINJACOREAPI bool BNCoreEnumToString(const char* enumName, size_t value, char** result); diff --git a/binaryview.cpp b/binaryview.cpp index 310396c0..d8477826 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -29,12 +29,12 @@ using namespace std; struct SymbolQueueResolveContext { - std::function<std::pair<Ref<Symbol>, Ref<Type>>()> resolve; + std::function<std::pair<Ref<Symbol>, Confidence<Ref<Type>>>()> resolve; }; struct SymbolQueueAddContext { - std::function<void(Symbol*, Type*)> add; + std::function<void(Symbol*, const Confidence<Ref<Type>>&)> add; }; @@ -3130,10 +3130,11 @@ void BinaryView::DefineAutoSymbol(Ref<Symbol> sym) } -Ref<Symbol> BinaryView::DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, Ref<Type> type) +Ref<Symbol> BinaryView::DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, const Confidence<Ref<Type>>& type) { + BNTypeWithConfidence apiType = {type.GetValue() ? type.GetValue()->GetObject() : nullptr, type.GetConfidence()}; BNSymbol* result = BNDefineAutoSymbolAndVariableOrFunction( - m_object, platform ? platform->GetObject() : nullptr, sym->GetObject(), type ? type->GetObject() : nullptr); + m_object, platform ? platform->GetObject() : nullptr, sym->GetObject(), &apiType); if (!result) return nullptr; return new Symbol(result); @@ -5694,28 +5695,29 @@ SymbolQueue::~SymbolQueue() } -void SymbolQueue::ResolveCallback(void* ctxt, BNSymbol** symbol, BNType** type) +void SymbolQueue::ResolveCallback(void* ctxt, BNSymbol** symbol, BNTypeWithConfidence* type) { SymbolQueueResolveContext* resolve = (SymbolQueueResolveContext*)ctxt; auto result = resolve->resolve(); delete resolve; *symbol = result.first ? BNNewSymbolReference(result.first->GetObject()) : nullptr; - *type = result.second ? BNNewTypeReference(result.second->GetObject()) : nullptr; + type->type = result.second.GetValue() ? BNNewTypeReference(result.second.GetValue()->GetObject()) : nullptr; + type->confidence = result.second.GetConfidence(); } -void SymbolQueue::AddCallback(void* ctxt, BNSymbol* symbol, BNType* type) +void SymbolQueue::AddCallback(void* ctxt, BNSymbol* symbol, BNTypeWithConfidence* type) { SymbolQueueAddContext* add = (SymbolQueueAddContext*)ctxt; Ref<Symbol> apiSymbol = new Symbol(symbol); - Ref<Type> apiType = new Type(type); + Confidence<Ref<Type>> apiType(type->type ? new Type(type->type) : nullptr, type->confidence); add->add(apiSymbol, apiType); delete add; } void SymbolQueue::Append( - const std::function<std::pair<Ref<Symbol>, Ref<Type>>()>& resolve, const std::function<void(Symbol*, Type*)>& add) + const std::function<std::pair<Ref<Symbol>, Confidence<Ref<Type>>>()>& resolve, const std::function<void(Symbol*, const Confidence<Ref<Type>>&)>& add) { SymbolQueueResolveContext* resolveCtxt = new SymbolQueueResolveContext {resolve}; SymbolQueueAddContext* addCtxt = new SymbolQueueAddContext {add}; diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs index 0a1a380b..c4aaf32d 100644 --- a/rust/src/binary_view.rs +++ b/rust/src/binary_view.rs @@ -528,10 +528,13 @@ pub trait BinaryViewExt: BinaryViewBase { plat: &Platform, ty: T, ) -> Result<Ref<Symbol>> { - let raw_type = if let Some(t) = ty.into() { - t.handle - } else { - std::ptr::null_mut() + let mut type_with_conf = BNTypeWithConfidence { + type_: if let Some(t) = ty.into() { + t.handle + } else { + std::ptr::null_mut() + }, + confidence: 255, // BN_FULL_CONFIDENCE }; unsafe { @@ -539,7 +542,7 @@ pub trait BinaryViewExt: BinaryViewBase { self.as_ref().handle, plat.handle, sym.handle, - raw_type, + &mut type_with_conf, ); if raw_sym.is_null() { |
