├── .gitignore ├── CUEORGBPlugin.sln ├── CUEORGBPlugin.vcxproj ├── CUEORGBPlugin.vcxproj.filters ├── CUESDKDevice.h ├── CorsairPluginDevice.cpp ├── CorsairPluginDevice.h ├── CorsairPluginDeviceManager.cpp ├── CorsairPluginDeviceManager.h ├── LICENSE ├── OpenRGBClient ├── OpenRGBClient.cpp ├── OpenRGBClient.vcxproj └── OpenRGBClient.vcxproj.filters ├── README.md ├── dist └── plugins │ └── OpenRGB │ ├── devices.json │ ├── images │ ├── gpu │ │ └── default │ │ │ ├── device_view.png │ │ │ ├── promo.png │ │ │ └── thumbnail.png │ ├── keyboard │ │ └── default │ │ │ ├── device_view.jpg │ │ │ ├── device_view_mask.png │ │ │ ├── promo.jpg │ │ │ └── thumbnail.png │ ├── led_strip │ │ └── default │ │ │ └── device_view.png │ └── motherboard │ │ └── default │ │ ├── device_view.png │ │ ├── promo.png │ │ └── thumbnail.png │ └── settings.json ├── dllmain.cpp ├── exports.def ├── screenshots ├── custom_device.png ├── custom_device_v4.PNG └── open_rgb_server.PNG ├── thirdparty ├── CUESDK │ └── CorsairLedIdEnum.h ├── MinHook │ ├── include │ │ └── MinHook.h │ └── src │ │ ├── buffer.c │ │ ├── buffer.h │ │ ├── hde │ │ ├── hde32.c │ │ ├── hde32.h │ │ ├── hde64.c │ │ ├── hde64.h │ │ ├── pstdint.h │ │ ├── table32.h │ │ └── table64.h │ │ ├── hook.c │ │ ├── trampoline.c │ │ └── trampoline.h ├── OpenRGB │ ├── NetworkClient.cpp │ ├── NetworkClient.h │ ├── NetworkProtocol.cpp │ ├── NetworkProtocol.h │ ├── RGBController │ │ ├── RGBController.cpp │ │ ├── RGBController.h │ │ ├── RGBController_Network.cpp │ │ └── RGBController_Network.h │ └── net_port │ │ ├── net_port.cpp │ │ └── net_port.h ├── json │ └── json.hpp └── sha256 │ └── picosha2.h ├── version_wrapper ├── dllmain.cpp ├── version.def ├── version_wrapper.vcxproj └── version_wrapper.vcxproj.filters └── wrapper ├── dllmain.cpp ├── dsound.def ├── wrapper.vcxproj └── wrapper.vcxproj.filters /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.db 3 | *.db-shm 4 | .vs/CUEORGBPlugin/v16/.suo 5 | .vs/CUEORGBPlugin/v16/Browse.VC.db-wal 6 | .vs/CUEORGBPlugin/v16/Browse.VC.opendb 7 | .vs/CUEORGBPlugin/v16/ipch/1ec06a64a6c4f86.ipch 8 | .vs/CUEORGBPlugin/v16/ipch/68643e07a70ce213.ipch 9 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/11ce7df6f0d933d/HOOK.ipch 10 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/306beae86944fa4/BUFFER.ipch 11 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/3c92720a49927499/DLLMAIN.ipch 12 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/4c08ecadff7d1e2e/RGBCONTROLLER.ipch 13 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/61e22fdb9b9d237f/RGBCONTROLLER_NETWORK.ipch 14 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/6db90fc3c31aa1d3/NETWORKCLIENT.ipch 15 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/757f2cce72e2e9ea/DLLMAIN.ipch 16 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/83027e4f9a54a6e6/MINHOOK.ipch 17 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/d7138a543be9ede/CORSAIRPLUGINDEVICE.ipch 18 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/d9129b772a1e2a9f/CORSAIRPLUGINDEVICEMANAGER.ipch 19 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/df49c5c67e15d04d/CORSAIRPLUGINDEVICEMANAGER.ipch 20 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/e53d65a3158db21c/DLLMAIN.ipch 21 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/f6cd0d56c2d1344f/DLLMAIN.ipch 22 | .vs/CUEORGBPlugin/v16/ipch/AutoPCH/f9f36af27f6193b3/HOOK.ipch 23 | CUEORGBPlugin.vcxproj.user 24 | Debug/CorsairPluginDevice.obj 25 | Debug/CorsairPluginDeviceManager.obj 26 | Debug/CUEORGBPlugin.dll 27 | Debug/CUEORGBPlugin.dll.recipe 28 | Debug/CUEORGBPlugin.exp 29 | Debug/CUEORGBPlugin.ilk 30 | Debug/CUEORGBPlugin.lib 31 | Debug/CUEORGBPlugin.log 32 | Debug/CUEORGBPlugin.pdb 33 | Debug/CUEORGBPlugin.tlog/CL.command.1.tlog 34 | Debug/CUEORGBPlugin.tlog/CL.read.1.tlog 35 | Debug/CUEORGBPlugin.tlog/CL.write.1.tlog 36 | Debug/CUEORGBPlugin.tlog/CUEORGBPlugin.lastbuildstate 37 | Debug/CUEORGBPlugin.tlog/CUEORGBPlugin.write.1u.tlog 38 | Debug/CUEORGBPlugin.tlog/link.34804.delete.1.tlog 39 | Debug/CUEORGBPlugin.tlog/link.command.1.tlog 40 | Debug/CUEORGBPlugin.tlog/link.read.1.tlog 41 | Debug/CUEORGBPlugin.tlog/link.write.1.tlog 42 | Debug/CUEORGBPlugin.vcxproj.FileListAbsolute.txt 43 | Debug/dllmain.obj 44 | Debug/dsound.dll 45 | Debug/dsound.exp 46 | Debug/dsound.ilk 47 | Debug/dsound.lib 48 | Debug/dsound.pdb 49 | Debug/net_port.obj 50 | Debug/NetworkClient.obj 51 | Debug/NetworkProtocol.obj 52 | Debug/RGBController.obj 53 | Debug/RGBController_Network.obj 54 | Debug/vc142.idb 55 | Debug/vc142.pdb 56 | Debug/wrapper.dll 57 | Debug/wrapper.exp 58 | Debug/wrapper.ilk 59 | Debug/wrapper.lib 60 | Debug/wrapper.pdb 61 | Release/CorsairPluginDevice.obj 62 | Release/CorsairPluginDeviceManager.obj 63 | Release/CUEORGBPlugin.dll 64 | Release/CUEORGBPlugin.dll.recipe 65 | Release/CUEORGBPlugin.exp 66 | Release/CUEORGBPlugin.iobj 67 | Release/CUEORGBPlugin.ipdb 68 | Release/CUEORGBPlugin.lib 69 | Release/CUEORGBPlugin.log 70 | Release/CUEORGBPlugin.pdb 71 | Release/CUEORGBPlugin.tlog/CL.command.1.tlog 72 | Release/CUEORGBPlugin.tlog/CL.read.1.tlog 73 | Release/CUEORGBPlugin.tlog/CL.write.1.tlog 74 | Release/CUEORGBPlugin.tlog/CUEORGBPlugin.lastbuildstate 75 | Release/CUEORGBPlugin.tlog/CUEORGBPlugin.write.1u.tlog 76 | Release/CUEORGBPlugin.tlog/link.command.1.tlog 77 | Release/CUEORGBPlugin.tlog/link.delete.1.tlog 78 | Release/CUEORGBPlugin.tlog/link.read.1.tlog 79 | Release/CUEORGBPlugin.tlog/link.write.1.tlog 80 | Release/CUEORGBPlugin.vcxproj.FileListAbsolute.txt 81 | Release/dllmain.obj 82 | Release/dsound.dll 83 | Release/dsound.exp 84 | Release/dsound.iobj 85 | Release/dsound.ipdb 86 | Release/dsound.lib 87 | Release/dsound.pdb 88 | Release/net_port.obj 89 | Release/NetworkClient.obj 90 | Release/NetworkProtocol.obj 91 | Release/RGBController.obj 92 | Release/RGBController_Network.obj 93 | Release/vc142.pdb 94 | wrapper/Debug/buffer.obj 95 | wrapper/Debug/dllmain.obj 96 | wrapper/Debug/dsound.dll.recipe 97 | wrapper/Debug/hde32.obj 98 | wrapper/Debug/hde64.obj 99 | wrapper/Debug/hook.obj 100 | wrapper/Debug/trampoline.obj 101 | wrapper/Debug/vc142.idb 102 | wrapper/Debug/vc142.pdb 103 | wrapper/Debug/wrapper.log 104 | wrapper/Debug/wrapper.tlog/CL.command.1.tlog 105 | wrapper/Debug/wrapper.tlog/CL.read.1.tlog 106 | wrapper/Debug/wrapper.tlog/CL.write.1.tlog 107 | wrapper/Debug/wrapper.tlog/link.command.1.tlog 108 | wrapper/Debug/wrapper.tlog/link.read.1.tlog 109 | wrapper/Debug/wrapper.tlog/link.write.1.tlog 110 | wrapper/Debug/wrapper.tlog/wrapper.lastbuildstate 111 | wrapper/Debug/wrapper.tlog/wrapper.write.1u.tlog 112 | wrapper/Release/buffer.obj 113 | wrapper/Release/dllmain.obj 114 | wrapper/Release/dsound.dll.recipe 115 | wrapper/Release/hde32.obj 116 | wrapper/Release/hde64.obj 117 | wrapper/Release/hook.obj 118 | wrapper/Release/trampoline.obj 119 | wrapper/Release/vc142.pdb 120 | wrapper/Release/wrapper.log 121 | wrapper/Release/wrapper.tlog/CL.command.1.tlog 122 | wrapper/Release/wrapper.tlog/CL.read.1.tlog 123 | wrapper/Release/wrapper.tlog/CL.write.1.tlog 124 | wrapper/Release/wrapper.tlog/link.command.1.tlog 125 | wrapper/Release/wrapper.tlog/link.read.1.tlog 126 | wrapper/Release/wrapper.tlog/link.write.1.tlog 127 | wrapper/Release/wrapper.tlog/wrapper.lastbuildstate 128 | wrapper/Release/wrapper.tlog/wrapper.write.1u.tlog 129 | wrapper/wrapper.vcxproj.user 130 | *.db-wal 131 | *.ipch 132 | *.obj 133 | *.idb 134 | *.pdb 135 | *.tlog 136 | *.log 137 | *.recipe 138 | *.txt 139 | *.dll 140 | *.exp 141 | *.ilk 142 | *.lib 143 | *.iobj 144 | *.ipdb 145 | -------------------------------------------------------------------------------- /CUEORGBPlugin.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32126.317 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CUEORGBPlugin", "CUEORGBPlugin.vcxproj", "{B71258E2-6D34-419A-82C0-E6F822E57902}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenRGBClient", "OpenRGBClient\OpenRGBClient.vcxproj", "{299ADF00-111D-4EEB-B721-A5EE41FF3B72}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "version_wrapper", "version_wrapper\version_wrapper.vcxproj", "{B6B1125B-DED4-4315-AFA8-B0A0481F1D73}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|x64 = Debug|x64 15 | Debug|x86 = Debug|x86 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {B71258E2-6D34-419A-82C0-E6F822E57902}.Debug|x64.ActiveCfg = Debug|x64 21 | {B71258E2-6D34-419A-82C0-E6F822E57902}.Debug|x64.Build.0 = Debug|x64 22 | {B71258E2-6D34-419A-82C0-E6F822E57902}.Debug|x86.ActiveCfg = Debug|Win32 23 | {B71258E2-6D34-419A-82C0-E6F822E57902}.Debug|x86.Build.0 = Debug|Win32 24 | {B71258E2-6D34-419A-82C0-E6F822E57902}.Release|x64.ActiveCfg = Release|x64 25 | {B71258E2-6D34-419A-82C0-E6F822E57902}.Release|x64.Build.0 = Release|x64 26 | {B71258E2-6D34-419A-82C0-E6F822E57902}.Release|x86.ActiveCfg = Release|Win32 27 | {B71258E2-6D34-419A-82C0-E6F822E57902}.Release|x86.Build.0 = Release|Win32 28 | {299ADF00-111D-4EEB-B721-A5EE41FF3B72}.Debug|x64.ActiveCfg = Debug|x64 29 | {299ADF00-111D-4EEB-B721-A5EE41FF3B72}.Debug|x64.Build.0 = Debug|x64 30 | {299ADF00-111D-4EEB-B721-A5EE41FF3B72}.Debug|x86.ActiveCfg = Debug|Win32 31 | {299ADF00-111D-4EEB-B721-A5EE41FF3B72}.Debug|x86.Build.0 = Debug|Win32 32 | {299ADF00-111D-4EEB-B721-A5EE41FF3B72}.Release|x64.ActiveCfg = Release|x64 33 | {299ADF00-111D-4EEB-B721-A5EE41FF3B72}.Release|x64.Build.0 = Release|x64 34 | {299ADF00-111D-4EEB-B721-A5EE41FF3B72}.Release|x86.ActiveCfg = Release|Win32 35 | {299ADF00-111D-4EEB-B721-A5EE41FF3B72}.Release|x86.Build.0 = Release|Win32 36 | {B6B1125B-DED4-4315-AFA8-B0A0481F1D73}.Debug|x64.ActiveCfg = Debug|x64 37 | {B6B1125B-DED4-4315-AFA8-B0A0481F1D73}.Debug|x64.Build.0 = Debug|x64 38 | {B6B1125B-DED4-4315-AFA8-B0A0481F1D73}.Debug|x86.ActiveCfg = Debug|Win32 39 | {B6B1125B-DED4-4315-AFA8-B0A0481F1D73}.Debug|x86.Build.0 = Debug|Win32 40 | {B6B1125B-DED4-4315-AFA8-B0A0481F1D73}.Release|x64.ActiveCfg = Release|x64 41 | {B6B1125B-DED4-4315-AFA8-B0A0481F1D73}.Release|x64.Build.0 = Release|x64 42 | {B6B1125B-DED4-4315-AFA8-B0A0481F1D73}.Release|x86.ActiveCfg = Release|Win32 43 | {B6B1125B-DED4-4315-AFA8-B0A0481F1D73}.Release|x86.Build.0 = Release|Win32 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {9AB9AE6F-EED3-48D5-8324-3BEBBDDE5026} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /CUEORGBPlugin.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 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 16.0 45 | Win32Proj 46 | {b71258e2-6d34-419a-82c0-e6f822e57902} 47 | CUEORGBPlugin 48 | 10.0 49 | 50 | 51 | 52 | DynamicLibrary 53 | true 54 | v143 55 | Unicode 56 | 57 | 58 | DynamicLibrary 59 | false 60 | v143 61 | true 62 | Unicode 63 | 64 | 65 | DynamicLibrary 66 | true 67 | v143 68 | Unicode 69 | 70 | 71 | DynamicLibrary 72 | false 73 | v143 74 | true 75 | Unicode 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | true 97 | 98 | 99 | false 100 | 101 | 102 | true 103 | 104 | 105 | false 106 | 107 | 108 | 109 | Level3 110 | true 111 | WIN32;_DEBUG;CUEORGBPLUGIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS 112 | true 113 | $(ProjectDir)thirdparty;$(ProjectDir)thirdparty\OpenRGB;$(ProjectDir)thirdparty\OpenRGB\RGBController;$(ProjectDir)thirdparty\OpenRGB\net_port;$(ProjectDir)thirdparty\CUESDK;%(AdditionalIncludeDirectories) 114 | MultiThreadedDebug 115 | 116 | 117 | Windows 118 | true 119 | false 120 | exports.def 121 | 122 | 123 | 124 | 125 | Level3 126 | true 127 | true 128 | true 129 | WIN32;NDEBUG;CUEORGBPLUGIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS 130 | true 131 | $(ProjectDir)thirdparty;$(ProjectDir)thirdparty\OpenRGB;$(ProjectDir)thirdparty\OpenRGB\RGBController;$(ProjectDir)thirdparty\OpenRGB\net_port;$(ProjectDir)thirdparty\CUESDK;%(AdditionalIncludeDirectories) 132 | MultiThreaded 133 | 134 | 135 | Windows 136 | true 137 | true 138 | true 139 | false 140 | exports.def 141 | 142 | 143 | 144 | 145 | Level3 146 | true 147 | WIN32;_DEBUG;CUEORGBPLUGIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS 148 | true 149 | $(ProjectDir)thirdparty;$(ProjectDir)thirdparty\OpenRGB;$(ProjectDir)thirdparty\OpenRGB\RGBController;$(ProjectDir)thirdparty\OpenRGB\net_port;$(ProjectDir)thirdparty\CUESDK;%(AdditionalIncludeDirectories) 150 | MultiThreadedDebug 151 | 152 | 153 | Windows 154 | true 155 | false 156 | exports.def 157 | 158 | 159 | 160 | 161 | Level3 162 | true 163 | true 164 | true 165 | WIN32;NDEBUG;CUEORGBPLUGIN_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS 166 | true 167 | $(ProjectDir)thirdparty;$(ProjectDir)thirdparty\OpenRGB;$(ProjectDir)thirdparty\OpenRGB\RGBController;$(ProjectDir)thirdparty\OpenRGB\net_port;$(ProjectDir)thirdparty\CUESDK;%(AdditionalIncludeDirectories) 168 | MultiThreaded 169 | 170 | 171 | Windows 172 | true 173 | true 174 | true 175 | false 176 | exports.def 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /CUEORGBPlugin.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 | {28b22ee5-a288-44e4-9de0-64cebbe8261b} 18 | 19 | 20 | {eb880aac-2d97-4e92-8299-786b3caf2dec} 21 | 22 | 23 | {554632bb-f343-4283-abab-df219646a837} 24 | 25 | 26 | {85b595a2-96dd-45aa-9ee8-4e35d4d6b553} 27 | 28 | 29 | {58d07bae-6faa-4a30-bc55-1f652b3facd9} 30 | 31 | 32 | {ad402db8-b4ab-400d-9409-68733bf348ad} 33 | 34 | 35 | {666e7ab7-ad7e-44f9-b510-299bc6b70abe} 36 | 37 | 38 | {eb8bde11-6355-48ee-a47b-437607a44227} 39 | 40 | 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files\OpenRGB\net_port 47 | 48 | 49 | Source Files\OpenRGB\RGBController 50 | 51 | 52 | Source Files\OpenRGB\RGBController 53 | 54 | 55 | Source Files\OpenRGB 56 | 57 | 58 | Source Files\OpenRGB 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files\CUESDK 73 | 74 | 75 | Header Files\json 76 | 77 | 78 | Header Files\OpenRGB 79 | 80 | 81 | Header Files\OpenRGB 82 | 83 | 84 | Header Files\OpenRGB\RGBController 85 | 86 | 87 | Header Files\OpenRGB\RGBController 88 | 89 | 90 | Header Files\OpenRGB\net_port 91 | 92 | 93 | Header Files 94 | 95 | 96 | Header Files 97 | 98 | 99 | -------------------------------------------------------------------------------- /CUESDKDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CorsairLedIdEnum.h" 4 | #include 5 | 6 | #define ENABLE_BITMASK_OPERATORS(ENUMTYPE) \ 7 | constexpr ENUMTYPE operator |(ENUMTYPE lhs, ENUMTYPE rhs) {return static_cast (static_cast::type>(lhs) | static_cast::type>(rhs));} \ 8 | constexpr ENUMTYPE operator &(ENUMTYPE lhs, ENUMTYPE rhs) {return static_cast(static_cast::type>(lhs) & static_cast::type>(rhs));} \ 9 | constexpr ENUMTYPE operator ^(ENUMTYPE lhs, ENUMTYPE rhs) {return static_cast (static_cast::type>(lhs) ^ static_cast::type>(rhs));} \ 10 | constexpr ENUMTYPE operator ~(ENUMTYPE rhs) {return static_cast (~static_cast::type>(rhs));} \ 11 | constexpr ENUMTYPE& operator |=(ENUMTYPE& lhs, ENUMTYPE rhs) {lhs = static_cast(static_cast::type>(lhs) | static_cast::type>(rhs));return lhs;} \ 12 | constexpr ENUMTYPE& operator &=(ENUMTYPE& lhs, ENUMTYPE rhs) {lhs = static_cast(static_cast::type>(lhs) & static_cast::type>(rhs));return lhs;} \ 13 | constexpr ENUMTYPE& operator ^=(ENUMTYPE& lhs, ENUMTYPE rhs) {lhs = static_cast(static_cast::type>(lhs) ^ static_cast::type>(rhs));return lhs;} 14 | 15 | namespace cue 16 | { 17 | namespace dev 18 | { 19 | namespace plugin 20 | { 21 | struct Event; 22 | 23 | enum class ZoneAppearance : std::uint32_t 24 | { 25 | SVG_Path = 0, // This seems to be a list of draw commands for a rectangle: "M 155 111 L 233 111 L 233 166 L 155 166 Z" 26 | UI_Text = 1, // Doesn't seem to work? This should be the flow where it takes a text key and converts to UI text 27 | Literal_Text = 2 // Doesn't seem to work? This should be the flow that takes the text from 28 | }; 29 | 30 | enum class SupportedFeatures : std::uint32_t 31 | { 32 | KeyEvents = (1 << 0), 33 | KeyEventsConfiguration = (1 << 1), 34 | DetachedMode = (1 << 2), 35 | PluginProperties = (1 << 3), 36 | DeviceProperties = (1 << 4), 37 | DeviceChannels = (1 << 5) 38 | }; 39 | ENABLE_BITMASK_OPERATORS(SupportedFeatures); 40 | 41 | enum SensorType : std::uint32_t 42 | { 43 | Invalid, 44 | Temperature, 45 | FanRpm, 46 | PumpRpm, 47 | Voltage, 48 | Current, 49 | Power 50 | }; 51 | 52 | enum class PropertyFlags : std::uint32_t 53 | { 54 | CanRead = (1 << 0), 55 | CanWrite = (1 << 1), 56 | Indexed = (1 << 2) 57 | }; 58 | ENABLE_BITMASK_OPERATORS(PropertyFlags); 59 | 60 | enum class PluginPropertyId : std::uint32_t 61 | { 62 | Invalid, 63 | PropertiesList, 64 | Locale 65 | }; 66 | 67 | enum class DevicePropertyId : std::int32_t 68 | { 69 | Invalid, 70 | PropertiesList, 71 | ChannelsCount, // Max 2 channels 72 | ChannelName, 73 | SensorsCount, 74 | SensorType, 75 | SensorName, 76 | SensorValue, 77 | FanPerformanceMode, 78 | FanPerformanceModesList, 79 | PerformanceCurveTemplateDefault, 80 | SensorValueMin, 81 | SensorValueMax, 82 | SingleColorZonesList 83 | }; 84 | 85 | struct PropertyData 86 | { 87 | union 88 | { 89 | bool* boolArray; 90 | std::int32_t* intArray; 91 | double* doubleArray; 92 | char** strArray; 93 | std::int32_t i32; 94 | std::int64_t s64; 95 | double f64; 96 | char* str; 97 | DevicePropertyId* devicePropertyArray; 98 | PluginPropertyId* pluginPropertyArray; 99 | } data; 100 | std::int32_t count; // 04 101 | }; 102 | 103 | enum class FanPerformanceMode : std::uint32_t 104 | { 105 | Invalid, 106 | Default, 107 | Quiet, 108 | Balanced, 109 | Performance, 110 | FixedPwm, 111 | FixedRpm, 112 | Custom, 113 | ZeroRpm 114 | }; 115 | 116 | enum class PropertyDataType : std::uint32_t 117 | { 118 | Bool, 119 | Integer, 120 | Double, 121 | String, 122 | BoolArray = 16, 123 | IntegerArray, 124 | DoubleArray, 125 | StringArray, 126 | LedColorArray 127 | }; 128 | 129 | enum class Mode : std::uint32_t 130 | { 131 | Invalid, 132 | Detached, 133 | Attached 134 | }; 135 | 136 | // 08 137 | struct Image 138 | { 139 | char* path; // 00 00 140 | char* hash; // 04 08 - This is a SHA256 of the image data at the provided path 141 | }; 142 | 143 | struct LedColor // contains information about led and its color. 144 | { 145 | CorsairLedId ledId; // identifier of LED to set. 146 | std::int32_t r; // red brightness[0..255]. 147 | std::int32_t g; // green brightness[0..255]. 148 | std::int32_t b; // blue brightness[0..255]. 149 | }; 150 | 151 | // 20 152 | struct LedPosition 153 | { 154 | CorsairLedId ledId; // 00 155 | std::int32_t unk04; // 04 - Don't know? 156 | double x; // 08 - Is this supposed to be flipped? 157 | double y; // 10 158 | std::int32_t unk18; // 18 - Don't know? 159 | std::int32_t unk1C; // 1C - Don't know? 160 | }; 161 | 162 | // 08 163 | struct LedPositions 164 | { 165 | std::int32_t numberOfLed; // 00 00 166 | LedPosition* ledPosition; // 04 08 167 | }; 168 | 169 | // 10 170 | struct LedView 171 | { 172 | CorsairLedId ledId; // 00 00 173 | char* path; // 04 08 174 | ZoneAppearance appearance; // 08 10 175 | char* text; // 0C 18 176 | }; 177 | 178 | // 08 179 | struct LedViews 180 | { 181 | std::int32_t numberOfLed; // 00 00 182 | LedView* view; // 04 08 183 | }; 184 | 185 | enum class DeviceType : std::uint32_t 186 | { 187 | Invalid = 0, 188 | Keyboard, 189 | Mouse 190 | }; 191 | 192 | // 1C 193 | struct DeviceInfo 194 | { 195 | char* deviceName; // 00 00 - UI name of the device 196 | DeviceType deviceType; // 04 04 197 | LedPositions* ledPositions; // 08 08 198 | Image* thumbnail; // 0C 10 - Thumbnail shown when editing a device 199 | char* deviceId; // 10 18 - Unique name of the device, passed to other calls to determine what device it is 200 | std::int32_t numberOfDeviceView; // 14 20 - Number of device views to display in the UI, this will result in multiple calls to CorsairPluginGetDeviceView with a different View index 201 | Image* promoImage; // 18 28 - Image shown in the Devices summary 202 | }; 203 | 204 | // 10 205 | struct DeviceView 206 | { 207 | Image* view; // 00 00 - Image shown in the editing view of the device 208 | Image* mask; // 04 08 - Masks the view image, white is opaque, black is transparent 209 | LedViews* ledView; // 08 10 210 | LedViews* actionZones; // 0C 18 - I don't know what this is yet 211 | }; 212 | } 213 | } 214 | } 215 | 216 | typedef cue::dev::plugin::DeviceInfo* (*_CorsairPluginGetDeviceInfo)(const char* deviceId); 217 | typedef bool (*_CorsairSetLedsColors)(const char* deviceId, std::int32_t size, cue::dev::plugin::LedColor* ledsColors); 218 | typedef std::int32_t(*_DeviceConnectionStatusChangeCallback)(void* context, const char* deviceName, std::int32_t unk3); 219 | typedef void (*_CorsairSubscribeForDeviceConnectionStatusChanges)(void* context, _DeviceConnectionStatusChangeCallback callback); 220 | typedef void (*_CorsairPluginUnsubscribeFromDeviceStatusChanges)(); 221 | typedef cue::dev::plugin::DeviceView* (*_CorsairPluginGetDeviceView)(const char* deviceId, std::int32_t index); 222 | typedef void (*_CorsairPluginFreeDeviceInfo)(cue::dev::plugin::DeviceInfo* memory); 223 | typedef void (*_CorsairPluginFreeDeviceView)(cue::dev::plugin::DeviceView* memory); 224 | typedef bool (*_CorsairConfigureKeyEvent)(void* unk1, std::int32_t unk2); 225 | typedef void (*CorsairEventHandler)(void* context, const cue::dev::plugin::Event* event); 226 | typedef bool (*_CorsairSubscribeForEvents)(CorsairEventHandler onEvent, void* context); 227 | typedef bool (*_CorsairUnsubscribeFromEvents)(); 228 | typedef void (*_CorsairSetMode)(std::int32_t mode); 229 | 230 | // 2C 231 | struct CorsairGetInstance_v66 232 | { 233 | _CorsairPluginGetDeviceInfo getDeviceInfo; // 00 00 234 | _CorsairSetLedsColors setLedsColors; // 04 08 235 | _CorsairSubscribeForDeviceConnectionStatusChanges subscribeForDeviceConnectionStatusChanges; // 08 10 236 | _CorsairPluginUnsubscribeFromDeviceStatusChanges unsubscribeFromDeviceConnectionStatusChanges; // 0C 18 237 | _CorsairPluginGetDeviceView getDeviceView; // 10 20 238 | _CorsairPluginFreeDeviceInfo freeDeviceInfo; // 14 28 239 | _CorsairPluginFreeDeviceView freeDeviceView; // 18 30 240 | _CorsairConfigureKeyEvent configureKeyEvent; // 1C 38 241 | _CorsairSubscribeForEvents subscribeForEvents; // 20 40 242 | _CorsairUnsubscribeFromEvents unsubscribeFromEvents; // 24 48 243 | _CorsairSetMode setMode; // 28 50 244 | }; 245 | 246 | typedef bool (*_CorsairGetPluginPropertyInfo)(cue::dev::plugin::PluginPropertyId propertyId, std::int32_t index, cue::dev::plugin::PropertyDataType& dataType, cue::dev::plugin::PropertyFlags& flags); 247 | typedef cue::dev::plugin::PropertyData* (*_CorsairReadPluginPropertyData)(cue::dev::plugin::PluginPropertyId propertyId, std::int32_t index); 248 | typedef bool (*_CorsairWritePluginPropertyData)(cue::dev::plugin::PluginPropertyId propertyId, std::int32_t index, cue::dev::plugin::PropertyData&); 249 | 250 | typedef bool (*_CorsairGetDevicePropertyInfo)(const char* deviceId, cue::dev::plugin::DevicePropertyId propertyId, std::int32_t index, cue::dev::plugin::PropertyDataType& dataType, cue::dev::plugin::PropertyFlags& flags); 251 | typedef cue::dev::plugin::PropertyData* (*_CorsairReadDevicePropertyData)(const char* deviceId, cue::dev::plugin::DevicePropertyId propertyId, std::int32_t index); 252 | typedef bool (*_CorsairWriteDevicePropertyData)(const char* deviceId, cue::dev::plugin::DevicePropertyId propertyId, std::int32_t index, cue::dev::plugin::PropertyData&); 253 | 254 | typedef void (*_CorsairFreePropertyData)(cue::dev::plugin::PropertyDataType dataType, cue::dev::plugin::PropertyData* data); 255 | 256 | struct LedColorChannel 257 | { 258 | void* unk00; 259 | cue::dev::plugin::LedColor* ledColors; 260 | }; 261 | typedef void (*_CorsairSetLedColorAtChannel)(const char* deviceId, std::int32_t unk1, std::int32_t size, LedColorChannel& channel); 262 | 263 | // 4C 264 | struct CorsairGetInstance_v67 265 | { 266 | _CorsairPluginGetDeviceInfo getDeviceInfo; // 00 00 267 | _CorsairSetLedsColors setLedsColors; // 04 08 268 | _CorsairSubscribeForDeviceConnectionStatusChanges subscribeForDeviceConnectionStatusChanges; // 08 10 269 | _CorsairPluginUnsubscribeFromDeviceStatusChanges unsubscribeFromDeviceConnectionStatusChanges; // 0C 18 270 | _CorsairPluginGetDeviceView getDeviceView; // 10 20 271 | _CorsairPluginFreeDeviceInfo freeDeviceInfo; // 14 28 272 | _CorsairPluginFreeDeviceView freeDeviceView; // 18 30 273 | _CorsairConfigureKeyEvent configureKeyEvent; // 1C 38 274 | _CorsairSubscribeForEvents subscribeForEvents; // 20 40 275 | _CorsairUnsubscribeFromEvents unsubscribeFromEvents; // 24 48 276 | _CorsairSetMode setMode; // 28 50 277 | _CorsairGetPluginPropertyInfo getPropertyInfo; // 2C 58 278 | _CorsairReadPluginPropertyData readPropertyData; // 30 60 279 | _CorsairWritePluginPropertyData writePropertyData; // 34 68 280 | _CorsairGetDevicePropertyInfo getDevicePropertyInfo; // 38 70 281 | _CorsairReadDevicePropertyData readDevicePropertyData; // 3C 78 282 | _CorsairWriteDevicePropertyData writeDevicePropertyData; // 40 80 283 | _CorsairFreePropertyData freePropertyData; // 44 88 284 | _CorsairSetLedColorAtChannel setLedsColorsAtChannel; // 48 90 285 | }; 286 | -------------------------------------------------------------------------------- /CorsairPluginDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class RGBController; 12 | 13 | namespace cue 14 | { 15 | namespace dev 16 | { 17 | namespace plugin 18 | { 19 | struct DeviceInfo; 20 | struct DeviceView; 21 | } 22 | } 23 | } 24 | 25 | 26 | struct LEDData 27 | { 28 | double x; 29 | double y; 30 | }; 31 | 32 | struct ZoneData 33 | { 34 | std::map ledData; 35 | }; 36 | 37 | struct DeviceInfo 38 | { 39 | std::string deviceName; 40 | std::string deviceId; 41 | std::string thumbnail; 42 | std::string promo; 43 | std::unordered_map> ledMapping; 44 | std::map zones; 45 | }; 46 | 47 | struct DeviceView 48 | { 49 | std::string image; 50 | std::string mask; 51 | std::map drawPath; 52 | }; 53 | typedef std::map DeviceViews; 54 | 55 | class CorsairPluginDevice 56 | { 57 | public: 58 | CorsairPluginDevice(RGBController* controller) : mController(controller) { } 59 | 60 | cue::dev::plugin::DeviceInfo* CreateDeviceInfo(); 61 | cue::dev::plugin::DeviceView* CreateDeviceView(std::int32_t index); 62 | static void DestroyDeviceInfo(cue::dev::plugin::DeviceInfo* deviceInfo); 63 | static void DestroyDeviceView(cue::dev::plugin::DeviceView* deviceInfo); 64 | 65 | const DeviceInfo& GetInfo() const { return mDeviceInfo; } 66 | const DeviceViews& GetViews() const { return mDeviceViews; } 67 | RGBController* GetController() const { return mController; } 68 | 69 | bool ReadFromJson(const nlohmann::json& settings, const nlohmann::json& devices, bool clear = false); 70 | void SetImageHasher(std::function functor) { mImageHasher = functor; }; 71 | void SetDeviceHasher(std::function functor) { mDeviceHasher = functor; } 72 | 73 | typedef std::unordered_map ResizeMap; 74 | ResizeMap& GetResizeMap() { return mZoneResize; } 75 | 76 | protected: 77 | 78 | void GetDeviceInfoFromJson(const nlohmann::json& settings, const nlohmann::json& devices); 79 | bool GetDeviceViewFromJson(const nlohmann::json& settings, const nlohmann::json& devices); 80 | 81 | bool ReadZonesFromJson(const nlohmann::json& zone); 82 | void ReadViewFromJson(const nlohmann::json& view, DeviceView& deviceView); 83 | 84 | private: 85 | ResizeMap mZoneResize; 86 | RGBController* mController; 87 | std::function mImageHasher; 88 | std::function mDeviceHasher; 89 | DeviceInfo mDeviceInfo; 90 | DeviceViews mDeviceViews; 91 | }; -------------------------------------------------------------------------------- /CorsairPluginDeviceManager.cpp: -------------------------------------------------------------------------------- 1 | #include "CorsairPluginDeviceManager.h" 2 | #include "NetworkClient.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | void ClientChanged(void* arg) 9 | { 10 | CorsairPluginDeviceManager* pluginManager = static_cast(arg); 11 | pluginManager->DisconnectDevices(); 12 | pluginManager->ConnectDevices(); 13 | } 14 | 15 | CorsairPluginDeviceManager::CorsairPluginDeviceManager(void* pluginContext, _DeviceConnectionStatusChangeCallback callback, 16 | std::function imageHasher, 17 | std::function deviceHasher, 18 | std::function localPath) 19 | : mPluginContext(pluginContext) 20 | , mDeviceCallback(callback) 21 | , mNetworkClient(std::make_unique(mControllerList)) 22 | , mImageHasher(imageHasher) 23 | , mDeviceHasher(deviceHasher) 24 | , mLocalFile(localPath) 25 | , mServicing(true) 26 | { 27 | mNetworkClient->RegisterClientInfoChangeCallback(ClientChanged, this); 28 | } 29 | 30 | CorsairPluginDeviceManager::~CorsairPluginDeviceManager() 31 | { 32 | Stop(); 33 | 34 | if (mDeviceUpdateRequest.valid()) 35 | { 36 | mDeviceUpdateRequest.wait(); 37 | } 38 | } 39 | 40 | void CorsairPluginDeviceManager::Start() 41 | { 42 | if (ReadJson()) 43 | { 44 | if (mSettings.contains("OpenRGB")) 45 | { 46 | const auto& openRGB = mSettings["OpenRGB"]; 47 | if (openRGB.contains("Host")) 48 | { 49 | mNetworkClient->SetIP(openRGB["Host"].get().c_str()); 50 | } 51 | if (openRGB.contains("Port")) 52 | { 53 | mNetworkClient->SetPort(openRGB["Port"]); 54 | } 55 | if (openRGB.contains("Client")) 56 | { 57 | mNetworkClient->SetName(openRGB["Client"].get().c_str()); 58 | } 59 | } 60 | 61 | mNetworkClient->StartClient(); 62 | 63 | mServicing = true; 64 | mQueueServiceThread = std::make_unique(&CorsairPluginDeviceManager::ServiceThreadFunction, this); 65 | } 66 | } 67 | 68 | void CorsairPluginDeviceManager::Stop() 69 | { 70 | mNetworkClient->StopClient(); 71 | mServicing = false; 72 | if (mQueueServiceThread) 73 | { 74 | mQueueServiceThread->join(); 75 | } 76 | } 77 | 78 | void CorsairPluginDeviceManager::ServiceThreadFunction() 79 | { 80 | while (mServicing) 81 | { 82 | mQueueLock.lock(); 83 | std::unique_ptr colorQueue = nullptr; 84 | if (!mColorQueue.empty()) { 85 | colorQueue = std::move(mColorQueue.front()); 86 | mColorQueue.pop(); 87 | } 88 | mQueueLock.unlock(); 89 | 90 | if (colorQueue) { 91 | _SetColor(colorQueue->mDeviceId.c_str(), colorQueue->mLEDs.size(), &colorQueue->mLEDs.at(0)); 92 | } 93 | 94 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); 95 | } 96 | } 97 | 98 | bool CorsairPluginDeviceManager::SetColor(const char* deviceId, std::int32_t size, cue::dev::plugin::LedColor* ledsColors) 99 | { 100 | mQueueLock.lock(); 101 | mColorQueue.push(std::make_unique(deviceId, std::vector(ledsColors, ledsColors + size))); 102 | mQueueLock.unlock(); 103 | return true; 104 | } 105 | 106 | bool CorsairPluginDeviceManager::_SetColor(const char* deviceId, std::int32_t size, cue::dev::plugin::LedColor* ledsColors) 107 | { 108 | std::lock_guard controllerLock(mNetworkClient->ControllerListMutex); 109 | std::lock_guard deviceLock(mDeviceLock); 110 | 111 | auto it = mDeviceMap.find(deviceId); 112 | if (it != mDeviceMap.end()) 113 | { 114 | auto controller = it->second->GetController(); 115 | for (std::int32_t i = 0; i < size; ++i) 116 | { 117 | auto& ledColor = ledsColors[i]; 118 | auto ledIt = it->second->GetInfo().ledMapping.find(ledColor.ledId); 119 | if (ledIt != it->second->GetInfo().ledMapping.end()) 120 | { 121 | std::uint32_t zoneId = ledIt->second.first; 122 | std::uint32_t zoneIndex = ledIt->second.second; 123 | controller->SetLED(controller->zones.at(zoneId).start_idx + zoneIndex, ToRGBColor(ledColor.r, ledColor.g, ledColor.b)); 124 | } 125 | } 126 | 127 | controller->UpdateLEDs(); 128 | return true; 129 | } 130 | 131 | return false; 132 | } 133 | 134 | cue::dev::plugin::DeviceInfo* CorsairPluginDeviceManager::GetDeviceInfo(const char* deviceId) 135 | { 136 | std::lock_guard networkLock(mNetworkClient->ControllerListMutex); 137 | std::lock_guard deviceLock(mDeviceLock); 138 | 139 | auto it = mDeviceMap.find(deviceId); 140 | if (it != mDeviceMap.end()) 141 | { 142 | return it->second->CreateDeviceInfo(); 143 | } 144 | 145 | return nullptr; 146 | } 147 | 148 | cue::dev::plugin::DeviceView* CorsairPluginDeviceManager::GetDeviceView(const char* deviceId, std::int32_t index) 149 | { 150 | std::lock_guard networkLock(mNetworkClient->ControllerListMutex); 151 | std::lock_guard deviceLock(mDeviceLock); 152 | 153 | auto it = mDeviceMap.find(deviceId); 154 | if (it != mDeviceMap.end()) 155 | { 156 | return it->second->CreateDeviceView(index); 157 | } 158 | 159 | return nullptr; 160 | } 161 | 162 | void CorsairPluginDeviceManager::UpdateDevices(std::unordered_set deviceSet, bool notifyHost) 163 | { 164 | std::lock_guard deviceLock(mDeviceLock); 165 | for (auto& deviceId : deviceSet) 166 | { 167 | auto it = mDeviceMap.find(deviceId); 168 | if (it != mDeviceMap.end()) 169 | { 170 | it->second->GetController()->SetCustomMode(); // Calls SendRequest_ControllerData and waits for response 171 | if (it->second->ReadFromJson(mSettings, mDevices, true) && notifyHost) 172 | { 173 | mDeviceCallback(mPluginContext, deviceId.c_str(), 1); 174 | } 175 | } 176 | } 177 | } 178 | 179 | bool CorsairPluginDeviceManager::ReadJson() 180 | { 181 | std::ifstream devices(mLocalFile(L"devices.json").c_str()); 182 | nlohmann::json jd; 183 | try 184 | { 185 | devices >> jd; 186 | } 187 | catch (...) 188 | { 189 | devices.close(); 190 | return false; 191 | } 192 | 193 | devices.close(); 194 | 195 | std::ifstream settings(mLocalFile(L"settings.json").c_str()); 196 | nlohmann::json js; 197 | try 198 | { 199 | settings >> js; 200 | } 201 | catch (...) 202 | { 203 | settings.close(); 204 | return false; 205 | } 206 | settings.close(); 207 | 208 | mSettings = js; 209 | mDevices = jd; 210 | return true; 211 | } 212 | 213 | void CorsairPluginDeviceManager::ConnectDevices() 214 | { 215 | std::lock_guard deviceLock(mDeviceLock); 216 | 217 | std::unordered_set deviceUpdate; 218 | for (auto controller : mControllerList) 219 | { 220 | std::unique_ptr device = std::make_unique(controller); 221 | device->SetImageHasher(mImageHasher); 222 | device->SetDeviceHasher(mDeviceHasher); 223 | if (device->ReadFromJson(mSettings, mDevices)) 224 | { 225 | // Device needs a resize, send the resize packet and re-request the controller data 226 | // We will delay sending the notification to the host until the new data has come back 227 | if (device->GetResizeMap().size()) 228 | { 229 | for (auto& zone : device->GetResizeMap()) 230 | { 231 | controller->ResizeZone(zone.first, zone.second); 232 | deviceUpdate.emplace(device->GetInfo().deviceId); 233 | } 234 | } 235 | else 236 | { 237 | mDeviceCallback(mPluginContext, device->GetInfo().deviceId.c_str(), 1); 238 | } 239 | 240 | mDeviceMap.emplace(device->GetInfo().deviceId, std::move(device)); 241 | } 242 | } 243 | 244 | // If there's a device that's the wrong size, send a device update and wait for the response 245 | // We need this in another thread because we call ConnectDevices from within the Changed devices callback, which has a lock on ControllerListMutex 246 | if (deviceUpdate.size()) 247 | { 248 | if (mDeviceUpdateRequest.valid()) 249 | { 250 | mDeviceUpdateRequest.wait(); 251 | } 252 | 253 | mDeviceUpdateRequest = std::async(std::launch::async, &CorsairPluginDeviceManager::UpdateDevices, this, deviceUpdate, true); 254 | } 255 | } 256 | 257 | void CorsairPluginDeviceManager::DisconnectDevices() 258 | { 259 | std::lock_guard deviceLock(mDeviceLock); 260 | 261 | for (auto& device : mDeviceMap) 262 | { 263 | mDeviceCallback(mPluginContext, device.first.c_str(), 0); 264 | } 265 | mDeviceMap.clear(); 266 | } 267 | -------------------------------------------------------------------------------- /CorsairPluginDeviceManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "CUESDKDevice.h" 14 | #include "CorsairPluginDevice.h" 15 | #include "json/json.hpp" 16 | 17 | class NetworkClient; 18 | class RGBController; 19 | 20 | class CorsairPluginDeviceManager 21 | { 22 | public: 23 | CorsairPluginDeviceManager(void* pluginContext, _DeviceConnectionStatusChangeCallback callback, 24 | std::function imageHasher, 25 | std::function deviceHasher, 26 | std::function localPath); 27 | virtual ~CorsairPluginDeviceManager(); 28 | 29 | virtual void Start(); 30 | virtual void Stop(); 31 | virtual bool ReadJson(); 32 | virtual void ConnectDevices(); 33 | virtual void DisconnectDevices(); 34 | 35 | struct SetColorData 36 | { 37 | SetColorData(const char* deviceId, const std::vector& leds) : mDeviceId(deviceId), mLEDs(leds) { } 38 | 39 | std::string mDeviceId; 40 | std::vector mLEDs; 41 | }; 42 | 43 | // CUE Calls 44 | virtual bool SetColor(const char* deviceId, std::int32_t size, cue::dev::plugin::LedColor* ledsColors); 45 | virtual cue::dev::plugin::DeviceInfo* GetDeviceInfo(const char* deviceId); 46 | virtual cue::dev::plugin::DeviceView* GetDeviceView(const char* deviceId, std::int32_t index); 47 | 48 | protected: 49 | bool _SetColor(const char* deviceId, std::int32_t size, cue::dev::plugin::LedColor* ledsColors); 50 | 51 | void ServiceThreadFunction(); 52 | 53 | void* mPluginContext; 54 | _DeviceConnectionStatusChangeCallback mDeviceCallback; 55 | nlohmann::json mSettings; 56 | nlohmann::json mDevices; 57 | 58 | private: 59 | void UpdateDevices(std::unordered_set deviceSet, bool notifyHost); 60 | 61 | std::mutex mQueueLock; 62 | std::queue> mColorQueue; 63 | std::unique_ptr mQueueServiceThread; 64 | std::atomic_bool mServicing; 65 | 66 | std::mutex mDeviceLock; 67 | std::unordered_map> mDeviceMap; 68 | std::future mDeviceUpdateRequest; 69 | std::unique_ptr mNetworkClient; 70 | std::vector mControllerList; 71 | 72 | std::function mImageHasher; 73 | std::function mDeviceHasher; 74 | std::function mLocalFile; 75 | }; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Brendan Borthwick 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /OpenRGBClient/OpenRGBClient.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "NetworkClient.h" 9 | #include "RGBController.h" 10 | #include "CorsairPluginDeviceManager.h" 11 | #include "CorsairPluginDevice.h" 12 | 13 | EXTERN_C IMAGE_DOS_HEADER __ImageBase; 14 | 15 | #include 16 | #pragma comment(lib, "shlwapi.lib") 17 | #pragma comment(lib, "ws2_32.lib") 18 | 19 | using namespace std::chrono_literals; 20 | using json = nlohmann::json; 21 | 22 | std::unique_ptr g_deviceManager = nullptr; 23 | 24 | std::int32_t DeviceConnectionStatusChangeCallback(void* context, const char* deviceName, std::int32_t unk3) 25 | { 26 | std::cout << "Device: " << deviceName << " Status: " << unk3 << std::endl; 27 | return 0; 28 | } 29 | 30 | std::wstring GetLocalFile(const std::wstring& relativePath) 31 | { 32 | wchar_t path[MAX_PATH] = { 0 }; 33 | GetModuleFileNameW((HINSTANCE)&__ImageBase, path, MAX_PATH); 34 | PathRemoveFileSpecW(path); 35 | PathCombineW(path, path, L"..\\..\\dist\\plugins\\OpenRGB"); 36 | PathCombineW(path, path, relativePath.c_str()); 37 | return path; 38 | } 39 | 40 | std::string GetImageHash(const std::string& relativePath) 41 | { 42 | size_t reqLength = ::MultiByteToWideChar(CP_UTF8, 0, relativePath.c_str(), (std::int32_t)relativePath.length(), 0, 0); 43 | std::wstring ret(reqLength, L'\0'); 44 | ::MultiByteToWideChar(CP_UTF8, 0, relativePath.c_str(), (std::int32_t)relativePath.length(), &ret[0], (std::int32_t)ret.length()); 45 | std::ifstream f(GetLocalFile(ret.c_str()).c_str(), std::ios::binary); 46 | std::vector s(picosha2::k_digest_size); 47 | picosha2::hash256(f, s.begin(), s.end()); 48 | return picosha2::bytes_to_hex_string(s); 49 | } 50 | 51 | int main() 52 | { 53 | g_deviceManager = std::make_unique(nullptr, DeviceConnectionStatusChangeCallback, GetImageHash, nullptr, GetLocalFile); 54 | g_deviceManager->Start(); 55 | 56 | std::string deviceCommand; 57 | 58 | while (true) 59 | { 60 | std::cout << "Enter JSON Command:" << std::endl; 61 | std::getline(std::cin, deviceCommand); 62 | 63 | nlohmann::json jd; 64 | try 65 | { 66 | jd = nlohmann::json::parse(deviceCommand); 67 | 68 | if (jd.contains("device") && jd["device"].is_string() && jd.contains("leds") && jd["leds"].is_array()) 69 | { 70 | auto& ledArray = jd["leds"]; 71 | auto leds = std::make_unique(ledArray.size()); 72 | for (std::int32_t i = 0; i < ledArray.size(); ++i) 73 | { 74 | const auto& ledObject = ledArray[i]; 75 | if (ledObject.is_object()) 76 | { 77 | leds[i].ledId = ledObject["id"]; 78 | leds[i].r = ledObject["r"]; 79 | leds[i].g = ledObject["g"]; 80 | leds[i].b = ledObject["b"]; 81 | } 82 | } 83 | 84 | g_deviceManager->SetColor(jd["device"].get().c_str(), ledArray.size(), leds.get()); 85 | } 86 | } 87 | catch (const std::string& ex) 88 | { 89 | std::cout << "Exception: " << ex << std::endl; 90 | } 91 | } 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /OpenRGBClient/OpenRGBClient.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 | {299adf00-111d-4eeb-b721-a5ee41ff3b72} 25 | OpenRGBClient 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 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 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | $(SolutionDir)thirdparty;$(SolutionDir);$(SolutionDir)thirdparty\OpenRGB;$(SolutionDir)thirdparty\OpenRGB\RGBController;$(SolutionDir)thirdparty\OpenRGB\net_port;$(SolutionDir)thirdparty\CUESDK;%(AdditionalIncludeDirectories) 92 | 93 | 94 | Console 95 | true 96 | 97 | 98 | 99 | 100 | Level3 101 | true 102 | true 103 | true 104 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 105 | true 106 | $(SolutionDir)thirdparty;$(SolutionDir);$(SolutionDir)thirdparty\OpenRGB;$(SolutionDir)thirdparty\OpenRGB\RGBController;$(SolutionDir)thirdparty\OpenRGB\net_port;$(SolutionDir)thirdparty\CUESDK;%(AdditionalIncludeDirectories) 107 | 108 | 109 | Console 110 | true 111 | true 112 | true 113 | 114 | 115 | 116 | 117 | Level3 118 | true 119 | WIN32;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 120 | true 121 | $(SolutionDir)thirdparty;$(SolutionDir);$(SolutionDir)thirdparty\OpenRGB;$(SolutionDir)thirdparty\OpenRGB\RGBController;$(SolutionDir)thirdparty\OpenRGB\net_port;$(SolutionDir)thirdparty\CUESDK;%(AdditionalIncludeDirectories) 122 | 123 | 124 | Console 125 | true 126 | 127 | 128 | 129 | 130 | Level3 131 | true 132 | true 133 | true 134 | WIN32;_WINSOCK_DEPRECATED_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 135 | true 136 | $(SolutionDir)thirdparty;$(SolutionDir);$(SolutionDir)thirdparty\OpenRGB;$(SolutionDir)thirdparty\OpenRGB\RGBController;$(SolutionDir)thirdparty\OpenRGB\net_port;$(SolutionDir)thirdparty\CUESDK;%(AdditionalIncludeDirectories) 137 | 138 | 139 | Console 140 | true 141 | true 142 | true 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /OpenRGBClient/OpenRGBClient.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 | {2c80681e-030a-454e-9459-aee40740ba14} 18 | 19 | 20 | {68467804-d7b1-461b-9e00-d4e6c92bcc7f} 21 | 22 | 23 | {011134a8-4bb2-498a-8400-db42def62e4e} 24 | 25 | 26 | {117cc2e5-2f3e-49dc-ad0d-5a4383e477c6} 27 | 28 | 29 | {2971b9be-cfc5-404d-8f6e-38990ccea51b} 30 | 31 | 32 | {08e5d5ab-277a-457d-9e9f-94201de86648} 33 | 34 | 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files\OpenRGB 47 | 48 | 49 | Source Files\OpenRGB 50 | 51 | 52 | Source Files\OpenRGB\net_port 53 | 54 | 55 | Source Files\OpenRGB\RGBController 56 | 57 | 58 | Source Files\OpenRGB\RGBController 59 | 60 | 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files\OpenRGB\RGBController 70 | 71 | 72 | Header Files\OpenRGB\RGBController 73 | 74 | 75 | Header Files\OpenRGB 76 | 77 | 78 | Header Files\OpenRGB 79 | 80 | 81 | Header Files\OpenRGB\net_port 82 | 83 | 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CUEORGBPlugin 2 | Custom iCUE plugin to control OpenRGB from within iCUE 3 | 4 | # Compiling 5 | Should be no major dependencies, built with Visual Studio Community 2019. 6 | 7 | # Description 8 | This plugin allows creating custom device layouts using json files and custom images as well as generating some generic LED layouts if there is no defined device. Corsair has not released an official SDK for adding custom devices. The reverse engineering is contained in `CUESDKDevice.h`. 9 | 10 | ![Custom Device](/screenshots/custom_device_v4.PNG) 11 | 12 | **Files of Importance** 13 | * `dsound.dll` - This is a wrapper dll to disable iCUE's signature check on plugins loaded from the Plugins folder. Normally iCUE will run WinVerifyTrust on all plugins it is attempting to load. I haven't determined whether it needs to be signed by Corsair specifically, this wrapper when placed in the Corsair iCUE program directory will disable this check entirely. 14 | * `CUEORGBPlugin.dll` - This implements the OpenRGB Client interface and utilizes/merges json files to create devices 15 | * `settings.json` - This file specifies the default LED/Zone layout display of some devices in the event no specific device is found within `devices.json` 16 | * `devices.json` - This file maps devices by name given within OpenRGB and allows overriding the Default layout 17 | 18 | # Release Installation 19 | * Close iCUE completely by right-clicking in the task bar and pressing `Quit` 20 | * Copy contents of archive to `C:\Program Files\Corsair\CORSAIR iCUE 4 Software` directly. 21 | 22 | # Manual Installation 23 | * Close iCUE completely by right-clicking in the task bar and pressing `Quit` 24 | * Copy `dist/plugins` folder to `C:\Program Files\Corsair\CORSAIR iCUE 4 Software` 25 | * Copy built `dsound.dll` to `C:\Program Files\Corsair\CORSAIR iCUE 4 Software` 26 | * Copy built `CUEORGBPlugin.dll` to `C:\Program Files\Corsair\CORSAIR iCUE 4 Software\plugins\OpenRGB` 27 | 28 | # OpenRGB Installation 29 | * Download [OpenRGB x64](https://gitlab.com/CalcProgrammer1/OpenRGB/-/jobs/artifacts/master/download?job=build_windows_64) or [OpenRGB x86](https://gitlab.com/CalcProgrammer1/OpenRGB/-/jobs/artifacts/master/download?job=build_windows_32) 30 | * Place the folder anywhere 31 | * Create `disabled_devices.txt` in the same directory as `OpenRGB.exe` add the following contents: 32 | ``` 33 | Corsair Dominator Platinum 34 | Corsair Hydro Series 35 | Corsair Lighting Node 36 | Corsair Peripheral 37 | Corsair Vengeance 38 | Corsair Vengeance Pro 39 | ``` 40 | This will disable OpenRGB from scanning Corsair devices and potentially breaking some (e.g. Commander Pro fan speeds may no longer show up after device scan) 41 | * Run OpenRGB 42 | * Navigate to `SDK Server` tab 43 | * Press `Start Server` 44 | * Run iCUE 45 | 46 | OpenRGB should look like the following when iCUE connects: 47 | ![OpenRGB](/screenshots/open_rgb_server.PNG) 48 | 49 | # OpenRGB as a Startup process (Windows) 50 | You might want to start OpenRGB when you start windows as iCUE is also a Startup process, allowing OpenRGB to be started alongside will allow you to resume effects controlled by iCUE when both programs start 51 | * Win+R 52 | * `shell:startup` 53 | * Create shortcut to OpenRGB.exe 54 | * Add `--startminimized --server` to the end of the `Target` field 55 | 56 | # Thirdparty Projects used 57 | 58 | * CUESDK - https://github.com/CorsairOfficial/cue-sdk 59 | * OpenRGB - https://gitlab.com/CalcProgrammer1/OpenRGB 60 | * Json C++ - https://github.com/nlohmann/json 61 | * SHA256 - https://github.com/okdshin/PicoSHA2 62 | -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/devices.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "Name": "ASUS ROG ZENITH II EXTREME ALPHA", 4 | "Thumbnail": "images/motherboard/default/thumbnail.png", 5 | "Image": "images/motherboard/default/promo.png", 6 | "InheritDefault": false, 7 | "Zones": [ 8 | {"Zone": "Aura Mainboard"}, 9 | {"Zone": "Aura Addressable 1", "Size": 27, "Pattern": "LinearY", "Multiplier": 540}, 10 | {"Zone": "Aura Addressable 2", "Size": 28, "Pattern": "LinearY", "Multiplier": 560}, 11 | {"Zone": "Aura Addressable 3", "LEDs": [ 12 | {"Id": 200, "Index": 0, "Position": [0, 0]}, 13 | {"Id": 201, "Index": 1, "Position": [0, 20]}, 14 | {"Id": 202, "Index": 2, "Position": [0, 40]}, 15 | {"Id": 203, "Index": 3, "Position": [0, 60]}, 16 | {"Id": 204, "Index": 4, "Position": [0, 80]}, 17 | {"Id": 205, "Index": 5, "Position": [0, 100]}, 18 | {"Id": 206, "Index": 6, "Position": [0, 120]}, 19 | {"Id": 207, "Index": 7, "Position": [0, 140]}, 20 | {"Id": 208, "Index": 8, "Position": [0, 160]}, 21 | {"Id": 209, "Index": 9, "Position": [0, 180]} 22 | ]} 23 | ], 24 | "Views": [ 25 | { 26 | "Image": "images/motherboard/default/device_view.png", 27 | "PolyGenerator": {"Zone": "Aura Mainboard", "Rect": [0, 300, 300, 340], "Spacing": 5} 28 | }, 29 | { 30 | "Image": "images/motherboard/default/device_view.png", 31 | "PolyGenerator": {"Zone": "Aura Addressable 1", "Rect": [0, 300, 300, 340], "Spacing": 2} 32 | }, 33 | { 34 | "Image": "images/motherboard/default/device_view.png", 35 | "PolyGenerator": {"Zone": "Aura Addressable 2", "Rect": [0, 300, 300, 340], "Spacing": 2} 36 | }, 37 | { 38 | "Image": "images/motherboard/default/device_view.png", 39 | "PolyGenerator": {"Zone": "Aura Addressable 3", "Rect": [0, 300, 300, 340], "Spacing": 5} 40 | } 41 | ] 42 | } 43 | ] -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/gpu/default/device_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/gpu/default/device_view.png -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/gpu/default/promo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/gpu/default/promo.png -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/gpu/default/thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/gpu/default/thumbnail.png -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/keyboard/default/device_view.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/keyboard/default/device_view.jpg -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/keyboard/default/device_view_mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/keyboard/default/device_view_mask.png -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/keyboard/default/promo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/keyboard/default/promo.jpg -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/keyboard/default/thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/keyboard/default/thumbnail.png -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/led_strip/default/device_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/led_strip/default/device_view.png -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/motherboard/default/device_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/motherboard/default/device_view.png -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/motherboard/default/promo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/motherboard/default/promo.png -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/images/motherboard/default/thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/dist/plugins/OpenRGB/images/motherboard/default/thumbnail.png -------------------------------------------------------------------------------- /dist/plugins/OpenRGB/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "OpenRGB": { 3 | "Host": "127.0.0.1", 4 | "Port": 6742, 5 | "Client": "iCue Plugin" 6 | }, 7 | "Defaults": { 8 | "Motherboard": { 9 | "Thumbnail": "images/motherboard/default/thumbnail.png", 10 | "Image": "images/motherboard/default/promo.png", 11 | "Zones": [ 12 | {"Zone": 0}, 13 | {"Zone": 1}, 14 | {"Zone": 2} 15 | ], 16 | "Views": [ 17 | {"Image": "images/motherboard/default/device_view.png", "PolyGenerator": {"Zone": 0, "Rect": [0, 300, 300, 340], "Spacing": 5}}, 18 | {"Image": "images/motherboard/default/device_view.png", "PolyGenerator": {"Zone": 1, "Rect": [0, 300, 300, 340], "Spacing": 5}}, 19 | {"Image": "images/motherboard/default/device_view.png", "PolyGenerator": {"Zone": 2, "Rect": [0, 300, 300, 340], "Spacing": 5}} 20 | ] 21 | }, 22 | "GPU": { 23 | "Thumbnail": "images/gpu/default/thumbnail.png", 24 | "Image": "images/gpu/default/promo.png", 25 | "Zones": [ 26 | {"Zone": 0} 27 | ], 28 | "Views": [ 29 | {"Image": "images/gpu/default/device_view.png", "PolyGenerator": {"Zone": 0, "Rect": [50, 0, 349, 24], "Spacing": 5}} 30 | ] 31 | }, 32 | "Keyboard": { 33 | "Thumbnail": "images/keyboard/default/thumbnail.png", 34 | "Image": "images/keyboard/default/promo.jpg", 35 | "Zones": [ 36 | { 37 | "Zone": 0, 38 | "LEDs": [ 39 | {"Id": 1, "Index": 0, "Position": [1.5625, 1.375]}, 40 | {"Id": 2, "Index": 1, "Position": [1.3125, 1.375]} 41 | ] 42 | } 43 | ], 44 | "Views": [ 45 | { 46 | "Image": "images/keyboard/default/device_view.jpg", 47 | "Mask": "images/keyboard/default/device_view_mask.png", 48 | "Polygons": [ 49 | {"Id": 1, "Path": "M 155 111 L 233 111 L 233 166 L 155 166 Z"}, 50 | {"Id": 2, "Path": "M 262 111 L 340 111 L 340 166 L 262 166 Z"} 51 | ] 52 | } 53 | ] 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /exports.def: -------------------------------------------------------------------------------- 1 | LIBRARY "CUEORGBPlugin" 2 | EXPORTS 3 | CorsairPluginFreeInstance 4 | CorsairPluginGetAPIVersion 5 | CorsairPluginGetFeatures 6 | CorsairPluginGetInstance -------------------------------------------------------------------------------- /screenshots/custom_device.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/screenshots/custom_device.png -------------------------------------------------------------------------------- /screenshots/custom_device_v4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/screenshots/custom_device_v4.PNG -------------------------------------------------------------------------------- /screenshots/open_rgb_server.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/expired6978/CUEORGBPlugin/34a3187ba0f67cbe5e068df798a1dd251dadc4db/screenshots/open_rgb_server.PNG -------------------------------------------------------------------------------- /thirdparty/MinHook/include/MinHook.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | #if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__) 32 | #error MinHook supports only x86 and x64 systems. 33 | #endif 34 | 35 | #include 36 | 37 | // MinHook Error Codes. 38 | typedef enum MH_STATUS 39 | { 40 | // Unknown error. Should not be returned. 41 | MH_UNKNOWN = -1, 42 | 43 | // Successful. 44 | MH_OK = 0, 45 | 46 | // MinHook is already initialized. 47 | MH_ERROR_ALREADY_INITIALIZED, 48 | 49 | // MinHook is not initialized yet, or already uninitialized. 50 | MH_ERROR_NOT_INITIALIZED, 51 | 52 | // The hook for the specified target function is already created. 53 | MH_ERROR_ALREADY_CREATED, 54 | 55 | // The hook for the specified target function is not created yet. 56 | MH_ERROR_NOT_CREATED, 57 | 58 | // The hook for the specified target function is already enabled. 59 | MH_ERROR_ENABLED, 60 | 61 | // The hook for the specified target function is not enabled yet, or already 62 | // disabled. 63 | MH_ERROR_DISABLED, 64 | 65 | // The specified pointer is invalid. It points the address of non-allocated 66 | // and/or non-executable region. 67 | MH_ERROR_NOT_EXECUTABLE, 68 | 69 | // The specified target function cannot be hooked. 70 | MH_ERROR_UNSUPPORTED_FUNCTION, 71 | 72 | // Failed to allocate memory. 73 | MH_ERROR_MEMORY_ALLOC, 74 | 75 | // Failed to change the memory protection. 76 | MH_ERROR_MEMORY_PROTECT, 77 | 78 | // The specified module is not loaded. 79 | MH_ERROR_MODULE_NOT_FOUND, 80 | 81 | // The specified function is not found. 82 | MH_ERROR_FUNCTION_NOT_FOUND 83 | } 84 | MH_STATUS; 85 | 86 | // Can be passed as a parameter to MH_EnableHook, MH_DisableHook, 87 | // MH_QueueEnableHook or MH_QueueDisableHook. 88 | #define MH_ALL_HOOKS NULL 89 | 90 | #ifdef __cplusplus 91 | extern "C" { 92 | #endif 93 | 94 | // Initialize the MinHook library. You must call this function EXACTLY ONCE 95 | // at the beginning of your program. 96 | MH_STATUS WINAPI MH_Initialize(VOID); 97 | 98 | // Uninitialize the MinHook library. You must call this function EXACTLY 99 | // ONCE at the end of your program. 100 | MH_STATUS WINAPI MH_Uninitialize(VOID); 101 | 102 | // Creates a Hook for the specified target function, in disabled state. 103 | // Parameters: 104 | // pTarget [in] A pointer to the target function, which will be 105 | // overridden by the detour function. 106 | // pDetour [in] A pointer to the detour function, which will override 107 | // the target function. 108 | // ppOriginal [out] A pointer to the trampoline function, which will be 109 | // used to call the original target function. 110 | // This parameter can be NULL. 111 | MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal); 112 | 113 | // Creates a Hook for the specified API function, in disabled state. 114 | // Parameters: 115 | // pszModule [in] A pointer to the loaded module name which contains the 116 | // target function. 117 | // pszTarget [in] A pointer to the target function name, which will be 118 | // overridden by the detour function. 119 | // pDetour [in] A pointer to the detour function, which will override 120 | // the target function. 121 | // ppOriginal [out] A pointer to the trampoline function, which will be 122 | // used to call the original target function. 123 | // This parameter can be NULL. 124 | MH_STATUS WINAPI MH_CreateHookApi( 125 | LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal); 126 | 127 | // Creates a Hook for the specified API function, in disabled state. 128 | // Parameters: 129 | // pszModule [in] A pointer to the loaded module name which contains the 130 | // target function. 131 | // pszTarget [in] A pointer to the target function name, which will be 132 | // overridden by the detour function. 133 | // pDetour [in] A pointer to the detour function, which will override 134 | // the target function. 135 | // ppOriginal [out] A pointer to the trampoline function, which will be 136 | // used to call the original target function. 137 | // This parameter can be NULL. 138 | // ppTarget [out] A pointer to the target function, which will be used 139 | // with other functions. 140 | // This parameter can be NULL. 141 | MH_STATUS WINAPI MH_CreateHookApiEx( 142 | LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal, LPVOID *ppTarget); 143 | 144 | // Removes an already created hook. 145 | // Parameters: 146 | // pTarget [in] A pointer to the target function. 147 | MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget); 148 | 149 | // Enables an already created hook. 150 | // Parameters: 151 | // pTarget [in] A pointer to the target function. 152 | // If this parameter is MH_ALL_HOOKS, all created hooks are 153 | // enabled in one go. 154 | MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget); 155 | 156 | // Disables an already created hook. 157 | // Parameters: 158 | // pTarget [in] A pointer to the target function. 159 | // If this parameter is MH_ALL_HOOKS, all created hooks are 160 | // disabled in one go. 161 | MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget); 162 | 163 | // Queues to enable an already created hook. 164 | // Parameters: 165 | // pTarget [in] A pointer to the target function. 166 | // If this parameter is MH_ALL_HOOKS, all created hooks are 167 | // queued to be enabled. 168 | MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget); 169 | 170 | // Queues to disable an already created hook. 171 | // Parameters: 172 | // pTarget [in] A pointer to the target function. 173 | // If this parameter is MH_ALL_HOOKS, all created hooks are 174 | // queued to be disabled. 175 | MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget); 176 | 177 | // Applies all queued changes in one go. 178 | MH_STATUS WINAPI MH_ApplyQueued(VOID); 179 | 180 | // Translates the MH_STATUS to its name as a string. 181 | const char * WINAPI MH_StatusToString(MH_STATUS status); 182 | 183 | #ifdef __cplusplus 184 | } 185 | #endif 186 | 187 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include "buffer.h" 31 | 32 | // Size of each memory block. (= page size of VirtualAlloc) 33 | #define MEMORY_BLOCK_SIZE 0x1000 34 | 35 | // Max range for seeking a memory block. (= 1024MB) 36 | #define MAX_MEMORY_RANGE 0x40000000 37 | 38 | // Memory protection flags to check the executable address. 39 | #define PAGE_EXECUTE_FLAGS \ 40 | (PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY) 41 | 42 | // Memory slot. 43 | typedef struct _MEMORY_SLOT 44 | { 45 | union 46 | { 47 | struct _MEMORY_SLOT *pNext; 48 | UINT8 buffer[MEMORY_SLOT_SIZE]; 49 | }; 50 | } MEMORY_SLOT, *PMEMORY_SLOT; 51 | 52 | // Memory block info. Placed at the head of each block. 53 | typedef struct _MEMORY_BLOCK 54 | { 55 | struct _MEMORY_BLOCK *pNext; 56 | PMEMORY_SLOT pFree; // First element of the free slot list. 57 | UINT usedCount; 58 | } MEMORY_BLOCK, *PMEMORY_BLOCK; 59 | 60 | //------------------------------------------------------------------------- 61 | // Global Variables: 62 | //------------------------------------------------------------------------- 63 | 64 | // First element of the memory block list. 65 | PMEMORY_BLOCK g_pMemoryBlocks; 66 | 67 | //------------------------------------------------------------------------- 68 | VOID InitializeBuffer(VOID) 69 | { 70 | // Nothing to do for now. 71 | } 72 | 73 | //------------------------------------------------------------------------- 74 | VOID UninitializeBuffer(VOID) 75 | { 76 | PMEMORY_BLOCK pBlock = g_pMemoryBlocks; 77 | g_pMemoryBlocks = NULL; 78 | 79 | while (pBlock) 80 | { 81 | PMEMORY_BLOCK pNext = pBlock->pNext; 82 | VirtualFree(pBlock, 0, MEM_RELEASE); 83 | pBlock = pNext; 84 | } 85 | } 86 | 87 | //------------------------------------------------------------------------- 88 | #if defined(_M_X64) || defined(__x86_64__) 89 | static LPVOID FindPrevFreeRegion(LPVOID pAddress, LPVOID pMinAddr, DWORD dwAllocationGranularity) 90 | { 91 | ULONG_PTR tryAddr = (ULONG_PTR)pAddress; 92 | 93 | // Round down to the allocation granularity. 94 | tryAddr -= tryAddr % dwAllocationGranularity; 95 | 96 | // Start from the previous allocation granularity multiply. 97 | tryAddr -= dwAllocationGranularity; 98 | 99 | while (tryAddr >= (ULONG_PTR)pMinAddr) 100 | { 101 | MEMORY_BASIC_INFORMATION mbi; 102 | if (VirtualQuery((LPVOID)tryAddr, &mbi, sizeof(mbi)) == 0) 103 | break; 104 | 105 | if (mbi.State == MEM_FREE) 106 | return (LPVOID)tryAddr; 107 | 108 | if ((ULONG_PTR)mbi.AllocationBase < dwAllocationGranularity) 109 | break; 110 | 111 | tryAddr = (ULONG_PTR)mbi.AllocationBase - dwAllocationGranularity; 112 | } 113 | 114 | return NULL; 115 | } 116 | #endif 117 | 118 | //------------------------------------------------------------------------- 119 | #if defined(_M_X64) || defined(__x86_64__) 120 | static LPVOID FindNextFreeRegion(LPVOID pAddress, LPVOID pMaxAddr, DWORD dwAllocationGranularity) 121 | { 122 | ULONG_PTR tryAddr = (ULONG_PTR)pAddress; 123 | 124 | // Round down to the allocation granularity. 125 | tryAddr -= tryAddr % dwAllocationGranularity; 126 | 127 | // Start from the next allocation granularity multiply. 128 | tryAddr += dwAllocationGranularity; 129 | 130 | while (tryAddr <= (ULONG_PTR)pMaxAddr) 131 | { 132 | MEMORY_BASIC_INFORMATION mbi; 133 | if (VirtualQuery((LPVOID)tryAddr, &mbi, sizeof(mbi)) == 0) 134 | break; 135 | 136 | if (mbi.State == MEM_FREE) 137 | return (LPVOID)tryAddr; 138 | 139 | tryAddr = (ULONG_PTR)mbi.BaseAddress + mbi.RegionSize; 140 | 141 | // Round up to the next allocation granularity. 142 | tryAddr += dwAllocationGranularity - 1; 143 | tryAddr -= tryAddr % dwAllocationGranularity; 144 | } 145 | 146 | return NULL; 147 | } 148 | #endif 149 | 150 | //------------------------------------------------------------------------- 151 | static PMEMORY_BLOCK GetMemoryBlock(LPVOID pOrigin) 152 | { 153 | PMEMORY_BLOCK pBlock; 154 | #if defined(_M_X64) || defined(__x86_64__) 155 | ULONG_PTR minAddr; 156 | ULONG_PTR maxAddr; 157 | 158 | SYSTEM_INFO si; 159 | GetSystemInfo(&si); 160 | minAddr = (ULONG_PTR)si.lpMinimumApplicationAddress; 161 | maxAddr = (ULONG_PTR)si.lpMaximumApplicationAddress; 162 | 163 | // pOrigin ± 512MB 164 | if ((ULONG_PTR)pOrigin > MAX_MEMORY_RANGE && minAddr < (ULONG_PTR)pOrigin - MAX_MEMORY_RANGE) 165 | minAddr = (ULONG_PTR)pOrigin - MAX_MEMORY_RANGE; 166 | 167 | if (maxAddr > (ULONG_PTR)pOrigin + MAX_MEMORY_RANGE) 168 | maxAddr = (ULONG_PTR)pOrigin + MAX_MEMORY_RANGE; 169 | 170 | // Make room for MEMORY_BLOCK_SIZE bytes. 171 | maxAddr -= MEMORY_BLOCK_SIZE - 1; 172 | #endif 173 | 174 | // Look the registered blocks for a reachable one. 175 | for (pBlock = g_pMemoryBlocks; pBlock != NULL; pBlock = pBlock->pNext) 176 | { 177 | #if defined(_M_X64) || defined(__x86_64__) 178 | // Ignore the blocks too far. 179 | if ((ULONG_PTR)pBlock < minAddr || (ULONG_PTR)pBlock >= maxAddr) 180 | continue; 181 | #endif 182 | // The block has at least one unused slot. 183 | if (pBlock->pFree != NULL) 184 | return pBlock; 185 | } 186 | 187 | #if defined(_M_X64) || defined(__x86_64__) 188 | // Alloc a new block above if not found. 189 | { 190 | LPVOID pAlloc = pOrigin; 191 | while ((ULONG_PTR)pAlloc >= minAddr) 192 | { 193 | pAlloc = FindPrevFreeRegion(pAlloc, (LPVOID)minAddr, si.dwAllocationGranularity); 194 | if (pAlloc == NULL) 195 | break; 196 | 197 | pBlock = (PMEMORY_BLOCK)VirtualAlloc( 198 | pAlloc, MEMORY_BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); 199 | if (pBlock != NULL) 200 | break; 201 | } 202 | } 203 | 204 | // Alloc a new block below if not found. 205 | if (pBlock == NULL) 206 | { 207 | LPVOID pAlloc = pOrigin; 208 | while ((ULONG_PTR)pAlloc <= maxAddr) 209 | { 210 | pAlloc = FindNextFreeRegion(pAlloc, (LPVOID)maxAddr, si.dwAllocationGranularity); 211 | if (pAlloc == NULL) 212 | break; 213 | 214 | pBlock = (PMEMORY_BLOCK)VirtualAlloc( 215 | pAlloc, MEMORY_BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); 216 | if (pBlock != NULL) 217 | break; 218 | } 219 | } 220 | #else 221 | // In x86 mode, a memory block can be placed anywhere. 222 | pBlock = (PMEMORY_BLOCK)VirtualAlloc( 223 | NULL, MEMORY_BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); 224 | #endif 225 | 226 | if (pBlock != NULL) 227 | { 228 | // Build a linked list of all the slots. 229 | PMEMORY_SLOT pSlot = (PMEMORY_SLOT)pBlock + 1; 230 | pBlock->pFree = NULL; 231 | pBlock->usedCount = 0; 232 | do 233 | { 234 | pSlot->pNext = pBlock->pFree; 235 | pBlock->pFree = pSlot; 236 | pSlot++; 237 | } while ((ULONG_PTR)pSlot - (ULONG_PTR)pBlock <= MEMORY_BLOCK_SIZE - MEMORY_SLOT_SIZE); 238 | 239 | pBlock->pNext = g_pMemoryBlocks; 240 | g_pMemoryBlocks = pBlock; 241 | } 242 | 243 | return pBlock; 244 | } 245 | 246 | //------------------------------------------------------------------------- 247 | LPVOID AllocateBuffer(LPVOID pOrigin) 248 | { 249 | PMEMORY_SLOT pSlot; 250 | PMEMORY_BLOCK pBlock = GetMemoryBlock(pOrigin); 251 | if (pBlock == NULL) 252 | return NULL; 253 | 254 | // Remove an unused slot from the list. 255 | pSlot = pBlock->pFree; 256 | pBlock->pFree = pSlot->pNext; 257 | pBlock->usedCount++; 258 | #ifdef _DEBUG 259 | // Fill the slot with INT3 for debugging. 260 | memset(pSlot, 0xCC, sizeof(MEMORY_SLOT)); 261 | #endif 262 | return pSlot; 263 | } 264 | 265 | //------------------------------------------------------------------------- 266 | VOID FreeBuffer(LPVOID pBuffer) 267 | { 268 | PMEMORY_BLOCK pBlock = g_pMemoryBlocks; 269 | PMEMORY_BLOCK pPrev = NULL; 270 | ULONG_PTR pTargetBlock = ((ULONG_PTR)pBuffer / MEMORY_BLOCK_SIZE) * MEMORY_BLOCK_SIZE; 271 | 272 | while (pBlock != NULL) 273 | { 274 | if ((ULONG_PTR)pBlock == pTargetBlock) 275 | { 276 | PMEMORY_SLOT pSlot = (PMEMORY_SLOT)pBuffer; 277 | #ifdef _DEBUG 278 | // Clear the released slot for debugging. 279 | memset(pSlot, 0x00, sizeof(*pSlot)); 280 | #endif 281 | // Restore the released slot to the list. 282 | pSlot->pNext = pBlock->pFree; 283 | pBlock->pFree = pSlot; 284 | pBlock->usedCount--; 285 | 286 | // Free if unused. 287 | if (pBlock->usedCount == 0) 288 | { 289 | if (pPrev) 290 | pPrev->pNext = pBlock->pNext; 291 | else 292 | g_pMemoryBlocks = pBlock->pNext; 293 | 294 | VirtualFree(pBlock, 0, MEM_RELEASE); 295 | } 296 | 297 | break; 298 | } 299 | 300 | pPrev = pBlock; 301 | pBlock = pBlock->pNext; 302 | } 303 | } 304 | 305 | //------------------------------------------------------------------------- 306 | BOOL IsExecutableAddress(LPVOID pAddress) 307 | { 308 | MEMORY_BASIC_INFORMATION mi; 309 | VirtualQuery(pAddress, &mi, sizeof(mi)); 310 | 311 | return (mi.State == MEM_COMMIT && (mi.Protect & PAGE_EXECUTE_FLAGS)); 312 | } 313 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | // Size of each memory slot. 32 | #if defined(_M_X64) || defined(__x86_64__) 33 | #define MEMORY_SLOT_SIZE 64 34 | #else 35 | #define MEMORY_SLOT_SIZE 32 36 | #endif 37 | 38 | VOID InitializeBuffer(VOID); 39 | VOID UninitializeBuffer(VOID); 40 | LPVOID AllocateBuffer(LPVOID pOrigin); 41 | VOID FreeBuffer(LPVOID pBuffer); 42 | BOOL IsExecutableAddress(LPVOID pAddress); 43 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/hde/hde32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #if defined(_M_IX86) || defined(__i386__) 9 | 10 | #include "hde32.h" 11 | #include "table32.h" 12 | 13 | unsigned int hde32_disasm(const void *code, hde32s *hs) 14 | { 15 | uint8_t x, c, *p = (uint8_t *)code, cflags, opcode, pref = 0; 16 | uint8_t *ht = hde32_table, m_mod, m_reg, m_rm, disp_size = 0; 17 | 18 | // Avoid using memset to reduce the footprint. 19 | #ifndef _MSC_VER 20 | memset((LPBYTE)hs, 0, sizeof(hde32s)); 21 | #else 22 | __stosb((LPBYTE)hs, 0, sizeof(hde32s)); 23 | #endif 24 | 25 | for (x = 16; x; x--) 26 | switch (c = *p++) { 27 | case 0xf3: 28 | hs->p_rep = c; 29 | pref |= PRE_F3; 30 | break; 31 | case 0xf2: 32 | hs->p_rep = c; 33 | pref |= PRE_F2; 34 | break; 35 | case 0xf0: 36 | hs->p_lock = c; 37 | pref |= PRE_LOCK; 38 | break; 39 | case 0x26: case 0x2e: case 0x36: 40 | case 0x3e: case 0x64: case 0x65: 41 | hs->p_seg = c; 42 | pref |= PRE_SEG; 43 | break; 44 | case 0x66: 45 | hs->p_66 = c; 46 | pref |= PRE_66; 47 | break; 48 | case 0x67: 49 | hs->p_67 = c; 50 | pref |= PRE_67; 51 | break; 52 | default: 53 | goto pref_done; 54 | } 55 | pref_done: 56 | 57 | hs->flags = (uint32_t)pref << 23; 58 | 59 | if (!pref) 60 | pref |= PRE_NONE; 61 | 62 | if ((hs->opcode = c) == 0x0f) { 63 | hs->opcode2 = c = *p++; 64 | ht += DELTA_OPCODES; 65 | } else if (c >= 0xa0 && c <= 0xa3) { 66 | if (pref & PRE_67) 67 | pref |= PRE_66; 68 | else 69 | pref &= ~PRE_66; 70 | } 71 | 72 | opcode = c; 73 | cflags = ht[ht[opcode / 4] + (opcode % 4)]; 74 | 75 | if (cflags == C_ERROR) { 76 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 77 | cflags = 0; 78 | if ((opcode & -3) == 0x24) 79 | cflags++; 80 | } 81 | 82 | x = 0; 83 | if (cflags & C_GROUP) { 84 | uint16_t t; 85 | t = *(uint16_t *)(ht + (cflags & 0x7f)); 86 | cflags = (uint8_t)t; 87 | x = (uint8_t)(t >> 8); 88 | } 89 | 90 | if (hs->opcode2) { 91 | ht = hde32_table + DELTA_PREFIXES; 92 | if (ht[ht[opcode / 4] + (opcode % 4)] & pref) 93 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 94 | } 95 | 96 | if (cflags & C_MODRM) { 97 | hs->flags |= F_MODRM; 98 | hs->modrm = c = *p++; 99 | hs->modrm_mod = m_mod = c >> 6; 100 | hs->modrm_rm = m_rm = c & 7; 101 | hs->modrm_reg = m_reg = (c & 0x3f) >> 3; 102 | 103 | if (x && ((x << m_reg) & 0x80)) 104 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 105 | 106 | if (!hs->opcode2 && opcode >= 0xd9 && opcode <= 0xdf) { 107 | uint8_t t = opcode - 0xd9; 108 | if (m_mod == 3) { 109 | ht = hde32_table + DELTA_FPU_MODRM + t*8; 110 | t = ht[m_reg] << m_rm; 111 | } else { 112 | ht = hde32_table + DELTA_FPU_REG; 113 | t = ht[t] << m_reg; 114 | } 115 | if (t & 0x80) 116 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 117 | } 118 | 119 | if (pref & PRE_LOCK) { 120 | if (m_mod == 3) { 121 | hs->flags |= F_ERROR | F_ERROR_LOCK; 122 | } else { 123 | uint8_t *table_end, op = opcode; 124 | if (hs->opcode2) { 125 | ht = hde32_table + DELTA_OP2_LOCK_OK; 126 | table_end = ht + DELTA_OP_ONLY_MEM - DELTA_OP2_LOCK_OK; 127 | } else { 128 | ht = hde32_table + DELTA_OP_LOCK_OK; 129 | table_end = ht + DELTA_OP2_LOCK_OK - DELTA_OP_LOCK_OK; 130 | op &= -2; 131 | } 132 | for (; ht != table_end; ht++) 133 | if (*ht++ == op) { 134 | if (!((*ht << m_reg) & 0x80)) 135 | goto no_lock_error; 136 | else 137 | break; 138 | } 139 | hs->flags |= F_ERROR | F_ERROR_LOCK; 140 | no_lock_error: 141 | ; 142 | } 143 | } 144 | 145 | if (hs->opcode2) { 146 | switch (opcode) { 147 | case 0x20: case 0x22: 148 | m_mod = 3; 149 | if (m_reg > 4 || m_reg == 1) 150 | goto error_operand; 151 | else 152 | goto no_error_operand; 153 | case 0x21: case 0x23: 154 | m_mod = 3; 155 | if (m_reg == 4 || m_reg == 5) 156 | goto error_operand; 157 | else 158 | goto no_error_operand; 159 | } 160 | } else { 161 | switch (opcode) { 162 | case 0x8c: 163 | if (m_reg > 5) 164 | goto error_operand; 165 | else 166 | goto no_error_operand; 167 | case 0x8e: 168 | if (m_reg == 1 || m_reg > 5) 169 | goto error_operand; 170 | else 171 | goto no_error_operand; 172 | } 173 | } 174 | 175 | if (m_mod == 3) { 176 | uint8_t *table_end; 177 | if (hs->opcode2) { 178 | ht = hde32_table + DELTA_OP2_ONLY_MEM; 179 | table_end = ht + sizeof(hde32_table) - DELTA_OP2_ONLY_MEM; 180 | } else { 181 | ht = hde32_table + DELTA_OP_ONLY_MEM; 182 | table_end = ht + DELTA_OP2_ONLY_MEM - DELTA_OP_ONLY_MEM; 183 | } 184 | for (; ht != table_end; ht += 2) 185 | if (*ht++ == opcode) { 186 | if (*ht++ & pref && !((*ht << m_reg) & 0x80)) 187 | goto error_operand; 188 | else 189 | break; 190 | } 191 | goto no_error_operand; 192 | } else if (hs->opcode2) { 193 | switch (opcode) { 194 | case 0x50: case 0xd7: case 0xf7: 195 | if (pref & (PRE_NONE | PRE_66)) 196 | goto error_operand; 197 | break; 198 | case 0xd6: 199 | if (pref & (PRE_F2 | PRE_F3)) 200 | goto error_operand; 201 | break; 202 | case 0xc5: 203 | goto error_operand; 204 | } 205 | goto no_error_operand; 206 | } else 207 | goto no_error_operand; 208 | 209 | error_operand: 210 | hs->flags |= F_ERROR | F_ERROR_OPERAND; 211 | no_error_operand: 212 | 213 | c = *p++; 214 | if (m_reg <= 1) { 215 | if (opcode == 0xf6) 216 | cflags |= C_IMM8; 217 | else if (opcode == 0xf7) 218 | cflags |= C_IMM_P66; 219 | } 220 | 221 | switch (m_mod) { 222 | case 0: 223 | if (pref & PRE_67) { 224 | if (m_rm == 6) 225 | disp_size = 2; 226 | } else 227 | if (m_rm == 5) 228 | disp_size = 4; 229 | break; 230 | case 1: 231 | disp_size = 1; 232 | break; 233 | case 2: 234 | disp_size = 2; 235 | if (!(pref & PRE_67)) 236 | disp_size <<= 1; 237 | } 238 | 239 | if (m_mod != 3 && m_rm == 4 && !(pref & PRE_67)) { 240 | hs->flags |= F_SIB; 241 | p++; 242 | hs->sib = c; 243 | hs->sib_scale = c >> 6; 244 | hs->sib_index = (c & 0x3f) >> 3; 245 | if ((hs->sib_base = c & 7) == 5 && !(m_mod & 1)) 246 | disp_size = 4; 247 | } 248 | 249 | p--; 250 | switch (disp_size) { 251 | case 1: 252 | hs->flags |= F_DISP8; 253 | hs->disp.disp8 = *p; 254 | break; 255 | case 2: 256 | hs->flags |= F_DISP16; 257 | hs->disp.disp16 = *(uint16_t *)p; 258 | break; 259 | case 4: 260 | hs->flags |= F_DISP32; 261 | hs->disp.disp32 = *(uint32_t *)p; 262 | } 263 | p += disp_size; 264 | } else if (pref & PRE_LOCK) 265 | hs->flags |= F_ERROR | F_ERROR_LOCK; 266 | 267 | if (cflags & C_IMM_P66) { 268 | if (cflags & C_REL32) { 269 | if (pref & PRE_66) { 270 | hs->flags |= F_IMM16 | F_RELATIVE; 271 | hs->imm.imm16 = *(uint16_t *)p; 272 | p += 2; 273 | goto disasm_done; 274 | } 275 | goto rel32_ok; 276 | } 277 | if (pref & PRE_66) { 278 | hs->flags |= F_IMM16; 279 | hs->imm.imm16 = *(uint16_t *)p; 280 | p += 2; 281 | } else { 282 | hs->flags |= F_IMM32; 283 | hs->imm.imm32 = *(uint32_t *)p; 284 | p += 4; 285 | } 286 | } 287 | 288 | if (cflags & C_IMM16) { 289 | if (hs->flags & F_IMM32) { 290 | hs->flags |= F_IMM16; 291 | hs->disp.disp16 = *(uint16_t *)p; 292 | } else if (hs->flags & F_IMM16) { 293 | hs->flags |= F_2IMM16; 294 | hs->disp.disp16 = *(uint16_t *)p; 295 | } else { 296 | hs->flags |= F_IMM16; 297 | hs->imm.imm16 = *(uint16_t *)p; 298 | } 299 | p += 2; 300 | } 301 | if (cflags & C_IMM8) { 302 | hs->flags |= F_IMM8; 303 | hs->imm.imm8 = *p++; 304 | } 305 | 306 | if (cflags & C_REL32) { 307 | rel32_ok: 308 | hs->flags |= F_IMM32 | F_RELATIVE; 309 | hs->imm.imm32 = *(uint32_t *)p; 310 | p += 4; 311 | } else if (cflags & C_REL8) { 312 | hs->flags |= F_IMM8 | F_RELATIVE; 313 | hs->imm.imm8 = *p++; 314 | } 315 | 316 | disasm_done: 317 | 318 | if ((hs->len = (uint8_t)(p-(uint8_t *)code)) > 15) { 319 | hs->flags |= F_ERROR | F_ERROR_LENGTH; 320 | hs->len = 15; 321 | } 322 | 323 | return (unsigned int)hs->len; 324 | } 325 | 326 | #endif // defined(_M_IX86) || defined(__i386__) 327 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/hde/hde32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 3 | * Copyright (c) 2006-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde32.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE32_H_ 11 | #define _HDE32_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_DISP8 0x00000020 30 | #define F_DISP16 0x00000040 31 | #define F_DISP32 0x00000080 32 | #define F_RELATIVE 0x00000100 33 | #define F_2IMM16 0x00000800 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_ANY 0x3f000000 47 | 48 | #define PREFIX_SEGMENT_CS 0x2e 49 | #define PREFIX_SEGMENT_SS 0x36 50 | #define PREFIX_SEGMENT_DS 0x3e 51 | #define PREFIX_SEGMENT_ES 0x26 52 | #define PREFIX_SEGMENT_FS 0x64 53 | #define PREFIX_SEGMENT_GS 0x65 54 | #define PREFIX_LOCK 0xf0 55 | #define PREFIX_REPNZ 0xf2 56 | #define PREFIX_REPX 0xf3 57 | #define PREFIX_OPERAND_SIZE 0x66 58 | #define PREFIX_ADDRESS_SIZE 0x67 59 | 60 | #pragma pack(push,1) 61 | 62 | typedef struct { 63 | uint8_t len; 64 | uint8_t p_rep; 65 | uint8_t p_lock; 66 | uint8_t p_seg; 67 | uint8_t p_66; 68 | uint8_t p_67; 69 | uint8_t opcode; 70 | uint8_t opcode2; 71 | uint8_t modrm; 72 | uint8_t modrm_mod; 73 | uint8_t modrm_reg; 74 | uint8_t modrm_rm; 75 | uint8_t sib; 76 | uint8_t sib_scale; 77 | uint8_t sib_index; 78 | uint8_t sib_base; 79 | union { 80 | uint8_t imm8; 81 | uint16_t imm16; 82 | uint32_t imm32; 83 | } imm; 84 | union { 85 | uint8_t disp8; 86 | uint16_t disp16; 87 | uint32_t disp32; 88 | } disp; 89 | uint32_t flags; 90 | } hde32s; 91 | 92 | #pragma pack(pop) 93 | 94 | #ifdef __cplusplus 95 | extern "C" { 96 | #endif 97 | 98 | /* __cdecl */ 99 | unsigned int hde32_disasm(const void *code, hde32s *hs); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* _HDE32_H_ */ 106 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/hde/hde64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #if defined(_M_X64) || defined(__x86_64__) 9 | 10 | #include "hde64.h" 11 | #include "table64.h" 12 | 13 | unsigned int hde64_disasm(const void *code, hde64s *hs) 14 | { 15 | uint8_t x, c, *p = (uint8_t *)code, cflags, opcode, pref = 0; 16 | uint8_t *ht = hde64_table, m_mod, m_reg, m_rm, disp_size = 0; 17 | uint8_t op64 = 0; 18 | 19 | // Avoid using memset to reduce the footprint. 20 | #ifndef _MSC_VER 21 | memset((LPBYTE)hs, 0, sizeof(hde64s)); 22 | #else 23 | __stosb((LPBYTE)hs, 0, sizeof(hde64s)); 24 | #endif 25 | 26 | for (x = 16; x; x--) 27 | switch (c = *p++) { 28 | case 0xf3: 29 | hs->p_rep = c; 30 | pref |= PRE_F3; 31 | break; 32 | case 0xf2: 33 | hs->p_rep = c; 34 | pref |= PRE_F2; 35 | break; 36 | case 0xf0: 37 | hs->p_lock = c; 38 | pref |= PRE_LOCK; 39 | break; 40 | case 0x26: case 0x2e: case 0x36: 41 | case 0x3e: case 0x64: case 0x65: 42 | hs->p_seg = c; 43 | pref |= PRE_SEG; 44 | break; 45 | case 0x66: 46 | hs->p_66 = c; 47 | pref |= PRE_66; 48 | break; 49 | case 0x67: 50 | hs->p_67 = c; 51 | pref |= PRE_67; 52 | break; 53 | default: 54 | goto pref_done; 55 | } 56 | pref_done: 57 | 58 | hs->flags = (uint32_t)pref << 23; 59 | 60 | if (!pref) 61 | pref |= PRE_NONE; 62 | 63 | if ((c & 0xf0) == 0x40) { 64 | hs->flags |= F_PREFIX_REX; 65 | if ((hs->rex_w = (c & 0xf) >> 3) && (*p & 0xf8) == 0xb8) 66 | op64++; 67 | hs->rex_r = (c & 7) >> 2; 68 | hs->rex_x = (c & 3) >> 1; 69 | hs->rex_b = c & 1; 70 | if (((c = *p++) & 0xf0) == 0x40) { 71 | opcode = c; 72 | goto error_opcode; 73 | } 74 | } 75 | 76 | if ((hs->opcode = c) == 0x0f) { 77 | hs->opcode2 = c = *p++; 78 | ht += DELTA_OPCODES; 79 | } else if (c >= 0xa0 && c <= 0xa3) { 80 | op64++; 81 | if (pref & PRE_67) 82 | pref |= PRE_66; 83 | else 84 | pref &= ~PRE_66; 85 | } 86 | 87 | opcode = c; 88 | cflags = ht[ht[opcode / 4] + (opcode % 4)]; 89 | 90 | if (cflags == C_ERROR) { 91 | error_opcode: 92 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 93 | cflags = 0; 94 | if ((opcode & -3) == 0x24) 95 | cflags++; 96 | } 97 | 98 | x = 0; 99 | if (cflags & C_GROUP) { 100 | uint16_t t; 101 | t = *(uint16_t *)(ht + (cflags & 0x7f)); 102 | cflags = (uint8_t)t; 103 | x = (uint8_t)(t >> 8); 104 | } 105 | 106 | if (hs->opcode2) { 107 | ht = hde64_table + DELTA_PREFIXES; 108 | if (ht[ht[opcode / 4] + (opcode % 4)] & pref) 109 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 110 | } 111 | 112 | if (cflags & C_MODRM) { 113 | hs->flags |= F_MODRM; 114 | hs->modrm = c = *p++; 115 | hs->modrm_mod = m_mod = c >> 6; 116 | hs->modrm_rm = m_rm = c & 7; 117 | hs->modrm_reg = m_reg = (c & 0x3f) >> 3; 118 | 119 | if (x && ((x << m_reg) & 0x80)) 120 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 121 | 122 | if (!hs->opcode2 && opcode >= 0xd9 && opcode <= 0xdf) { 123 | uint8_t t = opcode - 0xd9; 124 | if (m_mod == 3) { 125 | ht = hde64_table + DELTA_FPU_MODRM + t*8; 126 | t = ht[m_reg] << m_rm; 127 | } else { 128 | ht = hde64_table + DELTA_FPU_REG; 129 | t = ht[t] << m_reg; 130 | } 131 | if (t & 0x80) 132 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 133 | } 134 | 135 | if (pref & PRE_LOCK) { 136 | if (m_mod == 3) { 137 | hs->flags |= F_ERROR | F_ERROR_LOCK; 138 | } else { 139 | uint8_t *table_end, op = opcode; 140 | if (hs->opcode2) { 141 | ht = hde64_table + DELTA_OP2_LOCK_OK; 142 | table_end = ht + DELTA_OP_ONLY_MEM - DELTA_OP2_LOCK_OK; 143 | } else { 144 | ht = hde64_table + DELTA_OP_LOCK_OK; 145 | table_end = ht + DELTA_OP2_LOCK_OK - DELTA_OP_LOCK_OK; 146 | op &= -2; 147 | } 148 | for (; ht != table_end; ht++) 149 | if (*ht++ == op) { 150 | if (!((*ht << m_reg) & 0x80)) 151 | goto no_lock_error; 152 | else 153 | break; 154 | } 155 | hs->flags |= F_ERROR | F_ERROR_LOCK; 156 | no_lock_error: 157 | ; 158 | } 159 | } 160 | 161 | if (hs->opcode2) { 162 | switch (opcode) { 163 | case 0x20: case 0x22: 164 | m_mod = 3; 165 | if (m_reg > 4 || m_reg == 1) 166 | goto error_operand; 167 | else 168 | goto no_error_operand; 169 | case 0x21: case 0x23: 170 | m_mod = 3; 171 | if (m_reg == 4 || m_reg == 5) 172 | goto error_operand; 173 | else 174 | goto no_error_operand; 175 | } 176 | } else { 177 | switch (opcode) { 178 | case 0x8c: 179 | if (m_reg > 5) 180 | goto error_operand; 181 | else 182 | goto no_error_operand; 183 | case 0x8e: 184 | if (m_reg == 1 || m_reg > 5) 185 | goto error_operand; 186 | else 187 | goto no_error_operand; 188 | } 189 | } 190 | 191 | if (m_mod == 3) { 192 | uint8_t *table_end; 193 | if (hs->opcode2) { 194 | ht = hde64_table + DELTA_OP2_ONLY_MEM; 195 | table_end = ht + sizeof(hde64_table) - DELTA_OP2_ONLY_MEM; 196 | } else { 197 | ht = hde64_table + DELTA_OP_ONLY_MEM; 198 | table_end = ht + DELTA_OP2_ONLY_MEM - DELTA_OP_ONLY_MEM; 199 | } 200 | for (; ht != table_end; ht += 2) 201 | if (*ht++ == opcode) { 202 | if (*ht++ & pref && !((*ht << m_reg) & 0x80)) 203 | goto error_operand; 204 | else 205 | break; 206 | } 207 | goto no_error_operand; 208 | } else if (hs->opcode2) { 209 | switch (opcode) { 210 | case 0x50: case 0xd7: case 0xf7: 211 | if (pref & (PRE_NONE | PRE_66)) 212 | goto error_operand; 213 | break; 214 | case 0xd6: 215 | if (pref & (PRE_F2 | PRE_F3)) 216 | goto error_operand; 217 | break; 218 | case 0xc5: 219 | goto error_operand; 220 | } 221 | goto no_error_operand; 222 | } else 223 | goto no_error_operand; 224 | 225 | error_operand: 226 | hs->flags |= F_ERROR | F_ERROR_OPERAND; 227 | no_error_operand: 228 | 229 | c = *p++; 230 | if (m_reg <= 1) { 231 | if (opcode == 0xf6) 232 | cflags |= C_IMM8; 233 | else if (opcode == 0xf7) 234 | cflags |= C_IMM_P66; 235 | } 236 | 237 | switch (m_mod) { 238 | case 0: 239 | if (pref & PRE_67) { 240 | if (m_rm == 6) 241 | disp_size = 2; 242 | } else 243 | if (m_rm == 5) 244 | disp_size = 4; 245 | break; 246 | case 1: 247 | disp_size = 1; 248 | break; 249 | case 2: 250 | disp_size = 2; 251 | if (!(pref & PRE_67)) 252 | disp_size <<= 1; 253 | } 254 | 255 | if (m_mod != 3 && m_rm == 4) { 256 | hs->flags |= F_SIB; 257 | p++; 258 | hs->sib = c; 259 | hs->sib_scale = c >> 6; 260 | hs->sib_index = (c & 0x3f) >> 3; 261 | if ((hs->sib_base = c & 7) == 5 && !(m_mod & 1)) 262 | disp_size = 4; 263 | } 264 | 265 | p--; 266 | switch (disp_size) { 267 | case 1: 268 | hs->flags |= F_DISP8; 269 | hs->disp.disp8 = *p; 270 | break; 271 | case 2: 272 | hs->flags |= F_DISP16; 273 | hs->disp.disp16 = *(uint16_t *)p; 274 | break; 275 | case 4: 276 | hs->flags |= F_DISP32; 277 | hs->disp.disp32 = *(uint32_t *)p; 278 | } 279 | p += disp_size; 280 | } else if (pref & PRE_LOCK) 281 | hs->flags |= F_ERROR | F_ERROR_LOCK; 282 | 283 | if (cflags & C_IMM_P66) { 284 | if (cflags & C_REL32) { 285 | if (pref & PRE_66) { 286 | hs->flags |= F_IMM16 | F_RELATIVE; 287 | hs->imm.imm16 = *(uint16_t *)p; 288 | p += 2; 289 | goto disasm_done; 290 | } 291 | goto rel32_ok; 292 | } 293 | if (op64) { 294 | hs->flags |= F_IMM64; 295 | hs->imm.imm64 = *(uint64_t *)p; 296 | p += 8; 297 | } else if (!(pref & PRE_66)) { 298 | hs->flags |= F_IMM32; 299 | hs->imm.imm32 = *(uint32_t *)p; 300 | p += 4; 301 | } else 302 | goto imm16_ok; 303 | } 304 | 305 | 306 | if (cflags & C_IMM16) { 307 | imm16_ok: 308 | hs->flags |= F_IMM16; 309 | hs->imm.imm16 = *(uint16_t *)p; 310 | p += 2; 311 | } 312 | if (cflags & C_IMM8) { 313 | hs->flags |= F_IMM8; 314 | hs->imm.imm8 = *p++; 315 | } 316 | 317 | if (cflags & C_REL32) { 318 | rel32_ok: 319 | hs->flags |= F_IMM32 | F_RELATIVE; 320 | hs->imm.imm32 = *(uint32_t *)p; 321 | p += 4; 322 | } else if (cflags & C_REL8) { 323 | hs->flags |= F_IMM8 | F_RELATIVE; 324 | hs->imm.imm8 = *p++; 325 | } 326 | 327 | disasm_done: 328 | 329 | if ((hs->len = (uint8_t)(p-(uint8_t *)code)) > 15) { 330 | hs->flags |= F_ERROR | F_ERROR_LENGTH; 331 | hs->len = 15; 332 | } 333 | 334 | return (unsigned int)hs->len; 335 | } 336 | 337 | #endif // defined(_M_X64) || defined(__x86_64__) 338 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/hde/hde64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde64.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE64_H_ 11 | #define _HDE64_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_IMM64 0x00000020 30 | #define F_DISP8 0x00000040 31 | #define F_DISP16 0x00000080 32 | #define F_DISP32 0x00000100 33 | #define F_RELATIVE 0x00000200 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_REX 0x40000000 47 | #define F_PREFIX_ANY 0x7f000000 48 | 49 | #define PREFIX_SEGMENT_CS 0x2e 50 | #define PREFIX_SEGMENT_SS 0x36 51 | #define PREFIX_SEGMENT_DS 0x3e 52 | #define PREFIX_SEGMENT_ES 0x26 53 | #define PREFIX_SEGMENT_FS 0x64 54 | #define PREFIX_SEGMENT_GS 0x65 55 | #define PREFIX_LOCK 0xf0 56 | #define PREFIX_REPNZ 0xf2 57 | #define PREFIX_REPX 0xf3 58 | #define PREFIX_OPERAND_SIZE 0x66 59 | #define PREFIX_ADDRESS_SIZE 0x67 60 | 61 | #pragma pack(push,1) 62 | 63 | typedef struct { 64 | uint8_t len; 65 | uint8_t p_rep; 66 | uint8_t p_lock; 67 | uint8_t p_seg; 68 | uint8_t p_66; 69 | uint8_t p_67; 70 | uint8_t rex; 71 | uint8_t rex_w; 72 | uint8_t rex_r; 73 | uint8_t rex_x; 74 | uint8_t rex_b; 75 | uint8_t opcode; 76 | uint8_t opcode2; 77 | uint8_t modrm; 78 | uint8_t modrm_mod; 79 | uint8_t modrm_reg; 80 | uint8_t modrm_rm; 81 | uint8_t sib; 82 | uint8_t sib_scale; 83 | uint8_t sib_index; 84 | uint8_t sib_base; 85 | union { 86 | uint8_t imm8; 87 | uint16_t imm16; 88 | uint32_t imm32; 89 | uint64_t imm64; 90 | } imm; 91 | union { 92 | uint8_t disp8; 93 | uint16_t disp16; 94 | uint32_t disp32; 95 | } disp; 96 | uint32_t flags; 97 | } hde64s; 98 | 99 | #pragma pack(pop) 100 | 101 | #ifdef __cplusplus 102 | extern "C" { 103 | #endif 104 | 105 | /* __cdecl */ 106 | unsigned int hde64_disasm(const void *code, hde64s *hs); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* _HDE64_H_ */ 113 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/hde/pstdint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | // Integer types for HDE. 32 | typedef INT8 int8_t; 33 | typedef INT16 int16_t; 34 | typedef INT32 int32_t; 35 | typedef INT64 int64_t; 36 | typedef UINT8 uint8_t; 37 | typedef UINT16 uint16_t; 38 | typedef UINT32 uint32_t; 39 | typedef UINT64 uint64_t; 40 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/hde/table32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xf1 30 | #define DELTA_FPU_MODRM 0xf8 31 | #define DELTA_PREFIXES 0x130 32 | #define DELTA_OP_LOCK_OK 0x1a1 33 | #define DELTA_OP2_LOCK_OK 0x1b9 34 | #define DELTA_OP_ONLY_MEM 0x1cb 35 | #define DELTA_OP2_ONLY_MEM 0x1da 36 | 37 | unsigned char hde32_table[] = { 38 | 0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3, 39 | 0xa8,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xac,0xaa,0xb2,0xaa,0x9f,0x9f, 40 | 0x9f,0x9f,0xb5,0xa3,0xa3,0xa4,0xaa,0xaa,0xba,0xaa,0x96,0xaa,0xa8,0xaa,0xc3, 41 | 0xc3,0x96,0x96,0xb7,0xae,0xd6,0xbd,0xa3,0xc5,0xa3,0xa3,0x9f,0xc3,0x9c,0xaa, 42 | 0xaa,0xac,0xaa,0xbf,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0x90, 43 | 0x82,0x7d,0x97,0x59,0x59,0x59,0x59,0x59,0x7f,0x59,0x59,0x60,0x7d,0x7f,0x7f, 44 | 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x9a,0x88,0x7d, 45 | 0x59,0x50,0x50,0x50,0x50,0x59,0x59,0x59,0x59,0x61,0x94,0x61,0x9e,0x59,0x59, 46 | 0x85,0x59,0x92,0xa3,0x60,0x60,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59, 47 | 0x59,0x59,0x9f,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xcc,0x01,0xbc,0x03,0xf0, 48 | 0x10,0x10,0x10,0x10,0x50,0x50,0x50,0x50,0x14,0x20,0x20,0x20,0x20,0x01,0x01, 49 | 0x01,0x01,0xc4,0x02,0x10,0x00,0x00,0x00,0x00,0x01,0x01,0xc0,0xc2,0x10,0x11, 50 | 0x02,0x03,0x11,0x03,0x03,0x04,0x00,0x00,0x14,0x00,0x02,0x00,0x00,0xc6,0xc8, 51 | 0x02,0x02,0x02,0x02,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0xca, 52 | 0x01,0x01,0x01,0x00,0x06,0x00,0x04,0x00,0xc0,0xc2,0x01,0x01,0x03,0x01,0xff, 53 | 0xff,0x01,0x00,0x03,0xc4,0xc4,0xc6,0x03,0x01,0x01,0x01,0xff,0x03,0x03,0x03, 54 | 0xc8,0x40,0x00,0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00, 55 | 0x00,0x00,0x00,0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00, 56 | 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 57 | 0x00,0xff,0xff,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 58 | 0x7f,0x00,0x00,0xff,0x4a,0x4a,0x4a,0x4a,0x4b,0x52,0x4a,0x4a,0x4a,0x4a,0x4f, 59 | 0x4c,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x55,0x45,0x40,0x4a,0x4a,0x4a, 60 | 0x45,0x59,0x4d,0x46,0x4a,0x5d,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a, 61 | 0x4a,0x4a,0x4a,0x4a,0x4a,0x61,0x63,0x67,0x4e,0x4a,0x4a,0x6b,0x6d,0x4a,0x4a, 62 | 0x45,0x6d,0x4a,0x4a,0x44,0x45,0x4a,0x4a,0x00,0x00,0x00,0x02,0x0d,0x06,0x06, 63 | 0x06,0x06,0x0e,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x02,0x06, 64 | 0x00,0x0a,0x0a,0x07,0x07,0x06,0x02,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 65 | 0x04,0x04,0x00,0x00,0x00,0x0e,0x05,0x06,0x06,0x06,0x01,0x06,0x00,0x00,0x08, 66 | 0x00,0x10,0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01, 67 | 0x86,0x00,0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba, 68 | 0xf8,0xbb,0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00, 69 | 0xc4,0xff,0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00, 70 | 0x13,0x09,0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07, 71 | 0xb2,0xff,0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf, 72 | 0xe7,0x08,0x00,0xf0,0x02,0x00 73 | }; 74 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/hde/table64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xfd 30 | #define DELTA_FPU_MODRM 0x104 31 | #define DELTA_PREFIXES 0x13c 32 | #define DELTA_OP_LOCK_OK 0x1ae 33 | #define DELTA_OP2_LOCK_OK 0x1c6 34 | #define DELTA_OP_ONLY_MEM 0x1d8 35 | #define DELTA_OP2_ONLY_MEM 0x1e7 36 | 37 | unsigned char hde64_table[] = { 38 | 0xa5,0xaa,0xa5,0xb8,0xa5,0xaa,0xa5,0xaa,0xa5,0xb8,0xa5,0xb8,0xa5,0xb8,0xa5, 39 | 0xb8,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xac,0xc0,0xcc,0xc0,0xa1,0xa1, 40 | 0xa1,0xa1,0xb1,0xa5,0xa5,0xa6,0xc0,0xc0,0xd7,0xda,0xe0,0xc0,0xe4,0xc0,0xea, 41 | 0xea,0xe0,0xe0,0x98,0xc8,0xee,0xf1,0xa5,0xd3,0xa5,0xa5,0xa1,0xea,0x9e,0xc0, 42 | 0xc0,0xc2,0xc0,0xe6,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0xab, 43 | 0x8b,0x90,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x92,0x5b,0x5b,0x76,0x90,0x92,0x92, 44 | 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x6a,0x73,0x90, 45 | 0x5b,0x52,0x52,0x52,0x52,0x5b,0x5b,0x5b,0x5b,0x77,0x7c,0x77,0x85,0x5b,0x5b, 46 | 0x70,0x5b,0x7a,0xaf,0x76,0x76,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b, 47 | 0x5b,0x5b,0x86,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xd5,0x03,0xcc,0x01,0xbc, 48 | 0x03,0xf0,0x03,0x03,0x04,0x00,0x50,0x50,0x50,0x50,0xff,0x20,0x20,0x20,0x20, 49 | 0x01,0x01,0x01,0x01,0xc4,0x02,0x10,0xff,0xff,0xff,0x01,0x00,0x03,0x11,0xff, 50 | 0x03,0xc4,0xc6,0xc8,0x02,0x10,0x00,0xff,0xcc,0x01,0x01,0x01,0x00,0x00,0x00, 51 | 0x00,0x01,0x01,0x03,0x01,0xff,0xff,0xc0,0xc2,0x10,0x11,0x02,0x03,0x01,0x01, 52 | 0x01,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x10, 53 | 0x10,0x10,0x10,0x02,0x10,0x00,0x00,0xc6,0xc8,0x02,0x02,0x02,0x02,0x06,0x00, 54 | 0x04,0x00,0x02,0xff,0x00,0xc0,0xc2,0x01,0x01,0x03,0x03,0x03,0xca,0x40,0x00, 55 | 0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,0x00,0x00,0x00, 56 | 0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0xff,0x00, 57 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff, 58 | 0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00, 59 | 0xff,0x40,0x40,0x40,0x40,0x41,0x49,0x40,0x40,0x40,0x40,0x4c,0x42,0x40,0x40, 60 | 0x40,0x40,0x40,0x40,0x40,0x40,0x4f,0x44,0x53,0x40,0x40,0x40,0x44,0x57,0x43, 61 | 0x5c,0x40,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 62 | 0x40,0x40,0x64,0x66,0x6e,0x6b,0x40,0x40,0x6a,0x46,0x40,0x40,0x44,0x46,0x40, 63 | 0x40,0x5b,0x44,0x40,0x40,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x01,0x06, 64 | 0x06,0x02,0x06,0x06,0x00,0x06,0x00,0x0a,0x0a,0x00,0x00,0x00,0x02,0x07,0x07, 65 | 0x06,0x02,0x0d,0x06,0x06,0x06,0x0e,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 66 | 0x04,0x04,0x05,0x06,0x06,0x06,0x00,0x00,0x00,0x0e,0x00,0x00,0x08,0x00,0x10, 67 | 0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,0x86,0x00, 68 | 0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,0xf8,0xbb, 69 | 0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,0xc4,0xff, 70 | 0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00,0x13,0x09, 71 | 0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07,0xb2,0xff, 72 | 0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,0xe7,0x08, 73 | 0x00,0xf0,0x02,0x00 74 | }; 75 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/trampoline.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | 31 | #ifndef ARRAYSIZE 32 | #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) 33 | #endif 34 | 35 | #if defined(_M_X64) || defined(__x86_64__) 36 | #include "./hde/hde64.h" 37 | typedef hde64s HDE; 38 | #define HDE_DISASM(code, hs) hde64_disasm(code, hs) 39 | #else 40 | #include "./hde/hde32.h" 41 | typedef hde32s HDE; 42 | #define HDE_DISASM(code, hs) hde32_disasm(code, hs) 43 | #endif 44 | 45 | #include "trampoline.h" 46 | #include "buffer.h" 47 | 48 | // Maximum size of a trampoline function. 49 | #if defined(_M_X64) || defined(__x86_64__) 50 | #define TRAMPOLINE_MAX_SIZE (MEMORY_SLOT_SIZE - sizeof(JMP_ABS)) 51 | #else 52 | #define TRAMPOLINE_MAX_SIZE MEMORY_SLOT_SIZE 53 | #endif 54 | 55 | //------------------------------------------------------------------------- 56 | static BOOL IsCodePadding(LPBYTE pInst, UINT size) 57 | { 58 | UINT i; 59 | 60 | if (pInst[0] != 0x00 && pInst[0] != 0x90 && pInst[0] != 0xCC) 61 | return FALSE; 62 | 63 | for (i = 1; i < size; ++i) 64 | { 65 | if (pInst[i] != pInst[0]) 66 | return FALSE; 67 | } 68 | return TRUE; 69 | } 70 | 71 | //------------------------------------------------------------------------- 72 | BOOL CreateTrampolineFunction(PTRAMPOLINE ct) 73 | { 74 | #if defined(_M_X64) || defined(__x86_64__) 75 | CALL_ABS call = { 76 | 0xFF, 0x15, 0x00000002, // FF15 00000002: CALL [RIP+8] 77 | 0xEB, 0x08, // EB 08: JMP +10 78 | 0x0000000000000000ULL // Absolute destination address 79 | }; 80 | JMP_ABS jmp = { 81 | 0xFF, 0x25, 0x00000000, // FF25 00000000: JMP [RIP+6] 82 | 0x0000000000000000ULL // Absolute destination address 83 | }; 84 | JCC_ABS jcc = { 85 | 0x70, 0x0E, // 7* 0E: J** +16 86 | 0xFF, 0x25, 0x00000000, // FF25 00000000: JMP [RIP+6] 87 | 0x0000000000000000ULL // Absolute destination address 88 | }; 89 | #else 90 | CALL_REL call = { 91 | 0xE8, // E8 xxxxxxxx: CALL +5+xxxxxxxx 92 | 0x00000000 // Relative destination address 93 | }; 94 | JMP_REL jmp = { 95 | 0xE9, // E9 xxxxxxxx: JMP +5+xxxxxxxx 96 | 0x00000000 // Relative destination address 97 | }; 98 | JCC_REL jcc = { 99 | 0x0F, 0x80, // 0F8* xxxxxxxx: J** +6+xxxxxxxx 100 | 0x00000000 // Relative destination address 101 | }; 102 | #endif 103 | 104 | UINT8 oldPos = 0; 105 | UINT8 newPos = 0; 106 | ULONG_PTR jmpDest = 0; // Destination address of an internal jump. 107 | BOOL finished = FALSE; // Is the function completed? 108 | #if defined(_M_X64) || defined(__x86_64__) 109 | UINT8 instBuf[16]; 110 | #endif 111 | 112 | ct->patchAbove = FALSE; 113 | ct->nIP = 0; 114 | 115 | do 116 | { 117 | HDE hs; 118 | UINT copySize; 119 | LPVOID pCopySrc; 120 | ULONG_PTR pOldInst = (ULONG_PTR)ct->pTarget + oldPos; 121 | ULONG_PTR pNewInst = (ULONG_PTR)ct->pTrampoline + newPos; 122 | 123 | copySize = HDE_DISASM((LPVOID)pOldInst, &hs); 124 | if (hs.flags & F_ERROR) 125 | return FALSE; 126 | 127 | pCopySrc = (LPVOID)pOldInst; 128 | if (oldPos >= sizeof(JMP_REL)) 129 | { 130 | // The trampoline function is long enough. 131 | // Complete the function with the jump to the target function. 132 | #if defined(_M_X64) || defined(__x86_64__) 133 | jmp.address = pOldInst; 134 | #else 135 | jmp.operand = (UINT32)(pOldInst - (pNewInst + sizeof(jmp))); 136 | #endif 137 | pCopySrc = &jmp; 138 | copySize = sizeof(jmp); 139 | 140 | finished = TRUE; 141 | } 142 | #if defined(_M_X64) || defined(__x86_64__) 143 | else if ((hs.modrm & 0xC7) == 0x05) 144 | { 145 | // Instructions using RIP relative addressing. (ModR/M = 00???101B) 146 | 147 | // Modify the RIP relative address. 148 | PUINT32 pRelAddr; 149 | 150 | // Avoid using memcpy to reduce the footprint. 151 | #ifndef _MSC_VER 152 | memcpy(instBuf, (LPBYTE)pOldInst, copySize); 153 | #else 154 | __movsb(instBuf, (LPBYTE)pOldInst, copySize); 155 | #endif 156 | pCopySrc = instBuf; 157 | 158 | // Relative address is stored at (instruction length - immediate value length - 4). 159 | pRelAddr = (PUINT32)(instBuf + hs.len - ((hs.flags & 0x3C) >> 2) - 4); 160 | *pRelAddr 161 | = (UINT32)((pOldInst + hs.len + (INT32)hs.disp.disp32) - (pNewInst + hs.len)); 162 | 163 | // Complete the function if JMP (FF /4). 164 | if (hs.opcode == 0xFF && hs.modrm_reg == 4) 165 | finished = TRUE; 166 | } 167 | #endif 168 | else if (hs.opcode == 0xE8) 169 | { 170 | // Direct relative CALL 171 | ULONG_PTR dest = pOldInst + hs.len + (INT32)hs.imm.imm32; 172 | #if defined(_M_X64) || defined(__x86_64__) 173 | call.address = dest; 174 | #else 175 | call.operand = (UINT32)(dest - (pNewInst + sizeof(call))); 176 | #endif 177 | pCopySrc = &call; 178 | copySize = sizeof(call); 179 | } 180 | else if ((hs.opcode & 0xFD) == 0xE9) 181 | { 182 | // Direct relative JMP (EB or E9) 183 | ULONG_PTR dest = pOldInst + hs.len; 184 | 185 | if (hs.opcode == 0xEB) // isShort jmp 186 | dest += (INT8)hs.imm.imm8; 187 | else 188 | dest += (INT32)hs.imm.imm32; 189 | 190 | // Simply copy an internal jump. 191 | if ((ULONG_PTR)ct->pTarget <= dest 192 | && dest < ((ULONG_PTR)ct->pTarget + sizeof(JMP_REL))) 193 | { 194 | if (jmpDest < dest) 195 | jmpDest = dest; 196 | } 197 | else 198 | { 199 | #if defined(_M_X64) || defined(__x86_64__) 200 | jmp.address = dest; 201 | #else 202 | jmp.operand = (UINT32)(dest - (pNewInst + sizeof(jmp))); 203 | #endif 204 | pCopySrc = &jmp; 205 | copySize = sizeof(jmp); 206 | 207 | // Exit the function If it is not in the branch 208 | finished = (pOldInst >= jmpDest); 209 | } 210 | } 211 | else if ((hs.opcode & 0xF0) == 0x70 212 | || (hs.opcode & 0xFC) == 0xE0 213 | || (hs.opcode2 & 0xF0) == 0x80) 214 | { 215 | // Direct relative Jcc 216 | ULONG_PTR dest = pOldInst + hs.len; 217 | 218 | if ((hs.opcode & 0xF0) == 0x70 // Jcc 219 | || (hs.opcode & 0xFC) == 0xE0) // LOOPNZ/LOOPZ/LOOP/JECXZ 220 | dest += (INT8)hs.imm.imm8; 221 | else 222 | dest += (INT32)hs.imm.imm32; 223 | 224 | // Simply copy an internal jump. 225 | if ((ULONG_PTR)ct->pTarget <= dest 226 | && dest < ((ULONG_PTR)ct->pTarget + sizeof(JMP_REL))) 227 | { 228 | if (jmpDest < dest) 229 | jmpDest = dest; 230 | } 231 | else if ((hs.opcode & 0xFC) == 0xE0) 232 | { 233 | // LOOPNZ/LOOPZ/LOOP/JCXZ/JECXZ to the outside are not supported. 234 | return FALSE; 235 | } 236 | else 237 | { 238 | UINT8 cond = ((hs.opcode != 0x0F ? hs.opcode : hs.opcode2) & 0x0F); 239 | #if defined(_M_X64) || defined(__x86_64__) 240 | // Invert the condition in x64 mode to simplify the conditional jump logic. 241 | jcc.opcode = 0x71 ^ cond; 242 | jcc.address = dest; 243 | #else 244 | jcc.opcode1 = 0x80 | cond; 245 | jcc.operand = (UINT32)(dest - (pNewInst + sizeof(jcc))); 246 | #endif 247 | pCopySrc = &jcc; 248 | copySize = sizeof(jcc); 249 | } 250 | } 251 | else if ((hs.opcode & 0xFE) == 0xC2) 252 | { 253 | // RET (C2 or C3) 254 | 255 | // Complete the function if not in a branch. 256 | finished = (pOldInst >= jmpDest); 257 | } 258 | 259 | // Can't alter the instruction length in a branch. 260 | if (pOldInst < jmpDest && copySize != hs.len) 261 | return FALSE; 262 | 263 | // Trampoline function is too large. 264 | if ((newPos + copySize) > TRAMPOLINE_MAX_SIZE) 265 | return FALSE; 266 | 267 | // Trampoline function has too many instructions. 268 | if (ct->nIP >= ARRAYSIZE(ct->oldIPs)) 269 | return FALSE; 270 | 271 | ct->oldIPs[ct->nIP] = oldPos; 272 | ct->newIPs[ct->nIP] = newPos; 273 | ct->nIP++; 274 | 275 | // Avoid using memcpy to reduce the footprint. 276 | #ifndef _MSC_VER 277 | memcpy((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize); 278 | #else 279 | __movsb((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize); 280 | #endif 281 | newPos += copySize; 282 | oldPos += hs.len; 283 | } 284 | while (!finished); 285 | 286 | // Is there enough place for a long jump? 287 | if (oldPos < sizeof(JMP_REL) 288 | && !IsCodePadding((LPBYTE)ct->pTarget + oldPos, sizeof(JMP_REL) - oldPos)) 289 | { 290 | // Is there enough place for a short jump? 291 | if (oldPos < sizeof(JMP_REL_SHORT) 292 | && !IsCodePadding((LPBYTE)ct->pTarget + oldPos, sizeof(JMP_REL_SHORT) - oldPos)) 293 | { 294 | return FALSE; 295 | } 296 | 297 | // Can we place the long jump above the function? 298 | if (!IsExecutableAddress((LPBYTE)ct->pTarget - sizeof(JMP_REL))) 299 | return FALSE; 300 | 301 | if (!IsCodePadding((LPBYTE)ct->pTarget - sizeof(JMP_REL), sizeof(JMP_REL))) 302 | return FALSE; 303 | 304 | ct->patchAbove = TRUE; 305 | } 306 | 307 | #if defined(_M_X64) || defined(__x86_64__) 308 | // Create a relay function. 309 | jmp.address = (ULONG_PTR)ct->pDetour; 310 | 311 | ct->pRelay = (LPBYTE)ct->pTrampoline + newPos; 312 | memcpy(ct->pRelay, &jmp, sizeof(jmp)); 313 | #endif 314 | 315 | return TRUE; 316 | } 317 | -------------------------------------------------------------------------------- /thirdparty/MinHook/src/trampoline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | #pragma pack(push, 1) 32 | 33 | // Structs for writing x86/x64 instructions. 34 | 35 | // 8-bit relative jump. 36 | typedef struct _JMP_REL_SHORT 37 | { 38 | UINT8 opcode; // EB xx: JMP +2+xx 39 | UINT8 operand; 40 | } JMP_REL_SHORT, *PJMP_REL_SHORT; 41 | 42 | // 32-bit direct relative jump/call. 43 | typedef struct _JMP_REL 44 | { 45 | UINT8 opcode; // E9/E8 xxxxxxxx: JMP/CALL +5+xxxxxxxx 46 | UINT32 operand; // Relative destination address 47 | } JMP_REL, *PJMP_REL, CALL_REL; 48 | 49 | // 64-bit indirect absolute jump. 50 | typedef struct _JMP_ABS 51 | { 52 | UINT8 opcode0; // FF25 00000000: JMP [+6] 53 | UINT8 opcode1; 54 | UINT32 dummy; 55 | UINT64 address; // Absolute destination address 56 | } JMP_ABS, *PJMP_ABS; 57 | 58 | // 64-bit indirect absolute call. 59 | typedef struct _CALL_ABS 60 | { 61 | UINT8 opcode0; // FF15 00000002: CALL [+6] 62 | UINT8 opcode1; 63 | UINT32 dummy0; 64 | UINT8 dummy1; // EB 08: JMP +10 65 | UINT8 dummy2; 66 | UINT64 address; // Absolute destination address 67 | } CALL_ABS; 68 | 69 | // 32-bit direct relative conditional jumps. 70 | typedef struct _JCC_REL 71 | { 72 | UINT8 opcode0; // 0F8* xxxxxxxx: J** +6+xxxxxxxx 73 | UINT8 opcode1; 74 | UINT32 operand; // Relative destination address 75 | } JCC_REL; 76 | 77 | // 64bit indirect absolute conditional jumps that x64 lacks. 78 | typedef struct _JCC_ABS 79 | { 80 | UINT8 opcode; // 7* 0E: J** +16 81 | UINT8 dummy0; 82 | UINT8 dummy1; // FF25 00000000: JMP [+6] 83 | UINT8 dummy2; 84 | UINT32 dummy3; 85 | UINT64 address; // Absolute destination address 86 | } JCC_ABS; 87 | 88 | #pragma pack(pop) 89 | 90 | typedef struct _TRAMPOLINE 91 | { 92 | LPVOID pTarget; // [In] Address of the target function. 93 | LPVOID pDetour; // [In] Address of the detour function. 94 | LPVOID pTrampoline; // [In] Buffer address for the trampoline and relay function. 95 | 96 | #if defined(_M_X64) || defined(__x86_64__) 97 | LPVOID pRelay; // [Out] Address of the relay function. 98 | #endif 99 | BOOL patchAbove; // [Out] Should use the hot patch area? 100 | UINT nIP; // [Out] Number of the instruction boundaries. 101 | UINT8 oldIPs[8]; // [Out] Instruction boundaries of the target function. 102 | UINT8 newIPs[8]; // [Out] Instruction boundaries of the trampoline function. 103 | } TRAMPOLINE, *PTRAMPOLINE; 104 | 105 | BOOL CreateTrampolineFunction(PTRAMPOLINE ct); 106 | -------------------------------------------------------------------------------- /thirdparty/OpenRGB/NetworkClient.h: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------*\ 2 | | NetworkClient.h | 3 | | | 4 | | Client header for OpenRGB SDK | 5 | | | 6 | | Adam Honse (CalcProgrammer1) 5/9/2020 | 7 | \*-----------------------------------------*/ 8 | 9 | #include "RGBController.h" 10 | #include "NetworkProtocol.h" 11 | #include "net_port.h" 12 | 13 | #include 14 | #include 15 | 16 | #pragma once 17 | 18 | typedef void (*NetClientCallback)(void *); 19 | 20 | class NetworkClient 21 | { 22 | public: 23 | NetworkClient(std::vector& control); 24 | ~NetworkClient(); 25 | 26 | void ClientInfoChanged(); 27 | 28 | bool GetConnected(); 29 | const char * GetIP(); 30 | unsigned short GetPort(); 31 | unsigned int GetProtocolVersion(); 32 | bool GetOnline(); 33 | 34 | void ClearCallbacks(); 35 | void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg); 36 | 37 | void SetIP(const char *new_ip); 38 | void SetName(const char *new_name); 39 | void SetPort(unsigned short new_port); 40 | 41 | void StartClient(); 42 | void StopClient(); 43 | 44 | void ConnectionThreadFunction(); 45 | void ListenThreadFunction(); 46 | 47 | void WaitOnControllerData(); 48 | 49 | void ProcessReply_ControllerCount(unsigned int data_size, char * data); 50 | void ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx); 51 | void ProcessReply_ProtocolVersion(unsigned int data_size, char * data); 52 | 53 | void ProcessRequest_DeviceListChanged(); 54 | 55 | void SendData_ClientString(); 56 | 57 | void SendRequest_ControllerCount(); 58 | void SendRequest_ControllerData(unsigned int dev_idx); 59 | void SendRequest_ProtocolVersion(); 60 | 61 | void SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size); 62 | 63 | void SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size); 64 | void SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size); 65 | void SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size); 66 | 67 | void SendRequest_RGBController_SetCustomMode(unsigned int dev_idx); 68 | 69 | void SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size); 70 | void SendRequest_RGBController_SaveMode(unsigned int dev_idx, unsigned char * data, unsigned int size); 71 | 72 | 73 | std::vector * ProcessReply_ProfileList(unsigned int data_size, char * data); 74 | 75 | void SendRequest_GetProfileList(); 76 | void SendRequest_LoadProfile(std::string profile_name); 77 | void SendRequest_SaveProfile(std::string profile_name); 78 | void SendRequest_DeleteProfile(std::string profile_name); 79 | 80 | std::vector server_controllers; 81 | 82 | std::mutex ControllerListMutex; 83 | 84 | protected: 85 | std::vector& controllers; 86 | 87 | 88 | private: 89 | SOCKET client_sock; 90 | std::string client_name; 91 | net_port port; 92 | char port_ip[20]; 93 | unsigned short port_num; 94 | bool client_active; 95 | bool controller_data_received; 96 | bool server_connected; 97 | bool server_initialized; 98 | unsigned int server_controller_count; 99 | bool server_controller_count_received; 100 | unsigned int server_protocol_version; 101 | bool server_protocol_version_received; 102 | bool change_in_progress; 103 | std::mutex SendLock; 104 | 105 | std::thread * ConnectionThread; 106 | std::thread * ListenThread; 107 | 108 | std::mutex ClientInfoChangeMutex; 109 | std::vector ClientInfoChangeCallbacks; 110 | std::vector ClientInfoChangeCallbackArgs; 111 | 112 | int recv_select(SOCKET s, char *buf, int len, int flags); 113 | }; 114 | -------------------------------------------------------------------------------- /thirdparty/OpenRGB/NetworkProtocol.cpp: -------------------------------------------------------------------------------- 1 | #include "NetworkProtocol.h" 2 | 3 | NetPacketHeader * InitNetPacketHeader 4 | ( 5 | unsigned int pkt_dev_idx, 6 | unsigned int pkt_id, 7 | unsigned int pkt_size 8 | ) 9 | { 10 | NetPacketHeader * new_header = new NetPacketHeader; 11 | 12 | new_header->pkt_magic[0] = 'O'; 13 | new_header->pkt_magic[1] = 'R'; 14 | new_header->pkt_magic[2] = 'G'; 15 | new_header->pkt_magic[3] = 'B'; 16 | 17 | new_header->pkt_dev_idx = pkt_dev_idx; 18 | new_header->pkt_id = pkt_id; 19 | new_header->pkt_size = pkt_size; 20 | return new_header; 21 | } -------------------------------------------------------------------------------- /thirdparty/OpenRGB/NetworkProtocol.h: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------*\ 2 | | NetworkProtocol.h | 3 | | | 4 | | Protocol header for OpenRGB SDK | 5 | | | 6 | | Adam Honse (CalcProgrammer1) 5/9/2020 | 7 | \*-----------------------------------------*/ 8 | 9 | #pragma once 10 | 11 | /*-----------------------------------------------------*\ 12 | | OpenRGB SDK protocol version | 13 | | | 14 | | 0: Initial (unversioned) protocol | 15 | | 1: Add versioning, vendor string (Release 0.5) | 16 | | 2: Add profile controls (Release 0.6) | 17 | | 3: Add brightness field to modes (Release 0.7) | 18 | \*-----------------------------------------------------*/ 19 | #define OPENRGB_SDK_PROTOCOL_VERSION 3 20 | 21 | /*-----------------------------------------------------*\ 22 | | Default OpenRGB SDK port is 6742 | 23 | | This is "ORGB" on a phone keypad | 24 | \*-----------------------------------------------------*/ 25 | #define OPENRGB_SDK_PORT 6742 26 | 27 | typedef struct NetPacketHeader 28 | { 29 | char pkt_magic[4]; /* Magic value "ORGB" identifies beginning of packet */ 30 | unsigned int pkt_dev_idx; /* Device index */ 31 | unsigned int pkt_id; /* Packet ID */ 32 | unsigned int pkt_size; /* Packet size */ 33 | } NetPacketHeader; 34 | 35 | enum 36 | { 37 | /*----------------------------------------------------------------------------------------------------------*\ 38 | | Network requests | 39 | \*----------------------------------------------------------------------------------------------------------*/ 40 | NET_PACKET_ID_REQUEST_CONTROLLER_COUNT = 0, /* Request RGBController device count from server */ 41 | NET_PACKET_ID_REQUEST_CONTROLLER_DATA = 1, /* Request RGBController data block */ 42 | 43 | NET_PACKET_ID_REQUEST_PROTOCOL_VERSION = 40, /* Request OpenRGB SDK protocol version from server */ 44 | 45 | NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */ 46 | 47 | NET_PACKET_ID_DEVICE_LIST_UPDATED = 100, /* Indicate to clients that device list has updated */ 48 | 49 | NET_PACKET_ID_REQUEST_PROFILE_LIST = 150, /* Request profile list */ 50 | NET_PACKET_ID_REQUEST_SAVE_PROFILE = 151, /* Save current configuration in a new profile */ 51 | NET_PACKET_ID_REQUEST_LOAD_PROFILE = 152, /* Load a given profile */ 52 | NET_PACKET_ID_REQUEST_DELETE_PROFILE = 153, /* Delete a given profile */ 53 | 54 | /*----------------------------------------------------------------------------------------------------------*\ 55 | | RGBController class functions | 56 | \*----------------------------------------------------------------------------------------------------------*/ 57 | NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE = 1000, /* RGBController::ResizeZone() */ 58 | 59 | NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS = 1050, /* RGBController::UpdateLEDs() */ 60 | NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS = 1051, /* RGBController::UpdateZoneLEDs() */ 61 | NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED = 1052, /* RGBController::UpdateSingleLED() */ 62 | 63 | NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE = 1100, /* RGBController::SetCustomMode() */ 64 | NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE = 1101, /* RGBController::UpdateMode() */ 65 | NET_PACKET_ID_RGBCONTROLLER_SAVEMODE = 1102, /* RGBController::SaveMode() */ 66 | }; 67 | -------------------------------------------------------------------------------- /thirdparty/OpenRGB/RGBController/RGBController_Network.cpp: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------*\ 2 | | RGBController_Network.cpp | 3 | | | 4 | | Generic RGB Interface Network Class | 5 | | | 6 | | Adam Honse (CalcProgrammer1) 4/11/2020 | 7 | \*-----------------------------------------*/ 8 | 9 | #include 10 | 11 | #include "RGBController_Network.h" 12 | 13 | RGBController_Network::RGBController_Network(NetworkClient * client_ptr, unsigned int dev_idx_val) 14 | { 15 | client = client_ptr; 16 | dev_idx = dev_idx_val; 17 | } 18 | 19 | void RGBController_Network::SetupZones() 20 | { 21 | //Don't send anything, this function should only process on host 22 | } 23 | 24 | void RGBController_Network::ResizeZone(int zone, int new_size) 25 | { 26 | client->SendRequest_RGBController_ResizeZone(dev_idx, zone, new_size); 27 | } 28 | 29 | void RGBController_Network::DeviceUpdateLEDs() 30 | { 31 | unsigned char * data = GetColorDescription(); 32 | unsigned int size; 33 | 34 | memcpy(&size, &data[0], sizeof(unsigned int)); 35 | 36 | client->SendRequest_RGBController_UpdateLEDs(dev_idx, data, size); 37 | 38 | delete[] data; 39 | } 40 | 41 | void RGBController_Network::UpdateZoneLEDs(int zone) 42 | { 43 | unsigned char * data = GetZoneColorDescription(zone); 44 | unsigned int size; 45 | 46 | memcpy(&size, &data[0], sizeof(unsigned int)); 47 | 48 | client->SendRequest_RGBController_UpdateZoneLEDs(dev_idx, data, size); 49 | 50 | delete[] data; 51 | } 52 | 53 | void RGBController_Network::UpdateSingleLED(int led) 54 | { 55 | unsigned char * data = GetSingleLEDColorDescription(led); 56 | 57 | client->SendRequest_RGBController_UpdateSingleLED(dev_idx, data, sizeof(int) + sizeof(RGBColor)); 58 | 59 | delete[] data; 60 | } 61 | 62 | void RGBController_Network::SetCustomMode() 63 | { 64 | client->SendRequest_RGBController_SetCustomMode(dev_idx); 65 | 66 | client->SendRequest_ControllerData(dev_idx); 67 | client->WaitOnControllerData(); 68 | } 69 | 70 | void RGBController_Network::DeviceUpdateMode() 71 | { 72 | unsigned char * data = GetModeDescription(active_mode, client->GetProtocolVersion()); 73 | unsigned int size; 74 | 75 | memcpy(&size, &data[0], sizeof(unsigned int)); 76 | 77 | client->SendRequest_RGBController_UpdateMode(dev_idx, data, size); 78 | 79 | delete[] data; 80 | } 81 | 82 | void RGBController_Network::DeviceSaveMode() 83 | { 84 | unsigned char * data = GetModeDescription(active_mode, client->GetProtocolVersion()); 85 | unsigned int size; 86 | 87 | memcpy(&size, &data[0], sizeof(unsigned int)); 88 | 89 | client->SendRequest_RGBController_SaveMode(dev_idx, data, size); 90 | 91 | delete[] data; 92 | } 93 | -------------------------------------------------------------------------------- /thirdparty/OpenRGB/RGBController/RGBController_Network.h: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------*\ 2 | | RGBController_Network.h | 3 | | | 4 | | Generic RGB Interface Network Class | 5 | | | 6 | | Adam Honse (CalcProgrammer1) 4/11/2020 | 7 | \*-----------------------------------------*/ 8 | 9 | #pragma once 10 | 11 | #include "RGBController.h" 12 | #include "NetworkClient.h" 13 | 14 | class RGBController_Network : public RGBController 15 | { 16 | public: 17 | RGBController_Network(NetworkClient * client_ptr, unsigned int dev_idx_val); 18 | 19 | void SetupZones(); 20 | 21 | void ResizeZone(int zone, int new_size); 22 | 23 | void DeviceUpdateLEDs(); 24 | void UpdateZoneLEDs(int zone); 25 | void UpdateSingleLED(int led); 26 | 27 | void SetCustomMode(); 28 | void DeviceUpdateMode(); 29 | void DeviceSaveMode(); 30 | 31 | private: 32 | NetworkClient * client; 33 | unsigned int dev_idx; 34 | }; 35 | -------------------------------------------------------------------------------- /thirdparty/OpenRGB/net_port/net_port.cpp: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------*\ 2 | | Cross Platform Network Library for Windows and Linux | 3 | | This library provides access to TCP and UDP ports with | 4 | | a common API for both Windows and Linux systems. It | 5 | | features read and write | 6 | | | 7 | | Adam Honse (calcprogrammer1@gmail.com), 12/15/2016 | 8 | \*---------------------------------------------------------*/ 9 | 10 | #include "net_port.h" 11 | 12 | #ifndef WIN32 13 | #include 14 | #include 15 | #include 16 | #endif 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | const char yes = 1; 23 | 24 | net_port::net_port() 25 | { 26 | 27 | } 28 | 29 | //net_port (constructor) 30 | // When created with port information, the constructor 31 | // will automatically open client address on port 32 | net_port::net_port(const char * client_name, const char * port) 33 | { 34 | udp_client(client_name, port); 35 | } 36 | 37 | net_port::~net_port() 38 | { 39 | freeaddrinfo(result_list); 40 | } 41 | 42 | bool net_port::udp_client(const char * client_name, const char * port) 43 | { 44 | sockaddr_in myAddress; 45 | 46 | #ifdef WIN32 47 | if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) 48 | { 49 | WSACleanup(); 50 | return(false); 51 | } 52 | #endif 53 | 54 | sock = socket(AF_INET, SOCK_DGRAM, 0); 55 | if (sock == INVALID_SOCKET) 56 | { 57 | WSACleanup(); 58 | return(false); 59 | } 60 | 61 | myAddress.sin_family = AF_INET; 62 | myAddress.sin_addr.s_addr = inet_addr("0.0.0.0"); 63 | myAddress.sin_port = htons(0); 64 | 65 | if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR) 66 | { 67 | WSACleanup(); 68 | return false; 69 | } 70 | 71 | result_list = NULL; 72 | addrinfo hints = {}; 73 | hints.ai_family = AF_INET; 74 | hints.ai_socktype = SOCK_DGRAM; 75 | if(getaddrinfo(client_name, port, &hints, &result_list) == 0) 76 | { 77 | memcpy(&addrDest, result_list->ai_addr, result_list->ai_addrlen); 78 | freeaddrinfo(result_list); 79 | return(true); 80 | } 81 | else 82 | { 83 | WSACleanup(); 84 | return(false); 85 | } 86 | } 87 | 88 | int net_port::udp_listen(char * recv_data, int length) 89 | { 90 | return(recvfrom(sock, recv_data, length, 0, NULL, NULL)); 91 | } 92 | 93 | int net_port::udp_write(char * buffer, int length) 94 | { 95 | return(sendto(sock, buffer, length, 0, (sockaddr *)&addrDest, sizeof(addrDest))); 96 | } 97 | 98 | bool net_port::tcp_client(const char * client_name, const char * port) 99 | { 100 | addrinfo hints = {}; 101 | 102 | connected = false; 103 | result_list = NULL; 104 | 105 | #ifdef WIN32 106 | if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) 107 | { 108 | WSACleanup(); 109 | return(false); 110 | } 111 | #endif 112 | 113 | port = strtok((char *)port, "\r"); 114 | 115 | hints.ai_family = AF_INET; 116 | hints.ai_socktype = SOCK_STREAM; 117 | getaddrinfo(client_name, port, &hints, &result_list); 118 | 119 | if(result_list == NULL) 120 | { 121 | WSACleanup(); 122 | return(false); 123 | } 124 | 125 | return(true); 126 | } 127 | 128 | bool net_port::tcp_client_connect() 129 | { 130 | connected = false; 131 | 132 | { 133 | sock = socket(AF_INET, SOCK_STREAM, 0); 134 | if (sock == INVALID_SOCKET) 135 | { 136 | WSACleanup(); 137 | return(false); 138 | } 139 | 140 | u_long arg = 1; 141 | fd_set fdset; 142 | timeval tv; 143 | 144 | ioctlsocket(sock, FIONBIO, &arg); 145 | 146 | if(result_list == NULL) 147 | { 148 | connected = false; 149 | return(false); 150 | } 151 | connect(sock, result_list->ai_addr, result_list->ai_addrlen); 152 | 153 | FD_ZERO(&fdset); 154 | FD_SET(sock, &fdset); 155 | 156 | tv.tv_sec = 4; 157 | tv.tv_usec = 0; 158 | 159 | /*-------------------------------------------------*\ 160 | | Set socket options - no delay | 161 | \*-------------------------------------------------*/ 162 | setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)); 163 | 164 | if (select(sock + 1, NULL, &fdset, NULL, &tv) == 1) 165 | { 166 | char so_error; 167 | socklen_t len = sizeof(so_error); 168 | 169 | getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len); 170 | 171 | if (so_error == 0) 172 | { 173 | connected = true; 174 | arg = 0; 175 | ioctlsocket(sock, FIONBIO, &arg); 176 | } 177 | else 178 | { 179 | connected = false; 180 | closesocket(sock); 181 | } 182 | } 183 | else 184 | { 185 | connected = false; 186 | closesocket(sock); 187 | } 188 | } 189 | return(connected); 190 | } 191 | 192 | bool net_port::tcp_server(const char * port) 193 | { 194 | sockaddr_in myAddress; 195 | 196 | /*-------------------------------------------------*\ 197 | | Windows requires WSAStartup before using sockets | 198 | \*-------------------------------------------------*/ 199 | #ifdef WIN32 200 | if (WSAStartup(MAKEWORD(2, 2), &wsa) != NO_ERROR) 201 | { 202 | WSACleanup(); 203 | return false; 204 | } 205 | #endif 206 | 207 | /*-------------------------------------------------*\ 208 | | Create the server socket | 209 | \*-------------------------------------------------*/ 210 | sock = socket(AF_INET, SOCK_STREAM, 0); 211 | if (sock == INVALID_SOCKET) 212 | { 213 | WSACleanup(); 214 | return false; 215 | } 216 | 217 | /*-------------------------------------------------*\ 218 | | Fill in server address info with port value | 219 | \*-------------------------------------------------*/ 220 | port = strtok((char *)port, "\r"); 221 | 222 | myAddress.sin_family = AF_INET; 223 | myAddress.sin_addr.s_addr = inet_addr("0.0.0.0"); 224 | myAddress.sin_port = htons(atoi(port)); 225 | 226 | /*-------------------------------------------------*\ 227 | | Bind the server socket | 228 | \*-------------------------------------------------*/ 229 | if (bind(sock, (sockaddr*)&myAddress, sizeof(myAddress)) == SOCKET_ERROR) 230 | { 231 | WSACleanup(); 232 | return false; 233 | } 234 | 235 | /*-------------------------------------------------*\ 236 | | Set socket options - no delay | 237 | \*-------------------------------------------------*/ 238 | setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)); 239 | 240 | return(true); 241 | } 242 | 243 | SOCKET * net_port::tcp_server_listen() 244 | { 245 | /*-------------------------------------------------*\ 246 | | Create new socket for client connection | 247 | \*-------------------------------------------------*/ 248 | SOCKET * client = new SOCKET(); 249 | 250 | /*-------------------------------------------------*\ 251 | | Listen for incoming client connection on the | 252 | | server socket. This call blocks until a | 253 | | connection is established | 254 | \*-------------------------------------------------*/ 255 | listen(sock, 10); 256 | 257 | /*-------------------------------------------------*\ 258 | | Accept the client connection | 259 | \*-------------------------------------------------*/ 260 | *client = accept(sock, NULL, NULL); 261 | 262 | /*-------------------------------------------------*\ 263 | | Get the new client socket and store it in the | 264 | | clients vector | 265 | \*-------------------------------------------------*/ 266 | u_long arg = 0; 267 | ioctlsocket(*client, FIONBIO, &arg); 268 | setsockopt(*client, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)); 269 | clients.push_back(client); 270 | 271 | return client; 272 | } 273 | 274 | void net_port::tcp_close() 275 | { 276 | closesocket(sock); 277 | connected = false; 278 | } 279 | 280 | int net_port::tcp_listen(char * recv_data, int length) 281 | { 282 | return(recv(sock, recv_data, length, 0)); 283 | } 284 | 285 | int net_port::tcp_client_write(char * buffer, int length) 286 | { 287 | return(send(sock, buffer, length, 0)); 288 | } 289 | 290 | int net_port::tcp_write(char * buffer, int length) 291 | { 292 | int ret = length; 293 | int val = length; 294 | 295 | timeval waitd; 296 | fd_set writefd; 297 | 298 | for (unsigned int i = 0; i < clients.size(); i++) 299 | { 300 | val = length; 301 | 302 | FD_ZERO(&writefd); 303 | FD_SET(*(clients[i]), &writefd); 304 | 305 | waitd.tv_sec = 5; 306 | waitd.tv_usec = 0; 307 | 308 | if (select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd)) 309 | { 310 | val = send(*(clients[i]), (const char *)&length, sizeof(length), 0); 311 | 312 | if (val == -1) 313 | { 314 | clients.erase(clients.begin() + i); 315 | return 0; 316 | } 317 | } 318 | else 319 | { 320 | clients.erase(clients.begin() + i); 321 | return 0; 322 | } 323 | 324 | waitd.tv_sec = 5; 325 | waitd.tv_usec = 0; 326 | 327 | if (select(*(clients[i]) + 1, NULL, &writefd, NULL, &waitd)) 328 | { 329 | val = send(*(clients[i]), buffer, length, 0); 330 | 331 | if (val == -1) 332 | { 333 | clients.erase(clients.begin() + i); 334 | return 0; 335 | } 336 | 337 | if (val != length) 338 | { 339 | ret = val; 340 | } 341 | } 342 | else 343 | { 344 | clients.erase(clients.begin() + i); 345 | return 0; 346 | } 347 | } 348 | return(ret); 349 | } 350 | -------------------------------------------------------------------------------- /thirdparty/OpenRGB/net_port/net_port.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------*\ 2 | | Cross Platform Network Library for Windows and Linux | 3 | | This library provides access to TCP and UDP ports with | 4 | | a common API for both Windows and Linux systems. It | 5 | | features read and write | 6 | | | 7 | | Adam Honse (calcprogrammer1@gmail.com), 12/15/2016 | 8 | \*---------------------------------------------------------*/ 9 | 10 | #ifndef NET_PORT_H 11 | #define NET_PORT_H 12 | 13 | #include 14 | 15 | #ifdef WIN32 16 | /*---------------------------------------------------------*\ 17 | | Windows interferes with std::max unless NOMINMAX defined | 18 | \*---------------------------------------------------------*/ 19 | #define NOMINMAX 20 | #include 21 | #include 22 | #else 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #endif 32 | 33 | #ifndef WIN32 34 | #define SOCKET int 35 | #define ioctlsocket ioctl 36 | #define closesocket close 37 | #define WSACleanup() 38 | #define INVALID_SOCKET -1 39 | #define SOCKET_ERROR -1 40 | #define SD_RECEIVE SHUT_RD 41 | #endif 42 | 43 | //Network Port Class 44 | //The reason for this class is that network ports are treated differently 45 | //on Windows and Linux. By creating a class, those differences can be 46 | //made invisible to the program and make cross-platform usage easy 47 | 48 | class net_port 49 | { 50 | public: 51 | net_port(); 52 | net_port(const char * client_name, const char * port); 53 | 54 | ~net_port(); 55 | 56 | //Function to open the port 57 | bool udp_client(const char* client_name, const char * port); 58 | bool tcp_client(const char* client_name, const char * port); 59 | bool tcp_client_connect(); 60 | 61 | //Function to open a server 62 | bool tcp_server(const char * port); 63 | std::size_t tcp_server_num_clients(); 64 | SOCKET * tcp_server_get_client(std::size_t client_idx); 65 | SOCKET * tcp_server_listen(); 66 | 67 | int udp_listen(char * recv_data, int length); 68 | int tcp_listen(char * recv_data, int length); 69 | 70 | //Function to write data to the serial port 71 | int udp_write(char * buffer, int length); 72 | int tcp_write(char * buffer, int length); 73 | int tcp_client_write(char * buffer, int length); 74 | 75 | void tcp_close(); 76 | 77 | bool connected; 78 | SOCKET sock; 79 | 80 | private: 81 | #ifdef WIN32 82 | WSADATA wsa; 83 | #endif 84 | 85 | std::vector clients; 86 | 87 | sockaddr addrDest; 88 | addrinfo* result_list; 89 | }; 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /version_wrapper/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #define WIN32_LEAN_AND_MEAN 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | // Function Name : GetFileVersionInfoA 11 | // Ordinal : 1 (0x1) 12 | namespace P { BOOL(WINAPI* GetFileVersionInfoA)(LPCSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData); } 13 | extern "C" BOOL WINAPI GetFileVersionInfoA(LPCSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData) { 14 | return P::GetFileVersionInfoA(lptstrFilename, dwHandle, dwLen, lpData); 15 | } 16 | 17 | 18 | 19 | // Function Name : GetFileVersionInfoByHandle 20 | // Ordinal : 2 (0x2) 21 | namespace P { int(WINAPI* GetFileVersionInfoByHandle)(int hMem, LPCWSTR lpFileName, int v2, int v3); } 22 | extern "C" int WINAPI GetFileVersionInfoByHandle(int hMem, LPCWSTR lpFileName, int v2, int v3) { 23 | return P::GetFileVersionInfoByHandle(hMem, lpFileName, v2, v3); 24 | } 25 | 26 | 27 | // Function Name : GetFileVersionInfoExA 28 | // Ordinal : 3 (0x3) 29 | namespace P { BOOL(WINAPI* GetFileVersionInfoExA)(DWORD dwFlags, LPCSTR lpwstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData); } 30 | extern "C" BOOL WINAPI GetFileVersionInfoExA(DWORD dwFlags, LPCSTR lpwstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData) { 31 | return P::GetFileVersionInfoExA(dwFlags, lpwstrFilename, dwHandle, dwLen, lpData); 32 | } 33 | 34 | 35 | // Function Name : GetFileVersionInfoExW 36 | // Ordinal : 4 (0x4) 37 | namespace P { BOOL(WINAPI* GetFileVersionInfoExW)(DWORD dwFlags, LPCWSTR lpwstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData); } 38 | extern "C" BOOL WINAPI GetFileVersionInfoExW(DWORD dwFlags, LPCWSTR lpwstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData) { 39 | return P::GetFileVersionInfoExW(dwFlags, lpwstrFilename, dwHandle, dwLen, lpData); 40 | } 41 | 42 | 43 | // Function Name : GetFileVersionInfoSizeA 44 | // Ordinal : 5 (0x5) 45 | namespace P { DWORD(WINAPI* GetFileVersionInfoSizeA)(LPCSTR lptstrFilename, LPDWORD lpdwHandle); } 46 | extern "C" DWORD WINAPI GetFileVersionInfoSizeA(LPCSTR lptstrFilename, LPDWORD lpdwHandle) { 47 | return P::GetFileVersionInfoSizeA(lptstrFilename, lpdwHandle); 48 | } 49 | 50 | 51 | // Function Name : GetFileVersionInfoSizeExA 52 | // Ordinal : 6 (0x6) 53 | namespace P { DWORD(WINAPI* GetFileVersionInfoSizeExA)(DWORD dwFlags, LPCSTR lpwstrFilename, LPDWORD lpdwHandle); } 54 | extern "C" DWORD WINAPI GetFileVersionInfoSizeExA(DWORD dwFlags, LPCSTR lpwstrFilename, LPDWORD lpdwHandle) { 55 | return P::GetFileVersionInfoSizeExA(dwFlags, lpwstrFilename, lpdwHandle); 56 | } 57 | 58 | 59 | // Function Name : GetFileVersionInfoSizeExW 60 | // Ordinal : 7 (0x7) 61 | #undef F 62 | #define F GetFileVersionInfoSizeExW 63 | namespace P { DWORD(WINAPI* GetFileVersionInfoSizeExW)(DWORD dwFlags, LPCWSTR lpwstrFilename, LPDWORD lpdwHandle); } 64 | extern "C" DWORD WINAPI GetFileVersionInfoSizeExW(DWORD dwFlags, LPCWSTR lpwstrFilename, LPDWORD lpdwHandle) { 65 | return P::GetFileVersionInfoSizeExW(dwFlags, lpwstrFilename, lpdwHandle); 66 | } 67 | 68 | 69 | // Function Name : GetFileVersionInfoSizeW 70 | // Ordinal : 8 (0x8) 71 | namespace P { DWORD(WINAPI* GetFileVersionInfoSizeW)(LPCWSTR lptstrFilename, LPDWORD lpdwHandle); } 72 | extern "C" DWORD WINAPI GetFileVersionInfoSizeW(LPCWSTR lptstrFilename, LPDWORD lpdwHandle) { 73 | return P::GetFileVersionInfoSizeW(lptstrFilename, lpdwHandle); 74 | } 75 | 76 | 77 | // Function Name : GetFileVersionInfoW 78 | // Ordinal : 9 (0x9) 79 | namespace P { BOOL(WINAPI* GetFileVersionInfoW)(LPCWSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData); } 80 | extern "C" BOOL WINAPI GetFileVersionInfoW(LPCWSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData) { 81 | return P::GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData); 82 | } 83 | 84 | 85 | // Function Name : VerFindFileA 86 | // Ordinal : 10 (0xa) 87 | namespace P { DWORD(WINAPI* VerFindFileA)(DWORD uFlags, LPCSTR szFileName, LPCSTR szWinDir, LPCSTR szAppDir, LPSTR szCurDir, PUINT lpuCurDirLen, LPSTR szDestDir, PUINT lpuDestDirLen); } 88 | extern "C" DWORD WINAPI VerFindFileA(DWORD uFlags, LPCSTR szFileName, LPCSTR szWinDir, LPCSTR szAppDir, LPSTR szCurDir, PUINT lpuCurDirLen, LPSTR szDestDir, PUINT lpuDestDirLen) { 89 | return P::VerFindFileA(uFlags, szFileName, szWinDir, szAppDir, szCurDir, lpuCurDirLen, szDestDir, lpuDestDirLen); 90 | } 91 | 92 | 93 | // Function Name : VerFindFileW 94 | // Ordinal : 11 (0xb) 95 | namespace P { DWORD(WINAPI* VerFindFileW)(DWORD uFlags, LPCWSTR szFileName, LPCWSTR szWinDir, LPCWSTR szAppDir, LPWSTR szCurDir, PUINT lpuCurDirLen, LPWSTR szDestDir, PUINT lpuDestDirLen); } 96 | extern "C" DWORD WINAPI VerFindFileW(DWORD uFlags, LPCWSTR szFileName, LPCWSTR szWinDir, LPCWSTR szAppDir, LPWSTR szCurDir, PUINT lpuCurDirLen, LPWSTR szDestDir, PUINT lpuDestDirLen) { 97 | return P::VerFindFileW(uFlags, szFileName, szWinDir, szAppDir, szCurDir, lpuCurDirLen, szDestDir, lpuDestDirLen); 98 | } 99 | 100 | 101 | // Function Name : VerInstallFileA 102 | // Ordinal : 12 (0xc) 103 | namespace P { DWORD(WINAPI* VerInstallFileA)(DWORD uFlags, LPCSTR szSrcFileName, LPCSTR szDestFileName, LPCSTR szSrcDir, LPCSTR szDestDir, LPCSTR szCurDir, LPSTR szTmpFile, PUINT lpuTmpFileLen); } 104 | extern "C" DWORD WINAPI VerInstallFileA(DWORD uFlags, LPCSTR szSrcFileName, LPCSTR szDestFileName, LPCSTR szSrcDir, LPCSTR szDestDir, LPCSTR szCurDir, LPSTR szTmpFile, PUINT lpuTmpFileLen) { 105 | return P::VerInstallFileA(uFlags, szSrcFileName, szDestFileName, szSrcDir, szDestDir, szCurDir, szTmpFile, lpuTmpFileLen); 106 | } 107 | 108 | 109 | // Function Name : VerInstallFileW 110 | // Ordinal : 13 (0xd) 111 | namespace P { DWORD(WINAPI* VerInstallFileW)(DWORD uFlags, LPCWSTR szSrcFileName, LPCWSTR szDestFileName, LPCWSTR szSrcDir, LPCWSTR szDestDir, LPCWSTR szCurDir, LPWSTR szTmpFile, PUINT lpuTmpFileLen); } 112 | extern "C" DWORD WINAPI VerInstallFileW(DWORD uFlags, LPCWSTR szSrcFileName, LPCWSTR szDestFileName, LPCWSTR szSrcDir, LPCWSTR szDestDir, LPCWSTR szCurDir, LPWSTR szTmpFile, PUINT lpuTmpFileLen) { 113 | return P::VerInstallFileW(uFlags, szSrcFileName, szDestFileName, szSrcDir, szDestDir, szCurDir, szTmpFile, lpuTmpFileLen); 114 | } 115 | 116 | 117 | // Function Name : VerLanguageNameA 118 | // Ordinal : 14 (0xe) 119 | namespace P { DWORD(WINAPI* VerLanguageNameA)(DWORD wLang, LPSTR szLang, DWORD cchLang); } 120 | extern "C" DWORD WINAPI VerLanguageNameA(DWORD wLang, LPSTR szLang, DWORD cchLang) { 121 | return P::VerLanguageNameA(wLang, szLang, cchLang); 122 | } 123 | 124 | 125 | // Function Name : VerLanguageNameW 126 | // Ordinal : 15 (0xf) 127 | namespace P { DWORD(WINAPI* VerLanguageNameW)(DWORD wLang, LPWSTR szLang, DWORD cchLang); } 128 | extern "C" DWORD WINAPI VerLanguageNameW(DWORD wLang, LPWSTR szLang, DWORD cchLang) { 129 | return P::VerLanguageNameW(wLang, szLang, cchLang); 130 | } 131 | 132 | 133 | // Function Name : VerQueryValueA 134 | // Ordinal : 16 (0x10) 135 | namespace P { BOOL(WINAPI* VerQueryValueA)(LPCVOID pBlock, LPCSTR lpSubBlock, LPVOID* lplpBuffer, PUINT puLen); } 136 | extern "C" BOOL WINAPI VerQueryValueA(LPCVOID pBlock, LPCSTR lpSubBlock, LPVOID * lplpBuffer, PUINT puLen) { 137 | return P::VerQueryValueA(pBlock, lpSubBlock, lplpBuffer, puLen); 138 | } 139 | 140 | 141 | // Function Name : VerQueryValueW 142 | // Ordinal : 17 (0x11) 143 | namespace P { BOOL(WINAPI* VerQueryValueW)(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID* lplpBuffer, PUINT puLen); } 144 | extern "C" BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID * lplpBuffer, PUINT puLen) { 145 | return P::VerQueryValueW(pBlock, lpSubBlock, lplpBuffer, puLen); 146 | } 147 | 148 | template 149 | void setup(T*& funcPtr, HMODULE library, const char* funcName) { 150 | if (funcPtr != nullptr) { 151 | return; 152 | } 153 | funcPtr = reinterpret_cast(GetProcAddress(library, funcName)); 154 | } 155 | 156 | #define ASSIGN_PROC(Name, library) \ 157 | setup(P::##Name, library, #Name); 158 | 159 | 160 | DWORD WINAPI CUEHookThread(LPVOID Arg) 161 | { 162 | #ifdef _DEBUG 163 | while (!::IsDebuggerPresent()) 164 | ::Sleep(100); 165 | #endif 166 | 167 | HMODULE winTrustModule = GetModuleHandle(_T("WINTRUST.dll")); 168 | if (winTrustModule) { 169 | FARPROC winVerifyTrust = GetProcAddress(winTrustModule, "WinVerifyTrust"); 170 | if (winVerifyTrust) { 171 | BYTE bypass[] = { 0x31, 0xC0, 0xC3 }; 172 | // xor eax, eax 173 | // ret 174 | 175 | DWORD d, ds; 176 | VirtualProtect((LPVOID)winVerifyTrust, 1, PAGE_EXECUTE_READWRITE, &d); 177 | memcpy((PBYTE)winVerifyTrust, bypass, sizeof(bypass)); 178 | VirtualProtect((LPVOID)winVerifyTrust, 1, d, &ds); 179 | } 180 | } 181 | 182 | return 0; 183 | } 184 | 185 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved) 186 | { 187 | UNREFERENCED_PARAMETER(lpReserved); 188 | 189 | static HMODULE versiondll; 190 | 191 | switch (fdwReason) 192 | { 193 | case DLL_PROCESS_ATTACH: 194 | // Load dll 195 | TCHAR path[MAX_PATH]; 196 | GetSystemDirectory(path, MAX_PATH); 197 | _tcscat_s(path, _T("\\version.dll")); 198 | versiondll = LoadLibrary(path); 199 | 200 | ASSIGN_PROC(GetFileVersionInfoA, versiondll); 201 | ASSIGN_PROC(GetFileVersionInfoByHandle, versiondll) 202 | ASSIGN_PROC(GetFileVersionInfoExA, versiondll) 203 | ASSIGN_PROC(GetFileVersionInfoExW, versiondll) 204 | ASSIGN_PROC(GetFileVersionInfoSizeA, versiondll) 205 | ASSIGN_PROC(GetFileVersionInfoSizeExA, versiondll) 206 | ASSIGN_PROC(GetFileVersionInfoSizeExW, versiondll) 207 | ASSIGN_PROC(GetFileVersionInfoSizeW, versiondll) 208 | ASSIGN_PROC(GetFileVersionInfoW, versiondll) 209 | ASSIGN_PROC(VerFindFileA, versiondll) 210 | ASSIGN_PROC(VerFindFileW, versiondll) 211 | ASSIGN_PROC(VerInstallFileA, versiondll) 212 | ASSIGN_PROC(VerInstallFileW, versiondll) 213 | ASSIGN_PROC(VerLanguageNameA, versiondll) 214 | ASSIGN_PROC(VerLanguageNameW, versiondll) 215 | ASSIGN_PROC(VerQueryValueA, versiondll) 216 | ASSIGN_PROC(VerQueryValueW, versiondll) 217 | 218 | CUEHookThread(nullptr); 219 | //CreateThread(nullptr, 0, CUEHookThread, nullptr, 0, nullptr); 220 | break; 221 | 222 | case DLL_PROCESS_DETACH: 223 | FreeLibrary(versiondll); 224 | break; 225 | } 226 | 227 | return TRUE; 228 | } 229 | -------------------------------------------------------------------------------- /version_wrapper/version.def: -------------------------------------------------------------------------------- 1 | LIBRARY version 2 | EXPORTS 3 | GetFileVersionInfoA 4 | GetFileVersionInfoByHandle 5 | GetFileVersionInfoExA 6 | GetFileVersionInfoExW 7 | GetFileVersionInfoSizeA 8 | GetFileVersionInfoSizeExA 9 | GetFileVersionInfoSizeExW 10 | GetFileVersionInfoSizeW 11 | GetFileVersionInfoW 12 | VerFindFileA 13 | VerFindFileW 14 | VerInstallFileA 15 | VerInstallFileW 16 | VerLanguageNameA 17 | VerLanguageNameW 18 | VerQueryValueA 19 | VerQueryValueW -------------------------------------------------------------------------------- /version_wrapper/version_wrapper.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 | {B6B1125B-DED4-4315-AFA8-B0A0481F1D73} 25 | version_wrapper 26 | 10.0 27 | 28 | 29 | 30 | DynamicLibrary 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | DynamicLibrary 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | DynamicLibrary 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | DynamicLibrary 50 | false 51 | v143 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 | version 76 | 77 | 78 | false 79 | version 80 | 81 | 82 | true 83 | version 84 | 85 | 86 | false 87 | version 88 | 89 | 90 | 91 | Level3 92 | true 93 | WIN32;_DEBUG;WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 94 | true 95 | MultiThreadedDebug 96 | $(ProjectDir)..\thirdparty\MinHook\include;%(AdditionalIncludeDirectories) 97 | 98 | 99 | Windows 100 | true 101 | false 102 | version.def 103 | 104 | 105 | 106 | 107 | Level3 108 | true 109 | true 110 | true 111 | WIN32;NDEBUG;WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 112 | true 113 | MultiThreaded 114 | $(ProjectDir)..\thirdparty\MinHook\include;%(AdditionalIncludeDirectories) 115 | 116 | 117 | Windows 118 | true 119 | true 120 | true 121 | false 122 | version.def 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | _DEBUG;WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 130 | true 131 | MultiThreadedDebug 132 | $(ProjectDir)..\thirdparty\MinHook\include;%(AdditionalIncludeDirectories) 133 | 134 | 135 | Windows 136 | true 137 | false 138 | version.def 139 | 140 | 141 | 142 | 143 | Level3 144 | true 145 | true 146 | true 147 | NDEBUG;WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 148 | true 149 | MultiThreaded 150 | $(ProjectDir)..\thirdparty\MinHook\include;%(AdditionalIncludeDirectories) 151 | 152 | 153 | Windows 154 | true 155 | true 156 | true 157 | false 158 | version.def 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /version_wrapper/version_wrapper.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 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /wrapper/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #define WIN32_LEAN_AND_MEAN 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | typedef HRESULT(WINAPI* DirectSoundCreateProc)(LPCGUID, LPDIRECTSOUND*, LPUNKNOWN); 11 | typedef HRESULT(WINAPI* DirectSoundEnumerateAProc)(LPDSENUMCALLBACKA, LPVOID); 12 | typedef HRESULT(WINAPI* DirectSoundEnumerateWProc)(LPDSENUMCALLBACKW, LPVOID); 13 | typedef HRESULT(WINAPI* DllCanUnloadNowProc)(); 14 | typedef HRESULT(WINAPI* DllGetClassObjectProc)(REFCLSID, REFIID, LPVOID*); 15 | typedef HRESULT(WINAPI* DirectSoundCaptureCreateProc)(LPCGUID, LPDIRECTSOUNDCAPTURE*, LPUNKNOWN); 16 | typedef HRESULT(WINAPI* DirectSoundCaptureEnumerateAProc)(LPDSENUMCALLBACKA, LPVOID); 17 | typedef HRESULT(WINAPI* DirectSoundCaptureEnumerateWProc)(LPDSENUMCALLBACKW, LPVOID); 18 | typedef HRESULT(WINAPI* GetDeviceIDProc)(LPCGUID, LPGUID); 19 | typedef HRESULT(WINAPI* DirectSoundFullDuplexCreateProc)(LPCGUID, LPCGUID, LPCDSCBUFFERDESC, LPCDSBUFFERDESC, HWND, DWORD, LPDIRECTSOUNDFULLDUPLEX*, LPDIRECTSOUNDCAPTUREBUFFER8*, LPDIRECTSOUNDBUFFER8*, LPUNKNOWN); 20 | typedef HRESULT(WINAPI* DirectSoundCreate8Proc)(LPCGUID, LPDIRECTSOUND8*, LPUNKNOWN); 21 | typedef HRESULT(WINAPI* DirectSoundCaptureCreate8Proc)(LPCGUID, LPDIRECTSOUNDCAPTURE8*, LPUNKNOWN); 22 | 23 | DirectSoundCreateProc m_pDirectSoundCreate; 24 | DirectSoundEnumerateAProc m_pDirectSoundEnumerateA; 25 | DirectSoundEnumerateWProc m_pDirectSoundEnumerateW; 26 | DllCanUnloadNowProc m_pDllCanUnloadNow; 27 | DllGetClassObjectProc m_pDllGetClassObject; 28 | DirectSoundCaptureCreateProc m_pDirectSoundCaptureCreate; 29 | DirectSoundCaptureEnumerateAProc m_pDirectSoundCaptureEnumerateA; 30 | DirectSoundCaptureEnumerateWProc m_pDirectSoundCaptureEnumerateW; 31 | GetDeviceIDProc m_pGetDeviceID; 32 | DirectSoundFullDuplexCreateProc m_pDirectSoundFullDuplexCreate; 33 | DirectSoundCreate8Proc m_pDirectSoundCreate8; 34 | DirectSoundCaptureCreate8Proc m_pDirectSoundCaptureCreate8; 35 | 36 | DWORD WINAPI CUEHookThread(LPVOID Arg) 37 | { 38 | #ifdef _DEBUG 39 | while (!::IsDebuggerPresent()) 40 | ::Sleep(100); 41 | #endif 42 | 43 | HMODULE winTrustModule = GetModuleHandle(_T("WINTRUST.dll")); 44 | FARPROC winVerifyTrust = GetProcAddress(winTrustModule, "WinVerifyTrust"); 45 | 46 | BYTE bypass[] = { 0x31, 0xC0, 0xC3 }; 47 | // xor eax, eax 48 | // ret 49 | 50 | DWORD d, ds; 51 | VirtualProtect((LPVOID)winVerifyTrust, 1, PAGE_EXECUTE_READWRITE, &d); 52 | memcpy((PBYTE)winVerifyTrust, bypass, sizeof(bypass)); 53 | VirtualProtect((LPVOID)winVerifyTrust, 1, d, &ds); 54 | 55 | return 0; 56 | } 57 | 58 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved) 59 | { 60 | UNREFERENCED_PARAMETER(lpReserved); 61 | 62 | static HMODULE dsounddll; 63 | 64 | switch (fdwReason) 65 | { 66 | case DLL_PROCESS_ATTACH: 67 | // Load dll 68 | TCHAR path[MAX_PATH]; 69 | GetSystemDirectory(path, MAX_PATH); 70 | _tcscat_s(path, _T("\\dsound.dll")); 71 | dsounddll = LoadLibrary(path); 72 | 73 | // Get function addresses 74 | m_pDirectSoundCreate = (DirectSoundCreateProc)GetProcAddress(dsounddll, "DirectSoundCreate"); 75 | m_pDirectSoundEnumerateA = (DirectSoundEnumerateAProc)GetProcAddress(dsounddll, "DirectSoundEnumerateA"); 76 | m_pDirectSoundEnumerateW = (DirectSoundEnumerateWProc)GetProcAddress(dsounddll, "DirectSoundEnumerateW"); 77 | m_pDllCanUnloadNow = (DllCanUnloadNowProc)GetProcAddress(dsounddll, "DllCanUnloadNow"); 78 | m_pDllGetClassObject = (DllGetClassObjectProc)GetProcAddress(dsounddll, "DllGetClassObject"); 79 | m_pDirectSoundCaptureCreate = (DirectSoundCaptureCreateProc)GetProcAddress(dsounddll, "DirectSoundCaptureCreate"); 80 | m_pDirectSoundCaptureEnumerateA = (DirectSoundCaptureEnumerateAProc)GetProcAddress(dsounddll, "DirectSoundCaptureEnumerateA"); 81 | m_pDirectSoundCaptureEnumerateW = (DirectSoundCaptureEnumerateWProc)GetProcAddress(dsounddll, "DirectSoundCaptureEnumerateW"); 82 | m_pGetDeviceID = (GetDeviceIDProc)GetProcAddress(dsounddll, "GetDeviceID"); 83 | m_pDirectSoundFullDuplexCreate = (DirectSoundFullDuplexCreateProc)GetProcAddress(dsounddll, "DirectSoundFullDuplexCreate"); 84 | m_pDirectSoundCreate8 = (DirectSoundCreate8Proc)GetProcAddress(dsounddll, "DirectSoundCreate8"); 85 | m_pDirectSoundCaptureCreate8 = (DirectSoundCaptureCreate8Proc)GetProcAddress(dsounddll, "DirectSoundCaptureCreate8"); 86 | 87 | CUEHookThread(nullptr); 88 | //CreateThread(nullptr, 0, CUEHookThread, nullptr, 0, nullptr); 89 | break; 90 | 91 | case DLL_PROCESS_DETACH: 92 | FreeLibrary(dsounddll); 93 | break; 94 | } 95 | 96 | return TRUE; 97 | } 98 | 99 | HRESULT WINAPI DirectSoundCreate(LPCGUID pcGuidDevice, LPDIRECTSOUND* ppDS, LPUNKNOWN pUnkOuter) 100 | { 101 | if (!m_pDirectSoundCreate) 102 | { 103 | return E_FAIL; 104 | } 105 | 106 | return m_pDirectSoundCreate(pcGuidDevice, ppDS, pUnkOuter); 107 | } 108 | 109 | HRESULT WINAPI DirectSoundEnumerateA(LPDSENUMCALLBACKA pDSEnumCallback, LPVOID pContext) 110 | { 111 | if (!m_pDirectSoundEnumerateA) 112 | { 113 | return E_FAIL; 114 | } 115 | 116 | return m_pDirectSoundEnumerateA(pDSEnumCallback, pContext); 117 | } 118 | 119 | HRESULT WINAPI DirectSoundEnumerateW(LPDSENUMCALLBACKW pDSEnumCallback, LPVOID pContext) 120 | { 121 | if (!m_pDirectSoundEnumerateW) 122 | { 123 | return E_FAIL; 124 | } 125 | 126 | return m_pDirectSoundEnumerateW(pDSEnumCallback, pContext); 127 | } 128 | 129 | HRESULT WINAPI DllCanUnloadNow() 130 | { 131 | if (!m_pDllCanUnloadNow) 132 | { 133 | return E_FAIL; 134 | } 135 | 136 | return m_pDllCanUnloadNow(); 137 | } 138 | 139 | HRESULT WINAPI DllGetClassObject(IN REFCLSID rclsid, IN REFIID riid, OUT LPVOID FAR* ppv) 140 | { 141 | if (!m_pDllGetClassObject) 142 | { 143 | return E_FAIL; 144 | } 145 | 146 | return m_pDllGetClassObject(rclsid, riid, ppv); 147 | } 148 | 149 | HRESULT WINAPI DirectSoundCaptureCreate(LPCGUID pcGuidDevice, LPDIRECTSOUNDCAPTURE* ppDSC, LPUNKNOWN pUnkOuter) 150 | { 151 | if (!m_pDirectSoundCaptureCreate) 152 | { 153 | return E_FAIL; 154 | } 155 | 156 | return m_pDirectSoundCaptureCreate(pcGuidDevice, ppDSC, pUnkOuter); 157 | } 158 | 159 | HRESULT WINAPI DirectSoundCaptureEnumerateA(LPDSENUMCALLBACKA pDSEnumCallback, LPVOID pContext) 160 | { 161 | if (!m_pDirectSoundCaptureEnumerateA) 162 | { 163 | return E_FAIL; 164 | } 165 | 166 | return m_pDirectSoundCaptureEnumerateA(pDSEnumCallback, pContext); 167 | } 168 | 169 | HRESULT WINAPI DirectSoundCaptureEnumerateW(LPDSENUMCALLBACKW pDSEnumCallback, LPVOID pContext) 170 | { 171 | if (!m_pDirectSoundCaptureEnumerateW) 172 | { 173 | return E_FAIL; 174 | } 175 | 176 | return m_pDirectSoundCaptureEnumerateW(pDSEnumCallback, pContext); 177 | } 178 | 179 | HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest) 180 | { 181 | return m_pGetDeviceID(pGuidSrc, pGuidDest); 182 | } 183 | 184 | HRESULT WINAPI DirectSoundFullDuplexCreate(LPCGUID pcGuidCaptureDevice, LPCGUID pcGuidRenderDevice, LPCDSCBUFFERDESC pcDSCBufferDesc, LPCDSBUFFERDESC pcDSBufferDesc, HWND hWnd, 185 | DWORD dwLevel, LPDIRECTSOUNDFULLDUPLEX* ppDSFD, LPDIRECTSOUNDCAPTUREBUFFER8* ppDSCBuffer8, LPDIRECTSOUNDBUFFER8* ppDSBuffer8, LPUNKNOWN pUnkOuter) 186 | { 187 | if (!m_pDirectSoundFullDuplexCreate) 188 | { 189 | return E_FAIL; 190 | } 191 | 192 | return m_pDirectSoundFullDuplexCreate(pcGuidCaptureDevice, pcGuidRenderDevice, pcDSCBufferDesc, pcDSBufferDesc, hWnd, dwLevel, ppDSFD, ppDSCBuffer8, ppDSBuffer8, pUnkOuter); 193 | } 194 | 195 | HRESULT WINAPI DirectSoundCreate8(LPCGUID pcGuidDevice, LPDIRECTSOUND8* ppDS8, LPUNKNOWN pUnkOuter) 196 | { 197 | if (!m_pDirectSoundCreate8) 198 | { 199 | return E_FAIL; 200 | } 201 | 202 | return m_pDirectSoundCreate8(pcGuidDevice, ppDS8, pUnkOuter); 203 | } 204 | 205 | HRESULT WINAPI DirectSoundCaptureCreate8(LPCGUID pcGuidDevice, LPDIRECTSOUNDCAPTURE8* ppDSC8, LPUNKNOWN pUnkOuter) 206 | { 207 | if (!m_pDirectSoundCaptureCreate8) 208 | { 209 | return E_FAIL; 210 | } 211 | 212 | return m_pDirectSoundCaptureCreate8(pcGuidDevice, ppDSC8, pUnkOuter); 213 | } -------------------------------------------------------------------------------- /wrapper/dsound.def: -------------------------------------------------------------------------------- 1 | LIBRARY dsound 2 | EXPORTS 3 | 4 | DirectSoundCreate @1 5 | DirectSoundEnumerateA @2 6 | DirectSoundEnumerateW @3 7 | DllCanUnloadNow PRIVATE 8 | DllGetClassObject PRIVATE 9 | DirectSoundCaptureCreate @6 10 | DirectSoundCaptureEnumerateA @7 11 | DirectSoundCaptureEnumerateW @8 12 | GetDeviceID @9 13 | DirectSoundFullDuplexCreate @10 14 | DirectSoundCreate8 @11 15 | DirectSoundCaptureCreate8 @12 16 | -------------------------------------------------------------------------------- /wrapper/wrapper.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 | {968a2c9e-c3a5-41df-810f-7770d6106879} 25 | wrapper 26 | 10.0 27 | 28 | 29 | 30 | DynamicLibrary 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | DynamicLibrary 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | DynamicLibrary 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | DynamicLibrary 50 | false 51 | v143 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 | dsound 76 | 77 | 78 | false 79 | dsound 80 | 81 | 82 | true 83 | dsound 84 | 85 | 86 | false 87 | dsound 88 | 89 | 90 | 91 | Level3 92 | true 93 | WIN32;_DEBUG;WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 94 | true 95 | MultiThreadedDebug 96 | $(ProjectDir)..\thirdparty\MinHook\include;%(AdditionalIncludeDirectories) 97 | 98 | 99 | Windows 100 | true 101 | false 102 | dsound.def 103 | 104 | 105 | 106 | 107 | Level3 108 | true 109 | true 110 | true 111 | WIN32;NDEBUG;WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 112 | true 113 | MultiThreaded 114 | $(ProjectDir)..\thirdparty\MinHook\include;%(AdditionalIncludeDirectories) 115 | 116 | 117 | Windows 118 | true 119 | true 120 | true 121 | false 122 | dsound.def 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | _DEBUG;WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 130 | true 131 | MultiThreadedDebug 132 | $(ProjectDir)..\thirdparty\MinHook\include;%(AdditionalIncludeDirectories) 133 | 134 | 135 | Windows 136 | true 137 | false 138 | dsound.def 139 | 140 | 141 | 142 | 143 | Level3 144 | true 145 | true 146 | true 147 | NDEBUG;WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 148 | true 149 | MultiThreaded 150 | $(ProjectDir)..\thirdparty\MinHook\include;%(AdditionalIncludeDirectories) 151 | 152 | 153 | Windows 154 | true 155 | true 156 | true 157 | false 158 | dsound.def 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /wrapper/wrapper.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 | Source Files 20 | 21 | 22 | --------------------------------------------------------------------------------