Example #1
0
 IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 {
     if (nullVal)
     {
         return(new MySqlDecimal(true));
     }
     if (length == -1L)
     {
         return(new MySqlDecimal(decimal.Parse(stream.ReadLenString(), CultureInfo.InvariantCulture)));
     }
     return(new MySqlDecimal(decimal.Parse(stream.ReadString(length), CultureInfo.InvariantCulture)));
 }
Example #2
0
 IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 {
     if (nullVal)
     {
         return(new MySqlInt16(true));
     }
     if (length == -1L)
     {
         return(new MySqlInt16((short)stream.ReadInteger(2)));
     }
     return(new MySqlInt16(short.Parse(stream.ReadString(length))));
 }
Example #3
0
 IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 {
     if (nullVal)
     {
         return(new MySqlUByte(true));
     }
     if (length == -1L)
     {
         return(new MySqlUByte((byte)stream.ReadByte()));
     }
     return(new MySqlUByte(byte.Parse(stream.ReadString(length))));
 }
Example #4
0
 IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 {
     if (nullVal)
     {
         return(new MySqlInt32(((IMySqlValue)this).MySqlDbType, true));
     }
     if (length == -1L)
     {
         return(new MySqlInt32(((IMySqlValue)this).MySqlDbType, stream.ReadInteger(4)));
     }
     return(new MySqlInt32(((IMySqlValue)this).MySqlDbType, int.Parse(stream.ReadString(length), CultureInfo.InvariantCulture)));
 }
Example #5
0
 IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 {
     if (nullVal)
     {
         return(new MySqlInt64(true));
     }
     if (length == -1L)
     {
         return(new MySqlInt64((long)stream.ReadLong(8)));
     }
     return(new MySqlInt64(long.Parse(stream.ReadString(length))));
 }
Example #6
0
 IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
 {
     if (nullVal)
     {
         return(new MySqlDouble(true));
     }
     if (length == -1L)
     {
         byte[] buffer = new byte[8];
         stream.Read(buffer, 0, 8);
         return(new MySqlDouble(BitConverter.ToDouble(buffer, 0)));
     }
     return(new MySqlDouble(double.Parse(stream.ReadString(length), CultureInfo.InvariantCulture)));
 }
Example #7
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlTimeSpan(true));
            }

            if (length >= 0)
            {
                string value = stream.ReadString(length);
                ParseMySql(value, stream.Version.isAtLeast(4, 1, 0));
                return(this);
            }

            long bufLength = stream.ReadByte();
            int  negate    = 0;

            if (bufLength > 0)
            {
                negate = stream.ReadByte();
            }

            isNull = false;
            if (bufLength == 0)
            {
                isNull = true;
            }
            else if (bufLength == 5)
            {
                mValue = new TimeSpan(stream.ReadInteger(4), 0, 0, 0);
            }
            else if (bufLength == 8)
            {
                mValue = new TimeSpan(stream.ReadInteger(4),
                                      stream.ReadByte(), stream.ReadByte(), stream.ReadByte());
            }
            else
            {
                mValue = new TimeSpan(stream.ReadInteger(4),
                                      stream.ReadByte(), stream.ReadByte(), stream.ReadByte(),
                                      stream.ReadInteger(4) / 1000000);
            }

            if (negate == 1)
            {
                mValue = mValue.Negate();
            }
            return(this);
        }
Example #8
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlByte(true));
            }
            if (length == -1L)
            {
                return(new MySqlByte((sbyte)stream.ReadByte()));
            }
            string    s   = stream.ReadString(length);
            MySqlByte num = new MySqlByte(sbyte.Parse(s, NumberStyles.Any, CultureInfo.InvariantCulture));

            num.TreatAsBoolean = this.TreatAsBoolean;
            return(num);
        }
Example #9
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlSingle(true));
            }

            if (length == -1)
            {
                byte[] b = new byte[4];
                stream.Read(b, 0, 4);
                return(new MySqlSingle(BitConverter.ToSingle(b, 0)));
            }
            return(new MySqlSingle(Single.Parse(stream.ReadString(length),
                                                CultureInfo.InvariantCulture)));
        }
Example #10
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlUInt64(true));
            }

            if (length == -1)
            {
                return(new MySqlUInt64((ulong)stream.ReadLong(8)));
            }
            else
            {
                return(new MySqlUInt64(UInt64.Parse(stream.ReadString(length))));
            }
        }
Example #11
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlByte(true));
            }

            if (length == -1)
            {
                return(new MySqlByte((sbyte)stream.ReadByte()));
            }
            else
            {
                string s = stream.ReadString(length);
                return(new MySqlByte(SByte.Parse(s, CultureInfo.InvariantCulture)));
            }
        }
