public static FeatureConfiguration QueryFeatureConfiguration(uint featureId, FeatureConfigurationSection section, ref uint changeStamp) { // One feature config is 12 bytes long IntPtr rawBuf = Marshal.AllocHGlobal(12); int hRes = NativeMethods.RtlQueryFeatureConfiguration(featureId, section, ref changeStamp, rawBuf); if (hRes != 0) { Marshal.FreeHGlobal(rawBuf); return(null); } byte[] buf = new byte[12]; Marshal.Copy(rawBuf, buf, 0, buf.Length); Marshal.FreeHGlobal(rawBuf); int compactState = BitConverter.ToInt32(buf, 4); return(new FeatureConfiguration() { FeatureId = BitConverter.ToUInt32(buf, 0), Group = compactState & 0xF, EnabledState = (FeatureEnabledState)((compactState & 0x30) >> 4), EnabledStateOptions = (compactState & 0x40) >> 6, Variant = (compactState & 0x3F00) >> 8, VariantPayloadKind = (compactState & 0xC000) >> 14, VariantPayload = BitConverter.ToInt32(buf, 8) }); }
public static List <FeatureConfiguration> QueryAllFeatureConfigurations(FeatureConfigurationSection section, ref uint changeStamp) { int featureCount = 0; NativeMethods.RtlQueryAllFeatureConfigurations(section, ref changeStamp, IntPtr.Zero, ref featureCount); if (featureCount == 0) { return(null); } // One feature config is 12 bytes long IntPtr rawBuf = Marshal.AllocHGlobal(featureCount * 12); int hRes = NativeMethods.RtlQueryAllFeatureConfigurations(section, ref changeStamp, rawBuf, ref featureCount); if (hRes != 0) { Marshal.FreeHGlobal(rawBuf); return(null); } byte[] buf = new byte[featureCount * 12]; Marshal.Copy(rawBuf, buf, 0, buf.Length); Marshal.FreeHGlobal(rawBuf); var allFeatureConfigs = new List <FeatureConfiguration>(); using (MemoryStream ms = new MemoryStream(buf, false)) { using (BinaryReader br = new BinaryReader(ms)) { for (int i = 0; i < featureCount; i++) { uint featureId = br.ReadUInt32(); int compactState = br.ReadInt32(); allFeatureConfigs.Add(new FeatureConfiguration() { FeatureId = featureId, Group = compactState & 0xF, EnabledState = (FeatureEnabledState)((compactState & 0x30) >> 4), EnabledStateOptions = (compactState & 0x40) >> 6, Variant = (compactState & 0x3F00) >> 8, VariantPayloadKind = (compactState & 0xC000) >> 14, VariantPayload = br.ReadInt32() }); } } } return(allFeatureConfigs); }
public static FeatureConfiguration QueryFeatureConfiguration(uint featureId, FeatureConfigurationSection section) { uint dummy = 0; return(QueryFeatureConfiguration(featureId, section, ref dummy)); }
public static List <FeatureConfiguration> QueryAllFeatureConfigurations(FeatureConfigurationSection section) { uint dummy = 0; return(QueryAllFeatureConfigurations(section, ref dummy)); }
public static int SetLiveFeatureConfigurations(List <FeatureConfiguration> configurations, FeatureConfigurationSection section, ref uint changeStamp) { return(NativeMethods.RtlSetFeatureConfigurations(ref changeStamp, section, RtlDataHelpers.SerializeFeatureConfigurations(configurations), configurations.Count)); }
public static int SetLiveFeatureConfigurations(List <FeatureConfiguration> configurations, FeatureConfigurationSection section) { uint dummy = 0; return(SetLiveFeatureConfigurations(configurations, section, ref dummy)); }
public static extern int RtlSetFeatureConfigurations( ref ulong changeStamp, FeatureConfigurationSection sectionType, byte[] buffer, int featureCount );
public static extern int RtlQueryFeatureConfiguration( uint featureId, FeatureConfigurationSection sectionType, ref ulong changeStamp, IntPtr buffer );
public static extern int RtlQueryAllFeatureConfigurations( FeatureConfigurationSection sectionType, ref ulong changeStamp, IntPtr buffer, ref int featureCount );
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 ProcessSetConfig(string[] args, FeatureConfigurationAction actionToUse) { if (args.Length < 4) { string helpPrefix = actionToUse == FeatureConfigurationAction.Delete ? "del" : "add"; Console.WriteLine("Syntax: {0}config <runtime | boot> <numeric id> <enabled state>\n [enabled state options] [variant] [variant payload kind] [variant payload] [group]\n", helpPrefix); Console.WriteLine("If an invalid section is specified, 'runtime' will be used\n\nEnabled state types: 0 = Default, 1 = Disabled, 2 = Enabled\n"); Console.WriteLine("Examples: {0}config runtime 123456 2\n {0}config runtime 456789 2 1 4 1 0 0", helpPrefix); return; } FeatureConfigurationSection sectionToUse = FeatureConfigurationSection.Runtime; if (args[1] == "boot") { sectionToUse = FeatureConfigurationSection.Boot; } else { Console.WriteLine("Invalid action, only 'add' or 'delete' are supported"); return; } if (!TryParseDecHexUint(args[2], out uint featureId)) { Console.WriteLine("Couldn't parse feature ID"); return; } if (!TryParseDecHexInt(args[3], 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[4], out enabledStateOptions)) { Console.WriteLine("Couldn't parse enabled state options"); return; } if (args.Length > 5 && !TryParseDecHexInt(args[5], out variant)) { Console.WriteLine("Couldn't parse variant"); return; } if (args.Length > 6 && !TryParseDecHexInt(args[6], out variantPayloadKind)) { Console.WriteLine("Couldn't parse variant payload kind"); return; } if (args.Length > 7 && !TryParseDecHexInt(args[7], out variantPayload)) { Console.WriteLine("Couldn't parse variant payload"); return; } if (args.Length > 8 && !TryParseDecHexInt(args[8], out group)) { Console.WriteLine("Couldn't parse group"); return; } int result = RtlFeatureManager.SetFeatureConfigurations(new List <FeatureConfiguration>() { new FeatureConfiguration() { FeatureId = featureId, EnabledState = (FeatureEnabledState)enabledState, EnabledStateOptions = enabledStateOptions, Group = group, Variant = variant, VariantPayloadKind = variantPayloadKind, VariantPayload = variantPayload, Action = actionToUse } }, sectionToUse); if (result != 0) { Console.WriteLine("An error occurred while setting the feature configuration (hr=0x{0:x8})", result); } else { Console.WriteLine("Successfully set feature configuration"); } }