Created
September 22, 2018 16:23
-
-
Save newyear2006/bfb6e4adc16182dc9ca16e37d34ac0e7 to your computer and use it in GitHub Desktop.
Versuch Confirm-SecureBoot nachzubauen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment