-
Notifications
You must be signed in to change notification settings - Fork 7
/
HookLib.dpr
80 lines (69 loc) · 1.85 KB
/
HookLib.dpr
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
library HookLib;
{$IMAGEBASE $60800000}
uses Windows;
var
Modules: array[1..100] of THandle;
ModuleNr: Integer;
procedure LibraryProc(Reason: Integer);
var
I: Integer;
begin
if Reason = DLL_PROCESS_DETACH then
begin
for I:=1 to ModuleNr do
FreeLibrary(Modules[I]);
ModuleNr:=0;
end;
end;
function SysErrorMessage(ErrorCode: Integer): string;
var
Buffer: array[0..255] of Char;
var
Len: Integer;
begin
Len := FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS or
FORMAT_MESSAGE_ARGUMENT_ARRAY, nil, ErrorCode, 0, Buffer,
SizeOf(Buffer), nil);
while (Len > 0) and (Buffer[Len - 1] in [#0..#32, '.']) do Dec(Len);
SetString(Result, Buffer, Len);
end;
procedure Dummy;
begin
end;
exports
Dummy;
var
F: TWin32FindData;
H, M: THandle;
ErrNo: Integer;
ErrNoStr: string;
begin
// locate and load WormKit modules
H:=FindFirstFile('wk*.dll', F);
if H=INVALID_HANDLE_VALUE then
MessageBox(0, 'Warning: no WormKit modules were loaded. '#13#10#13#10+
'WormKit''s features are provided by modules. '#13#10+
'To activate certain modules, simply copy the files from the WormKitModules folder.', 'WormKit', MB_ICONWARNING)
else
begin
repeat
M:=LoadLibrary(F.cFileName);
if M=0 then
begin
ErrNo := GetLastError;
Str(ErrNo, ErrNoStr);
MessageBox(0, PChar('Warning: can''t load module "'+F.cFileName+'".'#13#10+
'It''s probably missing some DLL files it depends on.'#13#10#13#10+
'Error #'+ErrNoStr+':'#13#10+
SysErrorMessage(ErrNo)), 'WormKit', MB_ICONWARNING);
end
else
begin
Inc(ModuleNr);
Modules[ModuleNr]:=M;
end;
until not FindNextFile(H, F);
end;
FindClose(H);
DllProc:=@LibraryProc;
end.