mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
* FileSystemIDandChk/Plugins/FAT.cs:
Modified logic to work around FAT12 predating DOS 2.0. Limiting it to disks supported by 86-DOS and DOS 1.x, yet probably it will give false positives. * FileSystemIDandChk/PrintHex.cs: * FileSystemIDandChk/FileSystemIDandChk.csproj: Added function to print hexadecimal output of sector, useful for debugging with compressed disk images.
This commit is contained in:
@@ -75,6 +75,7 @@
|
||||
<Compile Include="Plugins\LisaFS.cs" />
|
||||
<Compile Include="ImagePlugins\TeleDisk.cs" />
|
||||
<Compile Include="ArrayFill.cs" />
|
||||
<Compile Include="PrintHex.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
||||
@@ -61,7 +61,9 @@ namespace FileSystemIDandChk.Plugins
|
||||
UInt16 bps, rsectors;
|
||||
|
||||
byte[] bpb_sector = imagePlugin.ReadSector(0 + partitionOffset);
|
||||
byte[] fat_sector;
|
||||
byte[] fat_sector = imagePlugin.ReadSector(1 + partitionOffset);
|
||||
|
||||
bool bpb_found = true;
|
||||
|
||||
fats_no = bpb_sector[0x010]; // FATs, 1 or 2, maybe 0, never bigger
|
||||
media_descriptor = bpb_sector[0x015]; // Media Descriptor if present is in 0x15
|
||||
@@ -75,7 +77,10 @@ namespace FileSystemIDandChk.Plugins
|
||||
if (imagePlugin.GetSectors() > ((ulong)rsectors + partitionOffset))
|
||||
fat_sector = imagePlugin.ReadSector(rsectors + partitionOffset); // First FAT entry
|
||||
else
|
||||
return false;
|
||||
bpb_found=false;
|
||||
|
||||
if (bpb_found)
|
||||
{
|
||||
first_fat_entry = BitConverter.ToUInt32(fat_sector, 0); // Easier to manage
|
||||
|
||||
if (MainClass.isDebug)
|
||||
@@ -104,6 +109,62 @@ namespace FileSystemIDandChk.Plugins
|
||||
//if((first_fat_entry & 0xFF) == media_descriptor) // Pre DOS<4 does not implement this, TOS does and is !=
|
||||
return true; // It MUST be FAT12, or... maybe not :S
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// This may create a lot of false positives, need to do extensive checkins...
|
||||
fat_sector = imagePlugin.ReadSector(1 + partitionOffset);
|
||||
first_fat_entry = BitConverter.ToUInt32(fat_sector, 0);
|
||||
byte fat_id = fat_sector[0];
|
||||
|
||||
if ((first_fat_entry & 0x00FFFFF0) == 0x00FFFFF0)
|
||||
{
|
||||
if (fat_id == 0xFF)
|
||||
{
|
||||
if (imagePlugin.GetSectorSize() == 512 && imagePlugin.GetSectors() == 640)
|
||||
return true;
|
||||
if (imagePlugin.GetSectorSize() == 128)
|
||||
{
|
||||
if(imagePlugin.GetSectors() == 2002)
|
||||
return true;
|
||||
if(imagePlugin.GetSectors() == 4004)
|
||||
return true;
|
||||
}
|
||||
if (imagePlugin.GetSectorSize() == 1024)
|
||||
{
|
||||
if(imagePlugin.GetSectors() == 616)
|
||||
return true;
|
||||
if(imagePlugin.GetSectors() == 1232)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
if (fat_id == 0xFE)
|
||||
{
|
||||
if (imagePlugin.GetSectorSize() == 512 && imagePlugin.GetSectors() == 320)
|
||||
return true;
|
||||
if (imagePlugin.GetSectorSize() == 128)
|
||||
{
|
||||
if(imagePlugin.GetSectors() == 2002)
|
||||
return true;
|
||||
if(imagePlugin.GetSectors() == 4004)
|
||||
return true;
|
||||
}
|
||||
if (imagePlugin.GetSectorSize() == 1024)
|
||||
{
|
||||
if(imagePlugin.GetSectors() == 616)
|
||||
return true;
|
||||
if(imagePlugin.GetSectors() == 1232)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
if (fat_id == 0xFD && imagePlugin.GetSectors() == 2002)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -122,7 +183,9 @@ namespace FileSystemIDandChk.Plugins
|
||||
UInt16 bps, rsectors;
|
||||
|
||||
byte[] bpb_sector = imagePlugin.ReadSector(0 + partitionOffset);
|
||||
byte[] fat_sector;
|
||||
byte[] fat_sector = imagePlugin.ReadSector(1 + partitionOffset);
|
||||
|
||||
bool bpb_found = true;
|
||||
|
||||
fats_no = bpb_sector[0x010]; // FATs, 1 or 2, maybe 0, never bigger
|
||||
media_descriptor = bpb_sector[0x015]; // Media Descriptor if present is in 0x15
|
||||
@@ -135,7 +198,13 @@ namespace FileSystemIDandChk.Plugins
|
||||
rsectors = BitConverter.ToUInt16(bpb_sector, 0x00E); // Sectors between BPB and FAT, including the BPB sector => [BPB,FAT)
|
||||
if (rsectors == 0)
|
||||
rsectors = 1;
|
||||
if (imagePlugin.GetSectors() > ((ulong)rsectors + partitionOffset))
|
||||
fat_sector = imagePlugin.ReadSector(rsectors + partitionOffset); // First FAT entry
|
||||
else
|
||||
bpb_found=false;
|
||||
|
||||
if (bpb_found)
|
||||
{
|
||||
first_fat_entry = BitConverter.ToUInt32(fat_sector, 0); // Easier to manage
|
||||
|
||||
if (fats_no > 2) // Must be 1 or 2, but as TOS makes strange things and I have not checked if it puts this to 0, ignore if 0. MUST NOT BE BIGGER THAN 2!
|
||||
@@ -267,112 +336,128 @@ namespace FileSystemIDandChk.Plugins
|
||||
sb.AppendFormat("Filesystem type: {0}", EPB.fs_type).AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine("Pre-DOS 2.0 Microsoft FAT12.");
|
||||
sb.AppendLine("***WARNING***");
|
||||
sb.AppendLine("This may be a false positive.");
|
||||
sb.AppendFormat("Disk image identifies disk type as {0}.", imagePlugin.GetDiskType());
|
||||
}
|
||||
|
||||
information = sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>FAT's BIOS Parameter Block.</summary>
|
||||
public struct BIOSParameterBlock
|
||||
{
|
||||
/// <summary>0x03, OEM Name, 8 bytes, space-padded</summary>
|
||||
public string OEMName;
|
||||
// 0x03, OEM Name, 8 bytes, space-padded
|
||||
/// <summary>0x0B, Bytes per sector</summary>
|
||||
public UInt16 bps;
|
||||
// 0x0B, Bytes per sector
|
||||
/// <summary>0x0D, Sectors per cluster</summary>
|
||||
public byte spc;
|
||||
// 0x0D, Sectors per cluster
|
||||
/// <summary>0x0E, Reserved sectors between BPB and FAT</summary>
|
||||
public UInt16 rsectors;
|
||||
// 0x0E, Reserved sectors between BPB and FAT
|
||||
/// <summary>0x10, Number of FATs</summary>
|
||||
public byte fats_no;
|
||||
// 0x10, Number of FATs
|
||||
/// <summary>0x11, Number of entries on root directory</summary>
|
||||
public UInt16 root_ent;
|
||||
// 0x11, Number of entries on root directory
|
||||
/// <summary>0x13, Sectors in volume</summary>
|
||||
public UInt16 sectors;
|
||||
// 0x13, Sectors in volume
|
||||
/// <summary>0x15, Media descriptor</summary>
|
||||
public byte media;
|
||||
// 0x15, Media descriptor
|
||||
/// <summary>0x16, Sectors per FAT</summary>
|
||||
public UInt16 spfat;
|
||||
// 0x16, Sectors per FAT
|
||||
/// <summary>0x18, Sectors per track</summary>
|
||||
public UInt16 sptrk;
|
||||
// 0x18, Sectors per track
|
||||
/// <summary>0x1A, Heads</summary>
|
||||
public UInt16 heads;
|
||||
// 0x1A, Heads
|
||||
/// <summary>0x1C, Hidden sectors before BPB</summary>
|
||||
public UInt32 hsectors;
|
||||
// 0x1C, Hidden sectors before BPB
|
||||
/// <summary>0x20, Sectors in volume if > 65535</summary>
|
||||
public UInt32 big_sectors;
|
||||
// 0x20, Sectors in volume if > 65535
|
||||
}
|
||||
// This only applies for bootable disks
|
||||
// From http://info-coach.fr/atari/software/FD-Soft.php
|
||||
|
||||
/// <summary>
|
||||
/// Atari Boot Block.
|
||||
/// This only applies for bootable disks
|
||||
/// From http://info-coach.fr/atari/software/FD-Soft.php
|
||||
/// </summary>
|
||||
public struct AtariBootBlock
|
||||
{
|
||||
/// <summary>0x01C, Atari ST use 16 bit for hidden sectors, probably so did old DOS</summary>
|
||||
public UInt16 hsectors;
|
||||
// 0x01C, Atari ST use 16 bit for hidden sectors, probably so did old DOS
|
||||
/// <summary>0x01E, indicates if COMMAND.PRG must be executed after OS load</summary>
|
||||
public UInt16 xflag;
|
||||
// 0x01E, indicates if COMMAND.PRG must be executed after OS load
|
||||
/// <summary>0x020, load mode for, or 0 if fname indicates boot file</summary>
|
||||
public UInt16 ldmode;
|
||||
// 0x020, load mode for, or 0 if fname indicates boot file
|
||||
/// <summary>0x022, sector from which to boot</summary>
|
||||
public UInt16 bsect;
|
||||
// 0x022, sector from which to boot
|
||||
/// <summary>0x024, how many sectors to boot</summary>
|
||||
public UInt16 bsects_no;
|
||||
// 0x024, how many sectors to boot
|
||||
/// <summary>0x026, RAM address where boot should be located</summary>
|
||||
public UInt32 ldaddr;
|
||||
// 0x026, RAM address where boot should be located
|
||||
/// <summary>0x02A, RAM address to copy the FAT and root directory</summary>
|
||||
public UInt32 fatbuf;
|
||||
// 0x02A, RAM address to copy the FAT and root directory
|
||||
/// <summary>0x02E, 11 bytes, name of boot file</summary>
|
||||
public string fname;
|
||||
// 0x02E, 11 bytes, name of boot file
|
||||
/// <summary>0x039, unused</summary>
|
||||
public UInt16 reserved;
|
||||
// 0x039, unused
|
||||
/// <summary>0x03B, 451 bytes boot code</summary>
|
||||
public byte[] boot_code;
|
||||
// 0x03B, 451 bytes boot code
|
||||
/// <summary>0x1FE, the sum of all the BPB+ABB must be 0x1234, so this bigendian value works as adjustment</summary>
|
||||
public UInt16 checksum;
|
||||
// 0x1FE, the sum of all the BPB+ABB must be 0x1234, so this bigendian value works as adjustment
|
||||
}
|
||||
|
||||
/// <summary>DOS Extended Parameter Block</summary>
|
||||
public struct ExtendedParameterBlock
|
||||
{
|
||||
/// <summary>0x24, Drive number<summary>
|
||||
public byte drive_no;
|
||||
// 0x24, Drive number
|
||||
/// <summary>0x25, Volume flags if NT (must be 0x29 signature)<summary>
|
||||
public byte nt_flags;
|
||||
// 0x25, Volume flags if NT (must be 0x29 signature)
|
||||
/// <summary>0x26, EPB signature, 0x28 or 0x29<summary>
|
||||
public byte signature;
|
||||
// 0x26, EPB signature, 0x28 or 0x29
|
||||
/// <summary>0x27, Volume serial number<summary>
|
||||
public UInt32 serial_no;
|
||||
// 0x27, Volume serial number
|
||||
/* Present only if signature == 0x29 */
|
||||
/// <summary>0x2B, Volume label, 11 bytes, space-padded
|
||||
/// Present only if signature == 0x29<summary>
|
||||
public string volume_label;
|
||||
// 0x2B, Volume label, 11 bytes, space-padded
|
||||
/// <summary>0x36, Filesystem type, 8 bytes, space-padded
|
||||
/// Present only if signature == 0x29<summary>
|
||||
public string fs_type;
|
||||
// 0x36, Filesystem type, 8 bytes, space-padded
|
||||
}
|
||||
|
||||
/// <summary>FAT32 Parameter Block</summary>
|
||||
public struct FAT32ParameterBlock
|
||||
{
|
||||
/// <summary>0x24, Sectors per FAT</summary>
|
||||
public UInt32 spfat;
|
||||
// 0x24, Sectors per FAT
|
||||
/// <summary>0x28, FAT flags</summary>
|
||||
public UInt16 fat_flags;
|
||||
// 0x28, FAT flags
|
||||
/// <summary>0x2A, FAT32 version</summary>
|
||||
public UInt16 version;
|
||||
// 0x2A, FAT32 version
|
||||
/// <summary>0x2C, Cluster of root directory</summary>
|
||||
public UInt32 root_cluster;
|
||||
// 0x2C, Cluster of root directory
|
||||
/// <summary>0x30, Sector of FSINFO structure</summary>
|
||||
public UInt16 fsinfo_sector;
|
||||
// 0x30, Sector of FSINFO structure
|
||||
/// <summary>0x32, Sector of FAT32PB backup</summary>
|
||||
public UInt16 backup_sector;
|
||||
// 0x32, Sector of FAT32PB bacup
|
||||
/// <summary>0x34, 12 reserved bytes</summary>
|
||||
byte[] reserved;
|
||||
// 0x34, 12 reserved bytes
|
||||
/// <summary>0x40, Drive number</summary>
|
||||
public byte drive_no;
|
||||
// 0x40, Drive number
|
||||
/// <summary>0x41, Volume flags</summary>
|
||||
public byte nt_flags;
|
||||
// 0x41, Volume flags
|
||||
/// <summary>0x42, FAT32PB signature, should be 0x29</summary>
|
||||
public byte signature;
|
||||
// 0x42, FAT32PB signature, should be 0x29
|
||||
/// <summary>0x43, Volume serial number</summary>
|
||||
public UInt32 serial_no;
|
||||
// 0x43, Volume serial number
|
||||
/// <summary>0x47, Volume label, 11 bytes, space-padded</summary>
|
||||
public string volume_label;
|
||||
// 0x47, Volume label, 11 bytes, space-padded
|
||||
/// <summary>0x52, Filesystem type, 8 bytes, space-padded, must be "FAT32 "</summary>
|
||||
public string fs_type;
|
||||
// 0x52, Filesystem type, 8 bytes, space-padded, must be "FAT32 "
|
||||
}
|
||||
}
|
||||
}
|
||||
84
FileSystemIDandChk/PrintHex.cs
Normal file
84
FileSystemIDandChk/PrintHex.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
/***************************************************************************
|
||||
FileSystem identifier and checker
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : PrintHex.cs
|
||||
Version : 1.0
|
||||
Author(s) : Natalia Portillo
|
||||
|
||||
Component : Helpers
|
||||
|
||||
Revision : $Revision$
|
||||
Last change by : $Author$
|
||||
Date : $Date$
|
||||
|
||||
--[ Description ] ----------------------------------------------------------
|
||||
|
||||
Prints a byte array as hexadecimal in console.
|
||||
|
||||
--[ License ] --------------------------------------------------------------
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2014 Claunia.com
|
||||
****************************************************************************/
|
||||
//$Id$
|
||||
using System;
|
||||
|
||||
namespace FileSystemIDandChk
|
||||
{
|
||||
public static class PrintHex
|
||||
{
|
||||
public static void PrintHexArray(byte[] array, int width)
|
||||
{
|
||||
int counter = 0;
|
||||
int subcounter = 0;
|
||||
for (long i = 0; i < array.LongLength; i++)
|
||||
{
|
||||
if (counter == 0)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.Write("{0:X16} ", i);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (subcounter == 3 )
|
||||
{
|
||||
Console.Write(" ");
|
||||
subcounter = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write(" ");
|
||||
subcounter++;
|
||||
}
|
||||
}
|
||||
|
||||
Console.Write("{0:X2}", array[i]);
|
||||
|
||||
if (counter == width - 1)
|
||||
{
|
||||
counter = 0;
|
||||
subcounter = 0;
|
||||
}
|
||||
else
|
||||
counter++;
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user