Esempio n. 1
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);
        }
 public static List<EFI_DEVICE_PATH_PROTOCOL> ReadList(BinaryReader reader)
 {
     List<EFI_DEVICE_PATH_PROTOCOL> protocols = new List<EFI_DEVICE_PATH_PROTOCOL>();
     while (true) {
         EFI_DEVICE_PATH_PROTOCOL protocol = new EFI_DEVICE_PATH_PROTOCOL();
         protocol.Type = (DeviceType) reader.ReadByte();
         protocol.SubType = reader.ReadByte();
         protocol.Length = reader.ReadUInt16();
         protocol.Data = reader.ReadBytes(protocol.Length - 4);
         protocols.Add(protocol);
         if (protocol.Type == DeviceType.END && protocol.SubType == END_ENTIRE_DEVICE_PATH_SUB_TYPE) {
             break;
         }
     }
     return protocols;
 }
Esempio n. 3
0
        public static List <EFI_DEVICE_PATH_PROTOCOL> ReadList(BinaryReader reader)
        {
            List <EFI_DEVICE_PATH_PROTOCOL> protocols = new List <EFI_DEVICE_PATH_PROTOCOL>();

            while (true)
            {
                EFI_DEVICE_PATH_PROTOCOL protocol = new EFI_DEVICE_PATH_PROTOCOL();
                protocol.Type    = (DeviceType)reader.ReadByte();
                protocol.SubType = reader.ReadByte();
                protocol.Length  = reader.ReadUInt16();
                protocol.Data    = reader.ReadBytes(protocol.Length - 4);
                protocols.Add(protocol);
                if (protocol.Type == DeviceType.END && protocol.SubType == END_ENTIRE_DEVICE_PATH_SUB_TYPE)
                {
                    break;
                }
            }
            return(protocols);
        }