1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
namespace LibTSforge.Activators
{
using System;
using System.IO;
using System.Linq;
using Crypto;
using PhysicalStore;
using SPP;
public static class ZeroCID
{
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));
if (status != 0)
{
throw new InvalidOperationException("Failed to deposit fake CID.");
}
}
public static void Activate(PSVersion version, bool production, Guid actId)
{
Guid appId;
if (actId == Guid.Empty)
{
appId = SLApi.WINDOWS_APP_ID;
actId = SLApi.GetDefaultActivationID(appId, false);
if (actId == Guid.Empty)
{
throw new NotSupportedException("No applicable activation IDs found.");
}
}
else
{
appId = SLApi.GetAppId(actId);
}
if (!SLApi.IsPhoneActivatable(actId))
{
throw new NotSupportedException("Phone license is unavailable for this product.");
}
string instId = SLApi.GetInstallationID(actId);
Guid pkeyId = SLApi.GetInstalledPkeyID(actId);
if (version == PSVersion.Vista || version == PSVersion.Win7)
{
Deposit(actId, instId);
}
SPPUtils.KillSPP(version);
Logger.WriteLine("Writing TrustedStore data...");
using (IPhysicalStore store = SPPUtils.GetStore(version, production))
{
byte[] hwidBlock = Constants.UniversalHWIDBlock;
Logger.WriteLine("Activation ID: " + actId);
Logger.WriteLine("Installation ID: " + instId);
Logger.WriteLine("Product Key ID: " + pkeyId);
byte[] iidHash;
if (version == PSVersion.Vista)
{
iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId)).Take(0x10).ToArray();
}
else if (version == PSVersion.Win7)
{
iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId));
}
else
{
iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId + '\0' + Constants.ZeroCID));
}
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);
byte[] pkeyData;
if (version == PSVersion.Vista)
{
pkeyData = pkb.GetBlock("PKeyBasicInfo").Value;
string uniqueId = Utils.DecodeString(pkeyData.Skip(0x120).Take(0x80).ToArray());
string extPid = Utils.DecodeString(pkeyData.Skip(0x1A0).Take(0x80).ToArray());
uint group;
uint.TryParse(extPid.Split('-')[1], out group);
if (group == 0)
{
throw new FormatException("Extended PID has invalid format.");
}
ulong shortauth;
try
{
shortauth = BitConverter.ToUInt64(Convert.FromBase64String(uniqueId.Split('&')[1]), 0);
}
catch
{
throw new FormatException("Key Unique ID has invalid format.");
}
shortauth |= (ulong)group << 41;
pkeyData = BitConverter.GetBytes(shortauth);
}
else if (version == PSVersion.Win7)
{
pkeyData = pkb.GetBlock("SppPkeyShortAuthenticator").Value;
}
else
{
pkeyData = pkb.GetBlock("SppPkeyPhoneActivationData").Value;
}
pkb.DeleteBlock("SppPkeyVirtual");
store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());
BinaryWriter writer = new BinaryWriter(new MemoryStream());
writer.Write(iidHash.Length);
writer.Write(iidHash);
writer.Write(hwidBlock.Length);
writer.Write(hwidBlock);
byte[] tsHwidData = writer.GetBytes();
writer = new BinaryWriter(new MemoryStream());
writer.Write(iidHash.Length);
writer.Write(iidHash);
writer.Write(pkeyData.Length);
writer.Write(pkeyData);
byte[] tsPkeyInfoData = writer.GetBytes();
string phoneVersion = version == PSVersion.Vista ? "6.0" : "7.0";
Guid indexSlid = version == PSVersion.Vista ? actId : pkeyId;
string hwidBlockName = string.Format("msft:Windows/{0}/Phone/Cached/HwidBlock/{1}", phoneVersion, indexSlid);
string pkeyInfoName = string.Format("msft:Windows/{0}/Phone/Cached/PKeyInfo/{1}", phoneVersion, indexSlid);
store.DeleteBlock(key, hwidBlockName);
store.DeleteBlock(key, pkeyInfoName);
store.AddBlocks(new[] {
new PSBlock
{
Type = BlockType.NAMED,
Flags = 0,
KeyAsStr = key,
ValueAsStr = hwidBlockName,
Data = tsHwidData
},
new PSBlock
{
Type = BlockType.NAMED,
Flags = 0,
KeyAsStr = key,
ValueAsStr = pkeyInfoName,
Data = tsPkeyInfoData
}
});
}
if (version != PSVersion.Vista && version != PSVersion.Win7)
{
Deposit(actId, instId);
}
SPPUtils.RestartSPP(version);
SLApi.FireStateChangedEvent(appId);
Logger.WriteLine("Activated using ZeroCID successfully.");
}
}
}
|