From 6d759899d85939c95f2b97c8e041d7b4865208f9 Mon Sep 17 00:00:00 2001 From: WitherOrNot Date: Sat, 1 Mar 2025 02:01:39 -0500 Subject: Add partial support (zcid, rtmr, non-functional kms4k) for vista Co-authored-by: InvoxiPlayGames <22731889+InvoxiPlayGames@users.noreply.github.com> --- LibTSforge/SPP/ProductKey.cs | 10 +- LibTSforge/SPP/SLAPI.cs | 22 ++-- LibTSforge/SPP/SPPUtils.cs | 275 +++++++++++++++++++++++++++++++++++++++++++ LibTSforge/SPP/SPSys.cs | 47 ++++++++ 4 files changed, 338 insertions(+), 16 deletions(-) create mode 100644 LibTSforge/SPP/SPPUtils.cs create mode 100644 LibTSforge/SPP/SPSys.cs (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/SPP/ProductKey.cs b/LibTSforge/SPP/ProductKey.cs index 7a933da..b5fca9a 100644 --- a/LibTSforge/SPP/ProductKey.cs +++ b/LibTSforge/SPP/ProductKey.cs @@ -60,22 +60,22 @@ namespace LibTSforge.SPP public Guid GetPkeyId() { - VariableBag pkb = new VariableBag(); - pkb.Blocks.AddRange(new CRCBlock[] + VariableBag pkb = new VariableBag(PSVersion.WinModern); + pkb.Blocks.AddRange(new CRCBlockModern[] { - new CRCBlock + new CRCBlockModern { DataType = CRCBlockType.STRING, KeyAsStr = "SppPkeyBindingProductKey", ValueAsStr = ToString() }, - new CRCBlock + new CRCBlockModern { DataType = CRCBlockType.BINARY, KeyAsStr = "SppPkeyBindingMiscData", Value = new byte[] { } }, - new CRCBlock + new CRCBlockModern { DataType = CRCBlockType.STRING, KeyAsStr = "SppPkeyBindingAlgorithm", diff --git a/LibTSforge/SPP/SLAPI.cs b/LibTSforge/SPP/SLAPI.cs index cfd7dc5..336d88f 100644 --- a/LibTSforge/SPP/SLAPI.cs +++ b/LibTSforge/SPP/SLAPI.cs @@ -44,40 +44,40 @@ namespace LibTSforge.SPP public static readonly Guid WINDOWS_APP_ID = new Guid("55c92734-d682-4d71-983e-d6ec3f16059f"); - [DllImport("sppc.dll", CharSet = CharSet.Unicode, PreserveSig = false)] + [DllImport("slc.dll", CharSet = CharSet.Unicode, PreserveSig = false)] private static extern void SLOpen(out IntPtr hSLC); - [DllImport("sppc.dll", CharSet = CharSet.Unicode, PreserveSig = false)] + [DllImport("slc.dll", CharSet = CharSet.Unicode, PreserveSig = false)] private static extern void SLClose(IntPtr hSLC); [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLGetWindowsInformationDWORD(string ValueName, ref int Value); - [DllImport("sppc.dll", CharSet = CharSet.Unicode)] + [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLInstallProofOfPurchase(IntPtr hSLC, string pwszPKeyAlgorithm, string pwszPKeyString, uint cbPKeySpecificData, byte[] pbPKeySpecificData, ref Guid PKeyId); - [DllImport("sppc.dll", CharSet = CharSet.Unicode)] + [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLUninstallProofOfPurchase(IntPtr hSLC, ref Guid PKeyId); - [DllImport("sppc.dll", CharSet = CharSet.Unicode)] + [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLGetPKeyInformation(IntPtr hSLC, ref Guid pPKeyId, string pwszValueName, out SLDATATYPE peDataType, out uint pcbValue, out IntPtr ppbValue); - [DllImport("sppcext.dll", CharSet = CharSet.Unicode)] + [DllImport("slcext.dll", CharSet = CharSet.Unicode)] private static extern uint SLActivateProduct(IntPtr hSLC, ref Guid pProductSkuId, byte[] cbAppSpecificData, byte[] pvAppSpecificData, byte[] pActivationInfo, string pwszProxyServer, ushort wProxyPort); - [DllImport("sppc.dll", CharSet = CharSet.Unicode)] + [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLGenerateOfflineInstallationId(IntPtr hSLC, ref Guid pProductSkuId, ref string ppwszInstallationId); - [DllImport("sppc.dll", CharSet = CharSet.Unicode)] + [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLDepositOfflineConfirmationId(IntPtr hSLC, ref Guid pProductSkuId, string pwszInstallationId, string pwszConfirmationId); - [DllImport("sppc.dll", CharSet = CharSet.Unicode)] + [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLGetSLIDList(IntPtr hSLC, SLIDTYPE eQueryIdType, ref Guid pQueryId, SLIDTYPE eReturnIdType, out uint pnReturnIds, out IntPtr ppReturnIds); - [DllImport("sppc.dll", CharSet = CharSet.Unicode, PreserveSig = false)] + [DllImport("slc.dll", CharSet = CharSet.Unicode, PreserveSig = false)] private static extern void SLGetLicensingStatusInformation(IntPtr hSLC, ref Guid pAppID, IntPtr pProductSkuId, string pwszRightName, out uint pnStatusCount, out IntPtr ppLicensingStatus); - [DllImport("sppc.dll", CharSet = CharSet.Unicode)] + [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLGetInstalledProductKeyIds(IntPtr hSLC, ref Guid pProductSkuId, out uint pnProductKeyIds, out IntPtr ppProductKeyIds); [DllImport("slc.dll", CharSet = CharSet.Unicode)] diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs new file mode 100644 index 0000000..f1aa32f --- /dev/null +++ b/LibTSforge/SPP/SPPUtils.cs @@ -0,0 +1,275 @@ +namespace LibTSforge.SPP +{ + using LibTSforge.Crypto; + using LibTSforge.PhysicalStore; + using LibTSforge.TokenStore; + using Microsoft.Win32; + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.ServiceProcess; + using System.Text; + + public static class SPPUtils + { + public static void KillSPP(PSVersion version) + { + ServiceController sc; + + string svcName = version == PSVersion.Vista ? "slsvc" : "sppsvc"; + + try + { + sc = new ServiceController(svcName); + + if (sc.Status == ServiceControllerStatus.Stopped) + return; + } + catch (InvalidOperationException ex) + { + throw new InvalidOperationException(string.Format("Unable to access {0}: ", svcName) + ex.Message); + } + + Logger.WriteLine(string.Format("Stopping {0}...", svcName)); + + bool stopped = false; + + for (int i = 0; stopped == false && i < 360; i++) + { + try + { + if (sc.Status != ServiceControllerStatus.StopPending) + sc.Stop(); + + sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(500)); + } + catch (System.ServiceProcess.TimeoutException) + { + continue; + } + catch (InvalidOperationException) + { + System.Threading.Thread.Sleep(500); + continue; + } + + stopped = true; + } + + if (!stopped) + throw new System.TimeoutException(string.Format("Failed to stop {0}", svcName)); + + Logger.WriteLine(string.Format("{0} stopped successfully.", svcName)); + + if (version == PSVersion.Vista && SPSys.IsSpSysRunning()) + { + Logger.WriteLine("Unloading spsys..."); + + int status = SPSys.ControlSpSys(false); + + if (status < 0) + { + throw new IOException("Failed to unload spsys"); + } + + Logger.WriteLine("spsys unloaded successfully."); + } + } + + public static void RestartSPP(PSVersion version) + { + if (version == PSVersion.Vista) + { + ServiceController sc; + + try + { + sc = new ServiceController("slsvc"); + + if (sc.Status == ServiceControllerStatus.Running) + return; + } + catch (InvalidOperationException ex) + { + throw new InvalidOperationException("Unable to access slsvc: " + ex.Message); + } + + Logger.WriteLine("Starting slsvc..."); + + bool started = false; + + for (int i = 0; started == false && i < 360; i++) + { + try + { + if (sc.Status != ServiceControllerStatus.StartPending) + sc.Start(); + + sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMilliseconds(500)); + } + catch (System.ServiceProcess.TimeoutException) + { + continue; + } + catch (InvalidOperationException) + { + System.Threading.Thread.Sleep(500); + continue; + } + + started = true; + } + + if (!started) + throw new System.TimeoutException("Failed to start slsvc"); + + Logger.WriteLine("slsvc started successfully."); + } + + SLApi.RefreshLicenseStatus(); + } + + public static string GetPSPath(PSVersion version) + { + switch (version) + { + case PSVersion.Vista: + case PSVersion.Win7: + return Directory.GetFiles( + Environment.GetFolderPath(Environment.SpecialFolder.System), + "7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0") + .FirstOrDefault() ?? ""; + default: + return Path.Combine( + Environment.ExpandEnvironmentVariables( + (string)Registry.GetValue( + @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", + "TokenStore", + string.Empty + ) + ), + "data.dat" + ); + } + } + + public static string GetTokensPath(PSVersion version) + { + switch (version) + { + case PSVersion.Vista: + return Path.Combine( + Environment.ExpandEnvironmentVariables("%WINDIR%"), + @"ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareLicensing\tokens.dat" + ); + case PSVersion.Win7: + return Path.Combine( + Environment.ExpandEnvironmentVariables("%WINDIR%"), + @"ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat" + ); + default: + return Path.Combine( + Environment.ExpandEnvironmentVariables( + (string)Registry.GetValue( + @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", + "TokenStore", + string.Empty + ) + ), + "tokens.dat" + ); + } + } + + public static IPhysicalStore GetStore(PSVersion version, bool production) + { + string psPath; + + try + { + psPath = GetPSPath(version); + } + catch + { + throw new FileNotFoundException("Failed to get path of physical store."); + } + + if (string.IsNullOrEmpty(psPath) || !File.Exists(psPath)) + { + throw new FileNotFoundException(string.Format("Physical store not found at expected path {0}.", psPath)); + } + + switch (version) + { + case PSVersion.Vista: + return new PhysicalStoreVista(psPath, production); + case PSVersion.Win7: + return new PhysicalStoreWin7(psPath, production); + default: + return new PhysicalStoreModern(psPath, production, version); + } + } + + public static ITokenStore GetTokenStore(PSVersion version) + { + string tokPath; + + try + { + tokPath = GetTokensPath(version); + } + catch + { + throw new FileNotFoundException("Failed to get path of physical store."); + } + + if (string.IsNullOrEmpty(tokPath) || !File.Exists(tokPath)) + { + throw new FileNotFoundException(string.Format("Token store not found at expected path {0}.", tokPath)); + } + + return new TokenStoreModern(tokPath); + } + + public static void DumpStore(PSVersion version, bool production, string filePath, string encrFilePath) + { + if (encrFilePath == null) + { + encrFilePath = GetPSPath(version); + } + + if (string.IsNullOrEmpty(encrFilePath) || !File.Exists(encrFilePath)) + { + throw new FileNotFoundException("Store does not exist at expected path '" + encrFilePath + "'."); + } + + KillSPP(version); + + using (FileStream fs = File.Open(encrFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) + { + byte[] encrData = fs.ReadAllBytes(); + File.WriteAllBytes(filePath, PhysStoreCrypto.DecryptPhysicalStore(encrData, production, version)); + } + + Logger.WriteLine("Store dumped successfully to '" + filePath + "'."); + } + + public static void LoadStore(PSVersion version, bool production, string filePath) + { + if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) + { + throw new FileNotFoundException("Store file '" + filePath + "' does not exist."); + } + + KillSPP(version); + + using (IPhysicalStore store = GetStore(version, production)) + { + store.WriteRaw(File.ReadAllBytes(filePath)); + } + + Logger.WriteLine("Loaded store file succesfully."); + } + } +} diff --git a/LibTSforge/SPP/SPSys.cs b/LibTSforge/SPP/SPSys.cs new file mode 100644 index 0000000..10b8d04 --- /dev/null +++ b/LibTSforge/SPP/SPSys.cs @@ -0,0 +1,47 @@ +namespace LibTSforge.SPP +{ + using Microsoft.Win32.SafeHandles; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Runtime.InteropServices; + using System.Text; + + public class SPSys + { + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + private static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile); + private static SafeFileHandle CreateFileSafe(string device) + { + return new SafeFileHandle(CreateFile(device, 0xC0000000, 0, IntPtr.Zero, 3, 0, IntPtr.Zero), true); + } + + [return: MarshalAs(UnmanagedType.Bool)] + [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern bool DeviceIoControl([In] SafeFileHandle hDevice, [In] uint dwIoControlCode, [In] IntPtr lpInBuffer, [In] int nInBufferSize, [Out] IntPtr lpOutBuffer, [In] int nOutBufferSize, out int lpBytesReturned, [In] IntPtr lpOverlapped); + + public static bool IsSpSysRunning() + { + SafeFileHandle file = CreateFileSafe(@"\\.\SpDevice"); + IntPtr buffer = Marshal.AllocHGlobal(1); + int bytesReturned = 0; + DeviceIoControl(file, 0x80006008, IntPtr.Zero, 0, buffer, 1, out bytesReturned, IntPtr.Zero); + bool running = Marshal.ReadByte(buffer) != 0; + Marshal.FreeHGlobal(buffer); + file.Close(); + return running; + } + + public static int ControlSpSys(bool start) + { + SafeFileHandle file = CreateFileSafe(@"\\.\SpDevice"); + IntPtr buffer = Marshal.AllocHGlobal(4); + int bytesReturned = 0; + DeviceIoControl(file, start ? 0x8000a000 : 0x8000a004, IntPtr.Zero, 0, buffer, 4, out bytesReturned, IntPtr.Zero); + int result = Marshal.ReadInt32(buffer); + Marshal.FreeHGlobal(buffer); + file.Close(); + return result; + } + } +} -- cgit v1.2.3 From f2ad15e5a25c9cc2cdf0d198927be0562f466156 Mon Sep 17 00:00:00 2001 From: WitherOrNot Date: Sun, 2 Mar 2025 19:02:36 -0500 Subject: fix vista kms4k, add reset support --- LibTSforge/Activators/KMS4K.cs | 17 ++++++++++++----- LibTSforge/Common.cs | 4 ++-- LibTSforge/Modifiers/KeyChangeLockDelete.cs | 3 +++ LibTSforge/Modifiers/RearmReset.cs | 13 +++++++++++-- LibTSforge/Modifiers/TamperedFlagsDelete.cs | 17 ++++++++++------- LibTSforge/SPP/SPPUtils.cs | 4 ++++ 6 files changed, 42 insertions(+), 16 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/Activators/KMS4K.cs b/LibTSforge/Activators/KMS4K.cs index 315e082..01b7395 100644 --- a/LibTSforge/Activators/KMS4K.cs +++ b/LibTSforge/Activators/KMS4K.cs @@ -1,6 +1,7 @@ namespace LibTSforge.Activators { using System; + using System.IO; using LibTSforge.PhysicalStore; using LibTSforge.SPP; @@ -62,12 +63,18 @@ namespace LibTSforge.Activators { VistaTimer vistaTimer = new VistaTimer(); vistaTimer.Time = time2; - vistaTimer.Expiry = expiry; + vistaTimer.Expiry = Constants.TimerMax; string vistaTimerName = string.Format("msft:sl/timer/VLExpiration/VOLUME/{0}/{1}", appId, actId); store.DeleteBlock(key, vistaTimerName); - store.DeleteBlock(key, "45E81E65-6944-422E-9C02-D83F7E5F5A58"); + store.DeleteBlock(key, actId.ToString()); + + BinaryWriter writer = new BinaryWriter(new MemoryStream()); + writer.Write(Constants.KMSv4Response.Length); + writer.Write(Constants.KMSv4Response); + writer.Write(Constants.UniversalHWIDBlock); + byte[] kmsData = writer.GetBytes(); store.AddBlocks(new PSBlock[] { @@ -84,8 +91,8 @@ namespace LibTSforge.Activators Type = BlockType.NAMED, Flags = 0, KeyAsStr = key, - ValueAsStr = "45E81E65-6944-422E-9C02-D83F7E5F5A58", - Data = new Guid().ToByteArray() + ValueAsStr = actId.ToString(), + Data = kmsData } }); } @@ -191,7 +198,7 @@ namespace LibTSforge.Activators } } - SPPUtils.RestartSPP(version); + SPPUtils.RestartSPP(version); SLApi.FireStateChangedEvent(appId); Logger.WriteLine("Activated using KMS4k successfully."); } diff --git a/LibTSforge/Common.cs b/LibTSforge/Common.cs index 6973f6f..a1b4294 100644 --- a/LibTSforge/Common.cs +++ b/LibTSforge/Common.cs @@ -87,8 +87,8 @@ namespace LibTSforge 0x92, 0xA6, 0x56, 0x96 }; - // 2^31 - 1 minutes - public static ulong TimerMax = (ulong)TimeSpan.FromMinutes(2147483647).Ticks; + // 2^31 - 8 minutes + public static ulong TimerMax = (ulong)TimeSpan.FromMinutes(2147483640).Ticks; public static readonly string ZeroCID = new string('0', 48); } diff --git a/LibTSforge/Modifiers/KeyChangeLockDelete.cs b/LibTSforge/Modifiers/KeyChangeLockDelete.cs index 5150a41..3883d3c 100644 --- a/LibTSforge/Modifiers/KeyChangeLockDelete.cs +++ b/LibTSforge/Modifiers/KeyChangeLockDelete.cs @@ -5,11 +5,14 @@ namespace LibTSforge.Modifiers using LibTSforge.PhysicalStore; using LibTSforge.SPP; using LibTSforge; + using System; public static class KeyChangeLockDelete { public static void Delete(PSVersion version, bool production) { + if (version == PSVersion.Vista) throw new NotSupportedException("This feature is not supported on Windows Vista/Server 2008."); + SPPUtils.KillSPP(version); Logger.WriteLine("Writing TrustedStore data..."); using (IPhysicalStore store = SPPUtils.GetStore(version, production)) diff --git a/LibTSforge/Modifiers/RearmReset.cs b/LibTSforge/Modifiers/RearmReset.cs index a17c005..4b611b6 100644 --- a/LibTSforge/Modifiers/RearmReset.cs +++ b/LibTSforge/Modifiers/RearmReset.cs @@ -2,6 +2,7 @@ namespace LibTSforge.Modifiers { using System; using System.Collections.Generic; + using System.Data; using System.Linq; using LibTSforge.PhysicalStore; using LibTSforge.SPP; @@ -18,7 +19,11 @@ namespace LibTSforge.Modifiers { List blocks; - if (version == PSVersion.Win7) + if (version == PSVersion.Vista) + { + blocks = store.FindBlocks("740D70D8-6448-4b2f-9063-4A7A463600C5").ToList(); + } + else if (version == PSVersion.Win7) { blocks = store.FindBlocks(0xA0000).ToList(); } @@ -29,7 +34,11 @@ namespace LibTSforge.Modifiers foreach (PSBlock block in blocks) { - if (version == PSVersion.Win7) + if (version == PSVersion.Vista) + { + store.DeleteBlock(block.KeyAsStr, block.ValueAsStr); + } + else if (version == PSVersion.Win7) { store.SetBlock(block.KeyAsStr, block.ValueAsInt, new byte[8]); } diff --git a/LibTSforge/Modifiers/TamperedFlagsDelete.cs b/LibTSforge/Modifiers/TamperedFlagsDelete.cs index 55ba1ec..ecd9267 100644 --- a/LibTSforge/Modifiers/TamperedFlagsDelete.cs +++ b/LibTSforge/Modifiers/TamperedFlagsDelete.cs @@ -15,21 +15,24 @@ namespace LibTSforge.Modifiers using (IPhysicalStore store = SPPUtils.GetStore(version, production)) { - if (version != PSVersion.Win7) + if (version == PSVersion.Vista) { - string recreatedFlag = "__##USERSEP-RESERVED##__$$RECREATED-FLAG$$"; - string recoveredFlag = "__##USERSEP-RESERVED##__$$RECOVERED-FLAG$$"; - - DeleteFlag(store, recreatedFlag); - DeleteFlag(store, recoveredFlag); + DeleteFlag(store, "6BE8425B-E3CF-4e86-A6AF-5863E3DCB606"); } - else + else if (version == PSVersion.Win7) { SetFlag(store, 0xA0001); } + else + { + DeleteFlag(store, "__##USERSEP-RESERVED##__$$RECREATED-FLAG$$"); + DeleteFlag(store, "__##USERSEP-RESERVED##__$$RECOVERED-FLAG$$"); + } Logger.WriteLine("Successfully cleared the tamper state."); } + + SPPUtils.RestartSPP(version); } private static void DeleteFlag(IPhysicalStore store, string flag) diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index f1aa32f..08dbe03 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -252,6 +252,8 @@ namespace LibTSforge.SPP File.WriteAllBytes(filePath, PhysStoreCrypto.DecryptPhysicalStore(encrData, production, version)); } + RestartSPP(version); + Logger.WriteLine("Store dumped successfully to '" + filePath + "'."); } @@ -269,6 +271,8 @@ namespace LibTSforge.SPP store.WriteRaw(File.ReadAllBytes(filePath)); } + RestartSPP(version); + Logger.WriteLine("Loaded store file succesfully."); } } -- cgit v1.2.3 From 1cf9823ad3defaf063f7306540e5f1bcbf9acbe7 Mon Sep 17 00:00:00 2001 From: WitherOrNot Date: Sun, 2 Mar 2025 20:04:15 -0500 Subject: remove debug prints, partially fix compatibility with vista rtm --- LibTSforge/Activators/ZeroCID.cs | 6 ------ LibTSforge/SPP/SLAPI.cs | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/Activators/ZeroCID.cs b/LibTSforge/Activators/ZeroCID.cs index 6264f1d..255eea2 100644 --- a/LibTSforge/Activators/ZeroCID.cs +++ b/LibTSforge/Activators/ZeroCID.cs @@ -116,13 +116,7 @@ namespace LibTSforge.Activators throw new FormatException("Key Unique ID has invalid format."); } - Console.WriteLine(group); - Console.WriteLine(shortauth); - shortauth |= (ulong)group << 41; - - Console.WriteLine(shortauth); - pkeyData = BitConverter.GetBytes(shortauth); } else if (version == PSVersion.Win7) diff --git a/LibTSforge/SPP/SLAPI.cs b/LibTSforge/SPP/SLAPI.cs index 336d88f..c25fb03 100644 --- a/LibTSforge/SPP/SLAPI.cs +++ b/LibTSforge/SPP/SLAPI.cs @@ -165,7 +165,7 @@ namespace LibTSforge.SPP uint count; IntPtr pProductKeyIds; - status = SLGetInstalledProductKeyIds(sl.Handle, ref actId, out count, out pProductKeyIds); + status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_PKEY, out count, out pProductKeyIds); if (status != 0 || count == 0) { -- cgit v1.2.3 From 07f43e261381c8b9229fcf376e310d8f02ccb16d Mon Sep 17 00:00:00 2001 From: Lyssa Date: Wed, 2 Apr 2025 13:53:00 +0400 Subject: move detectcurrentkey to common --- LibTSforge/Common.cs | 18 ------------------ LibTSforge/SPP/SPPUtils.cs | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 20 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/Common.cs b/LibTSforge/Common.cs index a1b4294..4a95a08 100644 --- a/LibTSforge/Common.cs +++ b/LibTSforge/Common.cs @@ -243,24 +243,6 @@ namespace LibTSforge throw new NotSupportedException("Unable to auto-detect version info"); } - - public static bool DetectCurrentKey() - { - SLApi.RefreshLicenseStatus(); - - using (RegistryKey wpaKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\WPA")) - { - foreach (string subKey in wpaKey.GetSubKeyNames()) - { - if (subKey.StartsWith("8DEC0AF1")) - { - return subKey.Contains("P"); - } - } - } - - throw new FileNotFoundException("Failed to autodetect key type, specify physical store key with /prod or /test arguments."); - } } public static class Logger diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index 08dbe03..1046439 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -5,11 +5,9 @@ namespace LibTSforge.SPP using LibTSforge.TokenStore; using Microsoft.Win32; using System; - using System.Collections.Generic; using System.IO; using System.Linq; using System.ServiceProcess; - using System.Text; public static class SPPUtils { @@ -130,6 +128,24 @@ namespace LibTSforge.SPP SLApi.RefreshLicenseStatus(); } + public static bool DetectCurrentKey() + { + SLApi.RefreshLicenseStatus(); + + using (RegistryKey wpaKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\WPA")) + { + foreach (string subKey in wpaKey.GetSubKeyNames()) + { + if (subKey.StartsWith("8DEC0AF1")) + { + return subKey.Contains("P"); + } + } + } + + throw new FileNotFoundException("Failed to autodetect key type, specify physical store key with /prod or /test arguments."); + } + public static string GetPSPath(PSVersion version) { switch (version) -- cgit v1.2.3 From b8558d8fb2de25a97572ec9d3e33618b8fac3027 Mon Sep 17 00:00:00 2001 From: Lyssa Date: Wed, 2 Apr 2025 14:06:52 +0400 Subject: basic cleanup --- LibTSforge/Activators/KMS4K.cs | 8 ++++--- LibTSforge/Common.cs | 6 ----- LibTSforge/Crypto/PhysStoreCrypto.cs | 2 -- LibTSforge/Modifiers/GracePeriodReset.cs | 1 - LibTSforge/Modifiers/RearmReset.cs | 2 -- LibTSforge/Modifiers/TamperedFlagsDelete.cs | 1 - LibTSforge/PhysicalStore/VariableBag.cs | 3 +-- LibTSforge/SPP/PKeyConfig.cs | 36 ++++++++++++++++------------- LibTSforge/SPP/SPSys.cs | 7 ++---- LibTSforge/TokenStore/TokenStoreModern.cs | 5 ++-- 10 files changed, 30 insertions(+), 41 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/Activators/KMS4K.cs b/LibTSforge/Activators/KMS4K.cs index 01b7395..a68e263 100644 --- a/LibTSforge/Activators/KMS4K.cs +++ b/LibTSforge/Activators/KMS4K.cs @@ -61,9 +61,11 @@ namespace LibTSforge.Activators if (version == PSVersion.Vista) { - VistaTimer vistaTimer = new VistaTimer(); - vistaTimer.Time = time2; - vistaTimer.Expiry = Constants.TimerMax; + VistaTimer vistaTimer = new VistaTimer + { + Time = time2, + Expiry = Constants.TimerMax + }; string vistaTimerName = string.Format("msft:sl/timer/VLExpiration/VOLUME/{0}/{1}", appId, actId); diff --git a/LibTSforge/Common.cs b/LibTSforge/Common.cs index 4a95a08..75e31e4 100644 --- a/LibTSforge/Common.cs +++ b/LibTSforge/Common.cs @@ -1,16 +1,10 @@ namespace LibTSforge { - using Microsoft.Win32; using System; using System.IO; using System.Linq; using System.Runtime.InteropServices; - using System.ServiceProcess; using System.Text; - using LibTSforge.Crypto; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; - using LibTSforge.TokenStore; public enum PSVersion { diff --git a/LibTSforge/Crypto/PhysStoreCrypto.cs b/LibTSforge/Crypto/PhysStoreCrypto.cs index c0491db..b0acc2e 100644 --- a/LibTSforge/Crypto/PhysStoreCrypto.cs +++ b/LibTSforge/Crypto/PhysStoreCrypto.cs @@ -2,10 +2,8 @@ namespace LibTSforge.Crypto { using System; using System.Collections.Generic; - using System.Diagnostics; using System.IO; using System.Linq; - using System.Security.Cryptography; using System.Text; public static class PhysStoreCrypto diff --git a/LibTSforge/Modifiers/GracePeriodReset.cs b/LibTSforge/Modifiers/GracePeriodReset.cs index ddca3f7..059b1c5 100644 --- a/LibTSforge/Modifiers/GracePeriodReset.cs +++ b/LibTSforge/Modifiers/GracePeriodReset.cs @@ -1,6 +1,5 @@ namespace LibTSforge.Modifiers { - using System; using System.Collections.Generic; using System.Linq; using LibTSforge.PhysicalStore; diff --git a/LibTSforge/Modifiers/RearmReset.cs b/LibTSforge/Modifiers/RearmReset.cs index 4b611b6..89a12f3 100644 --- a/LibTSforge/Modifiers/RearmReset.cs +++ b/LibTSforge/Modifiers/RearmReset.cs @@ -1,8 +1,6 @@ namespace LibTSforge.Modifiers { - using System; using System.Collections.Generic; - using System.Data; using System.Linq; using LibTSforge.PhysicalStore; using LibTSforge.SPP; diff --git a/LibTSforge/Modifiers/TamperedFlagsDelete.cs b/LibTSforge/Modifiers/TamperedFlagsDelete.cs index ecd9267..8369d4e 100644 --- a/LibTSforge/Modifiers/TamperedFlagsDelete.cs +++ b/LibTSforge/Modifiers/TamperedFlagsDelete.cs @@ -1,6 +1,5 @@ namespace LibTSforge.Modifiers { - using System; using System.Linq; using LibTSforge.PhysicalStore; using LibTSforge.SPP; diff --git a/LibTSforge/PhysicalStore/VariableBag.cs b/LibTSforge/PhysicalStore/VariableBag.cs index 76098a9..ebe413f 100644 --- a/LibTSforge/PhysicalStore/VariableBag.cs +++ b/LibTSforge/PhysicalStore/VariableBag.cs @@ -3,7 +3,6 @@ namespace LibTSforge.PhysicalStore using System; using System.Collections.Generic; using System.IO; - using System.Runtime.CompilerServices; public enum CRCBlockType : uint { @@ -155,7 +154,7 @@ namespace LibTSforge.PhysicalStore public class VariableBag { public List Blocks = new List(); - private PSVersion Version; + private readonly PSVersion Version; public void Deserialize(byte[] data) { diff --git a/LibTSforge/SPP/PKeyConfig.cs b/LibTSforge/SPP/PKeyConfig.cs index a608608..6733940 100644 --- a/LibTSforge/SPP/PKeyConfig.cs +++ b/LibTSforge/SPP/PKeyConfig.cs @@ -75,7 +75,7 @@ namespace LibTSforge.SPP public class PKeyConfig { public Dictionary Products = new Dictionary(); - private List loadedPkeyConfigs = new List(); + private readonly List loadedPkeyConfigs = new List(); public void LoadConfig(Guid actId) { @@ -136,12 +136,14 @@ namespace LibTSforge.SPP ranges[refActIdStr] = new List(); } - KeyRange keyRange = new KeyRange(); - keyRange.Start = int.Parse(rangeNode.SelectSingleNode("./p:Start", nsmgr).InnerText); - keyRange.End = int.Parse(rangeNode.SelectSingleNode("./p:End", nsmgr).InnerText); - keyRange.EulaType = rangeNode.SelectSingleNode("./p:EulaType", nsmgr).InnerText; - keyRange.PartNumber = rangeNode.SelectSingleNode("./p:PartNumber", nsmgr).InnerText; - keyRange.Valid = rangeNode.SelectSingleNode("./p:IsValid", nsmgr).InnerText.ToLower() == "true"; + KeyRange keyRange = new KeyRange + { + Start = int.Parse(rangeNode.SelectSingleNode("./p:Start", nsmgr).InnerText), + End = int.Parse(rangeNode.SelectSingleNode("./p:End", nsmgr).InnerText), + EulaType = rangeNode.SelectSingleNode("./p:EulaType", nsmgr).InnerText, + PartNumber = rangeNode.SelectSingleNode("./p:PartNumber", nsmgr).InnerText, + Valid = rangeNode.SelectSingleNode("./p:IsValid", nsmgr).InnerText.ToLower() == "true" + }; ranges[refActIdStr].Add(keyRange); } @@ -155,15 +157,17 @@ namespace LibTSforge.SPP if (keyRanges.Count > 0 && !Products.ContainsKey(refActId)) { - ProductConfig productConfig = new ProductConfig(); - productConfig.GroupId = group; - productConfig.Edition = configNode.SelectSingleNode("./p:EditionId", nsmgr).InnerText; - productConfig.Description = configNode.SelectSingleNode("./p:ProductDescription", nsmgr).InnerText; - productConfig.Channel = configNode.SelectSingleNode("./p:ProductKeyType", nsmgr).InnerText; - productConfig.Randomized = configNode.SelectSingleNode("./p:ProductKeyType", nsmgr).InnerText.ToLower() == "true"; - productConfig.Algorithm = algorithms[group]; - productConfig.Ranges = keyRanges; - productConfig.ActivationId = refActId; + ProductConfig productConfig = new ProductConfig + { + GroupId = group, + Edition = configNode.SelectSingleNode("./p:EditionId", nsmgr).InnerText, + Description = configNode.SelectSingleNode("./p:ProductDescription", nsmgr).InnerText, + Channel = configNode.SelectSingleNode("./p:ProductKeyType", nsmgr).InnerText, + Randomized = configNode.SelectSingleNode("./p:ProductKeyType", nsmgr).InnerText.ToLower() == "true", + Algorithm = algorithms[group], + Ranges = keyRanges, + ActivationId = refActId + }; Products[refActId] = productConfig; } diff --git a/LibTSforge/SPP/SPSys.cs b/LibTSforge/SPP/SPSys.cs index 10b8d04..18b3655 100644 --- a/LibTSforge/SPP/SPSys.cs +++ b/LibTSforge/SPP/SPSys.cs @@ -2,10 +2,7 @@ namespace LibTSforge.SPP { using Microsoft.Win32.SafeHandles; using System; - using System.Collections.Generic; - using System.Linq; using System.Runtime.InteropServices; - using System.Text; public class SPSys { @@ -24,7 +21,7 @@ namespace LibTSforge.SPP { SafeFileHandle file = CreateFileSafe(@"\\.\SpDevice"); IntPtr buffer = Marshal.AllocHGlobal(1); - int bytesReturned = 0; + int bytesReturned; DeviceIoControl(file, 0x80006008, IntPtr.Zero, 0, buffer, 1, out bytesReturned, IntPtr.Zero); bool running = Marshal.ReadByte(buffer) != 0; Marshal.FreeHGlobal(buffer); @@ -36,7 +33,7 @@ namespace LibTSforge.SPP { SafeFileHandle file = CreateFileSafe(@"\\.\SpDevice"); IntPtr buffer = Marshal.AllocHGlobal(4); - int bytesReturned = 0; + int bytesReturned; DeviceIoControl(file, start ? 0x8000a000 : 0x8000a004, IntPtr.Zero, 0, buffer, 4, out bytesReturned, IntPtr.Zero); int result = Marshal.ReadInt32(buffer); Marshal.FreeHGlobal(buffer); diff --git a/LibTSforge/TokenStore/TokenStoreModern.cs b/LibTSforge/TokenStore/TokenStoreModern.cs index c3483ff..cfb35d0 100644 --- a/LibTSforge/TokenStore/TokenStoreModern.cs +++ b/LibTSforge/TokenStore/TokenStoreModern.cs @@ -25,17 +25,16 @@ namespace LibTSforge.TokenStore if (TokensFile.Length < BLOCK_SIZE) return; TokensFile.Seek(0x24, SeekOrigin.Begin); - uint nextBlock = 0; + uint nextBlock; BinaryReader reader = new BinaryReader(TokensFile); do { - uint curOffset = reader.ReadUInt32(); nextBlock = reader.ReadUInt32(); for (int i = 0; i < ENTRIES_PER_BLOCK; i++) { - curOffset = reader.ReadUInt32(); + uint curOffset = reader.ReadUInt32(); bool populated = reader.ReadUInt32() == 1; uint contentOffset = reader.ReadUInt32(); uint contentLength = reader.ReadUInt32(); -- cgit v1.2.3 From 1286b585015b085672afbadcc1408584bab94df2 Mon Sep 17 00:00:00 2001 From: Lyssa Date: Wed, 2 Apr 2025 18:23:16 +0400 Subject: fix dumping vista store (really hacky fix) --- LibTSforge/SPP/SPPUtils.cs | 33 ++++++++++++++++++++---------- TSforgeCLI/Properties/launchSettings.json | 8 ++++++++ vista.dat | Bin 0 -> 21788 bytes 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 TSforgeCLI/Properties/launchSettings.json create mode 100644 vista.dat (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index 1046439..1a6ef62 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -46,8 +46,9 @@ namespace LibTSforge.SPP { continue; } - catch (InvalidOperationException) + catch (InvalidOperationException ex) { + Logger.WriteLine("Warning: Stopping sppsvc failed, retrying. Details:" + ex.Message); System.Threading.Thread.Sleep(500); continue; } @@ -110,8 +111,9 @@ namespace LibTSforge.SPP { continue; } - catch (InvalidOperationException) + catch (InvalidOperationException ex) { + Logger.WriteLine("Warning: Starting slsvc failed, retrying. Details:" + ex.Message); System.Threading.Thread.Sleep(500); continue; } @@ -250,9 +252,13 @@ namespace LibTSforge.SPP public static void DumpStore(PSVersion version, bool production, string filePath, string encrFilePath) { + bool manageSpp = false; + if (encrFilePath == null) { encrFilePath = GetPSPath(version); + manageSpp = true; + KillSPP(version); } if (string.IsNullOrEmpty(encrFilePath) || !File.Exists(encrFilePath)) @@ -260,17 +266,22 @@ namespace LibTSforge.SPP throw new FileNotFoundException("Store does not exist at expected path '" + encrFilePath + "'."); } - KillSPP(version); - - using (FileStream fs = File.Open(encrFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) + try + { + using (FileStream fs = File.Open(encrFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + byte[] encrData = fs.ReadAllBytes(); + File.WriteAllBytes(filePath, PhysStoreCrypto.DecryptPhysicalStore(encrData, production, version)); + } + Logger.WriteLine("Store dumped successfully to '" + filePath + "'."); + } + finally { - byte[] encrData = fs.ReadAllBytes(); - File.WriteAllBytes(filePath, PhysStoreCrypto.DecryptPhysicalStore(encrData, production, version)); + if (manageSpp) + { + RestartSPP(version); + } } - - RestartSPP(version); - - Logger.WriteLine("Store dumped successfully to '" + filePath + "'."); } public static void LoadStore(PSVersion version, bool production, string filePath) diff --git a/TSforgeCLI/Properties/launchSettings.json b/TSforgeCLI/Properties/launchSettings.json new file mode 100644 index 0000000..112530f --- /dev/null +++ b/TSforgeCLI/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "TSforgeCLI": { + "commandName": "Project", + "commandLineArgs": "/dump vista.dat blah.dat /ver vista" + } + } +} \ No newline at end of file diff --git a/vista.dat b/vista.dat new file mode 100644 index 0000000..97ff497 Binary files /dev/null and b/vista.dat differ -- cgit v1.2.3 From 17a7c90245ccd45b6e32d8bbe01a1a3eddeeae4d Mon Sep 17 00:00:00 2001 From: Wither OrNot Date: Thu, 3 Apr 2025 18:22:33 -0400 Subject: miscellaneous fixes --- LibTSforge/Activators/AVMA4K.cs | 2 +- LibTSforge/Common.cs | 9 ++++++--- LibTSforge/SPP/SPPUtils.cs | 4 ++-- LibTSforge/TokenStore/TokenStoreModern.cs | 1 + TSforgeCLI/Program.cs | 2 ++ 5 files changed, 12 insertions(+), 6 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/Activators/AVMA4K.cs b/LibTSforge/Activators/AVMA4K.cs index ec09daf..2127652 100644 --- a/LibTSforge/Activators/AVMA4K.cs +++ b/LibTSforge/Activators/AVMA4K.cs @@ -8,7 +8,7 @@ namespace LibTSforge.Activators { public static void Activate(PSVersion version, bool production, Guid actId) { - if (version != PSVersion.WinModern) + if (version != PSVersion.WinModern && version != PSVersion.WinBlue) { throw new NotSupportedException("AVMA licenses are not available for this product."); } diff --git a/LibTSforge/Common.cs b/LibTSforge/Common.cs index b9c274a..4d61770 100644 --- a/LibTSforge/Common.cs +++ b/LibTSforge/Common.cs @@ -183,6 +183,12 @@ namespace LibTSforge public static class Utils { + [DllImport("kernel32.dll")] + public static extern uint GetSystemDefaultLCID(); + + [DllImport("kernel32.dll")] + public static extern bool Wow64EnableWow64FsRedirection(bool Wow64FsEnableRedirection); + public static string DecodeString(byte[] data) { return Encoding.Unicode.GetString(data).Trim('\0'); @@ -193,9 +199,6 @@ namespace LibTSforge return Encoding.Unicode.GetBytes(str + '\0'); } - [DllImport("kernel32.dll")] - public static extern uint GetSystemDefaultLCID(); - public static uint CRC32(byte[] data) { const uint polynomial = 0x04C11DB7; diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index 1a6ef62..5621305 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -33,7 +33,7 @@ namespace LibTSforge.SPP bool stopped = false; - for (int i = 0; stopped == false && i < 360; i++) + for (int i = 0; stopped == false && i < 1080; i++) { try { @@ -48,7 +48,7 @@ namespace LibTSforge.SPP } catch (InvalidOperationException ex) { - Logger.WriteLine("Warning: Stopping sppsvc failed, retrying. Details:" + ex.Message); + Logger.WriteLine("Warning: Stopping sppsvc failed, retrying. Details: " + ex.Message); System.Threading.Thread.Sleep(500); continue; } diff --git a/LibTSforge/TokenStore/TokenStoreModern.cs b/LibTSforge/TokenStore/TokenStoreModern.cs index cfb35d0..ee51e7a 100644 --- a/LibTSforge/TokenStore/TokenStoreModern.cs +++ b/LibTSforge/TokenStore/TokenStoreModern.cs @@ -30,6 +30,7 @@ namespace LibTSforge.TokenStore BinaryReader reader = new BinaryReader(TokensFile); do { + reader.ReadUInt32(); nextBlock = reader.ReadUInt32(); for (int i = 0; i < ENTRIES_PER_BLOCK; i++) diff --git a/TSforgeCLI/Program.cs b/TSforgeCLI/Program.cs index 865e51d..86945d5 100644 --- a/TSforgeCLI/Program.cs +++ b/TSforgeCLI/Program.cs @@ -35,6 +35,8 @@ namespace TSforgeCLI { Logger.WriteLine("TSforge (c) MASSGRAVE 2025"); + Utils.Wow64EnableWow64FsRedirection(false); + try { if (args.Length == 0) -- cgit v1.2.3 From 736c722880ef33cc2072f5ff28e6d051fed0c782 Mon Sep 17 00:00:00 2001 From: Wither OrNot Date: Thu, 3 Apr 2025 20:51:33 -0400 Subject: attempt at arm fix --- LibTSforge/SPP/SPPUtils.cs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index 5621305..21db680 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -161,14 +161,15 @@ namespace LibTSforge.SPP default: return Path.Combine( Environment.ExpandEnvironmentVariables( - (string)Registry.GetValue( - @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", + (string)RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Environment.MachineName) + .OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform") + .GetValue( "TokenStore", string.Empty - ) - ), - "data.dat" - ); + ) + ), + "data.dat" + ); } } @@ -189,14 +190,15 @@ namespace LibTSforge.SPP default: return Path.Combine( Environment.ExpandEnvironmentVariables( - (string)Registry.GetValue( - @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", + (string)RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Environment.MachineName) + .OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform") + .GetValue( "TokenStore", string.Empty - ) - ), - "tokens.dat" - ); + ) + ), + "tokens.dat" + ); } } @@ -204,14 +206,11 @@ namespace LibTSforge.SPP { string psPath; - try + { psPath = GetPSPath(version); } - catch - { - throw new FileNotFoundException("Failed to get path of physical store."); - } + if (string.IsNullOrEmpty(psPath) || !File.Exists(psPath)) { -- cgit v1.2.3 From aa0801c643729177454fc329f092456afb86f3ab Mon Sep 17 00:00:00 2001 From: Wither OrNot Date: Thu, 3 Apr 2025 21:02:50 -0400 Subject: fix error handling --- LibTSforge/SPP/SPPUtils.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index 21db680..a0b3a77 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -206,12 +206,15 @@ namespace LibTSforge.SPP { string psPath; - + try { psPath = GetPSPath(version); + } + catch + { + throw new FileNotFoundException("Failed to get path of physical store."); } - if (string.IsNullOrEmpty(psPath) || !File.Exists(psPath)) { throw new FileNotFoundException(string.Format("Physical store not found at expected path {0}.", psPath)); @@ -238,7 +241,7 @@ namespace LibTSforge.SPP } catch { - throw new FileNotFoundException("Failed to get path of physical store."); + throw new FileNotFoundException("Failed to get path of token store."); } if (string.IsNullOrEmpty(tokPath) || !File.Exists(tokPath)) -- cgit v1.2.3 From e86f43a2864585f8430e01849a04a51bc46c1908 Mon Sep 17 00:00:00 2001 From: Wither OrNot Date: Fri, 4 Apr 2025 00:21:07 -0400 Subject: hack fix for arm64 in absence of better solutions --- LibTSforge/SPP/ProductKey.cs | 9 ++++++++- LibTSforge/SPP/SPPUtils.cs | 16 +++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/SPP/ProductKey.cs b/LibTSforge/SPP/ProductKey.cs index b5fca9a..ce454d8 100644 --- a/LibTSforge/SPP/ProductKey.cs +++ b/LibTSforge/SPP/ProductKey.cs @@ -32,6 +32,11 @@ namespace LibTSforge.SPP get { return BitConverter.GetBytes(klow).Concat(BitConverter.GetBytes(khigh)).ToArray(); } } + public ProductKey() + { + + } + public ProductKey(int serial, ulong security, bool upgrade, PKeyAlgorithm algorithm, ProductConfig config, KeyRange range) { Group = config.GroupId; @@ -254,7 +259,9 @@ namespace LibTSforge.SPP int serialLow = Serial % 1000000; BinaryWriter writer = new BinaryWriter(new MemoryStream()); - writer.Write(new Guid("B8731595-A2F6-430B-A799-FBFFB81A8D73").ToByteArray()); + string algoId = Algorithm == PKeyAlgorithm.PKEY2005 ? "B8731595-A2F6-430B-A799-FBFFB81A8D73" : "660672EF-7809-4CFD-8D54-41B7FB738988"; + + writer.Write(new Guid(algoId).ToByteArray()); writer.Write(Group); writer.Write(serialHigh); writer.Write(serialLow); diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index a0b3a77..ad3840d 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -113,7 +113,7 @@ namespace LibTSforge.SPP } catch (InvalidOperationException ex) { - Logger.WriteLine("Warning: Starting slsvc failed, retrying. Details:" + ex.Message); + Logger.WriteLine("Warning: Starting slsvc failed, retrying. Details: " + ex.Message); System.Threading.Thread.Sleep(500); continue; } @@ -161,11 +161,10 @@ namespace LibTSforge.SPP default: return Path.Combine( Environment.ExpandEnvironmentVariables( - (string)RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Environment.MachineName) - .OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform") - .GetValue( + (string)Registry.GetValue( + @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", "TokenStore", - string.Empty + @"C:\Windows\System32\spp\store\2.0" ) ), "data.dat" @@ -190,11 +189,10 @@ namespace LibTSforge.SPP default: return Path.Combine( Environment.ExpandEnvironmentVariables( - (string)RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, Environment.MachineName) - .OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SoftwareProtectionPlatform") - .GetValue( + (string)Registry.GetValue( + @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", "TokenStore", - string.Empty + @"C:\Windows\System32\spp\store\2.0" ) ), "tokens.dat" -- cgit v1.2.3 From 28acb8012f3471262aa999071fbadde5ebe7edf9 Mon Sep 17 00:00:00 2001 From: Wither OrNot Date: Fri, 4 Apr 2025 03:43:27 -0400 Subject: add /siid option --- LibTSforge/Modifiers/SetIIDParams.cs | 69 ++++++++++++++++++++++++++++++++ LibTSforge/SPP/ProductKey.cs | 6 +-- TSforgeCLI/Program.cs | 76 ++++++++++++++++++++++++++++-------- 3 files changed, 130 insertions(+), 21 deletions(-) create mode 100644 LibTSforge/Modifiers/SetIIDParams.cs (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/Modifiers/SetIIDParams.cs b/LibTSforge/Modifiers/SetIIDParams.cs new file mode 100644 index 0000000..d7fa2c5 --- /dev/null +++ b/LibTSforge/Modifiers/SetIIDParams.cs @@ -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."); + } + } +} diff --git a/LibTSforge/SPP/ProductKey.cs b/LibTSforge/SPP/ProductKey.cs index ce454d8..ae48893 100644 --- a/LibTSforge/SPP/ProductKey.cs +++ b/LibTSforge/SPP/ProductKey.cs @@ -249,10 +249,8 @@ namespace LibTSforge.SPP { if (version == PSVersion.Win7) { - Random rnd = new Random(Group * 1000000000 + Serial); - byte[] data = new byte[8]; - rnd.NextBytes(data); - return data; + ulong shortauth = ((ulong)Group << 41) | ((ulong)Security << 31) | ((ulong)Serial << 1) | (Upgrade ? (ulong)1 : 0); + return BitConverter.GetBytes(shortauth); } int serialHigh = Serial / 1000000; diff --git a/TSforgeCLI/Program.cs b/TSforgeCLI/Program.cs index 86945d5..2c72265 100644 --- a/TSforgeCLI/Program.cs +++ b/TSforgeCLI/Program.cs @@ -25,10 +25,15 @@ namespace TSforgeCLI 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) @@ -103,6 +108,10 @@ namespace TSforgeCLI 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 { @@ -187,6 +196,38 @@ namespace TSforgeCLI 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 @@ -211,23 +252,24 @@ namespace TSforgeCLI string exeName = typeof(Program).Namespace; Logger.WriteLine("Usage: " + exeName + " [/dump ()] [/load ] [/kms4k] [/avma4k] [/zcid] [/rtmr] [/duid] [/igpk] [/kmsc] [/ctpr] [/revl] [/prod] [/test] [] [/ver ]"); Logger.WriteLine("Options:"); - Logger.WriteLine("\t/dump () Dump and decrypt the physical store to the specified path."); - Logger.WriteLine("\t/load 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/prod Use SPP production key."); - Logger.WriteLine("\t/test Use SPP test key."); - Logger.WriteLine("\t/ver Override the detected version. Available versions: vista, 7, 8, blue, modern."); - Logger.WriteLine("\t A specific activation ID. Useful if you want to activate specific addons like ESU."); - Logger.WriteLine("\t/? Display this help message."); + Logger.WriteLine("\t/dump () Dump and decrypt the physical store to the specified path."); + Logger.WriteLine("\t/load 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> 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 Override the detected version. Available versions: vista, 7, 8, blue, modern."); + Logger.WriteLine("\t 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) -- cgit v1.2.3 From 3a1b9c481df88e96515a89083034e17a90a26e86 Mon Sep 17 00:00:00 2001 From: Wither OrNot Date: Fri, 4 Apr 2025 05:24:33 -0400 Subject: slightly improve arm64 fix --- LibTSforge/SPP/SPPUtils.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index ad3840d..187d4f3 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -164,7 +164,10 @@ namespace LibTSforge.SPP (string)Registry.GetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", "TokenStore", - @"C:\Windows\System32\spp\store\2.0" + Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.System), + @"spp\store\2.0" + ) ) ), "data.dat" @@ -192,7 +195,10 @@ namespace LibTSforge.SPP (string)Registry.GetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", "TokenStore", - @"C:\Windows\System32\spp\store\2.0" + Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.System), + @"spp\store\2.0" + ) ) ), "tokens.dat" @@ -204,13 +210,13 @@ namespace LibTSforge.SPP { string psPath; - try + //try { psPath = GetPSPath(version); } - catch + //catch { - throw new FileNotFoundException("Failed to get path of physical store."); + //throw new FileNotFoundException("Failed to get path of physical store."); } if (string.IsNullOrEmpty(psPath) || !File.Exists(psPath)) -- cgit v1.2.3 From 233be2dd1446b1bfca18dff77bb25f57155ada15 Mon Sep 17 00:00:00 2001 From: Wither OrNot Date: Fri, 4 Apr 2025 11:01:48 -0400 Subject: . --- LibTSforge/SPP/SPPUtils.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index 187d4f3..8cf2643 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -210,13 +210,13 @@ namespace LibTSforge.SPP { string psPath; - //try + try { psPath = GetPSPath(version); } - //catch + catch { - //throw new FileNotFoundException("Failed to get path of physical store."); + throw new FileNotFoundException("Failed to get path of physical store."); } if (string.IsNullOrEmpty(psPath) || !File.Exists(psPath)) -- cgit v1.2.3 From 6d971c2f6df56bb6597c52700983871a81258f32 Mon Sep 17 00:00:00 2001 From: WitherOrNot Date: Fri, 4 Apr 2025 23:23:57 -0400 Subject: add fallback path search --- LibTSforge/SPP/SPPUtils.cs | 130 ++++++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 54 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index 8cf2643..a535bc7 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -159,19 +159,44 @@ namespace LibTSforge.SPP "7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0") .FirstOrDefault() ?? ""; default: - return Path.Combine( - Environment.ExpandEnvironmentVariables( - (string)Registry.GetValue( - @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", - "TokenStore", - Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.System), - @"spp\store\2.0" - ) - ) - ), - "data.dat" + string psDir = Environment.ExpandEnvironmentVariables( + (string)Registry.GetValue( + @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", + "TokenStore", + "" + ) ); + string psPath = Path.Combine(psDir, "data.dat"); + + if (string.IsNullOrEmpty(psDir) || !File.Exists(psPath)) + { + string[] psDirs = + { + @"spp\store", + @"spp\store\2.0", + @"spp\store_test", + @"spp\store_test\2.0" + }; + + foreach (string dir in psDirs) + { + psPath = Path.Combine( + Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.System), + dir + ), + "data.dat" + ); + + if (File.Exists(psPath)) return psPath; + } + } + else + { + return psPath; + } + + throw new FileNotFoundException("Failed to locate physical store."); } } @@ -190,39 +215,50 @@ namespace LibTSforge.SPP @"ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat" ); default: - return Path.Combine( - Environment.ExpandEnvironmentVariables( - (string)Registry.GetValue( - @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", - "TokenStore", - Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.System), - @"spp\store\2.0" - ) - ) - ), - "tokens.dat" + string tokDir = Environment.ExpandEnvironmentVariables( + (string)Registry.GetValue( + @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", + "TokenStore", + "" + ) ); + string tokPath = Path.Combine(tokDir, "tokens.dat"); + + if (string.IsNullOrEmpty(tokDir) || !File.Exists(tokPath)) + { + string[] tokDirs = + { + @"spp\store", + @"spp\store\2.0", + @"spp\store_test", + @"spp\store_test\2.0" + }; + + foreach (string dir in tokDirs) + { + tokPath = Path.Combine( + Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.System), + dir + ), + "tokens.dat" + ); + + if (File.Exists(tokPath)) return tokPath; + } + } + else + { + return tokPath; + } + + throw new FileNotFoundException("Failed to locate token store."); } } public static IPhysicalStore GetStore(PSVersion version, bool production) { - string psPath; - - try - { - psPath = GetPSPath(version); - } - catch - { - throw new FileNotFoundException("Failed to get path of physical store."); - } - - if (string.IsNullOrEmpty(psPath) || !File.Exists(psPath)) - { - throw new FileNotFoundException(string.Format("Physical store not found at expected path {0}.", psPath)); - } + string psPath = GetPSPath(version); switch (version) { @@ -237,21 +273,7 @@ namespace LibTSforge.SPP public static ITokenStore GetTokenStore(PSVersion version) { - string tokPath; - - try - { - tokPath = GetTokensPath(version); - } - catch - { - throw new FileNotFoundException("Failed to get path of token store."); - } - - if (string.IsNullOrEmpty(tokPath) || !File.Exists(tokPath)) - { - throw new FileNotFoundException(string.Format("Token store not found at expected path {0}.", tokPath)); - } + string tokPath = GetTokensPath(version); return new TokenStoreModern(tokPath); } -- cgit v1.2.3 From 0c8b1efaa9005de1d101ebab5e66117edfaec3b2 Mon Sep 17 00:00:00 2001 From: Lyssa Date: Mon, 7 Apr 2025 19:19:24 +0400 Subject: Minor fixups --- LibTSforge/Activators/AVMA4K.cs | 22 +++++------- LibTSforge/Activators/KMS4K.cs | 12 +++---- LibTSforge/Activators/ZeroCID.cs | 13 ++++--- LibTSforge/Crypto/PhysStoreCrypto.cs | 38 ++++++++++---------- LibTSforge/Modifiers/GenPKeyInstall.cs | 12 +++---- LibTSforge/Modifiers/GracePeriodReset.cs | 4 +-- LibTSforge/Modifiers/KMSHostCharge.cs | 12 +++---- LibTSforge/Modifiers/KeyChangeLockDelete.cs | 5 ++- LibTSforge/Modifiers/RearmReset.cs | 4 +-- LibTSforge/Modifiers/SetIIDParams.cs | 12 +++---- LibTSforge/Modifiers/TamperedFlagsDelete.cs | 6 ++-- LibTSforge/Modifiers/UniqueIdDelete.cs | 5 ++- LibTSforge/PhysicalStore/Common.cs | 4 +-- LibTSforge/PhysicalStore/PhysicalStoreModern.cs | 48 +++++++++++++------------ LibTSforge/PhysicalStore/PhysicalStoreVista.cs | 4 +-- LibTSforge/PhysicalStore/PhysicalStoreWin7.cs | 4 +-- LibTSforge/PhysicalStore/VariableBag.cs | 3 +- LibTSforge/SPP/PKeyConfig.cs | 7 +--- LibTSforge/SPP/ProductKey.cs | 26 +++++++------- LibTSforge/SPP/SLAPI.cs | 27 ++++++-------- LibTSforge/SPP/SPPUtils.cs | 10 +++--- LibTSforge/SPP/SPSys.cs | 2 +- LibTSforge/TokenStore/Common.cs | 4 +-- LibTSforge/TokenStore/TokenStoreModern.cs | 14 +++----- TSforgeCLI/Program.cs | 42 +++++++++++----------- 25 files changed, 157 insertions(+), 183 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/Activators/AVMA4K.cs b/LibTSforge/Activators/AVMA4K.cs index 2127652..51b546a 100644 --- a/LibTSforge/Activators/AVMA4K.cs +++ b/LibTSforge/Activators/AVMA4K.cs @@ -1,8 +1,8 @@ namespace LibTSforge.Activators { using System; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; + using PhysicalStore; + using SPP; public static class AVMA4k { @@ -42,24 +42,20 @@ namespace LibTSforge.Activators { string key = string.Format("SPPSVC\\{0}\\{1}", appId, actId); - ulong unknown = 0; - ulong time1; - ulong crcBindTime = (ulong)DateTime.UtcNow.ToFileTime(); - ulong timerTime; - - ulong expiry = Constants.TimerMax; - long creationTime = BitConverter.ToInt64(store.GetBlock("__##USERSEP##\\$$_RESERVED_$$\\NAMESPACE__", "__##USERSEP-RESERVED##__$$GLOBAL-CREATION-TIME$$").Data, 0); long tickCount = BitConverter.ToInt64(store.GetBlock("__##USERSEP##\\$$_RESERVED_$$\\NAMESPACE__", "__##USERSEP-RESERVED##__$$GLOBAL-TICKCOUNT-UPTIME$$").Data, 0); long deltaTime = BitConverter.ToInt64(store.GetBlock(key, "__##USERSEP-RESERVED##__$$UP-TIME-DELTA$$").Data, 0); - time1 = (ulong)(creationTime + tickCount + deltaTime); - timerTime = crcBindTime / 10000; + const ulong unknown = 0; + ulong time1 = (ulong)(creationTime + tickCount + deltaTime); + ulong crcBindTime = (ulong)DateTime.UtcNow.ToFileTime(); + ulong timerTime = crcBindTime / 10000; + ulong expiry = Constants.TimerMax; expiry /= 10000; VariableBag avmaBinding = new VariableBag(version); - avmaBinding.Blocks.AddRange(new CRCBlockModern[] + avmaBinding.Blocks.AddRange(new[] { new CRCBlockModern { @@ -97,7 +93,7 @@ namespace LibTSforge.Activators store.DeleteBlock(key, storeVal); store.DeleteBlock(key, timerVal); - store.AddBlocks(new PSBlock[] + store.AddBlocks(new[] { new PSBlock { diff --git a/LibTSforge/Activators/KMS4K.cs b/LibTSforge/Activators/KMS4K.cs index a68e263..6287c39 100644 --- a/LibTSforge/Activators/KMS4K.cs +++ b/LibTSforge/Activators/KMS4K.cs @@ -2,8 +2,8 @@ namespace LibTSforge.Activators { using System; using System.IO; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; + using PhysicalStore; + using SPP; public class KMS4k { @@ -78,7 +78,7 @@ namespace LibTSforge.Activators writer.Write(Constants.UniversalHWIDBlock); byte[] kmsData = writer.GetBytes(); - store.AddBlocks(new PSBlock[] + store.AddBlocks(new[] { new PSBlock { @@ -121,7 +121,7 @@ namespace LibTSforge.Activators VariableBag kmsBinding = new VariableBag(version); - kmsBinding.Blocks.AddRange(new CRCBlockModern[] + kmsBinding.Blocks.AddRange(new[] { new CRCBlockModern { @@ -145,7 +145,7 @@ namespace LibTSforge.Activators if (version == PSVersion.WinModern) { - kmsBinding.Blocks.AddRange(new CRCBlockModern[] + kmsBinding.Blocks.AddRange(new[] { new CRCBlockModern { @@ -178,7 +178,7 @@ namespace LibTSforge.Activators store.DeleteBlock(key, storeVal); store.DeleteBlock(key, timerVal); - store.AddBlocks(new PSBlock[] + store.AddBlocks(new[] { new PSBlock { diff --git a/LibTSforge/Activators/ZeroCID.cs b/LibTSforge/Activators/ZeroCID.cs index 1675173..147dceb 100644 --- a/LibTSforge/Activators/ZeroCID.cs +++ b/LibTSforge/Activators/ZeroCID.cs @@ -3,14 +3,13 @@ namespace LibTSforge.Activators using System; using System.IO; using System.Linq; - using System.Text.RegularExpressions; - using LibTSforge.Crypto; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; + using Crypto; + using PhysicalStore; + using SPP; public static class ZeroCID { - public static void Deposit(Guid actId, string instId) + private static void Deposit(Guid actId, string instId) { uint status = SLApi.DepositConfirmationID(actId, instId, Constants.ZeroCID); Logger.WriteLine(string.Format("Depositing fake CID status {0:X}", status)); @@ -98,7 +97,7 @@ namespace LibTSforge.Activators string uniqueId = Utils.DecodeString(pkeyData.Skip(0x120).Take(0x80).ToArray()); string extPid = Utils.DecodeString(pkeyData.Skip(0x1A0).Take(0x80).ToArray()); - uint group = 0; + uint group; uint.TryParse(extPid.Split('-')[1], out group); if (group == 0) @@ -154,7 +153,7 @@ namespace LibTSforge.Activators store.DeleteBlock(key, hwidBlockName); store.DeleteBlock(key, pkeyInfoName); - store.AddBlocks(new PSBlock[] { + store.AddBlocks(new[] { new PSBlock { Type = BlockType.NAMED, diff --git a/LibTSforge/Crypto/PhysStoreCrypto.cs b/LibTSforge/Crypto/PhysStoreCrypto.cs index b0acc2e..083841d 100644 --- a/LibTSforge/Crypto/PhysStoreCrypto.cs +++ b/LibTSforge/Crypto/PhysStoreCrypto.cs @@ -18,31 +18,31 @@ namespace LibTSforge.Crypto if (CryptoUtils.RSAVerifySignature(rsaKey, encAesKey, aesKeySig)) { - byte[] aesKey = CryptoUtils.RSADecrypt(rsaKey, encAesKey); - byte[] decData = CryptoUtils.AESDecrypt(br.ReadBytes((int)br.BaseStream.Length - 0x110), aesKey); - byte[] hmacKey = decData.Take(0x10).ToArray(); // SHA-1 salt on Vista - byte[] hmacSig = decData.Skip(0x10).Take(0x14).ToArray(); // SHA-1 hash on Vista - byte[] psData = decData.Skip(0x28).ToArray(); + throw new Exception("Failed to decrypt physical store."); + } + + byte[] aesKey = CryptoUtils.RSADecrypt(rsaKey, encAesKey); + byte[] decData = CryptoUtils.AESDecrypt(br.ReadBytes((int)br.BaseStream.Length - 0x110), aesKey); + byte[] hmacKey = decData.Take(0x10).ToArray(); // SHA-1 salt on Vista + byte[] hmacSig = decData.Skip(0x10).Take(0x14).ToArray(); // SHA-1 hash on Vista + byte[] psData = decData.Skip(0x28).ToArray(); - if (version != PSVersion.Vista) + if (version != PSVersion.Vista) + { + if (!CryptoUtils.HMACVerify(hmacKey, psData, hmacSig)) { - if (!CryptoUtils.HMACVerify(hmacKey, psData, hmacSig)) - { - throw new InvalidDataException("Failed to verify HMAC. Physical store is corrupt."); - } + throw new InvalidDataException("Failed to verify HMAC. Physical store is corrupt."); } - else + } + else + { + if (!CryptoUtils.SaltSHAVerify(hmacKey, psData, hmacSig)) { - if (!CryptoUtils.SaltSHAVerify(hmacKey, psData, hmacSig)) - { - throw new InvalidDataException("Failed to verify checksum. Physical store is corrupt."); - } + throw new InvalidDataException("Failed to verify checksum. Physical store is corrupt."); } - - return psData; } - throw new Exception("Failed to decrypt physical store."); + return psData; } public static byte[] EncryptPhysicalStore(byte[] data, bool production, PSVersion version) @@ -65,7 +65,7 @@ namespace LibTSforge.Crypto byte[] aesKeySig = CryptoUtils.RSASign(rsaKey, encAesKey); byte[] hmacSig = version != PSVersion.Vista ? CryptoUtils.HMACSign(hmacKey, data) : CryptoUtils.SaltSHASum(hmacKey, data); - byte[] decData = new byte[] { }; + byte[] decData = { }; decData = decData.Concat(hmacKey).Concat(hmacSig).Concat(BitConverter.GetBytes(0)).Concat(data).ToArray(); byte[] encData = CryptoUtils.AESEncrypt(decData, aesKey); diff --git a/LibTSforge/Modifiers/GenPKeyInstall.cs b/LibTSforge/Modifiers/GenPKeyInstall.cs index 2e4c23d..a747952 100644 --- a/LibTSforge/Modifiers/GenPKeyInstall.cs +++ b/LibTSforge/Modifiers/GenPKeyInstall.cs @@ -3,9 +3,9 @@ namespace LibTSforge.Modifiers using System; using System.IO; using Microsoft.Win32; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; - using LibTSforge.TokenStore; + using PhysicalStore; + using SPP; + using TokenStore; public static class GenPKeyInstall { @@ -58,7 +58,7 @@ namespace LibTSforge.Modifiers if (pkey.Algorithm == PKeyAlgorithm.PKEY2009) { uint status = SLApi.InstallProductKey(pkey); - Logger.WriteLine(string.Format("Installing generated product key {0} status {1:X}", pkey.ToString(), status)); + Logger.WriteLine(string.Format("Installing generated product key {0} status {1:X}", pkey, status)); if ((int)status < 0) { @@ -74,7 +74,7 @@ namespace LibTSforge.Modifiers if (pkey.Channel == "Volume:GVLK" && version == PSVersion.Win7) throw new NotSupportedException("Fake GVLK generation is not supported on Windows 7."); VariableBag pkb = new VariableBag(version); - pkb.Blocks.AddRange(new CRCBlockModern[] + pkb.Blocks.AddRange(new[] { new CRCBlockModern { @@ -169,7 +169,7 @@ namespace LibTSforge.Modifiers uriMap.Data[pkeyId] = pkey.GetAlgoUri(); tks.SetEntry(uriMapName, "xml", uriMap.Serialize()); - string skuMetaName = actId.ToString() + metSuffix; + string skuMetaName = actId + metSuffix; TokenMeta skuMeta = tks.GetMetaEntry(skuMetaName); foreach (string k in skuMeta.Data.Keys) diff --git a/LibTSforge/Modifiers/GracePeriodReset.cs b/LibTSforge/Modifiers/GracePeriodReset.cs index 059b1c5..3d0f6a3 100644 --- a/LibTSforge/Modifiers/GracePeriodReset.cs +++ b/LibTSforge/Modifiers/GracePeriodReset.cs @@ -2,8 +2,8 @@ namespace LibTSforge.Modifiers { using System.Collections.Generic; using System.Linq; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; + using PhysicalStore; + using SPP; public static class GracePeriodReset { diff --git a/LibTSforge/Modifiers/KMSHostCharge.cs b/LibTSforge/Modifiers/KMSHostCharge.cs index 94f4dfd..153c700 100644 --- a/LibTSforge/Modifiers/KMSHostCharge.cs +++ b/LibTSforge/Modifiers/KMSHostCharge.cs @@ -2,8 +2,8 @@ namespace LibTSforge.Modifiers { using System; using System.IO; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; + using PhysicalStore; + using SPP; public static class KMSHostCharge { @@ -31,9 +31,9 @@ namespace LibTSforge.Modifiers string key = string.Format("SPPSVC\\{0}", appId); long ldapTimestamp = DateTime.Now.ToFileTime(); - byte[] cmidGuids = new byte[] { }; - byte[] reqCounts = new byte[] { }; - byte[] kmsChargeData = new byte[] { }; + byte[] cmidGuids = { }; + byte[] reqCounts = { }; + byte[] kmsChargeData = { }; BinaryWriter writer = new BinaryWriter(new MemoryStream()); @@ -94,7 +94,7 @@ namespace LibTSforge.Modifiers if (version != PSVersion.Vista) { VariableBag kmsCountData = new VariableBag(version); - kmsCountData.Blocks.AddRange(new CRCBlockModern[] + kmsCountData.Blocks.AddRange(new[] { new CRCBlockModern { diff --git a/LibTSforge/Modifiers/KeyChangeLockDelete.cs b/LibTSforge/Modifiers/KeyChangeLockDelete.cs index 3883d3c..f6ec3de 100644 --- a/LibTSforge/Modifiers/KeyChangeLockDelete.cs +++ b/LibTSforge/Modifiers/KeyChangeLockDelete.cs @@ -2,9 +2,8 @@ namespace LibTSforge.Modifiers { using System.Collections.Generic; using System.Linq; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; - using LibTSforge; + using PhysicalStore; + using SPP; using System; public static class KeyChangeLockDelete diff --git a/LibTSforge/Modifiers/RearmReset.cs b/LibTSforge/Modifiers/RearmReset.cs index 89a12f3..e909316 100644 --- a/LibTSforge/Modifiers/RearmReset.cs +++ b/LibTSforge/Modifiers/RearmReset.cs @@ -2,8 +2,8 @@ namespace LibTSforge.Modifiers { using System.Collections.Generic; using System.Linq; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; + using PhysicalStore; + using SPP; public static class RearmReset { diff --git a/LibTSforge/Modifiers/SetIIDParams.cs b/LibTSforge/Modifiers/SetIIDParams.cs index d7fa2c5..2f34a7d 100644 --- a/LibTSforge/Modifiers/SetIIDParams.cs +++ b/LibTSforge/Modifiers/SetIIDParams.cs @@ -1,13 +1,9 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using LibTSforge.PhysicalStore; -using LibTSforge.SPP; - namespace LibTSforge.Modifiers { + using PhysicalStore; + using SPP; + using System.IO; + using System; public static class SetIIDParams { public static void SetParams(PSVersion version, bool production, Guid actId, PKeyAlgorithm algorithm, int group, int serial, ulong security) diff --git a/LibTSforge/Modifiers/TamperedFlagsDelete.cs b/LibTSforge/Modifiers/TamperedFlagsDelete.cs index 8369d4e..a9edc55 100644 --- a/LibTSforge/Modifiers/TamperedFlagsDelete.cs +++ b/LibTSforge/Modifiers/TamperedFlagsDelete.cs @@ -1,8 +1,8 @@ namespace LibTSforge.Modifiers { using System.Linq; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; + using PhysicalStore; + using SPP; public static class TamperedFlagsDelete { @@ -14,7 +14,7 @@ namespace LibTSforge.Modifiers using (IPhysicalStore store = SPPUtils.GetStore(version, production)) { - if (version == PSVersion.Vista) + if (version == PSVersion.Vista) { DeleteFlag(store, "6BE8425B-E3CF-4e86-A6AF-5863E3DCB606"); } diff --git a/LibTSforge/Modifiers/UniqueIdDelete.cs b/LibTSforge/Modifiers/UniqueIdDelete.cs index d1851c4..b66954a 100644 --- a/LibTSforge/Modifiers/UniqueIdDelete.cs +++ b/LibTSforge/Modifiers/UniqueIdDelete.cs @@ -1,8 +1,8 @@ namespace LibTSforge.Modifiers { using System; - using LibTSforge.PhysicalStore; - using LibTSforge.SPP; + using PhysicalStore; + using SPP; public static class UniqueIdDelete { @@ -27,7 +27,6 @@ namespace LibTSforge.Modifiers appId = SLApi.GetAppId(actId); } - string instId = SLApi.GetInstallationID(actId); Guid pkeyId = SLApi.GetInstalledPkeyID(actId); SPPUtils.KillSPP(version); diff --git a/LibTSforge/PhysicalStore/Common.cs b/LibTSforge/PhysicalStore/Common.cs index d0ad4fe..aef77f8 100644 --- a/LibTSforge/PhysicalStore/Common.cs +++ b/LibTSforge/PhysicalStore/Common.cs @@ -4,9 +4,9 @@ namespace LibTSforge.PhysicalStore public enum BlockType : uint { - NONE, + NONE, // unused NAMED, - ATTRIBUTE, + ATTRIBUTE, //unused TIMER } diff --git a/LibTSforge/PhysicalStore/PhysicalStoreModern.cs b/LibTSforge/PhysicalStore/PhysicalStoreModern.cs index 9d8bb73..b76852a 100644 --- a/LibTSforge/PhysicalStore/PhysicalStoreModern.cs +++ b/LibTSforge/PhysicalStore/PhysicalStoreModern.cs @@ -3,7 +3,7 @@ namespace LibTSforge.PhysicalStore using System; using System.Collections.Generic; using System.IO; - using LibTSforge.Crypto; + using Crypto; public class ModernBlock { @@ -93,7 +93,7 @@ namespace LibTSforge.PhysicalStore public sealed class PhysicalStoreModern : IPhysicalStore { - private byte[] PreHeaderBytes = new byte[] { }; + private byte[] PreHeaderBytes = { }; private readonly Dictionary> Data = new Dictionary>(); private readonly FileStream TSFile; private readonly PSVersion Version; @@ -281,40 +281,44 @@ namespace LibTSforge.PhysicalStore public void DeleteBlock(string key, string value) { - if (Data.ContainsKey(key)) + if (!Data.ContainsKey(key)) { - List blocks = Data[key]; + return; + } - foreach (ModernBlock block in blocks) + List blocks = Data[key]; + + foreach (ModernBlock block in blocks) + { + if (block.ValueAsStr == value) { - if (block.ValueAsStr == value) - { - blocks.Remove(block); - break; - } + blocks.Remove(block); + break; } - - Data[key] = blocks; } + + Data[key] = blocks; } public void DeleteBlock(string key, uint value) { - if (Data.ContainsKey(key)) + if (!Data.ContainsKey(key)) { - List blocks = Data[key]; + return; + } - foreach (ModernBlock block in blocks) + List blocks = Data[key]; + + foreach (ModernBlock block in blocks) + { + if (block.ValueAsInt == value) { - if (block.ValueAsInt == value) - { - blocks.Remove(block); - break; - } + blocks.Remove(block); + break; } - - Data[key] = blocks; } + + Data[key] = blocks; } public PhysicalStoreModern(string tsPath, bool production, PSVersion version) diff --git a/LibTSforge/PhysicalStore/PhysicalStoreVista.cs b/LibTSforge/PhysicalStore/PhysicalStoreVista.cs index 809be77..5251914 100644 --- a/LibTSforge/PhysicalStore/PhysicalStoreVista.cs +++ b/LibTSforge/PhysicalStore/PhysicalStoreVista.cs @@ -3,7 +3,7 @@ namespace LibTSforge.PhysicalStore using System; using System.Collections.Generic; using System.IO; - using LibTSforge.Crypto; + using Crypto; public class VistaBlock { @@ -88,7 +88,7 @@ namespace LibTSforge.PhysicalStore public sealed class PhysicalStoreVista : IPhysicalStore { - private byte[] PreHeaderBytes = new byte[] { }; + private byte[] PreHeaderBytes = { }; private readonly List Blocks = new List(); private readonly FileStream TSPrimary; private readonly FileStream TSSecondary; diff --git a/LibTSforge/PhysicalStore/PhysicalStoreWin7.cs b/LibTSforge/PhysicalStore/PhysicalStoreWin7.cs index d03bf9a..006c8df 100644 --- a/LibTSforge/PhysicalStore/PhysicalStoreWin7.cs +++ b/LibTSforge/PhysicalStore/PhysicalStoreWin7.cs @@ -3,7 +3,7 @@ namespace LibTSforge.PhysicalStore using System; using System.Collections.Generic; using System.IO; - using LibTSforge.Crypto; + using Crypto; public class Win7Block { @@ -105,7 +105,7 @@ namespace LibTSforge.PhysicalStore public sealed class PhysicalStoreWin7 : IPhysicalStore { - private byte[] PreHeaderBytes = new byte[] { }; + private byte[] PreHeaderBytes = { }; private readonly List Blocks = new List(); private readonly FileStream TSPrimary; private readonly FileStream TSSecondary; diff --git a/LibTSforge/PhysicalStore/VariableBag.cs b/LibTSforge/PhysicalStore/VariableBag.cs index ebe413f..bca0e32 100644 --- a/LibTSforge/PhysicalStore/VariableBag.cs +++ b/LibTSforge/PhysicalStore/VariableBag.cs @@ -74,7 +74,6 @@ namespace LibTSforge.PhysicalStore public override void Decode(BinaryReader reader) { uint type = reader.ReadUInt32(); - uint unk_zero = reader.ReadUInt32(); uint lenName = reader.ReadUInt32(); uint lenVal = reader.ReadUInt32(); uint crc = reader.ReadUInt32(); @@ -156,7 +155,7 @@ namespace LibTSforge.PhysicalStore public List Blocks = new List(); private readonly PSVersion Version; - public void Deserialize(byte[] data) + private void Deserialize(byte[] data) { int len = data.Length; diff --git a/LibTSforge/SPP/PKeyConfig.cs b/LibTSforge/SPP/PKeyConfig.cs index 6733940..83fc981 100644 --- a/LibTSforge/SPP/PKeyConfig.cs +++ b/LibTSforge/SPP/PKeyConfig.cs @@ -74,7 +74,7 @@ namespace LibTSforge.SPP public class PKeyConfig { - public Dictionary Products = new Dictionary(); + public readonly Dictionary Products = new Dictionary(); private readonly List loadedPkeyConfigs = new List(); public void LoadConfig(Guid actId) @@ -210,10 +210,5 @@ namespace LibTSforge.SPP } } } - - public PKeyConfig() - { - - } } } diff --git a/LibTSforge/SPP/ProductKey.cs b/LibTSforge/SPP/ProductKey.cs index ae48893..f4cf15a 100644 --- a/LibTSforge/SPP/ProductKey.cs +++ b/LibTSforge/SPP/ProductKey.cs @@ -3,8 +3,8 @@ namespace LibTSforge.SPP using System; using System.IO; using System.Linq; - using LibTSforge.Crypto; - using LibTSforge.PhysicalStore; + using Crypto; + using PhysicalStore; public class ProductKey { @@ -18,16 +18,16 @@ namespace LibTSforge.SPP public ulong Security; public bool Upgrade; public PKeyAlgorithm Algorithm; - public string EulaType; - public string PartNumber; - public string Edition; - public string Channel; - public Guid ActivationId; + private readonly string EulaType; + private readonly string PartNumber; + public readonly string Edition; + public readonly string Channel; + private readonly Guid ActivationId; private string mpc; private string pid2; - public byte[] KeyBytes + private byte[] KeyBytes { get { return BitConverter.GetBytes(klow).Concat(BitConverter.GetBytes(khigh)).ToArray(); } } @@ -66,7 +66,7 @@ namespace LibTSforge.SPP public Guid GetPkeyId() { VariableBag pkb = new VariableBag(PSVersion.WinModern); - pkb.Blocks.AddRange(new CRCBlockModern[] + pkb.Blocks.AddRange(new[] { new CRCBlockModern { @@ -91,7 +91,7 @@ namespace LibTSforge.SPP return new Guid(CryptoUtils.SHA256Hash(pkb.Serialize()).Take(16).ToArray()); } - public string GetDefaultMPC() + private string GetDefaultMPC() { int build = Environment.OSVersion.Version.Build; string defaultMPC = build >= 10240 ? "03612" : @@ -111,7 +111,7 @@ namespace LibTSforge.SPP mpc = GetDefaultMPC(); // setup.cfg doesn't exist in Windows 8+ - string setupcfg = string.Format("{0}\\oobe\\{1}", Environment.SystemDirectory, "setup.cfg"); + string setupcfg = string.Format(@"{0}\oobe\{1}", Environment.SystemDirectory, "setup.cfg"); if (!File.Exists(setupcfg) || Edition.Contains(";")) { @@ -205,7 +205,7 @@ namespace LibTSforge.SPP return writer.GetBytes(); } - public string GetExtendedPid() + private string GetExtendedPid() { string mpc = GetMPC(); int serialHigh = Serial / 1000000; @@ -249,7 +249,7 @@ namespace LibTSforge.SPP { if (version == PSVersion.Win7) { - ulong shortauth = ((ulong)Group << 41) | ((ulong)Security << 31) | ((ulong)Serial << 1) | (Upgrade ? (ulong)1 : 0); + ulong shortauth = ((ulong)Group << 41) | (Security << 31) | ((ulong)Serial << 1) | (Upgrade ? (ulong)1 : 0); return BitConverter.GetBytes(shortauth); } diff --git a/LibTSforge/SPP/SLAPI.cs b/LibTSforge/SPP/SLAPI.cs index c25fb03..fc5823b 100644 --- a/LibTSforge/SPP/SLAPI.cs +++ b/LibTSforge/SPP/SLAPI.cs @@ -86,9 +86,6 @@ namespace LibTSforge.SPP [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLGetProductSkuInformation(IntPtr hSLC, ref Guid pProductSkuId, string pwszValueName, out SLDATATYPE peDataType, out uint pcbValue, out IntPtr ppbValue); - [DllImport("slc.dll", CharSet = CharSet.Unicode)] - private static extern uint SLGetProductSkuInformation(IntPtr hSLC, ref Guid pProductSkuId, string pwszValueName, IntPtr peDataType, out uint pcbValue, out IntPtr ppbValue); - [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLGetLicense(IntPtr hSLC, ref Guid pLicenseFileId, out uint pcbLicenseFile, out IntPtr ppbLicenseFile); @@ -98,7 +95,7 @@ namespace LibTSforge.SPP [DllImport("slc.dll", CharSet = CharSet.Unicode)] private static extern uint SLFireEvent(IntPtr hSLC, string pwszEventId, ref Guid pApplicationId); - public class SLContext : IDisposable + private class SLContext : IDisposable { public readonly IntPtr Handle; @@ -161,11 +158,10 @@ namespace LibTSforge.SPP { using (SLContext sl = new SLContext()) { - uint status; uint count; IntPtr pProductKeyIds; - status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_PKEY, out count, out pProductKeyIds); + uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_PKEY, out count, out pProductKeyIds); if (status != 0 || count == 0) { @@ -189,7 +185,7 @@ namespace LibTSforge.SPP SLConsumeWindowsRight(0); } - public static bool RefreshTrustedTime(Guid actId) + public static void RefreshTrustedTime(Guid actId) { using (SLContext sl = new SLContext()) { @@ -197,8 +193,7 @@ namespace LibTSforge.SPP uint count; IntPtr ppbValue; - uint status = SLGetProductSkuInformation(sl.Handle, ref actId, "TrustedTime", out type, out count, out ppbValue); - return (int)status >= 0 && status != 0xC004F012; + SLGetProductSkuInformation(sl.Handle, ref actId, "TrustedTime", out type, out count, out ppbValue); } } @@ -214,11 +209,10 @@ namespace LibTSforge.SPP { using (SLContext sl = new SLContext()) { - uint status; uint count; IntPtr pAppIds; - status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_APPLICATION, out count, out pAppIds); + uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_APPLICATION, out count, out pAppIds); if (status != 0 || count == 0) { @@ -242,15 +236,14 @@ namespace LibTSforge.SPP } } - public static Guid GetLicenseFileId(Guid licId) + private static Guid GetLicenseFileId(Guid licId) { using (SLContext sl = new SLContext()) { - uint status; uint count; IntPtr ppReturnLics; - status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_LICENSE, ref licId, SLIDTYPE.SL_ID_LICENSE_FILE, out count, out ppReturnLics); + uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_LICENSE, ref licId, SLIDTYPE.SL_ID_LICENSE_FILE, out count, out ppReturnLics); if (status != 0 || count == 0) { @@ -312,7 +305,7 @@ namespace LibTSforge.SPP IntPtr ppbValue; uint status = SLGetProductSkuInformation(sl.Handle, ref actId, "msft:sl/EUL/PHONE/PUBLIC", out type, out count, out ppbValue); - return status >= 0 && status != 0xC004F012; + return status != 0xC004F012; } } @@ -395,11 +388,11 @@ namespace LibTSforge.SPP } } - public static uint UninstallProductKey(Guid pkeyId) + public static void UninstallProductKey(Guid pkeyId) { using (SLContext sl = new SLContext()) { - return SLUninstallProofOfPurchase(sl.Handle, ref pkeyId); + SLUninstallProofOfPurchase(sl.Handle, ref pkeyId); } } diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index a535bc7..062e5ca 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -1,13 +1,13 @@ namespace LibTSforge.SPP { - using LibTSforge.Crypto; - using LibTSforge.PhysicalStore; - using LibTSforge.TokenStore; using Microsoft.Win32; using System; using System.IO; using System.Linq; using System.ServiceProcess; + using Crypto; + using PhysicalStore; + using TokenStore; public static class SPPUtils { @@ -148,7 +148,7 @@ namespace LibTSforge.SPP throw new FileNotFoundException("Failed to autodetect key type, specify physical store key with /prod or /test arguments."); } - public static string GetPSPath(PSVersion version) + private static string GetPSPath(PSVersion version) { switch (version) { @@ -328,7 +328,7 @@ namespace LibTSforge.SPP RestartSPP(version); - Logger.WriteLine("Loaded store file succesfully."); + Logger.WriteLine("Loaded store file successfully."); } } } diff --git a/LibTSforge/SPP/SPSys.cs b/LibTSforge/SPP/SPSys.cs index 18b3655..ecc331c 100644 --- a/LibTSforge/SPP/SPSys.cs +++ b/LibTSforge/SPP/SPSys.cs @@ -15,7 +15,7 @@ namespace LibTSforge.SPP [return: MarshalAs(UnmanagedType.Bool)] [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern bool DeviceIoControl([In] SafeFileHandle hDevice, [In] uint dwIoControlCode, [In] IntPtr lpInBuffer, [In] int nInBufferSize, [Out] IntPtr lpOutBuffer, [In] int nOutBufferSize, out int lpBytesReturned, [In] IntPtr lpOverlapped); + private static extern bool DeviceIoControl([In] SafeFileHandle hDevice, [In] uint dwIoControlCode, [In] IntPtr lpInBuffer, [In] int nInBufferSize, [Out] IntPtr lpOutBuffer, [In] int nOutBufferSize, out int lpBytesReturned, [In] IntPtr lpOverlapped); public static bool IsSpSysRunning() { diff --git a/LibTSforge/TokenStore/Common.cs b/LibTSforge/TokenStore/Common.cs index 1dda7e7..d7133f2 100644 --- a/LibTSforge/TokenStore/Common.cs +++ b/LibTSforge/TokenStore/Common.cs @@ -14,7 +14,7 @@ namespace LibTSforge.TokenStore public class TokenMeta { public string Name; - public Dictionary Data = new Dictionary(); + public readonly Dictionary Data = new Dictionary(); public byte[] Serialize() { @@ -37,7 +37,7 @@ namespace LibTSforge.TokenStore return writer.GetBytes(); } - public void Deserialize(byte[] data) + private void Deserialize(byte[] data) { BinaryReader reader = new BinaryReader(new MemoryStream(data)); reader.ReadInt32(); diff --git a/LibTSforge/TokenStore/TokenStoreModern.cs b/LibTSforge/TokenStore/TokenStoreModern.cs index ee51e7a..2c39ca8 100644 --- a/LibTSforge/TokenStore/TokenStoreModern.cs +++ b/LibTSforge/TokenStore/TokenStoreModern.cs @@ -4,7 +4,7 @@ namespace LibTSforge.TokenStore using System.Collections.Generic; using System.IO; using System.Linq; - using LibTSforge.Crypto; + using Crypto; public class TokenStoreModern : ITokenStore { @@ -18,7 +18,7 @@ namespace LibTSforge.TokenStore private static readonly byte[] CONTS_FOOTER = Enumerable.Repeat((byte)0xAA, 0x20).ToArray(); private List Entries = new List(); - public FileStream TokensFile; + private readonly FileStream TokensFile; public void Deserialize() { @@ -40,7 +40,7 @@ namespace LibTSforge.TokenStore uint contentOffset = reader.ReadUInt32(); uint contentLength = reader.ReadUInt32(); uint allocLength = reader.ReadUInt32(); - byte[] contentData = new byte[] { }; + byte[] contentData = { }; if (populated) { @@ -140,11 +140,10 @@ namespace LibTSforge.TokenStore writer.WritePadding(BLOCK_PAD_SIZE); writer.BaseStream.Seek(curBlockOffset, SeekOrigin.Begin); - byte[] blockHash; byte[] blockData = new byte[BLOCK_SIZE - 0x20]; + byte[] blockHash = CryptoUtils.SHA256Hash(blockData); tokens.Read(blockData, 0, BLOCK_SIZE - 0x20); - blockHash = CryptoUtils.SHA256Hash(blockData); writer.BaseStream.Seek(curBlockOffset + BLOCK_SIZE - 0x20, SeekOrigin.Begin); writer.Write(blockHash); @@ -275,11 +274,6 @@ namespace LibTSforge.TokenStore Deserialize(); } - public TokenStoreModern() - { - - } - public void Dispose() { Serialize(); diff --git a/TSforgeCLI/Program.cs b/TSforgeCLI/Program.cs index 7c1a50b..d7073fe 100644 --- a/TSforgeCLI/Program.cs +++ b/TSforgeCLI/Program.cs @@ -10,30 +10,30 @@ namespace TSforgeCLI { private class Options { - public bool Dump = false; + public bool Dump; public string DumpFilePath = "dump.dat"; - public string EncrFilePath = null; - public bool Load = false; + public string EncrFilePath; + public bool Load; 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 bool KMS4k; + public bool AVMA4k; + public bool ZCID; + public bool TimerReset; + public bool RearmReset; + public bool DeleteUniqueId; + public bool InstallGenPKey; + public bool KMSHostCharge; + public bool TamperedFlagsDelete; + public bool KeyChangeLockDelete; + public bool SetIIDParams; + public bool? Production; + public PSVersion? Version; 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 bool ShowHelp; + public PKeyAlgorithm? Algorithm; + public int Group; + public int Serial; + public ulong Security; } public static void Main(string[] args) -- cgit v1.2.3 From 91e85088480b4734a9d7302cc980be761f68161b Mon Sep 17 00:00:00 2001 From: Wither OrNot Date: Mon, 7 Apr 2025 18:12:53 -0400 Subject: stylistic fixes --- LibTSforge/Activators/AVMA4K.cs | 3 +-- LibTSforge/Modifiers/SetIIDParams.cs | 1 + LibTSforge/PhysicalStore/Common.cs | 4 ++-- LibTSforge/SPP/ProductKey.cs | 27 +++++++++++---------------- LibTSforge/SPP/SPPUtils.cs | 2 +- 5 files changed, 16 insertions(+), 21 deletions(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/Activators/AVMA4K.cs b/LibTSforge/Activators/AVMA4K.cs index 51b546a..236b727 100644 --- a/LibTSforge/Activators/AVMA4K.cs +++ b/LibTSforge/Activators/AVMA4K.cs @@ -50,8 +50,7 @@ namespace LibTSforge.Activators ulong time1 = (ulong)(creationTime + tickCount + deltaTime); ulong crcBindTime = (ulong)DateTime.UtcNow.ToFileTime(); ulong timerTime = crcBindTime / 10000; - ulong expiry = Constants.TimerMax; - expiry /= 10000; + ulong expiry = Constants.TimerMax / 10000; VariableBag avmaBinding = new VariableBag(version); diff --git a/LibTSforge/Modifiers/SetIIDParams.cs b/LibTSforge/Modifiers/SetIIDParams.cs index 2f34a7d..3d54b9d 100644 --- a/LibTSforge/Modifiers/SetIIDParams.cs +++ b/LibTSforge/Modifiers/SetIIDParams.cs @@ -4,6 +4,7 @@ namespace LibTSforge.Modifiers using SPP; using System.IO; using System; + public static class SetIIDParams { public static void SetParams(PSVersion version, bool production, Guid actId, PKeyAlgorithm algorithm, int group, int serial, ulong security) diff --git a/LibTSforge/PhysicalStore/Common.cs b/LibTSforge/PhysicalStore/Common.cs index aef77f8..d0ad4fe 100644 --- a/LibTSforge/PhysicalStore/Common.cs +++ b/LibTSforge/PhysicalStore/Common.cs @@ -4,9 +4,9 @@ namespace LibTSforge.PhysicalStore public enum BlockType : uint { - NONE, // unused + NONE, NAMED, - ATTRIBUTE, //unused + ATTRIBUTE, TIMER } diff --git a/LibTSforge/SPP/ProductKey.cs b/LibTSforge/SPP/ProductKey.cs index f4cf15a..03eb729 100644 --- a/LibTSforge/SPP/ProductKey.cs +++ b/LibTSforge/SPP/ProductKey.cs @@ -18,16 +18,16 @@ namespace LibTSforge.SPP public ulong Security; public bool Upgrade; public PKeyAlgorithm Algorithm; - private readonly string EulaType; - private readonly string PartNumber; + public readonly string EulaType; + public readonly string PartNumber; public readonly string Edition; public readonly string Channel; - private readonly Guid ActivationId; + public readonly Guid ActivationId; private string mpc; private string pid2; - private byte[] KeyBytes + public byte[] KeyBytes { get { return BitConverter.GetBytes(klow).Concat(BitConverter.GetBytes(khigh)).ToArray(); } } @@ -91,16 +91,6 @@ namespace LibTSforge.SPP return new Guid(CryptoUtils.SHA256Hash(pkb.Serialize()).Take(16).ToArray()); } - private string GetDefaultMPC() - { - int build = Environment.OSVersion.Version.Build; - string defaultMPC = build >= 10240 ? "03612" : - build >= 9600 ? "06401" : - build >= 9200 ? "05426" : - "55041"; - return defaultMPC; - } - public string GetMPC() { if (mpc != null) @@ -108,7 +98,12 @@ namespace LibTSforge.SPP return mpc; } - mpc = GetDefaultMPC(); + int build = Environment.OSVersion.Version.Build; + + mpc = build >= 10240 ? "03612" : + build >= 9600 ? "06401" : + build >= 9200 ? "05426" : + "55041"; // setup.cfg doesn't exist in Windows 8+ string setupcfg = string.Format(@"{0}\oobe\{1}", Environment.SystemDirectory, "setup.cfg"); @@ -205,7 +200,7 @@ namespace LibTSforge.SPP return writer.GetBytes(); } - private string GetExtendedPid() + public string GetExtendedPid() { string mpc = GetMPC(); int serialHigh = Serial / 1000000; diff --git a/LibTSforge/SPP/SPPUtils.cs b/LibTSforge/SPP/SPPUtils.cs index 062e5ca..fc4967b 100644 --- a/LibTSforge/SPP/SPPUtils.cs +++ b/LibTSforge/SPP/SPPUtils.cs @@ -148,7 +148,7 @@ namespace LibTSforge.SPP throw new FileNotFoundException("Failed to autodetect key type, specify physical store key with /prod or /test arguments."); } - private static string GetPSPath(PSVersion version) + public static string GetPSPath(PSVersion version) { switch (version) { -- cgit v1.2.3 From 22bbb93e909154da94aee1b55e551038a3a37e6c Mon Sep 17 00:00:00 2001 From: Wither OrNot Date: Mon, 7 Apr 2025 18:17:43 -0400 Subject: make public --- LibTSforge/SPP/SLAPI.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'LibTSforge/SPP') diff --git a/LibTSforge/SPP/SLAPI.cs b/LibTSforge/SPP/SLAPI.cs index fc5823b..ec27381 100644 --- a/LibTSforge/SPP/SLAPI.cs +++ b/LibTSforge/SPP/SLAPI.cs @@ -236,7 +236,7 @@ namespace LibTSforge.SPP } } - private static Guid GetLicenseFileId(Guid licId) + public static Guid GetLicenseFileId(Guid licId) { using (SLContext sl = new SLContext()) { -- cgit v1.2.3