Skip to content

Commit a746433

Browse files
committed
Add helpers for whether a function is exported.
1 parent 4bbf543 commit a746433

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

binaryninjaapi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12352,6 +12352,11 @@ namespace BinaryNinja {
1235212352
*/
1235312353
Ref<Symbol> GetSymbol() const;
1235412354

12355+
/*!
12356+
\return Whether the function's symbol is globally or weakly bound (treated as exported)
12357+
*/
12358+
bool IsExported() const;
12359+
1235512360
/*! Whether this function was automatically discovered by analysis
1235612361

1235712362
\return Whether the function was automatically discovered

function.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ Ref<Symbol> Function::GetSymbol() const
202202
return new Symbol(BNGetFunctionSymbol(m_object));
203203
}
204204

205+
bool Function::IsExported() const
206+
{
207+
Ref<Symbol> sym = GetSymbol();
208+
if (!sym)
209+
return false;
210+
211+
SymbolBinding binding = sym->GetBinding();
212+
return (binding == SymbolBinding::GlobalBinding) || (binding == SymbolBinding::WeakBinding);
213+
}
214+
205215

206216
bool Function::WasAutomaticallyDiscovered() const
207217
{

python/function.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Binary Ninja components
2828
from . import _binaryninjacore as core
2929
from .enums import (
30-
AnalysisSkipReason, FunctionGraphType, SymbolType, InstructionTextTokenType, HighlightStandardColor,
30+
AnalysisSkipReason, FunctionGraphType, SymbolType, SymbolBinding, InstructionTextTokenType, HighlightStandardColor,
3131
HighlightColorStyle, DisassemblyOption, IntegerDisplayType, FunctionAnalysisSkipOverride, FunctionUpdateType,
3232
BuiltinType, ExprFolding, EarlyReturn, SwitchRecovery
3333
)
@@ -599,6 +599,16 @@ def symbol(self) -> 'types.CoreSymbol':
599599
assert sym is not None, "core.BNGetFunctionSymbol returned None"
600600
return types.CoreSymbol(sym)
601601

602+
@property
603+
def is_exported(self) -> bool:
604+
"""
605+
Whether the function is exported (read-only).
606+
607+
A function is considered exported when its symbol binding is global or weak.
608+
"""
609+
binding = self.symbol.binding
610+
return binding in (SymbolBinding.GlobalBinding, SymbolBinding.WeakBinding)
611+
602612
@property
603613
def auto(self) -> bool:
604614
"""

rust/src/function.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626
platform::Platform,
2727
references::CodeReference,
2828
string::*,
29-
symbol::Symbol,
29+
symbol::{Binding, Symbol},
3030
tags::{Tag, TagReference, TagType},
3131
types::{IntegerDisplayType, QualifiedName, Type},
3232
};
@@ -344,6 +344,12 @@ impl Function {
344344
}
345345
}
346346

347+
/// Returns true when the function's symbol binding marks it as exported.
348+
pub fn is_exported(&self) -> bool {
349+
let symbol = self.symbol();
350+
matches!(symbol.binding(), Binding::Global | Binding::Weak)
351+
}
352+
347353
pub fn workflow(&self) -> Option<Ref<Workflow>> {
348354
unsafe {
349355
let workflow = NonNull::new(BNGetWorkflowForFunction(self.handle))?;

0 commit comments

Comments
 (0)