示例#1
0
        private void ComapreCdromImagesMenuItem_Click(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog();

            var firstFile = string.Empty;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                firstFile = dialog.FileName;
            }

            var secondFile = string.Empty;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                secondFile = dialog.FileName;
            }

            var        cdromReader = new BinImageReader();
            CdromImage cdrom1      = cdromReader.ReadImage(firstFile);
            CdromImage cdrom2      = cdromReader.ReadImage(secondFile);

            var comparer = new CdromImageComparer();
            List <CdromSectorComparisonResult> result = Task.Run(() => comparer.Compare(cdrom1, cdrom2)).Result;

            var failed = result.Where(e => e.Equal == false).ToList();
        }
        public static void IsoToBin(string isofile, string binfile)
        {
            var        isoReader = new IsoImageReader();
            CdromImage cdrom     = isoReader.ReadImage(isofile);
            var        binWriter = new BinImageWriter();

            binWriter.WriteImage(cdrom, binfile);
        }
        public static void BinToiso(string binfile, string isofile)
        {
            var        binReader = new BinImageReader();
            CdromImage cdrom     = binReader.ReadImage(binfile);
            var        isoWriter = new IsoImageWriter();

            isoWriter.WriteImage(cdrom, isofile);
        }
示例#4
0
        // TODO: expand comparer to use CompareFlags flags
        public async Task <List <CdromSectorComparisonResult> > Compare(CdromImage image1, CdromImage image2)
        {
            var result = new List <CdromSectorComparisonResult>();

            var sectorMax = Math.Max(image1.Sectors.Count, image2.Sectors.Count);

            for (var i = 0; i < sectorMax; i++)
            {
                if (i >= image1.Sectors.Count)
                {
                    result.Add(new CdromSectorComparisonResult
                    {
                        SectorPhysicalAddress = i,
                        Message = "Sectors is missing in first image",
                        Equal   = false
                    });

                    continue;
                }

                if (i >= image2.Sectors.Count)
                {
                    result.Add(new CdromSectorComparisonResult
                    {
                        SectorPhysicalAddress = i,
                        Message = "Sectors is missing in second image",
                        Equal   = false
                    });

                    continue;
                }

                if (await BinaryComparer.Compare(image1.Sectors[i].Data, 0, image2.Sectors[i].Data, 0, CdromConstants.SectorDataSize))
                {
                    result.Add(new CdromSectorComparisonResult
                    {
                        SectorPhysicalAddress = i,
                        Message = "Sectors are equal",
                        Equal   = true
                    });
                }
                else
                {
                    result.Add(new CdromSectorComparisonResult
                    {
                        SectorPhysicalAddress = i,
                        Message = "Sectors are not equal",
                        Equal   = false
                    });
                }
            }

            return(result);
        }
        public CdromImage ReadImage(string filename)
        {
            byte[]   buffer;
            FileInfo fileinfo;

            try
            {
                fileinfo = new FileInfo(filename);
                if (fileinfo.Length % 2352 != 0)
                {
                    throw new IOException($"File size of {filename} does not match.");
                }
            }
            catch (Exception exception)
            {
                throw new IOException($"Unable to read file {filename}", exception);
            }

            try
            {
                buffer           = new byte[fileinfo.Length];
                using var stream = new FileStream(filename, FileMode.Open, FileAccess.Read);
                using var reader = new BinaryReader(stream);
                if (reader.Read(buffer, 0, (int)fileinfo.Length) != fileinfo.Length)
                {
                    throw new IOException($"Unable to read whole {filename} file.");
                }
                ;
            }
            catch (Exception exception)
            {
                throw new IOException($"Unable to read file {filename}", exception);
            }

            var cdrom = new CdromImage();

            for (var i = 0; i < buffer.Length / 2352; i++)
            {
                var sector = new CdromSector
                {
                    PhysicalAddress = i,
                    Mode            = CdromSectorMode.Mode1
                };

                Buffer.BlockCopy(buffer, i * 2352, sector.Data, 0, 2352);
                cdrom.Sectors.Add(sector);
            }

            return(cdrom);
        }
示例#6
0
 public void WriteImageInfo(CdromImage cdromImage, string filename)
 {
     try
     {
         using var stream = new FileStream(filename, FileMode.Create, FileAccess.Write);
         using var writer = new StreamWriter(stream);
         foreach (CdromSector sector in cdromImage.Sectors)
         {
             writer.WriteLine($"{sector.GetAddress()}");
         }
     }
     catch
     {
     }
 }
示例#7
0
        public void AnalyzeFolder(string foldername)
        {
            foreach (var filename in GetSupportedFiles(foldername))
            {
                IImageReader reader = ImageReaderFactory.CreateReader(filename);
                CdromImage   image  = reader.ReadImage(filename);
                WriteImageInfo(image, filename + ".txt");
                _cdromImages.Add(filename, image);
            }

            var writer = new BinImageWriter();

            foreach (var filename in _cdromImages.Keys)
            {
                writer.WriteImage(_cdromImages[filename], filename + ".new");
            }
        }
示例#8
0
 public void WriteImage(CdromImage cdromImage, string filename)
 {
     try
     {
         using var stream = new FileStream(filename, FileMode.Create, FileAccess.Write);
         using var writer = new BinaryWriter(stream);
         foreach (CdromSector sector in cdromImage.Sectors)
         {
             writer.Write(sector.Data, 0, CdromConstants.SectorDataSize);
         }
     }
     catch (Exception exception)
     {
         // TODO logging
         Console.WriteLine(exception.Message);
     }
 }
示例#9
0
        public IEnumerable <string> ValidateImage(CdromImage cdromImage)
        {
            var result = new List <string>();

            foreach (CdromSector sector in cdromImage.Sectors)
            {
                if (sector.Data[0x15] == (byte)CdromSectorMode.Mode1)
                {
                    var edc = ErrorCorrectionModel.CalculateEdc(sector.Data, 0, 0x810);
                    if (edc != sector.GetEdc())
                    {
                        result.Add("error");
                    }
                }
            }

            return(result);
        }