-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
69 lines (64 loc) · 2.55 KB
/
Copy pathmain.cpp
File metadata and controls
69 lines (64 loc) · 2.55 KB
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
#include <windows.h>
// ============================================================
// Export forwarding: choose between linker and runtime methods
// ============================================================
#if defined(PROXY_RUNTIME)
// Runtime forwarding: LoadLibrary + GetProcAddress + ASM thunks
// Compatible with ALL applications including complex game engines
#if defined(DLL_TYPE_version)
#include "src/exports/version_runtime.h"
#elif defined(DLL_TYPE_winmm)
#include "src/exports/winmm_runtime.h"
#elif defined(DLL_TYPE_winhttp)
#include "src/exports/winhttp_runtime.h"
#elif defined(DLL_TYPE_wininet)
#include "src/exports/wininet_runtime.h"
#else
#error "DLL_TYPE not defined. Please specify -DDLL_TYPE=<type> in CMake."
#endif
#else
// Linker forwarding: MSVC pragma directives (default)
// Simple and clean, works for most applications
#if defined(DLL_TYPE_version)
#include "src/exports/version.h"
#elif defined(DLL_TYPE_winmm)
#include "src/exports/winmm.h"
#elif defined(DLL_TYPE_winhttp)
#include "src/exports/winhttp.h"
#elif defined(DLL_TYPE_wininet)
#include "src/exports/wininet.h"
#else
#error "DLL_TYPE not defined. Please specify -DDLL_TYPE=<type> in CMake."
#endif
#endif
// Payload function - your custom code goes here
DWORD WINAPI Payload(LPVOID lpParam) {
MessageBoxA(NULL, "DLL Proxy Loaded!", "dll-proxy", MB_OK);
return 0;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) {
switch (dwReason) {
case DLL_PROCESS_ATTACH: {
DisableThreadLibraryCalls(hModule); // Optimization: We don't need thread attach/detach notifications
// Runtime forwarding: load the original DLL and resolve function pointers
// This MUST happen before any forwarded export is called
#ifdef PROXY_RUNTIME
if (!LoadOriginalDLL()) {
// Critical: if we can't load the original DLL, the process will crash
// when any forwarded function is called (NULL function pointer)
return FALSE;
}
#endif
HANDLE hThread = CreateThread(NULL, 0, Payload, NULL, 0, NULL);
if (hThread != NULL) {
CloseHandle(hThread);
}
break;
}
case DLL_PROCESS_DETACH:
// Cleanup code here (if needed)
// For simple payloads, no cleanup is usually necessary
break;
}
return TRUE;
}