🐛Move checksum initializers to instance constructors.

This commit is contained in:
2018-02-03 17:39:49 +00:00
parent 4b4671b4ef
commit b50b6c29ca
61 changed files with 1429 additions and 1599 deletions

View File

@@ -44,16 +44,16 @@ namespace DiscImageChef.Filesystems
{
public class AmigaDOSPlugin : IFilesystem
{
const uint FFS_MASK = 0x444F5300;
const uint FFS_MASK = 0x444F5300;
const uint MUFS_MASK = 0x6D754600;
const uint TYPE_HEADER = 2;
const uint TYPE_HEADER = 2;
const uint SUBTYPE_ROOT = 1;
public FileSystemType XmlFsType { get; private set; }
public string Name => "Amiga DOS filesystem";
public Guid Id => new Guid("3c882400-208c-427d-a086-9119852a1bc7");
public Encoding Encoding { get; private set; }
public string Name => "Amiga DOS filesystem";
public Guid Id => new Guid("3c882400-208c-427d-a086-9119852a1bc7");
public Encoding Encoding { get; private set; }
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
@@ -67,15 +67,15 @@ namespace DiscImageChef.Filesystems
// However while you can set a block size different from the sector size on formatting, the bootblock block
// size for floppies is the sector size, and for RDB is usually is the hard disk sector size,
// so this is not entirely wrong...
byte[] sector = imagePlugin.ReadSectors(0 + partition.Start, 2);
BootBlock bblk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(sector);
byte[] sector = imagePlugin.ReadSectors(0 + partition.Start, 2);
BootBlock bblk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(sector);
// AROS boot floppies...
if(sector.Length >= 512 && sector[510] == 0x55 && sector[511] == 0xAA &&
if(sector.Length >= 512 && sector[510] == 0x55 && sector[511] == 0xAA &&
(bblk.diskType & FFS_MASK) != FFS_MASK && (bblk.diskType & MUFS_MASK) != MUFS_MASK)
{
sector = imagePlugin.ReadSectors(1 + partition.Start, 2);
bblk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(sector);
bblk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(sector);
}
// Not FFS or MuFS?
@@ -86,7 +86,7 @@ namespace DiscImageChef.Filesystems
uint bsum = AmigaBootChecksum(sector);
DicConsole.DebugWriteLine("AmigaDOS plugin", "bblk.checksum = 0x{0:X8}", bblk.checksum);
DicConsole.DebugWriteLine("AmigaDOS plugin", "bsum = 0x{0:X8}", bsum);
DicConsole.DebugWriteLine("AmigaDOS plugin", "bsum = 0x{0:X8}", bsum);
ulong bRootPtr = 0;
@@ -99,10 +99,10 @@ namespace DiscImageChef.Filesystems
ulong[] rootPtrs =
{
bRootPtr + partition.Start, (partition.End - partition.Start + 1) / 2 + partition.Start - 2,
(partition.End - partition.Start + 1) / 2 + partition.Start - 1,
(partition.End - partition.Start + 1) / 2 + partition.Start,
(partition.End - partition.Start + 1) / 2 + partition.Start + 4
bRootPtr + partition.Start, (partition.End - partition.Start + 1) / 2 + partition.Start - 2,
(partition.End - partition.Start + 1) / 2 + partition.Start - 1,
(partition.End - partition.Start + 1) / 2 + partition.Start,
(partition.End - partition.Start + 1) / 2 + partition.Start + 4
};
RootBlock rblk = new RootBlock();
@@ -122,10 +122,10 @@ namespace DiscImageChef.Filesystems
DicConsole.DebugWriteLine("AmigaDOS plugin", "rblk.hashTableSize = {0}", rblk.hashTableSize);
uint blockSize = (rblk.hashTableSize + 56) * 4;
uint sectorsPerBlock = (uint)(blockSize / sector.Length);
uint blockSize = (rblk.hashTableSize + 56) * 4;
uint sectorsPerBlock = (uint)(blockSize / sector.Length);
DicConsole.DebugWriteLine("AmigaDOS plugin", "blockSize = {0}", blockSize);
DicConsole.DebugWriteLine("AmigaDOS plugin", "blockSize = {0}", blockSize);
DicConsole.DebugWriteLine("AmigaDOS plugin", "sectorsPerBlock = {0}", sectorsPerBlock);
if(blockSize % sector.Length > 0) sectorsPerBlock++;
@@ -136,11 +136,11 @@ namespace DiscImageChef.Filesystems
// Clear checksum on sector
rblk.checksum = BigEndianBitConverter.ToUInt32(sector, 20);
sector[20] = sector[21] = sector[22] = sector[23] = 0;
uint rsum = AmigaChecksum(sector);
sector[20] = sector[21] = sector[22] = sector[23] = 0;
uint rsum = AmigaChecksum(sector);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rblk.checksum = 0x{0:X8}", rblk.checksum);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rsum = 0x{0:X8}", rsum);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rsum = 0x{0:X8}", rsum);
rblk.sec_type = BigEndianBitConverter.ToUInt32(sector, sector.Length - 4);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rblk.sec_type = {0}", rblk.sec_type);
@@ -152,21 +152,21 @@ namespace DiscImageChef.Filesystems
}
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
Encoding encoding)
Encoding encoding)
{
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-1");
StringBuilder sbInformation = new StringBuilder();
XmlFsType = new FileSystemType();
information = null;
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-1");
StringBuilder sbInformation = new StringBuilder();
XmlFsType = new FileSystemType();
information = null;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
byte[] bootBlockSectors = imagePlugin.ReadSectors(0 + partition.Start, 2);
BootBlock bootBlk = BigEndianMarshal.ByteArrayToStructureBigEndian<BootBlock>(bootBlockSectors);
bootBlk.bootCode = new byte[bootBlockSectors.Length - 12];
bootBlk.bootCode = new byte[bootBlockSectors.Length - 12];
Array.Copy(bootBlockSectors, 12, bootBlk.bootCode, 0, bootBlk.bootCode.Length);
bootBlockSectors[4] = bootBlockSectors[5] = bootBlockSectors[6] = bootBlockSectors[7] = 0;
uint bsum = AmigaBootChecksum(bootBlockSectors);
uint bsum = AmigaBootChecksum(bootBlockSectors);
ulong bRootPtr = 0;
@@ -179,14 +179,14 @@ namespace DiscImageChef.Filesystems
ulong[] rootPtrs =
{
bRootPtr + partition.Start, (partition.End - partition.Start + 1) / 2 + partition.Start - 2,
(partition.End - partition.Start + 1) / 2 + partition.Start - 1,
(partition.End - partition.Start + 1) / 2 + partition.Start,
(partition.End - partition.Start + 1) / 2 + partition.Start + 4
bRootPtr + partition.Start, (partition.End - partition.Start + 1) / 2 + partition.Start - 2,
(partition.End - partition.Start + 1) / 2 + partition.Start - 1,
(partition.End - partition.Start + 1) / 2 + partition.Start,
(partition.End - partition.Start + 1) / 2 + partition.Start + 4
};
RootBlock rootBlk = new RootBlock();
byte[] rootBlockSector = null;
RootBlock rootBlk = new RootBlock();
byte[] rootBlockSector = null;
bool rootFound = false;
uint blockSize = 0;
@@ -206,10 +206,10 @@ namespace DiscImageChef.Filesystems
DicConsole.DebugWriteLine("AmigaDOS plugin", "rootBlk.hashTableSize = {0}", rootBlk.hashTableSize);
blockSize = (rootBlk.hashTableSize + 56) * 4;
uint sectorsPerBlock = (uint)(blockSize / rootBlockSector.Length);
blockSize = (rootBlk.hashTableSize + 56) * 4;
uint sectorsPerBlock = (uint)(blockSize / rootBlockSector.Length);
DicConsole.DebugWriteLine("AmigaDOS plugin", "blockSize = {0}", blockSize);
DicConsole.DebugWriteLine("AmigaDOS plugin", "blockSize = {0}", blockSize);
DicConsole.DebugWriteLine("AmigaDOS plugin", "sectorsPerBlock = {0}", sectorsPerBlock);
if(blockSize % rootBlockSector.Length > 0) sectorsPerBlock++;
@@ -219,12 +219,12 @@ namespace DiscImageChef.Filesystems
rootBlockSector = imagePlugin.ReadSectors(rootPtr, sectorsPerBlock);
// Clear checksum on sector
rootBlk.checksum = BigEndianBitConverter.ToUInt32(rootBlockSector, 20);
rootBlk.checksum = BigEndianBitConverter.ToUInt32(rootBlockSector, 20);
rootBlockSector[20] = rootBlockSector[21] = rootBlockSector[22] = rootBlockSector[23] = 0;
uint rsum = AmigaChecksum(rootBlockSector);
uint rsum = AmigaChecksum(rootBlockSector);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rootBlk.checksum = 0x{0:X8}", rootBlk.checksum);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rsum = 0x{0:X8}", rsum);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rsum = 0x{0:X8}", rsum);
rootBlk.sec_type = BigEndianBitConverter.ToUInt32(rootBlockSector, rootBlockSector.Length - 4);
DicConsole.DebugWriteLine("AmigaDOS plugin", "rootBlk.sec_type = {0}", rootBlk.sec_type);
@@ -232,7 +232,7 @@ namespace DiscImageChef.Filesystems
if(rootBlk.sec_type != SUBTYPE_ROOT || rootBlk.checksum != rsum) continue;
rootBlockSector = imagePlugin.ReadSectors(rootPtr, sectorsPerBlock);
rootFound = true;
rootFound = true;
break;
}
@@ -287,7 +287,6 @@ namespace DiscImageChef.Filesystems
if(bootBlk.checksum == bsum)
{
Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
sha1Ctx.Update(bootBlk.bootCode);
sbInformation.AppendLine("Volume is bootable");
sbInformation.AppendFormat("Boot code SHA1 is {0}", sha1Ctx.End()).AppendLine();
@@ -304,7 +303,7 @@ namespace DiscImageChef.Filesystems
long blocks = (long)((partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / blockSize);
sbInformation.AppendFormat("Volume block size is {0} bytes", blockSize).AppendLine();
sbInformation.AppendFormat("Volume has {0} blocks", blocks).AppendLine();
sbInformation.AppendFormat("Volume has {0} blocks", blocks).AppendLine();
sbInformation.AppendFormat("Volume created on {0}",
DateHandlers.AmigaToDateTime(rootBlk.cDays, rootBlk.cMins, rootBlk.cTicks))
.AppendLine();
@@ -317,15 +316,17 @@ namespace DiscImageChef.Filesystems
sbInformation.AppendFormat("Root block checksum is 0x{0:X8}", rootBlk.checksum).AppendLine();
information = sbInformation.ToString();
XmlFsType.CreationDate = DateHandlers.AmigaToDateTime(rootBlk.cDays, rootBlk.cMins, rootBlk.cTicks);
XmlFsType.CreationDate =
DateHandlers.AmigaToDateTime(rootBlk.cDays, rootBlk.cMins, rootBlk.cTicks);
XmlFsType.CreationDateSpecified = true;
XmlFsType.ModificationDate = DateHandlers.AmigaToDateTime(rootBlk.vDays, rootBlk.vMins, rootBlk.vTicks);
XmlFsType.ModificationDate =
DateHandlers.AmigaToDateTime(rootBlk.vDays, rootBlk.vMins, rootBlk.vTicks);
XmlFsType.ModificationDateSpecified = true;
XmlFsType.Dirty = rootBlk.bitmapFlag != 0xFFFFFFFF;
XmlFsType.Clusters = blocks;
XmlFsType.ClusterSize = (int)blockSize;
XmlFsType.VolumeName = diskName;
XmlFsType.Bootable = bsum == bootBlk.checksum;
XmlFsType.Dirty = rootBlk.bitmapFlag != 0xFFFFFFFF;
XmlFsType.Clusters = blocks;
XmlFsType.ClusterSize = (int)blockSize;
XmlFsType.VolumeName = diskName;
XmlFsType.Bootable = bsum == bootBlk.checksum;
// Useful as a serial
XmlFsType.VolumeSerial = $"{rootBlk.checksum:X8}";
}
@@ -333,10 +334,10 @@ namespace DiscImageChef.Filesystems
static RootBlock MarshalRootBlock(byte[] block)
{
byte[] tmp = new byte[228];
Array.Copy(block, 0, tmp, 0, 24);
Array.Copy(block, 0, tmp, 0, 24);
Array.Copy(block, block.Length - 200, tmp, 28, 200);
RootBlock root = BigEndianMarshal.ByteArrayToStructureBigEndian<RootBlock>(tmp);
root.hashTable = new uint[(block.Length - 224) / 4];
RootBlock root = BigEndianMarshal.ByteArrayToStructureBigEndian<RootBlock>(tmp);
root.hashTable = new uint[(block.Length - 224) / 4];
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
for(int i = 0; i < root.hashTable.Length; i++)
root.hashTable[i] = BigEndianBitConverter.ToUInt32(block, 24 + i * 4);
@@ -390,7 +391,8 @@ namespace DiscImageChef.Filesystems
/// <summary>
/// Offset 0x0C, Boot code, til completion. Size is intentionally incorrect to allow marshaling to work.
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] bootCode;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public byte[] bootCode;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
@@ -424,7 +426,8 @@ namespace DiscImageChef.Filesystems
/// Offset 0x18, Hashtable, size = (block size / 4) - 56 or size = hashTableSize.
/// Size intentionally bad to allow marshalling to work.
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public uint[] hashTable;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public uint[] hashTable;
/// <summary>
/// Offset 0x18+hashTableSize*4+0, bitmap flag, 0xFFFFFFFF if valid
/// </summary>
@@ -432,7 +435,8 @@ namespace DiscImageChef.Filesystems
/// <summary>
/// Offset 0x18+hashTableSize*4+4, bitmap pages, 25 entries
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 25)] public uint[] bitmapPages;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 25)]
public uint[] bitmapPages;
/// <summary>
/// Offset 0x18+hashTableSize*4+104, pointer to bitmap extension block
/// </summary>
@@ -452,7 +456,8 @@ namespace DiscImageChef.Filesystems
/// <summary>
/// Offset 0x18+hashTableSize*4+120, disk name, pascal string, 31 bytes
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)] public byte[] diskName;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 31)]
public byte[] diskName;
/// <summary>
/// Offset 0x18+hashTableSize*4+151, unused
/// </summary>

