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 --- basicblock.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'basicblock.cpp') diff --git a/basicblock.cpp b/basicblock.cpp index 28ee393b..e178bd6e 100644 --- a/basicblock.cpp +++ b/basicblock.cpp @@ -317,6 +317,12 @@ uint64_t BasicBlock::GetStart() const } +void BasicBlock::SetEnd(uint64_t end) +{ + BNSetBasicBlockEnd(m_object, end); +} + + uint64_t BasicBlock::GetEnd() const { return BNGetBasicBlockEnd(m_object); @@ -385,6 +391,81 @@ bool BasicBlock::HasUndeterminedOutgoingEdges() const } +bool BasicBlock::HasInvalidInstructions() const +{ + return BNBasicBlockHasInvalidInstructions(m_object); +} + + +void BasicBlock::SetHasInvalidInstructions(bool value) +{ + BNBasicBlockSetHasInvalidInstructions(m_object, value); +} + + +void BasicBlock::AddPendingOutgoingEdge(BNBranchType type, uint64_t addr, Ref arch, bool fallThrough) +{ + BNBasicBlockAddPendingOutgoingEdge(m_object, type, addr, arch ? arch->GetObject() : nullptr, fallThrough); +} + + +vector BasicBlock::GetPendingOutgoingEdges() const +{ + size_t count; + BNPendingBasicBlockEdge* edges = BNGetBasicBlockPendingOutgoingEdges(m_object, &count); + vector result; + result.reserve(count); + for (size_t i = 0; i < count; i++) + { + PendingBasicBlockEdge edge; + edge.type = edges[i].type; + edge.arch = edges[i].arch ? new CoreArchitecture(edges[i].arch) : nullptr; + edge.target = edges[i].target; + edge.fallThrough = edges[i].fallThrough; + result.push_back(edge); + } + + BNFreePendingBasicBlockEdgeList(edges); + return result; +} + + +void BasicBlock::ClearPendingOutgoingEdges() +{ + BNClearBasicBlockPendingOutgoingEdges(m_object); +} + + +void BasicBlock::SetUndeterminedOutgoingEdges(bool value) +{ + BNBasicBlockSetUndeterminedOutgoingEdges(m_object, value); +} + + +const uint8_t* BasicBlock::GetInstructionData(uint64_t addr, size_t* len) const +{ + return BNBasicBlockGetInstructionData(m_object, addr, len); +} + + +void BasicBlock::AddInstructionData(const void* data, size_t len) +{ + BNBasicBlockAddInstructionData(m_object, data, len); +} + + +void BasicBlock::SetFallThroughToFunction(bool value) +{ + BNBasicBlockSetFallThroughToFunction(m_object, value); +} + + +bool BasicBlock::IsFallThroughToFunction() const +{ + return BNBasicBlockIsFallThroughToFunction(m_object); +} + + bool BasicBlock::CanExit() const { return BNBasicBlockCanExit(m_object); -- cgit v1.3.1