/// <summary> /// Renders the current instance as a raw ASF object. /// </summary> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered version of the current instance. /// </returns> public override ByteVector Render() { var output = new ByteVector(); uint child_count = 0; foreach (var child in children) { if (child.Guid != Asf.Guid.AsfPaddingObject) { output.Add(child.Render()); child_count++; } } long size_diff = (long)output.Count + 30 - (long)OriginalSize; if (size_diff != 0) { var obj = new PaddingObject((uint)(size_diff > 0 ? 4096 : -size_diff)); output.Add(obj.Render()); child_count++; } output.Insert(0, reserved); output.Insert(0, RenderDWord(child_count)); return(Render(output)); }
/// <summary> /// Renders the current instance, including its children, to /// a new <see cref="ByteVector" /> object, preceeding the /// contents with a specified block of data. /// </summary> /// <param name="topData"> /// A <see cref="ByteVector" /> object containing box /// specific header data to preceed the content. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered version of the current instance. /// </returns> protected virtual ByteVector Render(ByteVector topData) { bool free_found = false; ByteVector output = new ByteVector(); if (Children != null) { foreach (Box box in Children) { if (box.GetType() == typeof( IsoFreeSpaceBox)) { free_found = true; } else { output.Add(box.Render()); } } } else if (Data != null) { output.Add(Data); } // If there was a free, don't take it away, and let meta // be a special case. if (free_found || BoxType == Mpeg4.BoxType.Meta) { long size_difference = DataSize - output.Count; // If we have room for free space, add it so we // don't have to resize the file. if (header.DataSize != 0 && size_difference >= 8) { output.Add((new IsoFreeSpaceBox( size_difference)).Render()); } // If we're getting bigger, get a lot bigger so // we might not have to again. else { output.Add((new IsoFreeSpaceBox(2048 )).Render()); } } // Adjust the header's data size to match the content. header.DataSize = topData.Count + output.Count; // Render the full box. output.Insert(0, topData); output.Insert(0, header.Render()); return(output); }
public override ByteVector Render() { ByteVector data = new ByteVector(); foreach (TagLib.Asf.Object obj2 in this.children) { data.Add(obj2.Render()); } data.Insert(0, TagLib.Asf.Object.RenderDWord((uint) data.Count)); data.Insert(0, TagLib.Asf.Object.RenderWord(6)); data.Insert(0, TagLib.Asf.Guid.AsfReserved1.ToByteArray()); return base.Render(data); }
protected override ByteVector RenderFields(byte version) { ByteVector data = ByteVector.FromULong(play_count); while (data.Count > 0 && data[0] == 0) { data.RemoveAt(0); } data.Insert(0, rating); data.Insert(0, 0); data.Insert(0, ByteVector.FromString(user, StringType.Latin1)); return(data); }
public override ByteVector Render() { ByteVector output = new ByteVector(); foreach (Object child in children) { output.Add(child.Render()); } output.Insert(0, RenderDWord((uint)output.Count)); output.Insert(0, RenderWord(6)); output.Insert(0, Asf.Guid.AsfReserved1.ToByteArray()); return(Render(output)); }
public override ByteVector Render(bool is_bigendian, uint offset, out ushort type, out uint count) { ByteVector data = new ByteVector(); ByteVector offset_data = new ByteVector(); uint data_offset = offset + (uint)(4 * Values.Length); for (int i = 0; i < Values.Length; i++) { uint new_offset = (uint)(data_offset + data.Count); file.Seek(Values[i], SeekOrigin.Begin); data.Add(file.ReadBlock((int)byte_counts[i])); Values[i] = new_offset; offset_data.Add(ByteVector.FromUInt(new_offset, is_bigendian)); } if (Values.Length > 1) { data.Insert(0, offset_data); } else { Values[0] = offset; } while (data.Count < 4) { data.Add(0x00); } type = (ushort)IFDEntryType.Long; count = (uint)Values.Length; return(data); }
public new ByteVector Render() { ByteVector output = new ByteVector(); output = _data; output.Insert(0, Header.Render()); return output; }
/// <summary> /// Unsynchronizes a <see cref="ByteVector" /> object by /// inserting empty bytes where necessary. /// </summary> /// <param name="data"> /// A <see cref="ByteVector" /> object to unsynchronize. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="data" /> is <see langword="null" />. /// </exception> public static void UnsynchByteVector (ByteVector data) { if (data == null) throw new ArgumentNullException (nameof(data)); for (int i = data.Count - 2; i >= 0; i --) if (data [i] == 0xFF && (data [i+1] == 0 || (data [i+1] & 0xE0) != 0)) data.Insert (i+1, 0); }
public ByteVector Render(bool is_bigendian, uint offset, out ushort type, out uint count) { type = (ushort)IFDEntryType.Undefined; var renderer = new IFDRenderer(this.is_bigendian ?? is_bigendian, Structure, absolute_offset?offset + ifd_offset:ifd_offset); ByteVector data = renderer.Render(); data.Insert(0, prefix); count = (uint)data.Count; return(data); }
/// <summary> /// Renders the current instance to a <see cref="ByteVector"/> /// </summary> /// <param name="is_bigendian"> /// A <see cref="System.Boolean"/> indicating the endianess for rendering. /// </param> /// <param name="offset"> /// A <see cref="System.UInt32"/> with the offset, the data is stored. /// </param> /// <param name="type"> /// A <see cref="System.UInt16"/> the ID of the type, which is rendered /// </param> /// <param name="count"> /// A <see cref="System.UInt32"/> with the count of the values which are /// rendered. /// </param> /// <returns> /// A <see cref="ByteVector"/> with the rendered data. /// </returns> public override ByteVector Render(bool is_bigendian, uint offset, out ushort type, out uint count) { // The StripOffsets are an array of offsets, where the image data can be found. // We store the offsets and behind the offsets the image data is stored. Therfore, // the ByteVector data first collects the image data and the offsets itself are // collected by offset_data. Then both are concatenated. ByteVector data = new ByteVector(); ByteVector offset_data = new ByteVector(); // every offset needs 4 byte, we need to reserve the bytes. uint data_offset = offset + (uint)(4 * Values.Length); for (int i = 0; i < Values.Length; i++) { uint new_offset = (uint)(data_offset + data.Count); file.Seek(Values[i], SeekOrigin.Begin); data.Add(file.ReadBlock((int)byte_counts[i])); // update strip offset data to new offset Values[i] = new_offset; offset_data.Add(ByteVector.FromUInt(new_offset, is_bigendian)); } // If the StripOffsets only consists of one offset, this doesn't work, because this offset // should be stored inside the IFD as a value. But, because of the additional image data, // it is not stored there. We need to fix this, that the offset is adjusted correctly. // Therefore, the offset_data is only added if it contains more than one value. // Then, the offset is set correctly. (However, we need to ensure, that the image data // consists at least of 4 bytes, which is probably the case every time, but to be sure ...) // However, the strip offset in the array must also be adjusted, if the offset_data is ignored. if (Values.Length > 1) { data.Insert(0, offset_data); } else { Values[0] = offset; } while (data.Count < 4) { data.Add(0x00); } // the entry is a single long entry where the value is an offset to the data // the offset is automatically updated by the renderer. type = (ushort)IFDEntryType.Long; count = (uint)Values.Length; return(data); }
public virtual ByteVector Render(byte version) { if (version < 4) { Flags &= ~(FrameFlags.DataLengthIndicator | FrameFlags.Unsynchronisation); } if (version < 3) { Flags &= ~(FrameFlags.Compression | FrameFlags.Encryption | FrameFlags.FileAlterPreservation | FrameFlags.GroupingIdentity | FrameFlags.ReadOnly | FrameFlags.TagAlterPreservation); } ByteVector field_data = RenderFields(version); if (field_data.Count == 0) { return(new ByteVector()); } ByteVector front_data = new ByteVector(); if ((Flags & (FrameFlags.Compression | FrameFlags.DataLengthIndicator)) != 0) { front_data.Add(ByteVector.FromUInt((uint)field_data.Count)); } if ((Flags & FrameFlags.GroupingIdentity) != 0) { front_data.Add(group_id); } if ((Flags & FrameFlags.Encryption) != 0) { front_data.Add(encryption_id); } if ((Flags & FrameFlags.Compression) != 0) { throw new NotImplementedException("Compression not yet supported"); } if ((Flags & FrameFlags.Encryption) != 0) { throw new NotImplementedException("Encryption not yet supported"); } if ((Flags & FrameFlags.Unsynchronisation) != 0) { SynchData.UnsynchByteVector(field_data); } if (front_data.Count > 0) { field_data.Insert(0, front_data); } header.FrameSize = (uint)field_data.Count; ByteVector header_data = header.Render(version); header_data.Add(field_data); return(header_data); }
public override ByteVector Render() { ByteVector data = new ByteVector(); uint num = 0; foreach (TagLib.Asf.Object obj2 in this.children) { if (obj2.Guid != TagLib.Asf.Guid.AsfPaddingObject) { data.Add(obj2.Render()); num++; } } long num2 = (data.Count + 30L) - ((long) base.OriginalSize); if (num2 != 0) { data.Add(new PaddingObject((num2 <= 0L) ? ((uint) -num2) : ((uint) 0x1000L)).Render()); num++; } data.Insert(0, this.reserved); data.Insert(0, TagLib.Asf.Object.RenderDWord(num)); return base.Render(data); }
public static void UnsynchByteVector(ByteVector data) { if (data == null) { throw new ArgumentNullException("data"); } for (int i = data.Count - 2; i >= 0; i--) { if ((data[i] == 0xff) && ((data[i + 1] == 0) || ((data[i + 1] & 0xe0) != 0))) { data.Insert(i + 1, (byte) 0); } } }
public ByteVector Render() { ByteVector data = new ByteVector(); uint item_count = 0; foreach (Item item in items) { data.Add(item.Render()); item_count++; } footer.ItemCount = item_count; footer.TagSize = (uint)(data.Count + Footer.Size); HeaderPresent = true; data.Insert(0, footer.RenderHeader()); data.Add(footer.RenderFooter()); return(data); }
public ByteVector Render() { bool has_footer = (header.Flags & HeaderFlags.FooterPresent) != 0; bool unsynchAtFrameLevel = (header.Flags & HeaderFlags.Unsynchronisation) != 0 && Version >= 4; bool unsynchAtTagLevel = (header.Flags & HeaderFlags.Unsynchronisation) != 0 && Version < 4; header.MajorVersion = has_footer?(byte)4:Version; ByteVector tag_data = new ByteVector(); header.Flags &= ~HeaderFlags.ExtendedHeader; foreach (Frame frame in frame_list) { if (unsynchAtFrameLevel) { frame.Flags |= FrameFlags.Unsynchronisation; } if ((frame.Flags & FrameFlags.TagAlterPreservation) != 0) { continue; } try { tag_data.Add(frame.Render(header.MajorVersion)); } catch (NotImplementedException) { } } if (unsynchAtTagLevel) { SynchData.UnsynchByteVector(tag_data); } if (!has_footer) { tag_data.Add(new ByteVector((int)((tag_data.Count < header.TagSize)?(header.TagSize - tag_data.Count):1024))); } header.TagSize = (uint)tag_data.Count; tag_data.Insert(0, header.Render()); if (has_footer) { tag_data.Add(new Footer(header).Render()); } return(tag_data); }
/// <summary> /// Renders the current instance, encoded in a specified /// ID3v2 version. /// </summary> /// <param name="version"> /// A <see cref="byte" /> value specifying the version of /// ID3v2 to use when encoding the current instance. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered version of the current instance. /// </returns> /// <exception cref="NotImplementedException"> /// The current instance uses some feature that cannot be /// implemented in the specified ID3v2 version, or uses a /// feature, such as encryption or compression, which is not /// yet implemented in the library. /// </exception> public virtual ByteVector Render(byte version) { // Remove flags that are not supported by older versions // of ID3v2. if (version < 4) { Flags &= ~(FrameFlags.DataLengthIndicator | FrameFlags.Unsychronisation); } if (version < 3) { Flags &= ~(FrameFlags.Compression | FrameFlags.Encryption | FrameFlags.FileAlterPreservation | FrameFlags.GroupingIdentity | FrameFlags.ReadOnly | FrameFlags.TagAlterPreservation); } ByteVector field_data = RenderFields(version); // If we don't have any content, don't render anything. // This will cause the frame to not be rendered. if (field_data.Count == 0) { return(new ByteVector()); } ByteVector front_data = new ByteVector(); if ((Flags & (FrameFlags.Compression | FrameFlags.DataLengthIndicator)) != 0) { front_data.Add(ByteVector.FromUInt((uint) field_data.Count)); } if ((Flags & FrameFlags.GroupingIdentity) != 0) { front_data.Add(group_id); } if ((Flags & FrameFlags.Encryption) != 0) { front_data.Add(encryption_id); } // FIXME: Implement compression. if ((Flags & FrameFlags.Compression) != 0) { throw new NotImplementedException( "Compression not yet supported"); } // FIXME: Implement encryption. if ((Flags & FrameFlags.Encryption) != 0) { throw new NotImplementedException( "Encryption not yet supported"); } if ((Flags & FrameFlags.Unsychronisation) != 0) { SynchData.UnsynchByteVector(field_data); } if (front_data.Count > 0) { field_data.Insert(0, front_data); } header.FrameSize = (uint)field_data.Count; ByteVector header_data = header.Render(version); header_data.Add(field_data); return(header_data); }
/// <summary> /// Renders the current instance as a raw ASF object. /// </summary> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered version of the current instance. /// </returns> public override ByteVector Render() { ByteVector output = new ByteVector (); uint child_count = 0; foreach (Object child in children) if (child.Guid != Asf.Guid.AsfPaddingObject) { output.Add (child.Render ()); child_count ++; } long size_diff = (long) output.Count + 30 - (long) OriginalSize; if (size_diff != 0) { PaddingObject obj = new PaddingObject ((uint) (size_diff > 0 ? 4096 : - size_diff)); output.Add (obj.Render ()); child_count ++; } output.Insert (0, reserved); output.Insert (0, RenderDWord (child_count)); return Render (output); }
/// <summary> /// Unsynchronizes a <see cref="ByteVector" /> object by /// inserting empty bytes where necessary. /// </summary> /// <param name="data"> /// A <see cref="ByteVector" /> object to unsynchronize. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="data" /> is <see langword="null" />. /// </exception> public static void UnsynchByteVector (ByteVector data) { if (data == null) throw new ArgumentNullException ("data"); for (int i = data.Count - 2; i >= 0; i --) if (data [i] == 0xFF && (data [i+1] == 0 || (data [i+1] & 0xE0) != 0)) data.Insert (i+1, 0); }
/// <summary> /// Renders the current instance as a raw ASF object. /// </summary> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered version of the current instance. /// </returns> public override ByteVector Render () { ByteVector output = new ByteVector (); foreach (Object child in children) output.Add (child.Render ()); output.Insert (0, RenderDWord ((uint) output.Count)); output.Insert (0, RenderWord (6)); output.Insert (0, Asf.Guid.AsfReserved1.ToByteArray ()); return Render (output); }
/// <summary> /// Renders the current instance, including its children, to /// a new <see cref="ByteVector" /> object, preceeding the /// contents with a specified block of data. /// </summary> /// <param name="topData"> /// A <see cref="ByteVector" /> object containing box /// specific header data to preceed the content. /// </param> /// <returns> /// A <see cref="ByteVector" /> object containing the /// rendered version of the current instance. /// </returns> protected virtual ByteVector Render (ByteVector topData) { bool free_found = false; ByteVector output = new ByteVector (); if (Children != null) foreach (Box box in Children) if (box.GetType () == typeof ( IsoFreeSpaceBox)) free_found = true; else output.Add (box.Render ()); else if (Data != null) output.Add (Data); // If there was a free, don't take it away, and let meta // be a special case. if (free_found || BoxType == Mpeg4.BoxType.Meta) { long size_difference = DataSize - output.Count; // If we have room for free space, add it so we // don't have to resize the file. if (header.DataSize != 0 && size_difference >= 8) output.Add ((new IsoFreeSpaceBox ( size_difference)).Render ()); // If we're getting bigger, get a lot bigger so // we might not have to again. else output.Add ((new IsoFreeSpaceBox (2048 )).Render ()); } // Adjust the header's data size to match the content. header.DataSize = topData.Count + output.Count; // Render the full box. output.Insert (0, topData); output.Insert (0, header.Render ()); return output; }
protected virtual ByteVector Render(ByteVector topData) { bool flag = false; ByteVector vector = new ByteVector(); if (this.Children != null) { IEnumerator<Box> enumerator = this.Children.GetEnumerator(); try { while (enumerator.MoveNext()) { Box current = enumerator.Current; if (current.GetType() == typeof(IsoFreeSpaceBox)) { flag = true; } else { vector.Add(current.Render()); } } } finally { if (enumerator == null) { } enumerator.Dispose(); } } else if (this.Data != null) { vector.Add(this.Data); } if (flag || (this.BoxType == TagLib.Mpeg4.BoxType.Meta)) { long padding = this.DataSize - vector.Count; if ((this.header.DataSize != 0) && (padding >= 8L)) { vector.Add(new IsoFreeSpaceBox(padding).Render()); } else { vector.Add(new IsoFreeSpaceBox(0x800L).Render()); } } this.header.DataSize = topData.Count + vector.Count; vector.Insert(0, topData); vector.Insert(0, this.header.Render()); return vector; }