Use new little endian marshaller on partitions.

This commit is contained in:
2019-02-28 00:32:14 +00:00
parent 691b51aa1b
commit e1b79b8e54
12 changed files with 99 additions and 148 deletions

View File

@@ -36,6 +36,7 @@ using System.Runtime.InteropServices;
using System.Text;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -70,10 +71,7 @@ namespace DiscImageChef.Partitions
if(sector.Length < 512) return false;
IntPtr bbPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(sector, 0, bbPtr, 512);
AcornBootBlock bootBlock = (AcornBootBlock)Marshal.PtrToStructure(bbPtr, typeof(AcornBootBlock));
Marshal.FreeHGlobal(bbPtr);
AcornBootBlock bootBlock = Marshal.ByteArrayToStructureLittleEndian<AcornBootBlock>(sector);
int checksum = 0;
for(int i = 0; i < 0x1FF; i++) checksum = (checksum & 0xFF) + (checksum >> 8) + sector[i];
@@ -112,10 +110,7 @@ namespace DiscImageChef.Partitions
{
case TYPE_LINUX:
{
IntPtr tablePtr = Marshal.AllocHGlobal(512);
Marshal.Copy(map, 0, tablePtr, 512);
LinuxTable table = (LinuxTable)Marshal.PtrToStructure(tablePtr, typeof(LinuxTable));
Marshal.FreeHGlobal(tablePtr);
LinuxTable table = Marshal.ByteArrayToStructureLittleEndian<LinuxTable>(map);
foreach(LinuxEntry entry in table.entries)
{
@@ -139,10 +134,7 @@ namespace DiscImageChef.Partitions
case TYPE_RISCIX_MFM:
case TYPE_RISCIX_SCSI:
{
IntPtr tablePtr = Marshal.AllocHGlobal(512);
Marshal.Copy(map, 0, tablePtr, 512);
RiscIxTable table = (RiscIxTable)Marshal.PtrToStructure(tablePtr, typeof(RiscIxTable));
Marshal.FreeHGlobal(tablePtr);
RiscIxTable table = Marshal.ByteArrayToStructureLittleEndian<RiscIxTable>(map);
if(table.magic == RISCIX_MAGIC)
foreach(RiscIxEntry entry in table.partitions)

View File

@@ -36,6 +36,7 @@ using System.Runtime.InteropServices;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -73,10 +74,7 @@ namespace DiscImageChef.Partitions
if(sector.Length < 512) return false;
IntPtr lblPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(sector, 0, lblPtr, 512);
ApricotLabel label = (ApricotLabel)Marshal.PtrToStructure(lblPtr, typeof(ApricotLabel));
Marshal.FreeHGlobal(lblPtr);
ApricotLabel label = Marshal.ByteArrayToStructureLittleEndian<ApricotLabel>(sector);
// Not much to check but...
ulong deviceSectors = imagePlugin.Info.Sectors;
@@ -273,15 +271,18 @@ namespace DiscImageChef.Partitions
/// <summary>Operating system.</summary>
public byte operatingSystem;
/// <summary>Software write protection.</summary>
[MarshalAs(UnmanagedType.U1)] public bool writeProtected;
[MarshalAs(UnmanagedType.U1)]
public bool writeProtected;
/// <summary>Copy protected.</summary>
[MarshalAs(UnmanagedType.U1)] public bool copyProtected;
[MarshalAs(UnmanagedType.U1)]
public bool copyProtected;
/// <summary>Boot type.</summary>
public byte bootType;
/// <summary>Partitions.</summary>
public byte partitionCount;
/// <summary>Is hard disk?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool winchester;
[MarshalAs(UnmanagedType.U1)]
public bool winchester;
/// <summary>Sector size.</summary>
public ushort sectorSize;
/// <summary>Sectors per track.</summary>
@@ -334,15 +335,18 @@ namespace DiscImageChef.Partitions
/// <summary>Major BIOS version.</summary>
public byte biosMajorVersion;
/// <summary>Diagnostics enabled?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool diagnosticsFlag;
[MarshalAs(UnmanagedType.U1)]
public bool diagnosticsFlag;
/// <summary>Printer device.</summary>
public byte prnDevice;
/// <summary>Bell volume.</summary>
public byte bellVolume;
/// <summary>Cache enabled?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool enableCache;
[MarshalAs(UnmanagedType.U1)]
public bool enableCache;
/// <summary>Graphics enabled?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool enableGraphics;
[MarshalAs(UnmanagedType.U1)]
public bool enableGraphics;
/// <summary>Length in sectors of DOS.</summary>
public byte dosLength;
/// <summary>Length in sectors of FONT file.</summary>
@@ -358,7 +362,8 @@ namespace DiscImageChef.Partitions
/// <summary>Keyboard click volume.</summary>
public byte keyboardVolume;
/// <summary>Auto-repeat enabled?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool autorepeat;
[MarshalAs(UnmanagedType.U1)]
public bool autorepeat;
/// <summary>Auto-repeat lead-in.</summary>
public byte autorepeatLeadIn;
/// <summary>Auto-repeat interval.</summary>
@@ -373,7 +378,8 @@ namespace DiscImageChef.Partitions
/// <summary>Screen line width.</summary>
public byte lineWidth;
/// <summary>Screen disabled?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool imageOff;
[MarshalAs(UnmanagedType.U1)]
public bool imageOff;
/// <summary>Spare area for screen values expansion.</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 13)]
public byte[] spareScreen;
@@ -388,13 +394,16 @@ namespace DiscImageChef.Partitions
/// <summary>Stop bits.</summary>
public byte stopBits;
/// <summary>Parity enabled?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool parityCheck;
[MarshalAs(UnmanagedType.U1)]
public bool parityCheck;
/// <summary>Parity type.</summary>
public byte parityType;
/// <summary>Xon/Xoff enabled on TX.</summary>
[MarshalAs(UnmanagedType.U1)] public bool txXonXoff;
[MarshalAs(UnmanagedType.U1)]
public bool txXonXoff;
/// <summary>Xon/Xoff enabled on RX.</summary>
[MarshalAs(UnmanagedType.U1)] public bool rxXonXoff;
[MarshalAs(UnmanagedType.U1)]
public bool rxXonXoff;
/// <summary>Xon character.</summary>
public byte xonCharacter;
/// <summary>Xoff character.</summary>
@@ -402,30 +411,39 @@ namespace DiscImageChef.Partitions
/// <summary>Xon/Xoff buffer on RX.</summary>
public ushort rxXonXoffBuffer;
/// <summary>DTR/DSR enabled?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool dtrDsr;
[MarshalAs(UnmanagedType.U1)]
public bool dtrDsr;
/// <summary>CTS/RTS enabled?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool ctsRts;
[MarshalAs(UnmanagedType.U1)]
public bool ctsRts;
/// <summary>NULLs after CR.</summary>
public byte nullsAfterCr;
/// <summary>NULLs after 0xFF.</summary>
public byte nullsAfterFF;
/// <summary>Send LF after CR in serial port.</summary>
[MarshalAs(UnmanagedType.U1)] public bool lfAfterCRSerial;
[MarshalAs(UnmanagedType.U1)]
public bool lfAfterCRSerial;
/// <summary>BIOS error report in serial port.</summary>
[MarshalAs(UnmanagedType.U1)] public bool biosErrorReportSerial;
[MarshalAs(UnmanagedType.U1)]
public bool biosErrorReportSerial;
/// <summary>Spare area for serial port values expansion.</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 13)]
public byte[] spareSerial;
/// <summary>Send LF after CR in parallel port.</summary>
[MarshalAs(UnmanagedType.U1)] public bool lfAfterCrParallel;
[MarshalAs(UnmanagedType.U1)]
public bool lfAfterCrParallel;
/// <summary>Select line supported?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool selectLine;
[MarshalAs(UnmanagedType.U1)]
public bool selectLine;
/// <summary>Paper empty supported?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool paperEmpty;
[MarshalAs(UnmanagedType.U1)]
public bool paperEmpty;
/// <summary>Fault line supported?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool faultLine;
[MarshalAs(UnmanagedType.U1)]
public bool faultLine;
/// <summary>BIOS error report in parallel port.</summary>
[MarshalAs(UnmanagedType.U1)] public bool biosErrorReportParallel;
[MarshalAs(UnmanagedType.U1)]
public bool biosErrorReportParallel;
/// <summary>Spare area for parallel port values expansion.</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)]
public byte[] spareParallel;
@@ -433,9 +451,11 @@ namespace DiscImageChef.Partitions
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)]
public byte[] spareWinchester;
/// <summary>Parking enabled?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool parkingEnabled;
[MarshalAs(UnmanagedType.U1)]
public bool parkingEnabled;
/// <summary>Format protection?.</summary>
[MarshalAs(UnmanagedType.U1)] public bool formatProtection;
[MarshalAs(UnmanagedType.U1)]
public bool formatProtection;
/// <summary>Spare area for RAM disk values expansion.</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] spareRamDisk;

View File

@@ -37,6 +37,7 @@ using System.Runtime.InteropServices;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -73,7 +74,7 @@ namespace DiscImageChef.Partitions
{
byte[] sector = new byte[MAX_LABEL_SIZE];
Array.Copy(tmp, offset, sector, 0, MAX_LABEL_SIZE);
dl = GetDiskLabel(sector);
dl = Marshal.ByteArrayToStructureLittleEndian<DiskLabel>(sector);
DicConsole.DebugWriteLine("BSD plugin",
"dl.magic on sector {0} at offset {1} = 0x{2:X8} (expected 0x{3:X8})",
location + sectorOffset, offset, dl.d_magic, DISKMAGIC);
@@ -206,21 +207,13 @@ namespace DiscImageChef.Partitions
}
}
static DiskLabel GetDiskLabel(byte[] disklabel)
{
GCHandle handle = GCHandle.Alloc(disklabel, GCHandleType.Pinned);
DiskLabel dl = (DiskLabel)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DiskLabel));
handle.Free();
return dl;
}
static DiskLabel SwapDiskLabel(DiskLabel dl)
{
dl = (DiskLabel)Helpers.Marshal.SwapStructureMembersEndian(dl);
dl = (DiskLabel)Marshal.SwapStructureMembersEndian(dl);
for(int i = 0; i < dl.d_drivedata.Length; i++) dl.d_drivedata[i] = Swapping.Swap(dl.d_drivedata[i]);
for(int i = 0; i < dl.d_spare.Length; i++) dl.d_spare[i] = Swapping.Swap(dl.d_spare[i]);
for(int i = 0; i < dl.d_partitions.Length; i++)
dl.d_partitions[i] = (BSDPartition)Helpers.Marshal.SwapStructureMembersEndian(dl.d_partitions[i]);
dl.d_partitions[i] = (BSDPartition)Marshal.SwapStructureMembersEndian(dl.d_partitions[i]);
return dl;
}

