diff --git a/BootMan.csproj b/BootMan.csproj index dde9eda..5d3e328 100644 --- a/BootMan.csproj +++ b/BootMan.csproj @@ -11,6 +11,7 @@ true true None + True diff --git a/Firmware.cs b/Firmware.cs index f5a4e59..16f2d82 100644 --- a/Firmware.cs +++ b/Firmware.cs @@ -13,7 +13,7 @@ public enum FirmwareType FirmwareTypeMax, } - private static readonly string EFI_GLOBAL_VARIABLE = "{8BE4DF61-93CA-11D2-AA0D-00E098032B8C}"; + public static readonly string EFI_GLOBAL_VARIABLE = "{8BE4DF61-93CA-11D2-AA0D-00E098032B8C}"; [DllImport("Kernel32.dll")] private static extern bool GetFirmwareType(out FirmwareType firmwareType); @@ -22,7 +22,7 @@ public enum FirmwareType private static extern uint GetFirmwareEnvironmentVariable( string lpName, string lpGuid, - Span lpBuffer, + byte[] lpBuffer, uint nSize ); @@ -30,13 +30,25 @@ uint nSize private static extern bool SetFirmwareEnvironmentVariable( string lpName, string lpGuid, - Span lpBuffer, + byte[] lpBuffer, uint nSize ); + public static unsafe T GetFirmwareEnvironmentVariable(string name, string guid) where T : unmanaged + { + var buffer = new byte[sizeof(T)]; + uint size = GetFirmwareEnvironmentVariable(name, guid, buffer, (uint)buffer.Length); + if (size == 0) + { + throw new Exception($"GetFirmwareEnvironmentVariable failed with error code {Marshal.GetLastPInvokeError()}"); + } + return MemoryMarshal.Cast(buffer)[0]; + } + public static FirmwareType GetFirmwareType() { - bool success = Firmware.GetFirmwareType(out FirmwareType firmwareType); + // TODO: Do error handling to indicate win32 error + bool success = GetFirmwareType(out FirmwareType firmwareType); return success ? firmwareType : FirmwareType.FirmwareTypeUnknown; } } diff --git a/app.manifest b/app.manifest index f62e771..7bed033 100644 --- a/app.manifest +++ b/app.manifest @@ -2,6 +2,15 @@ + + + + + + + + +