-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMain.c
63 lines (58 loc) · 2 KB
/
Main.c
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
#include <Windows.h>
#include <stdio.h>
typedef int (*pfnMessageBoxA)(
HWND hWnd,
LPCSTR lpText,
LPCSTR lpCaption,
UINT uType
);
typedef BOOL (*pfnCreateProcessA)(
LPCSTR lpApplicationName,
LPSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCSTR lpCurrentDirectory,
LPSTARTUPINFOA lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
typedef DWORD (*pfnGetModuleFileNameA)(
HMODULE hModule,
LPSTR lpFilename,
DWORD nSize
);
typedef HANDLE (*pfnCreateThread)(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
__drv_aliasesMem LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
);
pfnMessageBoxA messageBoxA = NULL;
pfnCreateProcessA createProcessA = NULL;
pfnGetModuleFileNameA getModuleFileNameA = NULL;
pfnCreateThread createThread = NULL;
void InitializeFunctionPointers() {
// NOTE:
// The following Win32 API addresses are stored as global variables
// Win32 API functions are called through these global variables
HMODULE kernel32Base = LoadLibraryA("kernel32.dll");
if (kernel32Base) {
createProcessA = (pfnCreateProcessA)GetProcAddress(kernel32Base, "CreateProcessA");
getModuleFileNameA = (pfnGetModuleFileNameA)GetProcAddress(kernel32Base, "GetModuleFileNameA");
createThread = (pfnCreateThread)GetProcAddress(kernel32Base, "CreateThread");
}
HMODULE user32Base = LoadLibraryA("user32.dll");
if (user32Base) {
messageBoxA = (pfnMessageBoxA)GetProcAddress(user32Base, "MessageBoxA");
}
printf("%p %p %p %p\n", createProcessA, getModuleFileNameA, createThread, messageBoxA);
}
int main() {
InitializeFunctionPointers();
messageBoxA(NULL, "Hi", "Hello", MB_OK);
return 0;
}