View File

@@ -36,6 +36,7 @@ using System.Linq;
using System.Runtime.InteropServices;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -57,10 +58,7 @@ namespace DiscImageChef.Partitions
byte[] sector = imagePlugin.ReadSector(31 + sectorOffset);
if(sector.Length < 512) return false;
IntPtr tablePtr = Marshal.AllocHGlobal(512);
Marshal.Copy(sector, 0, tablePtr, 512);
DECLabel table = (DECLabel)Marshal.PtrToStructure(tablePtr, typeof(DECLabel));
Marshal.FreeHGlobal(tablePtr);
DECLabel table = Marshal.ByteArrayToStructureLittleEndian<DECLabel>(sector);
if(table.pt_magic != PT_MAGIC || table.pt_valid != PT_VALID) return false;

View File

@@ -35,6 +35,7 @@ using System.Collections.Generic;
using System.Runtime.InteropServices;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -57,10 +58,7 @@ namespace DiscImageChef.Partitions
byte[] sectors = imagePlugin.ReadSectors(sectorOffset, nSectors);
if(sectors.Length < 2048) return false;
IntPtr labelPtr = Marshal.AllocHGlobal(2048);
Marshal.Copy(sectors, 0, labelPtr, 2048);
Disklabel64 disklabel = (Disklabel64)Marshal.PtrToStructure(labelPtr, typeof(Disklabel64));
Marshal.FreeHGlobal(labelPtr);
Disklabel64 disklabel = Marshal.ByteArrayToStructureLittleEndian<Disklabel64>(sectors);
if(disklabel.d_magic != 0xC4464C59) return false;

