public void TruncatedValue() { var reader = new RegFileReader(Resources.TruncatedValue); Assert.IsTrue(reader.Read()); reader.Read(); }
public void InvalidKind() { var reader = new RegFileReader(Resources.InvalidKind); Assert.IsTrue(reader.Read()); reader.Read(); }
public void Create_emptyFile_zeroKeys() { var stream = new MemoryStream(); var reader = new RegFileReader(stream); Assert.AreEqual(0, reader.RegValues.Count); }
/// <summary> /// 对比 Reg 文件和注册表,判断是否存在不同,如果不同就说明需要优化。 /// </summary> public bool NeedOptimize() { var reader = new RegFileReader(content); var expected = true; while (expected && reader.Read()) { if (reader.IsKey) { var exists = RegHelper.KeyExists(reader.Key); expected = reader.IsDelete ^ exists; } else if (reader.IsDelete) { expected = Registry.GetValue(reader.Key, reader.Name, null) == null; } else { expected = CheckValueInDB(reader.Key, reader.Name, reader.Value, reader.Kind); } } return(!expected); }
public void ReadKey() { var reader = new RegFileReader(Resources.ImportTest); Assert.IsTrue(reader.Read()); Assert.IsTrue(reader.IsKey); Assert.AreEqual(@"HKEY_CURRENT_USER\_Test_Import\Key", reader.Key); }
public void Create_regedit5WithOneKey_OK() { var stream = stringToStream( @"Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\MyKey]", Encoding.UTF8); var reader = new RegFileReader(stream); Assert.AreEqual(1, reader.RegValues.Count); Assert.IsTrue(reader.RegValues.ContainsKey(@"HKEY_LOCAL_MACHINE\SOFTWARE\MyKey")); }
public void Multipart() { var reader = new RegFileReader(Resources.ValueParts); Assert.IsTrue(reader.Read()); Assert.IsTrue(reader.Read()); var expected = new string[] { "Str0", "Str1" }; CollectionAssert.AreEqual(expected, (string[])reader.Value); }
public bool Read() { var t = new RegFileReader(content); var avoidElimination = false; while (t.Read()) { avoidElimination = t.IsKey; } return(avoidElimination); }
public void Create_oneKeyWithOneValue_OK() { var text = @"Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\MyKey] " + "\"MyValue\"=\"_RegFreeComRotClass\""; var stream = stringToStream(text,Encoding.UTF8); var reader = new RegFileReader(stream); var key = reader.RegValues[@"HKEY_LOCAL_MACHINE\SOFTWARE\MyKey"]; Assert.IsNotNull(key); Assert.IsTrue(key.ContainsKey("MyValue")); }
public void Create_oneKeyWithOneValue_OK() { var text = @"Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\MyKey] " + "\"MyValue\"=\"_RegFreeComRotClass\""; var stream = stringToStream(text, Encoding.UTF8); var reader = new RegFileReader(stream); var key = reader.RegValues[@"HKEY_LOCAL_MACHINE\SOFTWARE\MyKey"]; Assert.IsNotNull(key); Assert.IsTrue(key.ContainsKey("MyValue")); }
static void Main(string[] args) { Console.WriteLine("Registry File Parser"); if (args.Length == 0) { Console.WriteLine("Missing paramter(s)."); Console.WriteLine("Syntax:"); Console.WriteLine("RegFileParser <reg file path> [<output file path>]"); Console.WriteLine(); //Wait for ENTER key to close program Console.WriteLine("Press 'ENTER' to exit program."); Console.ReadLine(); return; } if (!File.Exists(args[0])) { Console.WriteLine("File '{0}' not found.", args[0]); //Wait for ENTER key to close program Console.WriteLine("Press 'ENTER' to exit program."); Console.ReadLine(); return; } if (args.Length == 0) { outputPath = args[1]; } try { var file = new FileStream(args[0], FileMode.Open); var regfile = new RegFileReader(file); Console.WriteLine("Reg file has been imported."); //For proofing purpose generate new txt file with imported content Int32 count = 0; var sb = new StringBuilder(); foreach (KeyValuePair <String, Dictionary <String, RegValueObject> > entry in regfile.RegValues) { sb.AppendLine(String.Format(@"[{0}]", entry.Key)); foreach (KeyValuePair <String, RegValueObject> item in entry.Value) { if (String.IsNullOrEmpty(item.Value.Entry)) { sb.Append("@="); } else { sb.AppendFormat("\"{0}\"=", item.Value.Entry); } if (item.Value.Type == "REG_SZ") { sb.AppendLine(String.Format("\"{0}\"", item.Value.Value)); } else { sb.AppendLine(String.Format("[{0}] {1}", item.Value.Type, item.Value.Value)); } count++; } sb.AppendLine(); } File.WriteAllText(outputPath, sb.ToString()); Console.WriteLine("Content file generated as '{0}'", outputPath); Console.WriteLine("Reg file contains {0} keys and {1} values.", regfile.RegValues.Count, count); } catch (Exception ex) { Console.WriteLine("Exception thrown\n{0}", ex); } //Wait for ENTER key to close program Console.WriteLine("Press 'ENTER' to exit program."); Console.ReadLine(); }
public void Create_emptyFile_zeroKeys() { var stream = new MemoryStream(); var reader = new RegFileReader(stream); Assert.AreEqual(0,reader.RegValues.Count); }