-
-
Notifications
You must be signed in to change notification settings - Fork 293
/
Program.cs
393 lines (376 loc) · 16.6 KB
/
Program.cs
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/*
ViVeTool - Vibranium feature configuration tool
Copyright (C) 2019 @thebookisclosed
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using Albacore.ViVe;
namespace Albacore.ViVeTool
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("ViVeTool v0.2.1 - Vibranium feature configuration tool\n");
if (args.Length < 1)
{
PrintHelp();
return;
}
if (Environment.OSVersion.Version.Build < 18963)
{
Console.WriteLine("Windows 10 build 18963 or newer is required for this program to function");
return;
}
ProcessArgs(args);
}
static void ProcessArgs(string[] args)
{
for (int i = 0; i < args.Length; i++)
args[i] = args[i].ToLower();
#region QueryConfig
if (args[0] == "queryconfig")
{
if (args.Length < 2)
{
Console.WriteLine("Syntax: queryconfig <all | numeric id> [runtime | boot]\n");
Console.WriteLine("Examples: queryconfig all\n queryconfig 123456 runtime\n");
Console.WriteLine("If no section or an invalid section is specified, 'runtime' will be used");
return;
}
FeatureConfigurationSection sectionToUse = FeatureConfigurationSection.Runtime;
if (args.Length > 2 && args[2] == "boot")
sectionToUse = FeatureConfigurationSection.Boot;
if (args[1] == "all")
{
var retrievedConfigs = RtlFeatureManager.QueryAllFeatureConfigurations(sectionToUse);
if (retrievedConfigs != null)
{
foreach (var config in retrievedConfigs)
{
PrintFeatureConfig(config);
Console.WriteLine();
}
}
else
Console.WriteLine("Failed to query feature configurations");
}
else
{
if (!TryParseDecHexUint(args[1], out uint featureId))
{
Console.WriteLine("Couldn't parse feature ID");
return;
}
var config = RtlFeatureManager.QueryFeatureConfiguration(featureId, sectionToUse);
if (config != null)
PrintFeatureConfig(config);
else
Console.WriteLine("Failed to query feature configuration, the specified ID may not exist in the store");
}
}
#endregion
#region QuerySubs
else if (args[0] == "querysubs")
{
var retrievedSubs = RtlFeatureManager.QueryFeatureUsageSubscriptions();
if (retrievedSubs != null)
{
foreach (var sub in retrievedSubs)
{
PrintSubscription(sub);
Console.WriteLine();
}
}
}
#endregion
#region ChangeStamp
else if (args[0] == "changestamp")
{
Console.WriteLine("Change stamp: {0}", RtlFeatureManager.QueryFeatureConfigurationChangeStamp());
}
#endregion
#region AddConfig
else if (args[0] == "addconfig")
{
ProcessSetConfig(args, FeatureConfigurationAction.UpdateAll);
}
#endregion
#region DelConfig
else if (args[0] == "delconfig")
{
ProcessSetConfig(args, FeatureConfigurationAction.Delete);
}
#endregion
#region AddSub
else if (args[0] == "addsub")
{
ProcessSetSubs(args, false);
}
#endregion
#region DelSub
else if (args[0] == "delsub")
{
ProcessSetSubs(args, true);
}
#endregion
#region NotifyUsage
else if (args[0] == "notifyusage")
{
if (args.Length < 2)
{
Console.WriteLine("Syntax: notifyusage <numeric id> <reporting kind> <reporting options>\n");
Console.WriteLine("Examples: notifyusage 123465 2 1");
return;
}
if (!TryParseDecHexUint(args[1], out uint featureId))
{
Console.WriteLine("Couldn't parse feature ID");
return;
}
if (!TryParseDecHexUshort(args[2], out ushort reportingKind))
{
Console.WriteLine("Couldn't parse reporting kind");
return;
}
if (!TryParseDecHexUshort(args[3], out ushort reportingOptions))
{
Console.WriteLine("Couldn't parse reporting options");
return;
}
int result = RtlFeatureManager.NotifyFeatureUsage(new FeatureUsageReport() {
FeatureId = featureId,
ReportingKind = reportingKind,
ReportingOptions = reportingOptions
});
if (result != 0)
Console.WriteLine("An error occurred while firing the notification (hr=0x{0:x8}), no such subscription may exist", result);
else
Console.WriteLine("Successfully fired the feature usage notification");
}
#endregion
#region SetBootState
else if (args[0] == "setbootstate")
{
int state = 1;
if (args.Length > 1)
if (!int.TryParse(args[1], out state))
{
Console.WriteLine("Couldn't parse desired state");
return;
}
var result = RtlFeatureManager.SetBootFeatureConfigurationState(ref state);
if (result < 0)
Console.WriteLine("Failed to set boot state (hr=0x{0:x8})", result);
else
Console.WriteLine("Successfully set boot state");
}
#endregion
#region GetBootState
else if (args[0] == "getbootstate")
{
int state = 0;
var result = RtlFeatureManager.GetBootFeatureConfigurationState(ref state);
if (result < 0)
Console.WriteLine("Failed to query boot state (hr=0x{0:x8})", result);
else
Console.WriteLine("Boot state: {0}", state);
}
#endregion
}
static void ProcessSetSubs(string[] args, bool del)
{
if (args.Length < 5)
{
string helpPrefix = del ? "del" : "add";
Console.WriteLine("Syntax: {0}sub <numeric id> <reporting kind> <reporting options> <reporting target>\n", helpPrefix);
Console.WriteLine("Reporting targets are WNF state names\n");
Console.WriteLine("Examples: {0}sub 123456 2 1 0d83063ea3bdf875", helpPrefix);
return;
}
if (!TryParseDecHexUint(args[1], out uint featureId))
{
Console.WriteLine("Couldn't parse feature ID");
return;
}
if (!TryParseDecHexUshort(args[2], out ushort reportingKind))
{
Console.WriteLine("Couldn't parse reporting kind");
return;
}
if (!TryParseDecHexUshort(args[3], out ushort reportingOptions))
{
Console.WriteLine("Couldn't parse reporting options");
return;
}
if (!ulong.TryParse(args[4], System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out ulong reportingTarget))
{
Console.WriteLine("Couldn't parse reporting target");
return;
}
var subList = new List<FeatureUsageSubscription>() {new FeatureUsageSubscription()
{
FeatureId = featureId,
ReportingKind = reportingKind,
ReportingOptions = reportingOptions,
ReportingTarget = reportingTarget
} };
int result;
if (del)
result = RtlFeatureManager.RemoveLiveFeatureUsageSubscriptions(subList);
else
result = RtlFeatureManager.AddLiveFeatureUsageSubscriptions(subList);
if (result != 0)
{
Console.WriteLine("An error occurred while setting a live feature usage subscription (hr=0x{0:x8})", result);
return;
}
if (del)
result = RtlFeatureManager.RemoveBootFeatureUsageSubscriptions(subList) ? 0 : -1;
else
result = RtlFeatureManager.AddBootFeatureUsageSubscriptions(subList) ? 0 : -1;
if (result != 0)
Console.WriteLine("An error occurred while setting a boot feature usage subscription");
else
Console.WriteLine("Successfully set feature usage subscription");
}
static void ProcessSetConfig(string[] args, FeatureConfigurationAction actionToUse)
{
if (args.Length < 3)
{
string helpPrefix = actionToUse == FeatureConfigurationAction.Delete ? "del" : "add";
Console.WriteLine("Syntax: {0}config <numeric id> <enabled state>\n [enabled state options] [variant] [variant payload kind] [variant payload] [group]\n", helpPrefix);
Console.WriteLine("Enabled state types: 0 = Default, 1 = Disabled, 2 = Enabled\n");
Console.WriteLine("Examples: {0}config 23456789 2\n {0}config 23456789 2 1 1 0 0 4", helpPrefix);
return;
}
if (!TryParseDecHexUint(args[1], out uint featureId))
{
Console.WriteLine("Couldn't parse feature ID");
return;
}
if (!TryParseDecHexInt(args[2], out int enabledState))
{
Console.WriteLine("Couldn't parse enabled state");
return;
}
int enabledStateOptions = 1;
int variant = 0;
int variantPayloadKind = 0;
int variantPayload = 0;
int group = 4;
if (args.Length > 4 && !TryParseDecHexInt(args[3], out enabledStateOptions))
{
Console.WriteLine("Couldn't parse enabled state options");
return;
}
if (args.Length > 5 && !TryParseDecHexInt(args[4], out variant))
{
Console.WriteLine("Couldn't parse variant");
return;
}
if (args.Length > 6 && !TryParseDecHexInt(args[5], out variantPayloadKind))
{
Console.WriteLine("Couldn't parse variant payload kind");
return;
}
if (args.Length > 7 && !TryParseDecHexInt(args[6], out variantPayload))
{
Console.WriteLine("Couldn't parse variant payload");
return;
}
if (args.Length > 8 && !TryParseDecHexInt(args[7], out group))
{
Console.WriteLine("Couldn't parse group");
return;
}
var configs = new List<FeatureConfiguration>() {
new FeatureConfiguration() {
FeatureId = featureId,
EnabledState = (FeatureEnabledState)enabledState,
EnabledStateOptions = enabledStateOptions,
Group = group,
Variant = variant,
VariantPayloadKind = variantPayloadKind,
VariantPayload = variantPayload,
Action = actionToUse
} };
int result = RtlFeatureManager.SetLiveFeatureConfigurations(configs, FeatureConfigurationSection.Runtime);
if (result != 0)
{
Console.WriteLine("An error occurred while setting a live feature configuration (hr=0x{0:x8})", result);
return;
}
if (!RtlFeatureManager.SetBootFeatureConfigurations(configs))
Console.WriteLine("An error occurred while setting a boot feature configuration");
else
Console.WriteLine("Successfully set feature configuration");
}
static bool TryParseDecHexUshort(string input, out ushort output)
{
bool success;
if (input.StartsWith("0x"))
success = ushort.TryParse(input.Substring(2), System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out output);
else
success = ushort.TryParse(input, out output);
return success;
}
static bool TryParseDecHexUint(string input, out uint output)
{
bool success;
if (input.StartsWith("0x"))
success = uint.TryParse(input.Substring(2), System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out output);
else
success = uint.TryParse(input, out output);
return success;
}
static bool TryParseDecHexInt(string input, out int output)
{
bool success;
if (input.StartsWith("0x"))
success = int.TryParse(input, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out output);
else
success = int.TryParse(input, out output);
return success;
}
static void PrintHelp()
{
Console.WriteLine("Available commands:");
Console.WriteLine(" queryconfig\tLists existing feature configuration(s)");
Console.WriteLine(" querysubs\tLists existing feature usage notification subscriptions");
Console.WriteLine(" changestamp\tPrints the current feature store change stamp");
Console.WriteLine(" addconfig\tAdds a feature configuration");
Console.WriteLine(" delconfig\tDeletes a feature configuration");
Console.WriteLine(" addsub\tAdds a feature usage subscription notification");
Console.WriteLine(" delsub\tDeletes a feature usage subscription notification");
Console.WriteLine(" notifyusage\tFires a feature usage notification");
}
static void PrintFeatureConfig(FeatureConfiguration config)
{
Console.WriteLine("[0x{0:X8} / {0}]", config.FeatureId);
Console.WriteLine("Group: {0}", config.Group);
Console.WriteLine("EnabledState: {0} ({1})", config.EnabledState, (int)config.EnabledState);
Console.WriteLine("EnabledStateOptions: {0}", config.EnabledStateOptions);
Console.WriteLine("Variant: {0}", config.Variant);
Console.WriteLine("VariantPayloadKind: {0}", config.VariantPayloadKind);
Console.WriteLine("VariantPayload: {0:x}", config.VariantPayload);
}
static void PrintSubscription(FeatureUsageSubscription sub)
{
Console.WriteLine("[0x{0:X8} / {0}]", sub.FeatureId);
Console.WriteLine("ReportingKind: {0}", sub.ReportingKind);
Console.WriteLine("ReportingOptions: {0}", sub.ReportingOptions);
Console.WriteLine("ReportingTarget: {0:x16}", sub.ReportingTarget);
}
}
}