Ejemplo n.º 1
0
        private void b_LoadCompleted(object sender, NavigationEventArgs e)
        {
            //this.Text = "Đang load!";
            WebBrowser b = sender as WebBrowser;


            string response = b.SaveToString();


            // format our data that we are going to post to the server
            // this will include our post parameters.  They do not need to be in a specific
            //	order, as long as they are concatenated together using an ampersand ( & )
            string        postData = "__LASTFOCUS=''&__EVENTTARGET=''&__EVENTARGUMENT=''&__VIEWSTATE=" + _VIEWSTATE + "&ctl00%24ContentPlaceHolder1%24txtUsername="******"&ctl00%24ContentPlaceHolder1%24txtPassword="******"&ctl00%24ContentPlaceHolder1%24btnLogin=%C4%90%C4%83ng+nh%E1%BA%ADp&ctl00$ContentPlaceHolder1$ctl00$cboNamHoc_gvDKHPLichThi$ob_CbocboNamHoc_gvDKHPLichThiTB=--T%E1%BA%A5t+c%E1%BA%A3--&ctl00$ContentPlaceHolder1$ctl00$cboNamHoc_gvDKHPLichThi$ob_CbocboNamHoc_gvDKHPLichThiSIS=0&ctl00$ContentPlaceHolder1$ctl00$cboNamHoc_gvDKHPLichThi=0&ctl00$ContentPlaceHolder1$ctl00$cboHocKy_gvDKHPLichThi$ob_CbocboHocKy_gvDKHPLichThiSIS=0&ctl00$ContentPlaceHolder1$ctl00$cboHocKy_gvDKHPLichThi=''&ctl00$ContentPlaceHolder1$ctl00$btnXemDiemThi=Xem+K%E1%BA%BFt+Qu%E1%BA%A3+H%E1%BB%8Dc+T%E1%BA%ADp";
            AsciiEncoding enc      = new AsciiEncoding();

            //  we are encoding the postData to a byte array
            b.Navigate(new Uri("http://portal1.hcmus.edu.vn/Login.aspx?ReturnUrl=%2fSinhVien.aspx%3fpid%3d211&pid=211"), enc.GetBytes(postData), "Content-Type: application/x-www-form-urlencoded\r\n");



            // unregisters the first event handler
            // adds a second event handler
            b.LoadCompleted += new LoadCompletedEventHandler(b_DocumentCompleted);

            b.LoadCompleted -= new LoadCompletedEventHandler(b_LoadCompleted);
        }
Ejemplo n.º 2
0
        public static string DecodeAsciiString(IBerInput input, int length)
        {
            var intLength = (int)length;
            var bytes     = ReadString(input, ref intLength);

            return(AsciiEncoding.GetString(bytes, 0, intLength));
        }
