mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add more optimized marshallers.
This commit is contained in:
@@ -37,6 +37,7 @@ using System.Text;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Interfaces;
|
||||
using DiscImageChef.Console;
|
||||
using Marshal = DiscImageChef.Helpers.Marshal;
|
||||
|
||||
namespace DiscImageChef.Partitions
|
||||
{
|
||||
@@ -83,8 +84,7 @@ namespace DiscImageChef.Partitions
|
||||
}
|
||||
else if(sectorSize < 256) return false;
|
||||
|
||||
AppleDriverDescriptorMap ddm =
|
||||
BigEndianMarshal.ByteArrayToStructureBigEndian<AppleDriverDescriptorMap>(ddmSector);
|
||||
AppleDriverDescriptorMap ddm = Marshal.ByteArrayToStructureBigEndian<AppleDriverDescriptorMap>(ddmSector);
|
||||
|
||||
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbSig = 0x{0:X4}", ddm.sbSig);
|
||||
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbBlockSize = {0}", ddm.sbBlockSize);
|
||||
@@ -104,7 +104,7 @@ namespace DiscImageChef.Partitions
|
||||
{
|
||||
byte[] tmp = new byte[8];
|
||||
Array.Copy(ddmSector, 18 + i * 8, tmp, 0, 8);
|
||||
ddm.sbMap[i] = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleDriverEntry>(tmp);
|
||||
ddm.sbMap[i] = Marshal.ByteArrayToStructureBigEndian<AppleDriverEntry>(tmp);
|
||||
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbMap[{1}].ddBlock = {0}",
|
||||
ddm.sbMap[i].ddBlock, i);
|
||||
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbMap[{1}].ddSize = {0}", ddm.sbMap[i].ddSize,
|
||||
@@ -134,7 +134,7 @@ namespace DiscImageChef.Partitions
|
||||
|
||||
byte[] partSector = imagePlugin.ReadSector(1 + sectorOffset);
|
||||
AppleOldDevicePartitionMap oldMap =
|
||||
BigEndianMarshal.ByteArrayToStructureBigEndian<AppleOldDevicePartitionMap>(partSector);
|
||||
Marshal.ByteArrayToStructureBigEndian<AppleOldDevicePartitionMap>(partSector);
|
||||
|
||||
// This is the easy one, no sector size mixing
|
||||
if(oldMap.pdSig == APM_MAGIC_OLD)
|
||||
@@ -144,7 +144,7 @@ namespace DiscImageChef.Partitions
|
||||
byte[] tmp = new byte[12];
|
||||
Array.Copy(partSector, i, tmp, 0, 12);
|
||||
AppleMapOldPartitionEntry oldEntry =
|
||||
BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapOldPartitionEntry>(tmp);
|
||||
Marshal.ByteArrayToStructureBigEndian<AppleMapOldPartitionEntry>(tmp);
|
||||
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdStart = {0}", oldEntry.pdStart,
|
||||
(i - 2) / 12);
|
||||
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdSize = {0}", oldEntry.pdSize,
|
||||
@@ -189,7 +189,7 @@ namespace DiscImageChef.Partitions
|
||||
{
|
||||
byte[] tmp = new byte[512];
|
||||
Array.Copy(ddmSector, 512, tmp, 0, 512);
|
||||
entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(tmp);
|
||||
entry = Marshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(tmp);
|
||||
// Check for a partition entry that's 512-byte aligned
|
||||
if(entry.signature == APM_MAGIC)
|
||||
{
|
||||
@@ -201,7 +201,7 @@ namespace DiscImageChef.Partitions
|
||||
}
|
||||
else
|
||||
{
|
||||
entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(partSector);
|
||||
entry = Marshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(partSector);
|
||||
if(entry.signature == APM_MAGIC)
|
||||
{
|
||||
DicConsole.DebugWriteLine("AppleMap Plugin", "Found aligned entry.");
|
||||
@@ -215,7 +215,7 @@ namespace DiscImageChef.Partitions
|
||||
}
|
||||
else
|
||||
{
|
||||
entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(partSector);
|
||||
entry = Marshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(partSector);
|
||||
if(entry.signature == APM_MAGIC)
|
||||
{
|
||||
DicConsole.DebugWriteLine("AppleMap Plugin", "Found aligned entry.");
|
||||
@@ -241,7 +241,7 @@ namespace DiscImageChef.Partitions
|
||||
{
|
||||
byte[] tmp = new byte[entrySize];
|
||||
Array.Copy(entries, i * entrySize, tmp, 0, entrySize);
|
||||
entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(tmp);
|
||||
entry = Marshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(tmp);
|
||||
if(entry.signature != APM_MAGIC) continue;
|
||||
|
||||
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].signature = 0x{1:X4}", i, entry.signature);
|
||||
|
||||
@@ -214,14 +214,13 @@ namespace DiscImageChef.Partitions
|
||||
return dl;
|
||||
}
|
||||
|
||||
static DiskLabel SwapDiskLabel(DiskLabel disklabel)
|
||||
static DiskLabel SwapDiskLabel(DiskLabel dl)
|
||||
{
|
||||
DiskLabel dl =
|
||||
(DiskLabel)BigEndianMarshal.SwapStructureMembersEndian(disklabel);
|
||||
dl = (DiskLabel)Helpers.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)BigEndianMarshal.SwapStructureMembersEndian(dl.d_partitions[i]);
|
||||
dl.d_partitions[i] = (BSDPartition)Helpers.Marshal.SwapStructureMembersEndian(dl.d_partitions[i]);
|
||||
|
||||
return dl;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ using System.Text;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Interfaces;
|
||||
using DiscImageChef.Console;
|
||||
using Marshal = DiscImageChef.Helpers.Marshal;
|
||||
|
||||
namespace DiscImageChef.Partitions
|
||||
{
|
||||
@@ -76,14 +77,14 @@ namespace DiscImageChef.Partitions
|
||||
default: return false;
|
||||
}
|
||||
|
||||
X68kTable table = BigEndianMarshal.ByteArrayToStructureBigEndian<X68kTable>(sector);
|
||||
X68kTable table = Marshal.ByteArrayToStructureBigEndian<X68kTable>(sector);
|
||||
|
||||
DicConsole.DebugWriteLine("Human68k plugin", "table.magic = {0:X4}", table.magic);
|
||||
|
||||
if(table.magic != X68K_MAGIC) return false;
|
||||
|
||||
for(int i = 0; i < table.entries.Length; i++)
|
||||
table.entries[i] = (X68kEntry)BigEndianMarshal.SwapStructureMembersEndian(table.entries[i]);
|
||||
table.entries[i] = (X68kEntry)Marshal.SwapStructureMembersEndian(table.entries[i]);
|
||||
|
||||
DicConsole.DebugWriteLine("Human68k plugin", "table.size = {0:X4}", table.size);
|
||||
DicConsole.DebugWriteLine("Human68k plugin", "table.size2 = {0:X4}", table.size2);
|
||||
|
||||
@@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes.Enums;
|
||||
using DiscImageChef.CommonTypes.Interfaces;
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Helpers;
|
||||
using Marshal = System.Runtime.InteropServices.Marshal;
|
||||
|
||||
namespace DiscImageChef.Partitions
|
||||
{
|
||||
|
||||
@@ -38,6 +38,7 @@ using System.Text;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Interfaces;
|
||||
using DiscImageChef.Console;
|
||||
using Marshal = DiscImageChef.Helpers.Marshal;
|
||||
|
||||
// Information learnt from XNU source and testing against real disks
|
||||
namespace DiscImageChef.Partitions
|
||||
@@ -95,10 +96,10 @@ namespace DiscImageChef.Partitions
|
||||
|
||||
labelSector = imagePlugin.ReadSectors(labelPosition, sectorsToRead);
|
||||
|
||||
NeXTLabel label = BigEndianMarshal.ByteArrayToStructureBigEndian<NeXTLabel>(labelSector);
|
||||
NeXTLabel label = Marshal.ByteArrayToStructureBigEndian<NeXTLabel>(labelSector);
|
||||
byte[] disktabB = new byte[498];
|
||||
Array.Copy(labelSector, 44, disktabB, 0, 498);
|
||||
label.dl_dt = BigEndianMarshal.ByteArrayToStructureBigEndian<NeXTDiskTab>(disktabB);
|
||||
label.dl_dt = Marshal.ByteArrayToStructureBigEndian<NeXTDiskTab>(disktabB);
|
||||
label.dl_dt.d_partitions = new NeXTEntry[8];
|
||||
|
||||
DicConsole.DebugWriteLine("NeXT Plugin", "label.dl_version = 0x{0:X8}", label.dl_version);
|
||||
@@ -138,7 +139,7 @@ namespace DiscImageChef.Partitions
|
||||
{
|
||||
byte[] partB = new byte[44];
|
||||
Array.Copy(labelSector, 44 + 146 + 44 * i, partB, 0, 44);
|
||||
label.dl_dt.d_partitions[i] = BigEndianMarshal.ByteArrayToStructureBigEndian<NeXTEntry>(partB);
|
||||
label.dl_dt.d_partitions[i] = Marshal.ByteArrayToStructureBigEndian<NeXTEntry>(partB);
|
||||
DicConsole.DebugWriteLine("NeXT Plugin", "label.dl_dt.d_partitions[{0}].p_base = {1}", i,
|
||||
label.dl_dt.d_partitions[i].p_base);
|
||||
DicConsole.DebugWriteLine("NeXT Plugin", "label.dl_dt.d_partitions[{0}].p_size = {1}", i,
|
||||
|
||||
@@ -38,6 +38,7 @@ using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Interfaces;
|
||||
using DiscImageChef.Console;
|
||||
using DiscImageChef.Helpers;
|
||||
using Marshal = System.Runtime.InteropServices.Marshal;
|
||||
|
||||
namespace DiscImageChef.Partitions
|
||||
{
|
||||
|
||||
@@ -37,6 +37,7 @@ using System.Runtime.InteropServices;
|
||||
using DiscImageChef.CommonTypes;
|
||||
using DiscImageChef.CommonTypes.Interfaces;
|
||||
using DiscImageChef.Console;
|
||||
using Marshal = DiscImageChef.Helpers.Marshal;
|
||||
|
||||
#pragma warning disable 169
|
||||
#pragma warning disable 649
|
||||
@@ -59,11 +60,12 @@ namespace DiscImageChef.Partitions
|
||||
byte[] sector = imagePlugin.ReadSector(sectorOffset);
|
||||
if(sector.Length < 512) return false;
|
||||
|
||||
SGILabel dvh = BigEndianMarshal.ByteArrayToStructureBigEndian<SGILabel>(sector);
|
||||
SGILabel dvh = Marshal.ByteArrayToStructureBigEndian<SGILabel>(sector);
|
||||
for(int i = 0; i < dvh.volume.Length; i++)
|
||||
dvh.volume[i] = (SGIVolume)BigEndianMarshal.SwapStructureMembersEndian(dvh.volume[i]);
|
||||
dvh.volume[i] = (SGIVolume)Marshal.SwapStructureMembersEndian(dvh.volume[i]);
|
||||
|
||||
for(int i = 0; i < dvh.partitions.Length; i++)
|
||||
dvh.partitions[i] = (SGIPartition)BigEndianMarshal.SwapStructureMembersEndian(dvh.partitions[i]);
|
||||
dvh.partitions[i] = (SGIPartition)Marshal.SwapStructureMembersEndian(dvh.partitions[i]);
|
||||
|
||||
DicConsole.DebugWriteLine("SGIVH plugin", "dvh.magic = 0x{0:X8} (should be 0x{1:X8})", dvh.magic,
|
||||
SGI_MAGIC);
|
||||
|
||||
@@ -322,55 +322,56 @@ namespace DiscImageChef.Partitions
|
||||
static dk_label SwapDiskLabel(dk_label label)
|
||||
{
|
||||
DicConsole.DebugWriteLine("Sun plugin", "Swapping dk_label");
|
||||
dk_label lebal = (dk_label)BigEndianMarshal.SwapStructureMembersEndian(label);
|
||||
label = (dk_label)Helpers.Marshal.SwapStructureMembersEndian(label);
|
||||
for(int i = 0; i < label.dkl_map.Length; i++)
|
||||
lebal.dkl_map[i] = (dk_map)BigEndianMarshal.SwapStructureMembersEndian(label.dkl_map[i]);
|
||||
label.dkl_map[i] = (dk_map)Helpers.Marshal.SwapStructureMembersEndian(label.dkl_map[i]);
|
||||
|
||||
return lebal;
|
||||
return label;
|
||||
}
|
||||
|
||||
static dk_label8 SwapDiskLabel(dk_label8 label)
|
||||
{
|
||||
DicConsole.DebugWriteLine("Sun plugin", "Swapping dk_label8");
|
||||
dk_label8 lebal = (dk_label8)BigEndianMarshal.SwapStructureMembersEndian(label);
|
||||
label = (dk_label8)Helpers.Marshal.SwapStructureMembersEndian(label);
|
||||
for(int i = 0; i < label.dkl_map.Length; i++)
|
||||
lebal.dkl_map[i] = (dk_map)BigEndianMarshal.SwapStructureMembersEndian(label.dkl_map[i]);
|
||||
label.dkl_map[i] = (dk_map)Helpers.Marshal.SwapStructureMembersEndian(label.dkl_map[i]);
|
||||
|
||||
for(int i = 0; i < label.dkl_vtoc.v_bootinfo.Length; i++)
|
||||
lebal.dkl_vtoc.v_bootinfo[i] = Swapping.Swap(label.dkl_vtoc.v_bootinfo[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++)
|
||||
{
|
||||
lebal.dkl_vtoc.v_part[i].p_flag = (SunFlags)Swapping.Swap((ushort)label.dkl_vtoc.v_part[i].p_flag);
|
||||
lebal.dkl_vtoc.v_part[i].p_tag = (SunTag)Swapping.Swap((ushort)label.dkl_vtoc.v_part[i].p_tag);
|
||||
label.dkl_vtoc.v_part[i].p_flag = (SunFlags)Swapping.Swap((ushort)label.dkl_vtoc.v_part[i].p_flag);
|
||||
label.dkl_vtoc.v_part[i].p_tag = (SunTag)Swapping.Swap((ushort)label.dkl_vtoc.v_part[i].p_tag);
|
||||
}
|
||||
|
||||
for(int i = 0; i < label.dkl_vtoc.v_timestamp.Length; i++)
|
||||
lebal.dkl_vtoc.v_timestamp[i] = Swapping.Swap(label.dkl_vtoc.v_timestamp[i]);
|
||||
label.dkl_vtoc.v_timestamp[i] = Swapping.Swap(label.dkl_vtoc.v_timestamp[i]);
|
||||
for(int i = 0; i < label.dkl_vtoc.v_reserved.Length; i++)
|
||||
lebal.dkl_vtoc.v_reserved[i] = Swapping.Swap(label.dkl_vtoc.v_reserved[i]);
|
||||
label.dkl_vtoc.v_reserved[i] = Swapping.Swap(label.dkl_vtoc.v_reserved[i]);
|
||||
|
||||
return lebal;
|
||||
return label;
|
||||
}
|
||||
|
||||
static dk_label16 SwapDiskLabel(dk_label16 label)
|
||||
{
|
||||
DicConsole.DebugWriteLine("Sun plugin", "Swapping dk_label16");
|
||||
dk_label16 lebal = (dk_label16)BigEndianMarshal.SwapStructureMembersEndian(label);
|
||||
label = (dk_label16)Helpers.Marshal.SwapStructureMembersEndian(label);
|
||||
for(int i = 0; i < label.dkl_vtoc.v_bootinfo.Length; i++)
|
||||
lebal.dkl_vtoc.v_bootinfo[i] = Swapping.Swap(label.dkl_vtoc.v_bootinfo[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++)
|
||||
{
|
||||
lebal.dkl_vtoc.v_part[i].p_flag = (SunFlags)Swapping.Swap((ushort)label.dkl_vtoc.v_part[i].p_flag);
|
||||
lebal.dkl_vtoc.v_part[i].p_tag = (SunTag)Swapping.Swap((ushort)label.dkl_vtoc.v_part[i].p_tag);
|
||||
lebal.dkl_vtoc.v_part[i].p_size = Swapping.Swap(label.dkl_vtoc.v_part[i].p_size);
|
||||
lebal.dkl_vtoc.v_part[i].p_start = Swapping.Swap(label.dkl_vtoc.v_part[i].p_start);
|
||||
label.dkl_vtoc.v_part[i].p_flag = (SunFlags)Swapping.Swap((ushort)label.dkl_vtoc.v_part[i].p_flag);
|
||||
label.dkl_vtoc.v_part[i].p_tag = (SunTag)Swapping.Swap((ushort)label.dkl_vtoc.v_part[i].p_tag);
|
||||
label.dkl_vtoc.v_part[i].p_size = Swapping.Swap(label.dkl_vtoc.v_part[i].p_size);
|
||||
label.dkl_vtoc.v_part[i].p_start = Swapping.Swap(label.dkl_vtoc.v_part[i].p_start);
|
||||
}
|
||||
|
||||
for(int i = 0; i < label.dkl_vtoc.v_timestamp.Length; i++)
|
||||
lebal.dkl_vtoc.v_timestamp[i] = Swapping.Swap(label.dkl_vtoc.v_timestamp[i]);
|
||||
label.dkl_vtoc.v_timestamp[i] = Swapping.Swap(label.dkl_vtoc.v_timestamp[i]);
|
||||
for(int i = 0; i < label.dkl_vtoc.v_reserved.Length; i++)
|
||||
lebal.dkl_vtoc.v_reserved[i] = Swapping.Swap(label.dkl_vtoc.v_reserved[i]);
|
||||
label.dkl_vtoc.v_reserved[i] = Swapping.Swap(label.dkl_vtoc.v_reserved[i]);
|
||||
|
||||
return lebal;
|
||||
return label;
|
||||
}
|
||||
|
||||
static string SunFlagsToString(SunFlags flags)
|
||||
|
||||
@@ -91,8 +91,8 @@ namespace DiscImageChef.Partitions
|
||||
}
|
||||
else
|
||||
{
|
||||
pd = BigEndianMarshal.ByteArrayToStructureBigEndian<PDInfo>(pdsector);
|
||||
pdold = BigEndianMarshal.ByteArrayToStructureBigEndian<PDInfoOld>(pdsector);
|
||||
pd = Helpers.Marshal.ByteArrayToStructureBigEndian<PDInfo>(pdsector);
|
||||
pdold = Helpers.Marshal.ByteArrayToStructureBigEndian<PDInfoOld>(pdsector);
|
||||
}
|
||||
|
||||
DicConsole.DebugWriteLine("VTOC plugin", "pdinfo.driveid = {0}", pd.driveid);
|
||||
@@ -157,7 +157,7 @@ namespace DiscImageChef.Partitions
|
||||
}
|
||||
else
|
||||
{
|
||||
vtoc = BigEndianMarshal.ByteArrayToStructureBigEndian<vtoc>(vtocsector);
|
||||
vtoc = Helpers.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);
|
||||
@@ -186,7 +186,7 @@ namespace DiscImageChef.Partitions
|
||||
}
|
||||
else
|
||||
{
|
||||
vtocOld = BigEndianMarshal.ByteArrayToStructureBigEndian<vtocold>(vtocsector);
|
||||
vtocOld = Helpers.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);
|
||||
@@ -232,7 +232,7 @@ namespace DiscImageChef.Partitions
|
||||
}
|
||||
else
|
||||
{
|
||||
vtoc = BigEndianMarshal.ByteArrayToStructureBigEndian<vtoc>(vtocsector);
|
||||
vtoc = Helpers.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);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
@@ -75,7 +76,7 @@ namespace DiscImageChef.Partitions
|
||||
if(sector.Length < 512) return false;
|
||||
|
||||
Xbox360DevKitPartitionTable table =
|
||||
BigEndianMarshal.ByteArrayToStructureBigEndian<Xbox360DevKitPartitionTable>(sector);
|
||||
Marshal.ByteArrayToStructureBigEndian<Xbox360DevKitPartitionTable>(sector);
|
||||
|
||||
if(table.magic == XBOX360_DEVKIT_MAGIC &&
|
||||
table.contentOff + table.contentLen <= imagePlugin.Info.Sectors &&
|
||||
|
||||
Reference in New Issue
Block a user