Пример #1
0
        /// <summary>
        /// Reads the footer of a file
        /// </summary>
        /// <param name="br">The file to be read</param>
        /// <remarks>
        /// Works backwards from the end of the file to calcuate the footer then returns the stream's position back to the start of the stream. Does not preserve the curren position of any streams passed to it.
        /// </remarks>
        public bool Read(BinaryReader br)
        {
            br.BaseStream.Seek(-1, SeekOrigin.End);

            int footerSize = 0;

            if (br.ReadByte() != 0x88)
            {
                br.BaseStream.Seek(0, SeekOrigin.Begin); // is this control flow convoluted?
                footerContents = new DataBox(0);
                footerContents.Read(br);
                return(true);
            }

            br.BaseStream.Seek(-1, SeekOrigin.End);

            while (br.ReadByte() == 0x88)
            {
                br.BaseStream.Seek(-2, SeekOrigin.Current);
                footerSize += 1;
            }

            footerContents = new DataBox(footerSize);
            footerContents.Read(br);

            br.BaseStream.Seek(0, SeekOrigin.Begin);

            return(true);
        }
Пример #2
0
 public bool Read(BinaryReader br)
 {
     opcode = FileIOHelper.ReadOpcode(br);
     box1   = new DataBox(0x2);
     box1.Read(br);
     return(true);
 }
Пример #3
0
        /// <summary>
        /// Reads the footer of a file
        /// </summary>
        /// <param name="br">The file to be read</param>
        /// <returns>A Box containing the file footer</returns>
        /// <remarks>
        /// Works backwards from the end of the file to calcuate the footer then returns the stream's position back to the start of the stream. Does not preserve the curren position of any streams passed to it.
        /// </remarks>
        private DataBox ReadFooter(BinaryReader br)
        {
            br.BaseStream.Seek(-1, SeekOrigin.End);

            int     footerSize = 0;
            DataBox footer;

            if (br.ReadByte() != 0x88)
            {
                br.BaseStream.Seek(0, SeekOrigin.Begin); // is this control flow convoluted?
                footer = new DataBox(0);
                footer.Read(br);
                return(footer);
            }

            br.BaseStream.Seek(-1, SeekOrigin.End);

            while (br.ReadByte() == 0x88)
            {
                br.BaseStream.Seek(-2, SeekOrigin.Current);
                footerSize += 1;
            }

            footer = new DataBox(footerSize);
            footer.Read(br);

            br.BaseStream.Seek(0, SeekOrigin.Begin);

            return(footer);
        }
Пример #4
0
        public static void DataBoxTest(Type element, string testFileName)
        {
            FileInfo boxTestFile = new FileInfo(Path.Combine(GetTestDir(), testFileName));
            int      dataSize    = (int)boxTestFile.Length;

            DataBox boxTest = new DataBox(dataSize);

            FileStream   fs = boxTestFile.Open(FileMode.Open);
            BinaryReader br = new BinaryReader(fs);

            byte[] inData = br.ReadBytes(dataSize);
            br.BaseStream.Seek(0, SeekOrigin.Begin);

            boxTest.Read(br);

            br.Close();
            fs.Close();

            byte[] outData = new byte[dataSize];

            MemoryStream ms = new MemoryStream(outData);
            BinaryWriter bw = new BinaryWriter(ms);

            boxTest.Write(bw);

            bw.Close();
            ms.Close();

            Debug.Assert(inData.SequenceEqual(outData), "Input/output replication test failed for " + element.ToString());
        }
Пример #5
0
 public bool Read(BinaryReader br)
 {
     fileNumber = br.ReadInt16();
     box1       = new DataBox(0x5E); // Header size seems to be 0x60 overall, so we read the first int16 then shove the rest in a Box. There seems to be a bit more to the header that can be used to validate but I'm skipping that at the moment.
     box1.Read(br);
     return(true);
 }
Пример #6
0
 public bool Read(BinaryReader br)
 {
     fileNumber.Read(br);
     box1 = new DataBox(0x5C); // header size minus size of StCp number
     box1.Read(br);
     return(true);
 }
Пример #7
0
 public bool Read(BinaryReader br)
 {
     fileNumber.Read(br);
     sequentialChoiceNumber = br.ReadInt16();
     unknown1      = br.ReadInt16();
     offset        = br.ReadInt16();
     offset        = HandleOffsetOnRead(offset); // since the offset is counted from the end of the header not the start of the file we make our own adjustment to it to turn into a real offset from the start of the file. since we will be dealing with full file streams this makes it easier to reason about and recalcuate the offets.
     unknown2      = br.ReadInt16();
     unknown3      = br.ReadInt16();
     lookupCode    = br.ReadInt16();
     unknown4      = br.ReadInt16();
     unknown5      = br.ReadInt16();
     trailingBlock = new DataBox(0x82);
     trailingBlock.Read(br);
     return(true);
 }