From d9ff4032894bd342b6e1ad7c1fd8888363980aaa Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Tue, 2 Dec 2025 20:07:00 -0500 Subject: Remove section semantics workarounds from ABB, use BinaryView interface directly for better performance in presence of many sections. --- defaultabb.cpp | 73 ++++------------------------------------------------------ 1 file changed, 4 insertions(+), 69 deletions(-) (limited to 'defaultabb.cpp') diff --git a/defaultabb.cpp b/defaultabb.cpp index 6c3fc270..71823dd1 100644 --- a/defaultabb.cpp +++ b/defaultabb.cpp @@ -9,45 +9,6 @@ using namespace std; using namespace BinaryNinja; -// TODO: Decomposed from BinaryView::IsOffsetCodeSemantics BinaryView::IsOffsetExternSemantics -// TODO: When the better sections model is merged, remove this -static bool IsOffsetCodeSemanticsFast(BinaryView* data, const vector& readOnlySections, const vector& dataExternSections, uint64_t offset) -{ - if (!data->IsOffsetBackedByFile(offset)) - return false; - - for (const auto& i : readOnlySections) - { - if ((offset >= i->GetStart()) && (offset < i->GetEnd())) - return true; - } - for (const auto& i : dataExternSections) - { - if ((offset >= i->GetStart()) && (offset < i->GetEnd())) - return false; - } - - return data->IsOffsetExecutable(offset); -} - - -static bool IsOffsetExternSemanticsFast(BinaryView* data, const vector& externSections, uint64_t offset) -{ - if (data->IsOffsetBackedByFile(offset)) - return false; - if (data->IsOffsetExecutable(offset)) - return false; - - for (const auto& i : externSections) - { - if ((offset >= i->GetStart()) && (offset < i->GetEnd())) - return true; - } - - return false; -} - - static bool GetNextFunctionAfterAddress(Ref data, Ref platform, uint64_t address, Ref& nextFunc) { uint64_t nextFuncAddr = data->GetNextFunctionStartAfterAddress(address); @@ -93,31 +54,6 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly return (strRef.length >= byteLimit); }; - // TODO: Decomposed from BinaryView::IsOffsetCodeSemantics BinaryView::IsOffsetExternSemantics - // TODO: When the better sections model is merged, remove this - auto sections = data->GetSections(); - vector externSections, readOnlySections, dataExternSections; - externSections.reserve(sections.size()); - readOnlySections.reserve(sections.size()); - dataExternSections.reserve(sections.size()); - for (auto& section: sections) - { - if (section->GetSemantics() == ExternalSectionSemantics) - { - externSections.push_back(section); - } - if (section->GetSemantics() == ReadOnlyCodeSectionSemantics) - { - readOnlySections.push_back(section); - } - if ((section->GetSemantics() == ReadOnlyDataSectionSemantics) || - (section->GetSemantics() == ReadWriteDataSectionSemantics) || - (section->GetSemantics() == ExternalSectionSemantics)) - { - dataExternSections.push_back(section); - } - } - // Start by processing the entry point of the function Ref funcPlatform = function->GetPlatform(); auto start = function->GetStart(); @@ -295,7 +231,7 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly uint64_t instrEnd = location.address + info.length - 1; bool slowPath = !fastValidate || (instrEnd < fastStartAddr) || (instrEnd > fastEndAddr); if (slowPath && - ((!IsOffsetCodeSemanticsFast(data, readOnlySections, dataExternSections, instrEnd) && IsOffsetCodeSemanticsFast(data, readOnlySections, dataExternSections,location.address)) || + ((!data->IsOffsetCodeSemantics(instrEnd) && data->IsOffsetCodeSemantics(location.address)) || (!data->IsOffsetBackedByFile(instrEnd) && data->IsOffsetBackedByFile(location.address)))) { string text = fmt::format("Instruction at {:#x} straddles a non-code section", location.address); @@ -410,7 +346,7 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly // Normal branch, resume disassembly at targets endsBlock = true; // Target of a call instruction, add the function to the analysis - if (IsOffsetExternSemanticsFast(data, externSections, info.branchTarget[i])) + if (data->IsOffsetExternSemantics(info.branchTarget[i])) { // Deal with direct pointers into the extern section DataVariable dataVar; @@ -487,7 +423,7 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly case CallDestination: // Target of a call instruction, add the function to the analysis - if (IsOffsetExternSemanticsFast(data, externSections, info.branchTarget[i])) + if (data->IsOffsetExternSemantics(info.branchTarget[i])) { // Deal with direct pointers into the extern section DataVariable dataVar; @@ -514,8 +450,7 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly { target = ArchAndAddr(info.branchArch[i] ? new CoreArchitecture(info.branchArch[i]) : location.arch, info.branchTarget[i]); - if (!fastPath && !IsOffsetCodeSemanticsFast(data, readOnlySections, dataExternSections, target.address) && - IsOffsetCodeSemanticsFast(data, readOnlySections, dataExternSections, location.address)) + if (!fastPath && !data->IsOffsetCodeSemantics(target.address) && data->IsOffsetCodeSemantics(location.address)) { string message = fmt::format("Non-code call target {:#x}", target.address); function->CreateAutoAddressTag(target.arch, location.address, "Non-code Branch", message, true); -- cgit v1.3.1