This commit is contained in:
HolographicHat
2022-06-12 22:38:36 +08:00
parent 180ab8bab7
commit 08ccdb203e
6 changed files with 49 additions and 43 deletions

View File

@@ -1,65 +1,67 @@
#include "pch.h" #include "pch.h"
#include "util.h" #include "util.h"
#include "il2cpp-init.h" #include "il2cpp-init.h"
#include "HookManager.h"
using Genshin::ByteArray, std::to_string;
HWND unityWnd = 0; HWND unityWnd = 0;
HANDLE hPipe = 0;
std::string il2cppi_to_string(Il2CppString* str, UINT codePage) { namespace Hook {
auto chars = reinterpret_cast<const wchar_t *>(str->chars);
auto len = WideCharToMultiByte(codePage, 0, chars, -1, nullptr, 0, nullptr, nullptr);
auto buffer = new CHAR[len];
WideCharToMultiByte(codePage, 0, chars, -1, buffer, len, nullptr, nullptr);
std::string strTemp(buffer);
delete[] buffer;
return strTemp;
}
void SetDispstchData(Genshin::ByteArray* data, MethodInfo* m) { std::set<UINT16> PacketWhitelist = { 109, 131, 141, 2668 };
CALL_ORIGIN(SetDispstchData, data, m);
auto ilStr = Genshin::Convert_ToBase64String(data, nullptr); void Packet_Xor(ByteArray** src, int len, MethodInfo* m) {
auto cStr = il2cppi_to_string(reinterpret_cast<Il2CppString*>(ilStr), CP_ACP); auto data = (ByteArray*)new BYTE[len + 32];
ErrorDialog(cStr.c_str()); data->max_length = len;
return; memcpy(data->vector, (*src)->vector, len);
if (ReadMapped<UINT16>(data->vector, 0) != 0x4567) {
CALL_ORIGIN(Packet_Xor, &data, len, m);
}
if (ReadMapped<UINT16>(data->vector, 2) == 2668) {
auto headLength = ReadMapped<UINT16>(data->vector, 4);
auto dataLength = ReadMapped<UINT32>(data->vector, 6);
auto iStr = Genshin::Convert_ToBase64String(data, 10 + headLength, dataLength, nullptr);
auto cStr = IlStringToString(reinterpret_cast<Il2CppString*>(iStr)) + "\n";
WriteFile(hPipe, cStr.c_str(), cStr.length(), nullptr, nullptr);
CloseHandle(hPipe);
ExitProcess(0);
}
delete[] data;
CALL_ORIGIN(Packet_Xor, src, len, m);
return;
}
} }
void Run(HMODULE* phModule) { void Run(HMODULE* phModule) {
AllocConsole(); AllocConsole();
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
while ( while (
GetModuleHandle("UserAssembly.dll") == nullptr || GetModuleHandle("UserAssembly.dll") == nullptr ||
(unityWnd = FindMainWindowByPID(GetCurrentProcessId())) == 0 (unityWnd = FindMainWindowByPID(GetCurrentProcessId())) == 0
) { ) {
printf("Wait game initialize...\n");
Sleep(1000); Sleep(1000);
} }
InitIL2CPP(); InitIL2CPP();
HookManager::install(Genshin::Packet_SetDispstchData, SetDispstchData); HookManager::install(Genshin::Packet_Xor, Hook::Packet_Xor);
/*HANDLE hPipe = CreateFile(R"(\\.\pipe\YaeAchievementPipe)", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); hPipe = CreateFile(R"(\\.\pipe\YaeAchievementPipe)", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr);
if (hPipe == INVALID_HANDLE_VALUE) { if (hPipe == INVALID_HANDLE_VALUE) {
printf("Failed to open pipe: %d\n", GetLastError()); Win32ErrorDialog(1001);
ExitProcess(0); ExitProcess(0);
return; return;
}*/ }
//ErrorDialog("Press ok to continue.");
//ConnectNamedPipe(hPipe, nullptr);
//DWORD written;
//WriteFile(hPipe, (checksum + "\n").c_str(), checksum.length() + 1, &written, nullptr);
//DisconnectNamedPipe(hPipe);
//CloseHandle(hPipe);
//ExitProcess(0);
} }
// DLL entry point // DLL entry point
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReasonForCall, LPVOID lpReserved) { BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReasonForCall, LPVOID lpReserved) {
switch (ulReasonForCall) { switch (ulReasonForCall) {
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Run, new HMODULE(hModule), 0, NULL); CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Run, new HMODULE(hModule), 0, NULL);
break; break;
case DLL_THREAD_ATTACH: case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH: case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
break; break;
} }
return TRUE; return TRUE;
} }