View File

@@ -705,7 +705,6 @@ namespace DiscImageChef.Filesystems
string extraInfo = null;
string bootChk = null;
Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
// This is needed because for FAT16, GEMDOS increases bytes per sector count instead of using big_sectors field.
uint sectorsPerRealSector;
@@ -1527,7 +1526,6 @@ namespace DiscImageChef.Filesystems
byte[] bootCode = new byte[512 - sigSize - bpbSector[1] - 2];
Array.Copy(bpbSector, bpbSector[1] + 2, bootCode, 0, bootCode.Length);
sha1Ctx = new Sha1Context();
sha1Ctx.Init();
sha1Ctx.Update(bootCode);
bootChk = sha1Ctx.End();
}
@@ -1539,7 +1537,6 @@ namespace DiscImageChef.Filesystems
Array.Copy(bpbSector, BitConverter.ToUInt16(bpbSector, 1) + 3, bootCode, 0,
bootCode.Length);
sha1Ctx = new Sha1Context();
sha1Ctx.Init();
sha1Ctx.Update(bootCode);
bootChk = sha1Ctx.End();
}

View File

@@ -44,28 +44,26 @@ namespace DiscImageChef.Filesystems
public class HPFS : IFilesystem
{
public FileSystemType XmlFsType { get; private set; }
public Encoding Encoding { get; private set; }
public string Name => "OS/2 High Performance File System";
public Guid Id => new Guid("33513B2C-f590-4acb-8bf2-0b1d5e19dec5");
public Encoding Encoding { get; private set; }
public string Name => "OS/2 High Performance File System";
public Guid Id => new Guid("33513B2C-f590-4acb-8bf2-0b1d5e19dec5");
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
if(16 + partition.Start >= partition.End) return false;
uint magic1, magic2;
byte[] hpfsSbSector =
imagePlugin.ReadSector(16 + partition.Start); // Seek to superblock, on logical sector 16
magic1 = BitConverter.ToUInt32(hpfsSbSector, 0x000);
magic2 = BitConverter.ToUInt32(hpfsSbSector, 0x004);
uint magic1 = BitConverter.ToUInt32(hpfsSbSector, 0x000);
uint magic2 = BitConverter.ToUInt32(hpfsSbSector, 0x004);
return magic1 == 0xF995E849 && magic2 == 0xFA53E9C5;
}
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
Encoding encoding)
Encoding encoding)
{
Encoding = encoding ?? Encoding.GetEncoding("ibm850");
Encoding = encoding ?? Encoding.GetEncoding("ibm850");
information = "";
StringBuilder sb = new StringBuilder();
@@ -94,7 +92,8 @@ namespace DiscImageChef.Filesystems
Marshal.FreeHGlobal(spPtr);
if(StringHandlers.CToString(hpfsBpb.fs_type) != "HPFS " || hpfsSb.magic1 != 0xF995E849 ||
hpfsSb.magic2 != 0xFA53E9C5 || hpfsSp.magic1 != 0xF9911849 || hpfsSp.magic2 != 0xFA5229C5)
hpfsSb.magic2 != 0xFA53E9C5 || hpfsSp.magic1 != 0xF9911849 ||
hpfsSp.magic2 != 0xFA5229C5)
{
sb.AppendLine("This may not be HPFS, following information may be not correct.");
sb.AppendFormat("File system type: \"{0}\" (Should be \"HPFS \")", hpfsBpb.fs_type).AppendLine();
@@ -104,7 +103,7 @@ namespace DiscImageChef.Filesystems
sb.AppendFormat("Spareblock magic2: 0x{0:X8} (Should be 0xFA5229C5)", hpfsSp.magic2).AppendLine();
}
sb.AppendFormat("OEM name: {0}", StringHandlers.CToString(hpfsBpb.oem_name)).AppendLine();
sb.AppendFormat("OEM name: {0}", StringHandlers.CToString(hpfsBpb.oem_name)).AppendLine();
sb.AppendFormat("{0} bytes per sector", hpfsBpb.bps).AppendLine();
// sb.AppendFormat("{0} sectors per cluster", hpfs_bpb.spc).AppendLine();
// sb.AppendFormat("{0} reserved sectors", hpfs_bpb.rsectors).AppendLine();
@@ -115,85 +114,91 @@ namespace DiscImageChef.Filesystems
// sb.AppendFormat("{0} sectors per FAT", hpfs_bpb.spfat).AppendLine();
// sb.AppendFormat("{0} sectors per track", hpfs_bpb.sptrk).AppendLine();
// sb.AppendFormat("{0} heads", hpfs_bpb.heads).AppendLine();
sb.AppendFormat("{0} sectors hidden before BPB", hpfsBpb.hsectors).AppendLine();
sb.AppendFormat("{0} sectors hidden before BPB", hpfsBpb.hsectors).AppendLine();
sb.AppendFormat("{0} sectors on volume ({1} bytes)", hpfsSb.sectors, hpfsSb.sectors * hpfsBpb.bps)
.AppendLine();
// sb.AppendFormat("{0} sectors on volume ({1} bytes)", hpfs_bpb.big_sectors, hpfs_bpb.big_sectors * hpfs_bpb.bps).AppendLine();
sb.AppendFormat("BIOS Drive Number: 0x{0:X2}", hpfsBpb.drive_no).AppendLine();
sb.AppendFormat("NT Flags: 0x{0:X2}", hpfsBpb.nt_flags).AppendLine();
sb.AppendFormat("Signature: 0x{0:X2}", hpfsBpb.signature).AppendLine();
sb.AppendFormat("Serial number: 0x{0:X8}", hpfsBpb.serial_no).AppendLine();
sb.AppendFormat("Volume label: {0}", StringHandlers.CToString(hpfsBpb.volume_label, Encoding)).AppendLine();
sb.AppendFormat("NT Flags: 0x{0:X2}", hpfsBpb.nt_flags).AppendLine();
sb.AppendFormat("Signature: 0x{0:X2}", hpfsBpb.signature).AppendLine();
sb.AppendFormat("Serial number: 0x{0:X8}", hpfsBpb.serial_no).AppendLine();
sb.AppendFormat("Volume label: {0}", StringHandlers.CToString(hpfsBpb.volume_label, Encoding))
.AppendLine();
// sb.AppendFormat("Filesystem type: \"{0}\"", hpfs_bpb.fs_type).AppendLine();
DateTime lastChk = DateHandlers.UnixToDateTime(hpfsSb.last_chkdsk);
DateTime lastChk = DateHandlers.UnixToDateTime(hpfsSb.last_chkdsk);
DateTime lastOptim = DateHandlers.UnixToDateTime(hpfsSb.last_optim);
sb.AppendFormat("HPFS version: {0}", hpfsSb.version).AppendLine();
sb.AppendFormat("Functional version: {0}", hpfsSb.func_version).AppendLine();
sb.AppendFormat("Sector of root directory FNode: {0}", hpfsSb.root_fnode).AppendLine();
sb.AppendFormat("{0} sectors are marked bad", hpfsSb.badblocks).AppendLine();
sb.AppendFormat("Sector of free space bitmaps: {0}", hpfsSb.bitmap_lsn).AppendLine();
sb.AppendFormat("Sector of bad blocks list: {0}", hpfsSb.badblock_lsn).AppendLine();
sb.AppendFormat("HPFS version: {0}", hpfsSb.version)
.AppendLine();
sb.AppendFormat("Functional version: {0}", hpfsSb.func_version)
.AppendLine();
sb.AppendFormat("Sector of root directory FNode: {0}", hpfsSb.root_fnode)
.AppendLine();
sb.AppendFormat("{0} sectors are marked bad", hpfsSb.badblocks)
.AppendLine();
sb.AppendFormat("Sector of free space bitmaps: {0}", hpfsSb.bitmap_lsn)
.AppendLine();
sb.AppendFormat("Sector of bad blocks list: {0}", hpfsSb.badblock_lsn)
.AppendLine();
if(hpfsSb.last_chkdsk > 0) sb.AppendFormat("Date of last integrity check: {0}", lastChk).AppendLine();
else sb.AppendLine("Filesystem integrity has never been checked");
if(hpfsSb.last_optim > 0) sb.AppendFormat("Date of last optimization {0}", lastOptim).AppendLine();
else sb.AppendLine("Filesystem has never been optimized");
sb.AppendFormat("Directory band has {0} sectors", hpfsSb.dband_sectors).AppendLine();
sb.AppendFormat("Directory band starts at sector {0}", hpfsSb.dband_start).AppendLine();
sb.AppendFormat("Directory band ends at sector {0}", hpfsSb.dband_last).AppendLine();
sb.AppendFormat("Directory band has {0} sectors", hpfsSb.dband_sectors).AppendLine();
sb.AppendFormat("Directory band starts at sector {0}", hpfsSb.dband_start).AppendLine();
sb.AppendFormat("Directory band ends at sector {0}", hpfsSb.dband_last).AppendLine();
sb.AppendFormat("Sector of directory band bitmap: {0}", hpfsSb.dband_bitmap).AppendLine();
sb.AppendFormat("Sector of ACL directory: {0}", hpfsSb.acl_start).AppendLine();
sb.AppendFormat("Sector of ACL directory: {0}", hpfsSb.acl_start).AppendLine();
sb.AppendFormat("Sector of Hotfix directory: {0}", hpfsSp.hotfix_start).AppendLine();
sb.AppendFormat("{0} used Hotfix entries", hpfsSp.hotfix_used).AppendLine();
sb.AppendFormat("{0} total Hotfix entries", hpfsSp.hotfix_entries).AppendLine();
sb.AppendFormat("{0} free spare DNodes", hpfsSp.spare_dnodes_free).AppendLine();
sb.AppendFormat("{0} total spare DNodes", hpfsSp.spare_dnodes).AppendLine();
sb.AppendFormat("Sector of Hotfix directory: {0}", hpfsSp.hotfix_start).AppendLine();
sb.AppendFormat("{0} used Hotfix entries", hpfsSp.hotfix_used).AppendLine();
sb.AppendFormat("{0} total Hotfix entries", hpfsSp.hotfix_entries).AppendLine();
sb.AppendFormat("{0} free spare DNodes", hpfsSp.spare_dnodes_free).AppendLine();
sb.AppendFormat("{0} total spare DNodes", hpfsSp.spare_dnodes).AppendLine();
sb.AppendFormat("Sector of codepage directory: {0}", hpfsSp.codepage_lsn).AppendLine();
sb.AppendFormat("{0} codepages used in the volume", hpfsSp.codepages).AppendLine();
sb.AppendFormat("SuperBlock CRC32: {0:X8}", hpfsSp.sb_crc32).AppendLine();
sb.AppendFormat("SpareBlock CRC32: {0:X8}", hpfsSp.sp_crc32).AppendLine();
sb.AppendFormat("{0} codepages used in the volume", hpfsSp.codepages).AppendLine();
sb.AppendFormat("SuperBlock CRC32: {0:X8}", hpfsSp.sb_crc32).AppendLine();
sb.AppendFormat("SpareBlock CRC32: {0:X8}", hpfsSp.sp_crc32).AppendLine();
sb.AppendLine("Flags:");
sb.AppendLine((hpfsSp.flags1 & 0x01) == 0x01 ? "Filesystem is dirty." : "Filesystem is clean.");
if((hpfsSp.flags1 & 0x02) == 0x02) sb.AppendLine("Spare directory blocks are in use");
if((hpfsSp.flags1 & 0x04) == 0x04) sb.AppendLine("Hotfixes are in use");
if((hpfsSp.flags1 & 0x08) == 0x08) sb.AppendLine("Disk contains bad sectors");
if((hpfsSp.flags1 & 0x10) == 0x10) sb.AppendLine("Disk has a bad bitmap");
if((hpfsSp.flags1 & 0x20) == 0x20) sb.AppendLine("Filesystem was formatted fast");
if((hpfsSp.flags1 & 0x40) == 0x40) sb.AppendLine("Unknown flag 0x40 on flags1 is active");
if((hpfsSp.flags1 & 0x80) == 0x80) sb.AppendLine("Filesystem has been mounted by an old IFS");
if((hpfsSp.flags2 & 0x01) == 0x01) sb.AppendLine("Install DASD limits");
if((hpfsSp.flags2 & 0x02) == 0x02) sb.AppendLine("Resync DASD limits");
if((hpfsSp.flags2 & 0x04) == 0x04) sb.AppendLine("DASD limits are operational");
if((hpfsSp.flags2 & 0x08) == 0x08) sb.AppendLine("Multimedia is active");
if((hpfsSp.flags2 & 0x10) == 0x10) sb.AppendLine("DCE ACLs are active");
if((hpfsSp.flags2 & 0x20) == 0x20) sb.AppendLine("DASD limits are dirty");
if((hpfsSp.flags2 & 0x40) == 0x40) sb.AppendLine("Unknown flag 0x40 on flags2 is active");
if((hpfsSp.flags2 & 0x80) == 0x80) sb.AppendLine("Unknown flag 0x80 on flags2 is active");
if((hpfsSp.flags1 & 0x02) == 0x02) sb.AppendLine("Spare directory blocks are in use");
if((hpfsSp.flags1 & 0x04) == 0x04) sb.AppendLine("Hotfixes are in use");
if((hpfsSp.flags1 & 0x08) == 0x08) sb.AppendLine("Disk contains bad sectors");
if((hpfsSp.flags1 & 0x10) == 0x10) sb.AppendLine("Disk has a bad bitmap");
if((hpfsSp.flags1 & 0x20) == 0x20) sb.AppendLine("Filesystem was formatted fast");
if((hpfsSp.flags1 & 0x40) == 0x40) sb.AppendLine("Unknown flag 0x40 on flags1 is active");
if((hpfsSp.flags1 & 0x80) == 0x80) sb.AppendLine("Filesystem has been mounted by an old IFS");
if((hpfsSp.flags2 & 0x01) == 0x01) sb.AppendLine("Install DASD limits");
if((hpfsSp.flags2 & 0x02) == 0x02) sb.AppendLine("Resync DASD limits");
if((hpfsSp.flags2 & 0x04) == 0x04) sb.AppendLine("DASD limits are operational");
if((hpfsSp.flags2 & 0x08) == 0x08) sb.AppendLine("Multimedia is active");
if((hpfsSp.flags2 & 0x10) == 0x10) sb.AppendLine("DCE ACLs are active");
if((hpfsSp.flags2 & 0x20) == 0x20) sb.AppendLine("DASD limits are dirty");
if((hpfsSp.flags2 & 0x40) == 0x40) sb.AppendLine("Unknown flag 0x40 on flags2 is active");
if((hpfsSp.flags2 & 0x80) == 0x80) sb.AppendLine("Unknown flag 0x80 on flags2 is active");
XmlFsType = new FileSystemType();
// Theoretically everything from BPB to SB is boot code, should I hash everything or only the sector loaded by BIOS itself?
if(hpfsBpb.jump[0] == 0xEB && hpfsBpb.jump[1] > 0x3C && hpfsBpb.jump[1] < 0x80 &&
if(hpfsBpb.jump[0] == 0xEB && hpfsBpb.jump[1] > 0x3C && hpfsBpb.jump[1] < 0x80 &&
hpfsBpb.signature2 == 0xAA55)
{
XmlFsType.Bootable = true;
XmlFsType.Bootable = true;
Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
string bootChk = sha1Ctx.Data(hpfsBpb.boot_code, out byte[] sha1_out);
string bootChk = sha1Ctx.Data(hpfsBpb.boot_code, out byte[] sha1_out);
sb.AppendLine("Volume is bootable");
sb.AppendFormat("Boot code's SHA1: {0}", bootChk).AppendLine();
}
XmlFsType.Dirty |= (hpfsSp.flags1 & 0x01) == 0x01;
XmlFsType.Clusters = hpfsSb.sectors;
XmlFsType.ClusterSize = hpfsBpb.bps;
XmlFsType.Type = "HPFS";
XmlFsType.VolumeName = StringHandlers.CToString(hpfsBpb.volume_label, Encoding);
XmlFsType.VolumeSerial = $"{hpfsBpb.serial_no:X8}";
XmlFsType.SystemIdentifier = StringHandlers.CToString(hpfsBpb.oem_name);
XmlFsType.Dirty |= (hpfsSp.flags1 & 0x01) == 0x01;
XmlFsType.Clusters = hpfsSb.sectors;
XmlFsType.ClusterSize = hpfsBpb.bps;
XmlFsType.Type = "HPFS";
XmlFsType.VolumeName = StringHandlers.CToString(hpfsBpb.volume_label, Encoding);
XmlFsType.VolumeSerial = $"{hpfsBpb.serial_no:X8}";
XmlFsType.SystemIdentifier = StringHandlers.CToString(hpfsBpb.oem_name);
information = sb.ToString();
}
@@ -205,9 +210,11 @@ namespace DiscImageChef.Filesystems
struct HPFS_BIOSParameterBlock
{
/// <summary>0x000, Jump to boot code</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] jump;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] jump;
/// <summary>0x003, OEM Name, 8 bytes, space-padded</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] oem_name;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] oem_name;
/// <summary>0x00B, Bytes per sector</summary>
public ushort bps;
/// <summary>0x00D, Sectors per cluster</summary>
@@ -241,11 +248,14 @@ namespace DiscImageChef.Filesystems
/// <summary>0x02B, Volume serial number</summary>
public uint serial_no;
/// <summary>0x02F, Volume label, 11 bytes, space-padded</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)] public byte[] volume_label;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)]
public byte[] volume_label;
/// <summary>0x03A, Filesystem type, 8 bytes, space-padded ("HPFS ")</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] fs_type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] fs_type;
/// <summary>Boot code.</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 448)] public byte[] boot_code;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 448)]
public byte[] boot_code;
/// <summary>0x1FE, 0xAA55</summary>
public ushort signature2;
}

