public void RegistryKeyWrapperTest()
        {
            byte[] buf = new byte[] {
                0x88, 0x00, 0x32, 0x00, 0xC3, 0x52, 0x7D, 0x00,
                0x85, 0x47, 0x1A, 0xA7, 0x20, 0x00, 0x41, 0x54,
                0x4B, 0x5F, 0x50, 0x41, 0x7E, 0x31, 0x2E, 0x5A,
                0x49, 0x50, 0x00, 0x00, 0x6C, 0x00, 0x08, 0x00,
                0x04, 0x00, 0xEF, 0xBE, 0x98, 0x47, 0x94, 0xB9,
                0x98, 0x47, 0x94, 0xB9, 0x2A, 0x00, 0x00, 0x00,
                0x64, 0xE9, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00,
                0x54, 0x00, 0x4B, 0x00, 0x5F, 0x00, 0x50, 0x00,
                0x61, 0x00, 0x63, 0x00, 0x6B, 0x00, 0x61, 0x00,
                0x67, 0x00, 0x65, 0x00, 0x5F, 0x00, 0x77, 0x00,
                0x69, 0x00, 0x6E, 0x00, 0x37, 0x00, 0x5F, 0x00,
                0x33, 0x00, 0x32, 0x00, 0x5F, 0x00, 0x5A, 0x00,
                0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00,
                0x30, 0x00, 0x38, 0x00, 0x2E, 0x00, 0x7A, 0x00,
                0x69, 0x00, 0x70, 0x00, 0x00, 0x00, 0x1C, 0x00,
                0x00, 0x00
            };

            RegistryKeyWrapper rkey = new RegistryKeyWrapper(buf);

            Assert.IsTrue(rkey.Value == buf);
        }
Ejemplo n.º 2
0
 protected override object loadSingleSetting(RegistryKeyWrapper regKeyWrapper, string settingId, object defaultValue)
 {
     RegKeysLoadedFrom.Add(regKeyWrapper);
     if (ForcedSettingsToLoad.ContainsKey(settingId))
     {
         return(ForcedSettingsToLoad[settingId]);
     }
     else
     {
         return(defaultValue);
     }
 }
Ejemplo n.º 3
0
        public void ShellItemRegistryDecoratorTest()
        {
            var shellItem = new MockShellItem("Test", 0x99);
            var regKey    = new RegistryKeyWrapper(null, "testUser", "testPath");

            int existingPropCount = shellItem.GetAllProperties().Count;

            //test injection of additional properties
            var regShellItem = new RegistryShellItemDecorator(shellItem, regKey);

            Assert.IsTrue(regShellItem.GetAllProperties().Count > existingPropCount);
        }
        /// <summary>
        /// Recursively iterates over the a registry key and its subkeys for enumerating all values of the keys and subkeys
        /// </summary>
        /// <param name="rk">the root registry key to start iterating over</param>
        /// <param name="hive">the offline registry hive</param>
        /// <param name="subKey">the path of the first subkey under the root key</param>
        /// <param name="indent"></param>
        /// <param name="path_prefix">the header to the current root key, needed for identification of the registry store</param>
        /// <returns></returns>
        private static IEnumerable <RegistryKeyWrapper> IterateOfflineRegistry(OfflineRegistryKey rk, OfflineRegistryHive hive, string subKey, RegistryKeyWrapper parent, string path_prefix)
        {
            if (rk == null)
            {
                yield break;
            }

            foreach (OfflineRegistryKey valueName in rk.SubKeys)
            {
                if (valueName.KeyName.ToUpper() == "ASSOCIATIONS")
                {
                    continue;
                }

                string             sk = GetSubkeyString(subKey, valueName.KeyName);
                OfflineRegistryKey rkNext;
                try
                {
                    rkNext = hive.GetKey(GetSubkeyString(rk.KeyPath, valueName.KeyName));
                }
                catch (SecurityException)
                {
                    continue;
                }

                string             path          = path_prefix;
                RegistryKeyWrapper rkNextWrapper = null;

                bool isNumeric = int.TryParse(valueName.KeyName, out _);
                if (isNumeric)
                {
                    OfflineKeyValue rkValue = null;
                    try
                    {
                        rkValue = rk.Values.First(val => val.ValueName == valueName.KeyName);
                    }
                    catch (InvalidOperationException) { }

                    if (rkValue == null)
                    {
                        continue;
                    }

                    byte[] byteVal = rkValue.ValueDataRaw;
                    yield return(rkNextWrapper = new RegistryKeyWrapper(rkNext, byteVal, hive, parent));
                }

                foreach (var wrapper in IterateOfflineRegistry(rkNext, hive, sk, rkNextWrapper, path))
                {
                    yield return(wrapper);
                }
            }
        }
