summaryrefslogtreecommitdiff
path: root/LibTSforge/Modifiers/KMSHostCharge.cs
diff options
context:
space:
mode:
Diffstat (limited to 'LibTSforge/Modifiers/KMSHostCharge.cs')
-rw-r--r--LibTSforge/Modifiers/KMSHostCharge.cs153
1 files changed, 96 insertions, 57 deletions
diff --git a/LibTSforge/Modifiers/KMSHostCharge.cs b/LibTSforge/Modifiers/KMSHostCharge.cs
index 5bfabdf..153c700 100644
--- a/LibTSforge/Modifiers/KMSHostCharge.cs
+++ b/LibTSforge/Modifiers/KMSHostCharge.cs
@@ -2,12 +2,12 @@ namespace LibTSforge.Modifiers
{
using System;
using System.IO;
- using LibTSforge.PhysicalStore;
- using LibTSforge.SPP;
+ using PhysicalStore;
+ using SPP;
public static class KMSHostCharge
{
- public static void Charge(PSVersion version, Guid actId, bool production)
+ public static void Charge(PSVersion version, bool production, Guid actId)
{
if (actId == Guid.Empty)
{
@@ -31,76 +31,113 @@ namespace LibTSforge.Modifiers
string key = string.Format("SPPSVC\\{0}", appId);
long ldapTimestamp = DateTime.Now.ToFileTime();
+ byte[] cmidGuids = { };
+ byte[] reqCounts = { };
+ byte[] kmsChargeData = { };
+
BinaryWriter writer = new BinaryWriter(new MemoryStream());
- for (int i = 0; i < currClients; i++)
+ if (version == PSVersion.Vista)
{
- writer.Write(ldapTimestamp - (10 * (i + 1)));
- writer.Write(Guid.NewGuid().ToByteArray());
- }
+ writer.Write(new byte[44]);
+ writer.Seek(0, SeekOrigin.Begin);
+
+ writer.Write(totalClients);
+ writer.Write(43200);
+ writer.Write(32);
+
+ writer.Seek(20, SeekOrigin.Begin);
+ writer.Write((byte)currClients);
+
+ writer.Seek(32, SeekOrigin.Begin);
+ writer.Write((byte)currClients);
+
+ writer.Seek(0, SeekOrigin.End);
- byte[] cmidGuids = writer.GetBytes();
+ for (int i = 0; i < currClients; i++)
+ {
+ writer.Write(Guid.NewGuid().ToByteArray());
+ writer.Write(ldapTimestamp - (10 * (i + 1)));
+ }
+
+ kmsChargeData = writer.GetBytes();
+ }
+ else
+ {
+ for (int i = 0; i < currClients; i++)
+ {
+ writer.Write(ldapTimestamp - (10 * (i + 1)));
+ writer.Write(Guid.NewGuid().ToByteArray());
+ }
- writer = new BinaryWriter(new MemoryStream());
+ cmidGuids = writer.GetBytes();
- writer.Write(new byte[40]);
+ writer = new BinaryWriter(new MemoryStream());
- writer.Seek(4, SeekOrigin.Begin);
- writer.Write((byte)currClients);
+ writer.Write(new byte[40]);
- writer.Seek(24, SeekOrigin.Begin);
- writer.Write((byte)currClients);
- byte[] reqCounts = writer.GetBytes();
+ writer.Seek(4, SeekOrigin.Begin);
+ writer.Write((byte)currClients);
- Utils.KillSPP();
+ writer.Seek(24, SeekOrigin.Begin);
+ writer.Write((byte)currClients);
+
+ reqCounts = writer.GetBytes();
+ }
+
+ SPPUtils.KillSPP(version);
Logger.WriteLine("Writing TrustedStore data...");
- using (IPhysicalStore store = Utils.GetStore(version, production))
+ using (IPhysicalStore store = SPPUtils.GetStore(version, production))
{
- VariableBag kmsCountData = new VariableBag();
- kmsCountData.Blocks.AddRange(new CRCBlock[]
+ if (version != PSVersion.Vista)
{
- new CRCBlock
- {
- DataType = CRCBlockType.BINARY,
- KeyAsStr = "SppBindingLicenseData",
- Value = hwidBlock
- },
- new CRCBlock
- {
- DataType = CRCBlockType.UINT,
- Key = new byte[] { },
- ValueAsInt = (uint)totalClients
- },
- new CRCBlock
- {
- DataType = CRCBlockType.UINT,
- Key = new byte[] { },
- ValueAsInt = 1051200000
- },
- new CRCBlock
+ VariableBag kmsCountData = new VariableBag(version);
+ kmsCountData.Blocks.AddRange(new[]
{
- DataType = CRCBlockType.UINT,
- Key = new byte[] { },
- ValueAsInt = (uint)currClients
- },
- new CRCBlock
- {
- DataType = CRCBlockType.BINARY,
- Key = new byte[] { },
- Value = cmidGuids
- },
- new CRCBlock
- {
- DataType = CRCBlockType.BINARY,
- Key = new byte[] { },
- Value = reqCounts
- }
- });
+ new CRCBlockModern
+ {
+ DataType = CRCBlockType.BINARY,
+ KeyAsStr = "SppBindingLicenseData",
+ Value = hwidBlock
+ },
+ new CRCBlockModern
+ {
+ DataType = CRCBlockType.UINT,
+ Key = new byte[] { },
+ ValueAsInt = (uint)totalClients
+ },
+ new CRCBlockModern
+ {
+ DataType = CRCBlockType.UINT,
+ Key = new byte[] { },
+ ValueAsInt = 1051200000
+ },
+ new CRCBlockModern
+ {
+ DataType = CRCBlockType.UINT,
+ Key = new byte[] { },
+ ValueAsInt = (uint)currClients
+ },
+ new CRCBlockModern
+ {
+ DataType = CRCBlockType.BINARY,
+ Key = new byte[] { },
+ Value = cmidGuids
+ },
+ new CRCBlockModern
+ {
+ DataType = CRCBlockType.BINARY,
+ Key = new byte[] { },
+ Value = reqCounts
+ }
+ });
+
+ kmsChargeData = kmsCountData.Serialize();
+ }
- byte[] kmsChargeData = kmsCountData.Serialize();
- string countVal = string.Format("msft:spp/kms/host/2.0/store/counters/{0}", appId);
+ string countVal = version == PSVersion.Vista ? "C8F6FFF1-79CE-404C-B150-F97991273DF1" : string.Format("msft:spp/kms/host/2.0/store/counters/{0}", appId);
store.DeleteBlock(key, countVal);
store.AddBlock(new PSBlock
@@ -114,6 +151,8 @@ namespace LibTSforge.Modifiers
Logger.WriteLine(string.Format("Set charge count to {0} successfully.", currClients));
}
+
+ SPPUtils.RestartSPP(version);
}
}
}