ReadByte() public method

public ReadByte ( ) : byte
return byte
Beispiel #1
0
        public static bool IsIMGAllowedExtension(Stream stream)
        {
            System.IO.BinaryReader r = new System.IO.BinaryReader(stream);
            string fileclass         = "";
            byte   buffer;

            try
            {
                buffer     = r.ReadByte();
                fileclass  = buffer.ToString();
                buffer     = r.ReadByte();
                fileclass += buffer.ToString();
            }
            catch
            {
            }
            r.Close();
            if (fileclass == "255216" || fileclass == "7173" || fileclass == "6677" || fileclass == "13780")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
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;
 }
Beispiel #3
0
        /// <summary>
        ///图片检测类    是否允许
        /// </summary>
        public static bool IsAllowedExtension(HttpPostedFile oFile, FileExtension[] fileEx)
        {
            int fileLen  = oFile.ContentLength;
            var imgArray = new byte[fileLen];

            oFile.InputStream.Read(imgArray, 0, fileLen);
            var    ms        = new MemoryStream(imgArray);
            var    br        = new System.IO.BinaryReader(ms);
            string fileclass = "";

            try
            {
                byte buffer = br.ReadByte();
                fileclass  = buffer.ToString(CultureInfo.InvariantCulture);
                buffer     = br.ReadByte();
                fileclass += buffer.ToString(CultureInfo.InvariantCulture);
            }
            catch
            {
            }
            br.Close();
            ms.Close();
            foreach (FileExtension fe in fileEx)
            {
                if (Int32.Parse(fileclass) == (int)fe)
                {
                    return(true);
                }
            }
            return(false);
        }
        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();
        }
        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);
            }
        }
        // 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;
        }
