Esempio n. 1
0
        static void Main(string[] args)
        {
            switch (args.Length)
            {
            case 1:
                break;

            default:
                Console.WriteLine("{\"status\":\"" + "error\", \"errormessage\": \"" + "Invalid number args, usage pidchk.exe XXXXX-XXXXX-XXXXX-XXXXX-XXXXX\"" + "}");
                return;
            }

            Regex rgx = new Regex(@"^([A-Za-z0-9]{5}-){4}[A-Za-z0-9]{5}$");

            if (!rgx.IsMatch(args[0]))
            {
                Console.WriteLine("{\"status\":\"" + "error\", \"errormessage\": \"" + "Productkey not in valid format XXXXX-XXXXX-XXXXX-XXXXX-XXXXX\"" + "}");
                return;
            }

            string productKey = args[0];
            //string pwd = Directory.GetCurrentDirectory();
            string        pwd = Environment.GetEnvironmentVariable("PIDCHK_HOME");
            DirectoryInfo objDirectoryInfo = new DirectoryInfo(pwd);

            FileInfo[] pkconfigFiles = objDirectoryInfo.GetFiles("*.xrm-ms", SearchOption.AllDirectories);
            if (pkconfigFiles.Length != 0)
            {
                bool   success = false;
                string lasterr = "";

                try
                {
                    PidChecker pidCheck;
                    pidCheck = new PidChecker();

                    foreach (var file in pkconfigFiles)
                    {
                        string      PKeyPath = file.FullName;
                        string      result   = pidCheck.CheckProductKey(productKey, PKeyPath);
                        LicenseInfo obj      = JsonConvert.DeserializeObject <LicenseInfo>(result);
                        if (obj.Status == "success")
                        {
                            success = true;
                            Console.WriteLine(result);
                            break;
                        }
                        lasterr = result;
                    }

                    if (!success)
                    {
                        Console.WriteLine(lasterr);
                    }
                }
                catch (System.DllNotFoundException)
                {
                    Console.WriteLine("{\"status\":\"" + "error\", \"errormessage\": \"" + "ProductKeyUtilities.dll from adk-vamt not found or missing\"" + "}");
                    throw;
                }
            }
            else
            {
                Console.WriteLine("{\"status\":\"" + "error\", \"errormessage\": \"" + "pkeyconfig files from adk-vamt not found or missing.\"" + "}");
            }
            return;
        }
Esempio n. 2
0
        internal string CheckProductKey(string productKey, string PKeyPath)
        {
            string      result = "";
            int         RetID;
            LicenseInfo licenseInfo;

            licenseInfo = new LicenseInfo();

            byte[] pid2 = new byte[0x32];
            byte[] pid3 = new byte[0xA4];
            byte[] pid4 = new byte[0x04F8];

            IntPtr PID   = Marshal.AllocHGlobal(0x32);
            IntPtr DPID  = Marshal.AllocHGlobal(0xA4);
            IntPtr DPID4 = Marshal.AllocHGlobal(0x04F8);
            string MSPID = "XXXXX";

            pid2[0] = 0x32;
            pid3[0] = 0xA4;
            pid4[0] = 0xF8;
            pid4[1] = 0x04;

            Marshal.Copy(pid2, 0, PID, 0x32);
            Marshal.Copy(pid3, 0, DPID, 0xA4);
            Marshal.Copy(pid4, 0, DPID4, 0x04F8);

            RetID = PidGenX(productKey, PKeyPath, MSPID, 0, PID, DPID, DPID4);

            if (RetID == 0)
            {
                Marshal.Copy(PID, pid2, 0, pid2.Length);
                Marshal.Copy(DPID4, pid4, 0, pid4.Length);
                string id         = GetString(pid4, 0x0008);
                string act        = GetString(pid4, 0x0088);
                string edi        = GetString(pid4, 0x0118);
                string edid       = GetString(pid4, 0x0378);
                string lit        = GetString(pid4, 0x03F8);
                string pchan      = GetString(pid4, 0x0478);
                string pdes       = GetProductDescription(PKeyPath, "{" + act + "}", edi);
                string configfile = PKeyPath.Substring(PKeyPath.LastIndexOf(@"\"));
                configfile = configfile.TrimStart('\\');

                licenseInfo.Status         = "success";
                licenseInfo.PkeyFile       = configfile;
                licenseInfo.ProductKey     = productKey;
                licenseInfo.KeyStatus      = "Valid";
                licenseInfo.ExtendedPID    = id;
                licenseInfo.ActivationID   = act;
                licenseInfo.EditionType    = edi;
                licenseInfo.EditionID      = edid;
                licenseInfo.LicenseType    = lit;
                licenseInfo.LicenseChannel = pchan;
                licenseInfo.ProductDesc    = pdes;

                /*
                 * Console.WriteLine(" Product Key:         = {0}",productKey);
                 * Console.WriteLine(" Key Status:          = Valid");
                 * Console.WriteLine(" Extended PID:        = " + id);
                 * Console.WriteLine(" Activation ID:       = " + act);
                 * Console.WriteLine(" Edition Type:        = " + edi);
                 * Console.WriteLine(" Edition ID:          = " + edid);
                 * Console.WriteLine(" License Type:        = " + lit);
                 * Console.WriteLine(" License Channel:     = " + pchan);
                 * Console.WriteLine(" Product Description: = " + pdes);
                 */

                result = licenseInfo.Dump();
            }
            else if (RetID == -2147024809)
            {
                licenseInfo.Status       = "error";
                licenseInfo.ErrorMessage = $"{RetID} PidGenX :: Invalid Arguments.";
                result = licenseInfo.Dump();
            }
            else if (RetID == -1979645695)
            {
                licenseInfo.Status       = "error";
                licenseInfo.ErrorMessage = $"{RetID} PidGenX :: Specified key does not work with pkeyconfig file.";
                result = licenseInfo.Dump();
            }
            else if (RetID == -2147024894)
            {
                licenseInfo.Status       = "error";
                licenseInfo.ErrorMessage = $"{RetID} in PidGenX :: pkeyconfig.xrm.ms file not found.";
                result = licenseInfo.Dump();
            }
            else if (RetID == -2147024893)
            {
                licenseInfo.Status       = "error";
                licenseInfo.ErrorMessage = $"{RetID} in PidGenX :: Invalid Function Call.";
                result = licenseInfo.Dump();
            }
            else
            {
                licenseInfo.Status       = "error";
                licenseInfo.ErrorMessage = $"{RetID} in PidGenX :: Unkown Error.";
                result = licenseInfo.Dump();
            }

            Marshal.FreeHGlobal(PID);
            Marshal.FreeHGlobal(DPID);
            Marshal.FreeHGlobal(DPID4);
            return(result);
        }