PeekChar() public method

public PeekChar ( ) : int
return int
Example #1
0
 public CServerProcessSources(MemoryStream buffer, uint ServerIP, ushort ServerPort)
 {
     byte[] FileHash;
     uint IP;
     ushort Port;
     byte nSources;
     bool moreFiles = true;
     BinaryReader reader = new BinaryReader(buffer);
     do
     {
         FileHash = reader.ReadBytes(16);
         nSources = reader.ReadByte();
         Debug.WriteLine("Received " + nSources.ToString() + " for " + CKernel.HashToString(FileHash));
         while (nSources > 0)
         {
             IP = reader.ReadUInt32();
             Port = reader.ReadUInt16();
             nSources--;
             CKernel.ClientsList.AddClientToFile(IP, Port, ServerIP, ServerPort, FileHash);
         }
         if ((reader.PeekChar() != 0) && (reader.PeekChar() != -1))
         {
             if ((Protocol.ProtocolType)reader.ReadByte() != Protocol.ProtocolType.eDonkey) moreFiles = false;
             if ((reader.PeekChar() == -1) || (reader.ReadByte() != (byte)Protocol.ServerCommandUDP.GlobalFoundSources))
                 moreFiles = false;
         }
         else moreFiles = false;
     }
     while (moreFiles);
     reader.Close();
     buffer.Close();
     reader = null;
     buffer = null;
 }
        private static BDictionary ReadDictionary(BinaryReader binaryReader)
        {
            Contract.Requires(binaryReader != null);

            int i = binaryReader.ReadByte();
            if (i != 'd')
            {
                throw Error();
            }

            BDictionary dict = new BDictionary();

            try
            {
                for (int c = binaryReader.PeekChar(); ; c = binaryReader.PeekChar())
                {
                    if (c == -1) throw Error();
                    if (c == 'e')
                    {
                        binaryReader.ReadByte();
                        break;
                    }
                    BString k = ReadString(binaryReader);
                    IBElement v = ReadElement(binaryReader);
                    dict.Add(k, v);
                }
            }
            catch (BencodingException) { throw; }
            catch (Exception e) { throw Error(e); }

            return dict;
        }
