99using namespace std ;
1010using namespace BinaryNinja ;
1111
12- // TODO: Decomposed from BinaryView::IsOffsetCodeSemantics BinaryView::IsOffsetExternSemantics
13- // TODO: When the better sections model is merged, remove this
14- static bool IsOffsetCodeSemanticsFast (BinaryView* data, const vector<Section*>& readOnlySections, const vector<Section*>& dataExternSections, uint64_t offset)
15- {
16- if (!data->IsOffsetBackedByFile (offset))
17- return false ;
18-
19- for (const auto & i : readOnlySections)
20- {
21- if ((offset >= i->GetStart ()) && (offset < i->GetEnd ()))
22- return true ;
23- }
24- for (const auto & i : dataExternSections)
25- {
26- if ((offset >= i->GetStart ()) && (offset < i->GetEnd ()))
27- return false ;
28- }
29-
30- return data->IsOffsetExecutable (offset);
31- }
32-
33-
34- static bool IsOffsetExternSemanticsFast (BinaryView* data, const vector<Section*>& externSections, uint64_t offset)
35- {
36- if (data->IsOffsetBackedByFile (offset))
37- return false ;
38- if (data->IsOffsetExecutable (offset))
39- return false ;
40-
41- for (const auto & i : externSections)
42- {
43- if ((offset >= i->GetStart ()) && (offset < i->GetEnd ()))
44- return true ;
45- }
46-
47- return false ;
48- }
49-
50-
5112static bool GetNextFunctionAfterAddress (Ref<BinaryView> data, Ref<Platform> platform, uint64_t address, Ref<Function>& nextFunc)
5213{
5314 uint64_t nextFuncAddr = data->GetNextFunctionStartAfterAddress (address);
@@ -93,31 +54,6 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly
9354 return (strRef.length >= byteLimit);
9455 };
9556
96- // TODO: Decomposed from BinaryView::IsOffsetCodeSemantics BinaryView::IsOffsetExternSemantics
97- // TODO: When the better sections model is merged, remove this
98- auto sections = data->GetSections ();
99- vector<Section*> externSections, readOnlySections, dataExternSections;
100- externSections.reserve (sections.size ());
101- readOnlySections.reserve (sections.size ());
102- dataExternSections.reserve (sections.size ());
103- for (auto & section: sections)
104- {
105- if (section->GetSemantics () == ExternalSectionSemantics)
106- {
107- externSections.push_back (section);
108- }
109- if (section->GetSemantics () == ReadOnlyCodeSectionSemantics)
110- {
111- readOnlySections.push_back (section);
112- }
113- if ((section->GetSemantics () == ReadOnlyDataSectionSemantics) ||
114- (section->GetSemantics () == ReadWriteDataSectionSemantics) ||
115- (section->GetSemantics () == ExternalSectionSemantics))
116- {
117- dataExternSections.push_back (section);
118- }
119- }
120-
12157 // Start by processing the entry point of the function
12258 Ref<Platform> funcPlatform = function->GetPlatform ();
12359 auto start = function->GetStart ();
@@ -295,7 +231,7 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly
295231 uint64_t instrEnd = location.address + info.length - 1 ;
296232 bool slowPath = !fastValidate || (instrEnd < fastStartAddr) || (instrEnd > fastEndAddr);
297233 if (slowPath &&
298- ((!IsOffsetCodeSemanticsFast ( data, readOnlySections, dataExternSections, instrEnd) && IsOffsetCodeSemanticsFast ( data, readOnlySections, dataExternSections, location.address )) ||
234+ ((!data-> IsOffsetCodeSemantics ( instrEnd) && data-> IsOffsetCodeSemantics ( location.address )) ||
299235 (!data->IsOffsetBackedByFile (instrEnd) && data->IsOffsetBackedByFile (location.address ))))
300236 {
301237 string text = fmt::format (" Instruction at {:#x} straddles a non-code section" , location.address );
@@ -410,7 +346,7 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly
410346 // Normal branch, resume disassembly at targets
411347 endsBlock = true ;
412348 // Target of a call instruction, add the function to the analysis
413- if (IsOffsetExternSemanticsFast ( data, externSections, info.branchTarget [i]))
349+ if (data-> IsOffsetExternSemantics ( info.branchTarget [i]))
414350 {
415351 // Deal with direct pointers into the extern section
416352 DataVariable dataVar;
@@ -487,7 +423,7 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly
487423
488424 case CallDestination:
489425 // Target of a call instruction, add the function to the analysis
490- if (IsOffsetExternSemanticsFast ( data, externSections, info.branchTarget [i]))
426+ if (data-> IsOffsetExternSemantics ( info.branchTarget [i]))
491427 {
492428 // Deal with direct pointers into the extern section
493429 DataVariable dataVar;
@@ -514,8 +450,7 @@ void Architecture::DefaultAnalyzeBasicBlocks(Function* function, BasicBlockAnaly
514450 {
515451 target = ArchAndAddr (info.branchArch [i] ? new CoreArchitecture (info.branchArch [i]) : location.arch , info.branchTarget [i]);
516452
517- if (!fastPath && !IsOffsetCodeSemanticsFast (data, readOnlySections, dataExternSections, target.address ) &&
518- IsOffsetCodeSemanticsFast (data, readOnlySections, dataExternSections, location.address ))
453+ if (!fastPath && !data->IsOffsetCodeSemantics (target.address ) && data->IsOffsetCodeSemantics (location.address ))
519454 {
520455 string message = fmt::format (" Non-code call target {:#x}" , target.address );
521456 function->CreateAutoAddressTag (target.arch , location.address , " Non-code Branch" , message, true );
0 commit comments