ReadByte() public method

public ReadByte ( ) : byte
return byte
Example #1
0
        public MapInfo(BinaryReader reader)
        {
            Index = reader.ReadInt32();
            FileName = reader.ReadString();
            Title = reader.ReadString();
            MiniMap = reader.ReadUInt16();
            Light = (LightSetting) reader.ReadByte();
            if (Envir.LoadVersion >= 3) BigMap = reader.ReadUInt16();
            if (Envir.LoadVersion >= 10) reader.ReadByte();

            int count = reader.ReadInt32();
            for (int i = 0; i < count; i++)
                SafeZones.Add(new SafeZoneInfo(reader) { Info = this });

            count = reader.ReadInt32();
            for (int i = 0; i < count; i++)
                Respawns.Add(new RespawnInfo(reader));

            count = reader.ReadInt32();
            for (int i = 0; i < count; i++)
                NPCs.Add(new NPCInfo(reader));

            count = reader.ReadInt32();
            for (int i = 0; i < count; i++)
                Movements.Add(new MovementInfo(reader));
        }
Example #2
0
        static Map LoadHeaderInternal( [NotNull] Stream stream ) {
            if( stream == null ) throw new ArgumentNullException( "stream" );
            BinaryReader bs = new BinaryReader( stream );

            // Read in the magic number
            if( bs.ReadByte() != 0xbe || bs.ReadByte() != 0xee || bs.ReadByte() != 0xef ) {
                throw new MapFormatException( "MinerCPP map header is incorrect." );
            }

            // Read in the map dimesions
            // Saved in big endian for who-know-what reason.
            // XYZ(?)
            int width = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
            int height = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
            int length = IPAddress.NetworkToHostOrder( bs.ReadInt16() );

            // ReSharper disable UseObjectOrCollectionInitializer
            Map map = new Map( null, width, length, height, false );
            // ReSharper restore UseObjectOrCollectionInitializer

            // Read in the spawn location
            // XYZ(?)
            map.Spawn = new Position {
                X = IPAddress.NetworkToHostOrder( bs.ReadInt16() ),
                Z = IPAddress.NetworkToHostOrder( bs.ReadInt16() ),
                Y = IPAddress.NetworkToHostOrder( bs.ReadInt16() ),
                R = bs.ReadByte(),
                L = bs.ReadByte()
            };

            // Skip over the block count, totally useless
            bs.ReadInt32();

            return map;
        }
Example #3
0
        protected override void check(object sender, EventArgs e) {
            int read_width = 0;
            int read_height = 0;
            int read_cwidth = 0;
            int read_cheight = 0;
            int read_quality = 0;
            int read_samples = 0;

            using (Stream stream = new FileStream(outPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                using (BinaryReader reader = new BinaryReader(stream, Encoding.Default)) {
                    read_width = reader.ReadUInt16();
                    read_height = reader.ReadUInt16();
                    read_cwidth = reader.ReadUInt16();
                    read_cheight = reader.ReadUInt16();
                    read_quality = reader.ReadByte();
                    read_samples = reader.ReadByte();
                }
            }

            System.Windows.Forms.MessageBox.Show(
                "image width: " + inC1.imageWidth + " = " + read_width +
                "\nimage height: " + inC1.imageHeight + " = " + read_height +
                "\nchannel width: " + inC1.channelWidth + " = " + read_cwidth +
                "\nchannel height: " + inC1.channelHeight + " = " + read_cheight +
                "\nquality: " + inC1.quantizeQuality + " = " + read_quality +
                "\nsamples: " + inC1.samplingMode + " = " + (DataBlob.Samples)read_samples
                , "File Information");
        }
        public void Receive(DataPackage pkgData)
        {
            //收到上报参数
            ReportedParameterItem reportParameterItem = new ReportedParameterItem();

            byte[] dataBuffer = pkgData.PureData;

            using (MemoryStream ms = new MemoryStream(dataBuffer))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    reportParameterItem.StateInterval = br.ReadInt16();
                    reportParameterItem.ThuEnable = br.ReadByte();
                    reportParameterItem.TempInterval = br.ReadByte();
                    reportParameterItem.HumiInterval = br.ReadByte();
                    reportParameterItem.GPIOEnable = br.ReadByte();
                    //br.ReadBytes(6);
                }
            }

            if (OnDataChanged != null)
            {
                DataHandlerEventArgs eventArgs = new DataHandlerEventArgs();
                eventArgs.CMD_ID = pkgData.CtrlHead.CMD_ID;
                eventArgs.Value = reportParameterItem;
                OnDataChanged(this, eventArgs);
            }
        }
