summaryrefslogtreecommitdiff
path: root/defaultabb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'defaultabb.cpp')
-rw-r--r--defaultabb.cpp73
1 files changed, 4 insertions, 69 deletions
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<Section*>& readOnlySections, const vector<Section*>& 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<Section*>& 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<BinaryView> data, Ref<Platform> platform, uint64_t address, Ref<Function>& 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<Section*> 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<Platform> 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);