summaryrefslogtreecommitdiff
path: root/TSforgeCLI/Program.cs
blob: 25e132fbe20ec245e7db887aa669ac67ccd24006 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
namespace TSforgeCLI
{
    using System;
    using LibTSforge;
    using LibTSforge.Activators;
    using LibTSforge.Modifiers;
    using LibTSforge.SPP;

    public class Program
    {
        private class Options
        {
            public bool Dump = false;
            public string DumpFilePath = "dump.dat";
            public string EncrFilePath = null;
            public bool Load = false;
            public string LoadFilePath = "load.dat";
            public bool KMS4k = false;
            public bool AVMA4k = false;
            public bool ZCID = false;
            public bool TimerReset = false;
            public bool RearmReset = false;
            public bool DeleteUniqueId = false;
            public bool InstallGenPKey = false;
            public bool KMSHostCharge = false;
            public bool TamperedFlagsDelete = false;
            public bool KeyChangeLockDelete = false;
            public bool SetIIDParams = false;
            public bool? Production = null;
            public PSVersion? Version = null;
            public Guid ActivationId = Guid.Empty;
            public bool ShowHelp = false;
            public PKeyAlgorithm? Algorithm = null;
            public int Group = 0;
            public int Serial = 0;
            public ulong Security = 0;
        }

        public static void Main(string[] args)
        {
            Logger.WriteLine("TSforge (c) MASSGRAVE 2025");

            Utils.Wow64EnableWow64FsRedirection(false);

            try
            {
                if (args.Length == 0)
                {
                    DisplayUsage();
                    return;
                }

                Options options = ParseArguments(args);

                if (options.ShowHelp)
                {
                    DisplayUsage();
                    return;
                }

                PSVersion version = options.Version ?? Utils.DetectVersion();
                bool production = options.Production ?? SPPUtils.DetectCurrentKey();

                if (options.Dump)
                {
                    SPPUtils.DumpStore(version, production, options.DumpFilePath, options.EncrFilePath);
                }
                else if (options.Load)
                {
                    SPPUtils.LoadStore(version, production, options.LoadFilePath);
                }
                else if (options.KMS4k)
                {
                    KMS4k.Activate(version, production, options.ActivationId);
                }
                else if (options.AVMA4k)
                {
                    AVMA4k.Activate(version, production, options.ActivationId);
                }
                else if (options.ZCID)
                {
                    ZeroCID.Activate(version, production, options.ActivationId);
                }
                else if (options.TimerReset)
                {
                    GracePeriodReset.Reset(version, production);
                }
                else if (options.DeleteUniqueId)
                {
                    UniqueIdDelete.DeleteUniqueId(version, production, options.ActivationId);
                }
                else if (options.RearmReset)
                {
                    RearmReset.Reset(version, production);
                }
                else if (options.InstallGenPKey)
                {
                    GenPKeyInstall.InstallGenPKey(version, production, options.ActivationId);
                }
                else if (options.KMSHostCharge)
                {
                    KMSHostCharge.Charge(version, production, options.ActivationId);
                }
                else if (options.TamperedFlagsDelete)
                {
                    TamperedFlagsDelete.DeleteTamperFlags(version, production);
                }
                else if (options.KeyChangeLockDelete)
                {
                    KeyChangeLockDelete.Delete(version, production);
                } 
                else if (options.SetIIDParams)
                {
                    SetIIDParams.SetParams(version, production, options.ActivationId, options.Algorithm.Value, options.Group, options.Serial, options.Security);
                }
                else
                {
                    DisplayUsage();
                }
            }
            catch (Exception e)
            {
#if DEBUG
                throw;
#else
                Logger.WriteLine("Fatal error: " + e.ToString());
                Environment.Exit(1);
#endif
            }
        }

