Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion view/sharedcache/core/MachOProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ SharedCacheMachOProcessor::SharedCacheMachOProcessor(Ref<BinaryView> view, std::
}
}

static bool HeuristicIsAFunction(Platform* targetPlatform, std::shared_ptr<VirtualMemory> vm, uint64_t func)
{
// Very dumb heuristic which prevents us from creating function at jump tables
if (targetPlatform->GetArchitecture()->GetName() == "aarch64")
{
// disassemble then and ensure it's not a UDF instruction
uint32_t instruction = 0;
size_t instructionLength = 4;
vm->Read(&instruction, func, sizeof(instruction));
std::vector<InstructionTextToken> result;
targetPlatform->GetArchitecture()->GetInstructionText((uint8_t*)&instruction, func, instructionLength, result);
bool isUDF = false;
for (const auto& instructionText : result)
{
if (instructionText.type == BNInstructionTextTokenType::InstructionToken && instructionText.text == "udf")
{
// This is likely a jump table entry, skip creating a function here.
return false;
}
}
}
return true;
}

void SharedCacheMachOProcessor::ApplyHeader(const SharedCache& cache, SharedCacheMachOHeader& header)
{
auto typeLibraryFromName = [&](const std::string& name) -> Ref<TypeLibrary> {
Expand Down Expand Up @@ -52,7 +76,10 @@ void SharedCacheMachOProcessor::ApplyHeader(const SharedCache& cache, SharedCach
auto targetPlatform = m_view->GetDefaultPlatform();
auto functions = header.ReadFunctionTable(*m_vm);
for (const auto& func : functions)
m_view->AddFunctionForAnalysis(targetPlatform, func, false);
{
if (HeuristicIsAFunction(targetPlatform, m_vm, func))
m_view->AddFunctionForAnalysis(targetPlatform, func, false);
}
}

BulkSymbolModification bulkSymbolModification(m_view);
Expand Down