Ejemplo n.º 3
0
        private byte[] GetTagBytes(Id3Tag tag)
        {
            var bytes = new List <byte>();

            bytes.AddRange(AsciiEncoding.GetBytes("ID3"));
            bytes.AddRange(new byte[] { 3, 0, 0 });
            foreach (Id3Frame frame in tag.Frames)
            {
                if (frame.IsAssigned)
                {
                    FrameHandler mapping = FrameHandlers[frame.GetType()];
                    if (mapping != null)
                    {
                        byte[] frameBytes = mapping.Encoder(frame);
                        bytes.AddRange(AsciiEncoding.GetBytes(GetFrameIdFromFrame(frame)));
                        bytes.AddRange(SyncSafeNumber.EncodeNormal(frameBytes.Length));
                        bytes.AddRange(new byte[] { 0, 0 });
                        bytes.AddRange(frameBytes);
                    }
                }
            }
            int framesSize = bytes.Count - 6;

            bytes.InsertRange(6, SyncSafeNumber.EncodeSafe(framesSize));
            return(bytes.ToArray());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Send a player action with the given type and parameters.
        /// Then executes the given callback when the response is received.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public static IEnumerator SendAction(string type, object parameters, Action <MatchableResponse> callback)
        {
            if (MatchableSettings.IsPluginEnabled())
            {
                if (type == null)
                {
                    Debug.LogError("SendAction(): parameter 'type' is required");
                    yield return(null);
                }

                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Content-Type", "application/json");
                headers.Add("Authorization", "api_key " + MatchableSettings.GetAppKey());

                Hashtable action = MatchableAction.Create(type, parameters);

                // Simple hack to wrap the action inside a JSON array
                string data = "[" + MJSON.Serialize(action) + "]";
                if (MatchableSettings.IsLoggingEnabled())
                {
                    Debug.Log("Sent action:" + data);
                }
                byte[] postData = AsciiEncoding.StringToAscii(data);

                WWW request = new WWW(MatchableSettings.GetActionsEndpoint(), postData, headers);
                yield return(request);

                MatchableResponse response = new MatchableResponse(request);
                yield return(response);

                callback(response);
            }
        }
Ejemplo n.º 5
0
        public static int EncodeAsciiString(IBerOutput output, string value)
        {
            byte[] bytes = AsciiEncoding.GetBytes(value);

            output.WriteBytes(bytes);

            return(bytes.Length);
        }
Ejemplo n.º 6
0
        public static int GetAsciiStringLength(string str)
        {
            if (str == null)
            {
                return(0);
            }

            return(AsciiEncoding.GetByteCount(str));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Writes an ASCII encoded string
        /// </summary>
        /// <param name="value">the string to write</param>
        /// <returns>the number of bytes written</returns>
        public int WriteAsciiString(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(0);
            }

            byte[] data = AsciiEncoding.GetBytes(value);
            this.dataStream.Write(data, 0, data.Length);
            return(data.Length);
        }
Ejemplo n.º 8
0
        internal override bool HasTag(Stream stream)
        {
            stream.Seek(0, SeekOrigin.Begin);

            var headerBytes = new byte[5];

            stream.Read(headerBytes, 0, 5);

            string magic = AsciiEncoding.GetString(headerBytes, 0, 3);

            return(magic == "ID3" && headerBytes[3] == 3);
        }
Ejemplo n.º 9
0
        public override void Load(DNSpySettings settings)
        {
            var xelem = settings[SETTINGS_SECTION_NAME];

            this.BytesGroupCountVM.Value = (int?)xelem.Attribute("BytesGroupCount") ?? 8;
            this.BytesPerLineVM.Value    = (int?)xelem.Attribute("BytesPerLine") ?? 0;
            this.UseHexPrefix            = (bool?)xelem.Attribute("UseHexPrefix") ?? false;
            this.ShowAscii     = (bool?)xelem.Attribute("ShowAscii") ?? true;
            this.LowerCaseHex  = (bool?)xelem.Attribute("LowerCaseHex") ?? false;
            this.FontFamily    = new FontFamily(SessionSettings.Unescape((string)xelem.Attribute("FontFamily")) ?? FontUtils.GetDefaultFont());
            this.FontSize      = (double?)xelem.Attribute("FontSize") ?? FontUtils.DEFAULT_FONT_SIZE;
            this.AsciiEncoding = (AsciiEncoding)((int?)xelem.Attribute("AsciiEncoding") ?? (int)AsciiEncoding.UTF8);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns an ASCII string converted from the given byte array.
        /// </summary>
        public static string ToAscii(byte[] data, bool endatfirstnull)
        {
            int len = data.Length;

            if (endatfirstnull)
            {
                len = Array.IndexOf(data, (byte)0);
                if (len == -1)
                {
                    len = data.Length;
                }
            }
            var encoding = new AsciiEncoding();

            return(encoding.GetString(data, 0, len));
            //return Encoding.ASCII.GetString(data, 0, len);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Reads an ASCII encoded string.
        /// </summary>
        /// <param name="length">number of bytes to read</param>
        /// <returns>The value as a string</returns>
        public string ReadAsciiString(int length)
        {
            if (length == 0)
            {
                return(string.Empty);
            }

            Guard.MustBeGreaterThan(length, 0, nameof(length));
            string value = AsciiEncoding.GetString(this.data, this.AddIndex(length), length);

            // remove data after (potential) null terminator
            int pos = value.IndexOf('\0');

            if (pos >= 0)
            {
                value = value.Substring(0, pos);
            }

            return(value);
        }
Ejemplo n.º 12
0
        public override ExifInterOperability GetInteroperability(BitConverterEx.ByteOrder fileByteOrder)
        {
            //if (mEncoding == null)
            //    enc = "\0\0\0\0\0\0\0\0";
            //else if (mEncoding.EncodingName == "US-ASCII")
            //    enc = "ASCII\0\0\0";
            //else if (mEncoding.EncodingName == "Japanese (JIS 0208-1990 and 0212-1990)")
            //    enc = "JIS\0\0\0\0\0";
            //else if (mEncoding.EncodingName == "Unicode")
            //    enc = "Unicode\0";
            //else
            string enc   = "\0\0\0\0\0\0\0\0";
            var    ascii = new AsciiEncoding();

            byte[] benc = ascii.GetBytes(enc);
            byte[] bstr = (mEncoding == null ? ascii.GetBytes(mValue) : mEncoding.GetBytes(mValue));
            byte[] data = new byte[benc.Length + bstr.Length];
            Array.Copy(benc, 0, data, 0, benc.Length);
            Array.Copy(bstr, 0, data, benc.Length, bstr.Length);

            return(new ExifInterOperability(ExifTagFactory.GetTagID(mTag), 7, (uint)data.Length, data));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Writes an ASCII encoded string resizes it to the given length
        /// </summary>
        /// <param name="value">The string to write</param>
        /// <param name="length">The desired length of the string (including potential null terminator)</param>
        /// <param name="ensureNullTerminator">If True, there will be a \0 added at the end</param>
        /// <returns>the number of bytes written</returns>
        public int WriteAsciiString(string value, int length, bool ensureNullTerminator)
        {
            if (length == 0)
            {
                return(0);
            }

            Guard.MustBeGreaterThan(length, 0, nameof(length));

            if (value == null)
            {
                value = string.Empty;
            }

            byte paddingChar  = (byte)' ';
            int  lengthAdjust = 0;

            if (ensureNullTerminator)
            {
                paddingChar  = 0;
                lengthAdjust = 1;
            }

            value = value.Substring(0, Math.Min(length - lengthAdjust, value.Length));

            byte[] textData     = AsciiEncoding.GetBytes(value);
            int    actualLength = Math.Min(length - lengthAdjust, textData.Length);

            this.dataStream.Write(textData, 0, actualLength);
            for (int i = 0; i < length - actualLength; i++)
            {
                this.dataStream.WriteByte(paddingChar);
            }

            return(length);
        }
Ejemplo n.º 14
0
		public override void Load(ILSpySettings settings) {
			var xelem = settings[SETTINGS_SECTION_NAME];
			this.BytesGroupCountVM.Value = (int?)xelem.Attribute("BytesGroupCount") ?? 8;
			this.BytesPerLineVM.Value = (int?)xelem.Attribute("BytesPerLine") ?? 0;
			this.UseHexPrefix = (bool?)xelem.Attribute("UseHexPrefix") ?? false;
			this.ShowAscii = (bool?)xelem.Attribute("ShowAscii") ?? true;
			this.LowerCaseHex = (bool?)xelem.Attribute("LowerCaseHex") ?? false;
			this.FontFamily = new FontFamily(SessionSettings.Unescape((string)xelem.Attribute("FontFamily")) ?? FontUtils.GetDefaultFont());
			this.FontSize = (double?)xelem.Attribute("FontSize") ?? FontUtils.DEFAULT_FONT_SIZE;
			this.AsciiEncoding = (AsciiEncoding)((int?)xelem.Attribute("AsciiEncoding") ?? (int)AsciiEncoding.UTF8);
		}
Ejemplo n.º 15
0
        internal override Id3Tag ReadTag(Stream stream)
        {
            if (!HasTag(stream))
            {
                return(null);
            }

            var tag = new Id3Tag {
                MajorVersion = 2,
                MinorVersion = 3,
                Family       = Id3TagFamily.Version2x,
                IsSupported  = true,
            };

            stream.Seek(4, SeekOrigin.Begin);
            var headerBytes = new byte[6];

            stream.Read(headerBytes, 0, 6);

            var headerContainer = new Id3v2Header();

            tag.AdditionalData = headerContainer;

            byte flags  = headerBytes[1];
            var  header = new Id3v2StandardHeader {
                Revision         = headerBytes[0],
                Unsyncronization = (flags & 0x80) > 0,
                ExtendedHeader   = (flags & 0x40) > 0,
                Experimental     = (flags & 0x20) > 0
            };

            headerContainer.Header = header;

            int tagSize = SyncSafeNumber.DecodeSafe(headerBytes, 2, 4);
            var tagData = new byte[tagSize];

            stream.Read(tagData, 0, tagSize);

            int currentPos = 0;

            if (header.ExtendedHeader)
            {
                SyncSafeNumber.DecodeSafe(tagData, currentPos, 4);
                currentPos += 4;

                var extendedHeader = new Id3v2ExtendedHeader {
                    PaddingSize = SyncSafeNumber.DecodeNormal(tagData, currentPos + 2, 4)
                };

                if ((tagData[currentPos] & 0x80) > 0)
                {
                    extendedHeader.Crc32 = SyncSafeNumber.DecodeNormal(tagData, currentPos + 6, 4);
                    currentPos          += 10;
                }
                else
                {
                    currentPos += 6;
                }

                headerContainer.ExtendedHeader = extendedHeader;
            }

            while (currentPos < tagSize && tagData[currentPos] != 0x00)
            {
                string frameId = AsciiEncoding.GetString(tagData, currentPos, 4);
                currentPos += 4;

                int frameSize = SyncSafeNumber.DecodeNormal(tagData, currentPos, 4);
                currentPos += 4;

                var frameFlags = (ushort)((tagData[currentPos] << 0x08) + tagData[currentPos + 1]);
                currentPos += 2;

                var frameData = new byte[frameSize];
                Array.Copy(tagData, currentPos, frameData, 0, frameSize);

                FrameHandler mapping = FrameHandlers[frameId];
                if (mapping != null && mapping.Decoder != null)
                {
                    Id3Frame frame = mapping.Decoder(frameData);
                    tag.Frames.Add(frame);
                }

                currentPos += frameSize;
            }

            return(tag);
        }
Ejemplo n.º 16
0
        private void b_DocumentCompleted(object sender, NavigationEventArgs e)
        {
            WebBrowser b = sender as WebBrowser;

            string response = "";

            response = b.SaveToString();


            string        postData = "ctl00_ContentPlaceHolder1_ctl00_ToolkitScriptManager_CauHinh_HiddenField=&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTIyNzU5NDYyNA9kFgJmD2QWAgIDD2QWCgIBDxYCHgRUZXh0BQMoMClkAgMPFgIfAAUSxJBvw6BuIEhp4bq%2FdSBUw6JtZAIFD2QWAgIBD2QWAmYPZBYIAgQPDxYIHgtfIURhdGFCb3VuZGceFEFwcGVuZERhdGFCb3VuZEl0ZW1zZx4NU2VsZWN0ZWRWYWx1ZQUFMTQtMTUeC18hSXRlbUNvdW50AgJkFgJmD2QWBGYPDxYCHgdUb29sVGlwZWRkAgEPZBYCAgEPZBYCAgEPZBYEZg9kFghmD2QWAmYPFgIfAAUOLS1U4bqldCBj4bqjLS1kAgEPZBYCZg8WAh8ABQEwZAICD2QWAmYPFgIfAAUOLS1U4bqldCBj4bqjLS1kAgMPZBYCZg8WAh8ABQEwZAIBDw8WBB8ABQUxNC0xNR4FVmFsdWUFBTE0LTE1ZBYEZg9kFgJmDxYCHwAFBTE0LTE1ZAIBD2QWAmYPFgIfAAUFMTQtMTVkAgYPDxYGHwFnHwMFATIfBAICZBYCZg9kFgRmDw8WAh8FZWRkAgEPZBYCAgEPZBYCAgEPZBYEZg8PFgQfAAUBMR8GBQExZBYEZg9kFgJmDxYCHwAFATFkAgEPZBYCZg8WAh8ABQExZAIBDw8WBB8ABQEyHwYFATJkFgRmD2QWAmYPFgIfAAUBMmQCAQ9kFgJmDxYCHwAFATJkAgoPFgIeB1Zpc2libGVoZAIMDxYCHwdnFgICAQ8WAh8EAgkWEgIBD2QWAmYPFQgFMTQtMTUBMgZOTkEwMDIKQW5oIHbEg24gMgMzLjAHMTRDVFQzMQQ3LjAwBDcuNTBkAgIPZBYCZg8VCAUxNC0xNQEyBlRUSDAwMw7EkOG6oWkgc%2BG7kSBCMQMzLjAGMTRDVFQzBCA2LjAENi4wMGQCAw9kFgJmDxUIBTE0LTE1ATIGVFRIMDI2D0dp4bqjaSB0w61jaCBCMQMzLjADSEwxBCA1LjAENS4wMGQCBA9kFgJmDxUIBTE0LTE1ATIGVFRIMDI3D0dp4bqjaSB0w61jaCBCMgMzLjAGMTRDVFQzBCAzLjAEMy4wMGQCBQ9kFgJmDxUIBTE0LTE1ATIGQ1RUMDA4GUvhu7kgVGh14bqtdCBM4bqtcCBUcsOsbmgDNC4wBzE0Q1RUMzEEIDkuNQQ5LjUwZAIGD2QWAmYPFQgFMTQtMTUBMgZEVFYwMTIuTMO9IHRodXnhur90IE3huqFjaCBz4buRIChjaG8gQ8O0bmcgTmdo4buHIFRUKQMzLjAGMTRDVFQzBCA1LjAENS4wMGQCBw9kFgJmDxUIBTE0LTE1ATIGQ1RUMDEwEk5o4bqtcCBtw7RuIENOVFQgMgMzLjAHMTRDVFQzMQQxMC4wBTEwLjAwZAIID2QWAmYPFQgFMTQtMTUBMgZUQ0gwMDINVGjhu4MgZOG7pWMgMgMyLjAHMTRDVFQzMQQgNS4wBDUuMDBkAgkPZBYCZg8VCAUxNC0xNQEyBkRUVjA5MhhUaOG7sWMgaMOgbmggbeG6oWNoIHPhu5EDMS4wBzE0Q1RUMzIEIDkuMAQ5LjAwZAIHDxYCHwAFBTIuMi44ZAIJDxYCHwAFCzIwMDcgLSAyMDE0ZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAgU3Y3RsMDAkQ29udGVudFBsYWNlSG9sZGVyMSRjdGwwMCRjYm9OYW1Ib2NfZ3ZES0hQTGljaFRoaQU2Y3RsMDAkQ29udGVudFBsYWNlSG9sZGVyMSRjdGwwMCRjYm9Ib2NLeV9ndkRLSFBMaWNoVGhp5EqBE0WY4dx7mg4r%2F8fsGwu2GyFCJBYU6p%2F8QvJKE14%3D&ctl00%24ContentPlaceHolder1%24ctl00%24cboNamHoc_gvDKHPLichThi%24ob_CbocboNamHoc_gvDKHPLichThiTB=--T%E1%BA%A5t+c%E1%BA%A3--&ctl00%24ContentPlaceHolder1%24ctl00%24cboNamHoc_gvDKHPLichThi%24ob_CbocboNamHoc_gvDKHPLichThiSIS=0&ctl00%24ContentPlaceHolder1%24ctl00%24cboNamHoc_gvDKHPLichThi=0&ctl00%24ContentPlaceHolder1%24ctl00%24cboHocKy_gvDKHPLichThi%24ob_CbocboHocKy_gvDKHPLichThiSIS=0&ctl00%24ContentPlaceHolder1%24ctl00%24cboHocKy_gvDKHPLichThi=&ctl00%24ContentPlaceHolder1%24ctl00%24btnXemDiemThi=Xem+K%E1%BA%BFt+Qu%E1%BA%A3+H%E1%BB%8Dc+T%E1%BA%ADp";
            AsciiEncoding enc      = new AsciiEncoding();

            time1++;

            //  we are encoding the postData to a byte array
            b.Navigate(new Uri("http://portal1.hcmus.edu.vn/SinhVien.aspx?pid=211"), enc.GetBytes(postData), "Content-Type: application/x-www-form-urlencoded\r\n");


            // response = b.DocumentText;


            string res = "";

            if (response.Contains("Điểm Tổng Kết"))
            {
                isLoggedIn = true;
                int index_start = response.IndexOf("Điểm Tổng Kết");
                int index_end   = response.IndexOf("</fieldset>");

                res = response.Substring(index_start, (index_end - index_start));
                //textBox2.Text = "<!DOCTYPE html>\r\n<html xmlns='http://www.w3.org/1999/xhtml'>\r\n<head>\r\n\t<title></title>\r\n</head>\r\n<body>\r\n\t<table id='tbDiemThiGK' class='dkhp-table'>\r\n\t\t<thead>\r\n\t\t\t<tr>\r\n\t\t\t\t<th title='Năm Học'>Năm Học</th>\r\n\t\t\t\t<th title='Học Kỳ'>Học Kỳ</th>\r\n\t\t\t\t<th title='Mã MH'>Mã Môn Học</th>\r\n\t\t\t\t<th class='left' title='Môn Học'>Môn Học</th>\r\n\t\t\t\t<th title='Số Tín Chỉ'>Số TC</th>\r\n\t\t\t\t<th title='Lớp'>Lớp</th>\r\n\t\t\t\t<th class='left'>Điểm Thi</th>\r\n\t\t\t<th class='left'>"
                //   + res
                // + "</body>\r\n</html>";
            }
            else
            {
                time1++;
                isLoggedIn = false;
            }



            //textBox3.Text = response;


            if (time1 == 2)
            {
                b.LoadCompleted -= new LoadCompletedEventHandler(b_DocumentCompleted);
                time1            = 0;

                if (isLoggedIn)
                {
                    txtBox_state.Text = "Thành công!";
                    test = "<!DOCTYPE html>\r\n<html xmlns='http://www.w3.org/1999/xhtml'>\r\n<head>\r\n\t<title></title>\r\n</head>\r\n<body>\r\n\t<table id='tbDiemThiGK' class='dkhp-table'>\r\n\t\t<thead>\r\n\t\t\t<tr>\r\n\t\t\t\t<th title='Năm Học'>Năm Học</th>\r\n\t\t\t\t<th title='Học Kỳ'>Học Kỳ</th>\r\n\t\t\t\t<th title='Mã MH'>Mã Môn Học</th>\r\n\t\t\t\t<th class='left' title='Môn Học'>Môn Học</th>\r\n\t\t\t\t<th title='Số Tín Chỉ'>Số TC</th>\r\n\t\t\t\t<th title='Lớp'>Lớp</th>\r\n\t\t\t\t<th class='left'>Điểm Thi</th>\r\n\t\t\t<th class='left'>"
                           + res
                           + "</body>\r\n</html>";
                    webBrowser1.NavigateToString(test);
                    isLoggedIn = false;
                    test       = "";
                }
                else
                {
                    txtBox_state.Text = "Sai tài khoản \nhoặc mật khẩu!";
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates an ExifProperty from the given interoperability parameters.
        /// </summary>
        /// <param name="tag">The tag id of the exif property.</param>
        /// <param name="type">The type id of the exif property.</param>
        /// <param name="count">Byte or component count.</param>
        /// <param name="value">Field data as an array of bytes.</param>
        /// <param name="byteOrder">Byte order of value.</param>
        /// <param name="ifd">IFD section containing this propery.</param>
        /// <returns>an ExifProperty initialized from the interoperability parameters.</returns>
        public static ExifProperty Get(ushort tag, ushort type, uint count, byte[] value, BitConverterEx.ByteOrder byteOrder, IFD ifd)
        {
            BitConverterEx conv = new BitConverterEx(byteOrder, BitConverterEx.ByteOrder.System);

            if (ifd == IFD.Zeroth)
            {
                if (tag == 0x103) // Compression
                {
                    return(new ExifEnumProperty <Compression>(ExifTag.Compression, (Compression)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x106) // PhotometricInterpretation
                {
                    return(new ExifEnumProperty <PhotometricInterpretation>(ExifTag.PhotometricInterpretation, (PhotometricInterpretation)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x112) // Orientation
                {
                    return(new ExifEnumProperty <Orientation>(ExifTag.Orientation, (Orientation)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x11c) // PlanarConfiguration
                {
                    return(new ExifEnumProperty <PlanarConfiguration>(ExifTag.PlanarConfiguration, (PlanarConfiguration)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x213) // YCbCrPositioning
                {
                    return(new ExifEnumProperty <YCbCrPositioning>(ExifTag.YCbCrPositioning, (YCbCrPositioning)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x128) // ResolutionUnit
                {
                    return(new ExifEnumProperty <ResolutionUnit>(ExifTag.ResolutionUnit, (ResolutionUnit)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x132) // DateTime
                {
                    return(new ExifDateTime(ExifTag.DateTime, ExifBitConverter.ToDateTime(value)));
                }
            }
            else if (ifd == IFD.EXIF)
            {
                if (tag == 0x9000) // ExifVersion
                {
                    return(new ExifVersion(ExifTag.ExifVersion, ExifBitConverter.ToAscii(value)));
                }
                else if (tag == 0xa000) // FlashpixVersion
                {
                    return(new ExifVersion(ExifTag.FlashpixVersion, ExifBitConverter.ToAscii(value)));
                }
                else if (tag == 0xa001) // ColorSpace
                {
                    return(new ExifEnumProperty <ColorSpace>(ExifTag.ColorSpace, (ColorSpace)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x9286) // UserComment
                {
                    byte[] encbytes = new byte[8];
                    byte[] strbytes = new byte[value.Length - 8];
                    Array.Copy(value, encbytes, 8);
                    Array.Copy(value, 8, strbytes, 0, value.Length - 8);
                    Encoding enc    = new AsciiEncoding();
                    string   encstr = enc.GetString(encbytes, 0, encbytes.Length);
                    if (encstr == "ASCII\0\0\0")
                    {
                        enc = new AsciiEncoding();
                    }
                    else if (encstr == "JIS\0\0\0\0\0")
                    {
                        enc = Encoding.GetEncoding("Japanese (JIS 0208-1990 and 0212-1990)");
                    }
                    else if (encstr == "Unicode\0")
                    {
                        enc = Encoding.Unicode;
                    }
                    else
                    {
                        enc = null;
                    }

                    int len = Array.IndexOf(strbytes, (byte)0);
                    if (len == -1)
                    {
                        len = strbytes.Length;
                    }
                    return(new ExifEncodedString(ExifTag.UserComment, (enc == null ? new AsciiEncoding().GetString(strbytes, 0, len) : enc.GetString(strbytes, 0, len)), enc));
                }
                else if (tag == 0x9003) // DateTimeOriginal
                {
                    return(new ExifDateTime(ExifTag.DateTimeOriginal, ExifBitConverter.ToDateTime(value)));
                }
                else if (tag == 0x9004) // DateTimeDigitized
                {
                    return(new ExifDateTime(ExifTag.DateTimeDigitized, ExifBitConverter.ToDateTime(value)));
                }
                else if (tag == 0x8822) // ExposureProgram
                {
                    return(new ExifEnumProperty <ExposureProgram>(ExifTag.ExposureProgram, (ExposureProgram)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x9207) // MeteringMode
                {
                    return(new ExifEnumProperty <MeteringMode>(ExifTag.MeteringMode, (MeteringMode)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x9208) // LightSource
                {
                    return(new ExifEnumProperty <LightSource>(ExifTag.LightSource, (LightSource)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x9209) // Flash
                {
                    return(new ExifEnumProperty <Flash>(ExifTag.Flash, (Flash)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0x9214) // SubjectArea
                {
                    if (count == 3)
                    {
                        return(new ExifCircularSubjectArea(ExifTag.SubjectArea, ExifBitConverter.ToUShortArray(value, (int)count, byteOrder)));
                    }
                    else if (count == 4)
                    {
                        return(new ExifRectangularSubjectArea(ExifTag.SubjectArea, ExifBitConverter.ToUShortArray(value, (int)count, byteOrder)));
                    }
                    else // count == 2
                    {
                        return(new ExifPointSubjectArea(ExifTag.SubjectArea, ExifBitConverter.ToUShortArray(value, (int)count, byteOrder)));
                    }
                }
                else if (tag == 0xa210) // FocalPlaneResolutionUnit
                {
                    return(new ExifEnumProperty <ResolutionUnit>(ExifTag.FocalPlaneResolutionUnit, (ResolutionUnit)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa214) // SubjectLocation
                {
                    return(new ExifPointSubjectArea(ExifTag.SubjectLocation, ExifBitConverter.ToUShortArray(value, (int)count, byteOrder)));
                }
                else if (tag == 0xa217) // SensingMethod
                {
                    return(new ExifEnumProperty <SensingMethod>(ExifTag.SensingMethod, (SensingMethod)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa300) // FileSource
                {
                    return(new ExifEnumProperty <FileSource>(ExifTag.FileSource, (FileSource)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa301) // SceneType
                {
                    return(new ExifEnumProperty <SceneType>(ExifTag.SceneType, (SceneType)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa401) // CustomRendered
                {
                    return(new ExifEnumProperty <CustomRendered>(ExifTag.CustomRendered, (CustomRendered)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa402) // ExposureMode
                {
                    return(new ExifEnumProperty <ExposureMode>(ExifTag.ExposureMode, (ExposureMode)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa403) // WhiteBalance
                {
                    return(new ExifEnumProperty <WhiteBalance>(ExifTag.WhiteBalance, (WhiteBalance)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa406) // SceneCaptureType
                {
                    return(new ExifEnumProperty <SceneCaptureType>(ExifTag.SceneCaptureType, (SceneCaptureType)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa407) // GainControl
                {
                    return(new ExifEnumProperty <GainControl>(ExifTag.GainControl, (GainControl)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa408) // Contrast
                {
                    return(new ExifEnumProperty <Contrast>(ExifTag.Contrast, (Contrast)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa409) // Saturation
                {
                    return(new ExifEnumProperty <Saturation>(ExifTag.Saturation, (Saturation)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa40a) // Sharpness
                {
                    return(new ExifEnumProperty <Sharpness>(ExifTag.Sharpness, (Sharpness)conv.ToUInt16(value, 0), true));
                }
                else if (tag == 0xa40c) // SubjectDistanceRange
                {
                    return(new ExifEnumProperty <SubjectDistanceRange>(ExifTag.SubjectDistance, (SubjectDistanceRange)conv.ToUInt16(value, 0), true));
                }
            }
            else if (ifd == IFD.GPS)
            {
                if (tag == 0) // GPSVersionID
                {
                    return(new ExifVersion(ExifTag.GPSVersionID, ExifBitConverter.ToString(value)));
                }
                else if (tag == 1) // GPSLatitudeRef
                {
                    return(new ExifEnumProperty <GPSLatitudeRef>(ExifTag.GPSLatitudeRef, (GPSLatitudeRef)value[0]));
                }
                else if (tag == 2) // GPSLatitude
                {
                    return(new GPSLatitudeLongitude(ExifTag.GPSLatitude, ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)));
                }
                else if (tag == 3) // GPSLongitudeRef
                {
                    return(new ExifEnumProperty <GPSLongitudeRef>(ExifTag.GPSLongitudeRef, (GPSLongitudeRef)value[0]));
                }
                else if (tag == 4) // GPSLongitude
                {
                    return(new GPSLatitudeLongitude(ExifTag.GPSLongitude, ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)));
                }
                else if (tag == 5) // GPSAltitudeRef
                {
                    return(new ExifEnumProperty <GPSAltitudeRef>(ExifTag.GPSAltitudeRef, (GPSAltitudeRef)value[0]));
                }
                else if (tag == 7) // GPSTimeStamp
                {
                    return(new GPSTimeStamp(ExifTag.GPSTimeStamp, ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)));
                }
                else if (tag == 9) // GPSStatus
                {
                    return(new ExifEnumProperty <GPSStatus>(ExifTag.GPSStatus, (GPSStatus)value[0]));
                }
                else if (tag == 10) // GPSMeasureMode
                {
                    return(new ExifEnumProperty <GPSMeasureMode>(ExifTag.GPSMeasureMode, (GPSMeasureMode)value[0]));
                }
                else if (tag == 12) // GPSSpeedRef
                {
                    return(new ExifEnumProperty <GPSSpeedRef>(ExifTag.GPSSpeedRef, (GPSSpeedRef)value[0]));
                }
                else if (tag == 14) // GPSTrackRef
                {
                    return(new ExifEnumProperty <GPSDirectionRef>(ExifTag.GPSTrackRef, (GPSDirectionRef)value[0]));
                }
                else if (tag == 16) // GPSImgDirectionRef
                {
                    return(new ExifEnumProperty <GPSDirectionRef>(ExifTag.GPSImgDirectionRef, (GPSDirectionRef)value[0]));
                }
                else if (tag == 19) // GPSDestLatitudeRef
                {
                    return(new ExifEnumProperty <GPSLatitudeRef>(ExifTag.GPSDestLatitudeRef, (GPSLatitudeRef)value[0]));
                }
                else if (tag == 20) // GPSDestLatitude
                {
                    return(new GPSLatitudeLongitude(ExifTag.GPSDestLatitude, ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)));
                }
                else if (tag == 21) // GPSDestLongitudeRef
                {
                    return(new ExifEnumProperty <GPSLongitudeRef>(ExifTag.GPSDestLongitudeRef, (GPSLongitudeRef)value[0]));
                }
                else if (tag == 22) // GPSDestLongitude
                {
                    return(new GPSLatitudeLongitude(ExifTag.GPSDestLongitude, ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)));
                }
                else if (tag == 23) // GPSDestBearingRef
                {
                    return(new ExifEnumProperty <GPSDirectionRef>(ExifTag.GPSDestBearingRef, (GPSDirectionRef)value[0]));
                }
                else if (tag == 25) // GPSDestDistanceRef
                {
                    return(new ExifEnumProperty <GPSDistanceRef>(ExifTag.GPSDestDistanceRef, (GPSDistanceRef)value[0]));
                }
                else if (tag == 29) // GPSDate
                {
                    return(new ExifDateTime(ExifTag.GPSDateStamp, ExifBitConverter.ToDateTime(value, false)));
                }
                else if (tag == 30) // GPSDifferential
                {
                    return(new ExifEnumProperty <GPSDifferential>(ExifTag.GPSDifferential, (GPSDifferential)conv.ToUInt16(value, 0)));
                }
            }
            else if (ifd == IFD.Interop)
            {
                if (tag == 1) // InteroperabilityIndex
                {
                    return(new ExifAscii(ExifTag.InteroperabilityIndex, ExifBitConverter.ToAscii(value)));
                }
                else if (tag == 2) // InteroperabilityVersion
                {
                    return(new ExifVersion(ExifTag.InteroperabilityVersion, ExifBitConverter.ToAscii(value)));
                }
            }
            else if (ifd == IFD.First)
            {
                if (tag == 0x103) // Compression
                {
                    return(new ExifEnumProperty <Compression>(ExifTag.ThumbnailCompression, (Compression)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x106) // PhotometricInterpretation
                {
                    return(new ExifEnumProperty <PhotometricInterpretation>(ExifTag.ThumbnailPhotometricInterpretation, (PhotometricInterpretation)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x112) // Orientation
                {
                    return(new ExifEnumProperty <Orientation>(ExifTag.ThumbnailOrientation, (Orientation)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x11c) // PlanarConfiguration
                {
                    return(new ExifEnumProperty <PlanarConfiguration>(ExifTag.ThumbnailPlanarConfiguration, (PlanarConfiguration)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x213) // YCbCrPositioning
                {
                    return(new ExifEnumProperty <YCbCrPositioning>(ExifTag.ThumbnailYCbCrPositioning, (YCbCrPositioning)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x128) // ResolutionUnit
                {
                    return(new ExifEnumProperty <ResolutionUnit>(ExifTag.ThumbnailResolutionUnit, (ResolutionUnit)conv.ToUInt16(value, 0)));
                }
                else if (tag == 0x132) // DateTime
                {
                    return(new ExifDateTime(ExifTag.ThumbnailDateTime, ExifBitConverter.ToDateTime(value)));
                }
            }

            // Find the exif tag corresponding to given tag id
            ExifTag etag = ExifTagFactory.GetExifTag(ifd, tag);

            if (type == 1) // 1 = BYTE An 8-bit unsigned integer.
            {
                if (count == 1)
                {
                    return(new ExifByte(etag, value[0]));
                }
                else
                {
                    return(new ExifByteArray(etag, value));
                }
            }
            else if (type == 2) // 2 = ASCII An 8-bit byte containing one 7-bit ASCII code.
            {
                return(new ExifAscii(etag, ExifBitConverter.ToAscii(value)));
            }
            else if (type == 3) // 3 = SHORT A 16-bit (2-byte) unsigned integer.
            {
                if (count == 1)
                {
                    return(new ExifUShort(etag, conv.ToUInt16(value, 0)));
                }
                else
                {
                    return(new ExifUShortArray(etag, ExifBitConverter.ToUShortArray(value, (int)count, byteOrder)));
                }
            }
            else if (type == 4) // 4 = LONG A 32-bit (4-byte) unsigned integer.
            {
                if (count == 1)
                {
                    return(new ExifUInt(etag, conv.ToUInt32(value, 0)));
                }
                else
                {
                    return(new ExifUIntArray(etag, ExifBitConverter.ToUIntArray(value, (int)count, byteOrder)));
                }
            }
            else if (type == 5) // 5 = RATIONAL Two LONGs. The first LONG is the numerator and the second LONG expresses the denominator.
            {
                if (count == 1)
                {
                    return(new ExifURational(etag, ExifBitConverter.ToURational(value, byteOrder)));
                }
                else
                {
                    return(new ExifURationalArray(etag, ExifBitConverter.ToURationalArray(value, (int)count, byteOrder)));
                }
            }
            else if (type == 7) // 7 = UNDEFINED An 8-bit byte that can take any value depending on the field definition.
            {
                return(new ExifUndefined(etag, value));
            }
            else if (type == 9) // 9 = SLONG A 32-bit (4-byte) signed integer (2's complement notation).
            {
                if (count == 1)
                {
                    return(new ExifSInt(etag, conv.ToInt32(value, 0)));
                }
                else
                {
                    return(new ExifSIntArray(etag, ExifBitConverter.ToSIntArray(value, (int)count, byteOrder)));
                }
            }
            else if (type == 10) // 10 = SRATIONAL Two SLONGs. The first SLONG is the numerator and the second SLONG is the denominator.
            {
                if (count == 1)
                {
                    return(new ExifSRational(etag, ExifBitConverter.ToSRational(value, byteOrder)));
                }
                else
                {
                    return(new ExifSRationalArray(etag, ExifBitConverter.ToSRationalArray(value, (int)count, byteOrder)));
                }
            }
            else
            {
                throw new ArgumentException("Unknown property type.");
            }
        }