From b079d1a1e19151f5c39de84c2e1e6cc6a91abc74 Mon Sep 17 00:00:00 2001 From: Brandon Miller Date: Fri, 25 Apr 2025 13:30:45 -0400 Subject: Perform BB analysis from Architecture C++ API This commit moves AnalyzeBasicBlocks from the binary ninja core to the API and allows architecture plugins to optionally override AnalyzeBasicBlocks for a custom implementation Supply ABB inputs in BNBasicBlockAnalysisContext Register default analyze basic blocks callback This allows the nanomips and rust core architecture plugins to work again while using the C++ API DefaultAnalyzeBasicBlocks Use default ABB from Python plugins Fix bug in API ArchAndAddr operator overload Python APIs for basic block analysis --- function.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'function.cpp') diff --git a/function.cpp b/function.cpp index 2e6b702e..0a4337df 100644 --- a/function.cpp +++ b/function.cpp @@ -319,6 +319,27 @@ vector> Function::GetBasicBlocks() const } +Ref Function::CreateBasicBlock(Architecture* arch, uint64_t addr) +{ + BNBasicBlock* block = BNCreateFunctionBasicBlock(m_object, arch->GetObject(), addr); + if (!block) + return nullptr; + return new BasicBlock(block); +} + + +void Function::AddBasicBlock(Ref block) +{ + BNAddFunctionBasicBlock(m_object, block->GetObject()); +} + + +void Function::FinalizeBasicBlocks() +{ + BNFinalizeFunctionBasicBlocks(m_object); +} + + Ref Function::GetBasicBlockAtAddress(Architecture* arch, uint64_t addr) const { BNBasicBlock* block = BNGetFunctionBasicBlockAtAddress(m_object, arch->GetObject(), addr); @@ -1787,6 +1808,78 @@ vector Function::GetIndirectBranchesAt(Architecture* arch, u } +void Function::AddDirectCodeReference(const ArchAndAddr& source, uint64_t target) +{ + BNArchitectureAndAddress bnSource; + bnSource.arch = source.arch->GetObject(); + bnSource.address = source.address; + BNFunctionAddDirectCodeReference(m_object, &bnSource, target); +} + + +void Function::AddDirectNoReturnCall(const ArchAndAddr& location) +{ + BNArchitectureAndAddress bnLocation; + bnLocation.arch = location.arch->GetObject(); + bnLocation.address = location.address; + BNFunctionAddDirectNoReturnCall(m_object, &bnLocation); +} + + +bool Function::LocationHasNoReturnCalls(const ArchAndAddr& location) const +{ + BNArchitectureAndAddress bnLocation; + bnLocation.arch = location.arch->GetObject(); + bnLocation.address = location.address; + return BNFunctionLocationHasNoReturnCalls(m_object, &bnLocation); +} + + +Ref Function::GetCalleeForAnalysis(Ref platform, uint64_t addr, bool exact) +{ + BNFunction* func = BNGetCalleeForAnalysis(m_object, platform->GetObject(), addr, exact); + if (!func) + return nullptr; + return new Function(func); +} + + +void Function::AddTempOutgoingReference(Ref target) +{ + BNFunctionAddTempOutgoingReference(m_object, target->GetObject()); +} + + +bool Function::HasTempOutgoingReference(Ref target) const +{ + return BNFunctionHasTempOutgoingReference(m_object, target->GetObject()); +} + + +void Function::AddTempIncomingReference(Ref source) +{ + BNFunctionAddTempIncomingReference(m_object, source->GetObject()); +} + + +bool Function::GetContextualFunctionReturn(const ArchAndAddr& location, bool& value) const +{ + BNArchitectureAndAddress bnLocation; + bnLocation.arch = location.arch->GetObject(); + bnLocation.address = location.address; + return BNFunctionGetContextualFunctionReturn(m_object, &bnLocation, &value); +} + + +void Function::SetContextualFunctionReturn(const ArchAndAddr& location, bool value) +{ + BNArchitectureAndAddress bnLocation; + bnLocation.arch = location.arch->GetObject(); + bnLocation.address = location.address; + BNFunctionSetContextualFunctionReturn(m_object, &bnLocation, value); +} + + vector Function::GetUnresolvedIndirectBranches() { size_t count; -- cgit v1.3.1