From 952970cc2a18a603e0bdccdc1f907b73da7eb4f4 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 27 Apr 2017 17:44:54 +0300 Subject: test -> simple --- README.md | 17 +- src/simple/device.c | 220 +++++++++++++++++++++++++ src/simple/device.h | 13 ++ src/simple/main.c | 29 ++++ src/simple/makefile | 1 + src/simple/sources | 3 + src/simple/vs12/.gitignore | 2 + src/simple/vs12/simple.vs12.sln | 64 ++++++++ src/simple/vs12/simple.vs12.vcxproj | 229 +++++++++++++++++++++++++++ src/test/device.c | 220 ------------------------- src/test/device.h | 13 -- src/test/main.c | 29 ---- src/test/makefile | 1 - src/test/sources | 3 - src/test/vs12/.gitignore | 2 - src/test/vs12/test.vs12.sln | 64 -------- src/test/vs12/test.vs12.vcxproj | 229 --------------------------- utils/CMakeLists.txt | 3 +- utils/README.md | 6 +- utils/libsimple/CMakeLists.txt | 9 ++ utils/libsimple/README.md | 43 +++++ utils/libsimple/include/libsimple/all.hpp | 8 + utils/libsimple/include/libsimple/device.hpp | 19 +++ utils/libsimple/src/device.cpp | 37 +++++ utils/libsimple/utils/CMakeLists.txt | 2 + utils/libsimple/utils/exchange_ints.cpp | 44 +++++ utils/libtest/CMakeLists.txt | 9 -- utils/libtest/README.md | 43 ----- utils/libtest/include/libtest/all.hpp | 8 - utils/libtest/include/libtest/device.hpp | 19 --- utils/libtest/src/device.cpp | 37 ----- utils/libtest/utils/CMakeLists.txt | 2 - utils/libtest/utils/exchange_ints.cpp | 44 ----- 33 files changed, 737 insertions(+), 735 deletions(-) create mode 100644 src/simple/device.c create mode 100644 src/simple/device.h create mode 100644 src/simple/main.c create mode 100644 src/simple/makefile create mode 100644 src/simple/sources create mode 100644 src/simple/vs12/.gitignore create mode 100644 src/simple/vs12/simple.vs12.sln create mode 100644 src/simple/vs12/simple.vs12.vcxproj delete mode 100644 src/test/device.c delete mode 100644 src/test/device.h delete mode 100644 src/test/main.c delete mode 100644 src/test/makefile delete mode 100644 src/test/sources delete mode 100644 src/test/vs12/.gitignore delete mode 100644 src/test/vs12/test.vs12.sln delete mode 100644 src/test/vs12/test.vs12.vcxproj create mode 100644 utils/libsimple/CMakeLists.txt create mode 100644 utils/libsimple/README.md create mode 100644 utils/libsimple/include/libsimple/all.hpp create mode 100644 utils/libsimple/include/libsimple/device.hpp create mode 100644 utils/libsimple/src/device.cpp create mode 100644 utils/libsimple/utils/CMakeLists.txt create mode 100644 utils/libsimple/utils/exchange_ints.cpp delete mode 100644 utils/libtest/CMakeLists.txt delete mode 100644 utils/libtest/README.md delete mode 100644 utils/libtest/include/libtest/all.hpp delete mode 100644 utils/libtest/include/libtest/device.hpp delete mode 100644 utils/libtest/src/device.cpp delete mode 100644 utils/libtest/utils/CMakeLists.txt delete mode 100644 utils/libtest/utils/exchange_ints.cpp diff --git a/README.md b/README.md index 8c31f8b..6f02fe5 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ To verify it's there, you can use the `certmgr.msc` utility. The binaries are signed automatically after they are built, but you can also sign manually by passing the path to a .sys file to `sign.bat`: - sign.bat C:\workspace\personal\windows7-drivers\bin\x64\Release\test.sys + sign.bat C:\workspace\personal\windows7-drivers\bin\x64\Release\simple.sys ### Building the drivers @@ -54,7 +54,7 @@ To build every driver under the "src/" directory, execute `build_drivers.bat`: To build a particular driver, pass the path to the driver's source directory to `build_driver.bat`: - build_driver.bat C:\workspace\personal\windows7-drivers\src\test + build_driver.bat C:\workspace\personal\windows7-drivers\src\simple Driver binaries are copied to the "bin/" directory under the project's root. @@ -72,25 +72,26 @@ To clean up after building every driver in the "src/" directory, execute To clean up after building a particular driver, pass the path to the driver's source directory to `clean_driver.bat`: - clean_driver.bat C:\workspace\personal\windows7-drivers\src\test + clean_driver.bat C:\workspace\personal\windows7-drivers\src\simple Installation ------------ To install a driver as a Windows service, you can use the `sc` utility. -For example, to install `test.sys` as a service with the name `test`, execute: +For example, to install `simple.sys` as a service with the name `simple`, +execute: - sc create test type= kernel binPath= C:\workspace\personal\windows7-drivers\bin\x64\Release\test.sys + sc create simple type= kernel binPath= C:\workspace\personal\windows7-drivers\bin\x64\Release\simple.sys You can then load/unload the driver by starting/stopping the corresponding service using the `net` utility. - net start test - net stop test + net start simple + net stop simple To uninstall a driver, delete the corresponding service using `sc`. - sc delete test + sc delete simple Please note, that **64-bit versions of Windows 7 disallow loading 32-bit drivers**! diff --git a/src/simple/device.c b/src/simple/device.c new file mode 100644 index 0000000..859ba67 --- /dev/null +++ b/src/simple/device.c @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#include "device.h" + +#include + +static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) +{ + NTSTATUS status = STATUS_SUCCESS; + + UNREFERENCED_PARAMETER(device_object); + + irp->IoStatus.Status = status; + irp->IoStatus.Information = 0; + IoCompleteRequest(irp, IO_NO_INCREMENT); + return status; +} + +typedef NTSTATUS (*ioctl_handler)( + void *, unsigned long, + void *, unsigned long, + ULONG_PTR *); + +static NTSTATUS handle_say_hello( + void *in_buf, + unsigned long in_buf_size, + void *out_buf, + unsigned long out_buf_size, + ULONG_PTR *nbwritten) +{ + UNREFERENCED_PARAMETER(in_buf); + UNREFERENCED_PARAMETER(in_buf_size); + UNREFERENCED_PARAMETER(out_buf); + UNREFERENCED_PARAMETER(out_buf_size); + UNREFERENCED_PARAMETER(nbwritten); + + DbgPrint("Hello, world!\n"); + return STATUS_SUCCESS; +} + +static unsigned int i = 42; + +static NTSTATUS handle_exchange_ints( + void *in_buf, + unsigned long in_buf_size, + void *out_buf, + unsigned long out_buf_size, + ULONG_PTR *nbwritten) +{ + unsigned int temp_i; + + if (in_buf_size != sizeof(temp_i)) + return STATUS_INVALID_BUFFER_SIZE; + + RtlCopyMemory(&temp_i, in_buf, in_buf_size); + DbgPrint("%08x\n", temp_i); + + if (out_buf_size < sizeof(i)) + return STATUS_BUFFER_TOO_SMALL; + + RtlCopyMemory(out_buf, &i, sizeof(i)); + *nbwritten += sizeof(i); + i = temp_i; + return STATUS_SUCCESS; +} + +#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; + unsigned long in_buf_size, out_buf_size; + ioctl_handler handler; + NTSTATUS status = STATUS_UNSUCCESSFUL; + + UNREFERENCED_PARAMETER(device_object); + + irp->IoStatus.Status = status; + irp->IoStatus.Information = 0; + io_stack_loc = IoGetCurrentIrpStackLocation(irp); + + in_buf = out_buf = irp->AssociatedIrp.SystemBuffer; + 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) + { + case SAY_HELLO: + handler = handle_say_hello; + break; + + case EXCHANGE_INTS: + handler = handle_exchange_ints; + break; + + default: + status = irp->IoStatus.Status = STATUS_NOT_SUPPORTED; + goto complete_request; + } + + 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); + + return status; +} + +typedef struct +{ + const wchar_t *path; + const wchar_t *symlink; +} +DeviceInfo; + +typedef struct +{ + DEVICE_OBJECT *object; + UNICODE_STRING path; + UNICODE_STRING symlink; +} +Device; + +#define NUMOF_DEVICES 2 + +static DeviceInfo devices_info[NUMOF_DEVICES] = +{ + { + L"\\Device\\simple_device1", + L"\\DosDevices\\simple_device1", + }, + { + L"\\Device\\simple_device2", + L"\\DosDevices\\simple_device2", + }, +}; + +static Device devices[NUMOF_DEVICES]; + +static void destroy_device(int i) +{ + IoDeleteSymbolicLink(&devices[i].symlink); + IoDeleteDevice(devices[i].object); +} + +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) +{ + NTSTATUS status = STATUS_SUCCESS; + + DbgPrint("Setting up device...\n"); + DbgPrint("\tPath: %ws\n", devices_info[i].path); + DbgPrint("\tSymlink: %ws\n", devices_info[i].symlink); + + RtlInitUnicodeString(&devices[i].path, devices_info[i].path); + RtlInitUnicodeString(&devices[i].symlink, devices_info[i].symlink); + + status = IoCreateDevice( + driver_object, + 0, + &devices[i].path, + FILE_DEVICE_UNKNOWN, + FILE_DEVICE_SECURE_OPEN, + FALSE, + &devices[i].object); + + if (!NT_SUCCESS(status)) + return status; + + 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))) + goto delete_device; + + return status; + +delete_device: + IoDeleteDevice(devices[i].object); + + return status; +} + +NTSTATUS set_up_devices(DRIVER_OBJECT *driver_object) +{ + int i, j; + NTSTATUS status = STATUS_SUCCESS; + + for (i = 0; i < NUMOF_DEVICES; ++i) + if (!NT_SUCCESS(status = set_up_device(driver_object, i))) + goto destroy_devices; + + driver_object->MajorFunction[IRP_MJ_CREATE] = device_open; + driver_object->MajorFunction[IRP_MJ_DEVICE_CONTROL] = device_ioctl; + + return status; + +destroy_devices: + for (j = 0; j < i; ++j) + destroy_device(j); + + return status; +} diff --git a/src/simple/device.h b/src/simple/device.h new file mode 100644 index 0000000..4f117e9 --- /dev/null +++ b/src/simple/device.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#pragma once + +#include + +NTSTATUS set_up_devices(DRIVER_OBJECT *); +void destroy_devices(); diff --git a/src/simple/main.c b/src/simple/main.c new file mode 100644 index 0000000..5148727 --- /dev/null +++ b/src/simple/main.c @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2015 Egor Tensin + * This file is part of the "Windows 7 drivers" project. + * For details, see https://github.com/egor-tensin/windows7-drivers. + * Distributed under the MIT License. + */ + +#include "device.h" + +#include + +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) +{ + UNREFERENCED_PARAMETER(registry_path); + + DbgPrint("simple: loading...\n"); + driver_object->DriverUnload = on_driver_unload; + return set_up_devices(driver_object); +} diff --git a/src/simple/makefile b/src/simple/makefile new file mode 100644 index 0000000..5acbbd2 --- /dev/null +++ b/src/simple/makefile @@ -0,0 +1 @@ +!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/src/simple/sources b/src/simple/sources new file mode 100644 index 0000000..1a5ce00 --- /dev/null +++ b/src/simple/sources @@ -0,0 +1,3 @@ +TARGETTYPE = DRIVER +TARGETNAME = simple +SOURCES = device.c main.c diff --git a/src/simple/vs12/.gitignore b/src/simple/vs12/.gitignore new file mode 100644 index 0000000..cd42ee3 --- /dev/null +++ b/src/simple/vs12/.gitignore @@ -0,0 +1,2 @@ +bin/ +obj/ diff --git a/src/simple/vs12/simple.vs12.sln b/src/simple/vs12/simple.vs12.sln new file mode 100644 index 0000000..2b1ad11 --- /dev/null +++ b/src/simple/vs12/simple.vs12.sln @@ -0,0 +1,64 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simple.vs12", "simple.vs12.vcxproj", "{8251FD47-D3D6-4A5D-8DFD-84669E075DAF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Win7 Debug|Win32 = Win7 Debug|Win32 + Win7 Debug|x64 = Win7 Debug|x64 + Win7 Release|Win32 = Win7 Release|Win32 + Win7 Release|x64 = Win7 Release|x64 + Win8 Debug|Win32 = Win8 Debug|Win32 + Win8 Debug|x64 = Win8 Debug|x64 + Win8 Release|Win32 = Win8 Release|Win32 + Win8 Release|x64 = Win8 Release|x64 + Win8.1 Debug|Win32 = Win8.1 Debug|Win32 + Win8.1 Debug|x64 = Win8.1 Debug|x64 + Win8.1 Release|Win32 = Win8.1 Release|Win32 + Win8.1 Release|x64 = Win8.1 Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.ActiveCfg = Win7 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.Build.0 = Win7 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.Deploy.0 = Win7 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.Build.0 = Win7 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.ActiveCfg = Win7 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.Build.0 = Win7 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.Deploy.0 = Win7 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.ActiveCfg = Win8 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.Build.0 = Win8 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.Deploy.0 = Win8 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.ActiveCfg = Win8 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.Build.0 = Win8 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.Deploy.0 = Win8 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.ActiveCfg = Win8 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.Build.0 = Win8 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.Deploy.0 = Win8 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.ActiveCfg = Win8 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.Build.0 = Win8 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.Deploy.0 = Win8 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.ActiveCfg = Win8.1 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.Build.0 = Win8.1 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.Deploy.0 = Win8.1 Debug|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.ActiveCfg = Win8.1 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.Build.0 = Win8.1 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.Deploy.0 = Win8.1 Debug|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.ActiveCfg = Win8.1 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.Build.0 = Win8.1 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.Deploy.0 = Win8.1 Release|Win32 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.ActiveCfg = Win8.1 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.Build.0 = Win8.1 Release|x64 + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.Deploy.0 = Win8.1 Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/simple/vs12/simple.vs12.vcxproj b/src/simple/vs12/simple.vs12.vcxproj new file mode 100644 index 0000000..5fee57f --- /dev/null +++ b/src/simple/vs12/simple.vs12.vcxproj @@ -0,0 +1,229 @@ + + + + + Win8.1 Debug + Win32 + + + Win8.1 Release + Win32 + + + Win8 Debug + Win32 + + + Win8 Release + Win32 + + + Win7 Debug + Win32 + + + Win7 Release + Win32 + + + Win8.1 Debug + x64 + + + Win8.1 Release + x64 + + + Win8 Debug + x64 + + + Win8 Release + x64 + + + Win7 Debug + x64 + + + Win7 Release + x64 + + + + {8251FD47-D3D6-4A5D-8DFD-84669E075DAF} + {dd38f7fc-d7bd-488b-9242-7d8754cde80d} + v4.5 + 11.0 + Win8.1 Debug + Win32 + simple_vs12 + + + + WindowsV6.3 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + WindowsV6.3 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows8 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + true + WindowsKernelModeDriver8.1 + Driver + WDM + + + Windows7 + false + WindowsKernelModeDriver8.1 + Driver + WDM + + + + + + + + + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\debug\ + obj\$(TargetVersion)\$(PlatformShortName)\debug\ + + + DbgengKernelDebugger + bin\$(TargetVersion)\$(PlatformShortName)\release\ + obj\$(TargetVersion)\$(PlatformShortName)\release\ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/device.c b/src/test/device.c deleted file mode 100644 index 7b871a3..0000000 --- a/src/test/device.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#include "device.h" - -#include - -static NTSTATUS device_open(DEVICE_OBJECT *device_object, IRP *irp) -{ - NTSTATUS status = STATUS_SUCCESS; - - UNREFERENCED_PARAMETER(device_object); - - irp->IoStatus.Status = status; - irp->IoStatus.Information = 0; - IoCompleteRequest(irp, IO_NO_INCREMENT); - return status; -} - -typedef NTSTATUS (*ioctl_handler)( - void *, unsigned long, - void *, unsigned long, - ULONG_PTR *); - -static NTSTATUS handle_say_hello( - void *in_buf, - unsigned long in_buf_size, - void *out_buf, - unsigned long out_buf_size, - ULONG_PTR *nbwritten) -{ - UNREFERENCED_PARAMETER(in_buf); - UNREFERENCED_PARAMETER(in_buf_size); - UNREFERENCED_PARAMETER(out_buf); - UNREFERENCED_PARAMETER(out_buf_size); - UNREFERENCED_PARAMETER(nbwritten); - - DbgPrint("Hello, world!\n"); - return STATUS_SUCCESS; -} - -static unsigned int i = 42; - -static NTSTATUS handle_exchange_ints( - void *in_buf, - unsigned long in_buf_size, - void *out_buf, - unsigned long out_buf_size, - ULONG_PTR *nbwritten) -{ - unsigned int temp_i; - - if (in_buf_size != sizeof(temp_i)) - return STATUS_INVALID_BUFFER_SIZE; - - RtlCopyMemory(&temp_i, in_buf, in_buf_size); - DbgPrint("%08x\n", temp_i); - - if (out_buf_size < sizeof(i)) - return STATUS_BUFFER_TOO_SMALL; - - RtlCopyMemory(out_buf, &i, sizeof(i)); - *nbwritten += sizeof(i); - i = temp_i; - return STATUS_SUCCESS; -} - -#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; - unsigned long in_buf_size, out_buf_size; - ioctl_handler handler; - NTSTATUS status = STATUS_UNSUCCESSFUL; - - UNREFERENCED_PARAMETER(device_object); - - irp->IoStatus.Status = status; - irp->IoStatus.Information = 0; - io_stack_loc = IoGetCurrentIrpStackLocation(irp); - - in_buf = out_buf = irp->AssociatedIrp.SystemBuffer; - 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) - { - case SAY_HELLO: - handler = handle_say_hello; - break; - - case EXCHANGE_INTS: - handler = handle_exchange_ints; - break; - - default: - status = irp->IoStatus.Status = STATUS_NOT_SUPPORTED; - goto complete_request; - } - - 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); - - return status; -} - -typedef struct -{ - const wchar_t *path; - const wchar_t *symlink; -} -DeviceInfo; - -typedef struct -{ - DEVICE_OBJECT *object; - UNICODE_STRING path; - UNICODE_STRING symlink; -} -Device; - -#define NUMOF_DEVICES 2 - -static DeviceInfo devices_info[NUMOF_DEVICES] = -{ - { - L"\\Device\\test_device1", - L"\\DosDevices\\test_device1", - }, - { - L"\\Device\\test_device2", - L"\\DosDevices\\test_device2", - }, -}; - -static Device devices[NUMOF_DEVICES]; - -static void destroy_device(int i) -{ - IoDeleteSymbolicLink(&devices[i].symlink); - IoDeleteDevice(devices[i].object); -} - -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) -{ - NTSTATUS status = STATUS_SUCCESS; - - DbgPrint("Setting up device...\n"); - DbgPrint("\tPath: %ws\n", devices_info[i].path); - DbgPrint("\tSymlink: %ws\n", devices_info[i].symlink); - - RtlInitUnicodeString(&devices[i].path, devices_info[i].path); - RtlInitUnicodeString(&devices[i].symlink, devices_info[i].symlink); - - status = IoCreateDevice( - driver_object, - 0, - &devices[i].path, - FILE_DEVICE_UNKNOWN, - FILE_DEVICE_SECURE_OPEN, - FALSE, - &devices[i].object); - - if (!NT_SUCCESS(status)) - return status; - - 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))) - goto delete_device; - - return status; - -delete_device: - IoDeleteDevice(devices[i].object); - - return status; -} - -NTSTATUS set_up_devices(DRIVER_OBJECT *driver_object) -{ - int i, j; - NTSTATUS status = STATUS_SUCCESS; - - for (i = 0; i < NUMOF_DEVICES; ++i) - if (!NT_SUCCESS(status = set_up_device(driver_object, i))) - goto destroy_devices; - - driver_object->MajorFunction[IRP_MJ_CREATE] = device_open; - driver_object->MajorFunction[IRP_MJ_DEVICE_CONTROL] = device_ioctl; - - return status; - -destroy_devices: - for (j = 0; j < i; ++j) - destroy_device(j); - - return status; -} diff --git a/src/test/device.h b/src/test/device.h deleted file mode 100644 index 4f117e9..0000000 --- a/src/test/device.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#pragma once - -#include - -NTSTATUS set_up_devices(DRIVER_OBJECT *); -void destroy_devices(); diff --git a/src/test/main.c b/src/test/main.c deleted file mode 100644 index b3d2b58..0000000 --- a/src/test/main.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015 Egor Tensin - * This file is part of the "Windows 7 drivers" project. - * For details, see https://github.com/egor-tensin/windows7-drivers. - * Distributed under the MIT License. - */ - -#include "device.h" - -#include - -static void on_driver_unload(DRIVER_OBJECT *driver_object) -{ - UNREFERENCED_PARAMETER(driver_object); - - DbgPrint("Unloading test driver...\n"); - destroy_devices(); -} - -NTSTATUS DriverEntry( - DRIVER_OBJECT *driver_object, - UNICODE_STRING *registry_path) -{ - UNREFERENCED_PARAMETER(registry_path); - - DbgPrint("Loading test driver...\n"); - driver_object->DriverUnload = on_driver_unload; - return set_up_devices(driver_object); -} diff --git a/src/test/makefile b/src/test/makefile deleted file mode 100644 index 5acbbd2..0000000 --- a/src/test/makefile +++ /dev/null @@ -1 +0,0 @@ -!INCLUDE $(NTMAKEENV)\makefile.def diff --git a/src/test/sources b/src/test/sources deleted file mode 100644 index 245a1a7..0000000 --- a/src/test/sources +++ /dev/null @@ -1,3 +0,0 @@ -TARGETTYPE = DRIVER -TARGETNAME = test -SOURCES = device.c main.c diff --git a/src/test/vs12/.gitignore b/src/test/vs12/.gitignore deleted file mode 100644 index cd42ee3..0000000 --- a/src/test/vs12/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin/ -obj/ diff --git a/src/test/vs12/test.vs12.sln b/src/test/vs12/test.vs12.sln deleted file mode 100644 index d42e421..0000000 --- a/src/test/vs12/test.vs12.sln +++ /dev/null @@ -1,64 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test.vs12", "test.vs12.vcxproj", "{8251FD47-D3D6-4A5D-8DFD-84669E075DAF}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Win7 Debug|Win32 = Win7 Debug|Win32 - Win7 Debug|x64 = Win7 Debug|x64 - Win7 Release|Win32 = Win7 Release|Win32 - Win7 Release|x64 = Win7 Release|x64 - Win8 Debug|Win32 = Win8 Debug|Win32 - Win8 Debug|x64 = Win8 Debug|x64 - Win8 Release|Win32 = Win8 Release|Win32 - Win8 Release|x64 = Win8 Release|x64 - Win8.1 Debug|Win32 = Win8.1 Debug|Win32 - Win8.1 Debug|x64 = Win8.1 Debug|x64 - Win8.1 Release|Win32 = Win8.1 Release|Win32 - Win8.1 Release|x64 = Win8.1 Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.ActiveCfg = Win7 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.Build.0 = Win7 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|Win32.Deploy.0 = Win7 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.ActiveCfg = Win7 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.Build.0 = Win7 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Debug|x64.Deploy.0 = Win7 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.ActiveCfg = Win7 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.Build.0 = Win7 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|Win32.Deploy.0 = Win7 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.ActiveCfg = Win7 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.Build.0 = Win7 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win7 Release|x64.Deploy.0 = Win7 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.ActiveCfg = Win8 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.Build.0 = Win8 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|Win32.Deploy.0 = Win8 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.ActiveCfg = Win8 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.Build.0 = Win8 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Debug|x64.Deploy.0 = Win8 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.ActiveCfg = Win8 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.Build.0 = Win8 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|Win32.Deploy.0 = Win8 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.ActiveCfg = Win8 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.Build.0 = Win8 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8 Release|x64.Deploy.0 = Win8 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.ActiveCfg = Win8.1 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.Build.0 = Win8.1 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|Win32.Deploy.0 = Win8.1 Debug|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.ActiveCfg = Win8.1 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.Build.0 = Win8.1 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Debug|x64.Deploy.0 = Win8.1 Debug|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.ActiveCfg = Win8.1 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.Build.0 = Win8.1 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|Win32.Deploy.0 = Win8.1 Release|Win32 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.ActiveCfg = Win8.1 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.Build.0 = Win8.1 Release|x64 - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF}.Win8.1 Release|x64.Deploy.0 = Win8.1 Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/test/vs12/test.vs12.vcxproj b/src/test/vs12/test.vs12.vcxproj deleted file mode 100644 index 6793bdf..0000000 --- a/src/test/vs12/test.vs12.vcxproj +++ /dev/null @@ -1,229 +0,0 @@ - - - - - Win8.1 Debug - Win32 - - - Win8.1 Release - Win32 - - - Win8 Debug - Win32 - - - Win8 Release - Win32 - - - Win7 Debug - Win32 - - - Win7 Release - Win32 - - - Win8.1 Debug - x64 - - - Win8.1 Release - x64 - - - Win8 Debug - x64 - - - Win8 Release - x64 - - - Win7 Debug - x64 - - - Win7 Release - x64 - - - - {8251FD47-D3D6-4A5D-8DFD-84669E075DAF} - {dd38f7fc-d7bd-488b-9242-7d8754cde80d} - v4.5 - 11.0 - Win8.1 Debug - Win32 - test_vs12 - - - - WindowsV6.3 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - WindowsV6.3 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows8 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - true - WindowsKernelModeDriver8.1 - Driver - WDM - - - Windows7 - false - WindowsKernelModeDriver8.1 - Driver - WDM - - - - - - - - - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\debug\ - obj\$(TargetVersion)\$(PlatformShortName)\debug\ - - - DbgengKernelDebugger - bin\$(TargetVersion)\$(PlatformShortName)\release\ - obj\$(TargetVersion)\$(PlatformShortName)\release\ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 716c661..31c8511 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,5 +1,6 @@ project(windows7_drivers_utils) add_subdirectory(libservice) + add_subdirectory(libnt_path_converter) -add_subdirectory(libtest) +add_subdirectory(libsimple) diff --git a/utils/README.md b/utils/README.md index 5d03428..1579471 100644 --- a/utils/README.md +++ b/utils/README.md @@ -4,12 +4,12 @@ Driver utilities A couple of usage examples are included along with the drivers. * [libservice]: Utilities to load/unload the drivers. -* [libtest]: [test] driver usage examples. +* [libsimple]: [simple] driver usage examples. * [libnt_path_converter]: [nt_path_converter] driver usage examples. [libservice]: libservice/README.md -[libtest]: libtest/README.md -[test]: ../src/test +[libsimple]: libsimple/README.md +[simple]: ../src/simple [libnt_path_converter]: libnt_path_converter/README.md [nt_path_converter]: ../src/nt_path_converter diff --git a/utils/libsimple/CMakeLists.txt b/utils/libsimple/CMakeLists.txt new file mode 100644 index 0000000..ff61bd7 --- /dev/null +++ b/utils/libsimple/CMakeLists.txt @@ -0,0 +1,9 @@ +file(GLOB_RECURSE libsimple_headers "include/*.hpp") +file(GLOB libsimple_sources "src/*.cpp") +add_library(libsimple + ${libsimple_sources} + ${libsimple_headers}) +target_link_libraries(libsimple libservice) +target_include_directories(libsimple PUBLIC include/) + +add_subdirectory(utils) diff --git a/utils/libsimple/README.md b/utils/libsimple/README.md new file mode 100644 index 0000000..1d9896a --- /dev/null +++ b/utils/libsimple/README.md @@ -0,0 +1,43 @@ +simple driver utilities +======================= + +[simple] driver usage examples. + +[simple]: ../../src/simple + +Usage +----- + +### exchange_ints.exe + +``` +Usage: exchange_ints.exe N +``` + +Parses its argument as an `unsigned int` and exchanges it with the one stored +in [simple] driver's memory. +For example: + +``` +> exchange_ints.exe 1 +42 +``` + +``` +> exchange_ints.exe 32 +1 +``` + +``` +> exchange_ints.exe 100500 +32 +``` + +See also +-------- + +* [Building the utilities] +* [License] + +[Building the utilities]: ../README.md#building-the-utilities +[License]: ../../README.md#license diff --git a/utils/libsimple/include/libsimple/all.hpp b/utils/libsimple/include/libsimple/all.hpp new file mode 100644 index 0000000..474b802 --- /dev/null +++ b/utils/libsimple/include/libsimple/all.hpp @@ -0,0 +1,8 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "device.hpp" diff --git a/utils/libsimple/include/libsimple/device.hpp b/utils/libsimple/include/libsimple/device.hpp new file mode 100644 index 0000000..3318818 --- /dev/null +++ b/utils/libsimple/include/libsimple/device.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#pragma once + +#include "libservice/all.hpp" + +namespace libsimple +{ + class Device : libservice::Device + { + public: + Device(); + + unsigned int exchange_ints(unsigned int) const; + }; +} diff --git a/utils/libsimple/src/device.cpp b/utils/libsimple/src/device.cpp new file mode 100644 index 0000000..57e6963 --- /dev/null +++ b/utils/libsimple/src/device.cpp @@ -0,0 +1,37 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libsimple/all.hpp" + +#include "libservice/all.hpp" + +#include + +namespace libsimple +{ + namespace + { + const char* const device_path = "\\\\.\\simple_device1"; + const auto exchange_ints_ctl_code = CTL_CODE(0x8001, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS); + } + + Device::Device() + : libservice::Device(libservice::Device::open(device_path)) + { } + + unsigned int Device::exchange_ints(unsigned int src) const + { + unsigned int dest; + + send_control_code( + exchange_ints_ctl_code, + &src, + sizeof(src), + &dest, + sizeof(dest)); + + return dest; + } +} diff --git a/utils/libsimple/utils/CMakeLists.txt b/utils/libsimple/utils/CMakeLists.txt new file mode 100644 index 0000000..8824e3e --- /dev/null +++ b/utils/libsimple/utils/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(exchange_ints exchange_ints.cpp) +target_link_libraries(exchange_ints libsimple) diff --git a/utils/libsimple/utils/exchange_ints.cpp b/utils/libsimple/utils/exchange_ints.cpp new file mode 100644 index 0000000..2935b2f --- /dev/null +++ b/utils/libsimple/utils/exchange_ints.cpp @@ -0,0 +1,44 @@ +// Copyright (c) 2015 Egor Tensin +// This file is part of the "Windows 7 drivers" project. +// For details, see https://github.com/egor-tensin/windows7-drivers. +// Distributed under the MIT License. + +#include "libsimple/all.hpp" + +#include +#include +#include +#include + +namespace +{ + bool parse_int(unsigned int& dest, const std::string& src) + { + std::istringstream iss(src); + char c; + return iss >> dest && !iss.get(c); + } +} + +int main(int argc, char* argv[]) +{ + try + { + unsigned int src; + + if (argc != 2 || !parse_int(src, argv[1])) + { + std::cout << "Usage: " << argv[0] << " N\n"; + return 1; + } + + std::cout << libsimple::Device().exchange_ints(src) << "\n"; + } + catch (const std::exception& e) + { + std::cerr << e.what() << "\n"; + return 1; + } + + return 0; +} diff --git a/utils/libtest/CMakeLists.txt b/utils/libtest/CMakeLists.txt deleted file mode 100644 index 8c64ba1..0000000 --- a/utils/libtest/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -file(GLOB_RECURSE libtest_headers "include/*.hpp") -file(GLOB libtest_sources "src/*.cpp") -add_library(libtest - ${libtest_sources} - ${libtest_headers}) -target_link_libraries(libtest libservice) -target_include_directories(libtest PUBLIC include/) - -add_subdirectory(utils) diff --git a/utils/libtest/README.md b/utils/libtest/README.md deleted file mode 100644 index 0257c71..0000000 --- a/utils/libtest/README.md +++ /dev/null @@ -1,43 +0,0 @@ -test driver utilities -===================== - -[test] driver usage examples. - -[test]: ../../src/test - -Usage ------ - -### exchange_ints.exe - -``` -Usage: exchange_ints.exe N -``` - -Parses its argument as an `unsigned int` and exchanges it with the one stored -in [test] driver's memory. -For example: - -``` -> exchange_ints.exe 1 -42 -``` - -``` -> exchange_ints.exe 32 -1 -``` - -``` -> exchange_ints.exe 100500 -32 -``` - -See also --------- - -* [Building the utilities] -* [License] - -[Building the utilities]: ../README.md#building-the-utilities -[License]: ../../README.md#license diff --git a/utils/libtest/include/libtest/all.hpp b/utils/libtest/include/libtest/all.hpp deleted file mode 100644 index 474b802..0000000 --- a/utils/libtest/include/libtest/all.hpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "device.hpp" diff --git a/utils/libtest/include/libtest/device.hpp b/utils/libtest/include/libtest/device.hpp deleted file mode 100644 index 591d215..0000000 --- a/utils/libtest/include/libtest/device.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#pragma once - -#include "libservice/all.hpp" - -namespace libtest -{ - class Device : libservice::Device - { - public: - Device(); - - unsigned int exchange_ints(unsigned int) const; - }; -} diff --git a/utils/libtest/src/device.cpp b/utils/libtest/src/device.cpp deleted file mode 100644 index f06a22a..0000000 --- a/utils/libtest/src/device.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libtest/all.hpp" - -#include "libservice/all.hpp" - -#include - -namespace libtest -{ - namespace - { - const char* const device_path = "\\\\.\\test_device1"; - const auto exchange_ints_ctl_code = CTL_CODE(0x8001, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS); - } - - Device::Device() - : libservice::Device(libservice::Device::open(device_path)) - { } - - unsigned int Device::exchange_ints(unsigned int src) const - { - unsigned int dest; - - send_control_code( - exchange_ints_ctl_code, - &src, - sizeof(src), - &dest, - sizeof(dest)); - - return dest; - } -} diff --git a/utils/libtest/utils/CMakeLists.txt b/utils/libtest/utils/CMakeLists.txt deleted file mode 100644 index 9b22ab2..0000000 --- a/utils/libtest/utils/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_executable(exchange_ints exchange_ints.cpp) -target_link_libraries(exchange_ints libtest) diff --git a/utils/libtest/utils/exchange_ints.cpp b/utils/libtest/utils/exchange_ints.cpp deleted file mode 100644 index f70badf..0000000 --- a/utils/libtest/utils/exchange_ints.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2015 Egor Tensin -// This file is part of the "Windows 7 drivers" project. -// For details, see https://github.com/egor-tensin/windows7-drivers. -// Distributed under the MIT License. - -#include "libtest/all.hpp" - -#include -#include -#include -#include - -namespace -{ - bool parse_int(unsigned int& dest, const std::string& src) - { - std::istringstream iss(src); - char c; - return iss >> dest && !iss.get(c); - } -} - -int main(int argc, char* argv[]) -{ - try - { - unsigned int src; - - if (argc != 2 || !parse_int(src, argv[1])) - { - std::cout << "Usage: " << argv[0] << " N\n"; - return 1; - } - - std::cout << libtest::Device().exchange_ints(src) << "\n"; - } - catch (const std::exception& e) - { - std::cerr << e.what() << "\n"; - return 1; - } - - return 0; -} -- cgit v1.2.3