MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / InstallWinRing0

Function InstallWinRing0

main.cpp:163–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161\******************************************************************************************/
162#ifdef _WIN32
163void InstallWinRing0()
164{
165 TCHAR winring0_install_location[MAX_PATH]; // driver final location usually C:\windows\system32\drivers\WinRing0x64.sys
166 uint system_path_length = GetSystemDirectory(winring0_install_location, MAX_PATH);
167 std::string winring0_filename = "WinRing0.sys";
168 BOOL bIsWow64 = false;
169#if _WIN64
170 winring0_filename = "WinRing0x64.sys";
171#else
172 BOOL (*fnIsWow64Process)(HANDLE, PBOOL) = (BOOL (__cdecl *)(HANDLE, PBOOL))GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
173 if (fnIsWow64Process)
174 {
175 fnIsWow64Process(GetCurrentProcess(),&bIsWow64);
176 }
177 if(bIsWow64)
178 {
179 winring0_filename = "WinRing0x64.sys";
180 }
181#endif
182 std::strncat(winring0_install_location, "\\drivers\\", MAX_PATH - system_path_length - 1);
183 std::strncat(winring0_install_location, winring0_filename.c_str(), MAX_PATH - system_path_length - 10);
184
185 std::string driver_name = winring0_filename.substr(0, winring0_filename.size() - 4); // driver name: WinRing0 or WinRing0x64
186 SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
187 if (manager)
188 {
189 PVOID wow64_fsredirection_OldValue = NULL;
190 if(bIsWow64)
191 {
192 Wow64DisableWow64FsRedirection(&wow64_fsredirection_OldValue);
193 }
194 if(INVALID_FILE_ATTRIBUTES == GetFileAttributes(winring0_install_location) && GetLastError()==ERROR_FILE_NOT_FOUND)
195 {
196 char module_path_buffer[MAX_PATH];
197 GetModuleFileNameA(NULL, module_path_buffer, MAX_PATH);
198 std::string::size_type exe_loc = std::string(module_path_buffer).find_last_of("\\/");
199 std::string driver_source_path = std::string(module_path_buffer).substr(0, exe_loc + 1) + winring0_filename;
200 CopyFile(driver_source_path.c_str(), winring0_install_location, true);
201 }
202 if(bIsWow64)
203 {
204 Wow64RevertWow64FsRedirection(wow64_fsredirection_OldValue);
205 }
206
207 SC_HANDLE service = OpenService(manager, driver_name.c_str(), SERVICE_ALL_ACCESS);
208 if(!service)
209 {
210 std::string service_sys_path = "System32\\Drivers\\" + winring0_filename;
211 service = CreateService(manager,
212 driver_name.c_str(),
213 driver_name.c_str(),
214 SERVICE_ALL_ACCESS,
215 SERVICE_KERNEL_DRIVER,
216 SERVICE_AUTO_START,
217 SERVICE_ERROR_NORMAL,
218 service_sys_path.c_str(),
219 NULL,
220 NULL,

Callers 1

mainFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected