public static void Close() { if (driver != null) { uint refCount = 0; driver.DeviceIOControl(IOCTL_OLS_GET_REFCOUNT, null, ref refCount); driver.Close(); if (refCount <= 1) { driver.Delete(); } driver = null; } if (isaBusMutex != null) { isaBusMutex.Close(); isaBusMutex = null; } // try to delete temporary driver file again if failed during open if (fileName != null && File.Exists(fileName)) { try { File.Delete(fileName); fileName = null; } catch (IOException) { } catch (UnauthorizedAccessException) { } } }
public static void Close() { if (driver != null) { driver.Close(); driver = null; } if (isaBusMutex != null) { isaBusMutex.Close(); isaBusMutex = null; } }
public static void UninstallKernelDriver() { InitializeKernelDriver(); if (driver != null) { try { if (driver.IsOpen) { driver.Close(); } driver.Delete(); driver = null; } catch { report.AppendLine("Status: Uninstalling driver failed"); } } }
public static void Close() { if (driver == null) { return; } uint refCount = 0; driver.DeviceIOControl(IOCTL_OLS_GET_REFCOUNT, null, ref refCount); driver.Close(); if (refCount <= 1) { driver.Delete(); } driver = null; isaBusMutex.Close(); }
public static void Open() { // no implementation for unix systems if (OperatingSystem.IsUnix) { return; } if (driver != null) { return; } // clear the current report report.Length = 0; driver = new KernelDriver("WinRing0_1_2_0"); driver.Open(); if (!driver.IsOpen) { // driver is not loaded, try to install and open fileName = GetTempFileName(); if (fileName != null && ExtractDriver(fileName)) { string installError; if (driver.Install(fileName, out installError)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine("Status: Opening driver failed after install"); } } else { string errorFirstInstall = installError; // install failed, try to delete and reinstall driver.Delete(); // wait a short moment to give the OS a chance to remove the driver Thread.Sleep(2000); string errorSecondInstall; if (driver.Install(fileName, out errorSecondInstall)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine( "Status: Opening driver failed after reinstall"); } } else { report.AppendLine("Status: Installing driver \"" + fileName + "\" failed" + (File.Exists(fileName) ? " and file exists" : "")); report.AppendLine("First Exception: " + errorFirstInstall); report.AppendLine("Second Exception: " + errorSecondInstall); } } } else { report.AppendLine("Status: Extracting driver failed"); } try { // try to delte the driver file if (File.Exists(fileName)) { File.Delete(fileName); } fileName = null; } catch (IOException) { } catch (UnauthorizedAccessException) { } } if (!driver.IsOpen) { driver = null; } string isaMutexName = "Global\\Access_ISABUS.HTP.Method"; try { isaBusMutex = new Mutex(false, isaMutexName); } catch (UnauthorizedAccessException) { try { isaBusMutex = Mutex.OpenExisting(isaMutexName, MutexRights.Synchronize); } catch { } } string pciMutexName = "Global\\Access_PCI"; try { pciBusMutex = new Mutex(false, pciMutexName); } catch (UnauthorizedAccessException) { try { pciBusMutex = Mutex.OpenExisting(pciMutexName, MutexRights.Synchronize); } catch { } } }
private static void InitializeKernelDriver() { driver = new KernelDriver(KernelDriverId); driver.Open(); }
public static void Open() { System.PlatformID p = Environment.OSVersion.Platform; // try loading shipped kernel drivers on Unix // (will probably only work on Linux through) if (p == PlatformID.Unix) { // try loading the `msr` kernel module on Linux (required on ost kernels) Process modprobe = new Process(); try { modprobe.StartInfo.FileName = "modprobe"; modprobe.StartInfo.Arguments = "msr"; modprobe.Start(); modprobe.WaitForExit(); } catch (Exception e) { report.AppendLine(string.Format("Failed to load `msr` kernel driver: {0}", e.Message)); } return; } // following code is Windows NT only if ((p != PlatformID.Win32NT) && (p != PlatformID.WinCE)) { return; } if (driver != null) { return; } // clear the current report report.Length = 0; InitializeKernelDriver(); if (!driver.IsOpen) { // driver is not loaded, try to install and open InstallKernelDriverCore( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); } if (!driver.IsOpen) { driver = null; } string mutexName = "Global\\Access_ISABUS.HTP.Method"; try { isaBusMutex = new Mutex(false, mutexName); } catch (UnauthorizedAccessException) { try { isaBusMutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize); } catch { } } }
public static void Open() { // no implementation for unix systems if (Software.OperatingSystem.IsLinux) { return; } if (driver != null) { return; } // clear the current report report.Length = 0; driver = new KernelDriver("WinRing0_1_2_0"); driver.Open(); if (!driver.IsOpen) { // driver is not loaded, try to install and open fileName = GetTempFileName(); if (fileName != null && ExtractDriver(fileName)) { string installError; if (driver.Install(fileName, out installError)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine("Status: Opening driver failed after install"); } } else { string errorFirstInstall = installError; // install failed, try to delete and reinstall driver.Delete(); // wait a short moment to give the OS a chance to remove the driver Thread.Sleep(2000); string errorSecondInstall; if (driver.Install(fileName, out errorSecondInstall)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine( "Status: Opening driver failed after reinstall"); } } else { report.AppendLine("Status: Installing driver \"" + fileName + "\" failed" + (File.Exists(fileName) ? " and file exists" : "")); report.AppendLine("First Exception: " + errorFirstInstall); report.AppendLine("Second Exception: " + errorSecondInstall); } } } else { report.AppendLine("Status: Extracting driver failed"); } try { // try to delte the driver file if (File.Exists(fileName)) { File.Delete(fileName); } fileName = null; } catch (IOException) { } catch (UnauthorizedAccessException) { } } if (!driver.IsOpen) { driver = null; } string mutexName = "Global\\Access_ISABUS.HTP.Method"; try { #if NETSTANDARD2_0 isaBusMutex = new Mutex(false, mutexName); #else //mutex permissions set to everyone to allow other software to access the hardware //otherwise other monitoring software cant access var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow); var securitySettings = new MutexSecurity(); securitySettings.AddAccessRule(allowEveryoneRule); isaBusMutex = new Mutex(false, mutexName, out _, securitySettings); #endif } catch (UnauthorizedAccessException) { try { #if NETSTANDARD2_0 isaBusMutex = Mutex.OpenExisting(mutexName); #else isaBusMutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize); #endif } catch { } } }
public static void Open() { // no implementation for unix systems int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { return; } if (driver != null) { return; } // clear the current report report.Length = 0; driver = new KernelDriver("WinRing0_1_2_0"); driver.Open(); if (!driver.IsOpen) { // driver is not loaded, try to reinstall and open driver.Delete(); fileName = GetTempFileName(); if (fileName != null && ExtractDriver(fileName)) { if (driver.Install(fileName)) { driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine("Status: Opening driver failed"); } } else { report.AppendLine("Status: Installing driver \"" + fileName + "\" failed" + (File.Exists(fileName) ? " and file exists" : "")); report.AppendLine(); report.Append("Exception: " + Marshal.GetExceptionForHR( Marshal.GetHRForLastWin32Error()).Message); } } else { report.AppendLine("Status: Extracting driver failed"); } try { // try to delte the driver file if (File.Exists(fileName)) { File.Delete(fileName); } fileName = null; } catch (IOException) { } catch (UnauthorizedAccessException) { } } if (!driver.IsOpen) { driver = null; } string mutexName = "Global\\Access_ISABUS.HTP.Method"; try { isaBusMutex = new Mutex(false, mutexName); } catch (UnauthorizedAccessException) { try { isaBusMutex = Mutex.OpenExisting(mutexName, MutexRights.Synchronize); } catch { } } }
public static void Open() { // no implementation for unix systems int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { return; } if (driver != null) { return; } // clear the current report report.Length = 0; driver = new KernelDriver("WinRing0_1_2_0"); driver.Open(); if (!driver.IsOpen) { // driver is not loaded, try to reinstall and open driver.Delete(); string fileName = Path.GetTempFileName(); if (ExtractDriver(fileName)) { if (driver.Install(fileName)) { File.Delete(fileName); driver.Open(); if (!driver.IsOpen) { driver.Delete(); report.AppendLine("Status: Opening driver failed"); } } else { report.AppendLine("Status: Installing driver \"" + fileName + "\" failed" + (File.Exists(fileName) ? " and file exists" : "")); report.AppendLine(); report.Append("Exception: " + Marshal.GetExceptionForHR( Marshal.GetHRForLastWin32Error()).Message); } } else { report.AppendLine( "Status: Extracting driver to \"" + fileName + "\" failed"); } } if (!driver.IsOpen) { driver = null; } isaBusMutex = new Mutex(false, "Global\\Access_ISABUS.HTP.Method"); }