@@ -308,12 +308,12 @@ bool Architecture::GetInstructionLowLevelILCallback(
308308}
309309
310310
311- bool Architecture::AnalyzeBasicBlocksCallback (void *ctxt, BNFunction* function,
312- bool incrementalUpdate, BNFunctionAnalysisSkipOverride analysisSkipOverride )
311+ void Architecture::AnalyzeBasicBlocksCallback (void *ctxt, BNFunction* function,
312+ BNBasicBlockAnalysisContext* context )
313313{
314314 CallbackRef<Architecture> arch (ctxt);
315315 Ref<Function> func (new Function (BNNewFunctionReference (function)));
316- return arch->AnalyzeBasicBlocks (*func, incrementalUpdate, analysisSkipOverride );
316+ arch->AnalyzeBasicBlocks (*func, context );
317317}
318318
319319
@@ -983,36 +983,20 @@ static bool GetNextFunctionAfterAddress(Ref<BinaryView> data, Ref<Platform> plat
983983}
984984
985985
986- bool Architecture::AnalyzeBasicBlocks (Function& function, bool incrementalUpdate, BNFunctionAnalysisSkipOverride analysisSkipOverride )
986+ void Architecture::AnalyzeBasicBlocks (Function& function, BNBasicBlockAnalysisContext* context )
987987{
988988 auto data = function.GetView ();
989989 queue<ArchAndAddr> blocksToProcess;
990990 map<ArchAndAddr, Ref<BasicBlock>> instrBlocks;
991991 set<ArchAndAddr> seenBlocks;
992-
993- // TODO - we might just want to create a generic analysis settings object that includes all of these
994- // bool tailCallTranslation = function.GetSettingsCache()->Get<bool>("core.function.translateTailCalls");
995- bool tailCallTranslation = true ;
996- // bool disallowBranchToString = owner->IsDisallowBranchToStringEnabled();
997- bool disallowBranchToString = false ;
998-
999- // TODO: add an API for querying ONLY the indirect branches that are auto-defined
1000- auto indirectBranches = function.GetAutoIndirectBranches ();
1001- map<ArchAndAddr, set<ArchAndAddr>> autoIndirectBranches;
1002- for (auto & branchInfo : indirectBranches)
1003- {
1004- auto sourceLocation = ArchAndAddr (branchInfo.sourceArch , branchInfo.sourceAddr );
1005- auto destLocation = ArchAndAddr (branchInfo.destArch , branchInfo.destAddr );
1006- autoIndirectBranches[sourceLocation].insert (destLocation);
1007- }
1008-
1009- map<ArchAndAddr, set<ArchAndAddr>> userIndirectBranches;
1010- indirectBranches = function.GetUserIndirectBranches ();
1011- for (auto & branchInfo : indirectBranches)
992+ map<ArchAndAddr, set<ArchAndAddr>> indirectBranches;
993+ for (size_t i = 0 ; i < context->indirectBranchesCount ; i++)
1012994 {
1013- auto sourceLocation = ArchAndAddr (branchInfo.sourceArch , branchInfo.sourceAddr );
1014- auto destLocation = ArchAndAddr (branchInfo.destArch , branchInfo.destAddr );
1015- userIndirectBranches[sourceLocation].insert (destLocation);
995+ auto sourceLocation = ArchAndAddr (new CoreArchitecture (context->indirectBranches [i].sourceArch ),
996+ context->indirectBranches [i].sourceAddr );
997+ auto destLocation = ArchAndAddr (new CoreArchitecture (context->indirectBranches [i].destArch ),
998+ context->indirectBranches [i].destAddr );
999+ indirectBranches[sourceLocation].insert (destLocation);
10161000 }
10171001
10181002 BNStringReference strRef;
@@ -1091,11 +1075,11 @@ bool Architecture::AnalyzeBasicBlocks(Function& function, bool incrementalUpdate
10911075 }
10921076
10931077 uint64_t totalSize = 0 ;
1094- uint64_t maxSize = data-> GetMaxFunctionSizeForAnalysis () ;
1078+ uint64_t maxSize = context-> maxFunctionSize ;
10951079 while (blocksToProcess.size () != 0 )
10961080 {
10971081 if (data->AnalysisIsAborted ())
1098- return true ;
1082+ return ;
10991083
11001084 // Get the next block to process
11011085 ArchAndAddr location = blocksToProcess.front ();
@@ -1120,7 +1104,7 @@ bool Architecture::AnalyzeBasicBlocks(Function& function, bool incrementalUpdate
11201104 while (true )
11211105 {
11221106 if (data->AnalysisIsAborted ())
1123- return true ;
1107+ return ;
11241108
11251109 if (!delaySlotCount)
11261110 {
@@ -1298,7 +1282,7 @@ bool Architecture::AnalyzeBasicBlocks(Function& function, bool incrementalUpdate
12981282 function.AddDirectCodeReference (location, info.branchTarget [i]);
12991283
13001284 auto otherFunc = function.GetCalleeForAnalysis (targetPlatform, target.address , true );
1301- if (tailCallTranslation && targetPlatform && otherFunc && (otherFunc->GetStart () != function.GetStart ()))
1285+ if (context-> translateTailCalls && targetPlatform && otherFunc && (otherFunc->GetStart () != function.GetStart ()))
13021286 {
13031287 calledFunctions.insert (otherFunc);
13041288 if (info.branchType [i] == UnconditionalBranch)
@@ -1313,7 +1297,7 @@ bool Architecture::AnalyzeBasicBlocks(Function& function, bool incrementalUpdate
13131297 break ;
13141298 }
13151299 }
1316- else if (disallowBranchToString && data->GetStringAtAddress (location.address , strRef) && targetExceedsByteLimit (strRef))
1300+ else if (context-> disallowBranchToString && data->GetStringAtAddress (location.address , strRef) && targetExceedsByteLimit (strRef))
13171301 {
13181302 BNLogInfo (" Not adding branch target from 0x%" PRIx64 " to string at 0x%" PRIx64
13191303 " length:%zu" ,
@@ -1433,15 +1417,8 @@ bool Architecture::AnalyzeBasicBlocks(Function& function, bool incrementalUpdate
14331417 }
14341418 }
14351419
1436- indirectBranchIter = userIndirectBranches.find (location);
1437- endIter = userIndirectBranches.end ();
1438-
1439- if (indirectBranchIter == endIter)
1440- {
1441- indirectBranchIter = autoIndirectBranches.find (location);
1442- endIter = autoIndirectBranches.end ();
1443- }
1444-
1420+ indirectBranchIter = indirectBranches.find (location);
1421+ endIter = indirectBranches.end ();
14451422 if (indirectBranchIter != endIter)
14461423 {
14471424 for (auto & branch : indirectBranchIter->second )
@@ -1452,7 +1429,7 @@ bool Architecture::AnalyzeBasicBlocks(Function& function, bool incrementalUpdate
14521429 targetPlatform = funcPlatform->GetRelatedPlatform (branch.arch );
14531430
14541431 // Normal analysis should not inline indirect targets that are function starts
1455- if (tailCallTranslation && data->GetAnalysisFunction (targetPlatform, branch.address ))
1432+ if (context-> translateTailCalls && data->GetAnalysisFunction (targetPlatform, branch.address ))
14561433 continue ;
14571434
14581435 block->AddPendingOutgoingEdge (IndirectBranch, branch.address , branch.arch );
@@ -1539,10 +1516,10 @@ bool Architecture::AnalyzeBasicBlocks(Function& function, bool incrementalUpdate
15391516 // We prefer to allow disassembly when function analysis is disabled, but only up to the maximum size.
15401517 // The log message and tag are generated in ProcessAnalysisSkip
15411518 totalSize += info.length ;
1542- if (analysisSkipOverride == NeverSkipFunctionAnalysis)
1519+ if (context-> analysisSkipOverride == NeverSkipFunctionAnalysis)
15431520 maxSize = 0 ;
1544- else if (!maxSize && (analysisSkipOverride == AlwaysSkipFunctionAnalysis))
1545- maxSize = data-> GetMaxFunctionSizeForAnalysis () ;
1521+ else if (!maxSize && (context-> analysisSkipOverride == AlwaysSkipFunctionAnalysis))
1522+ maxSize = context-> maxFunctionSize ;
15461523 if (maxSize && (totalSize > maxSize))
15471524 break ;
15481525
@@ -1558,7 +1535,7 @@ bool Architecture::AnalyzeBasicBlocks(Function& function, bool incrementalUpdate
15581535 delayInstructionEndsBlock = endsBlock;
15591536 }
15601537
1561- if (block->CanExit () && tailCallTranslation && !delaySlotCount && hasNextFunc && (location.address == nextFuncAddr))
1538+ if (block->CanExit () && context-> translateTailCalls && !delaySlotCount && hasNextFunc && (location.address == nextFuncAddr))
15621539 {
15631540 // Falling through into another function. Don't consider this a tail call if the current block
15641541 // called the function, as this indicates a get PC construct.
@@ -1587,7 +1564,6 @@ bool Architecture::AnalyzeBasicBlocks(Function& function, bool incrementalUpdate
15871564
15881565 // Finalize the function basic block list
15891566 function.FinalizeBasicBlocks ();
1590- return true ;
15911567}
15921568
15931569
@@ -2151,10 +2127,9 @@ bool CoreArchitecture::GetInstructionLowLevelIL(const uint8_t* data, uint64_t ad
21512127}
21522128
21532129
2154- bool CoreArchitecture::AnalyzeBasicBlocks (Function& function, bool incrementalUpdate,
2155- BNFunctionAnalysisSkipOverride analysisSkipOverride)
2130+ void CoreArchitecture::AnalyzeBasicBlocks (Function& function, BNBasicBlockAnalysisContext* context)
21562131{
2157- return BNArchitectureAnalyzeBasicBlocks (m_object, function.GetObject (), incrementalUpdate, analysisSkipOverride );
2132+ BNArchitectureAnalyzeBasicBlocks (m_object, function.GetObject (), context );
21582133}
21592134
21602135
0 commit comments