private static void write(Chunk chunk, StreamAccessor accessor) { accessor.Write(chunk.name, EncodingType.CC4); StreamAccessor ac2 = new StreamAccessor(accessor.WriteSubStream(4)); long pos0 = accessor.Position; // 内容 if (chunk.content != null) { if (chunk.content is byte[]) { accessor.Write((byte[])chunk.content); } else if (chunk.content is System.IO.Stream) { accessor.WriteStream((System.IO.Stream)chunk.content); } else { RiffChunkReadWriteAttribute.Write(chunk.content, accessor); } } else if (chunk._data != null) { accessor.Write(chunk._data); } else if (chunk._stream != null) { accessor.WriteStream(chunk.Stream); } ac2.Write(checked ((uint)(accessor.Position - pos0)), EncodingType.U4); ac2.Stream.Close(); }
private void WriteTagHeader(StreamAccessor accessor, bool unsync, out long pos_size) { accessor.Write("ID3", EncodingType.F4BE); accessor.Write((byte)3, EncodingType.U1); accessor.Write((byte)0, EncodingType.U1); byte num = 0; if (unsync) { num = (byte)(num | 0x80); } if (this.has_ext) { num = (byte)(num | 0x40); } if (this.experimental) { num = (byte)(num | 0x20); } accessor.Write(num, EncodingType.U1); pos_size = accessor.Position; accessor.Skip(4L); }
private static void write_chunk(ImageCollection images, StreamAccessor accessor) { accessor.Write(images.count, EncodingType.I4); foreach (Thumb thm in images.sorted) { accessor.Write(thm); } }
private static void write(ImageDirectory dir, StreamAccessor accessor) { accessor.Write(dir.name, EncodingType.NoSpecified); accessor.Write((uint)dir.images.Count, EncodingType.U4); foreach (int index in dir.images) { accessor.Write(index, EncodingType.I4); } accessor.Write(dir.dirs); }
internal void Save() { if (!_isChanged && !_isNew) { return; } if (_isNew) { // Set paths string fileName = _module.NameChanged ? _module.NewName : _module.Name; var assembly = (BuildAssembly)_module.Assembly; string outputPath = assembly.OutputPath; if (outputPath == null) { outputPath = Path.GetDirectoryName(assembly.Location); } _outputFilePath = Path.Combine(outputPath, fileName); _stateFilePath = _outputFilePath + ".adstate"; _buildFilePath = _outputFilePath + ".adbuild"; } using (var accessor = new StreamAccessor(new FileStream(_stateFilePath, FileMode.Create, FileAccess.Write, FileShare.None))) { accessor.Write7BitEncodedInt(_bufferLength); accessor.Write(_buffer, 0, _bufferLength); _objects.Serialize(accessor); _blobs.Serialize(accessor); var signatureBlob = new Blob(); _signatures.Serialize(new BlobAccessor(signatureBlob)); var stringBlob = new Blob(); _strings.Serialize(new BlobAccessor(stringBlob)); StrongCryptoUtils.Encrypt(stringBlob.GetBuffer(), 0, stringBlob.Length); accessor.Write7BitEncodedInt(stringBlob.Length); accessor.Write(stringBlob.GetBuffer(), 0, stringBlob.Length); accessor.Write(signatureBlob.GetBuffer(), 0, signatureBlob.Length); } _isNew = false; _isChanged = false; }
//================================================= // 他 //================================================= /// <summary> /// ファイルを保存します。 /// </summary> public void Save() { StreamAccessor accessor = new StreamAccessor(System.IO.File.OpenWrite(this.filename)); accessor.Write(this); accessor.Stream.Close(); }
private void WriteExtHeader(StreamAccessor accessor, out StreamAccessor str_crc32) { accessor.Write(this.hascrc ? 10 : 6, EncodingType.U4BE); ushort num = this.hascrc ? ((ushort)0x8000) : ((ushort)0); accessor.Write(num, EncodingType.U2BE); accessor.Write((uint)0, EncodingType.U4BE); if (this.hascrc) { str_crc32 = new StreamAccessor(accessor.WriteSubStream(4L)); } else { str_crc32 = null; } }
private static void write(RiffFile value, StreamAccessor accessor) { accessor.Write("RIFF", EncodingType.CC4); StreamAccessor acSize = new StreamAccessor(accessor.WriteSubStream(4)); long pos0 = accessor.Position; accessor.Write(value.type, EncodingType.CC4); foreach (Chunk chunk in value.chunks) { accessor.Write(chunk, EncodingType.NoSpecified); } uint size = checked ((uint)(accessor.Position - pos0)); acSize.Write(size, EncodingType.U4); acSize.Stream.Close(); }
private static void write(DirectoryCollection dirs, StreamAccessor accessor) { StreamAccessor acSize = new StreamAccessor(accessor.WriteSubStream(4)); long pos0 = accessor.Position; foreach (ImageDirectory childdir in dirs) { accessor.Write(childdir); } acSize.Write(checked ((uint)(accessor.Position - pos0)), EncodingType.U4); acSize.Stream.Close(); }
public static unsafe void WriteToStream(Tag tag, StreamAccessor accessor) { tag.Encode(); byte[] buffer = new byte[0x80]; fixed(byte *data = buffer) { tagID3v1_1 *pDst = (tagID3v1_1 *)data; *pDst = tag.data; } accessor.Write(buffer); }
internal void Serialize(StreamAccessor accessor) { var bufferBlob = new Blob(); var bufferAccessor = new BlobAccessor(bufferBlob); accessor.Write7BitEncodedInt(_count); var entries = new Entry[_count]; for (int i = 0; i < _count; i++) { int offset = (int)bufferAccessor.Position; var item = _items[i]; if (item != null && item.IsChanged) { item.Write(bufferAccessor); } else if (_entries != null && _entries.Length > i) { int existingSize = _entries[i].Size; if (existingSize > 0) { bufferAccessor.Write(_buffer, _entries[i].Offset, existingSize); } } int size = (int)bufferAccessor.Position - offset; accessor.Write7BitEncodedInt(offset); accessor.Write7BitEncodedInt(size); entries[i] = new Entry() { Offset = offset, Size = size, }; } _entries = entries; _buffer = bufferBlob.ToArray(); Array.Clear(_items, 0, _count); accessor.Write7BitEncodedInt(_buffer.Length); if (_buffer.Length > 0) { accessor.Write(_buffer, 0, _buffer.Length); } }
public static unsafe void WritePEChecksum(string filePath, uint checkSum) { using (var accessor = new StreamAccessor(new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite))) { // DOS DOSHeader dosHeader; fixed(byte *pBuff = accessor.ReadBytes(PEConstants.DosHeaderSize)) { dosHeader = *(DOSHeader *)pBuff; } if (dosHeader.Signature != PEConstants.DosSignature) { throw new BadImageFormatException(SR.DOSHeaderSignatureNotValid); } accessor.Position = dosHeader.Lfanew; // NT Signature if (accessor.ReadUInt32() != PEConstants.NTSignature) { throw new BadImageFormatException(SR.PESignatureNotValid); } // COFF accessor.ReadBytes(PEConstants.COFFHeaderSize); // PE ushort peMagic = accessor.ReadUInt16(); if (peMagic == PEConstants.PEMagic32) { accessor.ReadBytes(62); } else if (peMagic == 0x20b) { accessor.ReadBytes(62); } else { throw new BadImageFormatException(SR.PEHeaderSignatureNotValid); } accessor.Write((uint)checkSum); } }
public static void WriteToStream(Tag value, StreamAccessor accessor, out System.Action <long> SetSize) { long pos_size; Stream stream = new MemoryStream(); StreamAccessor accessor2 = new StreamAccessor(stream); StreamAccessor accessor3 = null; long start = 0L; if (value.has_ext) { value.WriteExtHeader(accessor2, out accessor3); start = stream.Position; } foreach (Frame frame in value.frames.Values) { accessor2.WriteAs <Frame>(frame); } if (value.has_ext) { long length = stream.Position - start; accessor3.Write(ID3Utils.CalculateCRC32(stream, start, length), EncodingType.U4BE); accessor3.Stream.Close(); } bool unsync = ID3Utils.ID3RequiredUnsync(stream); if (unsync) { Stream stream2 = ID3Utils.ID3Unsynchronize(stream); stream.Close(); stream = stream2; } value.WriteTagHeader(accessor, unsync, out pos_size); SetSize = delegate(long size){ if (size > StreamAccessor.MaxUInt28) { throw new System.ArgumentOutOfRangeException("Tag の情報量が多すぎて保存できません。Tag の内容は 256MB より小さくなる様にして下さい"); } accessor.PushPosition(pos_size); accessor.Write((uint)size, EncodingType.UInt28BE); accessor.PopPosition(); }; accessor.WriteStream(stream); }