From 78ca51fe3e18f9ebff5a6e3d3f5acdf79307a416 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Sat, 23 Dec 2023 18:02:13 +0300 Subject: [PATCH] ok only tuliphook and static libs left --- loader/src/hooks/DynamicCastFix.cpp | 2 + loader/src/platform/android/crashlog.cpp | 226 +---------------------- loader/src/platform/android/gdstdlib.cpp | 28 ++- 3 files changed, 26 insertions(+), 230 deletions(-) diff --git a/loader/src/hooks/DynamicCastFix.cpp b/loader/src/hooks/DynamicCastFix.cpp index fe9b4a05..9119b796 100644 --- a/loader/src/hooks/DynamicCastFix.cpp +++ b/loader/src/hooks/DynamicCastFix.cpp @@ -14,6 +14,8 @@ $execute { ); #elif defined(GEODE_IS_ANDROID32) (void)Mod::get()->addHook(reinterpret_cast(base::get() + (0x720348 - 0x10000) + 1), &cast::typeinfoCastInternal, "__dynamic_cast"); + #elif defined(GEODE_IS_ANDROID64) + (void)Mod::get()->addHook(reinterpret_cast(base::get() + (0xd6cb8c - 0x100000)), &cast::typeinfoCastInternal, "__dynamic_cast"); #endif diff --git a/loader/src/platform/android/crashlog.cpp b/loader/src/platform/android/crashlog.cpp index f73742bf..754c1b58 100644 --- a/loader/src/platform/android/crashlog.cpp +++ b/loader/src/platform/android/crashlog.cpp @@ -1,6 +1,6 @@ #include -#ifdef GEODE_IS_ANDROID32 +#ifdef GEODE_IS_ANDROID using namespace geode::prelude; @@ -65,7 +65,7 @@ static std::string_view getSignalCodeString() { } } -static std::string getImageName(Elf32_Phdr const* image) { +static std::string getImageName(void const* image) { if (image == nullptr) { return ""; } @@ -76,45 +76,10 @@ static std::string getImageName(Elf32_Phdr const* image) { return imageName; } -// static std::vector getAllImages() { -// std::vector images; -// struct task_dyld_info dyldInfo; -// mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT; -// if (task_info(mach_task_self(), TASK_DYLD_INFO, (task_info_t)&dyldInfo, &count) == KERN_SUCCESS) { -// struct dyld_all_image_infos* imageInfos = (struct dyld_all_image_infos*)dyldInfo.all_image_info_addr; - -// for (size_t i = 0; i < imageInfos->infoArrayCount; ++i) { -// images.push_back(&imageInfos->infoArray[i]); -// } -// } - -// return images; -// } - -static Elf32_Phdr const* imageFromAddress(void const* addr) { +static void const* imageFromAddress(void const* addr) { if (addr == nullptr) { return nullptr; } - - // auto loadedImages = getAllImages(); - // std::sort(loadedImages.begin(), loadedImages.end(), [](auto const a, auto const b) { - // return (uintptr_t)a->imageLoadAddress < (uintptr_t)b->imageLoadAddress; - // }); - // auto iter = std::upper_bound(loadedImages.begin(), loadedImages.end(), addr, [](auto const addr, auto const image) { - // return (uintptr_t)addr < (uintptr_t)image->imageLoadAddress; - // }); - - // if (iter == loadedImages.begin()) { - // return nullptr; - // } - // --iter; - - // auto image = *iter; - // // auto imageSize = getImageSize((struct mach_header_64 const*)image->imageLoadAddress); - // auto imageAddress = (uintptr_t)image->imageLoadAddress; - // if ((uintptr_t)addr >= imageAddress/* && (uintptr_t)addr < imageAddress + imageSize*/) { - // return image; - // } return nullptr; } @@ -122,28 +87,6 @@ static Mod* modFromAddress(void const* addr) { if (addr == nullptr) { return nullptr; } - // auto image = imageFromAddress(addr); - // if (image == nullptr) { - // return nullptr; - // } - - // ghc::filesystem::path imagePath = getImageName(image); - // if (!ghc::filesystem::exists(imagePath)) { - // return nullptr; - // } - // auto geodePath = dirs::getGameDir() / "Frameworks" / "Geode.dylib"; - // if (ghc::filesystem::equivalent(imagePath, geodePath)) { - // return Mod::get(); - // } - - // for (auto& mod : Loader::get()->getAllMods()) { - // if (!mod->isEnabled() || !ghc::filesystem::exists(mod->getBinaryPath())) { - // continue; - // } - // if (ghc::filesystem::equivalent(imagePath, mod->getBinaryPath())) { - // return mod; - // } - // } return nullptr; } @@ -217,64 +160,6 @@ static std::string getStacktrace() { // TODO: parse the message stacktrace << message << "\n"; - - - // auto stream = std::stringstream(message); - // int index; - // std::string binary; - // uintptr_t address; - // std::string function; - // uintptr_t offset; - // std::string line; - - // stream >> index; - - // if (!lines.eof()) { - // std::getline(lines, line); - // } - // std::getline(stream, binary); - // auto cutoff = binary.find("0x"); - // stream = std::stringstream(binary.substr(cutoff)); - // binary = geode::utils::string::trim(binary.substr(0, cutoff)); - // stream >> std::hex >> address >> std::dec; - - // if (!line.empty()) { - // // log::debug("address: {}", address); - // auto image = imageFromAddress(reinterpret_cast(address)); - // // log::debug("image: {}", image); - // stacktrace << " - " << std::showbase << std::hex; - - // if (image) { - // auto baseAddress = image->imageLoadAddress; - // auto imageName = getImageName(image); - // stacktrace << imageName << " + " << (address - (uintptr_t)baseAddress); - // } - // else { - // stacktrace << address; - // } - // stacktrace << std::dec; - // stacktrace << ": " << line << "\n"; - // } - // else { - // std::getline(stream, function); - // cutoff = function.find("+"); - // stream = std::stringstream(function.substr(cutoff)); - // stream >> offset; - // function = geode::utils::string::trim(function.substr(0, cutoff)); - - // { - // int status; - // auto demangle = abi::__cxa_demangle(function.c_str(), 0, 0, &status); - // if (status == 0) { - // function = demangle; - // } - // free(demangle); - // } - - // stacktrace << "- " << binary; - // stacktrace << " @ " << std::showbase << std::hex << address << std::dec; - // stacktrace << " (" << function << " + " << offset << ")\n"; - // } } free(messages); @@ -285,29 +170,6 @@ static std::string getStacktrace() { static std::string getRegisters() { std::stringstream registers; - auto context = s_context; - auto& ctx = context->uc_mcontext; - - // geez - registers << std::showbase << std::hex /*<< std::setfill('0') << std::setw(16) */; - registers << "r0: " << ctx.arm_r0 << "\n"; - registers << "r1: " << ctx.arm_r1 << "\n"; - registers << "r2: " << ctx.arm_r2 << "\n"; - registers << "r3: " << ctx.arm_r3 << "\n"; - registers << "r4: " << ctx.arm_r4 << "\n"; - registers << "r5: " << ctx.arm_r5 << "\n"; - registers << "r6: " << ctx.arm_r6 << "\n"; - registers << "r7: " << ctx.arm_r7 << "\n"; - registers << "r8: " << ctx.arm_r8 << "\n"; - registers << "r9: " << ctx.arm_r9 << "\n"; - registers << "r10: " << ctx.arm_r10 << "\n"; - registers << "r11: " << ctx.arm_fp << "\n"; - registers << "r12: " << ctx.arm_ip << "\n"; - registers << "sp: " << ctx.arm_sp << "\n"; - registers << "lr: " << ctx.arm_lr << "\n"; - registers << "pc: " << ctx.arm_pc << "\n"; - registers << "cpsr: " << ctx.arm_cpsr << "\n"; - return registers.str(); } @@ -316,14 +178,6 @@ static void handlerThread() { s_cv.wait(lock, [] { return s_signal != 0; }); auto signalAddress = reinterpret_cast(s_context->uc_mcontext.fault_address); - // Mod* faultyMod = nullptr; - // for (int i = 1; i < s_backtraceSize; ++i) { - // auto mod = modFromAddress(s_backtrace[i]); - // if (mod != nullptr) { - // faultyMod = mod; - // break; - // } - // } Mod* faultyMod = modFromAddress(signalAddress); auto text = crashlog::writeCrashlog(faultyMod, getInfo(signalAddress, faultyMod), getStacktrace(), getRegisters()); @@ -338,80 +192,6 @@ static void handlerThread() { static bool s_lastLaunchCrashed = false; -// bool crashlog::setupPlatformHandler() { -// auto pidFile = crashlog::getCrashLogDirectory() / "last-pid"; - -// int lastPid = 0; - -// if (ghc::filesystem::exists(pidFile)) { - -// auto res = file::readString(pidFile); -// if (!res) { -// log::warn("Failed to read last-pid file: {}", res.error()); -// } -// else { -// lastPid = std::stoi(res.unwrap()); -// } - -// std::error_code ec; -// ghc::filesystem::remove(pidFile, ec); - -// if (ec) { -// log::warn("Failed to remove last-pid file: {}", ec.message()); -// } -// } - -// auto res = file::writeString(pidFile, std::to_string(getpid())); -// if (!res) { -// log::warn("Failed to write last-pid file: {}", res.error()); -// } - -// lastPid = 1513; - - -// if (lastPid == 0) { -// return true; -// } - -// // TODO: get logcat crash - -// std::string logcatCrash = R"RAW()RAW"; - -// std::string crashTrace; -// auto findLast = logcatCrash.find_last_of(fmt::format("pid {} (.geode.launcher)", lastPid)); -// if (findLast != std::string::npos) { -// auto begin = logcatCrash.substr(0, findLast).find_last_of("F/libc"); -// if (begin != std::string::npos) { -// crashTrace = logcatCrash.substr(begin); -// } -// } -// else { -// return true; -// } - -// auto text = crashlog::writeCrashlog(nullptr, "", crashTrace, ""); -// s_lastLaunchCrashed = true; - -// auto lastCrashedFile = crashlog::getCrashLogDirectory() / "last-crashed"; -// if (ghc::filesystem::exists(lastCrashedFile)) { -// std::error_code ec; -// ghc::filesystem::remove(lastCrashedFile, ec); - -// if (ec) { -// log::warn("Failed to remove last-crashed file: {}", ec.message()); -// } -// } -// return true; -// } - -// bool crashlog::didLastLaunchCrash() { -// return s_lastLaunchCrashed; -// } - -// ghc::filesystem::path crashlog::getCrashLogDirectory() { -// return dirs::getGeodeDir() / "crashlogs"; -// } - ghc::filesystem::path crashlog::getCrashLogDirectory() { return dirs::getGeodeDir() / "crashlogs"; } diff --git a/loader/src/platform/android/gdstdlib.cpp b/loader/src/platform/android/gdstdlib.cpp index d41be179..1236df57 100644 --- a/loader/src/platform/android/gdstdlib.cpp +++ b/loader/src/platform/android/gdstdlib.cpp @@ -1,14 +1,30 @@ #include #include "../../c++stl/string-impl.hpp" -#ifdef GEODE_IS_ANDROID32 +#ifdef GEODE_IS_ANDROID + +#if defined(GEODE_IS_ANDROID32) + +static constexpr ptrdiff_t MENULAYER_SCENE = 0x309068 - 0x10000; +static constexpr ptrdiff_t STRING_EMPTY = 0xaa1c3c - 0x10000; +static constexpr ptrdiff_t OPERATOR_DELETE = 0x72033c - 0x10000 + 1; +static constexpr ptrdiff_t STRING_COPY = 0x753a44 - 0x10000 + 1; + +#elif defined(GEODE_IS_ANDROID64) + +static constexpr ptrdiff_t MENULAYER_SCENE = 0x6a62ec - 0x100000; +static constexpr ptrdiff_t STRING_EMPTY = 0x12d8568 - 0x100000; +static constexpr ptrdiff_t OPERATOR_DELETE = 0xd6cb80 - 0x100000; +static constexpr ptrdiff_t STRING_COPY = 0xdb5fdc - 0x100000; + +#endif // 2.2 addition // zmx please fix this namespace geode::base { uintptr_t get() { - static uintptr_t base = (reinterpret_cast(&MenuLayer::scene) - (0x309068 - 0x10000)) & (~0x1); + static uintptr_t base = (reinterpret_cast(&MenuLayer::scene) - MENULAYER_SCENE) & (~0x1); // static uintptr_t base = reinterpret_cast(dlopen("libcocos2dcpp.so", RTLD_NOW)); return base; } @@ -17,7 +33,7 @@ namespace geode::base { namespace geode::stl { static inline auto emptyInternalString() { return reinterpret_cast( - geode::base::get() + (0xaa1c3c - 0x10000) + sizeof(StringData::Internal) + geode::base::get() + STRING_EMPTY + sizeof(StringData::Internal) ); } @@ -28,9 +44,7 @@ namespace geode::stl { void StringImpl::free() { if (data.m_data == nullptr || data.m_data == emptyInternalString()) return; // TODO: reimplement this - reinterpret_cast(geode::base::get() + (0x7514c8 - 0x10000) + 1)(&data); - - + reinterpret_cast(geode::base::get() + OPERATOR_DELETE)(&data.m_data[-1]); } char* StringImpl::getStorage() { @@ -47,7 +61,7 @@ namespace geode::stl { } // TODO: should be using (char*, size_t) at the very least, or yknow, just reimplement it :-) - reinterpret_cast(geode::base::get() + (0x753a44 - 0x10000) + 1)(&data, str.data()); + reinterpret_cast(geode::base::get() + STRING_COPY)(&data, str.data()); return; // TODO: this crashes because we need to use gd's operator new...