        private static Options ParseArguments(string[] args)
        {
            Options options = new Options();
            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i].Trim().ToLowerInvariant();
                switch (arg)
                {
                    case "/dump":
                        options.Dump = true;
                        if (i + 1 < args.Length && !args[i + 1].StartsWith("/"))
                        {
                            options.DumpFilePath = args[++i];
                        }
                        if (i + 1 < args.Length && !args[i + 1].StartsWith("/"))
                        {
                            options.EncrFilePath = args[++i];
                        }
                        break;
                    case "/load":
                        options.Load = true;
                        if (i + 1 < args.Length && !args[i + 1].StartsWith("/"))
                        {
                            options.LoadFilePath = args[++i];
                        }
                        break;
                    case "/kms4k":
                        options.KMS4k = true;
                        break;
                    case "/avma4k":
                        options.AVMA4k = true;
                        break;
                    case "/zcid":
                        options.ZCID = true;
                        break;
                    case "/ver":
                        options.Version = i + 1 < args.Length ? ParseVersion(args[++i]) : throw new ArgumentException("/ver requires a version argument.");
                        break;
                    case "/rtmr":
                        options.TimerReset = true;
                        break;
                    case "/?":
                        options.ShowHelp = true;
                        break;
                    case "/duid":
                        options.DeleteUniqueId = true;
                        break;
                    case "/rrmc":
                        options.RearmReset = true;
                        break;
                    case "/igpk":
                        options.InstallGenPKey = true;
                        break;
                    case "/kmsc":
                        options.KMSHostCharge = true;
                        break;
                    case "/test":
                        options.Production = false;
                        break;
                    case "/prod":
                        options.Production = true;
                        break;
                    case "/ctpr":
                        options.TamperedFlagsDelete = true;
                        break;
                    case "/revl":
                        options.KeyChangeLockDelete = true;
                        break;
                    case "/siid":
                        options.SetIIDParams = true;

                        if (args.Length - i - 1 < 4) throw new ArgumentException("Not enough arguments specified.");

                        string algoType = args[++i];

                        if (algoType == "5")
                        {
                            options.Algorithm = PKeyAlgorithm.PKEY2005;
                        }
                        else if (algoType == "9")
                        {
                            options.Algorithm = PKeyAlgorithm.PKEY2009;
                        } 
                        else 
                        { 
                            throw new ArgumentException("Invalid key algorithm specified.");
                        }

                        try
                        {
                            options.Group = int.Parse(args[++i]);
                            options.Serial = int.Parse(args[++i]);
                            options.Security = ulong.Parse(args[++i]);
                        } 
                        catch
                        {
                            throw new ArgumentException("Failed to parse key parameters.");
                        }

                        break;
                    default:
                        try
                        {
                            options.ActivationId = new Guid(arg);
                        }
                        catch (FormatException)
                        {
                            Logger.WriteLine("Argument doesn't exist or the specified activation ID is invalid.");
                            options.ShowHelp = true;
                        }
                        break;
                }
            }

            return options;
        }

        private static void DisplayUsage()
        {
            string exeName = typeof(Program).Namespace;
            Logger.WriteLine("Usage: " + exeName + " [/dump <filePath> (<encrFilePath>)] [/load <filePath>] [/kms4k] [/avma4k] [/zcid] [/rtmr] [/duid] [/igpk] [/kmsc] [/ctpr] [/revl] [/siid <5/9> <group> <serial> <security>] [/prod] [/test] [<activation id>] [/ver <version override>]");
            Logger.WriteLine("Options:");
            Logger.WriteLine("\t/dump <filePath> (<encrFilePath>)         Dump and decrypt the physical store to the specified path.");
            Logger.WriteLine("\t/load <filePath>                          Load and re-encrypt the physical store from the specified path.");
            Logger.WriteLine("\t/kms4k                                    Activate using KMS4k. Only supports KMS-activatable editions.");
            Logger.WriteLine("\t/avma4k                                   Activate using AVMA4k. Only supports Windows Server 2012 R2+.");
            Logger.WriteLine("\t/zcid                                     Activate using ZeroCID. Only supports phone-activatable editions.");
            Logger.WriteLine("\t/rtmr                                     Reset grace/evaluation period timers.");
            Logger.WriteLine("\t/rrmc                                     Reset the rearm count.");
            Logger.WriteLine("\t/duid                                     Delete product key Unique ID used in online key validation.");
            Logger.WriteLine("\t/igpk                                     Install auto-generated/fake product key according to the specified Activation ID");
            Logger.WriteLine("\t/kmsc                                     Reset the charged count on the local KMS server to 25. Requires an activated KMS host.");
            Logger.WriteLine("\t/ctpr                                     Remove the tamper flags that get set in the physical store when sppsvc detects an attempt to tamper with it.");
            Logger.WriteLine("\t/revl                                     Remove the key change lock in evaluation edition store.");
            Logger.WriteLine("\t/siid <5/9> <group> <serial> <security>   Set Installation ID parameters independently of installed key. 5/9 argument specifies PKEY200[5/9] key algorithm.");
            Logger.WriteLine("\t/prod                                     Use SPP production key.");
            Logger.WriteLine("\t/test                                     Use SPP test key.");
            Logger.WriteLine("\t/ver <version>                            Override the detected version. Available versions: vista, 7, 8, blue, modern.");
            Logger.WriteLine("\t<activation id>                           A specific activation ID. Useful if you want to activate specific addons like ESU.");
            Logger.WriteLine("\t/?                                        Display this help message.");
        }

        private static PSVersion ParseVersion(string ver)
        {
            switch (ver.Trim().ToLowerInvariant())
            {
                case "vista": return PSVersion.Vista;
                case "7": return PSVersion.Win7;
                case "8": return PSVersion.Win8;
                case "blue": return PSVersion.WinBlue;
                case "modern": return PSVersion.WinModern;
                default: throw new ArgumentException("Invalid version specified.");
            }
        }
    }
}