View File

@@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -83,12 +84,7 @@ namespace DiscImageChef.Partitions
else
return false;
try
{
GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
hdr = (GptHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(GptHeader));
handle.Free();
}
try { hdr = Marshal.ByteArrayToStructureLittleEndian<GptHeader>(hdrBytes); }
catch { return false; }
DicConsole.DebugWriteLine("GPT Plugin", "hdr.revision = 0x{0:X8}", hdr.revision);
@@ -138,10 +134,7 @@ namespace DiscImageChef.Partitions
{
byte[] entryBytes = new byte[hdr.entriesSize];
Array.Copy(entriesBytes, hdr.entriesSize * i, entryBytes, 0, hdr.entriesSize);
GCHandle handle = GCHandle.Alloc(entryBytes, GCHandleType.Pinned);
GptEntry entry = (GptEntry)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(GptEntry));
handle.Free();
entries.Add(entry);
entries.Add(Marshal.ByteArrayToStructureLittleEndian<GptEntry>(entryBytes));
}
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
catch

View File

@@ -38,7 +38,7 @@ using DiscImageChef.CommonTypes.Enums;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using DiscImageChef.Helpers;
using Marshal = System.Runtime.InteropServices.Marshal;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -210,24 +210,14 @@ namespace DiscImageChef.Partitions
byte[] sector = imagePlugin.ReadSector(sectorOffset);
GCHandle handle = GCHandle.Alloc(sector, GCHandleType.Pinned);
MasterBootRecord mbr =
(MasterBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(MasterBootRecord));
TimedMasterBootRecord mbrTime =
(TimedMasterBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(TimedMasterBootRecord));
MasterBootRecord mbr = Marshal.ByteArrayToStructureLittleEndian<MasterBootRecord>(sector);
TimedMasterBootRecord mbrTime = Marshal.ByteArrayToStructureLittleEndian<TimedMasterBootRecord>(sector);
SerializedMasterBootRecord mbrSerial =
(SerializedMasterBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(SerializedMasterBootRecord));
ModernMasterBootRecord mbrModern =
(ModernMasterBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(ModernMasterBootRecord));
NecMasterBootRecord mbrNec =
(NecMasterBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(NecMasterBootRecord));
Marshal.ByteArrayToStructureLittleEndian<SerializedMasterBootRecord>(sector);
ModernMasterBootRecord mbrModern = Marshal.ByteArrayToStructureLittleEndian<ModernMasterBootRecord>(sector);
NecMasterBootRecord mbrNec = Marshal.ByteArrayToStructureLittleEndian<NecMasterBootRecord>(sector);
DiskManagerMasterBootRecord mbrOntrack =
(DiskManagerMasterBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(DiskManagerMasterBootRecord));
handle.Free();
Marshal.ByteArrayToStructureLittleEndian<DiskManagerMasterBootRecord>(sector);
DicConsole.DebugWriteLine("MBR plugin", "xmlmedia = {0}", imagePlugin.Info.XmlMediaType);
DicConsole.DebugWriteLine("MBR plugin", "mbr.magic = {0:X4}", mbr.magic);
@@ -369,11 +359,7 @@ namespace DiscImageChef.Partitions
{
sector = imagePlugin.ReadSector(lbaStart);
handle = GCHandle.Alloc(sector, GCHandleType.Pinned);
ExtendedBootRecord ebr =
(ExtendedBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(ExtendedBootRecord));
handle.Free();
ExtendedBootRecord ebr = Marshal.ByteArrayToStructureLittleEndian<ExtendedBootRecord>(sector);
DicConsole.DebugWriteLine("MBR plugin", "ebr.magic == MBR_Magic = {0}", ebr.magic == MBR_MAGIC);
@@ -493,10 +479,7 @@ namespace DiscImageChef.Partitions
byte[] sector = imagePlugin.ReadSector(start);
GCHandle handle = GCHandle.Alloc(sector, GCHandleType.Pinned);
ExtendedBootRecord mnx =
(ExtendedBootRecord)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(ExtendedBootRecord));
handle.Free();
ExtendedBootRecord mnx = Marshal.ByteArrayToStructureLittleEndian<ExtendedBootRecord>(sector);
DicConsole.DebugWriteLine("MBR plugin", "mnx.magic == MBR_Magic = {0}", mnx.magic == MBR_MAGIC);

