Exemplo n.º 1
0
        public void Convert()
        {
            var tempReg = System.Guid.NewGuid().ToString("N") + ".reg";
            var tempDir = "reg-out-" + System.Guid.NewGuid().ToString("N");

            Directory.CreateDirectory(tempDir);
            try
            {
                var mfn = typeof(TestConversion).Assembly.GetManifestResourceNames().First(a => a.EndsWith("team.reg"));
                using (var mf = typeof(TestConversion).Assembly.GetManifestResourceStream(mfn))
                {
                    using (var fs = File.OpenWrite(tempReg))
                    {
                        // ReSharper disable once PossibleNullReferenceException
                        mf.CopyTo(fs);
                        fs.Flush(true);
                    }
                }

                var regConv = new MsixRegistryFileWriter(tempDir);
                var regPars = new RegFileParser();

                regPars.Parse(Path.Combine(tempReg));
                regConv.ImportRegFile(tempReg);
            }
            finally
            {
                ExceptionGuard.Guard(() =>
                {
                    Directory.Delete(tempDir, true);
                    File.Delete(tempReg);
                });
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Import the content of the .REG file and return the RegKeyEntry created from it
 /// </summary>
 /// <returns></returns>
 public RegKeyEntry Import()
 {
     if (Result == null)
     {
         Result = Parser.Parse(Content);
     }
     return(Result);
 }
        public void Import(string regFile)
        {
            var regParser  = new RegFileParser();
            var parsedKeys = regParser.Parse(regFile);

            foreach (var key in parsedKeys)
            {
                this.Add(key);
            }
        }
Exemplo n.º 4
0
        public void Convert()
        {
            var tempReg = System.Guid.NewGuid().ToString("N") + ".reg";
            var tempDir = "reg-out-" + System.Guid.NewGuid().ToString("N");

            Directory.CreateDirectory(tempDir);
            try
            {
                var mfn = typeof(TestConversion).Assembly.GetManifestResourceNames().First(a => a.EndsWith("team.reg"));
                using (var mf = typeof(TestConversion).Assembly.GetManifestResourceStream(mfn))
                {
                    using (var fs = System.IO.File.OpenWrite(tempReg))
                    {
                        // ReSharper disable once PossibleNullReferenceException
                        mf.CopyTo(fs);
                        fs.Flush(true);
                    }
                }

                var regConv = new RegConverter();
                var regPars = new RegFileParser();

                regPars.Parse(Path.Combine(tempReg));
                regConv.ConvertFromRegToDat(tempReg, Path.Combine(tempDir, "Registry.dat"), RegistryRoot.HKEY_LOCAL_MACHINE).GetAwaiter().GetResult();
                regConv.ConvertFromRegToDat(tempReg, Path.Combine(tempDir, "UserClasses.dat"), RegistryRoot.HKEY_CLASSES_ROOT).GetAwaiter().GetResult();
                regConv.ConvertFromRegToDat(tempReg, Path.Combine(tempDir, "User.dat"), RegistryRoot.HKEY_CURRENT_USER).GetAwaiter().GetResult();
            }
            finally
            {
                ExceptionGuard.Guard(() =>
                {
                    System.IO.Directory.Delete(tempDir, true);
                    System.IO.File.Delete(tempReg);
                });
            }
        }
Exemplo n.º 5
0
        public async Task ConvertFromRegToDat(string regFile, string file, RegistryRoot?root = null)
        {
            var regParser  = new RegFileParser();
            var parsedKeys = regParser.Parse(regFile);

            IEnumerable <RegistryEntry> parsedFilteredKeys;

            if (root == null)
            {
                parsedFilteredKeys = parsedKeys;
            }
            else
            {
                parsedFilteredKeys = parsedKeys.Where(r => r.Root == root.Value);
            }

            var reader = new RawReader();

            using (var hive = await reader.Create())
            {
                var mustSave = false;
                foreach (var item in parsedFilteredKeys)
                {
                    var key = PrepareRegistryKey(item);

                    mustSave = true;

                    var k = this.EnsureRegistryKey(hive.Root, key);

                    if (!string.IsNullOrEmpty(item.Name))
                    {
                        switch (item.Type)
                        {
                        case ValueType.Default:
                            break;

                        case ValueType.String:
                            k.SetValue(item.Name, this.Tokenize((string)item.Value));
                            break;

                        case ValueType.DWord:
                            var val = (long)Convert.ChangeType(item.Value, typeof(long));
                            if (val > int.MaxValue)
                            {
                                k.SetValue(item.Name, val);
                            }
                            else
                            {
                                k.SetValue(item.Name, (int)val);
                            }
                            break;

                        case ValueType.QWord:
                            k.SetValue(item.Name, (long)Convert.ChangeType(item.Value, typeof(long)));
                            break;

                        case ValueType.Multi:
                            k.SetValue(item.Name, this.Tokenize((string[])item.Value));
                            break;

                        case ValueType.Expandable:
                            k.SetValue(item.Name, this.Tokenize((string)item.Value));
                            break;

                        case ValueType.Binary:
                            k.SetValue(item.Name, (byte[])item.Value);
                            break;

                        case ValueType.DWordBigEndian:
                            k.SetValue(item.Name, (int)Convert.ChangeType(item.Value, typeof(int)));
                            break;
                        }
                    }
                }

                if (mustSave)
                {
                    await hive.Save(file);
                }
            }
        }