View File

@@ -569,7 +569,6 @@ namespace DiscImageChef.Filesystems.ISO9660
{
vdSector = imagePlugin.ReadSector(torito.Value.catalog_sector + partition.Start);
Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
int toritoOff = 0;

View File

@@ -44,17 +44,15 @@ namespace DiscImageChef.Filesystems
public class NTFS : IFilesystem
{
public FileSystemType XmlFsType { get; private set; }
public Encoding Encoding { get; private set; }
public string Name => "New Technology File System (NTFS)";
public Guid Id => new Guid("33513B2C-1e6d-4d21-a660-0bbc789c3871");
public Encoding Encoding { get; private set; }
public string Name => "New Technology File System (NTFS)";
public Guid Id => new Guid("33513B2C-1e6d-4d21-a660-0bbc789c3871");
public bool Identify(IMediaImage imagePlugin, Partition partition)
{
if(2 + partition.Start >= partition.End) return false;
byte[] eigthBytes = new byte[8];
byte fatsNo;
ushort spFat, signature;
byte[] ntfsBpb = imagePlugin.ReadSector(0 + partition.Start);
@@ -63,23 +61,20 @@ namespace DiscImageChef.Filesystems
if(oemName != "NTFS ") return false;
fatsNo = ntfsBpb[0x010];
byte fatsNo = ntfsBpb[0x010];
ushort spFat = BitConverter.ToUInt16(ntfsBpb, 0x016);
ushort signature = BitConverter.ToUInt16(ntfsBpb, 0x1FE);
if(fatsNo != 0) return false;
spFat = BitConverter.ToUInt16(ntfsBpb, 0x016);
if(spFat != 0) return false;
signature = BitConverter.ToUInt16(ntfsBpb, 0x1FE);
if(spFat != 0) return false;
return signature == 0xAA55;
}
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
Encoding encoding)
Encoding encoding)
{
Encoding = Encoding.Unicode;
Encoding = Encoding.Unicode;
information = "";
StringBuilder sb = new StringBuilder();
@@ -91,7 +86,7 @@ namespace DiscImageChef.Filesystems
NtfsBootBlock ntfsBb = (NtfsBootBlock)Marshal.PtrToStructure(bpbPtr, typeof(NtfsBootBlock));
Marshal.FreeHGlobal(bpbPtr);
sb.AppendFormat("{0} bytes per sector", ntfsBb.bps).AppendLine();
sb.AppendFormat("{0} bytes per sector", ntfsBb.bps).AppendLine();
sb.AppendFormat("{0} sectors per cluster ({1} bytes)", ntfsBb.spc, ntfsBb.spc * ntfsBb.bps).AppendLine();
// sb.AppendFormat("{0} reserved sectors", ntfs_bb.rsectors).AppendLine();
// sb.AppendFormat("{0} FATs", ntfs_bb.fats_no).AppendLine();
@@ -99,8 +94,8 @@ namespace DiscImageChef.Filesystems
// sb.AppendFormat("{0} sectors on volume (small)", ntfs_bb.sml_sectors).AppendLine();
sb.AppendFormat("Media descriptor: 0x{0:X2}", ntfsBb.media).AppendLine();
// sb.AppendFormat("{0} sectors per FAT", ntfs_bb.spfat).AppendLine();
sb.AppendFormat("{0} sectors per track", ntfsBb.sptrk).AppendLine();
sb.AppendFormat("{0} heads", ntfsBb.heads).AppendLine();
sb.AppendFormat("{0} sectors per track", ntfsBb.sptrk).AppendLine();
sb.AppendFormat("{0} heads", ntfsBb.heads).AppendLine();
sb.AppendFormat("{0} hidden sectors before filesystem", ntfsBb.hsectors).AppendLine();
// sb.AppendFormat("{0} sectors on volume (big)", ntfs_bb.big_sectors).AppendLine();
sb.AppendFormat("BIOS drive number: 0x{0:X2}", ntfsBb.drive_no).AppendLine();
@@ -108,7 +103,7 @@ namespace DiscImageChef.Filesystems
// sb.AppendFormat("Signature 1: 0x{0:X2}", ntfs_bb.signature1).AppendLine();
sb.AppendFormat("{0} sectors on volume ({1} bytes)", ntfsBb.sectors, ntfsBb.sectors * ntfsBb.bps)
.AppendLine();
sb.AppendFormat("Cluster where $MFT starts: {0}", ntfsBb.mft_lsn).AppendLine();
sb.AppendFormat("Cluster where $MFT starts: {0}", ntfsBb.mft_lsn).AppendLine();
sb.AppendFormat("Cluster where $MFTMirr starts: {0}", ntfsBb.mftmirror_lsn).AppendLine();
if(ntfsBb.mft_rc_clusters > 0)
@@ -127,18 +122,17 @@ namespace DiscImageChef.Filesystems
if(ntfsBb.jump[0] == 0xEB && ntfsBb.jump[1] > 0x4E && ntfsBb.jump[1] < 0x80 && ntfsBb.signature2 == 0xAA55)
{
XmlFsType.Bootable = true;
XmlFsType.Bootable = true;
Sha1Context sha1Ctx = new Sha1Context();
sha1Ctx.Init();
string bootChk = sha1Ctx.Data(ntfsBb.boot_code, out _);
string bootChk = sha1Ctx.Data(ntfsBb.boot_code, out _);
sb.AppendLine("Volume is bootable");
sb.AppendFormat("Boot code's SHA1: {0}", bootChk).AppendLine();
}
XmlFsType.ClusterSize = ntfsBb.spc * ntfsBb.bps;
XmlFsType.Clusters = ntfsBb.sectors / ntfsBb.spc;
XmlFsType.ClusterSize = ntfsBb.spc * ntfsBb.bps;
XmlFsType.Clusters = ntfsBb.sectors / ntfsBb.spc;
XmlFsType.VolumeSerial = $"{ntfsBb.serial_no:X16}";
XmlFsType.Type = "NTFS";
XmlFsType.Type = "NTFS";
information = sb.ToString();
}
@@ -151,9 +145,11 @@ namespace DiscImageChef.Filesystems
{
// Start of BIOS Parameter Block
/// <summary>0x000, Jump to boot code</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] jump;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] jump;
/// <summary>0x003, OEM Name, 8 bytes, space-padded, must be "NTFS "</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] oem_name;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] oem_name;
/// <summary>0x00B, Bytes per sector</summary>
public ushort bps;
/// <summary>0x00D, Sectors per cluster</summary>
@@ -210,7 +206,8 @@ namespace DiscImageChef.Filesystems
/// <summary>0x048, Volume serial number</summary>
public ulong serial_no;
/// <summary>Boot code.</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 430)] public byte[] boot_code;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 430)]
public byte[] boot_code;
/// <summary>0x1FE, 0xAA55</summary>
public ushort signature2;
}