Example #12
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlString(this.type, true));
            }
            string val = string.Empty;

            if (length == -1L)
            {
                val = stream.ReadLenString();
            }
            else
            {
                val = stream.ReadString(length);
            }
            return(new MySqlString(this.type, val));
        }
Example #13
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlUInt32((this as IMySqlValue).MySqlDbType, true));
            }

            if (length == -1)
            {
                return(new MySqlUInt32((this as IMySqlValue).MySqlDbType,
                                       (uint)stream.ReadInteger(4)));
            }
            else
            {
                return(new MySqlUInt32((this as IMySqlValue).MySqlDbType,
                                       UInt32.Parse(stream.ReadString(length), NumberStyles.Any, CultureInfo.InvariantCulture)));
            }
        }
Example #14
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlTimeSpan(true));
            }
            if (length >= 0L)
            {
                string s = stream.ReadString(length);
                this.ParseMySql(s, stream.Version.isAtLeast(4, 1, 0));
                return(this);
            }
            long num  = stream.ReadByte();
            int  num2 = 0;

            if (num > 0L)
            {
                num2 = stream.ReadByte();
            }
            this.isNull = false;
            switch (num)
            {
            case 0L:
                this.isNull = true;
                break;

            case 5L:
                this.mValue = new TimeSpan(stream.ReadInteger(4), 0, 0, 0);
                break;

            case 8L:
                this.mValue = new TimeSpan(stream.ReadInteger(4), stream.ReadByte(), stream.ReadByte(), stream.ReadByte());
                break;

            default:
                this.mValue = new TimeSpan(stream.ReadInteger(4), stream.ReadByte(), stream.ReadByte(), stream.ReadByte(), stream.ReadInteger(4) / 0xf4240);
                break;
            }
            if (num2 == 1)
            {
                this.mValue = this.mValue.Negate();
            }
            return(this);
        }
Example #15
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlString(type, true));
            }

            string s = String.Empty;

            if (length == -1)
            {
                s = stream.ReadLenString();
            }
            else
            {
                s = stream.ReadString(length);
            }
            MySqlString str = new MySqlString(type, s);

            return(str);
        }
Example #16
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlDateTime(type, true));
            }

            if (length >= 0)
            {
                string value = stream.ReadString(length);
                return(ParseMySql(value, stream.Version.isAtLeast(4, 1, 0)));
            }

            long bufLength = stream.ReadByte();
            int  year = 0, month = 0, day = 0;
            int  hour = 0, minute = 0, second = 0;

            if (bufLength >= 4)
            {
                year  = stream.ReadInteger(2);
                month = stream.ReadByte();
                day   = stream.ReadByte();
            }

            if (bufLength > 4)
            {
                hour   = stream.ReadByte();
                minute = stream.ReadByte();
                second = stream.ReadByte();
            }

            if (bufLength > 7)
            {
                stream.ReadInteger(4);
            }

            return(new MySqlDateTime(type, year, month, day, hour, minute, second));
        }
