From 07a08f56d4be24dbcaa2529cf2ddd6f9d489b55d Mon Sep 17 00:00:00 2001 From: HolographicHat Date: Tue, 27 Sep 2022 19:02:13 +0800 Subject: [PATCH] 3.1 native lib --- lib/YaeAchievementLib.vcxproj | 2 +- lib/src/dllmain.cpp | 32 ++++++++++++++++------------- lib/src/il2cpp-functions.h | 35 ++++++++++++++++++++++++++------ lib/src/il2cpp-unity-functions.h | 2 +- src/AppConfig.cs | 2 +- src/Utils.cs | 3 ++- 6 files changed, 52 insertions(+), 24 deletions(-) diff --git a/lib/YaeAchievementLib.vcxproj b/lib/YaeAchievementLib.vcxproj index 3a11d92..c6c436a 100644 --- a/lib/YaeAchievementLib.vcxproj +++ b/lib/YaeAchievementLib.vcxproj @@ -105,7 +105,7 @@ detours-x64.lib;%(AdditionalDependencies) - copy $(TargetPath) $(ProjectDir)..\bin\Debug\net6.0 + copy $(TargetPath) $(ProjectDir)..\bin\Debug\net6.0\win-x64 diff --git a/lib/src/dllmain.cpp b/lib/src/dllmain.cpp index 5b01c0f..4dffbd7 100644 --- a/lib/src/dllmain.cpp +++ b/lib/src/dllmain.cpp @@ -16,7 +16,7 @@ bool OnPacket(KcpPacket* pkt) { auto data = (ByteArray*)new BYTE[len + 32]; data->max_length = len; memcpy(data->vector, pkt->data, len); - Genshin::Packet_Xor(&data, len, nullptr); + Genshin::XorEncrypt(&data, len, nullptr); if (ReadMapped(data->vector, 0) != 0x4567) { delete[] data; return true; @@ -32,7 +32,7 @@ bool OnPacket(KcpPacket* pkt) { if (ReadMapped(data->vector, 2) == 2676) { auto headLength = ReadMapped(data->vector, 4); auto dataLength = ReadMapped(data->vector, 6); - auto iStr = Genshin::Convert_ToBase64String(data, 10 + headLength, dataLength, nullptr); + auto iStr = Genshin::ToBase64String(data, 10 + headLength, dataLength, nullptr); auto cStr = IlStringToString(iStr) + "\n"; WriteFile(hPipe, cStr.c_str(), cStr.length(), nullptr, nullptr); CloseHandle(hPipe); @@ -44,18 +44,18 @@ bool OnPacket(KcpPacket* pkt) { namespace Hook { - int Kcp_Send(void* client, KcpPacket* pkt, void* method) { - return OnPacket(pkt) ? CALL_ORIGIN(Kcp_Send, client, pkt, method) : 0; + int KcpSend(void* client, KcpPacket* pkt, void* method) { + return OnPacket(pkt) ? CALL_ORIGIN(KcpSend, client, pkt, method) : 0; } - void MonoLoginMainPage__set_version(void* obj, Il2CppString* value, void* method) { + void SetVersion(void* obj, Il2CppString* value, void* method) { auto version = IlStringToString(value); value = string_new(version + " YaeAchievement"); - CALL_ORIGIN(MonoLoginMainPage__set_version, obj, value, method); + CALL_ORIGIN(SetVersion, obj, value, method); } - bool Kcp_Recv(void* client, ClientKcpEvent* evt, void* method) { - auto result = CALL_ORIGIN(Kcp_Recv, client, evt, method); + bool KcpRecv(void* client, ClientKcpEvent* evt, void* method) { + auto result = CALL_ORIGIN(KcpRecv, client, evt, method); if (result == 0 || evt->fields.type != KcpEventType::EventRecvMsg) { return result; } @@ -68,29 +68,33 @@ namespace Hook { if (signatures.count(type)) { return GCHandle_GetObject(signatures[type]); } + auto encoder = Genshin::Encoding_GetDefault(nullptr); auto result = CALL_ORIGIN(UnityEngine_RecordUserData, type); + auto str = Genshin::Encoding_GetString(encoder, result, nullptr); + printf("RecordUserData%d: %s\n", type, IlStringToString(str).c_str()); signatures[type] = GCHandle_New(result, true); return result; } } void Run(HMODULE* phModule) { - //AllocConsole(); - //freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); + AllocConsole(); + freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); while ( GetModuleHandle("UserAssembly.dll") == nullptr || (unityWnd = FindMainWindowByPID(GetCurrentProcessId())) == 0 ) { Sleep(1000); } + Sleep(5000); InitIL2CPP(); HookManager::install(Genshin::UnityEngine_RecordUserData, Hook::UnityEngine_RecordUserData); for (int i = 0; i < 4; i++) { - Genshin::Application_RecordUserData(i, nullptr); + Genshin::RecordUserData(i, nullptr); } - HookManager::install(Genshin::Kcp_Send, Hook::Kcp_Send); - HookManager::install(Genshin::Kcp_Recv, Hook::Kcp_Recv); - HookManager::install(Genshin::MonoLoginMainPage__set_version, Hook::MonoLoginMainPage__set_version); + HookManager::install(Genshin::KcpSend, Hook::KcpSend); + HookManager::install(Genshin::KcpRecv, Hook::KcpRecv); + HookManager::install(Genshin::SetVersion, Hook::SetVersion); hPipe = CreateFile(R"(\\.\pipe\YaeAchievementPipe)", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); if (hPipe == INVALID_HANDLE_VALUE) { Win32ErrorDialog(1001); diff --git a/lib/src/il2cpp-functions.h b/lib/src/il2cpp-functions.h index 699fa1e..4544930 100644 --- a/lib/src/il2cpp-functions.h +++ b/lib/src/il2cpp-functions.h @@ -1,10 +1,33 @@ using namespace Genshin; -DO_APP_FUNC(0x05254960, 0x052544E0, Il2CppString*, Convert_ToBase64String, (ByteArray* value, int offset, int length, void* method)); -DO_APP_FUNC(0x020127B0, 0x02012D40, void, Packet_Xor, (ByteArray** data, int length, void* method)); +// DO_APP_FUNC(CN_OFFSET, OS_OFFSET, RETURN, FUNC_NAME, (ARGS...)); -DO_APP_FUNC(0X01AD8E40, 0x01AD9740, void, MonoLoginMainPage__set_version, (void* obj, Il2CppString* value, void* method)); -DO_APP_FUNC(0x05C25AC0, 0x05C25E60, ByteArray*, Application_RecordUserData, (int32_t nType, void* method)); +// N: System.Convert$ToBase64String +// L: mscorlib +DO_APP_FUNC(0x051CC420, 0x051CCB00, Il2CppString*, ToBase64String, (ByteArray* value, int offset, int length, void* method)); -DO_APP_FUNC(0x015C19D0, 0x015C2150, int, Kcp_Send, (void* client, KcpPacket* pkt, void* method)); -DO_APP_FUNC(0x02CF31D0, 0x02CF33A0, bool, Kcp_Recv, (void* client, ClientKcpEvent* evt, void* method)); +// N: MoleMole.MonoLoginMainPage.version$set +// L: Assembly-CSharp +DO_APP_FUNC(0X01E6CC80, 0x01E6CD90, void, SetVersion, (void* obj, Il2CppString* value, void* method)); + +// N: UnityEngine.Application$RecordUserData +// L: UnityEngine.CoreModule +DO_APP_FUNC(0x05AFD640, 0x05AFD630, ByteArray*, RecordUserData, (int32_t nType, void* method)); + +// N: MoleMole.Packet$XorEncrypt [Obfuscated] +// L: Assembly-CSharp +DO_APP_FUNC(0x0133C8A0, 0x0133D110, void, XorEncrypt, (ByteArray** data, int length, void* method)); + +// N: Kcp.KcpNative$kcp_client_send_packet [Obfuscated] +// L: Assembly-CSharp +DO_APP_FUNC(0x0094FBD0, 0x0094FCF0, int, KcpSend, (void* client, KcpPacket* pkt, void* method)); + +// N: MoleMole.KcpClient$TryDequeueEvent [Obfuscated] +// L: Assembly-CSharp +DO_APP_FUNC(0x026C8690, 0x026C9030, bool, KcpRecv, (void* client, ClientKcpEvent* evt, void* method)); + +DO_APP_FUNC(0x054AC8A0, 0x054AC8A0, void*, Encoding_GetDefault, (void* method)); + +// N: System.Text.Encoding$GetBytes +// L: mscorlib +DO_APP_FUNC(0x054AB010, 0x054AB010, Il2CppString*, Encoding_GetString, (void* obj, ByteArray* s, void* method)); diff --git a/lib/src/il2cpp-unity-functions.h b/lib/src/il2cpp-unity-functions.h index 7a89fbd..5d18a15 100644 --- a/lib/src/il2cpp-unity-functions.h +++ b/lib/src/il2cpp-unity-functions.h @@ -1,3 +1,3 @@ using namespace Genshin; -DO_UNI_FUNC(0x00B9D710, 0x00B9D710, ByteArray*, UnityEngine_RecordUserData, (int32_t nType)); +DO_UNI_FUNC(0x00BAB2B0, 0x00BAB2B0, ByteArray*, UnityEngine_RecordUserData, (int32_t nType)); diff --git a/src/AppConfig.cs b/src/AppConfig.cs index afa77bd..dba2735 100644 --- a/src/AppConfig.cs +++ b/src/AppConfig.cs @@ -8,7 +8,7 @@ public static class AppConfig { public static string GamePath { get; private set; } = null!; internal static void Load(string argumentPath) { - if (argumentPath == "auto" && File.Exists(argumentPath)) { + if (argumentPath != "auto" && File.Exists(argumentPath)) { GamePath = argumentPath; return; } diff --git a/src/Utils.cs b/src/Utils.cs index 76758a6..4fbcf79 100644 --- a/src/Utils.cs +++ b/src/Utils.cs @@ -102,7 +102,8 @@ public static class Utils { } } if (useLocalLib) { - File.Copy(GlobalVars.LibPath, Path.Combine(GlobalVars.AppPath, "YaeLib.dll")); + Console.WriteLine(@"Use local native lib."); + File.Copy(Path.Combine(GlobalVars.AppPath, "YaeAchievementLib.dll"), GlobalVars.LibPath, true); } else if (info.EnableLibDownload) { File.WriteAllBytes(GlobalVars.LibPath, GetBucketFileAsByteArray("schicksal/lib.dll")); }