From b7254033d61af6f890cf0a0809a789bb20215bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:24:26 +0800 Subject: [PATCH] 1 Update Ryujinx.cpp Update Ryujinx.cpp Update Ryujinx.cpp Update Ryujinx.cpp --- LunaHook/CMakeLists.txt | 2 +- LunaHook/engine64/Ryujinx.cpp | 83 +++++++++++++++++++++++++++++++++ LunaHook/engine64/Ryujinx.h | 18 +++++++ LunaHook/enginecollection64.cpp | 2 + 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 LunaHook/engine64/Ryujinx.cpp create mode 100644 LunaHook/engine64/Ryujinx.h diff --git a/LunaHook/CMakeLists.txt b/LunaHook/CMakeLists.txt index 5510b07..2ea1c73 100644 --- a/LunaHook/CMakeLists.txt +++ b/LunaHook/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(. util engines) if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) - set(enginessrc livecaptions Kincaid vita3k rpcs3 yuzusuyu TYPEMOON ENTERGRAM AGES7 mono Godot 5pb lucasystem LightVN V8 pchooks Artemis KiriKiri YOX PPSSPP CMVS Suika2 ) + set(enginessrc Ryujinx livecaptions Kincaid vita3k rpcs3 yuzusuyu TYPEMOON ENTERGRAM AGES7 mono Godot 5pb lucasystem LightVN V8 pchooks Artemis KiriKiri YOX PPSSPP CMVS Suika2 ) set(enginepath "engine64") set(collector "enginecollection64.cpp") else() diff --git a/LunaHook/engine64/Ryujinx.cpp b/LunaHook/engine64/Ryujinx.cpp new file mode 100644 index 0000000..a7a8ea4 --- /dev/null +++ b/LunaHook/engine64/Ryujinx.cpp @@ -0,0 +1,83 @@ +#include "Ryujinx.h" + +namespace +{ + /* + const char* CEEInfo::getMethodNameFromMetadata(CORINFO_METHOD_HANDLE ftnHnd, + const char** className, + const char** namespaceName, + const char** enclosingClassNames, + size_t maxEnclosingClassNames) + */ + /* + CorJitResult CILJit::compileMethod(ICorJitInfo* compHnd, + CORINFO_METHOD_INFO* methodInfo, + unsigned flags, + uint8_t** entryAddress, + uint32_t* nativeSizeOfCode) + */ + /* + CorJitResult invokeCompileMethodHelper(EEJitManager *jitMgr, + CEEInfo *comp, + struct CORINFO_METHOD_INFO *info, + CORJIT_FLAGS jitFlags, + BYTE **nativeEntry, + uint32_t *nativeSizeOfCode) + */ + struct CEEInfo; + struct CORINFO_METHOD_HANDLE; + struct CORINFO_METHOD_INFO + { + CORINFO_METHOD_HANDLE *ftn; + // CORINFO_MODULE_HANDLE scope; + // uint8_t *ILCode; + // unsigned ILCodeSize; + // unsigned maxStack; + // unsigned EHcount; + // CorInfoOptions options; + // CorInfoRegionKind regionKind; + // CORINFO_SIG_INFO args; + // CORINFO_SIG_INFO locals; + }; + const char *(*getMethodNameFromMetadata)(CEEInfo *, CORINFO_METHOD_HANDLE *, const char **, const char **, const char **) = 0; + +} +bool Ryujinx::attach_function() +{ + auto invokeCompileMethodHelper = processStartAddress + 0x84CC0; + getMethodNameFromMetadata = (decltype(getMethodNameFromMetadata))(processStartAddress + 0x7AED0); + HookParam hp; + hp.address = invokeCompileMethodHelper; + hp.text_fun = [](hook_stack *stack, HookParam *hp, uintptr_t *data, uintptr_t *split, size_t *len) + { + auto methodInfo = (CORINFO_METHOD_INFO *)stack->r8; + + const char *className; + const char *namespaceName; + const char *enclosingClassName; + auto methodname = getMethodNameFromMetadata((CEEInfo *)stack->rdx, methodInfo->ftn, &className, &namespaceName, &enclosingClassName); + if (!methodname) + return; + if (strcmp(methodname, "RegisterFunction") != 0) + return; + + ConsoleOutput("%s %s %s %s", className, namespaceName, enclosingClassName, methodname); + HookParam hpinternal; + hpinternal.user_value = stack->stack[5]; // entryAddress->RegisterFunction + hpinternal.address = stack->retaddr; + hpinternal.text_fun = [](hook_stack *stack, HookParam *hp, uintptr_t *data, uintptr_t *split, size_t *len) + { + HookParam hp_cs_function; + hp_cs_function.address = *(uintptr_t *)hp->user_value; + hp_cs_function.text_fun = [](hook_stack *stack, HookParam *hp, uintptr_t *data, uintptr_t *split, size_t *len) + { + ConsoleOutput("%p %p %p %p %p %p", stack->rcx, stack->rdx, stack->r8, stack->r9, stack->r10, stack->r11); + }; + NewHook(hp_cs_function, "RegisterFunction"); + + hp->type = HOOK_EMPTY; + }; + NewHook(hpinternal, "invokeCompileMethodHelper Return"); + }; + return NewHook(hp, "invokeCompileMethodHelper"); +} \ No newline at end of file diff --git a/LunaHook/engine64/Ryujinx.h b/LunaHook/engine64/Ryujinx.h new file mode 100644 index 0000000..46cbad8 --- /dev/null +++ b/LunaHook/engine64/Ryujinx.h @@ -0,0 +1,18 @@ + + +class Ryujinx : public ENGINE +{ +public: + Ryujinx() + { + + check_by = CHECK_BY::FILE; + is_engine_certain = false; + check_by = CHECK_BY::CUSTOM; + check_by_target = []() + { + return wcscmp(processName_lower, L"ryujinx.exe") == 0; + }; + }; + bool attach_function(); +}; diff --git a/LunaHook/enginecollection64.cpp b/LunaHook/enginecollection64.cpp index 9f43c96..375ad07 100644 --- a/LunaHook/enginecollection64.cpp +++ b/LunaHook/enginecollection64.cpp @@ -17,6 +17,7 @@ #include "engine64/Kincaid.h" #include "engine64/LightVN.h" #include "engine64/yuzusuyu.h" +#include "engine64/Ryujinx.h" #include "engine64/vita3k.h" #include "engine64/rpcs3.h" #include "engines/lua/lua51.h" @@ -47,5 +48,6 @@ std::vector check_engines() new Kincaid, new livecaptions, new lua51, + new Ryujinx }; }