diff options
Diffstat (limited to 'km')
| -rw-r--r-- | km/src/minimal/main.c | 8 | ||||
| -rw-r--r-- | km/src/nt_namespace/device.c | 81 | ||||
| -rw-r--r-- | km/src/nt_namespace/device.h | 2 | ||||
| -rw-r--r-- | km/src/nt_namespace/main.c | 8 | ||||
| -rw-r--r-- | km/src/nt_namespace/nt2dos.c | 50 | ||||
| -rw-r--r-- | km/src/nt_namespace/nt2dos.h | 2 | ||||
| -rw-r--r-- | km/src/simple/device.c | 81 | ||||
| -rw-r--r-- | km/src/simple/device.h | 2 | ||||
| -rw-r--r-- | km/src/simple/main.c | 8 | ||||
| -rw-r--r-- | km/src/sysenter/main.c | 26 |
10 files changed, 101 insertions, 167 deletions
diff --git a/km/src/minimal/main.c b/km/src/minimal/main.c index 219477a..0164692 100644 --- a/km/src/minimal/main.c +++ b/km/src/minimal/main.c @@ -7,15 +7,11 @@ #include <ntddk.h> -static void on_driver_unload(DRIVER_OBJECT *driver_object) -{ +static void on_driver_unload(DRIVER_OBJECT* driver_object) { UNREFERENCED_PARAMETER(driver_object); } -NTSTATUS DriverEntry( - DRIVER_OBJECT *driver_object, - UNICODE_STRING *registry_path) -{ +NTSTATUS DriverEntry(DRIVER_OBJECT* driver_object, UNICODE_STRING* registry_path) { UNREFERENCED_PARAMETER(registry_path); driver_object->DriverUnload = on_driver_unload; diff --git a/km/src/nt_namespace/device.c b/km/src/nt_namespace/device.c index 6d88dc4..afb9813 100644 --- a/km/src/nt_namespace/device.c +++ b/km/src/nt_namespace/device.c @@ -5,14 +5,14 @@ * Distributed under the MIT License. */ -#include "control_codes.h" #include "device.h" + +#include "control_codes.h" #include "nt2dos.h" #include <ntddk.h> -static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) -{ +static NTSTATUS device_open(DEVICE_OBJECT* device_object, IRP* irp) { NTSTATUS status = STATUS_SUCCESS; UNREFERENCED_PARAMETER(device_object); @@ -23,25 +23,22 @@ static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) return status; } -typedef NTSTATUS (*ioctl_handler)( - void *, unsigned long, - void *, unsigned long, - ULONG_PTR *); +typedef NTSTATUS (*ioctl_handler)(void*, unsigned long, void*, unsigned long, ULONG_PTR*); static NTSTATUS handle_convert_nt_path( - void *in_buf, + void* in_buf, unsigned long in_buf_size, - void *out_buf, + void* out_buf, unsigned long out_buf_size, - ULONG_PTR *nbwritten) -{ + ULONG_PTR* nbwritten +) { UNICODE_STRING uUnresolved, uResolved; NTSTATUS status = STATUS_SUCCESS; - DbgPrint("nt_namespace: unresolved path: %ws\n", (WCHAR *) in_buf); + DbgPrint("nt_namespace: unresolved path: %ws\n", (WCHAR*)in_buf); DbgPrint("nt_namespace: unresolved size: %lu\n", in_buf_size); - RtlInitUnicodeString(&uUnresolved, (WCHAR *) in_buf); + RtlInitUnicodeString(&uUnresolved, (WCHAR*)in_buf); status = nt2dos(&uResolved, &uUnresolved); if (!NT_SUCCESS(status)) @@ -52,8 +49,7 @@ static NTSTATUS handle_convert_nt_path( DbgPrint("nt_namespace: resolved path: %wZ\n", &uResolved); DbgPrint("nt_namespace: resolved size: %Iu\n", *nbwritten); - if (out_buf_size < *nbwritten) - { + if (out_buf_size < *nbwritten) { status = STATUS_BUFFER_OVERFLOW; goto free_resolved; } @@ -67,10 +63,9 @@ free_resolved: return status; } -static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) -{ - IO_STACK_LOCATION *io_stack_loc; - void* in_buf, *out_buf; +static NTSTATUS device_ioctl(DEVICE_OBJECT* device_object, IRP* irp) { + IO_STACK_LOCATION* io_stack_loc; + void *in_buf, *out_buf; unsigned long in_buf_size, out_buf_size; ioctl_handler handler; NTSTATUS status = STATUS_UNSUCCESSFUL; @@ -85,8 +80,7 @@ static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) in_buf_size = io_stack_loc->Parameters.DeviceIoControl.InputBufferLength; out_buf_size = io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength; - switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) - { + switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) { case CONVERT_NT_PATH: handler = handle_convert_nt_path; break; @@ -96,10 +90,8 @@ static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) goto complete_request; } - status = irp->IoStatus.Status = handler( - in_buf, in_buf_size, - out_buf, out_buf_size, - &irp->IoStatus.Information); + status = irp->IoStatus.Status = + handler(in_buf, in_buf_size, out_buf, out_buf_size, &irp->IoStatus.Information); complete_request: IoCompleteRequest(irp, IO_NO_INCREMENT); @@ -107,25 +99,20 @@ complete_request: return status; } -typedef struct -{ - const wchar_t *path; - const wchar_t *symlink; -} -DeviceInfo; +typedef struct { + const wchar_t* path; + const wchar_t* symlink; +} DeviceInfo; -typedef struct -{ - DEVICE_OBJECT *object; +typedef struct { + DEVICE_OBJECT* object; UNICODE_STRING path; UNICODE_STRING symlink; -} -Device; +} Device; #define NUMOF_DEVICES 1 -static DeviceInfo devices_info[NUMOF_DEVICES] = -{ +static DeviceInfo devices_info[NUMOF_DEVICES] = { { L"\\Device\\nt_namespace", L"\\DosDevices\\nt_namespace", @@ -134,21 +121,18 @@ static DeviceInfo devices_info[NUMOF_DEVICES] = static Device devices[NUMOF_DEVICES]; -static void destroy_device(int i) -{ +static void destroy_device(int i) { IoDeleteSymbolicLink(&devices[i].symlink); IoDeleteDevice(devices[i].object); } -void destroy_devices() -{ +void destroy_devices() { int i; for (i = 0; i < NUMOF_DEVICES; ++i) destroy_device(i); } -static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) -{ +static NTSTATUS set_up_device(DRIVER_OBJECT* driver_object, int i) { NTSTATUS status = STATUS_SUCCESS; RtlInitUnicodeString(&devices[i].path, devices_info[i].path); @@ -161,7 +145,8 @@ static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, - &devices[i].object); + &devices[i].object + ); if (!NT_SUCCESS(status)) return status; @@ -169,8 +154,7 @@ static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) devices[i].object->Flags |= DO_BUFFERED_IO; devices[i].object->Flags &= ~DO_DEVICE_INITIALIZING; - if (!NT_SUCCESS(status = IoCreateSymbolicLink( - &devices[i].symlink, &devices[i].path))) + if (!NT_SUCCESS(status = IoCreateSymbolicLink(&devices[i].symlink, &devices[i].path))) goto delete_device; return status; @@ -181,8 +165,7 @@ delete_device: return status; } -NTSTATUS set_up_devices(DRIVER_OBJECT *driver_object) -{ +NTSTATUS set_up_devices(DRIVER_OBJECT* driver_object) { int i, j; NTSTATUS status = STATUS_SUCCESS; diff --git a/km/src/nt_namespace/device.h b/km/src/nt_namespace/device.h index 4f117e9..8cc2c1d 100644 --- a/km/src/nt_namespace/device.h +++ b/km/src/nt_namespace/device.h @@ -9,5 +9,5 @@ #include <ntddk.h> -NTSTATUS set_up_devices(DRIVER_OBJECT *); +NTSTATUS set_up_devices(DRIVER_OBJECT*); void destroy_devices(); diff --git a/km/src/nt_namespace/main.c b/km/src/nt_namespace/main.c index 4c7ef74..a8d0c14 100644 --- a/km/src/nt_namespace/main.c +++ b/km/src/nt_namespace/main.c @@ -9,17 +9,13 @@ #include <ntddk.h> -static void on_driver_unload(DRIVER_OBJECT *driver_object) -{ +static void on_driver_unload(DRIVER_OBJECT* driver_object) { UNREFERENCED_PARAMETER(driver_object); destroy_devices(); } -NTSTATUS DriverEntry( - DRIVER_OBJECT *driver_object, - UNICODE_STRING *registry_path) -{ +NTSTATUS DriverEntry(DRIVER_OBJECT* driver_object, UNICODE_STRING* registry_path) { UNREFERENCED_PARAMETER(registry_path); ExInitializeDriverRuntime(DrvRtPoolNxOptIn); diff --git a/km/src/nt_namespace/nt2dos.c b/km/src/nt_namespace/nt2dos.c index be2c2f5..2e6db6c 100644 --- a/km/src/nt_namespace/nt2dos.c +++ b/km/src/nt_namespace/nt2dos.c @@ -5,12 +5,13 @@ * Distributed under the MIT License. */ +/* clang-format off */ #include <ntifs.h> #include "nt2dos.h" +/* clang-format on */ -static PVOID allocate(SIZE_T nb) -{ +static PVOID allocate(SIZE_T nb) { #if !defined(NTDDI_WIN10) || NTDDI_VERSION < NTDDI_WIN10 return ExAllocatePoolWithTag(PagedPool, nb, '1l'); #else @@ -18,10 +19,7 @@ static PVOID allocate(SIZE_T nb) #endif } -static NTSTATUS get_object_name_info( - void *object, - OBJECT_NAME_INFORMATION **object_name_info) -{ +static NTSTATUS get_object_name_info(void* object, OBJECT_NAME_INFORMATION** object_name_info) { unsigned long nbneeded; NTSTATUS status = STATUS_SUCCESS; @@ -48,11 +46,10 @@ free_object_name_info: return status; } -NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) -{ +NTSTATUS nt2dos(UNICODE_STRING* u_resolved, UNICODE_STRING* u_unresolved) { IO_STATUS_BLOCK io_status_block; - DEVICE_OBJECT *volume_object; - FILE_OBJECT *file_object; + DEVICE_OBJECT* volume_object; + FILE_OBJECT* file_object; HANDLE file; OBJECT_ATTRIBUTES file_attrs; OBJECT_NAME_INFORMATION *file_name_info, *volume_name_info; @@ -61,11 +58,8 @@ NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) NTSTATUS status = STATUS_SUCCESS; InitializeObjectAttributes( - &file_attrs, - u_unresolved, - OBJ_CASE_INSENSITIVE | OBJ_OPENIF, - NULL, - NULL); + &file_attrs, u_unresolved, OBJ_CASE_INSENSITIVE | OBJ_OPENIF, NULL, NULL + ); status = ZwCreateFile( &file, @@ -78,18 +72,15 @@ NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, - 0); + 0 + ); if (!NT_SUCCESS(status)) return status; status = ObReferenceObjectByHandle( - file, - FILE_READ_ATTRIBUTES, - *IoFileObjectType, - KernelMode, - &file_object, - NULL); + file, FILE_READ_ATTRIBUTES, *IoFileObjectType, KernelMode, &file_object, NULL + ); if (!NT_SUCCESS(status)) goto close_file; @@ -99,18 +90,15 @@ NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) if (!NT_SUCCESS(status)) goto close_file; - if (file_object->Vpb == NULL) - { + if (file_object->Vpb == NULL) { u_resolved->Buffer = allocate(file_name_info->Name.Length); - if (u_resolved->Buffer == NULL) - { + if (u_resolved->Buffer == NULL) { status = STATUS_INSUFFICIENT_RESOURCES; goto free_file_name_info; } - RtlInitEmptyUnicodeString( - u_resolved, u_resolved->Buffer, file_name_info->Name.Length); + RtlInitEmptyUnicodeString(u_resolved, u_resolved->Buffer, file_name_info->Name.Length); RtlCopyUnicodeString(u_resolved, &file_name_info->Name); goto free_file_name_info; } @@ -126,12 +114,12 @@ NTSTATUS nt2dos(UNICODE_STRING *u_resolved, UNICODE_STRING *u_unresolved) if (!NT_SUCCESS(status)) goto free_volume_name_info; - u_resolved_size = file_name_info->Name.Length - volume_name_info->Name.Length + u_dos_name.Length; + u_resolved_size = + file_name_info->Name.Length - volume_name_info->Name.Length + u_dos_name.Length; u_resolved->Buffer = allocate(u_resolved_size); - if (u_resolved->Buffer == NULL) - { + if (u_resolved->Buffer == NULL) { status = STATUS_INSUFFICIENT_RESOURCES; goto free_dos_name; } diff --git a/km/src/nt_namespace/nt2dos.h b/km/src/nt_namespace/nt2dos.h index ce0b690..7f24b5b 100644 --- a/km/src/nt_namespace/nt2dos.h +++ b/km/src/nt_namespace/nt2dos.h @@ -9,4 +9,4 @@ #include <ntstrsafe.h> -NTSTATUS nt2dos(UNICODE_STRING *resolved, UNICODE_STRING *unresolved); +NTSTATUS nt2dos(UNICODE_STRING* resolved, UNICODE_STRING* unresolved); diff --git a/km/src/simple/device.c b/km/src/simple/device.c index f632a8d..ccc780d 100644 --- a/km/src/simple/device.c +++ b/km/src/simple/device.c @@ -9,8 +9,7 @@ #include <ntddk.h> -static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) -{ +static NTSTATUS device_open(DEVICE_OBJECT* device_object, IRP* irp) { NTSTATUS status = STATUS_SUCCESS; UNREFERENCED_PARAMETER(device_object); @@ -21,18 +20,15 @@ static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) return status; } -typedef NTSTATUS (*ioctl_handler)( - void *, unsigned long, - void *, unsigned long, - ULONG_PTR *); +typedef NTSTATUS (*ioctl_handler)(void*, unsigned long, void*, unsigned long, ULONG_PTR*); static NTSTATUS handle_say_hello( - void *in_buf, + void* in_buf, unsigned long in_buf_size, - void *out_buf, + void* out_buf, unsigned long out_buf_size, - ULONG_PTR *nbwritten) -{ + ULONG_PTR* nbwritten +) { UNREFERENCED_PARAMETER(in_buf); UNREFERENCED_PARAMETER(in_buf_size); UNREFERENCED_PARAMETER(out_buf); @@ -46,12 +42,12 @@ static NTSTATUS handle_say_hello( static unsigned int num = 42; static NTSTATUS handle_exchange_ints( - void *in_buf, + void* in_buf, unsigned long in_buf_size, - void *out_buf, + void* out_buf, unsigned long out_buf_size, - ULONG_PTR *nbwritten) -{ + ULONG_PTR* nbwritten +) { unsigned int temp_num; if (in_buf_size != sizeof(temp_num)) @@ -69,13 +65,12 @@ static NTSTATUS handle_exchange_ints( return STATUS_SUCCESS; } -#define SAY_HELLO CTL_CODE(0x8000, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define SAY_HELLO CTL_CODE(0x8000, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) #define EXCHANGE_INTS CTL_CODE(0x8001, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) -static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) -{ - IO_STACK_LOCATION *io_stack_loc; - void* in_buf, *out_buf; +static NTSTATUS device_ioctl(DEVICE_OBJECT* device_object, IRP* irp) { + IO_STACK_LOCATION* io_stack_loc; + void *in_buf, *out_buf; unsigned long in_buf_size, out_buf_size; ioctl_handler handler; NTSTATUS status = STATUS_UNSUCCESSFUL; @@ -90,8 +85,7 @@ static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) in_buf_size = io_stack_loc->Parameters.DeviceIoControl.InputBufferLength; out_buf_size = io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength; - switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) - { + switch (io_stack_loc->Parameters.DeviceIoControl.IoControlCode) { case SAY_HELLO: handler = handle_say_hello; break; @@ -105,10 +99,8 @@ static NTSTATUS device_ioctl(DEVICE_OBJECT *device_object, IRP *irp) goto complete_request; } - status = irp->IoStatus.Status = handler( - in_buf, in_buf_size, - out_buf, out_buf_size, - &irp->IoStatus.Information); + status = irp->IoStatus.Status = + handler(in_buf, in_buf_size, out_buf, out_buf_size, &irp->IoStatus.Information); complete_request: IoCompleteRequest(irp, IO_NO_INCREMENT); @@ -116,25 +108,20 @@ complete_request: return status; } -typedef struct -{ - const wchar_t *path; - const wchar_t *symlink; -} -DeviceInfo; +typedef struct { + const wchar_t* path; + const wchar_t* symlink; +} DeviceInfo; -typedef struct -{ - DEVICE_OBJECT *object; +typedef struct { + DEVICE_OBJECT* object; UNICODE_STRING path; UNICODE_STRING symlink; -} -Device; +} Device; #define NUMOF_DEVICES 2 -static DeviceInfo devices_info[NUMOF_DEVICES] = -{ +static DeviceInfo devices_info[NUMOF_DEVICES] = { { L"\\Device\\simple_device1", L"\\DosDevices\\simple_device1", @@ -147,21 +134,18 @@ static DeviceInfo devices_info[NUMOF_DEVICES] = static Device devices[NUMOF_DEVICES]; -static void destroy_device(int i) -{ +static void destroy_device(int i) { IoDeleteSymbolicLink(&devices[i].symlink); IoDeleteDevice(devices[i].object); } -void destroy_devices() -{ +void destroy_devices() { int i; for (i = 0; i < NUMOF_DEVICES; ++i) destroy_device(i); } -static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) -{ +static NTSTATUS set_up_device(DRIVER_OBJECT* driver_object, int i) { NTSTATUS status = STATUS_SUCCESS; DbgPrint("Setting up device...\n"); @@ -178,7 +162,8 @@ static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, - &devices[i].object); + &devices[i].object + ); if (!NT_SUCCESS(status)) return status; @@ -186,8 +171,7 @@ static NTSTATUS set_up_device(DRIVER_OBJECT *driver_object, int i) devices[i].object->Flags |= DO_BUFFERED_IO; devices[i].object->Flags &= ~DO_DEVICE_INITIALIZING; - if (!NT_SUCCESS(status = IoCreateSymbolicLink( - &devices[i].symlink, &devices[i].path))) + if (!NT_SUCCESS(status = IoCreateSymbolicLink(&devices[i].symlink, &devices[i].path))) goto delete_device; return status; @@ -198,8 +182,7 @@ delete_device: return status; } -NTSTATUS set_up_devices(DRIVER_OBJECT *driver_object) -{ +NTSTATUS set_up_devices(DRIVER_OBJECT* driver_object) { int i, j; NTSTATUS status = STATUS_SUCCESS; diff --git a/km/src/simple/device.h b/km/src/simple/device.h index 4f117e9..8cc2c1d 100644 --- a/km/src/simple/device.h +++ b/km/src/simple/device.h @@ -9,5 +9,5 @@ #include <ntddk.h> -NTSTATUS set_up_devices(DRIVER_OBJECT *); +NTSTATUS set_up_devices(DRIVER_OBJECT*); void destroy_devices(); diff --git a/km/src/simple/main.c b/km/src/simple/main.c index 5148727..100ad37 100644 --- a/km/src/simple/main.c +++ b/km/src/simple/main.c @@ -9,18 +9,14 @@ #include <ntddk.h> -static void on_driver_unload(DRIVER_OBJECT *driver_object) -{ +static void on_driver_unload(DRIVER_OBJECT* driver_object) { UNREFERENCED_PARAMETER(driver_object); DbgPrint("simple: unloading...\n"); destroy_devices(); } -NTSTATUS DriverEntry( - DRIVER_OBJECT *driver_object, - UNICODE_STRING *registry_path) -{ +NTSTATUS DriverEntry(DRIVER_OBJECT* driver_object, UNICODE_STRING* registry_path) { UNREFERENCED_PARAMETER(registry_path); DbgPrint("simple: loading...\n"); diff --git a/km/src/sysenter/main.c b/km/src/sysenter/main.c index 9eb9b28..c2d9144 100644 --- a/km/src/sysenter/main.c +++ b/km/src/sysenter/main.c @@ -8,10 +8,9 @@ #include <ntddk.h> static __int64 old_msr_value = 0; -static void *old_ki_fast_call_entry = NULL; +static void* old_ki_fast_call_entry = NULL; -static void __stdcall log_system_call() -{ +static void __stdcall log_system_call() { static LONG count = 0; static const LONG throttle = 10000; @@ -21,8 +20,7 @@ static void __stdcall log_system_call() DbgPrint("Another %ld of `sysenter`s (eax=)!\n", throttle); } -static void __declspec(naked) new_ki_fast_call_entry() -{ +static void __declspec(naked) new_ki_fast_call_entry() { __asm { pushad @@ -41,8 +39,7 @@ static void __declspec(naked) new_ki_fast_call_entry() #define IA32_SYSENTER_EIP 0x176 -static void hook_sysenter() -{ +static void hook_sysenter() { /* __asm { @@ -57,14 +54,13 @@ static void hook_sysenter() old_msr_value = __readmsr(IA32_SYSENTER_EIP); #pragma warning(push) -#pragma warning(disable: 4305) - old_ki_fast_call_entry = (void *) old_msr_value; +#pragma warning(disable : 4305) + old_ki_fast_call_entry = (void*)old_msr_value; #pragma warning(pop) __writemsr(IA32_SYSENTER_EIP, new_ki_fast_call_entry); } -static void unhook_sysenter() -{ +static void unhook_sysenter() { /* __asm { @@ -78,8 +74,7 @@ static void unhook_sysenter() __writemsr(IA32_SYSENTER_EIP, old_msr_value); } -static void on_driver_unload(DRIVER_OBJECT *driver_object) -{ +static void on_driver_unload(DRIVER_OBJECT* driver_object) { KTIMER timer; LARGE_INTEGER time_out; @@ -94,10 +89,7 @@ static void on_driver_unload(DRIVER_OBJECT *driver_object) KeWaitForSingleObject(&timer, Executive, KernelMode, FALSE, NULL); } -NTSTATUS DriverEntry( - DRIVER_OBJECT *driver_object, - UNICODE_STRING *registry_path) -{ +NTSTATUS DriverEntry(DRIVER_OBJECT* driver_object, UNICODE_STRING* registry_path) { UNREFERENCED_PARAMETER(registry_path); driver_object->DriverUnload = on_driver_unload; |
