From 0c8b1efaa9005de1d101ebab5e66117edfaec3b2 Mon Sep 17 00:00:00 2001 From: Lyssa Date: Mon, 7 Apr 2025 19:19:24 +0400 Subject: Minor fixups --- 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 +- 5 files changed, 30 insertions(+), 42 deletions(-) (limited to 'LibTSforge/SPP') 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() { -- cgit v1.2.3