Added more report output to the kernel driver loading code. Hopefully this helps to find the problems in Issue 253.
authormoel.mich
Wed, 18 Jul 2012 20:20:26 +0000
changeset 36745215572a774
parent 366 667c75cad937
child 368 1036b453f1f6
Added more report output to the kernel driver loading code. Hopefully this helps to find the problems in Issue 253.
Hardware/KernelDriver.cs
Hardware/Ring0.cs
Properties/AssemblyVersion.cs
     1.1 --- a/Hardware/KernelDriver.cs	Wed Jul 18 19:45:59 2012 +0000
     1.2 +++ b/Hardware/KernelDriver.cs	Wed Jul 18 20:20:26 2012 +0000
     1.3 @@ -4,7 +4,7 @@
     1.4    License, v. 2.0. If a copy of the MPL was not distributed with this
     1.5    file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.6   
     1.7 -  Copyright (C) 2010 Michael Möller <mmoeller@openhardwaremonitor.org>
     1.8 +  Copyright (C) 2010-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
     1.9  	
    1.10  */
    1.11  
    1.12 @@ -25,12 +25,14 @@
    1.13        this.id = id;
    1.14      }
    1.15     
    1.16 -    public bool Install(string path) {
    1.17 +    public bool Install(string path, out string errorMessage) {
    1.18        IntPtr manager = NativeMethods.OpenSCManager(null, null,
    1.19          ServiceControlManagerAccessRights.SC_MANAGER_ALL_ACCESS);
    1.20  
    1.21 -      if (manager == IntPtr.Zero)
    1.22 +      if (manager == IntPtr.Zero) {
    1.23 +        errorMessage = "OpenSCManager returned zero.";
    1.24          return false;
    1.25 +      }
    1.26  
    1.27        IntPtr service = NativeMethods.CreateService(manager, id, id,
    1.28          ServiceAccessRights.SERVICE_ALL_ACCESS,
    1.29 @@ -42,13 +44,22 @@
    1.30          if (Marshal.GetHRForLastWin32Error() == ERROR_SERVICE_EXISTS)
    1.31            service = NativeMethods.OpenService(manager, id,
    1.32              ServiceAccessRights.SERVICE_ALL_ACCESS);
    1.33 -        else
    1.34 +        else {
    1.35 +          errorMessage = "CreateService returned the error: " +
    1.36 +            Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()).Message;
    1.37 +          NativeMethods.CloseServiceHandle(manager);    
    1.38            return false;
    1.39 +        }
    1.40        }
    1.41  
    1.42        if (!NativeMethods.StartService(service, 0, null)) {
    1.43 -        if (Marshal.GetHRForLastWin32Error() != ERROR_SERVICE_ALREADY_RUNNING)
    1.44 +        if (Marshal.GetHRForLastWin32Error() != ERROR_SERVICE_ALREADY_RUNNING) {
    1.45 +          errorMessage = "StartService returned the error: " +
    1.46 +            Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()).Message;
    1.47 +          NativeMethods.CloseServiceHandle(service);
    1.48 +          NativeMethods.CloseServiceHandle(manager);
    1.49            return false;
    1.50 +        }
    1.51        }
    1.52  
    1.53        NativeMethods.CloseServiceHandle(service);
    1.54 @@ -62,7 +73,8 @@
    1.55            "O:BAG:SYD:(A;;FA;;;SY)(A;;FA;;;BA)");
    1.56          File.SetAccessControl(@"\\.\" + id, fileSecurity);
    1.57        } catch { }
    1.58 -      
    1.59 +
    1.60 +      errorMessage = null;
    1.61        return true;
    1.62      }
    1.63  
     2.1 --- a/Hardware/Ring0.cs	Wed Jul 18 19:45:59 2012 +0000
     2.2 +++ b/Hardware/Ring0.cs	Wed Jul 18 20:20:26 2012 +0000
     2.3 @@ -127,7 +127,8 @@
     2.4  
     2.5          fileName = GetTempFileName();
     2.6          if (fileName != null && ExtractDriver(fileName)) {
     2.7 -          if (driver.Install(fileName)) {
     2.8 +          string installError;
     2.9 +          if (driver.Install(fileName, out installError)) {
    2.10              driver.Open();
    2.11  
    2.12              if (!driver.IsOpen) {
    2.13 @@ -135,10 +136,13 @@
    2.14                report.AppendLine("Status: Opening driver failed after install");
    2.15              }
    2.16            } else {
    2.17 +            string errorFirstInstall = installError;
    2.18 +   
    2.19              // install failed, try to delete and reinstall
    2.20              driver.Delete();
    2.21  
    2.22 -            if (driver.Install(fileName)) {
    2.23 +            string errorSecondInstall;
    2.24 +            if (driver.Install(fileName, out errorSecondInstall)) {
    2.25                driver.Open();
    2.26  
    2.27                if (!driver.IsOpen) {
    2.28 @@ -150,9 +154,8 @@
    2.29                report.AppendLine("Status: Installing driver \"" +
    2.30                  fileName + "\" failed" +
    2.31                  (File.Exists(fileName) ? " and file exists" : ""));
    2.32 -              report.AppendLine();
    2.33 -              report.Append("Exception: " + Marshal.GetExceptionForHR(
    2.34 -                Marshal.GetHRForLastWin32Error()).Message);
    2.35 +              report.AppendLine("First Exception: " + errorFirstInstall);
    2.36 +              report.AppendLine("Second Exception: " + errorSecondInstall);
    2.37              }
    2.38            }
    2.39          } else {
     3.1 --- a/Properties/AssemblyVersion.cs	Wed Jul 18 19:45:59 2012 +0000
     3.2 +++ b/Properties/AssemblyVersion.cs	Wed Jul 18 20:20:26 2012 +0000
     3.3 @@ -10,5 +10,5 @@
     3.4  
     3.5  using System.Reflection;
     3.6  
     3.7 -[assembly: AssemblyVersion("0.4.0.18")]
     3.8 -[assembly: AssemblyInformationalVersion("0.4.0.18 Alpha")]
     3.9 \ No newline at end of file
    3.10 +[assembly: AssemblyVersion("0.4.0.19")]
    3.11 +[assembly: AssemblyInformationalVersion("0.4.0.19 Alpha")]
    3.12 \ No newline at end of file