mirror of
https://github.com/Metabolix/HackBGRT.git
synced 2025-12-07 09:36:10 -08:00
Report if UEFI is missing (can't read variables)
This commit is contained in:
26
src/Efi.cs
26
src/Efi.cs
@@ -4,6 +4,7 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.ComponentModel;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,24 +148,21 @@ public class Efi {
|
|||||||
if (len == buf.Length) {
|
if (len == buf.Length) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (len > 0 || Marshal.GetLastWin32Error() == 0) {
|
var error = Marshal.GetLastWin32Error();
|
||||||
|
const int ERROR_ENVVAR_NOT_FOUND = 0xCB;
|
||||||
|
if (error == ERROR_ENVVAR_NOT_FOUND) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (len > 0 || error == 0) {
|
||||||
result.Data = new byte[len];
|
result.Data = new byte[len];
|
||||||
Array.Copy(buf, 0, result.Data, 0, len);
|
Array.Copy(buf, 0, result.Data, 0, len);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
switch (len != 0 ? 0 : Marshal.GetLastWin32Error()) {
|
const int ERROR_INVALID_FUNCTION = 0x1;
|
||||||
case 203:
|
var msg = $"GetVariable: error 0x{error:X08}: ${new Win32Exception(error).Message}";
|
||||||
// Not found.
|
throw error == ERROR_INVALID_FUNCTION ? new NotImplementedException(msg) : new Exception(msg);
|
||||||
return result;
|
|
||||||
case 87:
|
|
||||||
throw new Exception("GetVariable: Invalid parameter");
|
|
||||||
case 1314:
|
|
||||||
throw new Exception("GetVariable: Privilege not held");
|
|
||||||
default:
|
|
||||||
throw new Exception("GetVariable: error " + Marshal.GetLastWin32Error());
|
|
||||||
}
|
}
|
||||||
}
|
throw new Exception("GetVariable: result exceeds 1MB");
|
||||||
throw new Exception("GetFirmwareEnvironmentVariable: too big data");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,6 +267,8 @@ public class Efi {
|
|||||||
return "Log is empty.";
|
return "Log is empty.";
|
||||||
}
|
}
|
||||||
return new string(BytesToUInt16s(log.Data).Select(i => (char)i).ToArray());
|
return new string(BytesToUInt16s(log.Data).Select(i => (char)i).ToArray());
|
||||||
|
} catch (NotImplementedException e) {
|
||||||
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return $"Log not found: {e.ToString()}";
|
return $"Log not found: {e.ToString()}";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -966,7 +966,14 @@ public class Setup {
|
|||||||
|
|
||||||
InitEspPath();
|
InitEspPath();
|
||||||
InitEspInfo();
|
InitEspInfo();
|
||||||
var bootLog = $"\n--- BOOT LOG START ---\n{Efi.GetHackBGRTLog()}\n--- BOOT LOG END ---";
|
Func<string> tryGetBootLog = () => {
|
||||||
|
try {
|
||||||
|
return $"\n--- BOOT LOG START ---\n{Efi.GetHackBGRTLog()}\n--- BOOT LOG END ---";
|
||||||
|
} catch (NotImplementedException e) {
|
||||||
|
throw new SetupException($"Looks like you're not booting in UEFI mode. ({e.Message})");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var bootLog = tryGetBootLog();
|
||||||
Setup.Log(bootLog);
|
Setup.Log(bootLog);
|
||||||
Efi.LogBGRT();
|
Efi.LogBGRT();
|
||||||
EfiBootEntries.TryLogEntries();
|
EfiBootEntries.TryLogEntries();
|
||||||
|
|||||||
Reference in New Issue
Block a user