From 794dded30f95b242426e841d7a7204ea46954af1 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Fri, 18 Aug 2023 11:04:53 +0300 Subject: [PATCH] Revert "replace macos entry with objc hook" --- loader/src/platform/mac/main.mm | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/loader/src/platform/mac/main.mm b/loader/src/platform/mac/main.mm index 770dbd21..ec92b1cd 100644 --- a/loader/src/platform/mac/main.mm +++ b/loader/src/platform/mac/main.mm @@ -14,7 +14,6 @@ #include "../../loader/LoaderImpl.hpp" #include #include -#include using namespace geode::prelude; @@ -112,26 +111,38 @@ void updateGeode() { extern "C" void fake() {} -static IMP s_applicationDidFinishLaunching; -void applicationDidFinishLaunching(id self, SEL sel, NSNotification* notification) { +void applicationDidFinishLaunchingHook(void* self, SEL sel, NSNotification* notification) { updateGeode(); + std::array patchBytes = { + 0x55, + 0x48, 0x89, 0xe5, + 0x41, 0x57 + }; + + auto res = tulip::hook::writeMemory((void*)(base::get() + 0x69a0), patchBytes.data(), 6); + if (!res) + return; + int exitCode = geodeEntry(nullptr); if (exitCode != 0) return; - - using Type = decltype(&applicationDidFinishLaunching); - return reinterpret_cast(s_applicationDidFinishLaunching)(self, sel, notification); + + return reinterpret_cast(geode::base::get() + 0x69a0)(self, sel, notification); } bool loadGeode() { - Class class_ = objc_getClass("AppController"); - SEL selector = @selector(applicationDidFinishLaunching:); - IMP function = (IMP)applicationDidFinishLaunching; - using Type = decltype(&applicationDidFinishLaunching); + auto detourAddr = reinterpret_cast(&applicationDidFinishLaunchingHook) - geode::base::get() - 0x69a5; + auto detourAddrPtr = reinterpret_cast(&detourAddr); - s_applicationDidFinishLaunching = class_replaceMethod(class_, selector, function, @encode(Type)); + std::array patchBytes = { + 0xe9, detourAddrPtr[0], detourAddrPtr[1], detourAddrPtr[2], detourAddrPtr[3] + }; + + auto res = tulip::hook::writeMemory((void*)(base::get() + 0x69a0), patchBytes.data(), 5); + if (!res) + return false; return true; }