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); } } }