forked from systoolz/sndbxkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlloader.c
43 lines (40 loc) · 866 Bytes
/
dlloader.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
#include "dlloader.h"
#pragma pack(push, 1)
typedef struct {
HINSTANCE hLibrary;
FARPROC *ProcList;
} LOADHEAD;
#pragma pack(pop)
void *LoadDLLFile(CCHAR *s, size_t l) {
LOADHEAD *p;
FARPROC *a;
p = NULL;
if ((s) && (l >= sizeof(LOADHEAD))) {
p = (LOADHEAD *) LocalAlloc(LPTR, l);
if (p) {
p->hLibrary = LoadLibraryA(s);
if (p->hLibrary) {
a = (FARPROC *) &p->ProcList;
for(; *s; s++); s++;
while (*s) {
*a = GetProcAddress(p->hLibrary, s);
a++;
for(; *s; s++); s++;
}
} else {
LocalFree(p);
p = NULL;
}
}
}
return(p);
}
void FreeDLLFile(void *p, size_t l) {
if ((p) && (l >= sizeof(LOADHEAD))) {
if (((LOADHEAD *) p)->hLibrary) {
FreeLibrary(((LOADHEAD *) p)->hLibrary);
}
ZeroMemory(p, l);
LocalFree(p);
}
}