Switched InpOut32 with WinRing0
This commit is contained in:
parent
8b1424a150
commit
cd06401edd
21 changed files with 837 additions and 239 deletions
80
main.cpp
80
main.cpp
|
|
@ -146,6 +146,80 @@ bool AttemptLocalConnection()
|
|||
return success;
|
||||
}
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* Install SMBus Driver WinRing0, If not already installed (Win32) *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
#ifdef _WIN32
|
||||
void InstallWinRing0()
|
||||
{
|
||||
TCHAR winring0_install_location[MAX_PATH]; // driver final location usually C:\windows\system32\drivers\WinRing0x64.sys
|
||||
uint system_path_length = GetSystemDirectory(winring0_install_location, MAX_PATH);
|
||||
std::string winring0_filename = "WinRing0.sys";
|
||||
BOOL bIsWow64 = false;
|
||||
#if _WIN64
|
||||
winring0_filename = "WinRing0x64.sys";
|
||||
#else
|
||||
BOOL (*fnIsWow64Process)(HANDLE, PBOOL) = (BOOL (__cdecl *)(HANDLE, PBOOL))GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
|
||||
if (fnIsWow64Process)
|
||||
{
|
||||
fnIsWow64Process(GetCurrentProcess(),&bIsWow64);
|
||||
}
|
||||
if(bIsWow64)
|
||||
{
|
||||
winring0_filename = "WinRing0x64.sys";
|
||||
}
|
||||
#endif
|
||||
std::strncat(winring0_install_location, "\\drivers\\", MAX_PATH - system_path_length - 1);
|
||||
std::strncat(winring0_install_location, winring0_filename.c_str(), MAX_PATH - system_path_length - 10);
|
||||
|
||||
std::string driver_name = winring0_filename.substr(0, winring0_filename.size() - 4); // driver name: WinRing0 or WinRing0x64
|
||||
SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||
if (manager)
|
||||
{
|
||||
PVOID wow64_fsredirection_OldValue = NULL;
|
||||
if(bIsWow64)
|
||||
{
|
||||
Wow64DisableWow64FsRedirection(&wow64_fsredirection_OldValue);
|
||||
}
|
||||
if(INVALID_FILE_ATTRIBUTES == GetFileAttributes(winring0_install_location) && GetLastError()==ERROR_FILE_NOT_FOUND)
|
||||
{
|
||||
char module_path_buffer[MAX_PATH];
|
||||
GetModuleFileNameA(NULL, module_path_buffer, MAX_PATH);
|
||||
std::string::size_type exe_loc = std::string(module_path_buffer).find_last_of("\\/");
|
||||
std::string driver_source_path = std::string(module_path_buffer).substr(0, exe_loc + 1) + winring0_filename;
|
||||
CopyFile(driver_source_path.c_str(), winring0_install_location, true);
|
||||
}
|
||||
if(bIsWow64)
|
||||
{
|
||||
Wow64RevertWow64FsRedirection(wow64_fsredirection_OldValue);
|
||||
}
|
||||
|
||||
SC_HANDLE service = OpenService(manager, driver_name.c_str(), SERVICE_ALL_ACCESS);
|
||||
if(!service)
|
||||
{
|
||||
std::string service_sys_path = "System32\\Drivers\\" + winring0_filename;
|
||||
service = CreateService(manager,
|
||||
driver_name.c_str(),
|
||||
driver_name.c_str(),
|
||||
SERVICE_ALL_ACCESS,
|
||||
SERVICE_KERNEL_DRIVER,
|
||||
SERVICE_AUTO_START,
|
||||
SERVICE_ERROR_NORMAL,
|
||||
service_sys_path.c_str(),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
CloseServiceHandle(service);
|
||||
CloseServiceHandle(manager);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* main *
|
||||
|
|
@ -177,8 +251,12 @@ int main(int argc, char* argv[])
|
|||
std::thread * InitializeTimerResolutionThread;
|
||||
InitializeTimerResolutionThread = new std::thread(InitializeTimerResolutionThreadFunction);
|
||||
InitializeTimerResolutionThread->detach();
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Windows only - Install SMBus Driver WinRing0 |
|
||||
\*---------------------------------------------------------*/
|
||||
InstallWinRing0();
|
||||
#endif
|
||||
/*---------------------------------------------------------*\
|
||||
| Process command line arguments before detection |
|
||||
\*---------------------------------------------------------*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue