diff options
| author | kat <kat@vector35.com> | 2024-07-11 13:48:50 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2024-07-11 16:28:13 -0400 |
| commit | 0bad362009c60a18364a0b153004b6c00aa34653 (patch) | |
| tree | 4af27d0a2c5e26e65b45cb0053c3edf1e312cdae | |
| parent | f7f05179bd9063fad6d3d2e243a7a6d44d6e7f94 (diff) | |
Fix a database upgrade issue regarding mac-aarch64 dbs that are now loaded as ios-aarch64 (skip-ci)
| -rw-r--r-- | platform/mac/platform_mac.cpp | 60 | ||||
| -rw-r--r-- | view/macho/machoview.cpp | 4 |
2 files changed, 51 insertions, 13 deletions
diff --git a/platform/mac/platform_mac.cpp b/platform/mac/platform_mac.cpp index 6a539f66..c922dd18 100644 --- a/platform/mac/platform_mac.cpp +++ b/platform/mac/platform_mac.cpp @@ -108,10 +108,19 @@ public: static Ref<Platform> Recognize(BinaryView* view, Metadata* metadata) { + bool shouldRecognizeOnIOS = false; + if (view->GetFile()->IsBackedByDatabase()) + { + if (auto database = view->GetFile()->GetDatabase()) + { + if (database->HasGlobal("original_version") && database->ReadGlobal("original_version").asInt64() < 6) + shouldRecognizeOnIOS = true; + } + } auto machoPlatform = metadata->Get("machoplatform"); if (!machoPlatform || !machoPlatform->IsUnsignedInteger()) return nullptr; - if (machoPlatform->GetUnsignedInteger() != 2) + if (machoPlatform->GetUnsignedInteger() != 2 || shouldRecognizeOnIOS) return g_macArmv7; return nullptr; @@ -143,10 +152,19 @@ public: static Ref<Platform> Recognize(BinaryView* view, Metadata* metadata) { + bool shouldRecognizeOnIOS = false; + if (view->GetFile()->IsBackedByDatabase()) + { + if (auto database = view->GetFile()->GetDatabase()) + { + if (database->HasGlobal("original_version") && database->ReadGlobal("original_version").asInt64() < 6) + shouldRecognizeOnIOS = true; + } + } auto machoPlatform = metadata->Get("machoplatform"); if (!machoPlatform || !machoPlatform->IsUnsignedInteger()) return nullptr; - if (machoPlatform->GetUnsignedInteger() != 2) + if (machoPlatform->GetUnsignedInteger() != 2 || shouldRecognizeOnIOS) return g_macArm64; return nullptr; @@ -179,12 +197,23 @@ public: static Ref<Platform> Recognize(BinaryView* view, Metadata* metadata) { auto machoPlatform = metadata->Get("machoplatform"); + if (machoPlatform->GetUnsignedInteger() != 2) + return nullptr; if (!machoPlatform || !machoPlatform->IsUnsignedInteger()) return nullptr; - if (machoPlatform->GetUnsignedInteger() == 2) - return g_iosArmv7; - - return nullptr; + if (view->GetFile()->IsBackedByDatabase()) + { + if (auto database = view->GetFile()->GetDatabase()) + { + if (database->HasGlobal("original_version") && database->ReadGlobal("original_version").asInt64() < 6) + { + LogError("%s", "iOS database was saved with mac platform. Unable to upgrade. For iOS typelibs to" + " function properly, this binary must be reopened."); + return nullptr; + } + } + } + return g_iosArmv7; } }; @@ -215,10 +244,21 @@ public: auto machoPlatform = metadata->Get("machoplatform"); if (!machoPlatform || !machoPlatform->IsUnsignedInteger()) return nullptr; - if (machoPlatform->GetUnsignedInteger() == 2) - return g_iosArm64; - - return nullptr; + if (machoPlatform->GetUnsignedInteger() != 2) + return nullptr; + if (view->GetFile()->IsBackedByDatabase()) + { + if (auto database = view->GetFile()->GetDatabase()) + { + if (database->HasGlobal("original_version") && database->ReadGlobal("original_version").asInt64() < 6) + { + LogError("%s", "iOS database was saved with mac platform. Unable to upgrade. For iOS typelibs to" + " function properly, this binary must be reopened."); + return nullptr; + } + } + } + return g_iosArm64; } }; diff --git a/view/macho/machoview.cpp b/view/macho/machoview.cpp index 69cf394a..2180bb96 100644 --- a/view/macho/machoview.cpp +++ b/view/macho/machoview.cpp @@ -1838,8 +1838,6 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_ BinaryReader virtualReader(this); virtualReader.SetEndianness(m_endian); - Ref<Platform> platform = m_plat ? m_plat : g_machoViewType->GetPlatform(0, m_arch); - bool parseObjCStructs = true; bool parseCFStrings = true; if (settings && settings->Contains("loader.macho.processObjectiveC")) @@ -2025,7 +2023,7 @@ bool MachoView::InitializeHeader(MachOHeader& header, bool isMainHeader, uint64_ { m_logger->LogDebug("Parsing function starts\n"); if (header.functionStartsPresent) - ParseFunctionStarts(platform, header.textBase, header.functionStarts); + ParseFunctionStarts(GetDefaultPlatform(), header.textBase, header.functionStarts); } BeginBulkModifySymbols(); |
