add /siid option

This commit is contained in:
Wither OrNot 2025-04-04 03:43:27 -04:00
parent e86f43a286
commit 28acb8012f
3 changed files with 130 additions and 21 deletions

View File

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using LibTSforge.PhysicalStore;
using LibTSforge.SPP;
namespace LibTSforge.Modifiers
{
public static class SetIIDParams
{
public static void SetParams(PSVersion version, bool production, Guid actId, PKeyAlgorithm algorithm, int group, int serial, ulong security)
{
if (version == PSVersion.Vista) throw new NotSupportedException("This feature is not supported on Windows Vista/Server 2008.");
Guid appId;
if (actId == Guid.Empty)
{
appId = SLApi.WINDOWS_APP_ID;
actId = SLApi.GetDefaultActivationID(appId, true);
if (actId == Guid.Empty)
{
throw new Exception("No applicable activation IDs found.");
}
}
else
{
appId = SLApi.GetAppId(actId);
}
Guid pkeyId = SLApi.GetInstalledPkeyID(actId);
SPPUtils.KillSPP(version);
Logger.WriteLine("Writing TrustedStore data...");
using (IPhysicalStore store = SPPUtils.GetStore(version, production))
{
string key = string.Format("SPPSVC\\{0}\\{1}", appId, actId);
PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());
if (keyBlock == null)
{
throw new InvalidDataException("Failed to get product key data for activation ID " + actId + ".");
}
VariableBag pkb = new VariableBag(keyBlock.Data, version);
ProductKey pkey = new ProductKey
{
Group = group,
Serial = serial,
Security = security,
Algorithm = algorithm,
Upgrade = false
};
string blockName = version == PSVersion.Win7 ? "SppPkeyShortAuthenticator" : "SppPkeyPhoneActivationData";
pkb.SetBlock(blockName, pkey.GetPhoneData(version));
store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());
}
Logger.WriteLine("Successfully set IID parameters.");
}
}
}

View File

@ -249,10 +249,8 @@ namespace LibTSforge.SPP
{ {
if (version == PSVersion.Win7) if (version == PSVersion.Win7)
{ {
Random rnd = new Random(Group * 1000000000 + Serial); ulong shortauth = ((ulong)Group << 41) | ((ulong)Security << 31) | ((ulong)Serial << 1) | (Upgrade ? (ulong)1 : 0);
byte[] data = new byte[8]; return BitConverter.GetBytes(shortauth);
rnd.NextBytes(data);
return data;
} }
int serialHigh = Serial / 1000000; int serialHigh = Serial / 1000000;

View File

@ -25,10 +25,15 @@ namespace TSforgeCLI
public bool KMSHostCharge = false; public bool KMSHostCharge = false;
public bool TamperedFlagsDelete = false; public bool TamperedFlagsDelete = false;
public bool KeyChangeLockDelete = false; public bool KeyChangeLockDelete = false;
public bool SetIIDParams = false;
public bool? Production = null; public bool? Production = null;
public PSVersion? Version = null; public PSVersion? Version = null;
public Guid ActivationId = Guid.Empty; public Guid ActivationId = Guid.Empty;
public bool ShowHelp = false; 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) public static void Main(string[] args)
@ -103,6 +108,10 @@ namespace TSforgeCLI
else if (options.KeyChangeLockDelete) else if (options.KeyChangeLockDelete)
{ {
KeyChangeLockDelete.Delete(version, production); KeyChangeLockDelete.Delete(version, production);
}
else if (options.SetIIDParams)
{
SetIIDParams.SetParams(version, production, options.ActivationId, options.Algorithm.Value, options.Group, options.Serial, options.Security);
} }
else else
{ {
@ -187,6 +196,38 @@ namespace TSforgeCLI
break; break;
case "/revl": case "/revl":
options.KeyChangeLockDelete = true; 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; break;
default: default:
try try
@ -211,23 +252,24 @@ namespace TSforgeCLI
string exeName = typeof(Program).Namespace; string exeName = typeof(Program).Namespace;
Logger.WriteLine("Usage: " + exeName + " [/dump <filePath> (<encrFilePath>)] [/load <filePath>] [/kms4k] [/avma4k] [/zcid] [/rtmr] [/duid] [/igpk] [/kmsc] [/ctpr] [/revl] [/prod] [/test] [<activation id>] [/ver <version override>]"); Logger.WriteLine("Usage: " + exeName + " [/dump <filePath> (<encrFilePath>)] [/load <filePath>] [/kms4k] [/avma4k] [/zcid] [/rtmr] [/duid] [/igpk] [/kmsc] [/ctpr] [/revl] [/prod] [/test] [<activation id>] [/ver <version override>]");
Logger.WriteLine("Options:"); Logger.WriteLine("Options:");
Logger.WriteLine("\t/dump <filePath> (<encrFilePath>) Dump and decrypt the physical store to the specified path."); 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/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/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/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/zcid Activate using ZeroCID. Only supports phone-activatable editions.");
Logger.WriteLine("\t/rtmr Reset grace/evaluation period timers."); Logger.WriteLine("\t/rtmr Reset grace/evaluation period timers.");
Logger.WriteLine("\t/rrmc Reset the rearm count."); 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/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/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/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/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/revl Remove the key change lock in evaluation edition store.");
Logger.WriteLine("\t/prod Use SPP production key."); 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/test Use SPP test key."); Logger.WriteLine("\t/prod Use SPP production key.");
Logger.WriteLine("\t/ver <version> Override the detected version. Available versions: vista, 7, 8, blue, modern."); Logger.WriteLine("\t/test Use SPP test key.");
Logger.WriteLine("\t<activation id> A specific activation ID. Useful if you want to activate specific addons like ESU."); Logger.WriteLine("\t/ver <version> Override the detected version. Available versions: vista, 7, 8, blue, modern.");
Logger.WriteLine("\t/? Display this help message."); 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) private static PSVersion ParseVersion(string ver)