View File

@@ -38,7 +38,7 @@ using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using DiscImageChef.Helpers;
using Marshal = System.Runtime.InteropServices.Marshal;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -61,10 +61,7 @@ namespace DiscImageChef.Partitions
// Prevent false positives with some FAT BPBs
if(Encoding.ASCII.GetString(bootSector, 0x36, 3) == "FAT") return false;
IntPtr tablePtr = Marshal.AllocHGlobal(256);
Marshal.Copy(sector, 0, tablePtr, 256);
PC98Table table = (PC98Table)Marshal.PtrToStructure(tablePtr, typeof(PC98Table));
Marshal.FreeHGlobal(tablePtr);
PC98Table table = Marshal.ByteArrayToStructureLittleEndian<PC98Table>(sector);
ulong counter = 0;

View File

@@ -36,6 +36,7 @@ using System.Linq;
using System.Runtime.InteropServices;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -54,10 +55,7 @@ namespace DiscImageChef.Partitions
byte[] sector = imagePlugin.ReadSector(sectorOffset);
if(sector.Length < 512) return false;
IntPtr tablePtr = Marshal.AllocHGlobal(512);
Marshal.Copy(sector, 0, tablePtr, 512);
RioKarmaTable table = (RioKarmaTable)Marshal.PtrToStructure(tablePtr, typeof(RioKarmaTable));
Marshal.FreeHGlobal(tablePtr);
RioKarmaTable table = Marshal.ByteArrayToStructureLittleEndian<RioKarmaTable>(sector);
if(table.magic != KARMA_MAGIC) return false;

