From ecf2b3dd3e14d8ed0a3485104eaaa34a372228ba Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Wed, 25 Jun 2025 15:12:23 -0400 Subject: Initial support for guided disassembly. --- defaultabb.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'defaultabb.cpp') diff --git a/defaultabb.cpp b/defaultabb.cpp index df5d0c5c..477e5722 100644 --- a/defaultabb.cpp +++ b/defaultabb.cpp @@ -76,6 +76,13 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly auto& directNoReturnCalls = context.GetDirectNoReturnCalls(); auto& haltedDisassemblyAddresses = context.GetHaltedDisassemblyAddresses(); + bool hasInvalidInstructions = false; + set guidedSourceBlockTargets; + auto guidedSourceBlocks = function->GetGuidedSourceBlocks(); + set guidedSourceBlocksSet; + for (const auto& block : guidedSourceBlocks) + guidedSourceBlocksSet.insert(block); + BNStringReference strRef; auto targetExceedsByteLimit = [](const BNStringReference& strRef) { size_t byteLimit = 8; @@ -164,6 +171,8 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly ArchAndAddr instructionGroupStart = location; blocksToProcess.pop(); + bool isGuidedSourceBlock = guidedSourceBlocksSet.count(location) ? true : false; + // Create a new basic block Ref block = context.CreateBasicBlock(location.arch, location.address); @@ -385,6 +394,8 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly } else { + if (isGuidedSourceBlock) + guidedSourceBlockTargets.insert(target); block->AddPendingOutgoingEdge(info.branchType[i], target.address, target.arch); // Add the block to the list of blocks to process if it is not already processed @@ -507,6 +518,9 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly if (translateTailCalls && data->GetAnalysisFunction(targetPlatform, branch.address)) continue; + if (isGuidedSourceBlock) + guidedSourceBlockTargets.insert(branch); + block->AddPendingOutgoingEdge(IndirectBranch, branch.address, branch.arch); if (seenBlocks.count(branch) == 0) { @@ -644,13 +658,21 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly break; if (haltOnInvalidInstructions && block->HasInvalidInstructions()) + hasInvalidInstructions = true; + + if (hasInvalidInstructions) { + queue guidedBlocksToProcess; while (!blocksToProcess.empty()) { auto i = blocksToProcess.front(); blocksToProcess.pop(); - haltedDisassemblyAddresses.emplace(i); + if (guidedSourceBlockTargets.count(i)) + guidedBlocksToProcess.emplace(i); + else + haltedDisassemblyAddresses.emplace(i); } + blocksToProcess = guidedBlocksToProcess; } } -- cgit v1.3.1