Implemented BcdHelper
Updated README
This commit is contained in:
		@@ -79,6 +79,9 @@
 | 
			
		||||
    <Reference Include="PInvoke.Windows.Core, Version=0.5.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
 | 
			
		||||
      <HintPath>..\packages\PInvoke.Windows.Core.0.5.155\lib\net35\PInvoke.Windows.Core.dll</HintPath>
 | 
			
		||||
    </Reference>
 | 
			
		||||
    <Reference Include="RunProcessAsTask, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL">
 | 
			
		||||
      <HintPath>..\packages\RunProcessAsTask.1.2.3\lib\net45\RunProcessAsTask.dll</HintPath>
 | 
			
		||||
    </Reference>
 | 
			
		||||
    <Reference Include="SimpleMapi, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
 | 
			
		||||
      <HintPath>..\packages\Simple-MAPI.NET.1.1.0\lib\net20\SimpleMapi.dll</HintPath>
 | 
			
		||||
    </Reference>
 | 
			
		||||
@@ -111,12 +114,14 @@
 | 
			
		||||
      <Generator>MSBuild:Compile</Generator>
 | 
			
		||||
      <SubType>Designer</SubType>
 | 
			
		||||
    </ApplicationDefinition>
 | 
			
		||||
    <Compile Include="Exceptions\BcdAlterAllowPrereleaseSignaturesFailedException.cs" />
 | 
			
		||||
    <Compile Include="Exceptions\NtQuerySystemInformationException.cs" />
 | 
			
		||||
    <Compile Include="Properties\Resources.Designer.cs">
 | 
			
		||||
      <AutoGen>True</AutoGen>
 | 
			
		||||
      <DesignTime>True</DesignTime>
 | 
			
		||||
      <DependentUpon>Resources.resx</DependentUpon>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="Util\BcdHelper.cs" />
 | 
			
		||||
    <Compile Include="Util\CodeIntegrityHelper.cs" />
 | 
			
		||||
    <Compile Include="Util\OsUpgradeDetection.cs" />
 | 
			
		||||
    <Compile Include="Util\OSVersionInfo.cs" />
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Runtime.Serialization;
 | 
			
		||||
 | 
			
		||||