Example #5
0
		void readSettings (BinaryReader inStream)
		{
			setColor (readInt (inStream));
			setTransparency (inStream.ReadByte ());
			setReflectivity (inStream.ReadByte ());
			setFlat (inStream.ReadBoolean ());
		}
        public void ByteArraySegmentedStream_ReadByteTest()
        {
            var arr = new byte[100];
            for (byte i = 0; i < 100; i++)
                arr[i] = i;

            var segments = new List<ArraySegment<byte>>();
            

            var stream = new ByteArraySegmentedStream(true);
            stream.AddSegment(new ArraySegment<byte>(arr, 0, 5));
            stream.AddSegment(new ArraySegment<byte>(arr, 2, 5));
            stream.AddSegment(new ArraySegment<byte>(arr, 10, 10));

            var reader = new BinaryReader(stream);

            for (byte i = 0; i < 5; i++)
                Assert.AreEqual(i, reader.ReadByte());

            for (byte i = 0; i < 5; i++)
                Assert.AreEqual(i + 2, reader.ReadByte());

            for (byte i = 0; i < 10; i++)
                Assert.AreEqual(i + 10, reader.ReadByte());
        }
 private void PlayerInfo(BinaryReader gr)
 {
     AppendFormatLine("FreePoints: {0}", gr.ReadUInt32());
     var speccount=gr.ReadByte();
     AppendFormatLine("SpectsCount: {0}", speccount);
     AppendFormatLine("ActiveSpec: {0}", gr.ReadByte());
     if (speccount > 0)
     {
         for (int id = 0; id < 1; id++)
         {
             var talidcount = gr.ReadByte();
             AppendFormatLine("TalentIDCount: {0}", talidcount);
             for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 12; j++)
               {
                   AppendFormatLine("TalentID {0}", gr.ReadUInt32());
                     AppendFormatLine("CurRanc: {0}", gr.ReadByte());
                 }
             }
             var GLYPHMAX = gr.ReadByte();
             AppendFormatLine("GLYPHMAX: {0}", GLYPHMAX);
           for (int g = 0; g < GLYPHMAX; g++)
             {
                 AppendFormatLine("GLYPID: {0}", gr.ReadUInt16());
             }
         }
     }
 }
        /// <summary> Parses the Replay.Messages.Events file. </summary>
        /// <param name="buffer"> Buffer containing the contents of the replay.messages.events file. </param>
        /// <returns> A list of chat messages parsed from the buffer. </returns>
        public static void Parse(Replay replay, byte[] buffer)
        {
            using (var stream = new MemoryStream(buffer))
            {
                using (var reader = new BinaryReader(stream))
                {
                    int totalTime = 0;
                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        // While not EOF
                        var message = new ChatMessage();

                        var time = ParseTimestamp(reader);

                        // sometimes we only have a header for the message
                        if (reader.BaseStream.Position >= reader.BaseStream.Length) 
                            break;

                        message.PlayerId = reader.ReadByte();

                        // I believe this 'PlayerId' is an index for this client list, which can include observers
                        // var player = replay.ClientList[message.PlayerId];

                        totalTime += time;
                        var opCode = reader.ReadByte();

                        if (opCode == 0x80)
                            reader.ReadBytes(4);
                        else if (opCode == 0x83)
                            reader.ReadBytes(8);
                        else if (opCode == 2 && message.PlayerId <= 10)
                        {
                            if (message.PlayerId == 80)
                                continue;

                            message.MessageTarget = (ChatMessageTarget)(opCode & 7);
                            var length = reader.ReadByte();

                            if ((opCode & 8) == 8)
                                length += 64;

                            if ((opCode & 16) == 16)
                                length += 128;

                            message.Message = Encoding.UTF8.GetString(reader.ReadBytes(length));
                        }
                        else
                        {
                            
                        }

                        if (message.Message != null)
                        {
                            message.Timestamp = new TimeSpan(0, 0, (int)Math.Round(totalTime / 16.0));
                            replay.ChatMessages.Add(message);
                        }
                    }
                }
            }
        }
        public PaletteMap(IffChunk Chunk)
            : base(Chunk)
        {
            MemoryStream MemStream = new MemoryStream(Chunk.Data);
            BinaryReader Reader = new BinaryReader(MemStream);

            //Reader.BaseStream.Position = INDEX_PALTID;
            /*m_ID = (uint)numPalettes++;
            m_ID = Reader.ReadUInt32();*/

            //m_Colors = new int[256];
            m_Colors = new Color[256];

            Reader.BaseStream.Position = 16;
            /*if (Reader.BaseStream.ReadByte() == 0)
                Reader.BaseStream.Position = 80;
            else
                Reader.BaseStream.Position = 16;*/

            for (int i = 0; i < 256; i++)
            {
                //Reader.BaseStream.Position += 3;
                byte[] colors = new byte[] {};
                if ((Reader.BaseStream.Length - Reader.BaseStream.Position) >= 3)
                    m_Colors[i] = Color.FromArgb(Reader.ReadByte(), Reader.ReadByte(), Reader.ReadByte());
                else
                    m_Colors[i] = Color.FromArgb(255, 0x80, 0x80, 0x80);
            }

            Reader.Close();
        }