Example #17
0
        IMySqlValue IMySqlValue.ReadValue(MySqlStream stream, long length, bool nullVal)
        {
            if (nullVal)
            {
                return(new MySqlDateTime(this.type, true));
            }
            if (length >= 0L)
            {
                string s = stream.ReadString(length);
                return(this.ParseMySql(s, stream.Version.isAtLeast(4, 1, 0)));
            }
            long num    = stream.ReadByte();
            int  year   = 0;
            int  month  = 0;
            int  day    = 0;
            int  hour   = 0;
            int  minute = 0;
            int  second = 0;

            if (num >= 4L)
            {
                year  = stream.ReadInteger(2);
                month = stream.ReadByte();
                day   = stream.ReadByte();
            }
            if (num > 4L)
            {
                hour   = stream.ReadByte();
                minute = stream.ReadByte();
                second = stream.ReadByte();
            }
            if (num > 7L)
            {
                stream.ReadInteger(4);
            }
            return(new MySqlDateTime(this.type, year, month, day, hour, minute, second));
        }
        public void crack(byte[] receive, byte[] send, out string Hash, out string Seed, out string DBUser)
        {
            Hash = ""; Seed = ""; DBUser = "";
            if (receive == null) return;
            if (send == null) return;

            try
            {
                MemoryStream ms = new MemoryStream(receive);
                MySqlStream stream = new MySqlStream(ms, _Codec);

                // read off the welcome packet and parse out it's values
                stream.OpenPacket();
                int protocol = stream.ReadByte();
                string versionString = stream.ReadString();
                DBVersion version = DBVersion.Parse(versionString);
                int threadId = stream.ReadInteger(4);
                string encryptionSeed = stream.ReadString();

                int serverCaps = 0;
                if (stream.HasMoreData) serverCaps = stream.ReadInteger(2);
                if (version.isAtLeast(4, 1, 1))
                {
                    /* New protocol with 16 bytes to describe server characteristics */
                    int serverCharSetIndex = stream.ReadInteger(1);

                    int serverStatus = stream.ReadInteger(2);
                    stream.SkipBytes(13);
                    string seedPart2 = stream.ReadString();
                    encryptionSeed += seedPart2;
                }
                stream.Close();
                ms.Close();
                ms.Dispose();

                if (version.isAtLeast(4, 1, 1))
                {
                    string msg = _Codec.GetString(send);
                    int i = msg.IndexOf("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
                    if (i != -1)
                    {
                        string user = msg.Remove(0, i + 23);
                        i = user.IndexOf('\0');
                        string hash1 = user.Remove(0, i + 1);
                        if (hash1 == "\0") hash1 = "";
                        user = user.Substring(0, i);
                        //CLIENT:  recv(public_seed)
                        //         hash_stage1=sha1("password")
                        //         hash_stage2=sha1(hash_stage1)
                        //         reply=xor(hash_stage1, sha1(public_seed,hash_stage2)
                        //         send(reply)
                        //SERVER:  recv(reply)
                        //         hash_stage1=xor(reply, sha1(public_seed,hash_stage2))
                        //         candidate_hash2=sha1(hash_stage1)
                        //         check(candidate_hash2==hash_stage2)                            
                        Seed = StringToHex(encryptionSeed, true);
                        Hash = StringToHex(hash1.Substring(0, 21), true);
                        DBUser = user;
                    }
                }
                else
                {
                    throw (new Exception("MYSQL ERROR VERSION INCOMPATIBLE, MUST BE >4.1.1"));
                }
            }
            catch { }
        }
        public void crack(byte[] receive, byte[] send, out string Hash, out string Seed, out string DBUser)
        {
            Hash = ""; Seed = ""; DBUser = "";
            if (receive == null)
            {
                return;
            }
            if (send == null)
            {
                return;
            }

            try
            {
                MemoryStream ms     = new MemoryStream(receive);
                MySqlStream  stream = new MySqlStream(ms, _Codec);

                // read off the welcome packet and parse out it's values
                stream.OpenPacket();
                int       protocol       = stream.ReadByte();
                string    versionString  = stream.ReadString();
                DBVersion version        = DBVersion.Parse(versionString);
                int       threadId       = stream.ReadInteger(4);
                string    encryptionSeed = stream.ReadString();

                int serverCaps = 0;
                if (stream.HasMoreData)
                {
                    serverCaps = stream.ReadInteger(2);
                }
                if (version.isAtLeast(4, 1, 1))
                {
                    /* New protocol with 16 bytes to describe server characteristics */
                    int serverCharSetIndex = stream.ReadInteger(1);

                    int serverStatus = stream.ReadInteger(2);
                    stream.SkipBytes(13);
                    string seedPart2 = stream.ReadString();
                    encryptionSeed += seedPart2;
                }
                stream.Close();
                ms.Close();
                ms.Dispose();

                if (version.isAtLeast(4, 1, 1))
                {
                    string msg = _Codec.GetString(send);
                    int    i   = msg.IndexOf("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
                    if (i != -1)
                    {
                        string user = msg.Remove(0, i + 23);
                        i = user.IndexOf('\0');
                        string hash1 = user.Remove(0, i + 1);
                        if (hash1 == "\0")
                        {
                            hash1 = "";
                        }
                        user = user.Substring(0, i);
                        //CLIENT:  recv(public_seed)
                        //         hash_stage1=sha1("password")
                        //         hash_stage2=sha1(hash_stage1)
                        //         reply=xor(hash_stage1, sha1(public_seed,hash_stage2)
                        //         send(reply)
                        //SERVER:  recv(reply)
                        //         hash_stage1=xor(reply, sha1(public_seed,hash_stage2))
                        //         candidate_hash2=sha1(hash_stage1)
                        //         check(candidate_hash2==hash_stage2)
                        Seed   = StringToHex(encryptionSeed, true);
                        Hash   = StringToHex(hash1.Substring(0, 21), true);
                        DBUser = user;
                    }
                }
                else
                {
                    throw (new Exception("MYSQL ERROR VERSION INCOMPATIBLE, MUST BE >4.1.1"));
                }
            }
            catch { }
        }