private FwPacket ProcessNextFwPacket(BinaryReaderEndian packetReader) { FwPacket packet = new FwPacket(); try { // Seek to next packet start while (true) { if (packetReader.ReadByte() == 0x00) { byte tableId = packetReader.ReadByte(); if (tableId == 0xB5 || tableId == 0xB6) { packetReader.BaseStream.Seek(-2, SeekOrigin.Current); break; } else { packetReader.BaseStream.Seek(-1, SeekOrigin.Current); } } } long startPos = packetReader.BaseStream.Position; // Skip over table id packetReader.ReadInt16(); packet.Length = (ushort)(packetReader.ReadUInt16() & 0x0FFF); packet.SectionType = packetReader.ReadUInt16(); packet.Unknown = packetReader.ReadUInt32(); packet.VendorId = packetReader.ReadByte(); packetReader.ReadByte(); packet.ModelId = packetReader.ReadByte(); packetReader.BaseStream.Seek(3, SeekOrigin.Current); packet.FirmwareVersion = packetReader.ReadByte(); packet.FileOffset = packetReader.ReadUInt32(); packet.FileLength = packetReader.ReadUInt32(); packet.Data = packetReader.ReadBytes(packet.Length - 25); packet.Crc32 = packetReader.ReadUInt32(); packetReader.BaseStream.Seek(startPos + 1, SeekOrigin.Begin); byte[] wholePacket = packetReader.ReadBytes(packet.Length + 3); packet.hasPassedCRC = (Crc32.crc32_mpeg(wholePacket, (uint)wholePacket.Length) == 0); } catch (EndOfStreamException ex) { throw ex; } catch (Exception) { packet.hasPassedCRC = false; } return(packet); }
private void Read(StreamPart streamFile) { streamFile.Stream.Position = streamFile.Position; using (BinaryReader reader = new BinaryReaderEndian(streamFile.Stream, Encoding.ASCII, true)) { Header = new DDSAtlusHeader(reader); int temp = 0; temp += ReadTexture(reader); if (temp != Header.SizeTexture) { throw new Exception("DDSAtlus: wrong texture size"); } LastBlock = reader.ReadBytes(Header.SizeWOHeader - Header.SizeTexture); } }
private FwPacket ProcessNextFwPacket(BinaryReaderEndian packetReader) { FwPacket packet = new FwPacket(); try { // Seek to next packet start while (true) { if (packetReader.ReadByte() == 0x00) { byte tableId = packetReader.ReadByte(); if (tableId == 0xB5 || tableId == 0xB6) { packetReader.BaseStream.Seek(-2, SeekOrigin.Current); break; } else { packetReader.BaseStream.Seek(-1, SeekOrigin.Current); } } } long startPos = packetReader.BaseStream.Position; // Skip over table id packetReader.ReadInt16(); packet.Length = (ushort)(packetReader.ReadUInt16() & 0x0FFF); packet.SectionType = packetReader.ReadUInt16(); packet.Unknown = packetReader.ReadUInt32(); packet.VendorId = packetReader.ReadByte(); packetReader.ReadByte(); packet.ModelId = packetReader.ReadByte(); packetReader.BaseStream.Seek(3, SeekOrigin.Current); packet.FirmwareVersion = packetReader.ReadByte(); packet.FileOffset = packetReader.ReadUInt32(); packet.FileLength = packetReader.ReadUInt32(); packet.Data = packetReader.ReadBytes(packet.Length - 25); packet.Crc32 = packetReader.ReadUInt32(); packetReader.BaseStream.Seek(startPos + 1, SeekOrigin.Begin); byte[] wholePacket = packetReader.ReadBytes(packet.Length + 3); packet.hasPassedCRC = (Crc32.crc32_mpeg(wholePacket, (uint)wholePacket.Length) == 0); } catch (EndOfStreamException ex) { throw ex; } catch (Exception) { packet.hasPassedCRC = false; } return packet; }