summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Taylor <alex@vector35.com>2025-11-03 14:31:20 -0500
committerAlexander Taylor <alex@vector35.com>2025-11-03 14:34:48 -0500
commit0c55bf12f6148a8f3c4b1af66c950d73e371b351 (patch)
tree18b067b2d5f81a15e726fa7c4c43911f8d774476
parent4bbf5434655da660322205b9db590c524bef4aa8 (diff)
Add helpers for whether a function is exported.
-rw-r--r--binaryninjaapi.h5
-rw-r--r--function.cpp10
-rw-r--r--python/function.py12
-rw-r--r--rust/src/function.rs8
4 files changed, 33 insertions, 2 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 85efc449..57dbb3ac 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -12352,6 +12352,11 @@ namespace BinaryNinja {
*/
Ref<Symbol> GetSymbol() const;
+ /*!
+ \return Whether the function's symbol is globally or weakly bound (treated as exported)
+ */
+ bool IsExported() const;
+
/*! Whether this function was automatically discovered by analysis
\return Whether the function was automatically discovered
diff --git a/function.cpp b/function.cpp
index df41b977..6a4564cd 100644
--- a/function.cpp
+++ b/function.cpp
@@ -202,6 +202,16 @@ Ref<Symbol> Function::GetSymbol() const
return new Symbol(BNGetFunctionSymbol(m_object));
}
+bool Function::IsExported() const
+{
+ Ref<Symbol> sym = GetSymbol();
+ if (!sym)
+ return false;
+
+ BNSymbolBinding binding = sym->GetBinding();
+ return (binding == BNSymbolBinding::GlobalBinding) || (binding == BNSymbolBinding::WeakBinding);
+}
+
bool Function::WasAutomaticallyDiscovered() const
{
diff --git a/python/function.py b/python/function.py
index b56327e1..0996d87f 100644
--- a/python/function.py
+++ b/python/function.py
@@ -27,7 +27,7 @@ from dataclasses import dataclass
# Binary Ninja components
from . import _binaryninjacore as core
from .enums import (
- AnalysisSkipReason, FunctionGraphType, SymbolType, InstructionTextTokenType, HighlightStandardColor,
+ AnalysisSkipReason, FunctionGraphType, SymbolType, SymbolBinding, InstructionTextTokenType, HighlightStandardColor,
HighlightColorStyle, DisassemblyOption, IntegerDisplayType, FunctionAnalysisSkipOverride, FunctionUpdateType,
BuiltinType, ExprFolding, EarlyReturn, SwitchRecovery
)
@@ -600,6 +600,16 @@ class Function:
return types.CoreSymbol(sym)
@property
+ def is_exported(self) -> bool:
+ """
+ Whether the function is exported (read-only).
+
+ A function is considered exported when its symbol binding is global or weak.
+ """
+ binding = self.symbol.binding
+ return binding in (SymbolBinding.GlobalBinding, SymbolBinding.WeakBinding)
+
+ @property
def auto(self) -> bool:
"""
Whether function was automatically discovered (read-only) as a result of some creation of a 'user' function.
diff --git a/rust/src/function.rs b/rust/src/function.rs
index 1a4add05..c0e00bd1 100644
--- a/rust/src/function.rs
+++ b/rust/src/function.rs
@@ -26,7 +26,7 @@ use crate::{
platform::Platform,
references::CodeReference,
string::*,
- symbol::Symbol,
+ symbol::{Binding, Symbol},
tags::{Tag, TagReference, TagType},
types::{IntegerDisplayType, QualifiedName, Type},
};
@@ -344,6 +344,12 @@ impl Function {
}
}
+ /// Returns true when the function's symbol binding marks it as exported.
+ pub fn is_exported(&self) -> bool {
+ let symbol = self.symbol();
+ matches!(symbol.binding(), Binding::Global | Binding::Weak)
+ }
+
pub fn workflow(&self) -> Option<Ref<Workflow>> {
unsafe {
let workflow = NonNull::new(BNGetWorkflowForFunction(self.handle))?;