TSforge/LibTSforge/Modifiers/UniqueIdDelete.cs
WitherOrNot 6d759899d8 Add partial support (zcid, rtmr, non-functional kms4k) for vista
Co-authored-by: InvoxiPlayGames <22731889+InvoxiPlayGames@users.noreply.github.com>
2025-03-01 02:06:21 -05:00

58 lines
1.8 KiB
C#

namespace LibTSforge.Modifiers
{
using System;
using LibTSforge.PhysicalStore;
using LibTSforge.SPP;
public static class UniqueIdDelete
{
public static void DeleteUniqueId(PSVersion version, bool production, Guid actId)
{
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);
}
string instId = SLApi.GetInstallationID(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 Exception("No product key found.");
}
VariableBag pkb = new VariableBag(keyBlock.Data, version);
pkb.DeleteBlock("SppPkeyUniqueIdToken");
store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());
}
Logger.WriteLine("Successfully removed Unique ID for product key ID " + pkeyId);
}
}
}