Example #3
0
 public CServerSearchResults(MemoryStream buffer, CSearcher search, bool esUDP)
 {
     BinaryReader reader = new BinaryReader(buffer);
     if (!esUDP)
     {
         uint nResultados = reader.ReadUInt32();
         for (uint i = 0; i < nResultados; i++)
         {
             m_ExtractResult(reader, search);
         }
         search.OnTCPSearchEnded();
     }
     else
     {
         m_ExtractResult(reader, search);
         while ((reader.PeekChar() != 0) && (reader.PeekChar() != -1))
         {
             Debug.WriteLine("MoreUDP results in one packet");
             if ((Protocol.ProtocolType)reader.ReadByte() != Protocol.ProtocolType.eDonkey) break;
             if ((reader.PeekChar() == -1) || (reader.ReadByte() != (byte)Protocol.ServerCommandUDP.GlobalSearchResult))
                 break;
             m_ExtractResult(reader, search);
         }
     }
     reader.Close();
     buffer.Close();
     reader = null;
     buffer = null;
 }
        static void Main(string[] args)
        {
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();           

            IsolatedStorageFileStream isfs = new IsolatedStorageFileStream("binPath", FileMode.OpenOrCreate, FileAccess.ReadWrite, isf);

            try
            {
                using (BinaryReader binreader = new BinaryReader(isfs))
                {
                    int BinPeek = binreader.PeekChar();
                    while (BinPeek > 0)
                    {
                        Int64 ID = binreader.ReadInt32();
                        string Name = binreader.ReadString();

                        Console.WriteLine("Readed binary = " + ID.ToString() + " " + Name);
                        BinPeek = binreader.PeekChar();
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                isfs.Close();
                Console.ReadKey();
            }
            
            
            Person p = new Person(2, "Pri", 21, DateTime.Parse("27/11/1990"));
            isfs = new IsolatedStorageFileStream("binPath", FileMode.OpenOrCreate, FileAccess.ReadWrite, isf);

            try
            {
                BinaryWriter binwriter = new BinaryWriter(isfs);

                binwriter.Write(p.ID);
                binwriter.Write(p.Name);
                binwriter.Write(p.Age);
                binwriter.Write(p.Birth.ToString());

                binwriter.Flush();
            }
            catch (Exception ex)
            {                
                Console.WriteLine(ex.Message);                
            }
            finally
            {
                isfs.Close();
                Console.ReadKey();
            }
        }
Example #5
0
        private static byte[] ReadUntilSeparator( BinaryReader reader )
        {
            var bytes = new List<byte>();

            int peek = reader.PeekChar();
            while( peek != INT_RecordSeparator && peek != INT_EOF)
            {
                bytes.Add( reader.ReadByte() );
                peek = reader.PeekChar();
            }

            return bytes.ToArray();
        }
 public StringList(string language)
 {
     this.m_Language = language;
       this.m_Table = new Hashtable();
       string filePath = Client.GetFilePath(string.Format("cliloc.{0}", (object) language));
       if (filePath == null)
       {
     this.m_Entries = new StringEntry[0];
       }
       else
       {
     ArrayList arrayList = new ArrayList();
     using (BinaryReader binaryReader = new BinaryReader((Stream) new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
     {
       binaryReader.ReadInt32();
       int num1 = (int) binaryReader.ReadInt16();
       while (binaryReader.PeekChar() != -1)
       {
     int number = binaryReader.ReadInt32();
     int num2 = (int) binaryReader.ReadByte();
     int count = (int) binaryReader.ReadInt16();
     if (count > StringList.m_Buffer.Length)
       StringList.m_Buffer = new byte[count + 1023 & -1024];
     binaryReader.Read(StringList.m_Buffer, 0, count);
     string @string = Encoding.UTF8.GetString(StringList.m_Buffer, 0, count);
     arrayList.Add((object) new StringEntry(number, @string));
     this.m_Table[(object) number] = (object) @string;
       }
     }
     this.m_Entries = (StringEntry[]) arrayList.ToArray(typeof (StringEntry));
       }
 }
Example #7
0
 public WkbBinaryReader(Stream stream)
 {
     _reader = new BinaryReader(stream);
     HasData = _reader.PeekChar() != -1;
     if (HasData)
         Encoding = (WkbEncoding)_reader.ReadByte();
 }
Example #8
0
        public SWFReader(string SWFFile)
        {
            Tags = new List<Tag>();
            using (BinaryReader b = new BinaryReader(File.Open(SWFFile, FileMode.Open)))
            {
                if (b.PeekChar() == 'C') //Zlib Compressed
                {
                    Uncompress(b);
                }
            }
            if (SWFBinary == null)
                SWFBinary = new BinaryReader(File.Open(SWFFile, FileMode.Open));

            ReadSWFHeader();

            bool readEndTag = false;
            while (SWFBinary.BaseStream.Position < SWFBinary.BaseStream.Length && !readEndTag)
            {
                Tag b = ReadTag();
                if (b != null)
                {
                    if (b is End)
                        readEndTag = true;
                    Tags.Add(b);
                }
            }
        }
 public StringList(string language)
 {
     this.m_Language = language;
     this.m_Table = new Hashtable();
     string filePath = Client.GetFilePath(string.Format("cliloc.{0}", language));
     if (filePath == null)
     {
         this.m_Entries = new StringEntry[0];
         return;
     }
     ArrayList arrayLists = new ArrayList();
     using (BinaryReader binaryReader = new BinaryReader(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
     {
         binaryReader.ReadInt32();
         binaryReader.ReadInt16();
         while (binaryReader.PeekChar() != -1)
         {
             int num = binaryReader.ReadInt32();
             binaryReader.ReadByte();
             int num1 = binaryReader.ReadInt16();
             if (num1 > (int)StringList.m_Buffer.Length)
             {
                 StringList.m_Buffer = new byte[num1 + 1023 & -1024];
             }
             binaryReader.Read(StringList.m_Buffer, 0, num1);
             string str = Encoding.UTF8.GetString(StringList.m_Buffer, 0, num1);
             arrayLists.Add(new StringEntry(num, str));
             this.m_Table[num] = str;
         }
     }
     this.m_Entries = (StringEntry[])arrayLists.ToArray(typeof(StringEntry));
 }
Example #10
0
        public void Decrypt(string inputFile, string outputFile, string password)
        {
            byte[] byteKeys = this.GetKey(password);
            byte[] ivBytes = this.GetIV();

            var decryptor = _symmetricAlgorithm.CreateDecryptor(byteKeys, ivBytes);
            int blockSize = _symmetricAlgorithm.BlockSize / 8;

            using (var binaryReader = new BinaryReader(File.OpenRead(inputFile), new ASCIIEncoding()))
            {
                using (var resultFile = File.Create(outputFile))
                {
                    using (var cryptoStream = new CryptoStream(resultFile, decryptor, CryptoStreamMode.Write))
                    {
                        using (var binaryWriter = new BinaryWriter(cryptoStream))
                        {
                            while (binaryReader.PeekChar() != -1)
                            {
                                binaryWriter.Write(binaryReader.ReadBytes(blockSize));
                            }
                        }
                    }
                }
            }
        }
Example #11
0
        protected void LoadDirectoriesFromStream( BinaryReader reader )
        {
            Directories = new List<DirectoryEntry>();

            while( reader.PeekChar() != INT_RecordSeparator )
            {
                var entry = CreateDirectoryObject();
                char[] buffer = reader.ReadChars( Leader.SizeFieldTag );
                string tag = new string( buffer );
                if( tag == "0000" )
                    entry.Tag = DirectoryDataType.Filename;
                else if( tag == "0001" )
                    entry.Tag = DirectoryDataType.DDFRecordIdentifier;
                else
                    entry.Tag = (DirectoryDataType)Enum.Parse( typeof( DirectoryDataType ), tag );
                if( entry.Tag == DirectoryDataType.Unknown )
                    throw new InvalidDataException( String.Format("Unknown tag {0}", tag) );
                buffer = reader.ReadChars( Leader.SizeFieldLength );
                entry.Length = int.Parse( new string( buffer ) );
                buffer = reader.ReadChars( Leader.SizeFieldPos );
                entry.Position = int.Parse( new string( buffer ) );
                Directories.Add( entry );
            }
            reader.Read();
        }
Example #12
0
        private List<KeyValuePair<DDRDirectoryEntry, byte[]>> GetRowData( BinaryReader reader )
        {
            var rowData = new List<KeyValuePair<DDRDirectoryEntry, byte[]>>();
            foreach( DirectoryEntry entry in Directories.OrderBy( dir => dir.Position ) )
            {
                int peek = reader.PeekChar();
                if( peek == INT_RecordSeparator || peek == INT_EOF )
                    break;
                var fieldDescDir = DescriptiveRecord.Directories.OfType<DDRDirectoryEntry>().FirstOrDefault( ddrEntry => ddrEntry.Fields.First() == entry.Tag.GetDescription() );

                byte[] block;
                if( fieldDescDir.SubFields != null && fieldDescDir.SubFields.Any( field => field.Type == FieldType.Binary ) )
                    block = reader.ReadBytes( entry.Length - 1 );
                else
                    block = ReadUntilSeparator( reader );
                reader.Read();

                if( fieldDescDir.Type == DDRDirectoryEntryType.ArrayFieldList )
                {
                    int dataLength = fieldDescDir.SubFields.Sum( field => field.Length.Value );
                    for( int i = 0; i < block.Length / dataLength; i++ )
                    {
                        byte[] subBlock = new byte[ dataLength ];
                        Array.Copy( block, i * dataLength, subBlock, 0, dataLength );
                        rowData.Add( new KeyValuePair<DDRDirectoryEntry, byte[]>( fieldDescDir, subBlock ) );
                    }
                }
                else
                {
                    rowData.Add( new KeyValuePair<DDRDirectoryEntry, byte[]>( fieldDescDir, block ) );
                }
            }
            return rowData;
        }
Example #13
0
        private void button_choose_file_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Text files (*.txt)|*.txt";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                BinaryReader sR = new BinaryReader(File.Open(ofd.FileName, FileMode.Open), Encoding.ASCII);
                int i = 0;
                while (sR.PeekChar() != -1)
                {
                    i++;
                  sR.ReadByte();

                }
                sR.Close();
                BinaryReader sR2 = new BinaryReader(File.Open(ofd.FileName, FileMode.Open), Encoding.ASCII);
                fileData = sR2.ReadBytes(i);

                sR2.Close();
            }

            textBox1.Text = ofd.FileName.Split('\\')[ofd.FileName.Split('\\').Length-1];

            textBox2.Enabled = true;
        }
        public static TapFile ReadTapFile(Stream inputStream, string fileName)
        {
            TapFile resultFile = new TapFile(fileName);

            using (BinaryReader fileReader = new BinaryReader(inputStream, Encoding.GetEncoding("ISO-8859-1")))
            {
                while (fileReader.PeekChar() >= 0)
                {
                    TapDataBlock dataBlock = ReadTapDataBlock(fileReader);
                    resultFile.DataBlocks.Add(dataBlock);

                    TapeSection section = new TapeSection(dataBlock);
                    resultFile.Sections.Add(section);
                }
            }
            TapeSection lastSection = resultFile.Sections[resultFile.Sections.Count-1];
            TapeSoundSequence lastSoundSequence = lastSection.SoundSequences[lastSection.SoundSequences.Count - 1];
            if(lastSoundSequence.GetType() != typeof(PauseSequence))
            {
                lastSection.SoundSequences.Add(new PauseSequence("End of tape", 1));
            }

            foreach (TapeSection section in resultFile.Sections)
            {
                resultFile.Duration += section.Duration;
            }
            resultFile.Description = ""; // Tap file do not contain metadata

            return resultFile;
        }
Example #15
0
        public IEnumerable<IAsn1Element> Parse(Stream asn1Stream)
        {
            using (var reader = new BinaryReader(asn1Stream))
            {
                while (reader.PeekChar() > -1)
                {
                    var element = GetAsn1ParsedElement(reader);

                    switch (element.Tag)
                    {
                        case 2:
                            yield return ParseInteger(element);
                            break;
                        case 4:
                            yield return ParseOctetString(element);
                            break;
                        case 48:
                            yield return ParseSequence(element);
                            break;
                        default:
                            yield return new Asn1UnknownElement(element.Tag, element.Data);
                            break;
                    }
                }
            }
        }
        internal static IBencodingType Decode(BinaryReader inputStream)
        {
            char next = (char)inputStream.PeekChar();

            switch (next)
            {
                case 'i':
                    // Integer
                    return BInt.Decode(inputStream);

                case 'l':
                    // List
                    return BList.Decode(inputStream);

                case 'd':
                    // List
                    return BDict.Decode(inputStream);

                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    // String
                    return BString.Decode(inputStream);
            }

            return null;
        }
        public SWFReader(Stream stream)
        {
            Tags = new List<Tag>();
            using (var b = new BinaryReader(stream))
                if (b.PeekChar() == 'C') //Zlib Compressed
                    Uncompress(b);

            if (SWFBinary == null)
                SWFBinary = new BinaryReader(stream);

            ReadSWFHeader();

            bool readEndTag = false;
            while (SWFBinary.BaseStream.Position < SWFBinary.BaseStream.Length && !readEndTag)
            {
                Tag b = ReadTag();
                if (b == null)
                    continue;

                if (b is End)
                    readEndTag = true;

                Tags.Add(b);
            }
        }
        public DocumentParser(string path)
        {
            using (var br = new BinaryReader(File.OpenRead(path))) {
                if (br.PeekChar() == '@')
                {
                    List<byte> processed = new List<byte>();

                    while (br.BaseStream.Position != br.BaseStream.Length)
                    {
                        var s = IWantToFiddle(ReadLine(br, 256));
                        if (s != null)
                        {
                            processed.AddRange(s);
                            processed.Add(13);
                            processed.Add(10);
                        }
                    }

                    data = new byte[processed.Count];
                    processed.CopyTo(data);

                    bFiddled = true;
                }
                else
                {
                    data = br.ReadBytes((int)br.BaseStream.Length);
                }
            }
        }
Example #19
0
        public static List<Customer> GetCustomers()
        {
            // if the directory doesn't exist, create it
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            // create the array list for customers
            List<Customer> customers = new List<Customer>();

            // create the object for the input stream for a binary file
            BinaryReader binaryIn =
                new BinaryReader(
                new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read));

            // read the data from the file and store it in the List<>
            while (binaryIn.PeekChar() != -1)
            {
                Customer c = new Customer();
                c.FirstName = binaryIn.ReadString();
                c.LastName = binaryIn.ReadString();
                c.Email = binaryIn.ReadString();
                customers.Add(c);
            }

            binaryIn.Close();

            return customers;
        }
    private bool ValidateCore(string token, Guid userId, ContactChallengePurpose purpose, string stamp) {
      try {
        byte[] unprotectedData = Protector.Unprotect(Convert.FromBase64String(token));
        var ms = new MemoryStream(unprotectedData);
        using (var reader = new BinaryReader(ms, DefaultEncoding, true)) {
          DateTimeOffset creationTime = new DateTimeOffset(reader.ReadInt64(), TimeSpan.Zero);
          DateTimeOffset expirationTime = creationTime + TokenLifespan;
          if (expirationTime < DateTimeOffset.UtcNow) {
            return false;
          }

          string tokenUserId = reader.ReadString();
          if (!string.Equals(tokenUserId, userId.ToString(), StringComparison.OrdinalIgnoreCase)) {
            return false;
          }

          var tokenPurpose = reader.ReadString();
          if (!string.Equals(tokenPurpose, purpose.ToString())) {
            return false;
          }

          var tokenStamp = reader.ReadString();
          if (reader.PeekChar() != -1) {
            return false;
          }

          bool isTokenValid = tokenStamp == stamp;
          return isTokenValid;
        }
      } catch {
        // do not leak exception
        return false;
      }
    }
Example #21
0
		public static List<Product> GetProducts()
		{
			// if the directory doesn't exist, create it
			if (!Directory.Exists(dir))
				Directory.CreateDirectory(dir);

			// create the object for the input stream for a binary file
			BinaryReader binaryIn = 
				new BinaryReader(
				new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read));

			// create the array list
			List<Product> products = new List<Product>();

			// read the data from the file and store it in the List<Product>
			while (binaryIn.PeekChar() != -1)
			{
				Product product = new Product();
				product.Code = binaryIn.ReadString();
				product.Description = binaryIn.ReadString();
				product.Price = binaryIn.ReadDecimal();
				products.Add(product);
			}

			// close the input stream for the binary file
			binaryIn.Close();

			return products;
		}
 public List<Book> ReadFrom(string FileName)
 {
     if (FileName.Equals(string.Empty) || FileName == null)
         throw new ArgumentNullException("File name not found!");
     //bookList.Clear();
     try
     {
         List<Book> bookList = new List<Book>();
         BinaryReader read = new BinaryReader(File.Open(FileName, FileMode.OpenOrCreate));
         while (read.PeekChar() > -1)
         {
             string author = read.ReadString();
             string title = read.ReadString();
             int PA = read.ReadInt32();
             string genre = read.ReadString();
             bookList.Add(new Book(author, title, PA, genre));
         }
         read.Close();
         return bookList;
     }
     catch (FileNotFoundException)
     {
         throw new InvalidDataException("File not found!");
     }
 }
        public int CheckTopScore()
        {
            BinaryReader br = new BinaryReader(new FileStream("ScoreData.txt", FileMode.Open));
            while (br.PeekChar() != -1)
            {
                SavePlayerScore sps = new SavePlayerScore(br.ReadString(), br.ReadInt32());
                SPSArrayList.Add(sps);
            }
            br.Close();

            SortOnPlayerScore sops = new SortOnPlayerScore();
            SPSArrayList.Sort(sops);

            int Listsize = 0;

            foreach (SavePlayerScore ba in SPSArrayList)
            {
                Listsize++;
                Console.WriteLine("{0}", ba.GetScore());
            }
            int[] WhoIsTheTop = new int[Listsize];

            int count2 = 0;
            foreach (SavePlayerScore ba in SPSArrayList)
            {
                WhoIsTheTop[count2] = ba.GetScore();
                count2++;
            }

            if (Listsize >= 1)
                return WhoIsTheTop[0];
            else
                return 0;
        }
Example #24
0
        public Assembly(Stream s)
        {
            var dict = new Dictionary<byte, Type>();
            var types = typeof (Assembly).Assembly.GetTypes();
            foreach (var t in types)
            {
                if (!t.IsSubclassOf(typeof (Instruction)))
                    continue;
                var instance = (Instruction) Activator.CreateInstance(t);
                var id = instance.Type;
                dict[id] = t;
            }

            using (var reader = new BinaryReader(s))
            {
                ReaderHeader(reader);
                while (reader.PeekChar() > -1)
                {
                    var type = reader.ReadByte();
                    var ins = dict[type];
                    var i = (Instruction) Activator.CreateInstance(ins);
                    i.ReadFrom(reader);
                    _template.Add(i);
                }
            }
        }
Example #25
0
 public CFileStatus(MemoryStream buffer, bool readHash)
 {
     BinaryReader reader = new BinaryReader(buffer);
     if (readHash) FileHash = reader.ReadBytes(16);
     if (reader.PeekChar() == -1)
         nChunks = 0;
     else
         nChunks = reader.ReadUInt16();
     if (nChunks > 0)
     {
         Chunks = new byte[nChunks];
         short bitProcesados = 0;
         byte bitArray;
         short i;
         while (bitProcesados != nChunks)
         {
             bitArray = reader.ReadByte();
             i = 0;
             do //for (i=0;i!=8;i++)
             {
                 Chunks[bitProcesados] = (((bitArray >> i) & 1) == 1) ? (byte)Protocol.ChunkState.Complete : (byte)Protocol.ChunkState.Empty;
                 bitProcesados++;
                 i++;
             }
             while ((i != 8) & (bitProcesados != nChunks));
         }
     }
     //          reader.Close();
     //          buffer.Close();
     //          reader=null;
     //          buffer=null;
 }
 //--Methods
 public UnknownChunk(string id, int size, BinaryReader reader)
     : base(id, size)
 {
     data = reader.ReadBytes(size);
     if (size % 2 == 1 && reader.PeekChar() == 0)
         reader.ReadByte();
 }
Example #27
0
        private void ValidateDisposedExceptions(BinaryReader binaryReader)
        {
            byte[] byteBuffer = new byte[10];
            char[] charBuffer = new char[10];

            Assert.Throws<ObjectDisposedException>(() => binaryReader.PeekChar());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(byteBuffer, 0, 1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(charBuffer, 0, 1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBoolean());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadByte());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBytes(1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChar());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChars(1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDecimal());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDouble());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt16());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt32());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt64());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSByte());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSingle());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadString());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt16());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt32());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt64());
        }
        public IEnumerable<Packet> ReadPackets(string file)
        {
            using (var gr = new BinaryReader(new FileStream(file, FileMode.Open, FileAccess.Read), Encoding.ASCII))
            {
                gr.ReadBytes(3); // PKT
                gr.ReadBytes(2); // 0x02, 0x02
                gr.ReadByte(); // 0x06
                Build = gr.ReadUInt16(); // build
                gr.ReadBytes(4); // client locale
                gr.ReadBytes(20); // packet key
                gr.ReadBytes(64); // realm name

                var packets = new List<Packet>();
                while (gr.PeekChar() >= 0)
                {
                    Direction direction = gr.ReadByte() == 0xff ? Direction.Server : Direction.Client;
                    uint unixtime = gr.ReadUInt32();
                    uint tickcount = gr.ReadUInt32();
                    uint size = gr.ReadUInt32();
                    OpCodes opcode = (direction == Direction.Client) ? (OpCodes)gr.ReadUInt32() : (OpCodes)gr.ReadUInt16();
                    byte[] data = gr.ReadBytes((int)size - ((direction == Direction.Client) ? 4 : 2));

                    packets.Add(new Packet(direction, opcode, data, unixtime, tickcount));
                }
                return packets;
            }
        }
        public static void AddCliloc( string lang )
        {
            StringList list = StringList.GetList( lang );
            if ( list == null )
                list = StringList.AddLanguage( lang );

            string path = Core.FindDataFile( String.Format( "cliloc.{0}", lang ) );

            if ( path == null )
            {
                Console.WriteLine( "Warning: cliloc.{0} not found", lang );
                return;
            }

            using ( BinaryReader bin = new BinaryReader( new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ), Encoding.ASCII ) )
            {
                bin.ReadInt32();
                bin.ReadInt16();

                Encoding utf8 = Encoding.GetEncoding( "UTF-8", new EncoderReplacementFallback(""), new DecoderReplacementFallback("") );

                while ( bin.PeekChar() != -1 )
                {
                    int number = bin.ReadInt32();
                    bin.ReadByte(); //State in Cliloc
                    int length = bin.ReadInt16(); //Max of 65535 characters

                    StringEntry entry = new StringEntry( number, LState.Original, StringList.FormatArguments( utf8.GetString( bin.ReadBytes( length ) ) ) );

                    list.Table[number] = entry;
                }

                bin.Close();
            }
        }
