Remove the ability to support little endian from BigEndianBitConverter.

This commit is contained in:
2019-05-11 20:49:32 +01:00
parent 6401e1b3a1
commit b6c7e84762
62 changed files with 502 additions and 560 deletions

View File

@@ -61,8 +61,6 @@ namespace DiscImageChef.Filesystems
{
if(partition.Start >= partition.End) return false;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
// Boot block is unless defined otherwise, 2 blocks
// Funny, you may need boot block to find root block if it's not in standard place just to know size of
// block size and then read the whole boot block.
@@ -159,10 +157,8 @@ namespace DiscImageChef.Filesystems
{
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-1");
StringBuilder sbInformation = new StringBuilder();
XmlFsType = new FileSystemType();
information = null;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
XmlFsType = new FileSystemType();
information = null;
byte[] bootBlockSectors = imagePlugin.ReadSectors(0 + partition.Start, 2);
BootBlock bootBlk = Marshal.ByteArrayToStructureBigEndian<BootBlock>(bootBlockSectors);
@@ -341,8 +337,7 @@ namespace DiscImageChef.Filesystems
Array.Copy(block, 0, tmp, 0, 24);
Array.Copy(block, block.Length - 200, tmp, 28, 200);
RootBlock root = Marshal.ByteArrayToStructureBigEndian<RootBlock>(tmp);
root.hashTable = new uint[(block.Length - 224) / 4];
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
root.hashTable = new uint[(block.Length - 224) / 4];
for(int i = 0; i < root.hashTable.Length; i++)
root.hashTable[i] = BigEndianBitConverter.ToUInt32(block, 24 + i * 4);

View File

@@ -49,8 +49,6 @@ namespace DiscImageChef.Filesystems.AppleMFS
byte[] mdbSector = imagePlugin.ReadSector(2 + partition.Start);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
ushort drSigWord = BigEndianBitConverter.ToUInt16(mdbSector, 0x000);
return drSigWord == MFS_MAGIC;
@@ -72,8 +70,6 @@ namespace DiscImageChef.Filesystems.AppleMFS
byte[] mdbSector = imagePlugin.ReadSector(2 + partition.Start);
byte[] bbSector = imagePlugin.ReadSector(0 + partition.Start);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
mdb.drSigWord = BigEndianBitConverter.ToUInt16(mdbSector, 0x000);
if(mdb.drSigWord != MFS_MAGIC) return;

View File

@@ -57,8 +57,6 @@ namespace DiscImageChef.Filesystems.AppleMFS
mdbBlocks = device.ReadSector(2 + partitionStart);
bootBlocks = device.ReadSector(0 + partitionStart);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
volMDB.drSigWord = BigEndianBitConverter.ToUInt16(mdbBlocks, 0x000);
if(volMDB.drSigWord != MFS_MAGIC) return Errno.InvalidArgument;

View File

@@ -514,8 +514,7 @@ namespace DiscImageChef.Filesystems.FAT
// Some fields could overflow fake BPB, those will be handled below
case BpbKind.Atari:
{
ushort sum = 0;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
ushort sum = 0;
for(int i = 0; i < bpbSector.Length; i += 2) sum += BigEndianBitConverter.ToUInt16(bpbSector, i);
// TODO: Check this

View File

@@ -216,8 +216,7 @@ namespace DiscImageChef.Filesystems.FAT
// Some fields could overflow fake BPB, those will be handled below
case BpbKind.Atari:
{
ushort sum = 0;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
ushort sum = 0;
for(int i = 0; i < bpbSector.Length; i += 2) sum += BigEndianBitConverter.ToUInt16(bpbSector, i);
// TODO: Check this

View File

@@ -162,6 +162,7 @@ namespace DiscImageChef.Filesystems.ISO9660
break;
}
case 1:
{
if(highSierra)
@@ -173,6 +174,7 @@ namespace DiscImageChef.Filesystems.ISO9660
break;
}
case 2:
{
PrimaryVolumeDescriptor svd =
@@ -181,8 +183,7 @@ namespace DiscImageChef.Filesystems.ISO9660
// Check if this is Joliet
if(svd.escape_sequences[0] == '%' && svd.escape_sequences[1] == '/')
if(svd.escape_sequences[2] == '@' || svd.escape_sequences[2] == 'C' ||
svd.escape_sequences[2] == 'E')
jolietvd = svd;
svd.escape_sequences[2] == 'E') jolietvd = svd;
else
DicConsole.WriteLine("ISO9660 plugin", "Found unknown supplementary volume descriptor");
@@ -248,8 +249,6 @@ namespace DiscImageChef.Filesystems.ISO9660
if(rootLocation + rootSize < imagePlugin.Info.Sectors)
rootDir = imagePlugin.ReadSectors(rootLocation, rootSize);
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
// Walk thru root directory to see system area extensions in use
while(rootOff + Marshal.SizeOf<DirectoryRecord>() < rootDir.Length && !cdi)
{

View File

@@ -53,9 +53,6 @@ namespace DiscImageChef.Filesystems.LisaFS
if(!imagePlugin.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag)) return false;
// LisaOS is big-endian
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
// Minimal LisaOS disk is 3.5" single sided double density, 800 sectors
if(imagePlugin.Info.Sectors < 800) return false;
@@ -134,9 +131,6 @@ namespace DiscImageChef.Filesystems.LisaFS
if(!imagePlugin.Info.ReadableSectorTags.Contains(SectorTagType.AppleSectorTag)) return;
// LisaOS is big-endian
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
// Minimal LisaOS disk is 3.5" single sided double density, 800 sectors
if(imagePlugin.Info.Sectors < 800) return;

View File

@@ -67,9 +67,6 @@ namespace DiscImageChef.Filesystems.LisaFS
return Errno.InOutError;
}
// LisaOS is big-endian
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
// Minimal LisaOS disk is 3.5" single sided double density, 800 sectors
if(device.Info.Sectors < 800)
{

View File

@@ -53,8 +53,6 @@ namespace DiscImageChef.Filesystems
if(imagePlugin.Info.Sectors * imagePlugin.Info.SectorSize < 0x50000) return false;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
byte[] header = imagePlugin.ReadSectors(0, 0x50000 / imagePlugin.Info.SectorSize);
uint magicGc = BigEndianBitConverter.ToUInt32(header, 0x1C);
@@ -72,7 +70,6 @@ namespace DiscImageChef.Filesystems
XmlFsType = new FileSystemType();
NintendoFields fields = new NintendoFields();
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
byte[] header = imagePlugin.ReadSectors(0, 0x50000 / imagePlugin.Info.SectorSize);

View File

@@ -73,8 +73,6 @@ namespace DiscImageChef.Filesystems
{
if(partition.Length < 3) return false;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
byte[] sector = imagePlugin.ReadSector(2 + partition.Start);
uint magic = BigEndianBitConverter.ToUInt32(sector, 0x00);

View File

@@ -57,8 +57,6 @@ namespace DiscImageChef.Filesystems
{
if(partition.Start >= partition.End) return false;
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
byte[] sector = imagePlugin.ReadSector(partition.Start);
uint magic = BigEndianBitConverter.ToUInt32(sector, 0x00);

View File

@@ -40,6 +40,7 @@ using Schemas;
namespace DiscImageChef.Filesystems
{
// TODO: Fix little endian
// Information from the Linux kernel
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class SysVfs : IFilesystem
@@ -157,18 +158,16 @@ namespace DiscImageChef.Filesystems
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15");
information = "";
StringBuilder sb = new StringBuilder();
BigEndianBitConverter.IsLittleEndian =
true; // Start in little endian until we know what are we handling here
int start = 0;
bool xenix = false;
bool sysv = false;
bool sys7th = false;
bool coherent = false;
bool xenix3 = false;
byte[] sb_sector;
byte sb_size_in_sectors;
int offset = 0;
StringBuilder sb = new StringBuilder();
int start = 0;
bool xenix = false;
bool sysv = false;
bool sys7th = false;
bool coherent = false;
bool xenix3 = false;
byte[] sb_sector;
byte sb_size_in_sectors;
int offset = 0;
if(imagePlugin.Info.SectorSize <= 0x400
) // Check if underlying device sector size is smaller than SuperBlock size
@@ -192,7 +191,6 @@ namespace DiscImageChef.Filesystems
if(magic == XENIX_MAGIC || magic == SYSV_MAGIC)
{
BigEndianBitConverter.IsLittleEndian = true; // Little endian
if(magic == SYSV_MAGIC)
{
sysv = true;
@@ -206,7 +204,6 @@ namespace DiscImageChef.Filesystems
if(magic == XENIX_CIGAM || magic == SYSV_CIGAM)
{
BigEndianBitConverter.IsLittleEndian = false; // Big endian
if(magic == SYSV_CIGAM)
{
sysv = true;
@@ -222,17 +219,15 @@ namespace DiscImageChef.Filesystems
if(magic == XENIX_MAGIC)
{
BigEndianBitConverter.IsLittleEndian = true; // Little endian
xenix3 = true;
start = i;
xenix3 = true;
start = i;
break;
}
if(magic == XENIX_CIGAM)
{
BigEndianBitConverter.IsLittleEndian = false; // Big endian
xenix3 = true;
start = i;
xenix3 = true;
start = i;
break;
}
@@ -240,17 +235,15 @@ namespace DiscImageChef.Filesystems
if(magic == SYSV_MAGIC)
{
BigEndianBitConverter.IsLittleEndian = true; // Little endian
sysv = true;
start = i;
sysv = true;
start = i;
break;
}
if(magic == SYSV_CIGAM)
{
BigEndianBitConverter.IsLittleEndian = false; // Big endian
sysv = true;
start = i;
sysv = true;
start = i;
break;
}
@@ -263,9 +256,8 @@ namespace DiscImageChef.Filesystems
if(s_fname == COH_FNAME && s_fpack == COH_FPACK || s_fname == COH_XXXXX && s_fpack == COH_XXXXX ||
s_fname == COH_XXXXS && s_fpack == COH_XXXXN)
{
BigEndianBitConverter.IsLittleEndian = true; // Coherent is in PDP endianness, use helper for that
coherent = true;
start = i;
coherent = true;
start = i;
break;
}
@@ -294,9 +286,8 @@ namespace DiscImageChef.Filesystems
if(s_fsize * 1024 != (partition.End - partition.Start) * imagePlugin.Info.SectorSize &&
s_fsize * 512 != (partition.End - partition.Start) * imagePlugin.Info.SectorSize) continue;
sys7th = true;
BigEndianBitConverter.IsLittleEndian = true;
start = i;
sys7th = true;
start = i;
break;
}
@@ -673,8 +664,6 @@ namespace DiscImageChef.Filesystems
}
information = sb.ToString();
BigEndianBitConverter.IsLittleEndian = false; // Return to default (bigendian)
}
// Old XENIX use different offsets

View File

@@ -53,22 +53,24 @@ namespace DiscImageChef.Filesystems.UCSDPascal
// Blocks 0 and 1 are boot code
byte[] volBlock = imagePlugin.ReadSectors(multiplier * 2 + partition.Start, multiplier);
PascalVolumeEntry volEntry = new PascalVolumeEntry();
// On Apple II, it's little endian
BigEndianBitConverter.IsLittleEndian =
multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
// TODO: Fix
/*BigEndianBitConverter.IsLittleEndian =
multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;*/
volEntry.FirstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00);
volEntry.LastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02);
volEntry.EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04);
volEntry.VolumeName = new byte[8];
PascalVolumeEntry volEntry = new PascalVolumeEntry
{
FirstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00),
LastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02),
EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04),
VolumeName = new byte[8],
Blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E),
Files = BigEndianBitConverter.ToInt16(volBlock, 0x10),
Dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12),
LastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14),
Tail = BigEndianBitConverter.ToInt32(volBlock, 0x16)
};
Array.Copy(volBlock, 0x06, volEntry.VolumeName, 0, 8);
volEntry.Blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E);
volEntry.Files = BigEndianBitConverter.ToInt16(volBlock, 0x10);
volEntry.Dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12);
volEntry.LastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14);
volEntry.Tail = BigEndianBitConverter.ToInt32(volBlock, 0x16);
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.firstBlock = {0}", volEntry.FirstBlock);
DicConsole.DebugWriteLine("UCSD Pascal Plugin", "volEntry.lastBlock = {0}", volEntry.LastBlock);
@@ -113,22 +115,25 @@ namespace DiscImageChef.Filesystems.UCSDPascal
// Blocks 0 and 1 are boot code
byte[] volBlock = imagePlugin.ReadSectors(multiplier * 2 + partition.Start, multiplier);
PascalVolumeEntry volEntry = new PascalVolumeEntry();
// On Apple //, it's little endian
BigEndianBitConverter.IsLittleEndian =
multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
// TODO: Fix
//BigEndianBitConverter.IsLittleEndian =
// multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
PascalVolumeEntry volEntry = new PascalVolumeEntry
{
FirstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00),
LastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02),
EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04),
VolumeName = new byte[8],
Blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E),
Files = BigEndianBitConverter.ToInt16(volBlock, 0x10),
Dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12),
LastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14),
Tail = BigEndianBitConverter.ToInt32(volBlock, 0x16)
};
volEntry.FirstBlock = BigEndianBitConverter.ToInt16(volBlock, 0x00);
volEntry.LastBlock = BigEndianBitConverter.ToInt16(volBlock, 0x02);
volEntry.EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(volBlock, 0x04);
volEntry.VolumeName = new byte[8];
Array.Copy(volBlock, 0x06, volEntry.VolumeName, 0, 8);
volEntry.Blocks = BigEndianBitConverter.ToInt16(volBlock, 0x0E);
volEntry.Files = BigEndianBitConverter.ToInt16(volBlock, 0x10);
volEntry.Dummy = BigEndianBitConverter.ToInt16(volBlock, 0x12);
volEntry.LastBoot = BigEndianBitConverter.ToInt16(volBlock, 0x14);
volEntry.Tail = BigEndianBitConverter.ToInt32(volBlock, 0x16);
// First block is always 0 (even is it's sector 2)
if(volEntry.FirstBlock != 0) return;

