-
Notifications
You must be signed in to change notification settings - Fork 2
/
DrvMgr.pas
97 lines (85 loc) · 2.29 KB
/
DrvMgr.pas
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
unit DrvMgr;
interface
uses
windows, NativeAPI, advApiHook;
function InstallDriver(drName, drPath: PChar): boolean;
function UninstallDriver(drName: PChar): boolean;
function LoadDriver(dName: PChar): boolean;
function UnloadDriver(dName: PChar): boolean;
implementation
const
DrRegPath = '\registry\machine\system\CurrentControlSet\Services\';
{
Ñîçäàíèå â ðååñòðå çàïèñè î äðàéâåðå.
drName - èìÿ äðàéâåðà,
drPath - ïóòü ê ôàéëó äðàéâåðà,
Result - óñïåøíîñòü óñòàíîâêè.
}
function InstallDriver(drName, drPath: PChar): boolean;
var
Key, Key2: HKEY;
dType: dword;
Err: dword;
NtPath: array[0..MAX_PATH] of Char;
begin
Result := false;
dType := 1;
Err := RegOpenKeyA(HKEY_LOCAL_MACHINE, 'system\CurrentControlSet\Services', Key);
if Err = ERROR_SUCCESS then
begin
Err := RegCreateKeyA(Key, drName, Key2);
if Err <> ERROR_SUCCESS then Err := RegOpenKeyA(Key, drName, Key2);
if Err = ERROR_SUCCESS then
begin
lstrcpy(NtPath, PChar('\??\' + drPath));
RegSetValueExA(Key2, 'ImagePath', 0, REG_SZ, @NtPath, lstrlen(NtPath));
RegSetValueExA(Key2, 'Type', 0, REG_DWORD, @dType, SizeOf(dword));
RegCloseKey(Key2);
Result := true;
end;
RegCloseKey(Key);
end;
end;
{
Óäàëåíèå çàïèñè î äðàéâåðå èç ðååñòðà.
}
function UninstallDriver(drName: PChar): boolean;
var
Key: HKEY;
begin
Result := false;
if RegOpenKeyA(HKEY_LOCAL_MACHINE, 'system\CurrentControlSet\Services', Key) = ERROR_SUCCESS then
begin
RegDeleteKey(Key, PChar(drName+'\Enum'));
RegDeleteKey(Key, PChar(drName+'\Security'));
Result := RegDeleteKey(Key, drName) = ERROR_SUCCESS;
RegCloseKey(Key);
end;
end;
{
Çàãðóçêà äðàéâåðà.
}
function LoadDriver(dName: PChar): boolean;
var
Image: TUnicodeString;
Buff: array [0..MAX_PATH] of WideChar;
begin
StringToWideChar(DrRegPath + dName, Buff, MAX_PATH);
RtlInitUnicodeString(@Image, Buff);
Result := ZwLoadDriver(@Image) = STATUS_SUCCESS;
end;
{
Âûãðóçêà äðàéâåðà.
}
function UnloadDriver(dName: PChar): boolean;
var
Image: TUnicodeString;
Buff: array [0..MAX_PATH] of WideChar;
begin
StringToWideChar(DrRegPath + dName, Buff, MAX_PATH);
RtlInitUnicodeString(@Image, Buff);
Result := ZwUnloadDriver(@Image) = STATUS_SUCCESS;
end;
initialization
EnablePrivilege('SeLoadDriverPrivilege');
end.