using System; using System.IO; using System.Text; namespace Filter { internal class BinaryReaderEx : BinaryReader { private const int BufferLength = 256; private static byte[] Buffer; public long Length { get { return this.BaseStream.Length; } } static BinaryReaderEx() { BinaryReaderEx.Buffer = new byte[256]; } public BinaryReaderEx(Stream input) : base(input) { } private string _ReadString(uint bytes) { string empty = string.Empty; if (bytes > 256) { empty = this.ReadString(bytes - 256); } this.Read(BinaryReaderEx.Buffer, 0, (int)bytes); Encoding encoding = Encoding.GetEncoding("ISO-8859-1"); string str = encoding.GetString(BinaryReaderEx.Buffer, 0, (int)bytes); return string.Concat(empty, str); } public override string ReadString() { int num = 0; for (byte i = this.ReadByte(); i != 0; i = this.ReadByte()) { int num1 = num; num = num1 + 1; BinaryReaderEx.Buffer[num1] = i; if (num >= 256) { break; } } string str = Encoding.GetEncoding("ISO-8859-1").GetString(BinaryReaderEx.Buffer, 0, num); if (num == 256) { str = string.Concat(str, this.ReadString()); } return str; } public string ReadString(int bytes) { if (bytes <= 0) { return string.Empty; } return this.ReadString((uint)bytes); } public string ReadString(uint bytes) { return this._ReadString(bytes).TrimEnd(new char[1]); } } }