From bac025dbf68066d0d4a72646bc77457cd818ee6c Mon Sep 17 00:00:00 2001 From: pixel-stuck Date: Tue, 24 May 2022 06:02:44 -0400 Subject: [PATCH] Add mechanism for handling version differences and update for 2.1.0 --- source/nn.hpp | 3 ++- source/nn/oe.hpp | 3 +++ source/nn/oe/application_proxy.hpp | 13 +++++++++++++ source/program/main.cpp | 31 ++++++++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 source/nn/oe.hpp create mode 100644 source/nn/oe/application_proxy.hpp diff --git a/source/nn.hpp b/source/nn.hpp index ea628ac..24c9011 100644 --- a/source/nn.hpp +++ b/source/nn.hpp @@ -7,4 +7,5 @@ #include "nn/fs.hpp" #include "nn/os.hpp" -#include "nn/time.hpp" \ No newline at end of file +#include "nn/time.hpp" +#include "nn/oe.hpp" \ No newline at end of file diff --git a/source/nn/oe.hpp b/source/nn/oe.hpp new file mode 100644 index 0000000..05820c5 --- /dev/null +++ b/source/nn/oe.hpp @@ -0,0 +1,3 @@ +#pragma once + +#include "nn/oe/application_proxy.hpp" \ No newline at end of file diff --git a/source/nn/oe/application_proxy.hpp b/source/nn/oe/application_proxy.hpp new file mode 100644 index 0000000..28bbe2a --- /dev/null +++ b/source/nn/oe/application_proxy.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace nn::oe +{ + typedef struct + { + char displayVersion[16]; + } DisplayVersion; + + void GetDisplayVersion(DisplayVersion *displayVersion); +} \ No newline at end of file diff --git a/source/program/main.cpp b/source/program/main.cpp index 7eb0682..2ae5ef8 100644 --- a/source/program/main.cpp +++ b/source/program/main.cpp @@ -116,18 +116,45 @@ MAKE_HOOK_T(Result, romMounted, (char const *path, void *romCache, unsigned long return res; ); +typedef struct +{ + uintptr_t crc64; + uintptr_t CFilePathStrIdCtor; +} functionOffsets; + +/* Handle version differences */ +void getVersionOffsets(functionOffsets *offsets) +{ + nn::oe::DisplayVersion dispVer; + nn::oe::GetDisplayVersion(&dispVer); + + if(strcmp(dispVer.displayVersion, "2.1.0") == 0) + { + offsets->crc64 = 0x1570; + offsets->CFilePathStrIdCtor = 0x166C8; + } + else /* 1.0.0 - 2.0.0 */ + { + offsets->crc64 = 0x1570; + offsets->CFilePathStrIdCtor = 0x16624; + } +} + extern "C" void exl_main(void* x0, void* x1) { + functionOffsets offsets; /* Setup hooking enviroment. */ envSetOwnProcessHandle(exl::util::proc_handle::Get()); exl::hook::Initialize(); + getVersionOffsets(&offsets); + /* Hook functions we care about */ - INJECT_HOOK_T(0x16624, forceRomfs); + INJECT_HOOK_T(offsets.CFilePathStrIdCtor, forceRomfs); INJECT_HOOK_T(nn::fs::MountRom, romMounted); /* Get the address of dread's crc64 function */ - crc64 = (u64 (*)(char const *, u64))exl::hook::GetTargetOffset(0x1570); + crc64 = (u64 (*)(char const *, u64))exl::hook::GetTargetOffset(offsets.crc64); } extern "C" NORETURN void exl_exception_entry()