Beispiel #7
0
        protected bool IsImageFile(HttpPostedFile httpPostedFile)
        {
            bool   isImage  = false;
            string fullPath = Server.MapPath("~/Profile Pic/" + FileUpload1.FileName);

            FileUpload1.SaveAs(fullPath);
            ImgPicture.ImageUrl = "~/Profile Pic/@" + FileUpload1.FileName;
            System.IO.FileStream   fs = new System.IO.FileStream(fullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
            string fileclass          = "";
            byte   buffer             = br.ReadByte();

            fileclass  = buffer.ToString();
            buffer     = br.ReadByte();
            fileclass += buffer.ToString();
            br.Close();
            fs.Close();

            // only allow images    jpg       gif     bmp     png
            String[] fileType = { "255216", "7173", "6677", "13780" };
            for (int i = 0; i < fileType.Length; i++)
            {
                if (fileclass == fileType[i])
                {
                    isImage = true;
                    break;
                }
            }
            return(isImage);
        }
Beispiel #8
0
        public void LoadPalette(string file)
        {
            try
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(file);
                if (fi.Exists)
                {
                    System.IO.MemoryStream ms = null;
                    System.IO.BinaryReader br = null;
                    System.IO.FileStream   fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    //If Filename = "D:\Games\items\°í°í.spr" Then Stop
                    byte[] @by = new byte[Convert.ToInt32(fs.Length) + 1];
                    fs.Read(@by, 0, Convert.ToInt32(fs.Length));
                    ms = new System.IO.MemoryStream(@by, 0, @by.Length);
                    br = new System.IO.BinaryReader(ms);
                    fs.Close();
                    fs.Dispose();

                    for (int i = 0; i <= 255; i++)
                    {
                        byte red   = br.ReadByte();
                        byte green = br.ReadByte();
                        byte blue  = br.ReadByte();
                        byte res   = br.ReadByte();
                        Palette[i] = System.Drawing.Color.FromArgb(red, green, blue);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #9
0
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.Type = binaryReader.ReadByte();
     this.Data = binaryReader.ReadByte();
     return(pointerQueue);
 }
Beispiel #10
0
        /// <summary>
        /// 获取文件格式
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public string CheckFileType(string path)
        {
            System.IO.FileStream   fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader r  = new System.IO.BinaryReader(fs);
            string bx = " ";
            byte   buffer;

            try
            {
                buffer = r.ReadByte();
                bx     = buffer.ToString();
                buffer = r.ReadByte();
                bx    += buffer.ToString();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
            r.Close();
            fs.Close();
            // 真实的文件类型
            fileExtension = bx;
            // 文件格式
            fileFormat = System.IO.Path.GetExtension(path);
            return(fileFormat);
        }
        /// <summary>
        /// 根据文件头判断上传的文件类型
        /// </summary>
        /// <modifyLog>
        /// @2015-1-22 @yaowq @新增
        /// </modifyLog>
        /// <param name="imgArray">字节数组</param>
        /// <returns>返回true或false</returns>
        public static bool IsPicture(byte[] imgArray)
        {
            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
            {
            }
            finally
            {
                br.Close();
                ms.Close();
            }
            return(Array.IndexOf(ExtArray.ImageExt, fileclass) > -1);

            if (fileclass == "255216" || fileclass == "7173" || fileclass == "13780" || fileclass == "6677")//255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
            {
                return(true);
            }
            return(false);
        }
Beispiel #12
0
        //充填媒体帧
        public void SetBytes(Stream stream)
        {
            var br = new System.IO.BinaryReader(stream);

            MediaFrameVersion = br.ReadByte();
            nEx         = br.ReadByte();
            nIsKeyFrame = br.ReadByte();
            nTimetick   = br.ReadInt64();
            nIsAudio    = br.ReadByte();
            nSize       = br.ReadInt32();
            nOffset     = br.ReadInt32();
            if (MediaFrameVersion == 1)
            {
                nEncoder = br.ReadInt32();
                if (nIsAudio == 0)
                {
                    nSPSLen = br.ReadInt16();
                    nPPSLen = br.ReadInt16();
                    nWidth  = br.ReadInt32();
                    nHeight = br.ReadInt32();
                }
                else
                {
                    nFrequency   = br.ReadInt32();
                    nChannel     = br.ReadInt32();
                    nAudioFormat = br.ReadInt16();
                    nSamples     = br.ReadInt16();
                }
            }
            Data = br.ReadBytes(nSize + nOffset);
        }
Beispiel #13
0
        public Character(System.IO.BinaryReader reader, bool sentFromServer)
            : base(reader, sentFromServer)
        {
            myHitPoints = reader.ReadInt16();
            myManaLevel = reader.ReadInt16();

            ushort attribCount = reader.ReadUInt16();

            for (int i = 0; i < attribCount; ++i)
            {
                myBaseAttributes.Add(CharAttribute.GetByID(reader.ReadUInt16()), reader.ReadByte());
            }

            ushort skillCount = reader.ReadUInt16();

            for (int i = 0; i < skillCount; ++i)
            {
                myBaseSkills.Add(CharSkill.GetByID(reader.ReadUInt16()), reader.ReadByte());
            }

            myCurrentWalkDirection = myFacingDirection = (WalkDirection)reader.ReadByte();

            if (!sentFromServer)
            {
                Inventory = new Inventory(this, reader);
            }
        }
        public byte[] ReadBytes()
        {
            FileStream fileStream = null;

            System.IO.BinaryReader binaryReader = null;
            List <byte>            byteList     = new List <byte>();
            byte fileByte;

            try {
                if (File.Exists(this.fileName))
                {
                    fileStream   = new FileStream(this.fileName, FileMode.Open, FileAccess.Read);
                    binaryReader = new System.IO.BinaryReader(fileStream);
                    fileByte     = binaryReader.ReadByte();
                    while ((int)fileByte != -1)
                    {
                        byteList.Add(fileByte);
                        fileByte = binaryReader.ReadByte();
                    }
                }
            } catch (Exception exception) {
                SetMessage(exception.Message, exception.StackTrace);
            }finally{
                binaryReader.Close();
                fileStream.Close();
            }
            return(byteList.ToArray());
        }
Beispiel #15
0
    //真正判断文件类型的关键函数
    public static bool IsAllowedExtension(FileUpload hifile)
    {
        string path = hifile.PostedFile.FileName;

        //只能访问服务器的文件系统
        //本地测试是 ie hifile.PostedFile.FileName; 返回完整路径, chrome 中得到的是文件名
        //path = @"e:\2015072709244673595997.jpg";
        System.IO.FileStream   fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
        System.IO.BinaryReader r  = new System.IO.BinaryReader(fs);
        string fileclass          = "";
        //这里的位长要具体判断.
        byte buffer;

        try
        {
            buffer     = r.ReadByte();
            fileclass  = buffer.ToString();
            buffer     = r.ReadByte();
            fileclass += buffer.ToString();
        }
        catch
        {
        }
        r.Close();
        fs.Close();
        if (fileclass == "255216" || fileclass == "7173")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Beispiel #16
0
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.Name                   = binaryReader.ReadStringID();
     pointerQueue                = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(pointerQueue.Concat(this.HudWidgetInputsStruct.ReadFields(binaryReader)));
     pointerQueue                = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(pointerQueue.Concat(this.HudWidgetStateDefinitionStruct.ReadFields(binaryReader)));
     this.Anchor                 = ((AnchorEnum)(binaryReader.ReadInt16()));
     this.HudTextWidgetsFlags    = ((Flags)(binaryReader.ReadInt16()));
     this.Shader                 = binaryReader.ReadTagReference();
     this.String                 = binaryReader.ReadStringID();
     this.Justification          = ((JustificationEnum)(binaryReader.ReadInt16()));
     this.fieldpad               = binaryReader.ReadBytes(2);
     this.FullscreenFontIndex    = ((FullscreenFontIndexEnum)(binaryReader.ReadByte()));
     this.HalfscreenFontIndex    = ((HalfscreenFontIndexEnum)(binaryReader.ReadByte()));
     this.QuarterscreenFontIndex = ((QuarterscreenFontIndexEnum)(binaryReader.ReadByte()));
     this.fieldpad0              = binaryReader.ReadBytes(1);
     this.FullscreenScale        = binaryReader.ReadSingle();
     this.HalfscreenScale        = binaryReader.ReadSingle();
     this.QuarterscreenScale     = binaryReader.ReadSingle();
     this.FullscreenOffset       = binaryReader.ReadPoint();
     this.HalfscreenOffset       = binaryReader.ReadPoint();
     this.QuarterscreenOffset    = binaryReader.ReadPoint();
     pointerQueue.Enqueue(binaryReader.ReadBlamPointer(104));
     return(pointerQueue);
 }
Beispiel #17
0
 private void button8_Click(object sender, EventArgs e)
 {
     if (listBox3.SelectedIndex == -1)
     {
         return;
     }
     System.IO.BinaryReader readEvent = new System.IO.BinaryReader(File.OpenRead(eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4")));
     File.Create(eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4") + "_new").Close();
     System.IO.BinaryWriter writeEvent = new System.IO.BinaryWriter(File.OpenWrite(eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4") + "_new"));
     for (int i = 0; i < (0x10 + 0x14 * furnitureCount + 0x20 * overworldCount + 0xc * warpCount + 0x10 * listBox4.SelectedIndex); i++)
     {
         writeEvent.Write(readEvent.ReadByte()); // Reads unmodified bytes and writes them to the main file
     }
     readEvent.BaseStream.Position += 0x10;
     for (int i = 0; i < (readEvent.BaseStream.Length - (0x10 + 0x14 * furnitureCount + 0x20 * overworldCount + 0xc * warpCount + 0x10 * listBox4.SelectedIndex + 0x10)); i++)
     {
         writeEvent.Write(readEvent.ReadByte()); // Reads unmodified bytes and writes them to the main file
     }
     writeEvent.BaseStream.Position = 0xc + furnitureCount * 0x14 + overworldCount * 0x20 + warpCount * 0xc;
     writeEvent.Write((int)(triggerCount - 1));
     readEvent.Close();
     writeEvent.Close();
     File.Delete(eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4"));
     File.Move(eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4") + "_new", eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4"));
     comboBox1_SelectedIndexChanged(null, null);
 }
Beispiel #18
0
        public static async Task <FileExtension> CheckFileType(Stream stream)
        {
            System.IO.BinaryReader br = new System.IO.BinaryReader(stream);
            string        fileType    = string.Empty;
            FileExtension extension;

            try
            {
                byte data = br.ReadByte();
                fileType += data.ToString();
                data      = br.ReadByte();
                fileType += data.ToString();

                try
                {
                    extension = (FileExtension)Enum.Parse(typeof(FileExtension), fileType);
                }
                catch
                {
                    extension = FileExtension.validfile;
                }
                return(extension);
            }
            catch
            {
                extension = FileExtension.validfile;
                return(extension);
            }
            finally
            {
                stream.Position = 0;
            }
        }
Beispiel #19
0
 public override void StateLoad(BinaryReader reader)
 {
     irqCounter = reader.ReadByte();
     irqLatch = reader.ReadByte();
     irqReload = reader.ReadBoolean();
     irqEnable = reader.ReadBoolean();
 }
 public void Read(System.IO.BinaryReader br)
 {
     this.Width      = br.ReadByte();
     this.Height     = br.ReadByte();
     this.ColorCount = br.ReadByte();
     this.reserved   = br.ReadByte();
 }
Beispiel #21
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);
                }

            }
        }
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.StateAttachedTo            = ((StateAttachedToEnum)(binaryReader.ReadInt16()));
     this.fieldpad                   = binaryReader.ReadBytes(2);
     this.CanUseOnMapType            = ((CanUseOnMapTypeEnum)(binaryReader.ReadInt16()));
     this.fieldpad0                  = binaryReader.ReadBytes(2);
     this.fieldpad1                  = binaryReader.ReadBytes(28);
     this.AnchorOffset               = binaryReader.ReadPoint();
     this.WidthScale                 = binaryReader.ReadSingle();
     this.HeightScale                = binaryReader.ReadSingle();
     this.WeaponHudMeterScalingFlags = ((ScalingFlags)(binaryReader.ReadInt16()));
     this.fieldpad2                  = binaryReader.ReadBytes(2);
     this.fieldpad3                  = binaryReader.ReadBytes(20);
     this.MeterBitmap                = binaryReader.ReadTagReference();
     this.ColorAtMeterMinimum        = binaryReader.ReadColourR1G1B1();
     this.ColorAtMeterMaximum        = binaryReader.ReadColourR1G1B1();
     this.FlashColor                 = binaryReader.ReadColourR1G1B1();
     this.EmptyColor                 = binaryReader.ReadColourA1R1G1B1();
     this.WeaponHudMeterFlags        = ((Flags)(binaryReader.ReadByte()));
     this.MinumumMeterValue          = binaryReader.ReadByte();
     this.SequenceIndex              = binaryReader.ReadInt16();
     this.AlphaMultiplier            = binaryReader.ReadByte();
     this.AlphaBias                  = binaryReader.ReadByte();
     this.ValueScale                 = binaryReader.ReadInt16();
     this.Opacity       = binaryReader.ReadSingle();
     this.Translucency  = binaryReader.ReadSingle();
     this.DisabledColor = binaryReader.ReadColourA1R1G1B1();
     pointerQueue.Enqueue(binaryReader.ReadBlamPointer(0));
     this.fieldpad4 = binaryReader.ReadBytes(4);
     this.fieldpad5 = binaryReader.ReadBytes(40);
     return(pointerQueue);
 }
 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());
             }
         }
     }
 }
