Ejemplo n.º 1
0
        public static Firmware Parse(byte[] buffer)
        {
            Firmware firmware = new Firmware();

            firmware.Partitions = new List <Partition>();

            int offset = 0;

            firmware.Header = Encoding.Default.GetString(buffer, offset, HEADER_SIZE);
            offset         += HEADER_SIZE;

            firmware.FirmwareDescription = Encoding.Default.GetString(buffer, offset, FIRMWARE_DESCRIPTION_SIZE);
            offset += FIRMWARE_DESCRIPTION_SIZE;

            firmware.TileBytes = new byte[TILE_SIZE];
            System.Array.Copy(buffer, offset, firmware.TileBytes, 0, TILE_SIZE);
            offset += TILE_SIZE;

            while (offset + 4 < buffer.Length)
            {
                Partition partition = Partition.Parse(buffer, offset);
                offset += PARTITION_HEADER_SIZE + partition.Bytes.Length;

                firmware.Partitions.Add(partition);
            }

            UInt32 crc32 = BitConverter.ToUInt32(buffer, offset);

            return(firmware);
        }
Ejemplo n.º 2
0
 public static Firmware ReadFromStream(Stream stream)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         stream.CopyTo(ms);
         return(Firmware.Parse(ms.ToArray()));
     }
 }
Ejemplo n.º 3
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                using (Stream stream = dialog.OpenFile())
                {
                    this.firmware = Firmware.ReadFromStream(stream);
                }
            }
            propertyGrid1.SelectedObject = this.firmware;
        }