Esempio n. 1
0
        public void AddUnsupportedToDB(string unSupportedKey)
        {
            this.ConnectToDB();

            string    tableName = "Unsupported Key";
            KeyDetail detail    = new KeyDetail(unSupportedKey);

            detail.prd  = tableName;
            detail.time = Utils.GetCurrentTime();

            //check table name exist
            SQLiteCommand table_cmd = m_connection.CreateCommand();

            table_cmd.CommandText = @" CREATE TABLE IF NOT EXISTS '" + tableName + @"' (
                                        Product_Key text PRIMARY KEY,
                                        Product_ID text,
                                        Advanced_PID text,
                                        Activation_ID text,
                                        Edition_Type text,
                                        Sub_Type text,
                                        Key_Type text,
                                        Eula text,
                                        Crypto_ID text,
                                        Activation_Count integer,
                                        Error_Code text,
                                        Time text
                                    ); ";
            table_cmd.ExecuteNonQuery();

            //add key to table
            SQLiteCommand sqlite_cmd = m_connection.CreateCommand();

            sqlite_cmd.CommandText = String.Format(@"INSERT INTO '" + tableName + @"' (Product_Key, Product_ID, Advanced_PID, Activation_ID,
                                            Edition_Type, Sub_Type, Key_Type, Eula, Crypto_ID, Activation_Count, Error_Code, Time) 
                                            VALUES ('{0}', '{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',{9},'{10}','{11}');",
                                                   detail.key, detail.keypid, detail.eid, detail.aid,
                                                   detail.edi, detail.sub, detail.lit, detail.lic, detail.cid,
                                                   detail.activationCount, detail.errorCode, detail.time);
            sqlite_cmd.ExecuteNonQuery();

            this.CloseDB();
        }
Esempio n. 2
0
        public string Check(string key, CheckMode checkMode, KeyDatabase keyDatabase)
        {
            key = key.ToUpper();

            string result = "";

            for (int j = 0; j < key.Length; j++)
            {
                char chr = key[j];
                if (!(chr == '-' || (chr >= '0' && chr <= '9') || (chr >= 'A' && chr <= 'Z')))
                {
                    return(result);
                }
            }

            KeyDetail detail = keyDatabase.GetKeyDetail(key);

            bool isKeyExistOnDB = true;

            if (detail == null) //Key is not exist on DB
            {
                detail         = PIDChecker.Check(key);
                isKeyExistOnDB = false;
            }

            if (detail == null || detail.prd.Contains("Unsupported")) //Key is invalid
            {
//                 result += "Key: " + key + "\n";
//                 result += "Error: Key is invalid or not supported\n\n";
                return(result);
            }

            bool isActivationCountUpdated = false;
            bool isErrorCodeUpdated       = false;
            bool isGetErrorCodeFail       = false;

            if (!(isKeyExistOnDB && detail.activationCount < 0))
            {
                detail.activationCount   = GetRemainingActivations(detail.eid);
                isActivationCountUpdated = true;
            }

            if (detail.activationCount <= 0)
            {
                bool isNeedGetErrorCode = true;

                bool isVLKey = false;
                if (detail.activationCount == 0)
                {
                    isVLKey = true;
                }

                if (detail.errorCode == "0xC004C003" || detail.errorCode == "0xC004C060" || detail.errorCode == "0xC004C004" || detail.errorCode == "Key Blocked") //key blocked or no remaining
                {
                    isNeedGetErrorCode = false;
                }
                else
                {
                    if (isKeyExistOnDB && detail.time != "")
                    {
                        var now           = DateTime.Now;
                        var lastTime      = Utils.ConvertStringToTime(detail.time);
                        var dt            = now - lastTime;
                        int timeToRecheck = 4;
                        if (detail.prd.Contains("Windows 7") || detail.prd.Contains("Office14"))
                        {
                            timeToRecheck = 10;
                        }

                        if (dt.TotalMinutes <= timeToRecheck)
                        {
                            isNeedGetErrorCode = false;
                        }
                    }
                }

                if (isNeedGetErrorCode && checkMode == CheckMode.ALL_DATA)
                {
                    string errorCode = this.GetErrorCodeOnServer(detail.prd, detail.key, isVLKey);
                    if (errorCode == "")
                    {
                        isGetErrorCodeFail = true;
                    }
                    else
                    {
                        detail.errorCode   = errorCode;
                        isErrorCodeUpdated = true;
                    }
                }
            }

            if (!isKeyExistOnDB)
            {
                detail.time = Utils.GetCurrentTime();


                keyDatabase.AddKeyToDB(detail);
            }
            else if ((isErrorCodeUpdated || isActivationCountUpdated) && !isGetErrorCodeFail)
            {
                detail.time = Utils.GetCurrentTime();

                keyDatabase.UpdateKeyInDB(detail);
            }
            else if (detail.time == "")
            {
                detail.time = Utils.GetCurrentTime();
            }

            result += "Key: " + key + "\r\n";
            result += "Description: " + detail.prd + "\r\n";
            result += "Sub Type: " + detail.sub + "\r\n";
            if (detail.activationCount >= 0)
            {
                result += "Activation Count: " + detail.activationCount.ToString() + "\r\n";
            }
            if (detail.activationCount <= 0 && checkMode == CheckMode.ALL_DATA)
            {
                if (isGetErrorCodeFail)
                {
                    result += "Error Code: Server busy, please try again later\r\n";
                }
                else
                {
                    result += "Error Code: " + detail.errorCode + "\r\n";
                }
            }
            result += "Time: " + detail.time + "\r\n\r\n";

            return(result);
        }