Beispiel #24
0
        private static void Read24BitImage(System.IO.BinaryReader aReader, BMPImage bmp)
        {
            int w         = Mathf.Abs(bmp.info.width);
            int h         = Mathf.Abs(bmp.info.height);
            int rowLength = ((24 * w + 31) / 32) * 4;
            int count     = rowLength * h;
            int pad       = rowLength - w * 3;

            Color32[] data = bmp.imageData = new Color32[w * h];
            if (aReader.BaseStream.Position + count > aReader.BaseStream.Length)
            {
                Debug.LogError("Unexpected end of file. (Have " + (aReader.BaseStream.Position + count) + " bytes, expected " + aReader.BaseStream.Length + " bytes)");
                return;
            }
            int shiftR = GetShiftCount(bmp.rMask);
            int shiftG = GetShiftCount(bmp.gMask);
            int shiftB = GetShiftCount(bmp.bMask);

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    uint v = aReader.ReadByte() | ((uint)aReader.ReadByte() << 8) | ((uint)aReader.ReadByte() << 16);
                    byte r = (byte)((v & bmp.rMask) >> shiftR);
                    byte g = (byte)((v & bmp.gMask) >> shiftG);
                    byte b = (byte)((v & bmp.bMask) >> shiftB);
                    data[x + y * w] = new Color32(r, g, b, 255);
                }
                for (int i = 0; i < pad; i++)
                {
                    aReader.ReadByte();
                }
            }
        }
        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);
        }
