Skip to content

Commit c44b9b3

Browse files
committed
Fix KPH install check and change KPH driver start to Auto
1 parent bbfa9cd commit c44b9b3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

phlib/kph.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ NTSTATUS KphConnect2(
9191
_In_ PWSTR FileName
9292
)
9393
{
94-
return KphConnect2Ex(DeviceName, FileName, NULL);
94+
KPH_PARAMETERS parameters;
95+
96+
parameters.SecurityLevel = KphSecuritySignatureCheck;
97+
parameters.CreateDynamicConfiguration = TRUE;
98+
99+
return KphConnect2Ex(DeviceName, FileName, &parameters);
95100
}
96101

97102
NTSTATUS KphConnect2Ex(
@@ -117,12 +122,12 @@ NTSTATUS KphConnect2Ex(
117122

118123
status = KphConnect(fullDeviceName);
119124

120-
if (status == STATUS_ADDRESS_ALREADY_EXISTS)
125+
if (NT_SUCCESS(status) || status == STATUS_ADDRESS_ALREADY_EXISTS)
121126
return status;
122127

123128
// Load the driver, and try again.
124129

125-
KphInstall(DeviceName, FileName);
130+
KphInstallEx(DeviceName, FileName, Parameters);
126131

127132
// Try to open the device again.
128133

@@ -281,7 +286,7 @@ NTSTATUS KphInstallEx(
281286
return STATUS_OBJECT_NAME_NOT_FOUND;
282287
}
283288

284-
if (NT_SUCCESS(NtOpenProcessToken(
289+
if (NT_SUCCESS(status = NtOpenProcessToken(
285290
NtCurrentProcess(),
286291
TOKEN_ADJUST_PRIVILEGES,
287292
&tokenHandle
@@ -291,6 +296,9 @@ NTSTATUS KphInstallEx(
291296
NtClose(tokenHandle);
292297
}
293298

299+
if (!NT_SUCCESS(status))
300+
goto CleanupExit;
301+
294302
keyName = PhConcatStrings(
295303
2,
296304
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
@@ -339,7 +347,7 @@ NTSTATUS KphInstallEx(
339347
if (!NT_SUCCESS(status = NtSetValueKey(keyHandle, &valueName, 0, REG_DWORD, &parameters, sizeof(ULONG))))
340348
goto CleanupExit;
341349

342-
parameters = SERVICE_DEMAND_START;
350+
parameters = SERVICE_AUTO_START;
343351
RtlInitUnicodeString(&valueName, L"Start");
344352
if (!NT_SUCCESS(status = NtSetValueKey(keyHandle, &valueName, 0, REG_DWORD, &parameters, sizeof(ULONG))))
345353
goto CleanupExit;

0 commit comments

Comments
 (0)