Ejemplo n.º 5
0
        public Type GetShellType(RegistryHive hive, RegistryKeyWrapper keyWrapper, byte[] value, IShellItem parent = null)
        {
            // iterate over shellitem parsers and attempt to parse with each one, in order of priority.
            foreach (var parser in parsers)
            {
                if (parser.CanParse(hive, keyWrapper, value, parent))
                {
                    return(parser.ShellItemType);
                }
            }

            return(null);
        }
        public void RegistryKeyWrapperTest3()
        {
            RegistryHiveOnDemand hive = new RegistryHiveOnDemand("Resources\\UsrClass.dat");

            RegistryKey key = hive.GetKey("Local Settings\\Software\\Microsoft\\Windows\\Shell\\BagMRU\\0\\0");

            RegistryKeyWrapper rkWrapper = new RegistryKeyWrapper(key, key.Values.First().ValueDataRaw, hive, null);

            Assert.IsTrue(rkWrapper.LastRegistryWriteDate == new DateTime(637300198697461019, DateTimeKind.Utc).ToLocalTime());
            Assert.IsTrue(rkWrapper.RegistryPath == "S-1-5-21-1023748813-111960264-4059772771-1001_Classes\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\BagMRU\\0\\0");
            Assert.IsTrue(rkWrapper.SlotModifiedDate == new DateTime(637300198698554500, DateTimeKind.Utc).ToLocalTime());
            Assert.IsTrue(rkWrapper.RegistryUser == "S-1-5-21-1023748813-111960264-4059772771-1001");
        }
        public void RegistryKeyWrapperTest2()
        {
            string key = Microsoft.Win32.Registry.Users.GetSubKeyNames().First();

            Microsoft.Win32.RegistryKey rkey = Microsoft.Win32.Registry.Users.OpenSubKey(key); // might not work on github workflow
            byte[] value = (byte[])Microsoft.Win32.Registry.Users.GetValue(key);

            RegistryKeyWrapper rkWrapper = new RegistryKeyWrapper(rkey, value);

            Assert.IsTrue(rkWrapper.LastRegistryWriteDate != DateTime.MinValue);
            Assert.IsTrue(rkWrapper.RegistryPath != string.Empty);
            Assert.IsTrue(rkWrapper.RegistryUser != string.Empty);
            Assert.IsTrue(rkWrapper.RegistrySID != string.Empty);
        }
        public void RegistryKeyWrapperTest1()
        {
            byte[] buf = new byte[] {
                0x14, 0x00, 0x1F, 0x50, 0xE0, 0x4F, 0xD0, 0x20,
                0xEA, 0x3A, 0x69, 0x10, 0xA2, 0xD8, 0x08, 0x00,
                0x2B, 0x30, 0x30, 0x9D, 0x00, 0x00
            };

            RegistryKeyWrapper rkey = new RegistryKeyWrapper(buf, "user", "@\\ntuser.dat");

            Assert.IsTrue(rkey.Value == buf);
            Assert.IsTrue(rkey.RegistryUser == "user");
            Assert.IsTrue(rkey.RegistryPath == "@\\ntuser.dat");
        }
Ejemplo n.º 9
0
        public void Ctor_KeepsKeyReference()
        {
            // Fixture setup...
            var hive = RegistryHive.LocalMachine;
            var key  = Registry.LocalMachine;

            // Exercise SUT...
            var wrapper = new RegistryKeyWrapper(hive, key);

            // Verify SUT...
            Assert.That(wrapper.Hive, Is.EqualTo(hive));
            Assert.That(wrapper.WrappedKey, Is.SameAs(key));

            // Fixture terdown by GC...
        }
        /// <summary>
        /// Recursively iterates over the a registry key and its subkeys for enumerating all values of the keys and subkeys
        /// </summary>
        /// <param name="rk">The root registry key to start iterating over</param>
        /// <param name="subKey">the path of the first subkey under the root key</param>
        /// <param name="parent">The Parent Key of the Registry Key currently being iterated. Can be null</param>
        /// <returns></returns>
        private static IEnumerable <RegistryKeyWrapper> IterateOnlineRegistry(OnlineRegistryKey rk, string subKey, RegistryKeyWrapper parent)
        {
            if (rk == null)
            {
                yield break;
            }

            string[] subKeys = rk.GetSubKeyNames();

            foreach (string valueName in subKeys)
            {
                if (valueName.ToUpper() == "ASSOCIATIONS")
                {
                    continue;
                }

                string            sk = GetSubkeyString(subKey, valueName);
                OnlineRegistryKey rkNext;
                try
                {
                    rkNext = rk.OpenSubKey(valueName);
                }
                catch (SecurityException)
                {
                    continue;
                }

                RegistryKeyWrapper rkNextWrapper = null;

                //shellbags only have their numerical identifer for the value name, not a shellbag otherwise
                bool isNumeric = int.TryParse(valueName, out _);
                if (isNumeric)
                {
                    byte[] byteVal = (byte[])rk.GetValue(valueName);
                    yield return(rkNextWrapper = new RegistryKeyWrapper(rkNext, byteVal, parent));
                }

                foreach (var wrapper in IterateOnlineRegistry(rkNext, sk, rkNextWrapper))
                {
                    yield return(wrapper);
                }
            }
        }
