-
Notifications
You must be signed in to change notification settings - Fork 0
/
dllmain.cpp
135 lines (128 loc) · 3.88 KB
/
dllmain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <windows.h>
#include <iostream>
#include <psapi.h>
#include <string>
#include <locale>
namespace PAT
{
static bool DataCompare(PBYTE pData, PBYTE bSig, const char* szMask)
{
for (; *szMask; ++szMask, ++pData, ++bSig)
{
if (*szMask == 'x' && *pData != *bSig)
return false;
}
return (*szMask) == 0;
}
static DWORD_PTR FindPattern(DWORD_PTR dwAddress, DWORD dwSize, const char* pbSig, const char* szMask, long offset)
{
size_t length = strlen(szMask);
for (size_t i = NULL; i < dwSize - length; i++)
{
if (DataCompare((PBYTE)dwAddress + i, (PBYTE)pbSig, szMask))
return dwAddress + i + offset;
}
return 0;
}
}
template<class T>
class TArray
{
public:
T* Data;
int Count;
int Max;
};
class FString : public TArray<wchar_t>
{
public:
inline const wchar_t* c_str() const
{
return Data;
}
std::string ToString() const
{
const auto length = std::wcslen(Data);
std::string str(length, '\0');
std::use_facet<std::ctype<wchar_t>>(std::locale()).narrow(Data, Data + length, '?', &str[0]);
return str;
}
};
void* Result;
DWORD_PTR addr_GetEngineVersion;
FString* GetEngineVersion(void* Result)
{
return reinterpret_cast<FString * (__fastcall*)(void*)>(addr_GetEngineVersion)(Result);
}
void CopyToClipboard(const std::string& text)
{
if (OpenClipboard(nullptr))
{
EmptyClipboard();
HGLOBAL hClipboardData = GlobalAlloc(GMEM_DDESHARE, text.size() + 1);
if (hClipboardData)
{
char* pchData = static_cast<char*>(GlobalLock(hClipboardData));
if (pchData)
{
strcpy_s(pchData, text.size() + 1, text.c_str());
GlobalUnlock(hClipboardData);
SetClipboardData(CF_TEXT, hClipboardData);
}
}
CloseClipboard();
}
}
DWORD _stdcall InitEngineVersion(LPVOID)
{
DWORD_PTR BaseAddress = (DWORD_PTR)GetModuleHandle(NULL);
MODULEINFO ModuleInfo;
GetModuleInformation(GetCurrentProcess(), (HMODULE)BaseAddress, &ModuleInfo, sizeof(ModuleInfo));
addr_GetEngineVersion = PAT::FindPattern(BaseAddress, ModuleInfo.SizeOfImage, "\x40\x53\x48\x83\xEC\x20\x48\x8B\xD9\xE8\x00\x00\x00\x00\x48\x8B\xC8\x41\xB8\x04\x00\x00\x00\x48\x8B\xD3", "xxxxxxxxxx????xxxxxxxxxxxx", 0);
if (addr_GetEngineVersion)
{
FString* Engine = GetEngineVersion(&Result);
std::cout << "EngineVer: " << Engine->ToString().c_str() << std::endl;
std::cout << " " << std::endl;
std::cout << "Do you want to copy the engine version to the clipboard? (Y/n): "; // for lazy ppl like me x)
char choice;
std::cin >> choice;
if (choice == 'Y' || choice == 'y')
{
std::string engineVersionStr = Engine->ToString();
CopyToClipboard(engineVersionStr);
std::cout << " " << std::endl;
std::cout << "Unreal Engine version copied to clipboard." << std::endl;
}
}
else
{
std::cout << " " << std::endl;
std::cout << "Pattern Not Found. Make sure to run on an UnrealEngine App, or your version might be unsuported" << std::endl;
}
return NULL;
}
BOOL __stdcall DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{
DisableThreadLibraryCalls(hModule);
AllocConsole();
ShowWindow(GetConsoleWindow(), SW_SHOW);
FILE* fp;
freopen_s(&fp, "CONIN$", "r", stdin);
freopen_s(&fp, "CONOUT$", "w", stdout);
freopen_s(&fp, "CONOUT$", "w", stderr);
std::cout << "DLL Attached" << std::endl;
CreateThread(0, 0, InitEngineVersion, 0, 0, 0);
break;
}
case DLL_PROCESS_DETACH:
{
break;
}
}
return TRUE;
}