Add DLL to modify PlayFab url
This commit is contained in:
@@ -1,17 +1,71 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <MinHook.h>
|
||||
#include <cstdio>
|
||||
#include "main.h"
|
||||
#include "logger.h"
|
||||
#include <detours.h>
|
||||
#include "SDK.h"
|
||||
#include "SDK_Memory.h"
|
||||
|
||||
/**
|
||||
* Variable offset, find with "STOPMOVIECAPTURE", scroll up.
|
||||
*/
|
||||
constexpr uintptr_t OffsetGMalloc = 0x5C9A3F8;
|
||||
|
||||
/**
|
||||
* Function offset, find with "?sdk=".
|
||||
*/
|
||||
constexpr uintptr_t OffsetPlayFabApiGetUrl = 0xCA5010;
|
||||
|
||||
/**
|
||||
* Function hooks.
|
||||
*/
|
||||
typedef SDK::FString(__fastcall* tPlayFabApiGetUrl)(SDK::UPlayFabAPISettings*, const SDK::FString&);
|
||||
|
||||
tPlayFabApiGetUrl OldPlayFabApiGetUrl;
|
||||
|
||||
SDK::FString __fastcall PlayFabApiGetUrlProxy(SDK::UPlayFabAPISettings* thiz, const SDK::FString& callPath)
|
||||
{
|
||||
logger::Print("[Agent] GetURL called with callPath %s\n", callPath.ToString().c_str());
|
||||
|
||||
return std::wstring(L"http://127.0.0.1:8888") + std::wstring(callPath.c_str());
|
||||
}
|
||||
|
||||
DWORD WINAPI OnDllAttach(LPVOID base)
|
||||
{
|
||||
logger::Attach();
|
||||
logger::Print("[Agent] DLL Attached\n");
|
||||
|
||||
// TODO: Patch.
|
||||
const auto hModule = GetModuleHandleW(nullptr);
|
||||
const auto hModulePtr = reinterpret_cast<uintptr_t>(hModule);
|
||||
|
||||
logger::Print("[Agent] DLL Exit\n");
|
||||
FreeLibraryAndExitThread(static_cast<HMODULE>(base), 1);
|
||||
// Initialize GMalloc.
|
||||
SDK::GMalloc = *reinterpret_cast<SDK::FMalloc**>(hModulePtr + OffsetGMalloc);
|
||||
|
||||
// Initialize MinHook.
|
||||
if (MH_Initialize() != MH_OK)
|
||||
{
|
||||
logger::Print("[Agent] Failed to initialize MinHook\n");
|
||||
FreeLibraryAndExitThread(hModule, 1);
|
||||
}
|
||||
|
||||
// Hook UPlayFabAPISettings::GetUrl.
|
||||
const auto pTarget = reinterpret_cast<LPVOID>(hModulePtr + OffsetPlayFabApiGetUrl);
|
||||
const auto ppOriginal = reinterpret_cast<LPVOID*>(&OldPlayFabApiGetUrl);
|
||||
const auto mhStatus = MH_CreateHook(pTarget, &PlayFabApiGetUrlProxy, ppOriginal);
|
||||
|
||||
if (mhStatus != MH_OK)
|
||||
{
|
||||
logger::Print("[Agent] Failed to create PlayFabAPIGetUrl hook (%d)\n", mhStatus);
|
||||
FreeLibraryAndExitThread(hModule, 1);
|
||||
}
|
||||
|
||||
if (MH_EnableHook(pTarget) != MH_OK)
|
||||
{
|
||||
logger::Print("[Agent] Failed to enable PlayFabAPIGetUrl hook\n");
|
||||
FreeLibraryAndExitThread(hModule, 1);
|
||||
}
|
||||
|
||||
logger::Print("[Agent] DLL Initialized\n");
|
||||
ExitThread(1);
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(
|
||||
@@ -27,10 +81,18 @@ BOOL WINAPI DllMain(
|
||||
// Allocate a console.
|
||||
AllocConsole();
|
||||
freopen_s(reinterpret_cast<FILE**>(stdout), "CONOUT$", "w", stdout);
|
||||
|
||||
// Attach logger.
|
||||
logger::Attach();
|
||||
|
||||
// Spawn thread.
|
||||
CreateThread(nullptr, 0, OnDllAttach, hinstDll, 0, nullptr);
|
||||
}
|
||||
else if (fdwReason == DLL_PROCESS_DETACH)
|
||||
{
|
||||
// Detach logger.
|
||||
logger::Detach();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user