├── HIDDriverLib ├── mouse.cpp ├── keyboard.cpp ├── framework.h ├── pch.cpp ├── HIDDriverLib.cpp ├── HIDDriverLib.vcxproj.user ├── pch.h ├── registry.h ├── device.h ├── registry.cpp ├── keyboard.h ├── HIDDriverLib.vcxproj.filters ├── mouse.h ├── device.cpp ├── keys.h └── HIDDriverLib.vcxproj ├── HIDDriver ├── driver.h ├── KMDFDriver.vcxproj.user ├── memory.h ├── queue_default.h ├── queue_manual.h ├── driver.c ├── device.h ├── README.md ├── memory.c ├── hid.h ├── hidriver.inf ├── KMDFDriver.vcxproj.filters ├── queue_manual.c ├── queue_default.c ├── device.c └── KMDFDriver.vcxproj ├── HIDDriverLibTest ├── HIDDriverLibTest.vcxproj.user ├── HIDDriverLibTest.vcxproj.filters ├── HIDDriverLibTest.cpp └── HIDDriverLibTest.vcxproj ├── .gitignore ├── README.md ├── HIDDriver.sln └── LICENSE /HIDDriverLib/mouse.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dengqizhou30/HIDDriver/HEAD/HIDDriverLib/mouse.cpp -------------------------------------------------------------------------------- /HIDDriverLib/keyboard.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dengqizhou30/HIDDriver/HEAD/HIDDriverLib/keyboard.cpp -------------------------------------------------------------------------------- /HIDDriverLib/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 4 | -------------------------------------------------------------------------------- /HIDDriverLib/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /HIDDriver/driver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | DRIVER_INITIALIZE DriverEntry; 7 | EVT_WDF_DRIVER_DEVICE_ADD DriverEvtDeviceAdd; -------------------------------------------------------------------------------- /HIDDriver/KMDFDriver.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /HIDDriverLib/HIDDriverLib.cpp: -------------------------------------------------------------------------------- 1 | // HIDDriverLib.cpp : 定义静态库的函数。 2 | // 3 | 4 | #include "pch.h" 5 | #include "framework.h" 6 | 7 | // TODO: 这是一个库函数示例 8 | void fnHIDDriverLib() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /HIDDriverLib/HIDDriverLib.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /HIDDriverLibTest/HIDDriverLibTest.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /HIDDriver/memory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | NTSTATUS 7 | CopyToRequestBuffer( 8 | _In_ WDFREQUEST request, 9 | _In_ PVOID sourceBuffer, 10 | _In_ size_t numBytesToCopyFrom 11 | ); -------------------------------------------------------------------------------- /HIDDriverLib/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。 3 | ################################################################################ 4 | 5 | /.vs 6 | /HIDDriver/x64/Release 7 | /HIDDriverLib/x64/Release 8 | /HIDDriverLibTest/x64/Release 9 | /x64/Release 10 | /HIDDriver/x64/Debug 11 | /HIDDriverLib/x64/Debug 12 | /HIDDriverLibTest/x64/Debug 13 | /x64/Debug 14 | -------------------------------------------------------------------------------- /HIDDriverLib/registry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class RegistryService 7 | { 8 | 9 | public: 10 | static RegistryService &get(); 11 | 12 | int getMouseSensivity() const; 13 | int getMouseSpeed() const; 14 | 15 | private: 16 | explicit RegistryService() = default; 17 | RegistryService(const RegistryService &) = delete; 18 | void operator =(const RegistryService &) = delete; 19 | virtual ~RegistryService() = default; 20 | }; 21 | -------------------------------------------------------------------------------- /HIDDriver/queue_default.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "device.h" 7 | 8 | typedef struct _QUEUE_DEFAULT_CONTEXT { 9 | WDFDEVICE device; 10 | WDFQUEUE queue; 11 | } QUEUE_DEFAULT_CONTEXT, *PQUEUE_DEFAULT_CONTEXT; 12 | 13 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(QUEUE_DEFAULT_CONTEXT, QueueDefaultGetContext); 14 | 15 | NTSTATUS 16 | QueueDefaultCreate( 17 | _In_ WDFDEVICE device, 18 | _Out_ WDFQUEUE *queue 19 | ); 20 | 21 | EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL QueueDefaultEvtIoDeviceControl; -------------------------------------------------------------------------------- /HIDDriver/queue_manual.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "device.h" 7 | #include "hid.h" 8 | 9 | typedef struct _QUEUE_MANUAL_CONTEXT { 10 | WDFDEVICE device; 11 | WDFQUEUE queue; 12 | } QUEUE_MANUAL_CONTEXT, *PQUEUE_MANUAL_CONTEXT; 13 | 14 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(QUEUE_MANUAL_CONTEXT, QueueManualGetContext); 15 | 16 | NTSTATUS 17 | QueueManualCreate( 18 | _In_ WDFDEVICE device, 19 | _Out_ WDFQUEUE *queue 20 | ); 21 | 22 | NTSTATUS 23 | QueueManualSendReport( 24 | _In_ WDFREQUEST outputRequest, 25 | _In_ PDEVICE_CONTEXT deviceContext 26 | ); -------------------------------------------------------------------------------- /HIDDriver/driver.c: -------------------------------------------------------------------------------- 1 | #include "driver.h" 2 | #include "device.h" 3 | 4 | #include 5 | 6 | _Use_decl_annotations_ 7 | NTSTATUS 8 | DriverEntry( 9 | _In_ PDRIVER_OBJECT driverObject, 10 | _In_ PUNICODE_STRING registryPath) 11 | { 12 | NTSTATUS status = STATUS_SUCCESS; 13 | WDF_DRIVER_CONFIG config; 14 | 15 | WDF_DRIVER_CONFIG_INIT(&config, DriverEvtDeviceAdd); 16 | 17 | status = WdfDriverCreate(driverObject, registryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE); 18 | 19 | return status; 20 | } 21 | 22 | _Use_decl_annotations_ 23 | NTSTATUS 24 | DriverEvtDeviceAdd( 25 | _In_ WDFDRIVER driver, 26 | _Inout_ PWDFDEVICE_INIT deviceInit) 27 | { 28 | UNREFERENCED_PARAMETER(driver); 29 | return DeviceCreate(deviceInit); 30 | } -------------------------------------------------------------------------------- /HIDDriver/device.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define VENDOR_ID 0x00 8 | #define PRODUCT_ID 0x00 9 | #define VERSION_NUMBER 0x00 10 | 11 | typedef UCHAR HID_REPORT_DESCRIPTOR, *PHID_REPORT_DESCRIPTOR; 12 | 13 | typedef struct _DEVICE_CONTEXT { 14 | WDFDEVICE device; 15 | WDFQUEUE queueDefault; 16 | WDFQUEUE queueManual; 17 | 18 | HID_DEVICE_ATTRIBUTES hidDeviceAttributes; 19 | PHID_DESCRIPTOR hidDescriptor; 20 | PHID_REPORT_DESCRIPTOR hidReportDescriptor; 21 | } DEVICE_CONTEXT, *PDEVICE_CONTEXT; 22 | 23 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DEVICE_CONTEXT, DeviceGetContext); 24 | 25 | NTSTATUS 26 | DeviceCreate( 27 | _Inout_ PWDFDEVICE_INIT deviceInit 28 | ); -------------------------------------------------------------------------------- /HIDDriverLib/device.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | 7 | class Device 8 | { 9 | 10 | public: 11 | explicit Device(PCWSTR deviceInterface); 12 | Device(const Device &) = delete; 13 | void operator =(const Device &) = delete; 14 | virtual ~Device() = default; 15 | 16 | virtual void initialize(); 17 | virtual void abort(); 18 | 19 | bool isInitialized() const; 20 | bool isAborted() const; 21 | 22 | protected: 23 | void setOutputReport(PVOID data, DWORD size); 24 | 25 | private: 26 | PCWSTR mp_deviceInterface {nullptr}; 27 | HANDLE mp_deviceHandle {nullptr}; 28 | bool m_isInitialized {false}; 29 | bool m_isAborted {false}; 30 | }; 31 | -------------------------------------------------------------------------------- /HIDDriverLib/registry.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "framework.h" 3 | 4 | #include "registry.h" 5 | 6 | RegistryService &RegistryService::get() 7 | { 8 | static RegistryService instance; 9 | return instance; 10 | } 11 | 12 | int RegistryService::getMouseSensivity() const 13 | { 14 | DWORD size = 3; 15 | char buffer[3]; 16 | 17 | LONG getValueResult = RegGetValueA(HKEY_CURRENT_USER, "Control Panel\\Mouse", "MouseSensitivity", RRF_RT_REG_SZ, nullptr, &buffer, &size); 18 | if (ERROR_SUCCESS != getValueResult) { 19 | return -1; 20 | } 21 | 22 | return atoi(buffer); 23 | } 24 | 25 | int RegistryService::getMouseSpeed() const 26 | { 27 | DWORD size = 2; 28 | char buffer[2]; 29 | 30 | LONG getValueResult = RegGetValueA(HKEY_CURRENT_USER, "Control Panel\\Mouse", "MouseSpeed", RRF_RT_REG_SZ, nullptr, &buffer, &size); 31 | if (ERROR_SUCCESS != getValueResult) { 32 | return -1; 33 | } 34 | 35 | return atoi(buffer); 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 虚拟鼠标键盘驱动程序,使用驱动程序执行鼠标键盘操作。
2 | 注意这个驱动目前使用的是测试证书,还没有微软颁发的正式证书,只能在win 10测试模式下执行。
3 | 4 | 5 | 一、项目编译:
6 | 建议使用Visual Studio 2019;
7 | 8 | 9 | 二、驱动安装:
10 | 1、关闭签名校验,开启调试模式:
11 | 在win10中,管理员模式的命令行中,执行如下命令:
12 | bcdedit /set nointegritychecks on
13 | bcdedit /set testsigning on
14 | 然后重启win10,进入测试模式
15 | 16 | 2、使用devcon安装驱动,最好先关闭360等杀毒软件:
17 | cd G:\workspace_github\loki-hidriver\x64\Debug\KMDFDriver
18 | & "D:/Windows Kits/10/Tools/x64/devcon.exe" find "root\hidriver"
19 | & "D:/Windows Kits/10/Tools/x64/devcon.exe" remove "root\hidriver"
20 | & "D:/Windows Kits/10/Tools/x64/devcon.exe" install hidriver.inf "root\hidriver"
21 | 22 | 3、安装驱动的日志文件,可以在这里检查驱动安装的明细日志:
23 | %windir%\\inf\\setupapi.dev.log
24 | C:\Windows\INF\setupapi.dev.log
25 | 26 | 27 | 三、项目来源:
28 | 目前只是针对win10做些兼容性调整,主体代码来源于loki-hidriver项目,感谢原开发者:
29 | https://github.com/hedgar2017/loki-hidriver
30 | -------------------------------------------------------------------------------- /HIDDriver/README.md: -------------------------------------------------------------------------------- 1 | 虚拟鼠标键盘驱动程序,使用驱动程序执行鼠标键盘操作。
2 | 注意这个驱动目前使用的是测试证书,还没有微软颁发的正式证书,只能在win 10测试模式下执行。
3 | 4 | 5 | 一、项目编译:
6 | 建议使用Visual Studio 2019;
7 | 8 | 9 | 二、驱动安装:
10 | 1、关闭签名校验,开启调试模式:
11 | 在win10中,管理员模式的命令行中,执行如下命令:
12 | bcdedit /set nointegritychecks on
13 | bcdedit /set testsigning on
14 | 然后重启win10,进入测试模式
15 | 16 | 2、使用devcon安装驱动,最好先关闭360等杀毒软件:
17 | cd G:\workspace_github\loki-hidriver\x64\Debug\KMDFDriver
18 | & "D:/Windows Kits/10/Tools/x64/devcon.exe" find "root\hidriver"
19 | & "D:/Windows Kits/10/Tools/x64/devcon.exe" remove "root\hidriver"
20 | & "D:/Windows Kits/10/Tools/x64/devcon.exe" install hidriver.inf "root\hidriver"
21 | 22 | 3、安装驱动的日志文件,可以在这里检查驱动安装的明细日志:
23 | %windir%\\inf\\setupapi.dev.log
24 | C:\Windows\INF\setupapi.dev.log
25 | 26 | 27 | 三、项目来源:
28 | 目前只是针对win10做些兼容性调整,主体代码来源于loki-hidriver项目,感谢原开发者:
29 | https://github.com/hedgar2017/loki-hidriver
30 | -------------------------------------------------------------------------------- /HIDDriverLibTest/HIDDriverLibTest.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /HIDDriver/memory.c: -------------------------------------------------------------------------------- 1 | #include "memory.h" 2 | 3 | _Use_decl_annotations_ 4 | NTSTATUS 5 | CopyToRequestBuffer( 6 | _In_ WDFREQUEST request, 7 | _In_ PVOID sourceBuffer, 8 | _In_ size_t numBytesToCopyFrom) 9 | { 10 | NTSTATUS status = STATUS_SUCCESS; 11 | WDFMEMORY memory = NULL; 12 | size_t outputBufferLength = 0; 13 | 14 | if (numBytesToCopyFrom <= 0) { 15 | status = STATUS_INVALID_BUFFER_SIZE; 16 | return status; 17 | } 18 | 19 | status = WdfRequestRetrieveOutputMemory(request, &memory); 20 | if (!NT_SUCCESS(status)) { 21 | return status; 22 | } 23 | 24 | WdfMemoryGetBuffer(memory, &outputBufferLength); 25 | if (outputBufferLength < numBytesToCopyFrom) { 26 | status = STATUS_INVALID_BUFFER_SIZE; 27 | return status; 28 | } 29 | 30 | status = WdfMemoryCopyFromBuffer(memory, 0, sourceBuffer, numBytesToCopyFrom); 31 | if (!NT_SUCCESS(status)) { 32 | return status; 33 | } 34 | 35 | WdfRequestSetInformation(request, numBytesToCopyFrom); 36 | return status; 37 | } -------------------------------------------------------------------------------- /HIDDriverLib/keyboard.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "device.h" 4 | 5 | #include 6 | 7 | #include "keys.h" 8 | 9 | class Keyboard : public Device 10 | { 11 | 12 | public: 13 | explicit Keyboard(); 14 | Keyboard(const Keyboard &) = delete; 15 | void operator =(const Keyboard &) = delete; 16 | virtual ~Keyboard() override = default; 17 | 18 | virtual void initialize() override; 19 | 20 | virtual void type(BYTE keyCode); 21 | 22 | virtual void abort() override; 23 | 24 | protected: 25 | BYTE m_modifiers {KEY_NONE}; 26 | 27 | static const BYTE REPORT_ID {0x04}; 28 | 29 | private: 30 | #pragma pack(1) 31 | struct Report { 32 | BYTE reportId; 33 | BYTE modifiers; 34 | BYTE _reserved; 35 | BYTE keyCodes[6]; 36 | }; 37 | #pragma pack() 38 | 39 | virtual void sendKeyboardReport(BYTE *keyCodes); 40 | }; 41 | -------------------------------------------------------------------------------- /HIDDriver/hid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #define REPORT_ID_MOUSE_INPUT 0x01 7 | #define REPORT_ID_MOUSE_OUTPUT 0x02 8 | #define REPORT_ID_KEYBOARD_INPUT 0x03 9 | #define REPORT_ID_KEYBOARD_OUTPUT 0x04 10 | 11 | #pragma pack(1) 12 | typedef struct _HID_MOUSE_INPUT_REPORT { 13 | BYTE reportId; 14 | BYTE buttons; 15 | CHAR x; 16 | CHAR y; 17 | } HID_MOUSE_INPUT_REPORT, *PHID_MOUSE_INPUT_REPORT; 18 | 19 | typedef struct _HID_MOUSE_OUTPUT_REPORT { 20 | BYTE reportId; 21 | BYTE buttons; 22 | CHAR x; 23 | CHAR y; 24 | } HID_MOUSE_OUTPUT_REPORT, *PHID_MOUSE_OUTPUT_REPORT; 25 | 26 | typedef struct _HID_KEYBOARD_INPUT_REPORT { 27 | BYTE reportId; 28 | BYTE modifiers; 29 | BYTE _reserved; 30 | BYTE keyCodes[6]; 31 | } HID_KEYBOARD_INPUT_REPORT, *PHID_KEYBOARD_INPUT_REPORT; 32 | 33 | typedef struct _HID_KEYBOARD_OUTPUT_REPORT { 34 | BYTE reportId; 35 | BYTE modifiers; 36 | BYTE _reserved; 37 | BYTE keyCodes[6]; 38 | } HID_KEYBOARD_OUTPUT_REPORT, *PHID_KEYBOARD_OUTPUT_REPORT; 39 | #pragma pack() -------------------------------------------------------------------------------- /HIDDriverLibTest/HIDDriverLibTest.cpp: -------------------------------------------------------------------------------- 1 | // HIDDriverLibTest.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | #include "mouse.h" 8 | #include "keyboard.h" 9 | 10 | int main() 11 | { 12 | Mouse mouse; 13 | try { 14 | mouse.initialize(); 15 | } 16 | catch (const std::runtime_error& e) { 17 | std::cout << std::string("鼠标设备初始化失败: ") + e.what() << std::endl; 18 | return EXIT_FAILURE; 19 | } 20 | 21 | Keyboard keyboard; 22 | try { 23 | keyboard.initialize(); 24 | } 25 | catch (const std::runtime_error& e) { 26 | std::cout << std::string("键盘设备初始化失败: ") + e.what() << std::endl; 27 | return EXIT_FAILURE; 28 | } 29 | 30 | Sleep(5000); 31 | 32 | 33 | mouse.moveCursor(900, 900, 300, 600, 1,1); 34 | Sleep(5000); 35 | 36 | /** 37 | //mouse.moveCursor(136, 271); 38 | mouse.moveCursorEx(10, 0); 39 | mouse.leftButtonClick(); 40 | Sleep(2000); 41 | //mouse.moveCursor(56, 315); 42 | mouse.moveCursorEx(-10, 0); 43 | mouse.leftButtonClick(); 44 | Sleep(2000); 45 | //mouse.moveCursor(283, 350); 46 | mouse.moveCursorEx(10, 0); 47 | mouse.leftButtonClick(); 48 | Sleep(2000); 49 | //mouse.moveCursor(275, 271); 50 | mouse.moveCursorEx(-10, 0); 51 | mouse.leftButtonClick(); 52 | Sleep(2000); 53 | */ 54 | 55 | return EXIT_SUCCESS; 56 | } 57 | -------------------------------------------------------------------------------- /HIDDriver/hidriver.inf: -------------------------------------------------------------------------------- 1 | [Version] 2 | Signature="$WINDOWS NT$" 3 | Class=%ClassName% 4 | ClassGuid={78A1C341-4539-11d3-B88D-00C04FAD5171} 5 | Provider=%ProviderName% 6 | CatalogFile=hidriver.cat 7 | DriverVer=10/10/2021 8 | 9 | [ClassInstall32] 10 | Addreg=ClassReg 11 | [ClassReg] 12 | HKR,,,0,%ClassName% 13 | HKR,,Icon,,-24 14 | 15 | [SourceDisksNames] 16 | 1=%DiskName%,,, 17 | [SourceDisksFiles] 18 | hidriver.sys=1 19 | [DestinationDirs] 20 | DefaultDestDir=12 21 | 22 | [Manufacturer] 23 | %ManufacturerName%=Microsoft,NT$ARCH$.6.1 24 | [Microsoft.NT$ARCH$.6.1] 25 | %DeviceName%=MyInstall,root\hidriver 26 | 27 | [MyInstall.NT] 28 | CopyFiles=Files 29 | [Files] 30 | hidriver.sys 31 | 32 | [MyInstall.NT.HW] 33 | AddReg=HWAddReg 34 | [HWAddReg] 35 | HKR,,"LowerFilters",0x00010008,"hidriver" 36 | 37 | [MyInstall.NT.Services] 38 | AddService=hidriver,0x00000000,hidriverService 39 | AddService=mshidkmdf,0x00000002,mshidkmdfService 40 | [hidriverService] 41 | DisplayName=%ServiceName% 42 | ServiceType=1 43 | StartType=3 44 | ErrorControl=1 45 | ServiceBinary=%12%\hidriver.sys 46 | [mshidkmdfService] 47 | ServiceType=1 48 | StartType=3 49 | ErrorControl=1 50 | ServiceBinary=%12%\mshidkmdf.sys 51 | 52 | [MyInstall.NT.Wdf] 53 | KmdfService=hidriver,KmdfLibrary 54 | [KmdfLibrary] 55 | KmdfLibraryVersion=$KMDFVERSION$ 56 | 57 | [Strings] 58 | # DeviceName="VARIABLE_1" 59 | # DiskName="VARIABLE_2" 60 | # ProviderName="VARIABLE_3" 61 | # ManufacturerName="VARIABLE_4" 62 | # ServiceName="VARIABLE_5" 63 | # ClassName="VARIABLE_6" 64 | 65 | DeviceName="HIDRIVERDEVICE" 66 | DiskName="HIDRIVERDISK" 67 | ProviderName="HIDRIVERPROVIDER" 68 | ManufacturerName="HIDRIVERMANUFACTURER" 69 | ServiceName="HIDRIVERSVC" 70 | ClassName="HIDRIVER" -------------------------------------------------------------------------------- /HIDDriver/KMDFDriver.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | c 6 | {EEA9A0D2-B8ED-4A83-9FD8-86D012F2A3DD} 7 | 8 | 9 | h 10 | {DE5B128E-EFF9-4660-B21A-9D0826098B5B} 11 | 12 | 13 | inf;inx 14 | {662CD683-2177-4B49-ACF5-1D536E8595F4} 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | 55 | 56 | Driver Files 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /HIDDriverLib/HIDDriverLib.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 源文件 49 | 50 | 51 | 源文件 52 | 53 | 54 | 源文件 55 | 56 | 57 | 源文件 58 | 59 | 60 | -------------------------------------------------------------------------------- /HIDDriverLib/mouse.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "device.h" 4 | 5 | #include 6 | #include 7 | 8 | class Mouse : public Device 9 | { 10 | 11 | public: 12 | explicit Mouse(); 13 | Mouse(const Mouse &) = delete; 14 | void operator =(const Mouse &) = delete; 15 | virtual ~Mouse() override = default; 16 | 17 | virtual void initialize() override; 18 | virtual void abort() override; 19 | 20 | virtual void leftButtonDown(); 21 | virtual void leftButtonUp(); 22 | virtual void leftButtonClick(); 23 | 24 | virtual void rightButtonDown(); 25 | virtual void rightButtonUp(); 26 | virtual void rightButtonClick(); 27 | 28 | virtual void middleButtonDown(); 29 | virtual void middleButtonUp(); 30 | virtual void middleButtonClick(); 31 | 32 | virtual void moveCursor(POINT); 33 | virtual void moveCursor(LONG x, LONG y); 34 | virtual void moveCursor(LONG x1, LONG y1, LONG x2, LONG y2, double z, double mouseMoveSlow); 35 | virtual void moveCursorEx(LONG x, LONG y); 36 | 37 | int getSpeedByRange(int range) const; 38 | static int getRangeBySpeed(int speed); 39 | 40 | virtual void sendMouseReport(CHAR xSpeed, CHAR ySpeed); 41 | 42 | protected: 43 | enum Button { 44 | BUTTON_NONE = 0x00, 45 | BUTTON_LEFT = 0x01, 46 | BUTTON_RIGHT = 0x02, 47 | BUTTON_MIDDLE = 0x04 48 | }; 49 | 50 | void populateRangeSpeedVector(); 51 | 52 | static POINT getCurrentCursorPosition(LPDWORD error); 53 | 54 | BYTE m_buttons {BUTTON_NONE}; 55 | std::vector m_rangeSpeedVector; 56 | 57 | static const BYTE REPORT_ID {0x02}; 58 | static const LONG MAX_ABSOLUTE_SPEED {127}; 59 | static const int DISTANCE_TOLERANCE {3}; 60 | static const int EPP_DISABLED {0}; 61 | static const int EPP_ENABLED {1}; 62 | static const int SENSITIVITY_MIN {1}; 63 | static const int SENSITIVITY_MAX {20}; 64 | 65 | private: 66 | #pragma pack(1) 67 | struct Report { 68 | BYTE reportId; 69 | BYTE buttons; 70 | CHAR x; 71 | CHAR y; 72 | }; 73 | #pragma pack() 74 | 75 | 76 | }; 77 | -------------------------------------------------------------------------------- /HIDDriverLib/device.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "framework.h" 3 | 4 | #include "device.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | Device::Device(PCWSTR deviceInterface) 11 | : mp_deviceInterface{deviceInterface} 12 | {} 13 | 14 | void Device::initialize() 15 | { 16 | if (isInitialized()) throw std::runtime_error{"ERROR_DOUBLE_INITIALIZATION"}; 17 | 18 | GUID guid; 19 | HidD_GetHidGuid(&guid); 20 | 21 | ULONG deviceInterfaceListLength = 0; 22 | CONFIGRET configret = CM_Get_Device_Interface_List_Size( 23 | &deviceInterfaceListLength, 24 | &guid, 25 | nullptr, 26 | CM_GET_DEVICE_INTERFACE_LIST_PRESENT 27 | ); 28 | if (CR_SUCCESS != configret) { 29 | throw std::runtime_error{"ERROR_GETTING_DEVICE_INTERFACE_LIST_SIZE"}; 30 | } 31 | 32 | if (deviceInterfaceListLength <= 1) { 33 | throw std::runtime_error{"ERROR_EMPTY_DEVICE_INTERFACE_LIST"}; 34 | } 35 | 36 | PWSTR deviceInterfaceList = (PWSTR) malloc(deviceInterfaceListLength * sizeof(WCHAR)); 37 | if (nullptr == deviceInterfaceList) { 38 | throw std::runtime_error{"ERROR_ALLOCATING_DEVICE_INTERFACE_LIST"}; 39 | } 40 | ZeroMemory(deviceInterfaceList, deviceInterfaceListLength * sizeof(WCHAR)); 41 | 42 | configret = CM_Get_Device_Interface_List( 43 | &guid, 44 | nullptr, 45 | deviceInterfaceList, 46 | deviceInterfaceListLength, 47 | CM_GET_DEVICE_INTERFACE_LIST_PRESENT 48 | ); 49 | if (CR_SUCCESS != configret) { 50 | free(deviceInterfaceList); 51 | throw std::runtime_error{"ERROR_GETTING_DEVICE_INTERFACE_LIST"}; 52 | } 53 | 54 | size_t deviceInterfaceLength = wcslen(mp_deviceInterface); 55 | HANDLE file = INVALID_HANDLE_VALUE; 56 | for (PWSTR currentInterface = deviceInterfaceList; *currentInterface; currentInterface += wcslen(currentInterface) + 1) { 57 | if (0 != wcsncmp(currentInterface, mp_deviceInterface, deviceInterfaceLength)) { 58 | continue; 59 | } 60 | 61 | file = CreateFile(currentInterface, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); 62 | if (INVALID_HANDLE_VALUE == file) { 63 | continue; 64 | } 65 | 66 | break; 67 | } 68 | free(deviceInterfaceList); 69 | if (INVALID_HANDLE_VALUE == file) { 70 | throw std::runtime_error{"ERROR_INVALID_HANDLE_VALUE"}; 71 | } 72 | 73 | mp_deviceHandle = file; 74 | m_isInitialized = true; 75 | } 76 | 77 | bool Device::isInitialized() const 78 | { 79 | return m_isInitialized; 80 | } 81 | 82 | bool Device::isAborted() const 83 | { 84 | return m_isAborted; 85 | } 86 | 87 | void Device::abort() 88 | { 89 | if (nullptr != mp_deviceHandle && INVALID_HANDLE_VALUE != mp_deviceHandle) { 90 | CloseHandle(mp_deviceHandle); 91 | } 92 | m_isAborted = true; 93 | } 94 | 95 | void Device::setOutputReport(PVOID data, DWORD size) 96 | { 97 | if (!HidD_SetOutputReport(mp_deviceHandle, data, size)) { 98 | throw std::runtime_error{"ERROR_SET_OUTPUT_REPORT"}; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /HIDDriver/queue_manual.c: -------------------------------------------------------------------------------- 1 | #include "queue_manual.h" 2 | #include "memory.h" 3 | #include "hid.h" 4 | 5 | _Use_decl_annotations_ 6 | NTSTATUS 7 | QueueManualCreate( 8 | _In_ WDFDEVICE device, 9 | _Out_ WDFQUEUE *queueOut) 10 | { 11 | NTSTATUS status = STATUS_SUCCESS; 12 | WDFQUEUE queue = NULL; 13 | PQUEUE_MANUAL_CONTEXT queueContext = NULL; 14 | 15 | WDF_IO_QUEUE_CONFIG queueConfig; 16 | WDF_OBJECT_ATTRIBUTES queueAttributes; 17 | 18 | WDF_IO_QUEUE_CONFIG_INIT(&queueConfig, WdfIoQueueDispatchManual); 19 | 20 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&queueAttributes, QUEUE_MANUAL_CONTEXT); 21 | 22 | status = WdfIoQueueCreate(device, &queueConfig, &queueAttributes, &queue); 23 | if (!NT_SUCCESS(status)) { 24 | return status; 25 | } 26 | 27 | queueContext = QueueManualGetContext(queue); 28 | queueContext->device = device; 29 | queueContext->queue = queue; 30 | 31 | *queueOut = queue; 32 | return status; 33 | } 34 | 35 | _Use_decl_annotations_ 36 | NTSTATUS 37 | QueueManualSendReport( 38 | _In_ WDFREQUEST outputRequest, 39 | _In_ PDEVICE_CONTEXT deviceContext) 40 | { 41 | NTSTATUS status = STATUS_SUCCESS; 42 | WDFQUEUE queue = deviceContext->queueManual; 43 | size_t inputReportRequiredSize = 0; 44 | 45 | WDFREQUEST inputRequest; 46 | WDF_REQUEST_PARAMETERS outputRequestParams; 47 | HID_XFER_PACKET hidXferPacket; 48 | 49 | WDF_REQUEST_PARAMETERS_INIT(&outputRequestParams); 50 | WdfRequestGetParameters(outputRequest, &outputRequestParams); 51 | if (outputRequestParams.Parameters.DeviceIoControl.InputBufferLength < sizeof(HID_XFER_PACKET)) { 52 | status = STATUS_BUFFER_TOO_SMALL; 53 | return status; 54 | } 55 | RtlCopyMemory(&hidXferPacket, WdfRequestWdmGetIrp(outputRequest)->UserBuffer, sizeof(HID_XFER_PACKET)); 56 | 57 | switch (hidXferPacket.reportId) { 58 | case REPORT_ID_MOUSE_OUTPUT: 59 | hidXferPacket.reportId = REPORT_ID_MOUSE_INPUT; 60 | hidXferPacket.reportBuffer[0] = hidXferPacket.reportId; 61 | inputReportRequiredSize = sizeof(HID_MOUSE_INPUT_REPORT); 62 | break; 63 | case REPORT_ID_KEYBOARD_OUTPUT: 64 | hidXferPacket.reportId = REPORT_ID_KEYBOARD_INPUT; 65 | hidXferPacket.reportBuffer[0] = hidXferPacket.reportId; 66 | inputReportRequiredSize = sizeof(HID_KEYBOARD_INPUT_REPORT); 67 | break; 68 | default: 69 | status = STATUS_INVALID_PARAMETER; 70 | return status; 71 | } 72 | 73 | if (hidXferPacket.reportBufferLen < inputReportRequiredSize) { 74 | status = STATUS_INVALID_BUFFER_SIZE; 75 | return status; 76 | } 77 | 78 | status = WdfIoQueueRetrieveNextRequest(queue, &inputRequest); 79 | if (!NT_SUCCESS(status)) { 80 | return status; 81 | } 82 | status = CopyToRequestBuffer(inputRequest, hidXferPacket.reportBuffer, inputReportRequiredSize); 83 | 84 | WdfRequestComplete(inputRequest, status); 85 | return status; 86 | } -------------------------------------------------------------------------------- /HIDDriver/queue_default.c: -------------------------------------------------------------------------------- 1 | #include "queue_default.h" 2 | #include "queue_manual.h" 3 | #include "device.h" 4 | #include "memory.h" 5 | 6 | _Use_decl_annotations_ 7 | NTSTATUS 8 | QueueDefaultCreate( 9 | _In_ WDFDEVICE device, 10 | _Out_ WDFQUEUE *queueOut) 11 | { 12 | NTSTATUS status = STATUS_SUCCESS; 13 | WDFQUEUE queue = NULL; 14 | PQUEUE_DEFAULT_CONTEXT context = NULL; 15 | WDF_IO_QUEUE_CONFIG config; 16 | WDF_OBJECT_ATTRIBUTES attributes; 17 | 18 | WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&config, WdfIoQueueDispatchSequential); 19 | config.EvtIoInternalDeviceControl = QueueDefaultEvtIoDeviceControl; 20 | 21 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, QUEUE_DEFAULT_CONTEXT); 22 | 23 | status = WdfIoQueueCreate(device, &config, &attributes, &queue); 24 | if (!NT_SUCCESS(status)) { 25 | return status; 26 | } 27 | 28 | context = QueueDefaultGetContext(queue); 29 | context->device = device; 30 | context->queue = queue; 31 | *queueOut = queue; 32 | 33 | return status; 34 | } 35 | 36 | _Use_decl_annotations_ 37 | VOID 38 | QueueDefaultEvtIoDeviceControl( 39 | _In_ WDFQUEUE queue, 40 | _In_ WDFREQUEST request, 41 | _In_ size_t outputBufferLength, 42 | _In_ size_t inputBufferLength, 43 | _In_ ULONG ioControlCode) 44 | { 45 | UNREFERENCED_PARAMETER(outputBufferLength); 46 | UNREFERENCED_PARAMETER(inputBufferLength); 47 | 48 | NTSTATUS status = STATUS_SUCCESS; 49 | PDEVICE_CONTEXT deviceContext = DeviceGetContext(QueueDefaultGetContext(queue)->device); 50 | 51 | switch (ioControlCode) { 52 | case IOCTL_HID_GET_DEVICE_DESCRIPTOR: 53 | status = CopyToRequestBuffer( 54 | request, 55 | deviceContext->hidDescriptor, 56 | deviceContext->hidDescriptor->bLength 57 | ); 58 | WdfRequestComplete(request, status); 59 | break; 60 | case IOCTL_HID_GET_DEVICE_ATTRIBUTES: 61 | status = CopyToRequestBuffer( 62 | request, 63 | &deviceContext->hidDeviceAttributes, 64 | sizeof(HID_DEVICE_ATTRIBUTES) 65 | ); 66 | WdfRequestComplete(request, status); 67 | break; 68 | case IOCTL_HID_GET_REPORT_DESCRIPTOR: 69 | status = CopyToRequestBuffer( 70 | request, 71 | deviceContext->hidReportDescriptor, 72 | deviceContext->hidDescriptor->DescriptorList[0].wReportLength 73 | ); 74 | WdfRequestComplete(request, status); 75 | break; 76 | case IOCTL_HID_READ_REPORT: 77 | case IOCTL_HID_GET_INPUT_REPORT: 78 | status = WdfRequestForwardToIoQueue( 79 | request, 80 | deviceContext->queueManual 81 | ); 82 | if (!NT_SUCCESS(status)) { 83 | WdfRequestComplete(request, status); 84 | } 85 | break; 86 | case IOCTL_HID_WRITE_REPORT: 87 | case IOCTL_HID_SET_OUTPUT_REPORT: 88 | status = QueueManualSendReport( 89 | request, 90 | deviceContext 91 | ); 92 | WdfRequestComplete(request, status); 93 | break; 94 | default: 95 | status = STATUS_NOT_IMPLEMENTED; 96 | WdfRequestComplete(request, status); 97 | break; 98 | } 99 | } -------------------------------------------------------------------------------- /HIDDriver.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31727.386 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HIDDriverLib", "HIDDriverLib\HIDDriverLib.vcxproj", "{6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HIDDriverLibTest", "HIDDriverLibTest\HIDDriverLibTest.vcxproj", "{6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82} = {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82} 11 | EndProjectSection 12 | EndProject 13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HIDDriver", "HIDDriver\KMDFDriver.vcxproj", "{F99BF4F7-CF9B-4891-AF76-70B1C5046B05}" 14 | EndProject 15 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7C7B93A0-08BF-41D6-B8E2-2D49D855097D}" 16 | ProjectSection(SolutionItems) = preProject 17 | README.md = README.md 18 | EndProjectSection 19 | EndProject 20 | Global 21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 22 | Debug|Any CPU = Debug|Any CPU 23 | Debug|x64 = Debug|x64 24 | Debug|x86 = Debug|x86 25 | Release|Any CPU = Release|Any CPU 26 | Release|x64 = Release|x64 27 | Release|x86 = Release|x86 28 | EndGlobalSection 29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 30 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}.Debug|Any CPU.ActiveCfg = Debug|Win32 31 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}.Debug|x64.ActiveCfg = Debug|x64 32 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}.Debug|x64.Build.0 = Debug|x64 33 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}.Debug|x86.ActiveCfg = Debug|Win32 34 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}.Debug|x86.Build.0 = Debug|Win32 35 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}.Release|Any CPU.ActiveCfg = Release|Win32 36 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}.Release|x64.ActiveCfg = Release|x64 37 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}.Release|x64.Build.0 = Release|x64 38 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}.Release|x86.ActiveCfg = Release|Win32 39 | {6A105B31-1EE8-4945-8AB0-CF79FBB5FF82}.Release|x86.Build.0 = Release|Win32 40 | {6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}.Debug|Any CPU.ActiveCfg = Debug|Win32 41 | {6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}.Debug|x64.ActiveCfg = Debug|x64 42 | {6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}.Debug|x64.Build.0 = Debug|x64 43 | {6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}.Debug|x86.ActiveCfg = Debug|Win32 44 | {6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}.Debug|x86.Build.0 = Debug|Win32 45 | {6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}.Release|Any CPU.ActiveCfg = Release|Win32 46 | {6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}.Release|x64.ActiveCfg = Release|x64 47 | {6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}.Release|x64.Build.0 = Release|x64 48 | {6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}.Release|x86.ActiveCfg = Release|Win32 49 | {6DB636CF-AB31-45BB-80A0-547C3C6DFDDA}.Release|x86.Build.0 = Release|Win32 50 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Debug|Any CPU.ActiveCfg = Debug|Win32 51 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Debug|x64.ActiveCfg = Debug|x64 52 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Debug|x64.Build.0 = Debug|x64 53 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Debug|x64.Deploy.0 = Debug|x64 54 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Debug|x86.ActiveCfg = Debug|Win32 55 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Debug|x86.Build.0 = Debug|Win32 56 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Debug|x86.Deploy.0 = Debug|Win32 57 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Release|Any CPU.ActiveCfg = Release|Win32 58 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Release|x64.ActiveCfg = Release|x64 59 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Release|x64.Build.0 = Release|x64 60 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Release|x64.Deploy.0 = Release|x64 61 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Release|x86.ActiveCfg = Release|Win32 62 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Release|x86.Build.0 = Release|Win32 63 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05}.Release|x86.Deploy.0 = Release|Win32 64 | EndGlobalSection 65 | GlobalSection(SolutionProperties) = preSolution 66 | HideSolutionNode = FALSE 67 | EndGlobalSection 68 | GlobalSection(ExtensibilityGlobals) = postSolution 69 | SolutionGuid = {FBE4F112-896D-40A2-B0C5-8687372A4CA8} 70 | EndGlobalSection 71 | EndGlobal 72 | -------------------------------------------------------------------------------- /HIDDriverLib/keys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define KEY_MOD_LCTRL 0x01 4 | #define KEY_MOD_LSHIFT 0x02 5 | #define KEY_MOD_LALT 0x04 6 | #define KEY_MOD_LMETA 0x08 7 | #define KEY_MOD_RCTRL 0x10 8 | #define KEY_MOD_RSHIFT 0x20 9 | #define KEY_MOD_RALT 0x40 10 | #define KEY_MOD_RMETA 0x80 11 | 12 | #define KEY_NONE 0x00 // No key pressed 13 | 14 | #define KEY_A 0x04 // Keyboard a and A 15 | #define KEY_B 0x05 // Keyboard b and B 16 | #define KEY_C 0x06 // Keyboard c and C 17 | #define KEY_D 0x07 // Keyboard d and D 18 | #define KEY_E 0x08 // Keyboard e and E 19 | #define KEY_F 0x09 // Keyboard f and F 20 | #define KEY_G 0x0a // Keyboard g and G 21 | #define KEY_H 0x0b // Keyboard h and H 22 | #define KEY_I 0x0c // Keyboard i and I 23 | #define KEY_J 0x0d // Keyboard j and J 24 | #define KEY_K 0x0e // Keyboard k and K 25 | #define KEY_L 0x0f // Keyboard l and L 26 | #define KEY_M 0x10 // Keyboard m and M 27 | #define KEY_N 0x11 // Keyboard n and N 28 | #define KEY_O 0x12 // Keyboard o and O 29 | #define KEY_P 0x13 // Keyboard p and P 30 | #define KEY_Q 0x14 // Keyboard q and Q 31 | #define KEY_R 0x15 // Keyboard r and R 32 | #define KEY_S 0x16 // Keyboard s and S 33 | #define KEY_T 0x17 // Keyboard t and T 34 | #define KEY_U 0x18 // Keyboard u and U 35 | #define KEY_V 0x19 // Keyboard v and V 36 | #define KEY_W 0x1a // Keyboard w and W 37 | #define KEY_X 0x1b // Keyboard x and X 38 | #define KEY_Y 0x1c // Keyboard y and Y 39 | #define KEY_Z 0x1d // Keyboard z and Z 40 | 41 | #define KEY_1 0x1e // Keyboard 1 and ! 42 | #define KEY_2 0x1f // Keyboard 2 and @ 43 | #define KEY_3 0x20 // Keyboard 3 and # 44 | #define KEY_4 0x21 // Keyboard 4 and $ 45 | #define KEY_5 0x22 // Keyboard 5 and % 46 | #define KEY_6 0x23 // Keyboard 6 and ^ 47 | #define KEY_7 0x24 // Keyboard 7 and & 48 | #define KEY_8 0x25 // Keyboard 8 and * 49 | #define KEY_9 0x26 // Keyboard 9 and ( 50 | #define KEY_0 0x27 // Keyboard 0 and ) 51 | 52 | #define KEY_ENTER 0x28 // Keyboard Return (ENTER) 53 | #define KEY_ESC 0x29 // Keyboard ESCAPE 54 | #define KEY_BACKSPACE 0x2a // Keyboard DELETE (Backspace) 55 | #define KEY_TAB 0x2b // Keyboard Tab 56 | #define KEY_SPACE 0x2c // Keyboard Spacebar 57 | #define KEY_MINUS 0x2d // Keyboard - and _ 58 | #define KEY_EQUAL 0x2e // Keyboard = and + 59 | #define KEY_LEFTBRACE 0x2f // Keyboard [ and { 60 | #define KEY_RIGHTBRACE 0x30 // Keyboard ] and } 61 | #define KEY_BACKSLASH 0x31 // Keyboard \ and | 62 | #define KEY_HASHTILDE 0x32 // Keyboard Non-US # and ~ 63 | #define KEY_SEMICOLON 0x33 // Keyboard ; and : 64 | #define KEY_APOSTROPHE 0x34 // Keyboard ' and " 65 | #define KEY_GRAVE 0x35 // Keyboard ` and ~ 66 | #define KEY_COMMA 0x36 // Keyboard , and < 67 | #define KEY_DOT 0x37 // Keyboard . and > 68 | #define KEY_SLASH 0x38 // Keyboard / and ? 69 | #define KEY_CAPSLOCK 0x39 // Keyboard Caps Lock 70 | 71 | #define KEY_F1 0x3a // Keyboard F1 72 | #define KEY_F2 0x3b // Keyboard F2 73 | #define KEY_F3 0x3c // Keyboard F3 74 | #define KEY_F4 0x3d // Keyboard F4 75 | #define KEY_F5 0x3e // Keyboard F5 76 | #define KEY_F6 0x3f // Keyboard F6 77 | #define KEY_F7 0x40 // Keyboard F7 78 | #define KEY_F8 0x41 // Keyboard F8 79 | #define KEY_F9 0x42 // Keyboard F9 80 | #define KEY_F10 0x43 // Keyboard F10 81 | #define KEY_F11 0x44 // Keyboard F11 82 | #define KEY_F12 0x45 // Keyboard F12 83 | 84 | #define KEY_SYSRQ 0x46 // Keyboard Print Screen 85 | #define KEY_SCROLLLOCK 0x47 // Keyboard Scroll Lock 86 | #define KEY_PAUSE 0x48 // Keyboard Pause 87 | #define KEY_INSERT 0x49 // Keyboard Insert 88 | #define KEY_HOME 0x4a // Keyboard Home 89 | #define KEY_PAGEUP 0x4b // Keyboard Page Up 90 | #define KEY_DELETE 0x4c // Keyboard Delete Forward 91 | #define KEY_END 0x4d // Keyboard End 92 | #define KEY_PAGEDOWN 0x4e // Keyboard Page Down 93 | #define KEY_RIGHT 0x4f // Keyboard Right Arrow 94 | #define KEY_LEFT 0x50 // Keyboard Left Arrow 95 | #define KEY_DOWN 0x51 // Keyboard Down Arrow 96 | #define KEY_UP 0x52 // Keyboard Up Arrow 97 | 98 | #define KEY_NUMLOCK 0x53 // Keyboard Num Lock and Clear 99 | #define KEY_KPSLASH 0x54 // Keypad / 100 | #define KEY_KPASTERISK 0x55 // Keypad * 101 | #define KEY_KPMINUS 0x56 // Keypad - 102 | #define KEY_KPPLUS 0x57 // Keypad + 103 | #define KEY_KPENTER 0x58 // Keypad ENTER 104 | #define KEY_KP1 0x59 // Keypad 1 and End 105 | #define KEY_KP2 0x5a // Keypad 2 and Down Arrow 106 | #define KEY_KP3 0x5b // Keypad 3 and PageDn 107 | #define KEY_KP4 0x5c // Keypad 4 and Left Arrow 108 | #define KEY_KP5 0x5d // Keypad 5 109 | #define KEY_KP6 0x5e // Keypad 6 and Right Arrow 110 | #define KEY_KP7 0x5f // Keypad 7 and Home 111 | #define KEY_KP8 0x60 // Keypad 8 and Up Arrow 112 | #define KEY_KP9 0x61 // Keypad 9 and Page Up 113 | #define KEY_KP0 0x62 // Keypad 0 and Insert 114 | #define KEY_KPDOT 0x63 // Keypad . and Delete 115 | 116 | #define KEY_102ND 0x64 // Keyboard Non-US \ and | 117 | #define KEY_COMPOSE 0x65 // Keyboard Application 118 | 119 | #define KEY_LEFTCTRL 0xe0 // Keyboard Left Control 120 | #define KEY_LEFTSHIFT 0xe1 // Keyboard Left Shift 121 | #define KEY_LEFTALT 0xe2 // Keyboard Left Alt 122 | #define KEY_LEFTMETA 0xe3 // Keyboard Left GUI 123 | #define KEY_RIGHTCTRL 0xe4 // Keyboard Right Control 124 | #define KEY_RIGHTSHIFT 0xe5 // Keyboard Right Shift 125 | #define KEY_RIGHTALT 0xe6 // Keyboard Right Alt 126 | #define KEY_RIGHTMETA 0xe7 // Keyboard Right GUI 127 | -------------------------------------------------------------------------------- /HIDDriver/device.c: -------------------------------------------------------------------------------- 1 | #include "device.h" 2 | #include "queue_default.h" 3 | #include "queue_manual.h" 4 | 5 | HID_REPORT_DESCRIPTOR g_reportDescriptor[] = { 6 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 7 | 0x09, 0x02, // USAGE (Mouse) 8 | 0xA1, 0x01, // COLLECTION (Application) 9 | 0x85, REPORT_ID_MOUSE_INPUT, 10 | 0x09, 0x01, // USAGE_PAGE (Pointer) 11 | 0xA1, 0x00, // COLLECTION (Physical) 12 | 0x05, 0x09, // USAGE_PAGE (Buttons) 13 | 0x19, 0x01, // USAGE_MINIMUM (1) 14 | 0x29, 0x03, // USAGE_MAXIMUM (3) 15 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 16 | 0x25, 0x01, // LOGICAL_MAXIMUM (1) 17 | 0x95, 0x03, // REPORT_COUNT (3) 18 | 0x75, 0x01, // REPORT_SIZE (1) 19 | 0x81, 0x02, // INPUT (Data, Variable, Absolute) 20 | 0x95, 0x01, // REPORT_COUNT (1) 21 | 0x75, 0x05, // REPORT_SIZE (5) 22 | 0x81, 0x01, // INPUT (Constant) 23 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 24 | 0x09, 0x30, // USAGE (X) 25 | 0x09, 0x31, // USAGE (Y) 26 | 0x15, 0x81, // LOGICAL_MINIMUM (-127) 27 | 0x25, 0x7F, // LOGICAL_MAXIMUM (127) 28 | 0x75, 0x08, // REPORT_SIZE (8) 29 | 0x95, 0x02, // REPORT_COUNT (2) 30 | 0x81, 0x06, // Input (Data, Variable, Relative) 31 | 0xC0, // END_COLLECTION 32 | 0xC0, // END_COLLECTION 33 | 34 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 35 | 0x09, 0x00, // USAGE (Undefined) 36 | 0xa1, 0x01, // COLLECTION (Application) 37 | 0x85, REPORT_ID_MOUSE_OUTPUT, 38 | 0x09, 0x00, // USAGE (Undefined) 39 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 40 | 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) 41 | 0x95, 0x03, // REPORT_COUNT (3) 42 | 0x75, 0x08, // REPORT_SIZE (8) 43 | 0x91, 0x02, // OUTPUT (Data, Variable, Absolute) 44 | 0xc0, // END_COLLECTION 45 | 46 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 47 | 0x09, 0x06, // USAGE (Keyboard) 48 | 0xA1, 0x01, // COLLECTION (Application) 49 | 0x85, REPORT_ID_KEYBOARD_INPUT, 50 | 0x05, 0x07, // USAGE_PAGE (Keyboard Key Codes) 51 | 0x19, 0xE0, // USAGE_MINIMUM (224) 52 | 0x29, 0xE7, // USAGE_MAXIMUM (231) 53 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 54 | 0x25, 0x01, // LOGICAL_MAXIMUM (1) 55 | 0x75, 0x01, // REPORT_SIZE (1) 56 | 0x95, 0x08, // REPORT_COUNT (8) 57 | 0x81, 0x02, // INPUT (Data, Variable, Absolute) 58 | 0x95, 0x01, // REPORT_COUNT (1) 59 | 0x75, 0x08, // REPORT_SIZE (8) 60 | 0x81, 0x01, // INPUT (Constant) 61 | 0x19, 0x00, // USAGE_MINIMUM (0) 62 | 0x29, 0x65, // USAGE_MAXIMUM (101) 63 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 64 | 0x25, 0x65, // LOGICAL_MAXIMUM (101) 65 | 0x95, 0x06, // REPORT_COUNT (6) 66 | 0x75, 0x08, // REPORT_SIZE (8) 67 | 0x81, 0x00, // INPUT (Data, Array, Absolute) 68 | 0x05, 0x08, // USAGE_PAGE (LEDs) 69 | 0x19, 0x01, // USAGE_MINIMUM (Num Lock) 70 | 0x29, 0x05, // USAGE_MAXIMUM (Kana) 71 | 0x95, 0x05, // REPORT_COUNT (5) 72 | 0x75, 0x01, // REPORT_SIZE (1) 73 | 0x91, 0x02, // OUTPUT (Data, Variable, Absolute) 74 | 0x95, 0x01, // REPORT_COUNT (1) 75 | 0x75, 0x03, // REPORT_SIZE (3) 76 | 0x91, 0x01, // OUTPUT (Constant) 77 | 0xC0, // END_COLLECTION 78 | 79 | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 80 | 0x09, 0x00, // USAGE (Undefined) 81 | 0xa1, 0x01, // COLLECTION (Application) 82 | 0x85, REPORT_ID_KEYBOARD_OUTPUT, 83 | 0x09, 0x00, // USAGE (Undefined) 84 | 0x15, 0x00, // LOGICAL_MINIMUM (0) 85 | 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255) 86 | 0x95, 0x08, // REPORT_COUNT (8) 87 | 0x75, 0x08, // REPORT_SIZE (8) 88 | 0x91, 0x02, // OUTPUT (Data, Variable, Absolute) 89 | 0xc0 // END_COLLECTION 90 | }; 91 | 92 | HID_DESCRIPTOR g_hidDescriptor = { 93 | 0x09, // length of HID descriptor 94 | 0x21, // descriptor type == HID 0x21 95 | 0x0100, // hid spec release 96 | 0x00, // country code == Not Specified 97 | 0x01, // number of HID class descriptors 98 | { // DescriptorList[0] 99 | 0x22, // report descriptor type 0x22 100 | sizeof(g_reportDescriptor) // total length of report descriptor 101 | } 102 | }; 103 | 104 | _Use_decl_annotations_ 105 | NTSTATUS 106 | DeviceCreate( 107 | _Inout_ PWDFDEVICE_INIT deviceInit) 108 | { 109 | NTSTATUS status = STATUS_SUCCESS; 110 | WDFDEVICE device = NULL; 111 | PDEVICE_CONTEXT deviceContext = NULL; 112 | WDF_OBJECT_ATTRIBUTES deviceAttributes; 113 | 114 | WdfFdoInitSetFilter(deviceInit); 115 | 116 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, DEVICE_CONTEXT); 117 | 118 | status = WdfDeviceCreate(&deviceInit, &deviceAttributes, &device); 119 | if (!NT_SUCCESS(status)) { 120 | return status; 121 | } 122 | 123 | deviceContext = DeviceGetContext(device); 124 | deviceContext->device = device; 125 | deviceContext->queueDefault = NULL; 126 | deviceContext->queueManual = NULL; 127 | deviceContext->hidDescriptor = &g_hidDescriptor; 128 | deviceContext->hidReportDescriptor = g_reportDescriptor; 129 | 130 | RtlZeroMemory(&deviceContext->hidDeviceAttributes, sizeof(HID_DEVICE_ATTRIBUTES)); 131 | deviceContext->hidDeviceAttributes.Size = sizeof(HID_DEVICE_ATTRIBUTES); 132 | deviceContext->hidDeviceAttributes.VendorID = VENDOR_ID; 133 | deviceContext->hidDeviceAttributes.ProductID = PRODUCT_ID; 134 | deviceContext->hidDeviceAttributes.VersionNumber = VERSION_NUMBER; 135 | 136 | status = QueueDefaultCreate(device, &deviceContext->queueDefault); 137 | if (!NT_SUCCESS(status)) { 138 | return status; 139 | } 140 | 141 | status = QueueManualCreate(device, &deviceContext->queueManual); 142 | 143 | return status; 144 | } -------------------------------------------------------------------------------- /HIDDriver/KMDFDriver.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {F99BF4F7-CF9B-4891-AF76-70B1C5046B05} 23 | {1bc93793-694f-48fe-9372-81e2b05556fd} 24 | 12.0 25 | Debug 26 | Win32 27 | KMDFDriver 28 | HIDDriver 29 | $(LatestTargetPlatformVersion) 30 | 31 | 32 | 33 | 34 | 35 | true 36 | WindowsKernelModeDriver10.0 37 | Driver 38 | KMDF 39 | 40 | 41 | 42 | 43 | 44 | 45 | false 46 | WindowsKernelModeDriver10.0 47 | Driver 48 | KMDF 49 | 50 | 51 | 52 | 53 | 54 | 55 | true 56 | WindowsKernelModeDriver10.0 57 | Driver 58 | KMDF 59 | 60 | 61 | 1 62 | 9 63 | 64 | 65 | 66 | 67 | false 68 | WindowsKernelModeDriver10.0 69 | Driver 70 | KMDF 71 | 72 | 73 | 1 74 | 9 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | hidriver 95 | AllRules.ruleset 96 | false 97 | true 98 | 99 | 100 | hidriver 101 | true 102 | 103 | 104 | hidriver 105 | 106 | 107 | hidriver 108 | 109 | 110 | 111 | false 112 | stdcpp17 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /HIDDriverLibTest/HIDDriverLibTest.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {6db636cf-ab31-45bb-80a0-547c3c6dfdda} 25 | HIDDriverLibTest 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | $(SolutionDir)HIDDriverLib;$(ExternalIncludePath) 82 | $(SolutionDir)x64\Debug;$(DDK_LibraryPath_DDKPlatform);$(LibraryPath) 83 | 84 | 85 | false 86 | $(SolutionDir)HIDDriverLib;$(ExternalIncludePath) 87 | $(SolutionDir)x64\Release;$(DDK_LibraryPath_DDKPlatform);$(LibraryPath) 88 | 89 | 90 | 91 | Level3 92 | true 93 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 94 | true 95 | 96 | 97 | Console 98 | true 99 | 100 | 101 | 102 | 103 | Level3 104 | true 105 | true 106 | true 107 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 108 | true 109 | 110 | 111 | Console 112 | true 113 | true 114 | true 115 | 116 | 117 | 118 | 119 | Level3 120 | true 121 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 122 | true 123 | 124 | 125 | Console 126 | true 127 | HIDDriverLib.lib;Cfgmgr32.lib;Hid.lib;%(AdditionalDependencies) 128 | 129 | 130 | 131 | 132 | Level3 133 | true 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | true 138 | stdcpp17 139 | MultiThreaded 140 | 141 | 142 | Console 143 | true 144 | true 145 | true 146 | HIDDriverLib.lib;Cfgmgr32.lib;Hid.lib;%(AdditionalDependencies) 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /HIDDriverLib/HIDDriverLib.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {6a105b31-1ee8-4945-8ab0-cf79fbb5ff82} 25 | HIDDriverLib 26 | 10.0 27 | 28 | 29 | 30 | StaticLibrary 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | StaticLibrary 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | StaticLibrary 44 | v142 45 | Unicode 46 | 47 | 48 | StaticLibrary 49 | true 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | false 77 | 78 | 79 | true 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Level3 87 | true 88 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 89 | true 90 | Use 91 | pch.h 92 | 93 | 94 | 95 | 96 | true 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | true 104 | true 105 | WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 106 | true 107 | Use 108 | pch.h 109 | 110 | 111 | 112 | 113 | true 114 | true 115 | true 116 | 117 | 118 | 119 | 120 | Level3 121 | true 122 | _DEBUG;_LIB;%(PreprocessorDefinitions) 123 | true 124 | Use 125 | pch.h 126 | Default 127 | MultiThreadedDebugDLL 128 | 129 | 130 | 131 | 132 | true 133 | 134 | 135 | 136 | 137 | Level3 138 | true 139 | true 140 | NDEBUG;_LIB;%(PreprocessorDefinitions) 141 | true 142 | Use 143 | pch.h 144 | stdcpp17 145 | MultiThreaded 146 | None 147 | true 148 | 149 | 150 | 151 | 152 | true 153 | true 154 | true 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | Create 173 | Create 174 | Create 175 | Create 176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------