Skip to content

Instantly share code, notes, and snippets.

@newyear2006
Created September 22, 2018 16:23
Show Gist options
  • Select an option

  • Save newyear2006/bfb6e4adc16182dc9ca16e37d34ac0e7 to your computer and use it in GitHub Desktop.

Select an option

Save newyear2006/bfb6e4adc16182dc9ca16e37d34ac0e7 to your computer and use it in GitHub Desktop.

Revisions

  1. newyear2006 created this gist Sep 22, 2018.
    74 changes: 74 additions & 0 deletions Confirm-SecureBootUEFI.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading.Tasks;

    namespace UEFIFirmwareVariablenAbfragen
    {
    class Program
    {
    internal struct UNICODE_STRING
    {
    private const int SIZEOF_WCHAR = 2;
    private ushort Length;
    private ushort MaximumLength;
    private string Buffer;

    public UNICODE_STRING(string sourceString)
    {
    this.Buffer = sourceString;
    this.Length = (ushort)(this.Buffer.Length * 2);
    this.MaximumLength = (ushort)(this.Length + 2);
    }
    }

    [DllImport("ntdll.dll", CharSet = CharSet.Unicode, ExactSpelling = false, SetLastError = true)]
    internal static extern uint NtQuerySystemEnvironmentValueEx(ref UNICODE_STRING VariableName, byte[] VendorGuid, byte[] Value, ref uint ValueLength, out uint Attributes);

    static void Main(string[] args)
    {
    var EFI_GLOBAL_VARIABLE = new Guid("{8BE4DF61-93CA-11D2-AA0D-00E098032B8C}");
    uint num = 0;
    byte[] numArray = new byte[1];
    byte[] numArray1 = new byte[] { 1 };
    UNICODE_STRING uNICODESTRING = new UNICODE_STRING("SecureBoot");
    uint num1 = 1;
    uint num2 = 7;
    num = NtQuerySystemEnvironmentValueEx(ref uNICODESTRING, EFI_GLOBAL_VARIABLE.ToByteArray(), numArray, ref num1, out num2);
    if (num != 0)
    {
    Console.WriteLine("leider nix");
    }
    uNICODESTRING = new UNICODE_STRING("SetupMode");
    num = NtQuerySystemEnvironmentValueEx(ref uNICODESTRING, EFI_GLOBAL_VARIABLE.ToByteArray(), numArray1, ref num1, out num2);
    if (num != 0)
    {
    Console.WriteLine("leider nix 2"); ;
    }
    if (numArray[0] == 1 && numArray1[0] == 1)
    {
    Console.WriteLine("SECURE!") ;
    }

    //// 0x8BE4DF61, 0x000093CA bzw. 0xFFFF93CA, 0x000011D2
    //var EFI_GLOBAL_VARIABLE = new Guid("{8BE4DF61-93CA-11D2-AA0D-00E098032B8C}"); // new Guid(-1947934879, 37834, 4562, 170, 13, 0, 224, 152, 3, 43, 140);
    //uint num = 0;
    //uint num1 = 0;
    //uint num2 = 0;

    //var uNICODESTRING = new UNICODE_STRING("SecureBoot");

    //num1 = NtQuerySystemEnvironmentValueEx(ref uNICODESTRING, EFI_GLOBAL_VARIABLE.ToByteArray(), null, ref num, out num2);
    ////if (num1 != -1073741789)
    ////{
    //// //throw Exception;
    ////}

    //byte[] numArray = new byte[num];
    //num1 = NtQuerySystemEnvironmentValueEx(ref uNICODESTRING, EFI_GLOBAL_VARIABLE.ToByteArray(), numArray, ref num, out num2);

    }
    }
    }