Minor fixups

This commit is contained in:
Lyssa
2025-04-07 19:19:24 +04:00
parent 3f1c878318
commit 0c8b1efaa9
25 changed files with 168 additions and 194 deletions

View File

@ -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()
{
}
}
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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.");
}
}
}

View File

@ -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()
{