namespace DerpingDrivers.Exceptions
 | 
			
		||||
{
 | 
			
		||||
    public class BcdAlterAllowPrereleaseSignaturesFailedException : Exception
 | 
			
		||||
    {
 | 
			
		||||
        public BcdAlterAllowPrereleaseSignaturesFailedException()
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public BcdAlterAllowPrereleaseSignaturesFailedException(string message) : base(message)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public BcdAlterAllowPrereleaseSignaturesFailedException(string message, Exception innerException) : base(message, innerException)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected BcdAlterAllowPrereleaseSignaturesFailedException(SerializationInfo info, StreamingContext context) : base(info, context)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -69,6 +69,8 @@ namespace DerpingDrivers
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                var t = BcdHelper.IsTestSignEnabled;
 | 
			
		||||
 | 
			
		||||
                #region TESTSIGNING mode
 | 
			
		||||
 | 
			
		||||
                if (CodeIntegrityHelper.IsTestSignEnabled)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										47
									
								
								DerpingDrivers/Util/BcdHelper.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								DerpingDrivers/Util/BcdHelper.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
			
		||||
using DerpingDrivers.Exceptions;
 | 
			
		||||
using Microsoft.Win32;
 | 
			
		||||
using RunProcessAsTask;
 | 
			
		||||
 | 
			
		||||
namespace DerpingDrivers.Util
 | 
			
		||||
{
 | 
			
		||||
    public static class BcdHelper
 | 
			
		||||
    {
 | 
			
		||||
        public static bool IsTestSignEnabled
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                var bootmgrDefaultGuid = (string) Registry.GetValue(
 | 
			
		||||
                    @"HKEY_LOCAL_MACHINE\BCD00000000\Objects\{9DEA862C-5CDD-4E70-ACC1-F32B344D4795}\Elements\23000003",
 | 
			
		||||
                    "Element", null);
 | 
			
		||||
 | 
			
		||||
                var allowPrereleaseSignatures = (byte[]) Registry.GetValue(
 | 
			
		||||
                    $@"HKEY_LOCAL_MACHINE\BCD00000000\Objects\{bootmgrDefaultGuid}\Elements\16000049",
 | 
			
		||||
                    "Element", default(byte[]));
 | 
			
		||||
 | 
			
		||||
                return allowPrereleaseSignatures != null && bool.Parse(allowPrereleaseSignatures[0].ToString());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void EnableTestSigning()
 | 
			
		||||
        {
 | 
			
		||||
            // NOTE: haven't found an API for this (yet), so system() we go!
 | 
			
		||||
            var ret = ProcessEx.RunAsync("Bcdedit.exe", "-set TESTSIGNING ON").Result;
 | 
			
		||||
 | 
			
		||||
            if (ret.ExitCode != 0)
 | 
			
		||||
            {
 | 
			
		||||
                throw new BcdAlterAllowPrereleaseSignaturesFailedException("Couldn't enable TESTSIGNING");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void DisableTestSigning()
 | 
			
		||||
        {
 | 
			
		||||
            // NOTE: haven't found an API for this (yet), so system() we go!
 | 
			
		||||
            var ret = ProcessEx.RunAsync("Bcdedit.exe", "-set TESTSIGNING OFF").Result;
 | 
			
		||||
 | 
			
		||||
            if (ret.ExitCode != 0)
 | 
			
		||||
            {
 | 
			
		||||
                throw new BcdAlterAllowPrereleaseSignaturesFailedException("Couldn't disable TESTSIGNING");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -12,5 +12,6 @@
 | 
			
		||||
  <package id="Markdig.Wpf" version="0.2.5" targetFramework="net461" />
 | 
			
		||||
  <package id="PInvoke.Kernel32" version="0.5.155" targetFramework="net461" />
 | 
			
		||||
  <package id="PInvoke.Windows.Core" version="0.5.155" targetFramework="net461" />
 | 
			
		||||
  <package id="RunProcessAsTask" version="1.2.3" targetFramework="net461" />
 | 
			
		||||
  <package id="Simple-MAPI.NET" version="1.1.0" targetFramework="net461" />
 | 
			
		||||
</packages>
 | 
			
		||||
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							@@ -4,9 +4,13 @@
 | 
			
		||||
 | 
			
		||||
- Icon by [Rebin Infotech](https://www.iconfinder.com/rebininfotech)
 | 
			
		||||
- [Getting Operating System Version Info - Even for Windows 10!](https://www.codeproject.com/Articles/73000/Getting-Operating-System-Version-Info-Even-for-Win)
 | 
			
		||||
- [How do I tell if Windows 10 was a fresh install or upgrade from 7/8?](https://superuser.com/questions/1032064/how-do-i-tell-if-windows-10-was-a-fresh-install-or-upgrade-from-7-8/1184670#1184670)
 | 
			
		||||
- [NtQuerySystemInformation](https://docs.microsoft.com/de-de/windows/desktop/api/winternl/nf-winternl-ntquerysysteminformation)
 | 
			
		||||
- [Can I have any way to detect the Driver Signing Policy status?](https://stackoverflow.com/questions/40084077/can-i-have-any-way-to-detect-the-driver-signing-policy-status/51230137#51230137)
 | 
			
		||||
- [The TESTSIGNING Boot Configuration Option](https://docs.microsoft.com/en-us/windows-hardware/drivers/install/the-testsigning-boot-configuration-option)
 | 
			
		||||
- [Windows Version Numbers](http://techthoughts.info/windows-version-numbers/)
 | 
			
		||||
- [Is there an easy way to check the .NET Framework version?](https://stackoverflow.com/questions/951856/is-there-an-easy-way-to-check-the-net-framework-version)
 | 
			
		||||
- [Super user: How do I tell if Windows 10 was a fresh install or upgrade from 7/8?](https://superuser.com/questions/1032064/how-do-i-tell-if-windows-10-was-a-fresh-install-or-upgrade-from-7-8/1184670#1184670)
 | 
			
		||||
- [Stack Overflow: Is there an easy way to check the .NET Framework version?](https://stackoverflow.com/questions/951856/is-there-an-easy-way-to-check-the-net-framework-version)
 | 
			
		||||
- [Stack Overflow: Can I have any way to detect the Driver Signing Policy status?](https://stackoverflow.com/questions/40084077/can-i-have-any-way-to-detect-the-driver-signing-policy-status/51230137#51230137)
 | 
			
		||||
- [BCDEdit: Mounting the BCD Store as a Registry Hive](http://www.mistyprojects.co.uk/documents/BCDEdit/files/bcd_as_registry_hive.htm)
 | 
			
		||||
- [BCDEdit: Objects and Elements](http://www.mistyprojects.co.uk/documents/BCDEdit/files/object_element_codes.htm)
 | 
			
		||||
- [Geoff Chappell: BCD Elements](https://www.geoffchappell.com/notes/windows/boot/bcd/elements.htm)
 | 
			
		||||
- [Geoff Chappell: Back Doors for Cross-Signed Drivers](https://www.geoffchappell.com/notes/security/whqlsettings/index.htm)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user