コード例 #1
0
ファイル: Tweet.cs プロジェクト: usnail/Ninokuni
        public void Read(DataStream inStr)
        {
            using (var decodedStr = new DataStream(new MemoryStream(), 0, -1)) {
                // Decode data
                Rc4.Run(inStr, Key, decodedStr);
                decodedStr.Seek(0, SeekMode.Origin);

                DataReader br = new DataReader(decodedStr);
                if (br.ReadString(4) != MagicHeader)
                {
                    throw new FormatException("Invalid MagicHeader");
                }

                br.ReadUInt32();    // CRC, I am not checking it

                for (int i = 0; i < MaxEntries; i++)
                {
                    this.entries[i] = Entry.FromStream(decodedStr);
                }
            }
        }
コード例 #2
0
ファイル: Tweet.cs プロジェクト: usnail/Ninokuni
        public void Write(DataStream outStr)
        {
            using (var decodedStr = new DataStream(new MemoryStream(), 0, -1)) {
                DataWriter bw = new DataWriter(decodedStr);
                bw.Write(MagicHeader);
                bw.Write((uint)0x00);   // CRC will be updated later

                foreach (Entry entry in this.entries)
                {
                    entry.Write(decodedStr);
                }

                // Calculate CRC and write it
                decodedStr.Seek(8, SeekMode.Origin);
                uint crc = Crc32.Run(decodedStr, (uint)decodedStr.Length - 8);
                decodedStr.Seek(4, SeekMode.Origin);
                bw.Write(crc);

                // Encode and write
                decodedStr.Seek(0, SeekMode.Origin);
                Rc4.Run(decodedStr, Key, outStr);
            }
        }