Ejemplo n.º 11
0
        public void InstallPackages(string _extensionId, string _extensionName)
        {
            //            IProgress<ServiceProgressData> _progress = new System.Progress<ServiceProgressData>();
            //            var task = InitializeAsync(new CancellationToken(false), _progress);

            // Waits for MEF to initialize before the extension manager is ready to use
            var scComponentModel = VSPackageInstaller.VSPackage.GetGlobalService(typeof(SComponentModel));

            var     repository = VSPackageInstaller.VSPackage.GetGlobalService(typeof(SVsExtensionRepository)) as IVsExtensionRepository;
            var     manager    = VSPackageInstaller.VSPackage.GetGlobalService(typeof(SVsExtensionManager)) as IVsExtensionManager;
            Version vsVersion  = VsHelpers.GetVisualStudioVersion();

            var registry = new RegistryKeyWrapper(VSPackageInstaller.VSPackage.thePackage.UserRegistryRoot);

            WebEssentials.Installer installer = new WebEssentials.Installer();

            ExtensionEntry extensionEntry = new ExtensionEntry
            {
                Id   = _extensionId,
                Name = _extensionName
            };

            installer.InstallExtension(extensionEntry, repository, manager);
        }
Ejemplo n.º 12
0
        public IShellItem Create(RegistryHive hive, RegistryKeyWrapper keyWrapper, byte[] value, IShellItem parent = null)
        {
            // iterate over shellitem parsers and attempt to parse with each one, in order of priority.
            foreach (var parser in parsers)
            {
                if (parser.CanParse(hive, keyWrapper, value, parent))
                {
                    var item = parser.Parse(hive, keyWrapper, value, parent);

                    if (item == null)
                    {
                        continue;
                    }

                    // replace the Place object created by the parser with an existing copy
                    // if the place has been observed before. This keeps place objects
                    // unique so they can be used as keys to search for shell items
                    if (hive != null && hive.Places.Contains(item.Place))
                    {
                        var place = hive.Places.First(place => place == item.Place);

                        item.GetType()
                        .GetField("fields", BindingFlags.Instance | BindingFlags.NonPublic)
                        .SetValue(item, place);
                    }
                    else if (hive != null)
                    {
                        hive.Places.Add(item.Place);
                    }

                    return(item);
                }
            }

            return(null);
        }
Ejemplo n.º 13
0
 protected override object loadSingleSetting(RegistryKeyWrapper regKeyWrapper, string settingId, object defaultValue)
 {
     RegKeysLoadedFrom.Add(regKeyWrapper);
     return(ForcedSettingsToLoad[settingId]);
 }
Ejemplo n.º 14
0
 protected override void saveSingleSetting(RegistryKeyWrapper regKeyWrapper, string settingId, object value)
 {
     RegKeysSavedInto.Add(regKeyWrapper);
     SettingsSaved[settingId] = (int)value;
 }
Ejemplo n.º 15
0
 protected override object loadSingleSetting(RegistryKeyWrapper regKeyWrapper, string settingId, object defaultValue)
 {
     RegKeysLoadedFrom.Add(regKeyWrapper);
     return ForcedSettingsToLoad[settingId];
 }
Ejemplo n.º 16
0
 protected override object loadSingleSetting(RegistryKeyWrapper regKeyWrapper, string settingId, object defaultValue)
 {
     RegKeysLoadedFrom.Add(regKeyWrapper);
     if (ForcedSettingsToLoad.ContainsKey(settingId))
         return ForcedSettingsToLoad[settingId];
     else
         return defaultValue;
 }
Ejemplo n.º 17
0
 protected override void saveSingleSetting(RegistryKeyWrapper regKeyWrapper, string settingId, object value)
 {
     RegKeysSavedInto.Add(regKeyWrapper);
     SettingsSaved[settingId] = value;
 }