Skip to content

Commit 5cab99a

Browse files
committed
Update SymbolQueue API to support types with confidence.
1 parent 979515f commit 5cab99a

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

binaryninjaapi.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5758,7 +5758,7 @@ namespace BinaryNinja {
57585758
\param type Type being defined
57595759
\return The defined symbol
57605760
*/
5761-
Ref<Symbol> DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, Ref<Type> type);
5761+
Ref<Symbol> DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, const Confidence<Ref<Type>>& type);
57625762

57635763
/*! Undefine an automatically defined symbol
57645764

@@ -18819,14 +18819,14 @@ namespace BinaryNinja {
1881918819
{
1882018820
BNSymbolQueue* m_object;
1882118821

18822-
static void ResolveCallback(void* ctxt, BNSymbol** symbol, BNType** type);
18823-
static void AddCallback(void* ctxt, BNSymbol* symbol, BNType* type);
18822+
static void ResolveCallback(void* ctxt, BNSymbol** symbol, BNTypeWithConfidence* type);
18823+
static void AddCallback(void* ctxt, BNSymbol* symbol, BNTypeWithConfidence* type);
1882418824

1882518825
public:
1882618826
SymbolQueue();
1882718827
~SymbolQueue();
18828-
void Append(const std::function<std::pair<Ref<Symbol>, Ref<Type>>()>& resolve,
18829-
const std::function<void(Symbol*, Type*)>& add);
18828+
void Append(const std::function<std::pair<Ref<Symbol>, Confidence<Ref<Type>>>()>& resolve,
18829+
const std::function<void(Symbol*, const Confidence<Ref<Type>>&)>& add);
1883018830
void Process();
1883118831
};
1883218832

binaryninjacore.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// Current ABI version for linking to the core. This is incremented any time
3838
// there are changes to the API that affect linking, including new functions,
3939
// new types, or modifications to existing functions or types.
40-
#define BN_CURRENT_CORE_ABI_VERSION 111
40+
#define BN_CURRENT_CORE_ABI_VERSION 112
4141

4242
// Minimum ABI version that is supported for loading of plugins. Plugins that
4343
// are linked to an ABI version less than this will not be able to load and
@@ -5807,7 +5807,7 @@ extern "C"
58075807
BINARYNINJACOREAPI void BNDefineImportedFunction(
58085808
BNBinaryView* view, BNSymbol* importAddressSym, BNFunction* func, BNType* type);
58095809
BINARYNINJACOREAPI BNSymbol* BNDefineAutoSymbolAndVariableOrFunction(
5810-
BNBinaryView* view, BNPlatform* platform, BNSymbol* sym, BNType* type);
5810+
BNBinaryView* view, BNPlatform* platform, BNSymbol* sym, BNTypeWithConfidence* type);
58115811
BINARYNINJACOREAPI void BNBeginBulkModifySymbols(BNBinaryView* view);
58125812
BINARYNINJACOREAPI void BNEndBulkModifySymbols(BNBinaryView* view);
58135813

@@ -7721,8 +7721,8 @@ extern "C"
77217721
BINARYNINJACOREAPI BNSymbolQueue* BNCreateSymbolQueue(void);
77227722
BINARYNINJACOREAPI void BNDestroySymbolQueue(BNSymbolQueue* queue);
77237723
BINARYNINJACOREAPI void BNAppendSymbolQueue(BNSymbolQueue* queue,
7724-
void (*resolve)(void* ctxt, BNSymbol** symbol, BNType** type), void* resolveContext,
7725-
void (*add)(void* ctxt, BNSymbol* symbol, BNType* type), void* addContext);
7724+
void (*resolve)(void* ctxt, BNSymbol** symbol, BNTypeWithConfidence* type), void* resolveContext,
7725+
void (*add)(void* ctxt, BNSymbol* symbol, BNTypeWithConfidence* type), void* addContext);
77267726
BINARYNINJACOREAPI void BNProcessSymbolQueue(BNSymbolQueue* queue);
77277727

77287728
BINARYNINJACOREAPI bool BNCoreEnumToString(const char* enumName, size_t value, char** result);

binaryview.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ using namespace std;
2929

3030
struct SymbolQueueResolveContext
3131
{
32-
std::function<std::pair<Ref<Symbol>, Ref<Type>>()> resolve;
32+
std::function<std::pair<Ref<Symbol>, Confidence<Ref<Type>>>()> resolve;
3333
};
3434

3535
struct SymbolQueueAddContext
3636
{
37-
std::function<void(Symbol*, Type*)> add;
37+
std::function<void(Symbol*, const Confidence<Ref<Type>>&)> add;
3838
};
3939

4040

@@ -3130,10 +3130,11 @@ void BinaryView::DefineAutoSymbol(Ref<Symbol> sym)
31303130
}
31313131

31323132

3133-
Ref<Symbol> BinaryView::DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, Ref<Type> type)
3133+
Ref<Symbol> BinaryView::DefineAutoSymbolAndVariableOrFunction(Ref<Platform> platform, Ref<Symbol> sym, const Confidence<Ref<Type>>& type)
31343134
{
3135+
BNTypeWithConfidence apiType = {type.GetValue() ? type.GetValue()->GetObject() : nullptr, type.GetConfidence()};
31353136
BNSymbol* result = BNDefineAutoSymbolAndVariableOrFunction(
3136-
m_object, platform ? platform->GetObject() : nullptr, sym->GetObject(), type ? type->GetObject() : nullptr);
3137+
m_object, platform ? platform->GetObject() : nullptr, sym->GetObject(), &apiType);
31373138
if (!result)
31383139
return nullptr;
31393140
return new Symbol(result);
@@ -5694,28 +5695,29 @@ SymbolQueue::~SymbolQueue()
56945695
}
56955696

56965697

5697-
void SymbolQueue::ResolveCallback(void* ctxt, BNSymbol** symbol, BNType** type)
5698+
void SymbolQueue::ResolveCallback(void* ctxt, BNSymbol** symbol, BNTypeWithConfidence* type)
56985699
{
56995700
SymbolQueueResolveContext* resolve = (SymbolQueueResolveContext*)ctxt;
57005701
auto result = resolve->resolve();
57015702
delete resolve;
57025703
*symbol = result.first ? BNNewSymbolReference(result.first->GetObject()) : nullptr;
5703-
*type = result.second ? BNNewTypeReference(result.second->GetObject()) : nullptr;
5704+
type->type = result.second.GetValue() ? BNNewTypeReference(result.second.GetValue()->GetObject()) : nullptr;
5705+
type->confidence = result.second.GetConfidence();
57045706
}
57055707

57065708

5707-
void SymbolQueue::AddCallback(void* ctxt, BNSymbol* symbol, BNType* type)
5709+
void SymbolQueue::AddCallback(void* ctxt, BNSymbol* symbol, BNTypeWithConfidence* type)
57085710
{
57095711
SymbolQueueAddContext* add = (SymbolQueueAddContext*)ctxt;
57105712
Ref<Symbol> apiSymbol = new Symbol(symbol);
5711-
Ref<Type> apiType = new Type(type);
5713+
Confidence<Ref<Type>> apiType(type->type ? new Type(type->type) : nullptr, type->confidence);
57125714
add->add(apiSymbol, apiType);
57135715
delete add;
57145716
}
57155717

57165718

57175719
void SymbolQueue::Append(
5718-
const std::function<std::pair<Ref<Symbol>, Ref<Type>>()>& resolve, const std::function<void(Symbol*, Type*)>& add)
5720+
const std::function<std::pair<Ref<Symbol>, Confidence<Ref<Type>>>()>& resolve, const std::function<void(Symbol*, const Confidence<Ref<Type>>&)>& add)
57195721
{
57205722
SymbolQueueResolveContext* resolveCtxt = new SymbolQueueResolveContext {resolve};
57215723
SymbolQueueAddContext* addCtxt = new SymbolQueueAddContext {add};

rust/src/binary_view.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,18 +528,21 @@ pub trait BinaryViewExt: BinaryViewBase {
528528
plat: &Platform,
529529
ty: T,
530530
) -> Result<Ref<Symbol>> {
531-
let raw_type = if let Some(t) = ty.into() {
532-
t.handle
533-
} else {
534-
std::ptr::null_mut()
531+
let mut type_with_conf = BNTypeWithConfidence {
532+
type_: if let Some(t) = ty.into() {
533+
t.handle
534+
} else {
535+
std::ptr::null_mut()
536+
},
537+
confidence: 255, // BN_FULL_CONFIDENCE
535538
};
536539

537540
unsafe {
538541
let raw_sym = BNDefineAutoSymbolAndVariableOrFunction(
539542
self.as_ref().handle,
540543
plat.handle,
541544
sym.handle,
542-
raw_type,
545+
&mut type_with_conf,
543546
);
544547

545548
if raw_sym.is_null() {

0 commit comments

Comments
 (0)