2021-03-02 00:35:16 +00:00
|
|
|
using System;
|
2021-07-07 04:14:10 +01:00
|
|
|
using System.Collections.Generic;
|
2021-03-05 16:36:51 +00:00
|
|
|
using System.IO;
|
2021-03-02 00:35:16 +00:00
|
|
|
using System.Linq;
|
2021-07-07 04:14:10 +01:00
|
|
|
using System.Text;
|
2021-03-02 00:35:16 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Aaru.Checksums;
|
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
2021-07-07 04:14:10 +01:00
|
|
|
using Aaru.Core;
|
|
|
|
|
using Aaru.Tests.Filesystems;
|
2021-03-02 00:35:16 +00:00
|
|
|
using FluentAssertions;
|
|
|
|
|
using FluentAssertions.Execution;
|
2021-07-07 04:14:10 +01:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Converters;
|
2021-03-02 00:35:16 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
namespace Aaru.Tests.Images
|
|
|
|
|
{
|
2021-03-02 02:59:20 +00:00
|
|
|
public abstract class OpticalMediaImageTest : BaseMediaImageTest
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2021-03-02 02:59:20 +00:00
|
|
|
const uint SECTORS_TO_READ = 256;
|
|
|
|
|
public abstract OpticalImageTestExpected[] Tests { get; }
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
[Test]
|
2021-03-02 02:59:20 +00:00
|
|
|
public void Info()
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2021-03-03 14:31:56 +00:00
|
|
|
Environment.CurrentDirectory = DataFolder;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
2021-03-02 02:59:20 +00:00
|
|
|
foreach(OpticalImageTestExpected test in Tests)
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2021-03-05 16:36:51 +00:00
|
|
|
string testFile = test.TestFile;
|
|
|
|
|
|
|
|
|
|
bool exists = File.Exists(testFile);
|
|
|
|
|
Assert.True(exists, $"{testFile} not found");
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It arrives here...
|
|
|
|
|
if(!exists)
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-03-02 00:35:16 +00:00
|
|
|
var filtersList = new FiltersList();
|
2021-03-02 02:59:20 +00:00
|
|
|
IFilter filter = filtersList.GetFilter(testFile);
|
|
|
|
|
filter.Open(testFile);
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
var image = Activator.CreateInstance(_plugin.GetType()) as IOpticalMediaImage;
|
2021-03-02 02:59:20 +00:00
|
|
|
Assert.NotNull(image, $"Could not instantiate filesystem for {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
bool opened = image.Open(filter);
|
2021-03-02 02:59:20 +00:00
|
|
|
Assert.AreEqual(true, opened, $"Open: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
if(!opened)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
using(new AssertionScope())
|
|
|
|
|
{
|
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
2021-03-02 02:59:20 +00:00
|
|
|
Assert.AreEqual(test.Sectors, image.Info.Sectors, $"Sectors: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2021-03-05 16:29:52 +00:00
|
|
|
if(test.SectorSize > 0)
|
2021-03-02 02:59:20 +00:00
|
|
|
Assert.AreEqual(test.SectorSize, image.Info.SectorSize, $"Sector size: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
2021-03-02 02:59:20 +00:00
|
|
|
Assert.AreEqual(test.MediaType, image.Info.MediaType, $"Media type: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
if(image.Info.XmlMediaType != XmlMediaType.OpticalDisc)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-03-05 16:30:25 +00:00
|
|
|
Assert.AreEqual(test.Tracks.Length, image.Tracks.Count, $"Tracks: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
image.Tracks.Select(t => t.TrackSession).Should().
|
2021-03-02 02:59:20 +00:00
|
|
|
BeEquivalentTo(test.Tracks.Select(s => s.Session), $"Track session: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
image.Tracks.Select(t => t.TrackStartSector).Should().
|
2021-03-02 02:59:20 +00:00
|
|
|
BeEquivalentTo(test.Tracks.Select(s => s.Start), $"Track start: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
image.Tracks.Select(t => t.TrackEndSector).Should().
|
2021-03-02 02:59:20 +00:00
|
|
|
BeEquivalentTo(test.Tracks.Select(s => s.End), $"Track end: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
image.Tracks.Select(t => t.TrackPregap).Should().
|
2021-03-02 02:59:20 +00:00
|
|
|
BeEquivalentTo(test.Tracks.Select(s => s.Pregap), $"Track pregap: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
int trackNo = 0;
|
|
|
|
|
|
2021-07-01 22:36:54 +01:00
|
|
|
byte?[] flags = new byte?[image.Tracks.Count];
|
|
|
|
|
ulong latestEndSector = 0;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
foreach(Track currentTrack in image.Tracks)
|
|
|
|
|
{
|
2021-07-01 22:36:54 +01:00
|
|
|
if(currentTrack.TrackEndSector > latestEndSector)
|
|
|
|
|
latestEndSector = currentTrack.TrackEndSector;
|
|
|
|
|
|
2021-03-02 00:35:16 +00:00
|
|
|
if(image.Info.ReadableSectorTags.Contains(SectorTagType.CdTrackFlags))
|
|
|
|
|
flags[trackNo] = image.ReadSectorTag(currentTrack.TrackSequence,
|
|
|
|
|
SectorTagType.CdTrackFlags)[0];
|
|
|
|
|
|
|
|
|
|
trackNo++;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 02:59:20 +00:00
|
|
|
flags.Should().BeEquivalentTo(test.Tracks.Select(s => s.Flags), $"Track flags: {testFile}");
|
2021-07-01 22:36:54 +01:00
|
|
|
|
|
|
|
|
Assert.AreEqual(latestEndSector, image.Info.Sectors - 1,
|
|
|
|
|
$"Last sector for tracks is {latestEndSector}, but it is {image.Info.Sectors} for image");
|
2021-03-02 00:35:16 +00:00
|
|
|
});
|
|
|
|
|
}
|
2021-07-09 09:50:41 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Contents()
|
|
|
|
|
{
|
|
|
|
|
Environment.CurrentDirectory = DataFolder;
|
|
|
|
|
|
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach(OpticalImageTestExpected test in Tests)
|
|
|
|
|
{
|
|
|
|
|
string testFile = test.TestFile;
|
|
|
|
|
|
|
|
|
|
bool exists = File.Exists(testFile);
|
|
|
|
|
Assert.True(exists, $"{testFile} not found");
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It arrives here...
|
|
|
|
|
if(!exists)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var filtersList = new FiltersList();
|
|
|
|
|
IFilter filter = filtersList.GetFilter(testFile);
|
|
|
|
|
filter.Open(testFile);
|
|
|
|
|
|
|
|
|
|
var image = Activator.CreateInstance(_plugin.GetType()) as IOpticalMediaImage;
|
|
|
|
|
Assert.NotNull(image, $"Could not instantiate filesystem for {testFile}");
|
|
|
|
|
|
|
|
|
|
bool opened = image.Open(filter);
|
|
|
|
|
Assert.AreEqual(true, opened, $"Open: {testFile}");
|
|
|
|
|
|
|
|
|
|
if(!opened)
|
|
|
|
|
continue;
|
2021-07-07 04:14:10 +01:00
|
|
|
|
|
|
|
|
using(new AssertionScope())
|
|
|
|
|
{
|
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach(TrackInfoTestExpected track in test.Tracks)
|
|
|
|
|
{
|
|
|
|
|
if(track.FileSystems is null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ulong trackStart = track.Start + track.Pregap;
|
|
|
|
|
|
|
|
|
|
if(track.Number == 1 &&
|
|
|
|
|
track.Pregap >= 150)
|
|
|
|
|
trackStart -= 150;
|
|
|
|
|
|
|
|
|
|
var partition = new Partition
|
|
|
|
|
{
|
|
|
|
|
Length = track.End - trackStart + 1,
|
|
|
|
|
Start = trackStart
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Core.Filesystems.Identify(image, out List<string> idPlugins, partition);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(track.FileSystems.Length, idPlugins.Count,
|
|
|
|
|
$"Expected {track.FileSystems.Length} filesystems in {testFile} but found {idPlugins.Count}");
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < track.FileSystems.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
PluginBase plugins = GetPluginBase.Instance;
|
|
|
|
|
bool found = plugins.PluginsList.TryGetValue(idPlugins[i], out IFilesystem plugin);
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It is not the case, it changes
|
|
|
|
|
if(!found)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var fs = Activator.CreateInstance(plugin.GetType()) as IFilesystem;
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(fs, $"Could not instantiate filesystem for {testFile}");
|
|
|
|
|
|
|
|
|
|
fs.GetInformation(image, partition, out _, null);
|
|
|
|
|
|
|
|
|
|
if(track.FileSystems[i].ApplicationId != null)
|
|
|
|
|
Assert.AreEqual(track.FileSystems[i].ApplicationId,
|
|
|
|
|
fs.XmlFsType.ApplicationIdentifier,
|
|
|
|
|
$"Application ID: {testFile}");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(track.FileSystems[i].Bootable, fs.XmlFsType.Bootable,
|
|
|
|
|
$"Bootable: {testFile}");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(track.FileSystems[i].Clusters, fs.XmlFsType.Clusters,
|
|
|
|
|
$"Clusters: {testFile}");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(track.FileSystems[i].ClusterSize, fs.XmlFsType.ClusterSize,
|
|
|
|
|
$"Cluster size: {testFile}");
|
|
|
|
|
|
|
|
|
|
if(track.FileSystems[i].SystemId != null)
|
|
|
|
|
Assert.AreEqual(track.FileSystems[i].SystemId, fs.XmlFsType.SystemIdentifier,
|
|
|
|
|
$"System ID: {testFile}");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(track.FileSystems[i].Type, fs.XmlFsType.Type,
|
|
|
|
|
$"Filesystem type: {testFile}");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(track.FileSystems[i].VolumeName, fs.XmlFsType.VolumeName,
|
|
|
|
|
$"Volume name: {testFile}");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(track.FileSystems[i].VolumeSerial, fs.XmlFsType.VolumeSerial,
|
|
|
|
|
$"Volume serial: {testFile}");
|
|
|
|
|
|
|
|
|
|
var rofs = Activator.CreateInstance(plugin.GetType()) as IReadOnlyFilesystem;
|
|
|
|
|
|
|
|
|
|
if(rofs == null)
|
|
|
|
|
{
|
|
|
|
|
if(track.FileSystems[i].Contents != null ||
|
|
|
|
|
track.FileSystems[i].ContentsJson != null ||
|
|
|
|
|
File.Exists($"{testFile}.track{track.Number}.filesystem{i}.contents.json"))
|
|
|
|
|
Assert.NotNull(rofs,
|
|
|
|
|
$"Could not instantiate filesystem for {testFile}, track {track.Number}, filesystem {i}");
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
track.FileSystems[i].Encoding ??= Encoding.ASCII;
|
|
|
|
|
|
|
|
|
|
Errno ret = rofs.Mount(image, partition, track.FileSystems[i].Encoding, null,
|
|
|
|
|
track.FileSystems[i].Namespace);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Errno.NoError, ret, $"Unmountable: {testFile}");
|
|
|
|
|
|
|
|
|
|
var serializer = new JsonSerializer
|
|
|
|
|
{
|
|
|
|
|
Formatting = Formatting.Indented,
|
|
|
|
|
MaxDepth = 16384,
|
|
|
|
|
NullValueHandling = NullValueHandling.Ignore
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
serializer.Converters.Add(new StringEnumConverter());
|
|
|
|
|
|
|
|
|
|
if(track.FileSystems[i].ContentsJson != null)
|
|
|
|
|
{
|
|
|
|
|
track.FileSystems[i].Contents =
|
|
|
|
|
serializer.
|
|
|
|
|
Deserialize<
|
|
|
|
|
Dictionary<string,
|
|
|
|
|
FileData>>(new JsonTextReader(new StringReader(track.
|
|
|
|
|
FileSystems[i].ContentsJson)));
|
|
|
|
|
}
|
|
|
|
|
else if(File.Exists($"{testFile}.track{track.Number}.filesystem{i}.contents.json"))
|
|
|
|
|
{
|
|
|
|
|
var sr =
|
|
|
|
|
new
|
|
|
|
|
StreamReader($"{testFile}.track{track.Number}.filesystem{i}.contents.json");
|
|
|
|
|
|
|
|
|
|
track.FileSystems[i].Contents =
|
|
|
|
|
serializer.
|
|
|
|
|
Deserialize<Dictionary<string, FileData>>(new JsonTextReader(sr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(track.FileSystems[i].Contents is null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ReadOnlyFilesystemTest.TestDirectory(rofs, "/", track.FileSystems[i].Contents,
|
|
|
|
|
testFile, false);
|
|
|
|
|
|
2021-07-09 09:50:41 +01:00
|
|
|
// Uncomment to generate JSON file
|
|
|
|
|
/* var contents = ReadOnlyFilesystemTest.BuildDirectory(rofs, "/");
|
|
|
|
|
|
|
|
|
|
var sw = new StreamWriter($"{testFile}.track{track.Number}.filesystem{i}.contents.json");
|
|
|
|
|
serializer.Serialize(sw, contents);
|
|
|
|
|
sw.Close();*/
|
2021-07-07 04:14:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2021-03-02 02:59:20 +00:00
|
|
|
public void Hashes()
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2021-03-03 14:31:56 +00:00
|
|
|
Environment.CurrentDirectory = Environment.CurrentDirectory = DataFolder;
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
2021-03-02 02:59:20 +00:00
|
|
|
Parallel.For(0L, Tests.Length, (i, state) =>
|
2021-03-02 00:35:16 +00:00
|
|
|
{
|
2021-03-05 16:36:51 +00:00
|
|
|
string testFile = Tests[i].TestFile;
|
|
|
|
|
|
|
|
|
|
bool exists = File.Exists(testFile);
|
|
|
|
|
Assert.True(exists, $"{testFile} not found");
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
|
|
|
|
// It arrives here...
|
|
|
|
|
if(!exists)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-03-02 00:35:16 +00:00
|
|
|
var filtersList = new FiltersList();
|
2021-03-02 02:59:20 +00:00
|
|
|
IFilter filter = filtersList.GetFilter(testFile);
|
|
|
|
|
filter.Open(testFile);
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
var image = Activator.CreateInstance(_plugin.GetType()) as IOpticalMediaImage;
|
2021-03-02 02:59:20 +00:00
|
|
|
Assert.NotNull(image, $"Could not instantiate filesystem for {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
bool opened = image.Open(filter);
|
2021-03-02 02:59:20 +00:00
|
|
|
Assert.AreEqual(true, opened, $"Open: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
|
|
|
|
|
if(!opened)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Md5Context ctx;
|
|
|
|
|
|
|
|
|
|
if(image.Info.XmlMediaType == XmlMediaType.OpticalDisc)
|
|
|
|
|
{
|
|
|
|
|
foreach(bool @long in new[]
|
|
|
|
|
{
|
|
|
|
|
false, true
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
ctx = new Md5Context();
|
|
|
|
|
|
|
|
|
|
foreach(Track currentTrack in image.Tracks)
|
|
|
|
|
{
|
|
|
|
|
ulong sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1;
|
|
|
|
|
ulong doneSectors = 0;
|
|
|
|
|
|
|
|
|
|
while(doneSectors < sectors)
|
|
|
|
|
{
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
|
|
|
if(sectors - doneSectors >= SECTORS_TO_READ)
|
|
|
|
|
{
|
|
|
|
|
sector =
|
|
|
|
|
@long ? image.ReadSectorsLong(doneSectors, SECTORS_TO_READ,
|
|
|
|
|
currentTrack.TrackSequence)
|
|
|
|
|
: image.ReadSectors(doneSectors, SECTORS_TO_READ,
|
|
|
|
|
currentTrack.TrackSequence);
|
|
|
|
|
|
|
|
|
|
doneSectors += SECTORS_TO_READ;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sector =
|
|
|
|
|
@long ? image.ReadSectorsLong(doneSectors, (uint)(sectors - doneSectors),
|
|
|
|
|
currentTrack.TrackSequence)
|
|
|
|
|
: image.ReadSectors(doneSectors, (uint)(sectors - doneSectors),
|
|
|
|
|
currentTrack.TrackSequence);
|
|
|
|
|
|
|
|
|
|
doneSectors += sectors - doneSectors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.Update(sector);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 02:59:20 +00:00
|
|
|
Assert.AreEqual(@long ? Tests[i].LongMD5 : Tests[i].MD5, ctx.End(),
|
|
|
|
|
$"{(@long ? "Long hash" : "Hash")}: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!image.Info.ReadableSectorTags.Contains(SectorTagType.CdSectorSubchannel))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ctx = new Md5Context();
|
|
|
|
|
|
|
|
|
|
foreach(Track currentTrack in image.Tracks)
|
|
|
|
|
{
|
|
|
|
|
ulong sectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1;
|
|
|
|
|
ulong doneSectors = 0;
|
|
|
|
|
|
|
|
|
|
while(doneSectors < sectors)
|
|
|
|
|
{
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
|
|
|
if(sectors - doneSectors >= SECTORS_TO_READ)
|
|
|
|
|
{
|
|
|
|
|
sector = image.ReadSectorsTag(doneSectors, SECTORS_TO_READ,
|
|
|
|
|
currentTrack.TrackSequence,
|
|
|
|
|
SectorTagType.CdSectorSubchannel);
|
|
|
|
|
|
|
|
|
|
doneSectors += SECTORS_TO_READ;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sector = image.ReadSectorsTag(doneSectors, (uint)(sectors - doneSectors),
|
|
|
|
|
currentTrack.TrackSequence,
|
|
|
|
|
SectorTagType.CdSectorSubchannel);
|
|
|
|
|
|
|
|
|
|
doneSectors += sectors - doneSectors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.Update(sector);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 02:59:20 +00:00
|
|
|
Assert.AreEqual(Tests[i].SubchannelMD5, ctx.End(), $"Subchannel hash: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ctx = new Md5Context();
|
|
|
|
|
ulong doneSectors = 0;
|
|
|
|
|
|
|
|
|
|
while(doneSectors < image.Info.Sectors)
|
|
|
|
|
{
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
|
|
|
if(image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
|
|
|
|
|
{
|
|
|
|
|
sector = image.ReadSectors(doneSectors, SECTORS_TO_READ);
|
|
|
|
|
doneSectors += SECTORS_TO_READ;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sector = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
|
|
|
|
|
doneSectors += image.Info.Sectors - doneSectors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.Update(sector);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 02:59:20 +00:00
|
|
|
Assert.AreEqual(Tests[i].MD5, ctx.End(), $"Hash: {testFile}");
|
2021-03-02 00:35:16 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|