From b34393c33a82050dcb5e65d5fc7d36960c18e167 Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Wed, 8 Jan 2025 14:52:33 -0500 Subject: Prevent crash when Mach-O view doesn't exist --- platform/mac/platform_mac.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'platform') diff --git a/platform/mac/platform_mac.cpp b/platform/mac/platform_mac.cpp index 6c2adf7a..2eec7f53 100644 --- a/platform/mac/platform_mac.cpp +++ b/platform/mac/platform_mac.cpp @@ -283,13 +283,14 @@ extern "C" BINARYNINJAPLUGIN bool CorePluginInit() #endif { - auto viewType = BinaryViewType::GetByName("Mach-O"); + Ref viewType = BinaryViewType::GetByName("Mach-O"); Ref x86 = Architecture::GetByName("x86"); if (x86) { g_macX86 = new MacX86Platform(x86); Platform::Register("mac", g_macX86); - viewType->RegisterPlatformRecognizer(7, LittleEndian, MacX86Platform::Recognize); + if (viewType) + viewType->RegisterPlatformRecognizer(7, LittleEndian, MacX86Platform::Recognize); } Ref x64 = Architecture::GetByName("x86_64"); @@ -297,7 +298,8 @@ extern "C" { g_macX64 = new MacX64Platform(x64); Platform::Register("mac", g_macX64); - viewType->RegisterPlatformRecognizer(0x01000007, LittleEndian, MacX64Platform::Recognize); + if (viewType) + viewType->RegisterPlatformRecognizer(0x01000007, LittleEndian, MacX64Platform::Recognize); } Ref armv7 = Architecture::GetByName("armv7"); @@ -316,8 +318,11 @@ extern "C" Platform::Register("ios", g_iosArmv7); Platform::Register("mac", g_macThumb2); Platform::Register("ios", g_iosThumb2); - viewType->RegisterPlatformRecognizer(0xc, LittleEndian, MacArmv7Platform::Recognize); - viewType->RegisterPlatformRecognizer(0xc, LittleEndian, IOSArmv7Platform::Recognize); + if (viewType) + { + viewType->RegisterPlatformRecognizer(0xc, LittleEndian, MacArmv7Platform::Recognize); + viewType->RegisterPlatformRecognizer(0xc, LittleEndian, IOSArmv7Platform::Recognize); + } } Ref arm64 = Architecture::GetByName("aarch64"); @@ -327,11 +332,14 @@ extern "C" g_iosArm64 = new IOSArm64Platform(arm64); Platform::Register("mac", g_macArm64); Platform::Register("ios", g_iosArm64); - viewType->RegisterPlatformRecognizer(0, LittleEndian, MacArm64Platform::Recognize); - viewType->RegisterPlatformRecognizer(0x0100000c, LittleEndian, MacArm64Platform::Recognize); - viewType->RegisterPlatformRecognizer(0x0200000c, LittleEndian, MacArm64Platform::Recognize); - viewType->RegisterPlatformRecognizer(0, LittleEndian, IOSArm64Platform::Recognize); - viewType->RegisterPlatformRecognizer(0x0100000c, LittleEndian, IOSArm64Platform::Recognize); + if (viewType) + { + viewType->RegisterPlatformRecognizer(0, LittleEndian, MacArm64Platform::Recognize); + viewType->RegisterPlatformRecognizer(0x0100000c, LittleEndian, MacArm64Platform::Recognize); + viewType->RegisterPlatformRecognizer(0x0200000c, LittleEndian, MacArm64Platform::Recognize); + viewType->RegisterPlatformRecognizer(0, LittleEndian, IOSArm64Platform::Recognize); + viewType->RegisterPlatformRecognizer(0x0100000c, LittleEndian, IOSArm64Platform::Recognize); + } } return true; -- cgit v1.3.1