Beispiel #26
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);
        }
Beispiel #27
0
        public void SetBytes(Stream stream)
        {
            var br = new System.IO.BinaryReader(stream);

            Packet_Start_Code_Prefix = br.ReadBytes(3);
            if (Packet_Start_Code_Prefix[0] != 0 || Packet_Start_Code_Prefix[1] != 0 || Packet_Start_Code_Prefix[2] != 1)
            {
                throw new Exception();
            }
            Stream_ID         = br.ReadByte();
            PES_Packet_Length = (ushort)IPAddress.NetworkToHostOrder(br.ReadInt16());
            if (PES_Packet_Length == 0 && false)
            {
                throw new Exception("PES_Packet_Length error");
            }
            PES_Header_Flags  = br.ReadBytes(2);
            PES_Header_Length = br.ReadByte();
            PES_Header_Fields = br.ReadBytes(PES_Header_Length);
            if (PES_Packet_Length > 0 && PES_Packet_Length - 3 - PES_Header_Length > 0)
            {
                PES_Packet_Data = br.ReadBytes(PES_Packet_Length - 3 - PES_Header_Length);
                if (PES_Packet_Data.Length < PES_Packet_Length - 3 - PES_Header_Length)
                {
                    Console.WriteLine("@@@@@@@@@@@@@@@" + PES_Packet_Length);
                }
            }
            else
            {
                PES_Packet_Data = br.ReadBytes((int)(stream.Length - stream.Position));
            }
        }
