Exemple #1
0
        public static EFI_LOAD_OPTION GetLoadOption(ushort optionId)
        {
            byte[] buffer = null;
            uint   length = ReadVariable(string.Format(LOAD_OPTION_FORMAT, optionId), ref buffer);

            return(EFI_LOAD_OPTION.ConvertOption(buffer, (int)length));
        }
        public static EFI_LOAD_OPTION ConvertOption(byte[] data, int lenght)
        {
            EFI_LOAD_OPTION LoadOption = new EFI_LOAD_OPTION();
            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, 0, lenght))) {
                while (reader.BaseStream.Position != reader.BaseStream.Length) {
                    LoadOption.Attributes = reader.ReadUInt32();
                    LoadOption.FilePathListLength = reader.ReadUInt16();
                    StringBuilder builder = new StringBuilder();
                    while (true) {
                        ushort chr = reader.ReadUInt16();
                        if (chr == 0) {
                            break;
                        }
                        builder.Append(Convert.ToChar(chr));
                    }
                    LoadOption.Description = builder.ToString();
                    LoadOption.FilePathList = EFI_DEVICE_PATH_PROTOCOL.ReadList(reader);

                    // Manually seek to optional data position because EFI_DEVICE_PATH_PROTOCOL sequence not always property aligned
                    reader.BaseStream.Seek(sizeof(UInt32) + sizeof(UInt16) + (LoadOption.Description.Length + 1) * sizeof(UInt16) + LoadOption.FilePathListLength, SeekOrigin.Begin);
                    LoadOption.OptionalData = reader.ReadBytes((int)(lenght - reader.BaseStream.Position));
                }
            }
            return LoadOption;
        }
Exemple #3
0
        public static EFI_LOAD_OPTION ConvertOption(byte[] data, int lenght)
        {
            EFI_LOAD_OPTION LoadOption = new EFI_LOAD_OPTION();

            using (BinaryReader reader = new BinaryReader(new MemoryStream(data, 0, lenght))) {
                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    LoadOption.Attributes         = reader.ReadUInt32();
                    LoadOption.FilePathListLength = reader.ReadUInt16();
                    StringBuilder builder = new StringBuilder();
                    while (true)
                    {
                        ushort chr = reader.ReadUInt16();
                        if (chr == 0)
                        {
                            break;
                        }
                        builder.Append(Convert.ToChar(chr));
                    }
                    LoadOption.Description  = builder.ToString();
                    LoadOption.FilePathList = EFI_DEVICE_PATH_PROTOCOL.ReadList(reader);

                    // Manually seek to optional data position because EFI_DEVICE_PATH_PROTOCOL sequence not always property aligned
                    reader.BaseStream.Seek(sizeof(UInt32) + sizeof(UInt16) + (LoadOption.Description.Length + 1) * sizeof(UInt16) + LoadOption.FilePathListLength, SeekOrigin.Begin);
                    LoadOption.OptionalData = reader.ReadBytes((int)(lenght - reader.BaseStream.Position));
                }
            }
            return(LoadOption);
        }
Exemple #4
0
        public static List <BootEntry> GetEntries()
        {
            byte[]           buffer         = null;
            uint             length         = ReadVariable(EFI_BOOT_ORDER, ref buffer);
            List <BootEntry> entries        = new List <BootEntry>();
            ushort           currentEntryId = GetBootCurrent();
            ushort           nextEntryId    = GetBootNext();

            using (BinaryReader reader = new BinaryReader(new MemoryStream(buffer, 0, (int)length))) {
                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    ushort          optionId   = reader.ReadUInt16();
                    EFI_LOAD_OPTION LoadOption = GetLoadOption(optionId);
                    entries.Add(new BootEntry()
                    {
                        Id         = optionId,
                        LoadOption = LoadOption,
                        IsCurrent  = currentEntryId == optionId,
                        IsBootNext = nextEntryId == optionId
                    });
                }
            }
            return(entries);
        }