diff options
| author | a1xd <[email protected]> | 2020-07-31 20:04:19 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-07-31 20:04:19 -0400 |
| commit | 5241f9783b41e74f719dc4a472c6b0803b0eff8c (patch) | |
| tree | 4c0a0507610e30b5c76b0dfff98e50b56993f8ae | |
| parent | Merge pull request #7 from JacobPalecki/GUI (diff) | |
| download | rawaccel-5241f9783b41e74f719dc4a472c6b0803b0eff8c.tar.xz rawaccel-5241f9783b41e74f719dc4a472c6b0803b0eff8c.zip | |
add read
add function that makes an ioctl call to return the driver's active mouse_modifier
| -rw-r--r-- | common/common.vcxitems | 1 | ||||
| -rw-r--r-- | common/external/tagged-union-single.h | 2 | ||||
| -rw-r--r-- | common/rawaccel-io.hpp | 46 | ||||
| -rw-r--r-- | driver/driver.cpp | 63 |
4 files changed, 89 insertions, 23 deletions
diff --git a/common/common.vcxitems b/common/common.vcxitems index d1e8db0..aeeaa95 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -23,6 +23,7 @@ <ClInclude Include="$(MSBuildThisFileDirectory)accel-power.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-sigmoid.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-error.hpp" /> + <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-io.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-userspace.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)x64-util.hpp" /> diff --git a/common/external/tagged-union-single.h b/common/external/tagged-union-single.h index 3353325..f0de097 100644 --- a/common/external/tagged-union-single.h +++ b/common/external/tagged-union-single.h @@ -137,7 +137,7 @@ struct tagged_union { int tag = 0; struct storage_t { - alignas(max_align_of<First, Rest...>) char bytes[max_size_of<First, Rest...>] = ""; + alignas(max_align_of<First, Rest...>) char bytes[max_size_of<First, Rest...>] = {}; template <typename T> inline constexpr T& as() { diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp new file mode 100644 index 0000000..5d6fad6 --- /dev/null +++ b/common/rawaccel-io.hpp @@ -0,0 +1,46 @@ +#pragma once + +#include <system_error> + +#define NOMINMAX +#include <Windows.h> + +#include "rawaccel.hpp" + +#define RA_IOCTL CTL_CODE(0x8888, 0x888, METHOD_BUFFERED, FILE_ANY_ACCESS) + +namespace rawaccel { + + mouse_modifier read() { + HANDLE ra_handle = INVALID_HANDLE_VALUE; + + ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0); + + if (ra_handle == INVALID_HANDLE_VALUE) { + throw std::system_error(GetLastError(), std::system_category(), "CreateFile failed"); + } + + mouse_modifier mod; + DWORD dummy; + + BOOL success = DeviceIoControl( + ra_handle, + RA_IOCTL, + NULL, // input buffer + 0, // input buffer size + &mod, // output buffer + sizeof(mouse_modifier), // output buffer size + &dummy, // bytes returned + NULL // overlapped structure + ); + + CloseHandle(ra_handle); + + if (!success) { + throw std::system_error(GetLastError(), std::system_category(), "DeviceIoControl failed"); + } + + return mod; + } + +} diff --git a/driver/driver.cpp b/driver/driver.cpp index 1f9cebd..c893b8b 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -143,41 +143,60 @@ Return Value: --*/ { NTSTATUS status; - void* input_buffer; - size_t input_size; + void* buffer; + size_t size; UNREFERENCED_PARAMETER(Queue); - UNREFERENCED_PARAMETER(OutputBufferLength); UNREFERENCED_PARAMETER(IoControlCode); PAGED_CODE(); DebugPrint(("Ioctl received into filter control object.\n")); - if (InputBufferLength != sizeof(ra::mouse_modifier)) { - DebugPrint(("Received unknown request of %u bytes\n", InputBufferLength)); - // status maps to win32 error code 1784: ERROR_INVALID_USER_BUFFER - WdfRequestComplete(Request, STATUS_INVALID_BUFFER_SIZE); - return; - } + if (InputBufferLength == sizeof(ra::mouse_modifier)) { + status = WdfRequestRetrieveInputBuffer( + Request, + sizeof(ra::mouse_modifier), + &buffer, + &size + ); - status = WdfRequestRetrieveInputBuffer( - Request, - sizeof(ra::mouse_modifier), - &input_buffer, - &input_size - ); + if (!NT_SUCCESS(status)) { + DebugPrint(("RetrieveInputBuffer failed: 0x%x\n", status)); + // status maps to win32 error code 1359: ERROR_INTERNAL_ERROR + WdfRequestComplete(Request, STATUS_MESSAGE_LOST); + return; + } - if (!NT_SUCCESS(status)) { - DebugPrint(("RetrieveInputBuffer failed: 0x%x\n", status)); - // status maps to win32 error code 1359: ERROR_INTERNAL_ERROR - WdfRequestComplete(Request, STATUS_MESSAGE_LOST); - return; + global.modifier = *reinterpret_cast<ra::mouse_modifier*>(buffer); + + WdfRequestComplete(Request, STATUS_SUCCESS); } + else if (OutputBufferLength == sizeof(ra::mouse_modifier)) { + status = WdfRequestRetrieveOutputBuffer( + Request, + sizeof(ra::mouse_modifier), + &buffer, + &size + ); + + if (!NT_SUCCESS(status)) { + DebugPrint(("RetrieveOutputBuffer failed: 0x%x\n", status)); + // status maps to win32 error code 1359: ERROR_INTERNAL_ERROR + WdfRequestComplete(Request, STATUS_MESSAGE_LOST); + return; + } + + *reinterpret_cast<ra::mouse_modifier*>(buffer) = global.modifier; - global.modifier = *reinterpret_cast<ra::mouse_modifier*>(input_buffer); + WdfRequestComplete(Request, STATUS_SUCCESS); + } + else { + DebugPrint(("Received unknown request: in %uB, out %uB\n", InputBufferLength, OutputBufferLength)); + // status maps to win32 error code 1784: ERROR_INVALID_USER_BUFFER + WdfRequestComplete(Request, STATUS_INVALID_BUFFER_SIZE); + } - WdfRequestComplete(Request, STATUS_SUCCESS); } #pragma warning(pop) // enable 28118 again |