Beispiel #28
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));
        }
Beispiel #29
0
 public FileFormatVersion(BinaryReader reader)
 {
     Major = reader.ReadByte();
     Minor = reader.ReadByte();
     reader.BaseStream.Seek(-2, SeekOrigin.Current);
     Version = reader.ReadUInt16();
 }
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.StateAttachedTo                    = ((StateAttachedToEnum)(binaryReader.ReadInt16()));
     this.fieldpad                           = binaryReader.ReadBytes(2);
     this.CanUseOnMapType                    = ((CanUseOnMapTypeEnum)(binaryReader.ReadInt16()));
     this.fieldpad0                          = binaryReader.ReadBytes(2);
     this.fieldpad1                          = binaryReader.ReadBytes(28);
     this.AnchorOffset                       = binaryReader.ReadPoint();
     this.WidthScale                         = binaryReader.ReadSingle();
     this.HeightScale                        = binaryReader.ReadSingle();
     this.WeaponHudNumberScalingFlags        = ((ScalingFlags)(binaryReader.ReadInt16()));
     this.fieldpad2                          = binaryReader.ReadBytes(2);
     this.fieldpad3                          = binaryReader.ReadBytes(20);
     this.DefaultColor                       = binaryReader.ReadColourA1R1G1B1();
     this.FlashingColor                      = binaryReader.ReadColourA1R1G1B1();
     this.FlashPeriod                        = binaryReader.ReadSingle();
     this.FlashDelay                         = binaryReader.ReadSingle();
     this.NumberOfFlashes                    = binaryReader.ReadInt16();
     this.WeaponHudNumberFlashFlags          = ((FlashFlags)(binaryReader.ReadInt16()));
     this.FlashLength                        = binaryReader.ReadSingle();
     this.DisabledColor                      = binaryReader.ReadColourA1R1G1B1();
     this.fieldpad4                          = binaryReader.ReadBytes(4);
     this.MaximumNumberOfDigits              = binaryReader.ReadByte();
     this.WeaponHudNumberFlags               = ((Flags)(binaryReader.ReadByte()));
     this.NumberOfFractionalDigits           = binaryReader.ReadByte();
     this.fieldpad5                          = binaryReader.ReadBytes(1);
     this.fieldpad6                          = binaryReader.ReadBytes(12);
     this.WeaponHudNumberWeaponSpecificFlags = ((WeaponSpecificFlags)(binaryReader.ReadInt16()));
     this.fieldpad7                          = binaryReader.ReadBytes(2);
     this.fieldpad8                          = binaryReader.ReadBytes(36);
     return(pointerQueue);
 }
