Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions inc/usersim/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ USERSIM_API
void
MmUnmapLockedPages(_In_ void* base_address, _In_ MDL* memory_descriptor_list);

USERSIM_API
void
MmProbeAndLockPages(
_Inout_ MDL* memory_descriptor_list,
__drv_strictType(KPROCESSOR_MODE / enum _MODE, __drv_typeConst) KPROCESSOR_MODE access_mode,
ULONG operation);

USERSIM_API
void
MmUnlockPages(_Inout_ MDL* memory_descriptor_list);

USERSIM_API
NTSTATUS
MmMapViewInSystemSpace(_In_ void* section, _Outptr_ void** mapped_base, _Inout_ SIZE_T* view_size);

USERSIM_API
NTSTATUS
MmUnmapViewInSystemSpace(_In_ void* mapped_base);

USERSIM_API
NTSTATUS
MmProtectMdlSystemAddress(_In_ MDL* memory_descriptor_list, ULONG new_protect);
Expand Down
10 changes: 10 additions & 0 deletions inc/usersim/ob.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ _IRQL_requires_max_(PASSIVE_LEVEL) USERSIM_API NTSTATUS ObReferenceObjectByHandl
_Out_ PVOID* object,
_Out_opt_ POBJECT_HANDLE_INFORMATION handle_information);

_IRQL_requires_max_(PASSIVE_LEVEL) USERSIM_API NTSTATUS
ObOpenObjectByPointer(
_In_ PVOID object,
_In_ ULONG handle_attributes,
_In_opt_ void* passed_access_state,
_In_ ACCESS_MASK desired_access,
_In_opt_ POBJECT_TYPE object_type,
_In_ KPROCESSOR_MODE access_mode,
_Out_ HANDLE* handle);

USERSIM_API
NTSTATUS
ObCloseHandle(_In_ _Post_ptr_invalid_ HANDLE handle, _In_ KPROCESSOR_MODE previous_mode);
Expand Down
45 changes: 45 additions & 0 deletions src/mm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "usersim/ex.h"
#include "usersim/ke.h"
#include "usersim/mm.h"
#include "utilities.h"

// Mm* functions.

Expand Down Expand Up @@ -132,6 +133,50 @@ MmUnmapLockedPages(_In_ void* base_address, _In_ MDL* memory_descriptor_list)
return MmUnmapLockedPagesCPP(base_address, memory_descriptor_list);
}

void
MmProbeAndLockPages(
_Inout_ MDL* memory_descriptor_list,
__drv_strictType(KPROCESSOR_MODE / enum _MODE, __drv_typeConst) KPROCESSOR_MODE access_mode,
ULONG operation)
{
UNREFERENCED_PARAMETER(memory_descriptor_list);
UNREFERENCED_PARAMETER(access_mode);
UNREFERENCED_PARAMETER(operation);
}

void
MmUnlockPages(_Inout_ MDL* memory_descriptor_list)
{
UNREFERENCED_PARAMETER(memory_descriptor_list);
}

NTSTATUS
MmMapViewInSystemSpace(_In_ void* section, _Outptr_ void** mapped_base, _Inout_ SIZE_T* view_size)
{
HANDLE section_handle = (HANDLE)section;
void* view;

view = MapViewOfFile(section_handle, FILE_MAP_ALL_ACCESS, 0, 0, *view_size);
if (view == nullptr) {
USERSIM_LOG_WIN32_API_FAILURE(USERSIM_TRACELOG_KEYWORD_BASE, MapViewOfFile);
return win32_error_to_usersim_error(GetLastError());
}

*mapped_base = view;
return STATUS_SUCCESS;
}

NTSTATUS
MmUnmapViewInSystemSpace(_In_ void* mapped_base)
{
if (!UnmapViewOfFile(mapped_base)) {
USERSIM_LOG_WIN32_API_FAILURE(USERSIM_TRACELOG_KEYWORD_BASE, UnmapViewOfFile);
return win32_error_to_usersim_error(GetLastError());
}

return STATUS_SUCCESS;
}

NTSTATUS
MmProtectMdlSystemAddress(_In_ MDL* memory_descriptor_list, ULONG new_protect)
{
Expand Down
23 changes: 23 additions & 0 deletions src/ob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "platform.h"
#include "kernel_um.h"
#include "usersim/ob.h"
#include "utilities.h"
#include <map>

static std::map<PVOID, ULONG> _object_references;
Expand Down Expand Up @@ -56,6 +57,28 @@ ObReferenceObjectByHandle(
return STATUS_SUCCESS;
}

_IRQL_requires_max_(PASSIVE_LEVEL) USERSIM_API NTSTATUS
ObOpenObjectByPointer(
_In_ PVOID object,
_In_ ULONG handle_attributes,
_In_opt_ void* passed_access_state,
_In_ ACCESS_MASK desired_access,
_In_opt_ POBJECT_TYPE object_type,
_In_ KPROCESSOR_MODE access_mode,
_Out_ HANDLE* handle)
{
UNREFERENCED_PARAMETER(handle_attributes);
UNREFERENCED_PARAMETER(passed_access_state);
UNREFERENCED_PARAMETER(object_type);
UNREFERENCED_PARAMETER(access_mode);

if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)object, GetCurrentProcess(), handle, desired_access, FALSE, 0)) {
return win32_error_to_usersim_error(GetLastError());
}

return STATUS_SUCCESS;
}

USERSIM_API
NTSTATUS
ObCloseHandle(_In_ _Post_ptr_invalid_ HANDLE handle, _In_ KPROCESSOR_MODE previous_mode)
Expand Down