diff options
Diffstat (limited to 'LibTSforge/SPP')
| -rw-r--r-- | LibTSforge/SPP/PKeyConfig.cs | 7 | ||||
| -rw-r--r-- | LibTSforge/SPP/ProductKey.cs | 37 | ||||
| -rw-r--r-- | LibTSforge/SPP/SLAPI.cs | 25 | ||||
| -rw-r--r-- | LibTSforge/SPP/SPPUtils.cs | 8 | ||||
| -rw-r--r-- | LibTSforge/SPP/SPSys.cs | 2 |
5 files changed, 31 insertions, 48 deletions
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<Guid, ProductConfig> Products = new Dictionary<Guid, ProductConfig>(); + public readonly Dictionary<Guid, ProductConfig> Products = new Dictionary<Guid, ProductConfig>(); private readonly List<Guid> loadedPkeyConfigs = new List<Guid>(); 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..03eb729 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,11 +18,11 @@ 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; + public readonly string EulaType; + public readonly string PartNumber; + public readonly string Edition; + public readonly string Channel; + public readonly Guid ActivationId; private string mpc; private string pid2; @@ -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,16 +91,6 @@ namespace LibTSforge.SPP return new Guid(CryptoUtils.SHA256Hash(pkb.Serialize()).Take(16).ToArray()); } - public 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,10 +98,15 @@ 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"); + string setupcfg = string.Format(@"{0}\oobe\{1}", Environment.SystemDirectory, "setup.cfg"); if (!File.Exists(setupcfg) || Edition.Contains(";")) { @@ -249,7 +244,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..ec27381 100644 --- a/LibTSforge/SPP/SLAPI.cs +++ b/LibTSforge/SPP/SLAPI.cs @@ -87,9 +87,6 @@ namespace LibTSforge.SPP 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); [DllImport("slc.dll", CharSet = CharSet.Unicode)] @@ -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) { @@ -246,11 +240,10 @@ namespace LibTSforge.SPP { 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..fc4967b 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 { @@ -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() { |
