Exemplo n.º 1
0
        public void UpdateKeyInDB(KeyDetail detail)
        {
            string tableName = detail.prd;

            this.ConnectToDB();

            SQLiteCommand sqlite_cmd = m_connection.CreateCommand();

            sqlite_cmd.CommandText = String.Format(@"UPDATE '" + tableName + "' SET Activation_Count = '{0}', Error_Code = '{1}', Time = '{2}' WHERE Product_Key = '{3}';",
                                                   detail.activationCount, detail.errorCode, detail.time, detail.key);

            sqlite_cmd.ExecuteNonQuery();

            this.CloseDB();
        }
Exemplo n.º 2
0
        public KeyDetail GetUncompletedKeyDetail(string uncompletedKey)
        {
            KeyDetail detail = null;

            ArrayList tables = GetTables();

            this.ConnectToDB();

            try
            {
                for (int i = 0; i < tables.Count; i++)
                {
                    SQLiteCommand sqlite_cmd = m_connection.CreateCommand();
                    sqlite_cmd.CommandText = String.Format("SELECT * FROM '" + tables[i].ToString() + "';");
                    SQLiteDataReader sqlite_datareader = sqlite_cmd.ExecuteReader();
                    while (sqlite_datareader.Read())
                    {
                        string key        = sqlite_datareader.GetString(0);
                        string compareKey = key.Substring(0, uncompletedKey.Length);
                        if (uncompletedKey == compareKey)
                        {
                            detail        = new KeyDetail(key);
                            detail.keypid = sqlite_datareader.GetString(1);
                            detail.eid    = sqlite_datareader.GetString(2);
                            detail.aid    = sqlite_datareader.GetString(3);
                            detail.edi    = sqlite_datareader.GetString(4);
                            detail.sub    = sqlite_datareader.GetString(5);
                            detail.lit    = sqlite_datareader.GetString(6);
                            detail.lic    = sqlite_datareader.GetString(7);
                            detail.cid    = sqlite_datareader.GetString(8);

                            detail.prd = tables[i].ToString();

                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Check uncompleted key exist fail");
            }

            this.CloseDB();

            return(detail);
        }
Exemplo n.º 3
0
        public KeyDetail GetKeyDetail(string key)
        {
            KeyDetail detail = null;

            ArrayList tables = GetTables();

            this.ConnectToDB();

            for (int i = 0; i < tables.Count; i++)
            {
                string query = "SELECT * FROM '" + tables[i].ToString() + "' WHERE Product_Key = '" + key + "'";
                try
                {
                    using (SQLiteCommand cmd = new SQLiteCommand(query, m_connection))
                    {
                        using (SQLiteDataReader sqlite_datareader = cmd.ExecuteReader())
                        {
                            if (sqlite_datareader.Read())
                            {
                                detail                 = new KeyDetail(key);
                                detail.keypid          = sqlite_datareader.GetString(1);
                                detail.eid             = sqlite_datareader.GetString(2);
                                detail.aid             = sqlite_datareader.GetString(3);
                                detail.edi             = sqlite_datareader.GetString(4);
                                detail.sub             = sqlite_datareader.GetString(5);
                                detail.lit             = sqlite_datareader.GetString(6);
                                detail.lic             = sqlite_datareader.GetString(7);
                                detail.cid             = sqlite_datareader.GetString(8);
                                detail.activationCount = sqlite_datareader.GetInt32(9);
                                detail.errorCode       = sqlite_datareader.GetString(10);
                                detail.time            = sqlite_datareader.GetString(11);
                                detail.prd             = tables[i].ToString();

                                break;
                            }
                        }
                    }
                }
                catch (Exception e) { };
            }

            this.CloseDB();

            return(detail);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        public ArrayList GetAllKeyFromTable(string tableName)
        {
            ArrayList list = new ArrayList();

            this.ConnectToDB();

            string query = "SELECT * FROM '" + tableName + "';";

            try
            {
                using (SQLiteCommand cmd = new SQLiteCommand(query, m_connection))
                {
                    using (SQLiteDataReader sqlite_datareader = cmd.ExecuteReader())
                    {
                        while (sqlite_datareader.Read())
                        {
                            KeyDetail detail = new KeyDetail(sqlite_datareader.GetString(0));
                            detail.keypid          = sqlite_datareader.GetString(1);
                            detail.eid             = sqlite_datareader.GetString(2);
                            detail.aid             = sqlite_datareader.GetString(3);
                            detail.edi             = sqlite_datareader.GetString(4);
                            detail.sub             = sqlite_datareader.GetString(5);
                            detail.lit             = sqlite_datareader.GetString(6);
                            detail.lic             = sqlite_datareader.GetString(7);
                            detail.cid             = sqlite_datareader.GetString(8);
                            detail.activationCount = sqlite_datareader.GetInt32(9);
                            detail.errorCode       = sqlite_datareader.GetString(10);
                            detail.time            = sqlite_datareader.GetString(11);
                            detail.prd             = tableName;

                            list.Add(detail);
                        }
                    }
                }
            }
            catch (Exception e) { };

            this.CloseDB();

            return(list);
        }
Exemplo n.º 6
0
        public static KeyDetail Check(string productKey)
        {
            KeyDetail detail = null;

            byte[] gpid = new byte[0x32];
            byte[] opid = new byte[0xA4];
            byte[] npid = new byte[0x04F8];

            IntPtr PID   = Marshal.AllocHGlobal(0x32);
            IntPtr DPID  = Marshal.AllocHGlobal(0xA4);
            IntPtr DPID4 = Marshal.AllocHGlobal(0x04F8);

            string MSPID = "00000";

            gpid[0] = 0x32;
            opid[0] = 0xA4;
            npid[0] = 0xF8;
            npid[1] = 0x04;

            Marshal.Copy(gpid, 0, PID, 0x32);
            Marshal.Copy(opid, 0, DPID, 0xA4);
            Marshal.Copy(npid, 0, DPID4, 0x04F8);

            int    RetID      = -1;
            string pKeyConfig = "";

            for (int i = 0; i < pkeyConfigList.Count; i++)
            {
                pKeyConfig = pkeyConfigList[i];
                RetID      = PidGenX(productKey, pKeyConfig, MSPID, 0, PID, DPID, DPID4);
                if (RetID == 0)
                {
                    detail = new KeyDetail(productKey);
                    Marshal.Copy(PID, gpid, 0, gpid.Length);
                    Marshal.Copy(DPID4, npid, 0, npid.Length);
                    detail.keypid = GetString(gpid, 0x0000);
                    detail.eid    = GetString(npid, 0x0008);
                    detail.aid    = GetString(npid, 0x0088);
                    detail.edi    = GetString(npid, 0x0118);
                    detail.sub    = GetString(npid, 0x0378);
                    detail.lit    = GetString(npid, 0x03F8);
                    detail.lic    = GetString(npid, 0x0478);
                    // Fix for 4/5 digit Win 8 CryptoId, Win 7 (3 digit) and Office (2 or 3 digit) are prefixed with zeros which are stripped below
                    detail.cid = Convert.ToInt32(detail.eid.Substring(6, 5)).ToString(CultureInfo.InvariantCulture);
                    string prd = GetProductDescription(pKeyConfig, "{" + detail.aid + "}", detail.edi);

                    if (prd.StartsWith("RTM_"))
                    {
                        prd = "Office14" + prd.Remove(0, 3);
                    }
                    detail.prd = prd;

                    break;
                }
            }

            Marshal.FreeHGlobal(PID);
            Marshal.FreeHGlobal(DPID);
            Marshal.FreeHGlobal(DPID4);
            //FreeLibrary(dllHandle);

            return(detail);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        private void keyTableRefreshClick(object sender, EventArgs e)
        {
            if (isKeyRefreshCanceling)
            {
                return;
            }

            if (isKeyRefreshing)
            {
                isKeyRefreshCanceling = true;

                return;
            }

            DataGridViewSelectedCellCollection selectedCells = this.keyDataGridView.SelectedCells;

            HashSet <DataGridViewRow> selectedRows = new HashSet <DataGridViewRow>();

            for (int i = 0; i < selectedCells.Count; i++)
            {
                selectedRows.Add(this.keyDataGridView.Rows[selectedCells[i].RowIndex]);
            }

            if (selectedRows.Count == 0)
            {
                return;
            }

            isKeyRefreshing = true;

            string tableName = this.keyTypeComboBox.SelectedItem.ToString();

            foreach (var r in selectedRows.Reverse())
            {
                string key = r.Cells[1].Value.ToString();

                r.Cells[3].Value = "Updating..";
                r.Cells[4].Value = "Updating..";
                r.Cells[5].Value = "Updating..";

                Thread t = new Thread(() =>
                {
                    keyChecker.Check(key, CheckMode.ALL_DATA, keyDatabase);
                });
                t.Start();

                while (t.IsAlive)
                {
                    Application.DoEvents();
                    Thread.Sleep(1);
                }

                KeyDetail detail = keyDatabase.GetKeyDetail(key);
                if (detail != null)
                {
                    r.Cells[3].Value = detail.activationCount.ToString();
                    r.Cells[4].Value = detail.errorCode;
                    r.Cells[5].Value = detail.time;

                    Application.DoEvents();
                }

                if (isKeyRefreshCanceling)
                {
                    break;
                }
            }

            isKeyRefreshing       = false;
            isKeyRefreshCanceling = false;
        }