summaryrefslogtreecommitdiff
path: root/WinKeyRecover/KeyChecker
diff options
context:
space:
mode:
Diffstat (limited to 'WinKeyRecover/KeyChecker')
-rw-r--r--WinKeyRecover/KeyChecker/CheckKey.cs62
-rw-r--r--WinKeyRecover/KeyChecker/GetProductDescription.cs29
-rw-r--r--WinKeyRecover/KeyChecker/GetString.cs23
3 files changed, 114 insertions, 0 deletions
diff --git a/WinKeyRecover/KeyChecker/CheckKey.cs b/WinKeyRecover/KeyChecker/CheckKey.cs
new file mode 100644
index 0000000..96b1f0e
--- /dev/null
+++ b/WinKeyRecover/KeyChecker/CheckKey.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WinKeyRecover
+{
+ internal class CheckKey
+ {
+ private readonly IntPtr hModule;
+ private readonly string fileXml;
+ private readonly string mspid = "00000";
+ private readonly byte[] array = new byte[50];
+ private readonly byte[] array2 = new byte[164];
+ private readonly byte[] array3 = new byte[1272];
+ private readonly IntPtr intPtr = Marshal.AllocHGlobal(50);
+ private readonly IntPtr intPtr2 = Marshal.AllocHGlobal(164);
+ private readonly IntPtr intPtr3 = Marshal.AllocHGlobal(1272);
+ private readonly GetProductDescription getProductDescription = new GetProductDescription();
+ private readonly GetString getString = new GetString();
+ private string result;
+
+ public CheckKey(IntPtr hModule, string fileXml)
+ {
+ this.hModule = hModule;
+ this.fileXml = fileXml;
+ array[0] = 50;
+ array2[0] = 164;
+ array3[0] = 248;
+ array3[1] = 4;
+ Marshal.Copy(array, 0, intPtr, 50);
+ Marshal.Copy(array2, 0, intPtr2, 164);
+ Marshal.Copy(array3, 0, intPtr3, 1272);
+ }
+
+ public string Check(string key)
+ {
+ int num = ((NativeMethods.PidGenX)Marshal.GetDelegateForFunctionPointer(NativeMethods.GetProcAddress(hModule, "PidGenX"), typeof(NativeMethods.PidGenX)))(key, fileXml, mspid, 0, intPtr, intPtr2, intPtr3);
+ if (num == 0)
+ {
+ Marshal.Copy(intPtr3, array3, 0, array3.Length);
+ string @string = getString.Get(array3, 136);
+ result = getProductDescription.Get("{" + @string + "}", fileXml);
+ }
+ else
+ {
+ result = "Invalid";
+ }
+
+ return result;
+ }
+
+ public void FreeMemory()
+ {
+ Marshal.FreeHGlobal(intPtr);
+ Marshal.FreeHGlobal(intPtr2);
+ Marshal.FreeHGlobal(intPtr3);
+ }
+ }
+}
diff --git a/WinKeyRecover/KeyChecker/GetProductDescription.cs b/WinKeyRecover/KeyChecker/GetProductDescription.cs
new file mode 100644
index 0000000..3a42418
--- /dev/null
+++ b/WinKeyRecover/KeyChecker/GetProductDescription.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml;
+
+namespace WinKeyRecover
+{
+ internal class GetProductDescription
+ {
+ public string Get(string aid, string fileXml)
+ {
+ XmlDocument xmlDocument = new XmlDocument();
+ xmlDocument.Load(fileXml);
+ Stream inStream = new MemoryStream(Convert.FromBase64String(xmlDocument.GetElementsByTagName("tm:infoBin")[0].InnerText));
+ xmlDocument.Load(inStream);
+ XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
+ xmlNamespaceManager.AddNamespace("pkc", "http://www.microsoft.com/DRM/PKEY/Configuration/2.0");
+ XmlNode xmlNode = xmlDocument.SelectSingleNode("/pkc:ProductKeyConfiguration/pkc:Configurations/pkc:Configuration[pkc:ActConfigId='" + aid + "']", xmlNamespaceManager);
+ if (xmlNode == null)
+ {
+ xmlNode = xmlDocument.SelectSingleNode("/pkc:ProductKeyConfiguration/pkc:Configurations/pkc:Configuration[pkc:ActConfigId='" + aid.ToUpper() + "']", xmlNamespaceManager);
+ }
+ return xmlNode.ChildNodes.Item(3).InnerText;
+ }
+ }
+}
diff --git a/WinKeyRecover/KeyChecker/GetString.cs b/WinKeyRecover/KeyChecker/GetString.cs
new file mode 100644
index 0000000..bad8722
--- /dev/null
+++ b/WinKeyRecover/KeyChecker/GetString.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WinKeyRecover
+{
+ internal class GetString
+ {
+ public string Get(byte[] bytes, int index)
+ {
+ int num = index;
+
+ while (bytes[num] != 0 || bytes[num + 1] != 0)
+ {
+ num++;
+ }
+
+ return Encoding.ASCII.GetString(bytes, index, num - index).Replace("\0", "");
+ }
+ }
+}