Exemplo n.º 1
0
 public static RegDiff ReadFromHive(RegistryHive Input)
 {
     var Out = new RegDiff();
     var Root = Input.Root;
     foreach (var name in Root.GetValueNames())
     {
         Out.Data[String.Empty][name] = new ValueObject(Root.GetValueType(name), Root.GetValue(name));
     }
     foreach (var sub in Root.GetSubKeyNames())
     {
         InnerRead(Root.OpenSubKey(sub), Out.Data);
     }
     return Out;
 }
Exemplo n.º 2
0
        //        private static WellKnownPartitionType GetPartitionType(PartitionInfo Partition)
        //        {
        //            switch (Partition.BiosType)
        //            {
        //                case BiosPartitionTypes.Fat16:
        //                case BiosPartitionTypes.Fat32:
        //                case BiosPartitionTypes.Fat32Lba:
        //                    return WellKnownPartitionType.WindowsFat;
        //                case BiosPartitionTypes.Ntfs:
        //                    return WellKnownPartitionType.WindowsNtfs;
        //                case BiosPartitionTypes.LinuxNative:
        //                    return WellKnownPartitionType.Linux;
        //                case BiosPartitionTypes.LinuxSwap:
        //                    return WellKnownPartitionType.LinuxSwap;
        //                case BiosPartitionTypes.LinuxLvm:
        //                    return WellKnownPartitionType.LinuxLvm;
        //                default:
        //                    throw new ArgumentException(
        //                        String.Format("Unsupported partition type: '{0}'", BiosPartitionTypes.ToString(Partition.BiosType)), "Partition");
        //            }
        //        }
        //
        //        private static DiscFileSystem DetectFileSystem(PartitionInfo Partition)
        //        {
        //            using (var stream = Partition.Open())
        //            {
        //                if (NtfsFileSystem.Detect(stream))
        //                    return new NtfsFileSystem(Partition.Open());
        //                stream.Seek(0, SeekOrigin.Begin);
        //                if (FatFileSystem.Detect(stream))
        //                    return new FatFileSystem(Partition.Open());
        //
        //                /* Ext2/3/4 file system - when Ext becomes fully writable
        //                
        //                stream.Seek(0, SeekOrigin.Begin);
        //                if (ExtFileSystem.Detect(stream))
        //                    return new ExtFileSystem(Partition.Open());
        //                */
        //
        //                return null;
        //            }
        //        }
        private static void DiffPart(DiscFileSystem PartA, DiscFileSystem PartB, DiscFileSystem Output, ComparisonStyle Style = ComparisonStyle.DateTimeOnly, CopyQueue WriteQueue = null)
        {
            if (PartA == null) throw new ArgumentNullException("PartA");
            if (PartB == null) throw new ArgumentNullException("PartB");
            if (Output == null) throw new ArgumentNullException("Output");

            if (PartA is NtfsFileSystem)
            {
                ((NtfsFileSystem) PartA).NtfsOptions.HideHiddenFiles = false;
                ((NtfsFileSystem) PartA).NtfsOptions.HideSystemFiles = false;
            }
            if (PartB is NtfsFileSystem)
            {
                ((NtfsFileSystem) PartB).NtfsOptions.HideHiddenFiles = false;
                ((NtfsFileSystem) PartB).NtfsOptions.HideSystemFiles = false;
            }
            if (Output is NtfsFileSystem)
            {
                ((NtfsFileSystem) Output).NtfsOptions.HideHiddenFiles = false;
                ((NtfsFileSystem) Output).NtfsOptions.HideSystemFiles = false;
            }

            if (WriteQueue == null) WriteQueue = new CopyQueue();

            var RootA = PartA.Root;
            var RootB = PartB.Root;
            var OutRoot = Output.Root;
            var OutFileRoot = Output.GetDirectoryInfo(RootFiles);
            if (!OutFileRoot.Exists) OutFileRoot.Create();

            CompareTree(RootA, RootB, OutFileRoot, WriteQueue, Style);

            WriteQueue.Go();

            // Now handle registry files (if any)
            ParallelQuery<DiscFileInfo> Ofiles;
            lock(OutFileRoot.FileSystem)
                Ofiles = OutFileRoot.GetFiles("*.*", SearchOption.AllDirectories).AsParallel();
            Ofiles = Ofiles.Where(dfi =>
                                    SystemRegistryFiles.Contains(dfi.FullName, StringComparer.CurrentCultureIgnoreCase));

            foreach (var file in Ofiles)
            {
                var A = PartA.GetFileInfo(file.FullName.Substring(RootFiles.Length + 1));
                if (!A.Exists)
                {
                    file.FileSystem.MoveFile(file.FullName, String.Concat(RootSystemRegistry, A.FullName));
                    continue;
                }
                //else
                MemoryStream SideA = new MemoryStream();
                using (var tmp = A.OpenRead()) tmp.CopyTo(SideA);
                MemoryStream SideB = new MemoryStream();
                using (var tmp = file.OpenRead()) tmp.CopyTo(SideB);
                var comp = new RegistryComparison(SideA, SideB, RegistryComparison.Side.B);
                comp.DoCompare();
                var diff = new RegDiff(comp, RegistryComparison.Side.B);
                var outFile = Output.GetFileInfo(Path.Combine(RootSystemRegistry, file.FullName));
                if (!outFile.Directory.Exists)
                {
                    outFile.Directory.Create();
                }
                using (var OUT = outFile.Open(outFile.Exists ? FileMode.Truncate : FileMode.CreateNew, FileAccess.ReadWrite))
                    diff.WriteToStream(OUT);
                file.Delete(); // remove this file from the set of file to copy and overwrite
            }

            lock (OutFileRoot.FileSystem)
                Ofiles = OutFileRoot.GetFiles("*.*", SearchOption.AllDirectories).AsParallel();
            Ofiles = Ofiles.Where(dfi => UserRegisrtyFiles.IsMatch(dfi.FullName));

            foreach (var file in Ofiles)
            {
                var match = UserRegisrtyFiles.Match(file.FullName);
                var A = PartA.GetFileInfo(file.FullName.Substring(RootFiles.Length + 1));
                if (!A.Exists)
                {
                    file.FileSystem.MoveFile(file.FullName,
                                                Path.Combine(RootUserRegistry, match.Groups["user"].Value, A.Name));
                    continue;
                }
                //else
                MemoryStream SideA = new MemoryStream();
                using (var tmp = A.OpenRead()) tmp.CopyTo(SideA);
                MemoryStream SideB = new MemoryStream();
                using (var tmp = file.OpenRead()) tmp.CopyTo(SideB);
                var comp = new RegistryComparison(SideA, SideB, RegistryComparison.Side.B);
                comp.DoCompare();
                var diff = new RegDiff(comp, RegistryComparison.Side.B);
                var outFile =
                    Output.GetFileInfo(Path.Combine(RootUserRegistry, match.Groups["user"].Value, file.FullName));
                if (!outFile.Directory.Exists)
                {
                    outFile.Directory.Create();
                }
                using (var OUT = outFile.Open(outFile.Exists ? FileMode.Truncate : FileMode.CreateNew, FileAccess.ReadWrite))
                    diff.WriteToStream(OUT);
                file.Delete(); // remove this file from the set of file to copy and overwrite
            }
        }