public static void UnpackData(dynamic file, byte[] data) { BinaryReader reader = new BinaryReader(new MemoryStream(data)); List <byte> result = new List <byte>(); for (int i = 0; i < Math.Ceiling((double)file.DataLength / 2048); i++) { if (!reader.ReadBytes(12).SequenceEqual(syncPattern)) { throw new ArgumentException($"Synchronization pattern not found. Incorrect file type. {file.Name} Segment: {i}"); } reader.BaseStream.Seek(4, SeekOrigin.Current); // Address and Mode reader.BaseStream.Seek(1, SeekOrigin.Current); // File Number reader.BaseStream.Seek(1, SeekOrigin.Current); // Channel Number var flags = new SubheaderFlags(reader.ReadByte()); reader.BaseStream.Seek(1, SeekOrigin.Current); // Coding info reader.BaseStream.Seek(4, SeekOrigin.Current); // skip copy of subheader int form = flags.Form2 ? 1 : 0; result.AddRange(reader.ReadBytes(2048 + form * 0x114)); reader.BaseStream.Seek(4, SeekOrigin.Current); // Error detection reader.BaseStream.Seek(276 - form * 276, SeekOrigin.Current); // Error correction } if (file.Name.Contains(".OV_")) { file.Data = BPE.Decompress(result.ToArray()); } else { file.Data = result.ToArray(); } reader.Close(); }
public void GetData(BinaryReader reader) { reader.BaseStream.Seek(extentLocation * 2352, SeekOrigin.Begin); // get first data segment, rest is writen sequentially data = new byte[dataLength]; for (int i = 0; i < Math.Ceiling((double)dataLength / 2048); i++) // get number of segments { if (!reader.ReadBytes(12).SequenceEqual(syncPattern)) { throw new ArgumentException($"Synchronization pattern not found. Incorrect file type. {name} Segment: {i}"); } reader.ReadBytes(12); for (int j = 0; j < 2048; j++) // read up to 2048 bytes of each segment { if (j + i * 2048 > dataLength - 1) { break; } else { data[j + i * 2048] = reader.ReadByte(); } } reader.ReadBytes(4); // error detection reader.ReadBytes(276); // error correction } if (name.Contains(".OV_")) { decompressedData = BPE.Decompress(data); } }