View File

@@ -59,8 +59,9 @@ namespace DiscImageChef.Filesystems.UCSDPascal
catalogBlocks = device.ReadSectors(multiplier * 2, multiplier);
// On Apple //, it's little endian
BigEndianBitConverter.IsLittleEndian =
multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
// TODO: Fix
//BigEndianBitConverter.IsLittleEndian =
// multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian;
mountedVolEntry.FirstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x00);
mountedVolEntry.LastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x02);

View File

@@ -169,8 +169,6 @@ namespace DiscImageChef.Filesystems
if(!xdr) return false;
BigEndianBitConverter.IsLittleEndian = littleEndian;
int offset = 8;
while(offset < nvlist.Length)
{
@@ -637,9 +635,9 @@ namespace DiscImageChef.Filesystems
struct ZIO_Empty
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 472)]
public byte[] empty;
public ulong magic;
public ZIO_Checksum checksum;
public readonly byte[] empty;
public readonly ulong magic;
public readonly ZIO_Checksum checksum;
}
/// <summary>
@@ -648,10 +646,10 @@ namespace DiscImageChef.Filesystems
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct NVS_Method
{
public byte encoding;
public byte endian;
public byte reserved1;
public byte reserved2;
public readonly byte encoding;
public readonly byte endian;
public readonly byte reserved1;
public readonly byte reserved2;
}
/// <summary>
@@ -660,9 +658,9 @@ namespace DiscImageChef.Filesystems
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct NVS_XDR_Header
{
public NVS_Method encodingAndEndian;
public uint version;
public uint flags;
public readonly NVS_Method encodingAndEndian;
public readonly uint version;
public readonly uint flags;
}
enum NVS_DataTypes : uint
@@ -732,7 +730,7 @@ namespace DiscImageChef.Filesystems
struct DVA
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public ulong[] word;
public readonly ulong[] word;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
@@ -742,40 +740,40 @@ namespace DiscImageChef.Filesystems
/// Data virtual address
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public DVA[] dataVirtualAddress;
public readonly DVA[] dataVirtualAddress;
/// <summary>
/// Block properties
/// </summary>
public ulong properties;
public readonly ulong properties;
/// <summary>
/// Reserved for future expansion
/// </summary>
public ulong[] padding;
public readonly ulong[] padding;
/// <summary>
/// TXG when block was allocated
/// </summary>
public ulong birthTxg;
public readonly ulong birthTxg;
/// <summary>
/// Transaction group at birth
/// </summary>
public ulong birth;
public readonly ulong birth;
/// <summary>
/// Fill count
/// </summary>
public ulong fill;
public ZIO_Checksum checksum;
public readonly ulong fill;
public readonly ZIO_Checksum checksum;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct ZFS_Uberblock
{
public ulong magic;
public ulong spaVersion;
public ulong lastTxg;
public ulong guidSum;
public ulong timestamp;
public SPA_BlockPointer mosPtr;
public ulong softwareVersion;
public readonly ulong magic;
public readonly ulong spaVersion;
public readonly ulong lastTxg;
public readonly ulong guidSum;
public readonly ulong timestamp;
public readonly SPA_BlockPointer mosPtr;
public readonly ulong softwareVersion;
}
}
}