From 47e04a43d217dd79d9001f75fcfe2f1538330593 Mon Sep 17 00:00:00 2001 From: Phyxion <7643972+Phyxion@users.noreply.github.com> Date: Sat, 30 Jun 2018 14:55:30 +0200 Subject: [PATCH] Pr/43 (#44) * Fixed 2 Bugs. 1. Mutex permissions: Global\\Access_ISABUS.HTP.Method, to allow other software access 2. when the driver is not in open the close function is not disposing the mutex * Misc - Misc. --- Hardware/Ring0.cs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Hardware/Ring0.cs b/Hardware/Ring0.cs index caefeb8..cde0068 100644 --- a/Hardware/Ring0.cs +++ b/Hardware/Ring0.cs @@ -15,6 +15,7 @@ using System.Runtime.InteropServices; using System.Security.AccessControl; using System.Threading; using System.Text; +using System.Security.Principal; //SecurityIdentifier namespace OpenHardwareMonitor.Hardware { internal static class Ring0 { @@ -197,8 +198,18 @@ namespace OpenHardwareMonitor.Hardware { string mutexName = "Global\\Access_ISABUS.HTP.Method"; try { +#if NETSTANDARD2_0 isaBusMutex = new Mutex(false, mutexName); - } catch (UnauthorizedAccessException) { +#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); @@ -214,18 +225,15 @@ namespace OpenHardwareMonitor.Hardware { } 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; + 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();