Example #30
0
        public static GSDump LoadDump(String FileName)
        {
            GSDump dmp = new GSDump();

            BinaryReader br = new BinaryReader(System.IO.File.Open(FileName, FileMode.Open));
            dmp.CRC = br.ReadInt32();

            Int32 ss = br.ReadInt32();
            dmp.StateData = br.ReadBytes(ss);

            dmp.Registers = br.ReadBytes(8192);

            while (br.PeekChar() != -1)
            {
                GSType id = (GSType)br.ReadByte();
                switch (id)
                {
                    case GSType.Transfer:
                        GSTransfer data = new GSTransfer();

                        byte index = br.ReadByte();

                        data.id = id;
                        data.Path = (GSTransferPath)index;

                        Int32 size = br.ReadInt32();

                        List<byte> Data = new List<byte>();
                        Data.AddRange(br.ReadBytes(size));
                        data.data = Data.ToArray();
                        dmp.Data.Add(data);
                        break;
                    case GSType.VSync:
                        GSData dataV = new GSData();
                        dataV.id = id;
                        dataV.data = br.ReadBytes(1);
                        dmp.Data.Add(dataV);
                        break;
                    case GSType.ReadFIFO2:
                        GSData dataR = new GSData();
                        dataR.id = id;
                        Int32 sF = br.ReadInt32();
                        dataR.data = BitConverter.GetBytes(sF);
                        dmp.Data.Add(dataR);
                        break;
                    case GSType.Registers:
                        GSData dataRR = new GSData();
                        dataRR.id = id;
                        dataRR.data = br.ReadBytes(8192);
                        dmp.Data.Add(dataRR);
                        break;
                    default:
                        break;
                }
            }
            br.Close();

            return dmp;
        }