From a45466fc3227c615c72e77eb7368d7e83220b325 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Tue, 8 Apr 2025 13:17:30 -0400 Subject: Remove notion of image name from objective-c processor This made the macho objective-c processor aware of images and was passed around everywhere, instead we have an overridable section getter that gives the control over the section retrieval to the derived processor. In the case of shared cache this means we can store the image to be processed and then use the header to locate the relevant sections. Fixes: https://github.com/Vector35/binaryninja-api/issues/6594 --- objectivec/objc.cpp | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'objectivec/objc.cpp') diff --git a/objectivec/objc.cpp b/objectivec/objc.cpp index 6f9c3cde..7d110450 100644 --- a/objectivec/objc.cpp +++ b/objectivec/objc.cpp @@ -1119,28 +1119,21 @@ void ObjCProcessor::ApplyMethodTypes(Class& cls) } } -Ref
ObjCProcessor::GetSectionForImage(std::optional imageName, const char* sectionName) +Ref
ObjCProcessor::GetSectionWithName(const char* sectionName) { - if (imageName) - { - return m_data->GetSectionByName(*imageName + "::" + sectionName); - } - else - { - return m_data->GetSectionByName(sectionName); - } + return m_data->GetSectionByName(sectionName); } -void ObjCProcessor::PostProcessObjCSections(ObjCReader* reader, std::optional imageName) +void ObjCProcessor::PostProcessObjCSections(ObjCReader* reader) { auto ptrSize = m_data->GetAddressSize(); - if (auto imageInfo = GetSectionForImage(imageName, "__objc_imageinfo")) + if (auto imageInfo = GetSectionWithName("__objc_imageinfo")) { auto start = imageInfo->GetStart(); auto type = Type::NamedType(m_data, m_typeNames.imageInfo); m_data->DefineDataVariable(start, type); } - if (auto selrefs = GetSectionForImage(imageName, "__objc_selrefs")) + if (auto selrefs = GetSectionWithName("__objc_selrefs")) { auto start = selrefs->GetStart(); auto end = selrefs->GetEnd(); @@ -1163,7 +1156,7 @@ void ObjCProcessor::PostProcessObjCSections(ObjCReader* reader, std::optionalGetStart(); auto end = superRefs->GetEnd(); @@ -1181,7 +1174,7 @@ void ObjCProcessor::PostProcessObjCSections(ObjCReader* reader, std::optionalGetStart(); auto end = superRefs->GetEnd(); @@ -1199,7 +1192,7 @@ void ObjCProcessor::PostProcessObjCSections(ObjCReader* reader, std::optionalGetStart(); auto end = protoRefs->GetEnd(); @@ -1217,7 +1210,7 @@ void ObjCProcessor::PostProcessObjCSections(ObjCReader* reader, std::optionalGetStart(); auto end = ivars->GetEnd(); @@ -1258,7 +1251,7 @@ Ref ObjCProcessor::GetSymbol(uint64_t address) return m_data->GetSymbolByAddress(address); } -void ObjCProcessor::ProcessObjCData(std::optional imageName) +void ObjCProcessor::ProcessObjCData() { m_symbolQueue = new SymbolQueue(); auto addrSize = m_data->GetAddressSize(); @@ -1426,26 +1419,26 @@ void ObjCProcessor::ProcessObjCData(std::optional imageName) m_typeNames.protocol = finalizeStructureBuilder(m_data, protocolBuilder, "objc_protocol_t").first; m_data->BeginBulkModifySymbols(); - if (auto classList = GetSectionForImage(imageName, "__objc_classlist")) + if (auto classList = GetSectionWithName("__objc_classlist")) LoadClasses(reader.get(), classList); - if (auto nonLazyClassList = GetSectionForImage(imageName, "__objc_nlclslist")) + if (auto nonLazyClassList = GetSectionWithName("__objc_nlclslist")) LoadClasses(reader.get(), nonLazyClassList); // See: https://stackoverflow.com/a/15318325 GenerateClassTypes(); for (auto& [_, cls] : m_classes) ApplyMethodTypes(cls); - if (auto catList = GetSectionForImage(imageName, "__objc_catlist")) // Do this after loading class type data. + if (auto catList = GetSectionWithName("__objc_catlist")) // Do this after loading class type data. LoadCategories(reader.get(), catList); - if (auto nonLazyCatList = GetSectionForImage(imageName, "__objc_nlcatlist")) // Do this after loading class type data. + if (auto nonLazyCatList = GetSectionWithName("__objc_nlcatlist")) // Do this after loading class type data. LoadCategories(reader.get(), nonLazyCatList); for (auto& [_, cat] : m_categories) ApplyMethodTypes(cat); - if (auto protoList = GetSectionForImage(imageName, "__objc_protolist")) + if (auto protoList = GetSectionWithName("__objc_protolist")) LoadProtocols(reader.get(), protoList); - PostProcessObjCSections(reader.get(), imageName); + PostProcessObjCSections(reader.get()); auto id = m_data->BeginUndoActions(); m_symbolQueue->Process(); @@ -1460,7 +1453,7 @@ void ObjCProcessor::ProcessObjCData(std::optional imageName) } -void ObjCProcessor::ProcessCFStrings(std::optional imageName) +void ObjCProcessor::ProcessCFStrings() { m_symbolQueue = new SymbolQueue(); uint64_t ptrSize = m_data->GetAddressSize(); @@ -1495,7 +1488,7 @@ void ObjCProcessor::ProcessCFStrings(std::optional imageName) m_typeNames.cfStringUTF16 = type.first; auto reader = GetReader(); - if (auto cfstrings = GetSectionForImage(imageName, "__cfstring")) + if (auto cfstrings = GetSectionWithName("__cfstring")) { auto start = cfstrings->GetStart(); auto end = cfstrings->GetEnd(); -- cgit v1.3.1