Esempio n. 1
0
        private void SaveData(IStream stream)
        {
            // Create a memory buffer and write the strings there
            using (var buffer = new MemoryStream())
                using (var bufferWriter = new EndianWriter(buffer, stream.Endianness))
                {
                    // Write the strings to the buffer
                    foreach (string str in _strings)
                    {
                        if (str != null)
                        {
                            bufferWriter.WriteAscii(str);
                        }
                    }

                    // Align the buffer's length if encryption is necessary
                    if (_key != null)
                    {
                        buffer.SetLength(AES.AlignSize((int)buffer.Length));
                    }

                    byte[] data = buffer.ToArray();

                    // Encrypt the buffer if necessary
                    if (_key != null)
                    {
                        data = AES.Encrypt(data, 0, (int)buffer.Length, _key.Key, _key.IV);
                    }

                    // Resize the data area and write it in
                    _data.Resize((int)buffer.Length, stream);
                    stream.SeekTo(_data.Offset);
                    stream.WriteBlock(data, 0, (int)buffer.Length);
                }
        }
Esempio n. 2
0
        private void SaveData(IStream stream)
        {
            // Create a memory buffer and write the strings there
            var buffer       = new MemoryStream();
            var bufferWriter = new EndianWriter(buffer, stream.Endianness);

            try
            {
                int count            = _strings.Count();
                int start_offset     = 0x8 + count * 4; // Start data offset of the first string
                int string_data_size = 0;
                foreach (string str in _strings)
                {
                    string_data_size += str.Length + 1;
                }
                int data_size = start_offset + string_data_size;

                // Headder
                bufferWriter.WriteInt32(count);
                bufferWriter.WriteInt32(data_size);

                // Offsets
                SaveOffsets(stream);

                // Write the strings to the buffer
                foreach (string str in _strings)
                {
                    if (str != null)
                    {
                        bufferWriter.WriteAscii(str);
                    }
                }
            }
            finally
            {
                bufferWriter.Close();
            }
        }