View File

@@ -38,6 +38,7 @@ using System.Text;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -86,11 +87,9 @@ namespace DiscImageChef.Partitions
byte[] sunSector = imagePlugin.ReadSector(sectorOffset);
GCHandle handle = GCHandle.Alloc(sunSector, GCHandleType.Pinned);
dk_label dkl = (dk_label)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(dk_label));
dk_label8 dkl8 = (dk_label8)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(dk_label8));
dk_label16 dkl16 = (dk_label16)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(dk_label16));
handle.Free();
dk_label dkl = Marshal.ByteArrayToStructureLittleEndian<dk_label>(sunSector);
dk_label8 dkl8 = Marshal.ByteArrayToStructureLittleEndian<dk_label8>(sunSector);
dk_label16 dkl16 = Marshal.ByteArrayToStructureLittleEndian<dk_label16>(sunSector);
DicConsole.DebugWriteLine("Sun plugin", "dkl.dkl_magic = 0x{0:X4}", dkl.dkl_magic);
DicConsole.DebugWriteLine("Sun plugin", "dkl8.dkl_vtoc.v_sanity = 0x{0:X8}", dkl8.dkl_vtoc.v_sanity);
@@ -106,11 +105,9 @@ namespace DiscImageChef.Partitions
{
sunSector = imagePlugin.ReadSector(sectorOffset + 1);
handle = GCHandle.Alloc(sunSector, GCHandleType.Pinned);
dkl = (dk_label)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(dk_label));
dkl8 = (dk_label8)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(dk_label8));
dkl16 = (dk_label16)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(dk_label16));
handle.Free();
dkl = Marshal.ByteArrayToStructureLittleEndian<dk_label>(sunSector);
dkl8 = Marshal.ByteArrayToStructureLittleEndian<dk_label8>(sunSector);
dkl16 = Marshal.ByteArrayToStructureLittleEndian<dk_label16>(sunSector);
if(dkl.dkl_magic == DKL_MAGIC || dkl.dkl_magic == DKL_CIGAM)
if(dkl16.dkl_vtoc.v_sanity == VTOC_SANE || dkl16.dkl_vtoc.v_sanity == VTOC_ENAS)
@@ -322,9 +319,9 @@ namespace DiscImageChef.Partitions
static dk_label SwapDiskLabel(dk_label label)
{
DicConsole.DebugWriteLine("Sun plugin", "Swapping dk_label");
label = (dk_label)Helpers.Marshal.SwapStructureMembersEndian(label);
label = (dk_label)Marshal.SwapStructureMembersEndian(label);
for(int i = 0; i < label.dkl_map.Length; i++)
label.dkl_map[i] = (dk_map)Helpers.Marshal.SwapStructureMembersEndian(label.dkl_map[i]);
label.dkl_map[i] = (dk_map)Marshal.SwapStructureMembersEndian(label.dkl_map[i]);
return label;
}
@@ -332,9 +329,9 @@ namespace DiscImageChef.Partitions
static dk_label8 SwapDiskLabel(dk_label8 label)
{
DicConsole.DebugWriteLine("Sun plugin", "Swapping dk_label8");
label = (dk_label8)Helpers.Marshal.SwapStructureMembersEndian(label);
label = (dk_label8)Marshal.SwapStructureMembersEndian(label);
for(int i = 0; i < label.dkl_map.Length; i++)
label.dkl_map[i] = (dk_map)Helpers.Marshal.SwapStructureMembersEndian(label.dkl_map[i]);
label.dkl_map[i] = (dk_map)Marshal.SwapStructureMembersEndian(label.dkl_map[i]);
for(int i = 0; i < label.dkl_vtoc.v_bootinfo.Length; i++)
label.dkl_vtoc.v_bootinfo[i] = Swapping.Swap(label.dkl_vtoc.v_bootinfo[i]);
@@ -355,7 +352,7 @@ namespace DiscImageChef.Partitions
static dk_label16 SwapDiskLabel(dk_label16 label)
{
DicConsole.DebugWriteLine("Sun plugin", "Swapping dk_label16");
label = (dk_label16)Helpers.Marshal.SwapStructureMembersEndian(label);
label = (dk_label16)Marshal.SwapStructureMembersEndian(label);
for(int i = 0; i < label.dkl_vtoc.v_bootinfo.Length; i++)
label.dkl_vtoc.v_bootinfo[i] = Swapping.Swap(label.dkl_vtoc.v_bootinfo[i]);
for(int i = 0; i < label.dkl_vtoc.v_part.Length; i++)

View File

@@ -37,6 +37,7 @@ using System.Runtime.InteropServices;
using DiscImageChef.CommonTypes;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -80,19 +81,16 @@ namespace DiscImageChef.Partitions
PDInfo pd;
PDInfoOld pdold;
GCHandle handle;
if(magic == PD_MAGIC)
{
handle = GCHandle.Alloc(pdsector, GCHandleType.Pinned);
pd = (PDInfo)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PDInfo));
pdold = (PDInfoOld)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PDInfoOld));
handle.Free();
pd = Marshal.ByteArrayToStructureLittleEndian<PDInfo>(pdsector);
pdold = Marshal.ByteArrayToStructureLittleEndian<PDInfoOld>(pdsector);
}
else
{
pd = Helpers.Marshal.ByteArrayToStructureBigEndian<PDInfo>(pdsector);
pdold = Helpers.Marshal.ByteArrayToStructureBigEndian<PDInfoOld>(pdsector);
pd = Marshal.ByteArrayToStructureBigEndian<PDInfo>(pdsector);
pdold = Marshal.ByteArrayToStructureBigEndian<PDInfoOld>(pdsector);
}
DicConsole.DebugWriteLine("VTOC plugin", "pdinfo.driveid = {0}", pd.driveid);
@@ -149,15 +147,10 @@ namespace DiscImageChef.Partitions
{
magicFound = true;
DicConsole.DebugWriteLine("VTOC plugin", "New VTOC found at {0}", pdloc + sectorOffset + 1);
if(magic == VTOC_SANE)
{
handle = GCHandle.Alloc(vtocsector, GCHandleType.Pinned);
vtoc = (vtoc)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(vtoc));
handle.Free();
}
if(magic == VTOC_SANE) vtoc = Marshal.ByteArrayToStructureLittleEndian<vtoc>(vtocsector);
else
{
vtoc = Helpers.Marshal.ByteArrayToStructureBigEndian<vtoc>(vtocsector);
vtoc = Marshal.ByteArrayToStructureBigEndian<vtoc>(vtocsector);
for(int i = 0; i < vtoc.v_part.Length; i++)
{
vtoc.v_part[i].p_tag = (pTag)Swapping.Swap((ushort)vtoc.v_part[i].p_tag);
@@ -178,15 +171,10 @@ namespace DiscImageChef.Partitions
magicFound = true;
useOld = true;
DicConsole.DebugWriteLine("VTOC plugin", "Old VTOC found at {0}", pdloc + sectorOffset + 1);
if(magic == VTOC_SANE)
{
handle = GCHandle.Alloc(vtocsector, GCHandleType.Pinned);
vtocOld = (vtocold)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(vtocold));
handle.Free();
}
if(magic == VTOC_SANE) vtocOld = Marshal.ByteArrayToStructureLittleEndian<vtocold>(vtocsector);
else
{
vtocOld = Helpers.Marshal.ByteArrayToStructureBigEndian<vtocold>(vtocsector);
vtocOld = Marshal.ByteArrayToStructureBigEndian<vtocold>(vtocsector);
for(int i = 0; i < vtocOld.v_part.Length; i++)
{
vtocOld.v_part[i].p_tag = (pTag)Swapping.Swap((ushort)vtocOld.v_part[i].p_tag);
@@ -224,15 +212,10 @@ namespace DiscImageChef.Partitions
{
magicFound = true;
DicConsole.DebugWriteLine("VTOC plugin", "New VTOC found.");
if(magic == VTOC_SANE)
{
handle = GCHandle.Alloc(vtocsector, GCHandleType.Pinned);
vtoc = (vtoc)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(vtoc));
handle.Free();
}
if(magic == VTOC_SANE) vtoc = Marshal.ByteArrayToStructureLittleEndian<vtoc>(vtocsector);
else
{
vtoc = Helpers.Marshal.ByteArrayToStructureBigEndian<vtoc>(vtocsector);
vtoc = Marshal.ByteArrayToStructureBigEndian<vtoc>(vtocsector);
for(int i = 0; i < vtoc.v_part.Length; i++)
{
vtoc.v_part[i].p_tag = (pTag)Swapping.Swap((ushort)vtoc.v_part[i].p_tag);

View File

@@ -35,6 +35,7 @@ using System.Collections.Generic;
using System.Runtime.InteropServices;
using DiscImageChef.CommonTypes.Interfaces;
using DiscImageChef.Console;
using Marshal = DiscImageChef.Helpers.Marshal;
namespace DiscImageChef.Partitions
{
@@ -60,9 +61,7 @@ namespace DiscImageChef.Partitions
byte[] tblsector = imagePlugin.ReadSector(42 + sectorOffset);
GCHandle handle = GCHandle.Alloc(tblsector, GCHandleType.Pinned);
Partable xnxtbl = (Partable)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Partable));
handle.Free();
Partable xnxtbl = Marshal.ByteArrayToStructureLittleEndian<Partable>(tblsector);
DicConsole.DebugWriteLine("XENIX plugin", "xnxtbl.p_magic = 0x{0:X4} (should be 0x{1:X4})", xnxtbl.p_magic,
PAMAGIC);