Beispiel #31
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;
        }
Beispiel #32
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);
        }
Beispiel #33
0
 private void button7_Click(object sender, EventArgs e)
 {
     System.IO.BinaryReader readEvent = new System.IO.BinaryReader(File.OpenRead(eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4")));
     File.Create(eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4") + "_new").Close();
     System.IO.BinaryWriter writeEvent = new System.IO.BinaryWriter(File.OpenWrite(eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4") + "_new"));
     for (int i = 0; i < (0xc + 0x14 * furnitureCount + 0x20 * overworldCount + 0xc * warpCount); i++)
     {
         writeEvent.Write(readEvent.ReadByte()); // Reads unmodified bytes and writes them to the main file
     }
     for (int i = 0; i < (0xc); i++)
     {
         writeEvent.Write((byte)0x0); // Writes new warp
     }
     for (int i = 0; i < (readEvent.BaseStream.Length - (0xc + 0x14 * furnitureCount + 0x20 * overworldCount + 0xc * warpCount)); i++)
     {
         writeEvent.Write(readEvent.ReadByte()); // Reads unmodified bytes and writes them to the main file
     }
     writeEvent.BaseStream.Position = 0x8 + furnitureCount * 0x14 + overworldCount * 0x20;
     writeEvent.Write(warpCount + 1);
     warpCount++;
     readEvent.Close();
     writeEvent.Close();
     File.Delete(eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4"));
     File.Move(eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4") + "_new", eventPath + "\\" + comboBox1.SelectedIndex.ToString("D4"));
     comboBox1_SelectedIndexChanged(null, null);
 }
Beispiel #34
0
        private string ValidFileType(string fileName)
        {
            string ext = null;

            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                using (System.IO.BinaryReader br = new System.IO.BinaryReader(fs))
                {
                    string fileType = string.Empty;;
                    byte   data     = br.ReadByte();
                    fileType += data.ToString();
                    data      = br.ReadByte();
                    fileType += data.ToString();
                    FileExtension extension;
                    extension = (FileExtension)Enum.Parse(typeof(FileExtension), fileType);
                    if (extension == FileExtension.JPG)
                    {
                        ext = ".jpg";
                    }

                    if (extension == FileExtension.PNG)
                    {
                        ext = ".png";
                    }

                    return(ext);
                }
            }
        }
        /// <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 ) );
        }
Beispiel #36
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();
         }
     }
 }
Beispiel #37
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, '^');
 }
 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
 }
Beispiel #39
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;
            }
        }
