From 42fe51aecc09d2d57bfacfa4504e4a1bb0e04281 Mon Sep 17 00:00:00 2001 From: kat Date: Fri, 14 Jun 2024 19:46:39 -0400 Subject: [Objective-C] Mark __objc_ivar as const, define names for class/super refs --- view/macho/objc.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'view/macho/objc.cpp') diff --git a/view/macho/objc.cpp b/view/macho/objc.cpp index 3daaf61e..b2e82fd7 100644 --- a/view/macho/objc.cpp +++ b/view/macho/objc.cpp @@ -967,7 +967,15 @@ void ObjCProcessor::PostProcessObjCSections(BinaryReader* reader) auto type = Type::PointerType(ptrSize, Type::NamedType(m_data, m_typeNames.cls)); for (view_ptr_t i = start; i < end; i += ptrSize) { - m_data->DefineDataVariable(i, type); + reader->Seek(i); + auto clsLoc = ReadPointerAccountingForRelocations(reader); + if (const auto& it = m_classes.find(clsLoc); it != m_classes.end()) + { + auto& cls = it->second; + std::string name = cls.name; + if (!name.empty()) + DefineObjCSymbol(DataSymbol, type, "clsRef_" + name, i, true); + } } } if (auto superRefs = m_data->GetSectionByName("__objc_superrefs")) @@ -976,6 +984,26 @@ void ObjCProcessor::PostProcessObjCSections(BinaryReader* reader) auto end = superRefs->GetEnd(); auto type = Type::PointerType(ptrSize, Type::NamedType(m_data, m_typeNames.cls)); for (view_ptr_t i = start; i < end; i += ptrSize) + { + reader->Seek(i); + auto clsLoc = ReadPointerAccountingForRelocations(reader); + if (const auto& it = m_classes.find(clsLoc); it != m_classes.end()) + { + auto& cls = it->second; + std::string name = cls.name; + if (!name.empty()) + DefineObjCSymbol(DataSymbol, type, "superRef_" + name, i, true); + } + } + } + if (auto ivars = m_data->GetSectionByName("__objc_ivar")) + { + auto start = ivars->GetStart(); + auto end = ivars->GetEnd(); + auto ivarSectionEntryTypeBuilder = new TypeBuilder(Type::IntegerType(8, false)); + ivarSectionEntryTypeBuilder->SetConst(true); + auto type = ivarSectionEntryTypeBuilder->Finalize(); + for (view_ptr_t i = start; i < end; i += ptrSize) { m_data->DefineDataVariable(i, type); } -- cgit v1.3.1