Пример #1
0
        public uint Id; // four-digit hex number part of its name Boot####
        // public uint Attributes;
        // public string FriendlyName; //FriendlyNameOffset: ULONG,
        // public string BootFilePath; //BootFilePathOffset: ULONG,
        // OsOptionsLength: ULONG,
        // OsOptions: [UCHAR; 1],

        public unsafe static NtEfiBootEntry MarshalFromNative(IntPtr data)
        {
            var result = new NtEfiBootEntry();

            result.Id = *(uint *)(data + 8);

            return(result);
        }
Пример #2
0
        static List <string> read_all_boot_entry_names()
        {
            var  result = new List <string>();
            uint size   = 0;
            var  buffer = IntPtr.Zero;
            var  status = Natives.NtEnumerateBootEntries(buffer, ref size);

            if (status != NtStatus.BufferTooSmall)
            {
                if (status >= 0)
                {
                    // Somehow there are no boot entries in NVRAM.
                    Console.WriteLine("Somehow there are no boot entries in NVRAM.");
                    return(result);
                }
                else
                {
                    // An unexpected error occurred
                    Console.WriteLine("An unexpected error occurred.");
                    throw new Exception();
                }
            }

            buffer = Marshal.AllocHGlobal((int)size);
            status = Natives.NtEnumerateBootEntries(buffer, ref size);

            if (status < 0)
            {
                // An unexpected error occurred
                Console.WriteLine("An unexpected error occurred. 2");
                Marshal.FreeHGlobal(buffer);
                throw new Exception();
            }

            var currPtr = buffer;

            for (var x = NtEfiBootEntryList.MarshalFromNative(currPtr); ; x = NtEfiBootEntryList.MarshalFromNative(currPtr += (int)x.NextEntryOffset))
            {
                var id = NtEfiBootEntry.MarshalFromNative(x.BootEntry).Id;
                result.Add($"Boot{id.ToString("X4")}");

                if (x.NextEntryOffset == 0)
                {
                    break;
                }
            }

            Marshal.FreeHGlobal(buffer);
            return(result);
        }