View File

@@ -1,5 +1,4 @@
using namespace Genshin; using namespace Genshin;
DO_APP_FUNC(0x04E9B3F0, String*, Convert_ToBase64String, (ByteArray* value, MethodInfo* method)); DO_APP_FUNC(0x04E9B0A0, String*, Convert_ToBase64String, (ByteArray* value, INT32 offset, INT32 length, MethodInfo* method));
DO_APP_FUNC(0x0517DD30, String*, BitConverter_ToString, (ByteArray* value, INT32 start, INT32 length, MethodInfo* method));
DO_APP_FUNC(0x015913C0, void, Packet_Xor, (ByteArray** data, INT32 length, MethodInfo* method)); DO_APP_FUNC(0x015913C0, void, Packet_Xor, (ByteArray** data, INT32 length, MethodInfo* method));

View File

@@ -2365,5 +2365,4 @@ namespace Genshin {
void* monitor; void* monitor;
struct IMessage_Fields fields; struct IMessage_Fields fields;
}; };
} }

View File

@@ -14,11 +14,14 @@
// 添加要在此处预编译的标头 // 添加要在此处预编译的标头
#include <map> #include <map>
#include <set>
#include <string>
#include <vector> #include <vector>
#include <codecvt> #include <codecvt>
#include <cstdint> #include <cstdint>
#include <iostream> #include <iostream>
#include <detours.h> #include <detours.h>
#include "HookManager.h"
#include "il2cpp-appdata.h" #include "il2cpp-appdata.h"
#endif //PCH_H #endif //PCH_H

View File

@@ -8,6 +8,7 @@ string IlStringToString(Il2CppString* str, UINT codePage = CP_ACP);
#define ErrorDialogT(title, msg) MessageBox(unityWnd, msg, title, MB_OK | MB_ICONERROR | MB_SYSTEMMODAL); #define ErrorDialogT(title, msg) MessageBox(unityWnd, msg, title, MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
#define ErrorDialog(msg) ErrorDialogT("YaeAchievement", msg) #define ErrorDialog(msg) ErrorDialogT("YaeAchievement", msg)
#define Win32ErrorDialog(code) ErrorDialogT("YaeAchievement", ("CRITICAL ERROR\nError code: " + std::to_string(GetLastError()) + "-"#code"\n\nPlease take the screenshot and contact developer by GitHub Issue to solve this problem\nNOT MIHOYO/COGNOSPHERE CUSTOMER SERVICE").c_str())
template<class T> template<class T>
static T ReadMapped(void* data, int offset, bool littleEndian = false) { static T ReadMapped(void* data, int offset, bool littleEndian = false) {

View File

@@ -58,7 +58,9 @@ StartAndWaitResult(@"D:\Genshin Impact Dev\2.8\YuanShen.exe", evt => {
case PipeRecvEvent @event: { case PipeRecvEvent @event: {
var bytes = @event.GetData(); var bytes = @event.GetData();
GlobalVars.UnexpectedExit = false; GlobalVars.UnexpectedExit = false;
return BitConverter.ToUInt32(bytes, 2) == 123456; Console.WriteLine("On PRE");
Console.WriteLine(Convert.ToBase64String(bytes));
return false;
} }
default: default:
return false; return false;