Beispiel #1
0
        private void populateRegistrykey(caCommandMessages.RegKey respKey, RegistryKey sysKey)
        {
            // First, populate the values for this key
            populateRegKeyValues(respKey, sysKey);

            // Second, recursively populate sub-keys for this key
            String[] subKeyNames = sysKey.GetSubKeyNames();

            if (subKeyNames.Length > 0)
            {
                RegKey[] childKeys = new RegKey[subKeyNames.Length];

                for (int i = 0; i < subKeyNames.Length; i++)
                {
                    RegistryKey subKey = sysKey.OpenSubKey(subKeyNames[i], false);

                    // Allocate a new RegKey to hold the subkey
                    childKeys[i] = new RegKey();

                    // Populate the subkey
                    populateRegistrykey(childKeys[i], subKey);
                }

                respKey.subKeys = childKeys;
            }
        }
Beispiel #2
0
        public void RegKey_SetGet_Int()
        {
            RegKey key;

            key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest");

            key.Set("Int1", 0);
            key.Set("Int2", 100);
            key.Set("Int3", "-100");
            key.Set("Int4", "what???");

            Assert.AreEqual(0, key.Get("Int1", 55));
            Assert.AreEqual(100, key.Get("Int2", 55));
            Assert.AreEqual(-100, key.Get("Int3", 55));
            Assert.AreEqual(55, key.Get("Int4", 55));
            Assert.AreEqual(55, key.Get("Int5", 55));

            key.Close();

            Assert.AreEqual(0, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int1", 55));
            Assert.AreEqual(100, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int2", 55));
            Assert.AreEqual(-100, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int3", 55));
            Assert.AreEqual(55, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int4", 55));
            Assert.AreEqual(55, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int5", 55));

            RegKey.SetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int6", 1001);
            Assert.AreEqual(1001, RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Int6", 0));

            RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest");
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="regPath"></param>
        /// <param name="lpKind"></param>
        /// <param name="lpData"></param>
        /// <param name="lpcbData"></param>
        /// <returns></returns>
        private static RegKey ConvertData(RegPath regPath, RegistryValueKind lpKind, IntPtr lpData, int lpcbData)
        {
            RegKey regkey;

            if (lpKind == RegistryValueKind.DWord)
            {
                var lpdataint = Marshal.ReadInt32(lpData);
                regkey = new RegKey(regPath, lpKind, lpdataint);
            }
            else if (lpKind == RegistryValueKind.QWord)
            {
                var lpdataint = Marshal.ReadInt64(lpData);
                regkey = new RegKey(regPath, lpKind, lpdataint);
            }
            else if (lpKind == RegistryValueKind.String ||
                     lpKind == RegistryValueKind.ExpandString ||
                     lpKind == RegistryValueKind.MultiString)
            {
                var lpdatastr = Marshal.PtrToStringUni(lpData);
                lpdatastr = lpdatastr?.Trim();
                regkey    = new RegKey(regPath, lpKind, lpdatastr);
            }
            else if (lpKind == RegistryValueKind.Binary)
            {
                var lpdatabin = new byte[lpcbData];
                Marshal.Copy(lpData, lpdatabin, 0, lpcbData);
                regkey = new RegKey(regPath, lpKind, lpdatabin);
            }
            else
            {
                throw new Exception(@"注册表访问失败" + '\n' + @"注册表数据类型异常" + '\n' + nameof(ConvertData));
            }
            return(regkey);
        }
Beispiel #4
0
        public override void PlayTitleInternal(string executablePath, string discPath, int title)
        {
            string version = RegKey.GetValue("Version") as string;

            string arguments;

            if (version.StartsWith("1"))
            {
                arguments = "DVD://\"" + discPath + "\\\"@" + title;
            }
            else
            {
                arguments = "dvd:///\"" + discPath + "\\\"#" + title;
            }

            var process = new Process();

            process.StartInfo =
                new ProcessStartInfo
            {
                FileName  = executablePath,
                Arguments = arguments
            };

            process.Start();
        }
Beispiel #5
0
        /// <summary>
        /// 获取注册表键信息。
        /// </summary>
        /// <param name="regPath">
        /// 注册表路径信息。
        /// </param>
        /// <exception cref="Exception">
        /// 非托管代码获取注册表时产生的异常,详情请参阅MSDN。
        /// </exception>
        /// <returns>
        /// 注册表键信息。
        /// </returns>
        public static RegKey RegGetValue(RegPath regPath)
        {
            RegKey regkey;

            try
            {
                var phkresult = RegOpenKey(regPath);
                var lpcbData  = 0;
                NativeMethods.RegQueryValueEx(phkresult, regPath.LpValueName, IntPtr.Zero, out var lpkind, IntPtr.Zero, ref lpcbData);
                if (lpcbData == 0)
                {
                    NativeMethods.RegCloseKey(phkresult);
                    throw new Exception(@"注册表访问失败" + '\n' + @"无法获取缓冲区大小" + '\n' + nameof(RegGetValue));
                }
                var lpdata          = Marshal.AllocHGlobal(lpcbData);
                var reggetvaluetemp = NativeMethods.RegQueryValueEx(phkresult, regPath.LpValueName, IntPtr.Zero, out lpkind, lpdata, ref lpcbData);
                if (reggetvaluetemp != (int)ERROR_CODE.ERROR_SUCCESS)
                {
                    throw new Exception(@"注册表访问失败" + '\n' + reggetvaluetemp + '\n' + nameof(RegGetValue));
                }
                NativeMethods.RegCloseKey(phkresult);
                if (reggetvaluetemp != (int)ERROR_CODE.ERROR_SUCCESS)
                {
                    throw new Exception(@"注册表访问失败" + '\n' + reggetvaluetemp + '\n' + nameof(RegGetValue));
                }
                regkey = ConvertData(regPath, lpkind, lpdata, lpcbData);
            }
            catch (Exception)
            {
                regkey = new RegKey(regPath);
            }
            return(regkey);
        }
Beispiel #6
0
        /// <summary>
        /// Restores the state to before the installation.
        /// </summary>
        /// <param name="state">The installer state.</param>
        private void Restore(IDictionary state)
        {
            try
            {
                string keyPath  = (string)state[InstallTools.GetStateKey(this, "KeyPath")];
                object orgValue = state[InstallTools.GetStateKey(this, "OrgValue")];

                if (orgValue == null)
                {
                    RegKey.Delete(keyPath);
                }
                else if (orgValue is int)
                {
                    RegKey.SetValue(keyPath, (int)orgValue);
                }
                else if (orgValue is string)
                {
                    RegKey.GetValue(keyPath, (string)orgValue);
                }
                else
                {
                    throw new InvalidOperationException("RegInstaller works only for REG_DWORD and REG_SZ registry values.");
                }
            }
            catch
            {
                // I'm going to ignore errors here since it'll often be the case
                // that the parent key has already been removed.
            }
        }
        /// <summary>
        /// Remove reference to HKLM or HKCU at the begining of the <see cref="dirtyRegKey"/>
        /// </summary>
        /// <param name="dirtyRegKey">A string that, eventually, contains a reference to HKLM or HKCU.</param>
        /// <param name="currentHive">The current Registry Hive.</param>
        /// <returns>Returns a <see cref="RegKey"/> that contains the clean RegistryKey name with the referenced Hive.</returns>
        public static RegKey RemoveRegistryHiveReference(string dirtyRegKey, RegistryHive currentHive)
        {
            const string HKLM        = "HKEY_LOCAL_MACHINE";
            const string HKCU        = "HKEY_CURRENT_USER";
            RegKey       cleanRegKey = new RegKey();

            cleanRegKey.RegHive    = currentHive;
            cleanRegKey.RegKeyName = dirtyRegKey;

            string tempTxt = dirtyRegKey.ToUpper();

            if (tempTxt.StartsWith(HKLM))
            {
                cleanRegKey.RegKeyName = dirtyRegKey.Substring(HKLM.Length);
                cleanRegKey.RegHive    = RegistryHelper.RegistryHive.HKey_Local_Machine;
            }

            if (tempTxt.StartsWith(HKCU))
            {
                cleanRegKey.RegKeyName = dirtyRegKey.Substring(HKCU.Length);
                cleanRegKey.RegHive    = RegistryHelper.RegistryHive.HKey_Current_User;
            }

            return(cleanRegKey);
        }
Beispiel #8
0
        public void RegKey_SetGet_TimeSpan()
        {
            RegKey key;

            key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest");

            key.Set("TS1", "10");
            key.Set("TS2", "10ms");
            key.Set("TS3", "hello?");

            Assert.AreEqual(TimeSpan.FromSeconds(10), key.Get("TS1", TimeSpan.FromSeconds(55)));
            Assert.AreEqual(TimeSpan.FromMilliseconds(10), key.Get("TS2", TimeSpan.FromSeconds(55)));
            Assert.AreEqual(TimeSpan.FromSeconds(55), key.Get("TS3", TimeSpan.FromSeconds(55)));

            key.Close();

            Assert.AreEqual(TimeSpan.FromSeconds(10), RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS1", TimeSpan.FromSeconds(55)));
            Assert.AreEqual(TimeSpan.FromMilliseconds(10), RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS2", TimeSpan.FromSeconds(55)));
            Assert.AreEqual(TimeSpan.FromSeconds(55), RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS3", TimeSpan.FromSeconds(55)));
            Assert.AreEqual(TimeSpan.FromSeconds(55), RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS4", TimeSpan.FromSeconds(55)));

            RegKey.SetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS5", TimeSpan.FromSeconds(1001));
            Assert.AreEqual(TimeSpan.FromSeconds(1001), RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:TS5", TimeSpan.FromSeconds(1)));

            RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest");
        }
Beispiel #9
0
 static void ExportValues(RegKey key, ExportProvider provider)
 {
     foreach (RegValue value in RegExplorer.GetValues(key.Key))
     {
         provider.WriteValue(value.Name, value.Kind, value.Data);
     }
 }
Beispiel #10
0
    public IEnumerator GetEnumerator()
    {
        List <string> ids = new List <string>();

        string bg = Background ? "\\Background" : "";

        RegKey crk = Type.CR.Open(Type.Link + shell);
        RegKey sak = Type.SA.Open(Type.ID + shell);

        if (crk != null)
        {
            ids.AddRange(crk.Keys);
        }
        if (sak != null)
        {
            foreach (string id in sak.Keys)
            {
                if (!ids.Contains(id))
                {
                    ids.Add(id);
                }
            }
        }

        foreach (string id in ids)
        {
            yield return(this[id]);
        }
    }
Beispiel #11
0
        private bool ExportToFile(RegKey key, RegExportFormat format, Stream output)
        {
            bool success = true;

            using (output)
            {
                DisableControls();
                try
                {
                    using (new BusyCursor(this))
                    {
                        using (StreamWriter writer = new StreamWriter(output))
                        {
                            RegExporter.Export(key, ExportProvider.Create(format, writer));
                        }
                    }
                }
                catch
                {
                    success = false;
                }
                EnableControls();
            }
            return(success);
        }
Beispiel #12
0
        /// <summary>
        /// Sets the startup mode for a service.
        /// </summary>
        /// <param name="serviceName">The service name.</param>
        /// <param name="mode">Thye new start mode.</param>
        public static void SetStartMode(string serviceName, ServiceStartMode mode)
        {
            RegKey key;
            int    raw = 0;

            key = RegKey.Open(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" + serviceName);

            if (key == null)
            {
                throw new InvalidOperationException(string.Format("Service [{0}] does not exist.", serviceName));
            }

            key.Close();

            switch (mode)
            {
            case ServiceStartMode.Automatic:    raw = 2; break;

            case ServiceStartMode.Manual:       raw = 3; break;

            case ServiceStartMode.Disabled:     raw = 4; break;
            }

            if (raw != 0)
            {
                RegKey.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" + serviceName + ":Start", raw);
            }
        }
Beispiel #13
0
        private void RenameRegistryKey()
        {
            Logger.Write("Rename Registry.");

            try
            {
                if (RegKey.EndsWith(@"\"))
                {
                    RegKey = RegKey.Substring(0, RegKey.Length - 1);
                }

                Logger.Write("Will try to rename " + RegHive + "\\" + RegKey + " into : " + RegName);

                RegistryKey parentKey  = GetRegistryHive().OpenSubKey(RegKey.Substring(0, RegKey.LastIndexOf(@"\")), true);
                string      subKeyName = RegKey.Substring(RegKey.LastIndexOf(@"\") + 1);

                CopyKey(parentKey, subKeyName, RegName);
                parentKey.DeleteSubKeyTree(subKeyName);
                parentKey.Flush();
                parentKey.Close();
            }
            catch (Exception ex)
            {
                Logger.Write("Error renaming Registry Key : " + RegHive + "\\" + RegKey + "\r\n" + ex.Message);
            }
        }
Beispiel #14
0
        public void RegKey_DeleteValue()
        {
            RegKey key;

            key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest");

            key.Set("Test1", "10");
            key.Set("Test2", "20");

            Assert.AreEqual("20", key.Get("Test2"));
            key.DeleteValue("Test2");
            Assert.IsNull(key.Get("Test2"));

            key.Close();

            RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1");
            Assert.IsNull(key.Get("Test1"));

            RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest");

            RegKey.SetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Foo", "test");
            Assert.AreEqual("test", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Foo"));

            RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest");
        }
Beispiel #15
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private List <ProfilePath> ExtractProfilePaths()
        {
            RegParser regParser = new RegParser(_softwareFile);

            RegKey rootKey = regParser.RootKey;

            RegKey regKey = rootKey.Key("Microsoft\\Windows NT\\CurrentVersion\\ProfileList");

            if (regKey == null)
            {
                Console.WriteLine("Unable to locate the following registry key: Microsoft\\Windows NT\\CurrentVersion\\ProfileList");
                return(null);
            }

            List <ProfilePath> profilePaths = new List <ProfilePath>();
            List <RegKey>      subKeys      = regKey.SubKeys;

            for (int index = 0; index < subKeys.Count; index++)
            {
                RegValue regValue = subKeys[index].Value("ProfileImagePath");
                if (regValue == null)
                {
                    continue;
                }

                ProfilePath profilePath = new ProfilePath();
                string      temp        = regValue.Data.ToString().Replace("\0", string.Empty);
                profilePath.Path = temp;
                profilePath.Rid  = woanware.Helper.RemoveHivePrefix(subKeys[index].Name).Replace("Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\", string.Empty);

                profilePaths.Add(profilePath);
            }

            return(profilePaths);
        }
            public RegKey SubKey(string key)
            {
                var regKey = new RegKey(key);

                SubKeys.Add(regKey);
                return(regKey);
            }
        public void SaveKeyData(string filePath, string pattern)
        {
            try
            {
                string keyFile;
                //if (filePath.LastIndexOf(@"\") == filePath.Length - 1)
                //{
                //    keyFile = filePath + FileName;
                //}
                //else
                //{
                //    keyFile = filePath + @"\" + FileName;
                //}

                keyFile = filePath + FileName;

                StreamWriter sw = new StreamWriter(keyFile, false);

                string dtValue = Convert.ToString(LastUpdateDate.Ticks, 16);

                string key_date = RegKey.Trim().ToUpper() + pattern + dtValue.ToUpper();

                sw.WriteLine(key_date);
                sw.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static System.Collections.Generic.List <RegKey> GetSubKeys(Microsoft.Win32.RegistryKey key)
        {
            int subKeyCount = key.SubKeyCount;

            if (subKeyCount == 0)
            {
                return(new System.Collections.Generic.List <RegKey>());
            }

            System.Collections.Generic.List <RegKey> subKeys = new System.Collections.Generic.List <RegKey>(subKeyCount);

            string[] subKeyNames = key.GetSubKeyNames();

            for (int i = 0; i < subKeyNames.Length; i++)
            {
                try
                {
                    string keyName = subKeyNames[i];
                    RegKey item    = new RegKey(keyName, key.OpenSubKey(keyName));
                    subKeys.Add(item);
                }
                catch { }
            }

            return(subKeys);
        }
Beispiel #19
0
        public void RegKey_Basic()
        {
            RegKey key;

            Assert.IsFalse(RegKey.Exists(@"HKEY_LOCAL_MACHINE\Software\RegTest"));
            key = RegKey.Create(@"HKEY_LOCAL_MACHINE\Software\RegTest");
            Assert.IsTrue(RegKey.Exists(@"HKEY_LOCAL_MACHINE\Software\RegTest"));

            key.Set("Test1", "value1");
            key.Set("Test2", "value2");
            key.Set("Test3", 3);

            Assert.AreEqual("value1", key.Get("Test1"));
            Assert.AreEqual("value2", key.Get("Test2"));
            Assert.AreEqual("3", key.Get("Test3"));

            key.Set("Test1", "hello");
            Assert.AreEqual("hello", key.Get("Test1"));

            Assert.AreEqual("default", key.Get("foobar", "default"));

            key.Close();

            Assert.AreEqual("hello", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test1"));
            Assert.AreEqual("value2", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test2"));
            Assert.AreEqual("3", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test3"));

            RegKey.SetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test4", "Hello");
            Assert.AreEqual("Hello", RegKey.GetValue(@"HKEY_LOCAL_MACHINE\Software\RegTest:Test4"));

            RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest");
        }
Beispiel #20
0
        /// <summary>
        /// Returns the startup mode for a service.
        /// </summary>
        /// <param name="serviceName">The service name.</param>
        /// <returns>The start mode.</returns>
        public static ServiceStartMode GetStartMode(string serviceName)
        {
            RegKey key;
            int    raw;

            key = RegKey.Open(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" + serviceName);

            if (key == null)
            {
                throw new InvalidOperationException(string.Format("Service [{0}] does not exist.", serviceName));
            }

            key.Close();

            raw = RegKey.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" + serviceName + ":Start", 0);

            switch (raw)
            {
            case 2:     return(ServiceStartMode.Automatic);

            case 3:     return(ServiceStartMode.Manual);

            default:
            case 4:     return(ServiceStartMode.Disabled);
            }
        }
Beispiel #21
0
        private void ConfirmDelete(object sender, RoutedEventArgs e)
        {
            RegistryKey RegKey, SubRegKey;

            switch (this.PathValue1.SelectedIndex)
            {
            case 0:
                RegKey = Registry.ClassesRoot;
                break;

            case 1:
                RegKey = Registry.CurrentUser;
                break;

            case 2:
                RegKey = Registry.LocalMachine;
                break;

            case 3:
                RegKey = Registry.Users;
                break;

            case 4:
                RegKey = Registry.CurrentConfig;
                break;

            default:
                RegKey = null;
                break;
            }
            SubRegKey = RegKey.OpenSubKey(this.PathValue2.Text, true);
            if (SubRegKey != null)
            {
                try
                {
                    if (SubRegKey.GetValue(this.NameValue.Text) == null)
                    {
                        this.ConfirmMsg.Content    = Msg[LanguageIdx, 0] + this.PathValue1.Text + "\\" + this.PathValue2.Text + ":" + this.NameValue.Text;
                        this.ConfirmMsg.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        SubRegKey.DeleteValue(this.NameValue.Text);
                        this.ConfirmMsg.Content    = Msg[LanguageIdx, 1] + this.PathValue1.Text + "\\" + this.PathValue2.Text + ":" + this.NameValue.Text;
                        this.ConfirmMsg.Foreground = new SolidColorBrush(Colors.Black);
                    }
                }
                catch
                {
                }
            }
            else
            {
                this.ConfirmMsg.Content    = Msg[LanguageIdx, 2] + this.PathValue1.Text + "\\" + this.PathValue2.Text;
                this.ConfirmMsg.Foreground = new SolidColorBrush(Colors.Red);
            }
            this.ConfirmDeleteBtn.Visibility = Visibility.Hidden;
            this.CancelDeleteBtn.Visibility  = Visibility.Hidden;
            this.OKBtn.Visibility            = Visibility.Visible;
        }
Beispiel #22
0
        public static RegKey GetEFIngresProviderKey()
        {
            var key = new RegKey("EFIngresProvider", new
            {
                _ = DeployUtils.GetDeployDir()
            });

            return(key);
        }
Beispiel #23
0
 public void Cleanup()
 {
     try
     {
         RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest");
     }
     catch
     {
     }
 }
Beispiel #24
0
 public void Initialize()
 {
     try
     {
         RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest");
     }
     catch
     {
     }
 }
Beispiel #25
0
 static void ExportKey(RegKey key, ExportProvider provider)
 {
     provider.WriteKeyStart(key.Key.Name);
     ExportValues(key, provider);
     foreach (RegKey subKey in RegExplorer.GetSubKeys(key.Key))
     {
         ExportKey(subKey, provider);
     }
     provider.WriteKeyEnd();
 }
Beispiel #26
0
 public static void Initialize(TestContext context)
 {
     try
     {
         RegKey.Delete(@"HKEY_LOCAL_MACHINE\Software\RegTest");
     }
     catch
     {
     }
 }
        private void btOK_Click(object sender, EventArgs e)
        {
            RegKey regKey = RegKey.Parse(RegExplorer.RegistryFavoritePath, true);

            foreach (var item in lstKeys.SelectedItems)
            {
                string key = item.ToString();
                regKey.Key.DeleteValue(key);
                favorites.Remove(key);
            }
        }
Beispiel #28
0
        void AddKeyToTree(TreeNode parent, RegKey subKey)
        {
            RegistryKey key     = subKey.Key;
            TreeNode    newNode = CreateNode(key.Name, subKey.Name, key);

            parent.Nodes.Add(newNode);
            if (key.SubKeyCount > 0)
            {
                newNode.Nodes.Add(CreateNode());
            }
        }
Beispiel #29
0
 public static void Clone(RegKey kf, RegKey kt)
 {
     foreach (string v in kf.Values)
     {
         kt[v] = kf[v];
     }
     foreach (string k in kf.Keys)
     {
         Clone(kf.Open(k), kt.Ensure(k));
     }
 }
Beispiel #30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bootKey"></param>
        /// <returns></returns>
        private byte[] GenerateHashedBootKey(List <byte> bootKey)
        {
            try
            {
                RegParser regParser = new RegParser(_samFile);

                RegKey rootKey = regParser.RootKey;

                RegKey regKey = rootKey.Key(@"SAM\Domains\Account");

                if (regKey == null)
                {
                    this.OnError("Unable to locate the following registry key: SAM\\SAM\\Domains\\Account");
                    return(null);
                }

                RegValue regValue = regKey.Value("F");
                if (regValue == null)
                {
                    this.OnError("Unable to locate the following registry key: SAM\\SAM\\Domains\\Account\\F");
                    return(null);
                }

                byte[] hashedBootKey = new byte[16];

                Buffer.BlockCopy((byte[])regValue.Data, 112, hashedBootKey, 0, 16);

                //this.PrintHex("Hashed bootkey", hashedBootKey.ToArray());

                List <byte> data = new List <byte>();
                data.AddRange(hashedBootKey.ToArray());
                data.AddRange(Encoding.ASCII.GetBytes(_aqwerty));
                data.AddRange(bootKey.ToArray());
                data.AddRange(Encoding.ASCII.GetBytes(_anum));
                byte[] md5 = MD5.Create().ComputeHash(data.ToArray());

                byte[] encData   = new byte[32];
                byte[] encOutput = new byte[32];

                Buffer.BlockCopy((byte[])regValue.Data, 128, encData, 0, 32);

                RC4Engine rc4Engine = new RC4Engine();
                rc4Engine.Init(true, new KeyParameter(md5));
                rc4Engine.ProcessBytes(encData, 0, 32, encOutput, 0);

                return(encOutput);
            }
            catch (Exception ex)
            {
                this.OnError("An error occured whilst generating the hashed boot key");
                Misc.WriteToEventLog(Application.ProductName, ex.Message, EventLogEntryType.Error);
                return(null);
            }
        }
        private void Unregister(RegistrationAttribute.RegistrationContext context, string prefix, RegKey regKey) {
            prefix += "\\" + regKey.Key;

            foreach (var registrySubKey in regKey.SubKeys) {
                Unregister(context, prefix, registrySubKey);
            }

            foreach (var value in regKey.Values) {
                context.RemoveValue(prefix, value.Key);
            }

            if (regKey.Package != null) {
                context.RemoveValue(prefix, regKey.Package);
            }
        }
        private void Register(RegistrationAttribute.RegistrationContext context, RegistrationAttribute.Key key, RegKey regKey) {
            foreach (var registrySubKey in regKey.SubKeys) {
                using (var subKey = key.CreateSubkey(registrySubKey.Key)) {
                    Register(context, subKey, registrySubKey);
                }
            }

            foreach (var value in regKey.Values) {
                key.SetValue(value.Key, value.Value);
            }

            if (regKey.Package != null) {
                key.SetValue(regKey.Package, context.ComponentType.GUID.ToString("B"));
            }
        }
Beispiel #33
0
 public static void Clone(RegKey kf, RegKey kt)
 {
     foreach (string v in kf.Values) kt[v] = kf[v];
     foreach (string k in kf.Keys) Clone(kf.Open(k), kt.Ensure(k));
 }
 public RegKey Key(string key) {
     var regKey = new RegKey(key);
     _keys.Add(regKey);
     return regKey;
 }