Beispiel #40
0
        /// <summary>
        /// 检测文件真实 扩展名
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static FileExtension CheckTrueFileName(string path)
        {
            System.IO.FileStream   fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader r  = new System.IO.BinaryReader(fs);
            string bx = " ";
            byte   buffer;

            try
            {
                buffer = r.ReadByte();
                bx     = buffer.ToString();
                buffer = r.ReadByte();
                bx    += buffer.ToString();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
            r.Close();
            fs.Close();
            int type = 0;

            int.TryParse(bx, out type);
            return((FileExtension)type);
        }
        /// <summary>
        /// 檢查是否為Excel檔
        /// </summary>
        /// <param name="FilePath"></param>
        /// <returns></returns>
        private bool CheckXls(string FilePath)
        {
            //default sFileName is not Exe or Dll File
            bool isExcelFile = false;

            System.IO.FileStream   fs = null;
            System.IO.BinaryReader r  = null;
            string bx = "";
            byte   buffer;

            fs     = new System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            r      = new System.IO.BinaryReader(fs);
            buffer = r.ReadByte();
            bx     = buffer.ToString();
            buffer = r.ReadByte();
            bx    += buffer.ToString();
            buffer = r.ReadByte();
            bx    += buffer.ToString();
            buffer = r.ReadByte();
            bx    += buffer.ToString();

            r.Close();
            fs.Close();

            if (bx == "20820717224")
            {
                isExcelFile = true;
            }
            Console.WriteLine(bx);
            return(isExcelFile);
        }
Beispiel #42
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;
 }
        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());
        }
Beispiel #44
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;
 }
Beispiel #45
0
 private void Form7_Load(object sender, EventArgs e)
 {
     System.IO.BinaryReader readMatrix = new System.IO.BinaryReader(File.OpenRead(Form1.matrixEditorPath));
     matrixWidth          = readMatrix.ReadByte();
     matrixHeight         = readMatrix.ReadByte();
     progressBar1.Maximum = matrixHeight * matrixHeight;
 }
Beispiel #46
0
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.Signature           = binaryReader.ReadTagClass();
     this.Width               = binaryReader.ReadInt16();
     this.Height              = binaryReader.ReadInt16();
     this.Depth               = binaryReader.ReadByte();
     this.BitmapDataMoreFlags = ((MoreFlags)(binaryReader.ReadByte()));
     this.Type                  = ((TypeEnum)(binaryReader.ReadInt16()));
     this.Format                = ((FormatEnum)(binaryReader.ReadInt16()));
     this.BitmapDataFlags       = ((Flags)(binaryReader.ReadInt16()));
     this.RegistrationPoint     = binaryReader.ReadPoint();
     this.MipmapCount           = binaryReader.ReadInt16();
     this.LowDetailMipmapCount  = binaryReader.ReadInt16();
     this.PixelsOffset          = binaryReader.ReadInt32();
     this.LOD1TextureDataOffset = binaryReader.ReadInt32();
     this.LOD2TextureDataOffset = binaryReader.ReadInt32();
     this.LOD3TextureDataOffset = binaryReader.ReadInt32();
     this.fieldskip             = binaryReader.ReadBytes(12);
     this.LOD1TextureDataLength = binaryReader.ReadInt32();
     this.LOD2TextureDataLength = binaryReader.ReadInt32();
     this.LOD3TextureDataLength = binaryReader.ReadInt32();
     this.fieldskip0            = binaryReader.ReadBytes(52);
     return(pointerQueue);
 }
Beispiel #47
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;
        }
        /// <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);
                        }
                    }
                }
            }
        }
Beispiel #49
0
        public static bool IsAllowedExtension(MemoryStream ms, FileExtension[] fileEx)
        {
            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);
        }
Beispiel #50
0
        /// <summary>
        /// 是否为真实的图片文件
        /// </summary>
        /// <param name="hpfile"></param>
        /// <returns></returns>
        private bool IsRealImage(HttpPostedFile hpfile)
        {
            bool ret = false;

            System.IO.BinaryReader r = new System.IO.BinaryReader(hpfile.InputStream);
            string fileclass         = "";
            byte   buffer;

            try
            {
                buffer     = r.ReadByte();
                fileclass  = buffer.ToString();
                buffer     = r.ReadByte();
                fileclass += buffer.ToString();
            }
            catch
            {
                return(false);
            }
            r.Close();

            /*文件扩展名说明
             * 7173        gif
             * 255216      jpg
             * 13780       png
             * 6677        bmp
             */
            String[] fileType = { "255216", "7173", "6677", "13780" };

            ret = Array.IndexOf(fileType, fileclass) >= 0;

            return(ret);
        }
