-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for simulating PsSetCreateProcessNotifyRoutineEx
Signed-off-by: Alan Jowett (from Dev Box) <[email protected]>
- Loading branch information
1 parent
01ae6b8
commit 6b91361
Showing
4 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,53 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include "platform.h" | ||
#include "kernel_um.h" | ||
#include "platform.h" | ||
#include "usersim/ps.h" | ||
|
||
// Ps* functions. | ||
|
||
HANDLE | ||
PsGetCurrentProcessId() { return (HANDLE)(uintptr_t)GetCurrentProcessId(); } | ||
|
||
_IRQL_requires_max_(DISPATCH_LEVEL) NTKERNELAPI HANDLE | ||
PsGetCurrentThreadId() { return (HANDLE)(uintptr_t)GetCurrentThreadId(); } | ||
_IRQL_requires_max_(DISPATCH_LEVEL) NTKERNELAPI HANDLE PsGetCurrentThreadId() | ||
{ | ||
return (HANDLE)(uintptr_t)GetCurrentThreadId(); | ||
} | ||
|
||
static PCREATE_PROCESS_NOTIFY_ROUTINE_EX _usersim_process_creation_notify_routine = NULL; | ||
|
||
USERSIM_API | ||
NTSTATUS | ||
PsSetCreateProcessNotifyRoutineEx(_In_ PCREATE_PROCESS_NOTIFY_ROUTINE_EX notify_routine, _In_ BOOLEAN remove) | ||
{ | ||
if (notify_routine == NULL) { | ||
return STATUS_INVALID_PARAMETER; | ||
} | ||
|
||
// Remove the routine. | ||
if (remove) { | ||
if (_usersim_process_creation_notify_routine == NULL) { | ||
return STATUS_INVALID_PARAMETER; | ||
} | ||
_usersim_process_creation_notify_routine = NULL; | ||
return STATUS_SUCCESS; | ||
} | ||
// Only one routine is supported. | ||
if (_usersim_process_creation_notify_routine != NULL) { | ||
return STATUS_INVALID_PARAMETER; | ||
} | ||
|
||
// Set the routine. | ||
_usersim_process_creation_notify_routine = notify_routine; | ||
return STATUS_SUCCESS; | ||
} | ||
|
||
void | ||
usersime_invoke_process_creation_notify_routine( | ||
_Inout_ PEPROCESS process, _In_ HANDLE process_id, _Inout_opt_ PPS_CREATE_NOTIFY_INFO create_info) | ||
{ | ||
if (_usersim_process_creation_notify_routine != NULL) { | ||
_usersim_process_creation_notify_routine(process, process_id, create_info); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// SPDX-License-Identifier: MIT | ||
|
||
#if !defined(CMAKE_NUGET) | ||
#include <catch2/catch_all.hpp> | ||
#else | ||
#include <catch2/catch.hpp> | ||
#endif | ||
#include "usersim/ps.h" | ||
|
||
TEST_CASE("PsSetCreateProcessNotifyRoutineEx", "[ps]") | ||
{ | ||
auto notify_routine = [](PEPROCESS, HANDLE, PPS_CREATE_NOTIFY_INFO) {}; | ||
// First call should succeed. | ||
auto status = PsSetCreateProcessNotifyRoutineEx(notify_routine, FALSE); | ||
REQUIRE(status == STATUS_SUCCESS); | ||
// Try to set the routine again, should fail. | ||
status = PsSetCreateProcessNotifyRoutineEx(notify_routine, FALSE); | ||
REQUIRE(status == STATUS_INVALID_PARAMETER); | ||
|
||
// Remove the routine. Should succeed. | ||
status = PsSetCreateProcessNotifyRoutineEx(notify_routine, TRUE); | ||
REQUIRE(status == STATUS_SUCCESS); | ||
|
||
// Try to remove the routine again, should fail. | ||
status = PsSetCreateProcessNotifyRoutineEx(notify_routine, TRUE); | ||
REQUIRE(status == STATUS_INVALID_PARAMETER); | ||
|
||
// Try to remove with a NULL routine, should fail. | ||
status = PsSetCreateProcessNotifyRoutineEx(NULL, TRUE); | ||
REQUIRE(status == STATUS_INVALID_PARAMETER); | ||
|
||
// Try set with a NULL routine, should fail. | ||
status = PsSetCreateProcessNotifyRoutineEx(NULL, FALSE); | ||
REQUIRE(status == STATUS_INVALID_PARAMETER); | ||
|
||
// Set the routine again, should succeed. | ||
status = PsSetCreateProcessNotifyRoutineEx(notify_routine, FALSE); | ||
REQUIRE(status == STATUS_SUCCESS); | ||
|
||
// Remove the routine. Should succeed. | ||
status = PsSetCreateProcessNotifyRoutineEx(notify_routine, TRUE); | ||
REQUIRE(status == STATUS_SUCCESS); | ||
} |