-
Notifications
You must be signed in to change notification settings - Fork 3
/
loader.c
63 lines (52 loc) · 1.19 KB
/
loader.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 "common.h"
#include "util.h"
#define MOD_NAME "loader"
#define AUTHOR "Zinx Verituse <[email protected]>"
#define FULL_NAME MOD_NAME " by "AUTHOR" [built @ "__DATE__" "__TIME__"]"
#define INI_NAME MOD_NAME ".ini"
static int modules;
static HMODULE module[4096];
static void loader_ini_load(void)
{
ini_t *ini = ini_load(INI_NAME);
modules = 0;
if (!ini) return;
while (ini_seek_section(ini, "loader")) {
while (ini_seek_setting(ini, NULL)) {
char *value = ini_value(ini);
module[modules] = LoadLibrary(value);
if (module[modules] != NULL) {
LOG("Loaded %s at %p", value, modules[module]);
++modules;
} else {
LOG("Failed to loaded %s", value);
}
}
}
ini_free(ini);
}
static void loader_exit()
{
/* Reverse unload order is intentional. */
while (modules--) {
FreeLibrary(module[modules]);
}
modules = 0;
}
WINAPI BOOL DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
loader_ini_load();
LOG(FULL_NAME " loaded %d modules", modules);
return modules != 0;
case DLL_PROCESS_DETACH:
loader_exit();
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}