Beispiel #51
0
		void readSettings (BinaryReader inStream)
		{
			setColor (readInt (inStream));
			setTransparency (inStream.ReadByte ());
			setReflectivity (inStream.ReadByte ());
			setFlat (inStream.ReadBoolean ());
		}
Beispiel #52
0
 public GAT(byte[] data)
 {
     try
     {
         using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data, 0, data.Length))
         {
             using (System.IO.BinaryReader br = new System.IO.BinaryReader(ms))
             {
                 m_Magic    = System.Text.Encoding.Default.GetString(br.ReadBytes(4));
                 m_VerMajor = br.ReadByte();
                 m_VerMinor = br.ReadByte();
                 m_Width    = br.ReadInt32();
                 m_Height   = br.ReadInt32();
                 m_Cells    = new GATCell[m_Width * m_Height + 1];
                 for (int i = 0; i <= m_Width * m_Height - 1; i++)
                 {
                     m_Cells[i] = new GATCell(br);
                 }
             }
         }
     }
     catch
     {
         throw;
     }
 }
Beispiel #53
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;
        }
        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();
        }
Beispiel #55
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);
            }
        }
 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();
     }
 }
Beispiel #57
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");
        }
Beispiel #58
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);
            }
        }
Beispiel #59
0
        public static bool IsAllowedExtension(HttpPostedFileBase fu, FileExtension[] fileEx)
        {
            int fileLen = fu.ContentLength;

            byte[] imgArray = new byte[fileLen];
            fu.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();
            //注意将文件流指针还原
            fu.InputStream.Position = 0;
            foreach (FileExtension fe in fileEx)
            {
                if (Int32.Parse(fileclass) == (int)fe)
                {
                    return(true);
                }
            }
            return(false);
        }
 public override System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> ReadFields(System.IO.BinaryReader binaryReader)
 {
     System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer> pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(base.ReadFields(binaryReader));
     this.Name    = binaryReader.ReadStringID();
     pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(pointerQueue.Concat(this.HudWidgetInputsStruct.ReadFields(binaryReader)));
     pointerQueue = new System.Collections.Generic.Queue <Moonfish.Tags.BlamPointer>(pointerQueue.Concat(this.HudWidgetStateDefinitionStruct.ReadFields(binaryReader)));
     this.Anchor  = ((AnchorEnum)(binaryReader.ReadInt16()));
     this.HudBitmapWidgetsFlags = ((Flags)(binaryReader.ReadInt16()));
     this.Bitmap = binaryReader.ReadTagReference();
     this.Shader = binaryReader.ReadTagReference();
     this.FullscreenSequenceIndex    = binaryReader.ReadByte();
     this.HalfscreenSequenceIndex    = binaryReader.ReadByte();
     this.QuarterscreenSequenceIndex = binaryReader.ReadByte();
     this.fieldpad                       = binaryReader.ReadBytes(1);
     this.FullscreenOffset               = binaryReader.ReadPoint();
     this.HalfscreenOffset               = binaryReader.ReadPoint();
     this.QuarterscreenOffset            = binaryReader.ReadPoint();
     this.FullscreenRegistrationPoint    = binaryReader.ReadVector2();
     this.HalfscreenRegistrationPoint    = binaryReader.ReadVector2();
     this.QuarterscreenRegistrationPoint = binaryReader.ReadVector2();
     pointerQueue.Enqueue(binaryReader.ReadBlamPointer(104));
     this.SpecialHudType = ((SpecialHudTypeEnum)(binaryReader.ReadInt16()));
     this.fieldpad0      = binaryReader.ReadBytes(2);
     return(pointerQueue);
 }