diff options
| author | Brandon Miller <brandon@vector35.com> | 2025-04-25 13:30:45 -0400 |
|---|---|---|
| committer | Ryan Snyder <ryan@vector35.com> | 2025-06-23 13:44:12 -0400 |
| commit | b079d1a1e19151f5c39de84c2e1e6cc6a91abc74 (patch) | |
| tree | 8cf27224630b690fcfdfd490ee43ec1cd56fc9b6 /function.cpp | |
| parent | 76215b86ff629da58aa94d4cf4093d2e67017412 (diff) | |
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
Diffstat (limited to 'function.cpp')
| -rw-r--r-- | function.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/function.cpp b/function.cpp index 2e6b702e..0a4337df 100644 --- a/function.cpp +++ b/function.cpp @@ -319,6 +319,27 @@ vector<Ref<BasicBlock>> Function::GetBasicBlocks() const } +Ref<BasicBlock> 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<BasicBlock> block) +{ + BNAddFunctionBasicBlock(m_object, block->GetObject()); +} + + +void Function::FinalizeBasicBlocks() +{ + BNFinalizeFunctionBasicBlocks(m_object); +} + + Ref<BasicBlock> Function::GetBasicBlockAtAddress(Architecture* arch, uint64_t addr) const { BNBasicBlock* block = BNGetFunctionBasicBlockAtAddress(m_object, arch->GetObject(), addr); @@ -1787,6 +1808,78 @@ vector<IndirectBranchInfo> 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> Function::GetCalleeForAnalysis(Ref<Platform> 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<Function> target) +{ + BNFunctionAddTempOutgoingReference(m_object, target->GetObject()); +} + + +bool Function::HasTempOutgoingReference(Ref<Function> target) const +{ + return BNFunctionHasTempOutgoingReference(m_object, target->GetObject()); +} + + +void Function::AddTempIncomingReference(Ref<Function> 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<uint64_t> Function::GetUnresolvedIndirectBranches() { size_t count; |
