summaryrefslogtreecommitdiff
path: root/WinKeyRecover/KeyChecker/CheckKey.cs
blob: 96b1f0ee5c55c5741babd932e661a7cbbbb8f224 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);
        }
    }
}