Example #10
0
 public static Message ReadMessage(Stream input)
 {
     var buffer = new BinaryReader(input);
     Message msg = new Message();
     msg.ProtocolVersion = buffer.ReadByte();
     msg.MessageType = buffer.ReadByte();
     // read kv
     IDictionary<string, object> dict = new Dictionary<string, object>();
     short headerType = buffer.ReadInt16();
     while (headerType != MessageType.HeaderType.EndOfHeaders)
     {
         if (headerType == MessageType.HeaderType.Custom)
             dict.Add(ReadCountedString(buffer), ReadCustomValue(buffer));
         else if (headerType == MessageType.HeaderType.StatusCode)
             msg.StatusCode = buffer.ReadInt32();
         else if (headerType == MessageType.HeaderType.StatusPhrase)
             msg.StatusPhase = ReadCountedString(buffer);
         else if (headerType == MessageType.HeaderType.Flag)
             msg.Flag = buffer.ReadInt32();
         else if (headerType == MessageType.HeaderType.Token)
             msg.Token = ReadCountedString(buffer);
         headerType = buffer.ReadInt16();
     }
     msg.Content = dict;
     return msg;
 }
Example #11
0
 public void Read(BinaryReader reader, float CoordZ, float scale)
 {
     Position = new float[3];
     for (int i = 0; i < Position.Length; i++)
     {
         Position[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale;
     }
     NormalVector = new float[3];
     for (int i = 0; i < NormalVector.Length; i++)
     {
         NormalVector[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     }
     UV = new float[2];
     for (int i = 0; i < UV.Length; i++)
     {
         UV[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0);
     }
     BoneNum = new WORD[2];
     for (int i = 0; i < BoneNum.Length; i++)
     {
         BoneNum[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
     }
     BoneWeight = reader.ReadByte();
     NonEdgeFlag = reader.ReadByte();
     Position[2] *= CoordZ;
     NormalVector[2] *= CoordZ;
 }
 protected override void ReadContentFrom(BinaryReader reader)
 {
     //USHORT 	version 	Version number (0 or 1).
     //USHORT 	numRecs 	Number of VDMX groups present
     //USHORT 	numRatios 	Number of aspect ratio groupings
     //Ratio 	ratRange[numRatios] 	Ratio ranges (see below for more info)
     //USHORT 	offset[numRatios] 	Offset from start of this table to the VDMX group for this ratio range.
     //Vdmx 	groups 	The actual VDMX groupings (documented below)
     //Ratio Record Type 	Name 	Description
     //BYTE 	bCharSet 	Character set (see below).
     //BYTE 	xRatio 	Value to use for x-Ratio
     //BYTE 	yStartRatio 	Starting y-Ratio value.
     //BYTE 	yEndRatio 	Ending y-Ratio value.
     ushort version = reader.ReadUInt16();
     ushort numRecs = reader.ReadUInt16();
     ushort numRatios = reader.ReadUInt16();
     ratios = new Ratio[numRatios];
     for (int i = 0; i < numRatios; ++i)
     {
         ratios[i] = new Ratio(
             reader.ReadByte(),
             reader.ReadByte(),
             reader.ReadByte(),
             reader.ReadByte());
     }
     short[] offsets = Utils.ReadInt16Array(reader, numRatios);
     //------
     //actual vdmx group
     //TODO: implement this
 }
Example #13
0
 public override void Decode()
 {
     using (var br = new BinaryReader(new MemoryStream(GetData())))
     {
         m_vAccountId = br.ReadInt64WithEndian();
         m_vPassToken = br.ReadScString();
         m_vClientMajorVersion = br.ReadInt32WithEndian();
         m_vClientContentVersion = br.ReadInt32WithEndian();
         m_vClientBuild = br.ReadInt32WithEndian();
         m_vResourceSha = br.ReadScString();
         m_vUDID = br.ReadScString();
         m_vOpenUDID = br.ReadScString();
         m_vMacAddress = br.ReadScString();
         m_vDevice = br.ReadScString();
         br.ReadInt32WithEndian();//00 1E 84 81, readDataReference for m_vPreferredLanguage
         m_vPreferredDeviceLanguage = br.ReadScString();
         //unchecked
         m_vPhoneId = br.ReadScString();
         m_vGameVersion = br.ReadScString();
         br.ReadByte();//01
         br.ReadInt32WithEndian();//00 00 00 00
         m_vSignature2 = br.ReadScString();
         m_vSignature3 = br.ReadScString();
         br.ReadByte();//01
         m_vSignature4 = br.ReadScString();
         m_vClientSeed = br.ReadUInt32WithEndian();
         Debugger.WriteLine("[M] Client with user id " + m_vAccountId + " accessing with " + m_vDevice);
         if(GetMessageVersion() >=7 )//7.200
         {
             br.ReadByte();
             br.ReadUInt32WithEndian();
             br.ReadUInt32WithEndian();
         }
     }
 }
Example #14
0
        public override ISqlObject DeserializeObject(Stream stream)
        {
            var reader = new BinaryReader(stream);

            var type = reader.ReadByte();

            if (type == 1) {
                var state = reader.ReadByte();
                if (state == 0)
                    return SqlDayToSecond.Null;

                var length = reader.ReadInt32();
                var bytes = reader.ReadBytes(length);
                return new SqlDayToSecond(bytes);
            }
            if (type == 2) {
                var state = reader.ReadByte();
                if (state == 0)
                    return SqlYearToMonth.Null;

                var months = reader.ReadInt32();
                return new SqlYearToMonth(months);
            }

            return base.DeserializeObject(stream);
        }
Example #15
0
        public void UOExtPacket(IClientPeer peer, byte header, byte[] buffer, int offset, short length)
        {
            MemoryStream ms = new MemoryStream(buffer, offset, length);
            BinaryReader br = new BinaryReader(ms);

            byte sequence = br.ReadByte();

            switch (sequence)
            {
                case (0x00):
                    byte version = br.ReadByte();
                    byte[] uoextmd5 = br.ReadBytes(16);
                    byte[] uoextguimd5 = br.ReadBytes(16);
                    if (version != 0)
                    {
                        peer.Close();
                    }
                    else
                    {

                        if (!ByteArrayCompare(uoextmd5, Dll.UOExt.MD5))
                        {
                            peer.Send(new Handshake(0x01));
                            peer.Send(Dll.UOExt.SimpleHeader);
                            foreach (DllContent dc in Dll.UOExt.Content)
                            {
                                peer.Send(dc);
                            }
                            return;
                        }
                        else if (!ByteArrayCompare(uoextguimd5, Dll.UOExtGUI.MD5))
                        {
                            peer.Send(new Handshake(0x02));
                            peer.Send(Dll.UOExtGUI.SimpleHeader);
                            foreach (DllContent dc in Dll.UOExtGUI.Content)
                            {
                                peer.Send(dc);
                            }
                        }
                        else
                        {
                            peer.Send(new Handshake(0x00));
                        }
                        peer.Send(m_libraryList);
                        peer.Send(m_pluginsList);
                    }
                    break;
                case (0x03):
                    for (short i = 0; i < Dll.Dlls.Length; i++)
                    {
                        peer.Send(Dll.Dlls[i].Header);
                        foreach (DllContent dc in Dll.Dlls[i].Content)
                        {
                            peer.Send(dc);
                        }
                    }
                    peer.Send(m_initComplete);
                    break;
            }
        }
 public List<PageItem> Process(int Flags, byte[] RecordData)
 {
     MemoryStream _ms = null;
     BinaryReader _br = null;
     MemoryStream _fs = null;
     BinaryReader _fr = null;
     try
     {
         _fs = new MemoryStream(BitConverter.GetBytes(Flags));
         _fr = new BinaryReader(_fs);
         _fr.ReadByte();
         //Byte 2 is the real flags
         byte RealFlags = _fr.ReadByte();
         // 0 1 2 3 4 5 6 7
         // X X X X X X C S                
         // if C = 1 Data int16 else float!
         bool Compressed = ((RealFlags & (int)Math.Pow(2, 6)) == (int)Math.Pow(2, 6));
         bool BrushIsARGB = ((RealFlags & (int)Math.Pow(2, 7)) == (int)Math.Pow(2, 7));
         _ms = new MemoryStream(RecordData);
         _br = new BinaryReader(_ms);
         Brush b;
         if (BrushIsARGB)
         {
             byte A, R, G, B;
             B = _br.ReadByte();
             G = _br.ReadByte();
             R = _br.ReadByte();
             A = _br.ReadByte();
             b = new SolidBrush(Color.FromArgb(A, R, G, B));
         }
         else
         {
             UInt32 BrushID = _br.ReadUInt32();
             EMFBrush EMFb = (EMFBrush)ObjectTable[(byte)BrushID];
             b = EMFb.myBrush;
         }
         Single StartAngle = _br.ReadSingle();
         Single SweepAngle = _br.ReadSingle();
         if (Compressed)
         {
             DoCompressed(StartAngle,SweepAngle, _br, b);
         }
         else
         {
             DoFloat(StartAngle,SweepAngle, _br, b);
         }
         return items;
     }
     finally
     {
         if (_br != null)
             _br.Close();
         if (_ms != null)
             _ms.Dispose();
         if (_fr != null)
             _fr.Close();
         if (_fs != null)
             _fs.Dispose();
     }
 }
Example #17
0
        public static Bitmap Open(string filePath)
        {
            using (var reader = new BinaryReader(new FileStream(filePath, FileMode.Open, FileAccess.Read)))
            {
                if(new string(reader.ReadChars(3)) != "PSF" || reader.ReadByte() != 1)
                    throw new Exception();

                var width = reader.ReadInt16();
                var height = reader.ReadInt16();
                var alphaMark = reader.ReadByte();

                var bmp = new Bitmap(width, height);
                var bmpData = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
                try
                {
                    var scanPointer = bmpData.Scan0;
                    for (var y = 0; y < bmpData.Height; y++, scanPointer += bmpData.Stride)
                    {
                        var dataBuffer = reader.ReadBytes(bmpData.Width * 4);
                        Marshal.Copy(dataBuffer, 0, scanPointer, dataBuffer.Length);
                    }

                    return bmp;
                }
                finally
                {
                    bmp.UnlockBits(bmpData);
                }

            }
        }
Example #18
0
        public override void Decode(Unmarshal context, MarshalOpcode op, BinaryReader source)
        {
            if (op == MarshalOpcode.ObjectEx2)
                IsType2 = true;

            Dictionary = new Dictionary<PyObject, PyObject>();
            List = new List<PyObject>();
            Header = context.ReadObject(source);

            while (source.BaseStream.Position < source.BaseStream.Length)
            {
                var b = source.ReadByte();
                if (b == PackedTerminator)
                    break;
                source.BaseStream.Seek(-1, SeekOrigin.Current);
                List.Add(context.ReadObject(source));
            }

            while (source.BaseStream.Position < source.BaseStream.Length)
            {
                var b = source.ReadByte();
                if (b == PackedTerminator)
                    break;
                source.BaseStream.Seek(-1, SeekOrigin.Current);
                var key = context.ReadObject(source);
                var value = context.ReadObject(source);
                Dictionary.Add(key, value);
            }
        }
        public PacketParser(Stream file)
        {
            var reader = new BinaryReader(file);
            Console.WriteLine("Reading packets!");

            while (file.Position != file.Length)
            {
                var packetOpcode = reader.ReadUInt32();
                var packetLength = reader.ReadUInt32();
                var packetTimestamp = reader.ReadUInt32();
                var packetType = reader.ReadByte();

                //Console.WriteLine("Opcode: 0x{0:X4}, Length: {1}", packetOpcode, packetLength);
                var packetBuffer = new byte[packetLength];
                for (var i = 0; i < packetLength; ++i)
                {
                    packetBuffer[i] = reader.ReadByte();
                }

                // ReSharper disable once ObjectCreationAsStatement
                // Handle the packet
                var p = new Packet(packetOpcode, packetLength, packetTimestamp, packetType, packetBuffer);
            }

            // Prevent exit.
            Console.ReadLine();
        }
Example #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static DibSection GetDibData(Stream stream)
        {
            var data = new DibSection();

            var reader = new BinaryReader(stream);
            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            if (reader.ReadByte() != 'B' || reader.ReadByte() != 'M')
            {
                throw new ArgumentException("Invalid bitmap stream.", "stream");
            }

            reader.BaseStream.Seek(10, SeekOrigin.Begin);
            var offBits = reader.ReadInt32();

            reader.ReadInt32(); // biSize

            data.Width = reader.ReadInt32();
            data.Height = reader.ReadInt32();

            reader.ReadInt16(); // biPlanes

            data.BitCount = reader.ReadInt16();

            reader.BaseStream.Seek(offBits, SeekOrigin.Begin);
            data.pixelsPerY = (((data.Width * (data.BitCount >> 3)) + 3) >> 2) << 2;
            data.data = reader.ReadBytes(data.pixelsPerY * data.Height);

            return data;
        }
Example #21
0
        /// <summary>
        /// Create a new piece of GameData from a byte array representation.
        /// </summary>
        /// <param name="byteArray">A byte array to create a GameData packet from.</param>
        public GameData(byte[] byteArray)
        {
            using (MemoryStream memoryStream = new MemoryStream(byteArray))
            {
                using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                {
                    Type = (GameDataType)binaryReader.ReadByte();
                    PlayerID = (int)binaryReader.ReadByte();
                    EventDetail = (int)binaryReader.ReadByte();

                    byte[] subData  = new byte[byteArray.Length - 3];
                    Array.ConstrainedCopy(byteArray, 3, subData, 0, byteArray.Length - 3);

                    if (Type == GameDataType.Movement)
                    {
                        TransformData = new TransformData(subData);
                    }
                    else if (Type == GameDataType.NewEntity)
                    {
                        EntityData = new EntityData(subData);
                    }
                    else if (Type == GameDataType.EntityStateChange)
                    {
                        EntityStateData = new EntityStateData(subData);
                    }
                }
            }

            return;
        }
Example #22
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        public override void Parse( Stream input )
        {
            BinaryReader br = new BinaryReader( input );

            _MatrixX = br.ReadByte();
            _MatrixY = br.ReadByte();
            _DivisorFLOAT = br.ReadUInt32();
            _BiasFLOAT = br.ReadUInt32();
            _MatrixValues = new List<uint>();
            for ( int i = 0; i < ( _MatrixX * _MatrixY ); i++ )
            {
                UInt32 a = br.ReadUInt32();
                _MatrixValues.Add( a );
            }
            _DefaultColor = new Rgba( this.Version );
            _DefaultColor.Parse( input );
            BitStream bits = new BitStream( input );

            uint reserved = bits.GetBits( 6 );
            if ( 0 != reserved )
            {
                throw new SwfFormatException( "ConvolutionFilter uses reserved bits" );
            }

            _Clamp = ( 0 != bits.GetBits( 1 ) );
            _PreserveAlpha = ( 0 != bits.GetBits( 1 ) );
        }
        public WowCorePacketReader(string filename)
        {
            _reader = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read), Encoding.ASCII);
            _reader.ReadBytes(3);                   // PKT
            Version = _reader.ReadUInt16();     // sniff version (0x0201, 0x0202)
            ushort build;
            switch (Version)
            {
                case 0x0201:
                    build = _reader.ReadUInt16();   // build
                    _reader.ReadBytes(40);          // session key
                    break;
                case 0x0202:
                    _reader.ReadByte();             // 0x06
                    build = _reader.ReadUInt16();   // build
                    _reader.ReadBytes(4);           // client locale
                    _reader.ReadBytes(20);          // packet key
                    _reader.ReadBytes(64);          // realm name
                    break;
                case 0x0300:
                    _reader.ReadByte();                  // snifferId
                    build = (ushort)_reader.ReadUInt32();// client build
                    _reader.ReadBytes(4);                // client locale
                    _reader.ReadBytes(40);               // session key
                    var optionalHeaderLength = _reader.ReadInt32();
                    _reader.ReadBytes(optionalHeaderLength);
                    break;
                default:
                    throw new Exception(String.Format("Unknown sniff version {0:X2}", Version));
            }

            UpdateFieldsLoader.LoadUpdateFields(build);
        }
Example #24
0
        // http://svn.python.org/projects/python/tags/r32/Lib/pickle.py
        private static bool ReadPickle(BinaryReader reader, out long result) {
            if (reader.ReadByte() != 128 || reader.ReadByte() != 3) {
                result = 0;
                return false;
            }

            switch (reader.ReadByte()) {
                case (byte)'F':
                    result = (long)reader.ReadSingle();
                    return true;
                case (byte)'N':
                    result = 0;
                    return true;
                case (byte)'I':
                case (byte)'J':
                    result = reader.ReadInt32();
                    return true;
                case (byte)'L':
                    result = reader.ReadInt64();
                    return true;
                case (byte)'M':
                    result = reader.ReadUInt16();
                    return true;
                case (byte)'K':
                    result = reader.ReadByte();
                    return true;
            }

            result = 0;
            return false;
        }
Example #25
0
 /// <summary>  
 /// 是否允许  
 /// </summary>  
 public static bool IsAllowedExtension(HttpPostedFile oFile, FileExtension[] fileEx)
 {
     int fileLen = oFile.ContentLength;
     byte[] imgArray = new byte[fileLen];
     oFile.InputStream.Read(imgArray, 0, fileLen);
     MemoryStream ms = new MemoryStream(imgArray);
     System.IO.BinaryReader br = new System.IO.BinaryReader(ms);
     string fileclass = "";
     byte buffer;
     try
     {
         buffer = br.ReadByte();
         fileclass = buffer.ToString();
         buffer = br.ReadByte();
         fileclass += buffer.ToString();
     }
     catch { }
     br.Close();
     ms.Close();
     foreach (FileExtension fe in fileEx)
     {
         if (Int32.Parse(fileclass) == (int)fe) return true;
     }
     return false;
 }
Example #26
0
 public FsaNajka(Stream stream, bool leaveOpen = false)
 {
     using (var file = new BinaryReader(stream, Encoding.UTF8, leaveOpen))
     {
         if (new string(file.ReadChars(4)) != "@naj")
             throw new Exception("Invalid header");
         if (file.ReadByte() != 1)
             throw new Exception("Invalid version");
         _type = file.ReadByte();
         _id2Char = file.ReadChars(file.ReadByte());
         _tree = file.ReadBytes((int)(file.BaseStream.Length - file.BaseStream.Position));
     }
     _id2ConvertedChar = new char[4][];
     _id2ConvertedChar[0] = _id2Char;
     _id2ConvertedChar[1] = new char[_id2Char.Length];
     _id2ConvertedChar[2] = new char[_id2Char.Length];
     _id2ConvertedChar[3] = new char[_id2Char.Length];
     for (var i = 0; i < _id2Char.Length; i++)
     {
         _id2ConvertedChar[1][i] = char.ToLowerInvariant(_id2Char[i]);
         _id2ConvertedChar[2][i] = _id2Char[i].RemoveDiacritics();
         _id2ConvertedChar[3][i] = char.ToLowerInvariant(_id2ConvertedChar[2][i]);
     }
     _nodePrefix = SinkTo(0, '!');
     _nodePostfix = SinkTo(0, '^');
 }
Example #27
0
        private ushort usTotalLength; //Шестнадцать битов для общей длины датаграммы (заголовок + сообщение)

        #endregion Fields

        #region Constructors

        public IPHeader(byte[] byBuffer, int nReceived)
        {
            try
            {
                MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived);
                BinaryReader binaryReader = new BinaryReader(memoryStream);

                byVersionAndHeaderLength = binaryReader.ReadByte();
                byDifferentiatedServices = binaryReader.ReadByte();
                usTotalLength = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                usIdentification = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                usFlagsAndOffset = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                byTTL = binaryReader.ReadByte();
                byProtocol = binaryReader.ReadByte();
                sChecksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                uiSourceIPAddress = (uint)(binaryReader.ReadInt32());
                uiDestinationIPAddress = (uint)(binaryReader.ReadInt32());

                byHeaderLength = byVersionAndHeaderLength;
                byHeaderLength <<= 4;
                byHeaderLength >>= 4;
                byHeaderLength *= 4;

                Array.Copy(byBuffer, byHeaderLength, byIPData, 0, usTotalLength - byHeaderLength);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Example #28
0
 public override void StateLoad(BinaryReader reader)
 {
     irqCounter = reader.ReadByte();
     irqLatch = reader.ReadByte();
     irqReload = reader.ReadBoolean();
     irqEnable = reader.ReadBoolean();
 }
Example #29
0
 public FileFormatVersion(BinaryReader reader)
 {
     Major = reader.ReadByte();
     Minor = reader.ReadByte();
     reader.BaseStream.Seek(-2, SeekOrigin.Current);
     Version = reader.ReadUInt16();
 }
Example #30
0
        public IPHeader(ArraySegment<byte> buffer)
        {

            using (var memoryStream = new MemoryStream(buffer.Array, buffer.Offset, buffer.Count))
            {
                using (var binaryReader = new BinaryReader(memoryStream))
                {
                    var versionAndHeaderLength = binaryReader.ReadByte();
                    var differentiatedServices = binaryReader.ReadByte();

                    DifferentiatedServices = (byte)(differentiatedServices >> 2);
                    CongestionNotification = (byte)(differentiatedServices & 0x03);

                    TotalLength = (ushort) IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                    Debug.Assert(TotalLength >= 20, "Invalid IP packet Total Lenght");
                    Identification = (ushort) IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                    _flagsAndOffset = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                    Ttl = binaryReader.ReadByte();

                    _protocol = binaryReader.ReadByte();

                    Checksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                    SourceAddress = new IPAddress(binaryReader.ReadUInt32());
                    DestinationAddress = new IPAddress(binaryReader.ReadUInt32());

                    HeaderLength = (versionAndHeaderLength & 0x0f) * 4;
                }
            }

            Raw = buffer;
            Data = new ArraySegment<byte>(buffer.Array, buffer.Offset + HeaderLength, MessageLength);
        }