Use new little endian marshaller on filesystems.

This commit is contained in:
2019-03-01 00:28:55 +00:00
parent f95633046e
commit 0ec558da55
45 changed files with 154 additions and 531 deletions

View File

@@ -63,11 +63,7 @@ namespace DiscImageChef.Filesystems
if(imagePlugin.Info.Sectors != 800 && imagePlugin.Info.Sectors != 1600) return false;
byte[] sector = imagePlugin.ReadSector(0);
AODOS_BootBlock bb = new AODOS_BootBlock();
IntPtr bbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(bb));
Marshal.Copy(sector, 0, bbPtr, Marshal.SizeOf(bb));
bb = (AODOS_BootBlock)Marshal.PtrToStructure(bbPtr, typeof(AODOS_BootBlock));
Marshal.FreeHGlobal(bbPtr);
AODOS_BootBlock bb = Helpers.Marshal.ByteArrayToStructureLittleEndian<AODOS_BootBlock>(sector);
return bb.identifier.SequenceEqual(AODOSIdentifier);
}
@@ -77,11 +73,7 @@ namespace DiscImageChef.Filesystems
{
Encoding = Encoding.GetEncoding("koi8-r");
byte[] sector = imagePlugin.ReadSector(0);
AODOS_BootBlock bb = new AODOS_BootBlock();
IntPtr bbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(bb));
Marshal.Copy(sector, 0, bbPtr, Marshal.SizeOf(bb));
bb = (AODOS_BootBlock)Marshal.PtrToStructure(bbPtr, typeof(AODOS_BootBlock));
Marshal.FreeHGlobal(bbPtr);
AODOS_BootBlock bb = Helpers.Marshal.ByteArrayToStructureLittleEndian<AODOS_BootBlock>(sector);
StringBuilder sbInformation = new StringBuilder();

View File

@@ -59,10 +59,7 @@ namespace DiscImageChef.Filesystems
try
{
GCHandle handle = GCHandle.Alloc(sector, GCHandleType.Pinned);
nxSb = (ApfsContainerSuperBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(ApfsContainerSuperBlock));
handle.Free();
nxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<ApfsContainerSuperBlock>(sector);
}
catch { return false; }
@@ -84,10 +81,7 @@ namespace DiscImageChef.Filesystems
try
{
GCHandle handle = GCHandle.Alloc(sector, GCHandleType.Pinned);
nxSb = (ApfsContainerSuperBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(ApfsContainerSuperBlock));
handle.Free();
nxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<ApfsContainerSuperBlock>(sector);
}
catch { return; }

View File

@@ -94,22 +94,17 @@ namespace DiscImageChef.Filesystems
if(imagePlugin.Info.SectorSize < 256) return false;
byte[] sector;
GCHandle ptr;
// ADFS-S, ADFS-M, ADFS-L, ADFS-D without partitions
if(partition.Start == 0)
{
sector = imagePlugin.ReadSector(0);
byte oldChk0 = AcornMapChecksum(sector, 255);
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
OldMapSector0 oldMap0 =
(OldMapSector0)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(OldMapSector0));
OldMapSector0 oldMap0 = Helpers.Marshal.ByteArrayToStructureLittleEndian<OldMapSector0>(sector);
sector = imagePlugin.ReadSector(1);
byte oldChk1 = AcornMapChecksum(sector, 255);
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
OldMapSector1 oldMap1 =
(OldMapSector1)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(OldMapSector1));
OldMapSector1 oldMap1 = Helpers.Marshal.ByteArrayToStructureLittleEndian<OldMapSector1>(sector);
DicConsole.DebugWriteLine("ADFS Plugin", "oldMap0.checksum = {0}", oldMap0.checksum);
DicConsole.DebugWriteLine("ADFS Plugin", "oldChk0 = {0}", oldChk0);
@@ -121,8 +116,7 @@ namespace DiscImageChef.Filesystems
byte[] tmp = new byte[256];
Array.Copy(sector, 256, tmp, 0, 256);
oldChk1 = AcornMapChecksum(tmp, 255);
ptr = GCHandle.Alloc(tmp, GCHandleType.Pinned);
oldMap1 = (OldMapSector1)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(OldMapSector1));
oldMap1 = Helpers.Marshal.ByteArrayToStructureLittleEndian<OldMapSector1>(tmp);
}
DicConsole.DebugWriteLine("ADFS Plugin", "oldMap1.checksum = {0}", oldMap1.checksum);
@@ -144,9 +138,7 @@ namespace DiscImageChef.Filesystems
sector = tmp;
}
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
OldDirectory oldRoot =
(OldDirectory)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(OldDirectory));
OldDirectory oldRoot = Helpers.Marshal.ByteArrayToStructureLittleEndian<OldDirectory>(sector);
byte dirChk = AcornDirectoryChecksum(sector, (int)OLD_DIRECTORY_SIZE - 1);
DicConsole.DebugWriteLine("ADFS Plugin", "oldRoot.header.magic at 0x200 = {0}",
@@ -173,8 +165,7 @@ namespace DiscImageChef.Filesystems
sector = tmp;
}
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
oldRoot = (OldDirectory)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(OldDirectory));
oldRoot = Helpers.Marshal.ByteArrayToStructureLittleEndian<OldDirectory>(sector);
dirChk = AcornDirectoryChecksum(sector, (int)OLD_DIRECTORY_SIZE - 1);
DicConsole.DebugWriteLine("ADFS Plugin", "oldRoot.header.magic at 0x400 = {0}",
@@ -212,16 +203,12 @@ namespace DiscImageChef.Filesystems
if(newChk == sector[0] && newChk != 0)
{
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
NewMap nmap = (NewMap)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(NewMap));
ptr.Free();
NewMap nmap = Helpers.Marshal.ByteArrayToStructureLittleEndian<NewMap>(sector);
drSb = nmap.discRecord;
}
else if(bootChk == bootSector[0x1FF])
{
ptr = GCHandle.Alloc(bootSector, GCHandleType.Pinned);
BootBlock bBlock = (BootBlock)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(BootBlock));
ptr.Free();
BootBlock bBlock = Helpers.Marshal.ByteArrayToStructureLittleEndian<BootBlock>(bootSector);
drSb = bBlock.discRecord;
}
else return false;
@@ -262,7 +249,6 @@ namespace DiscImageChef.Filesystems
ulong sbSector;
byte[] sector;
uint sectorsToRead;
GCHandle ptr;
ulong bytes;
// ADFS-S, ADFS-M, ADFS-L, ADFS-D without partitions
@@ -270,15 +256,11 @@ namespace DiscImageChef.Filesystems
{
sector = imagePlugin.ReadSector(0);
byte oldChk0 = AcornMapChecksum(sector, 255);
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
OldMapSector0 oldMap0 =
(OldMapSector0)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(OldMapSector0));
OldMapSector0 oldMap0 = Helpers.Marshal.ByteArrayToStructureLittleEndian<OldMapSector0>(sector);
sector = imagePlugin.ReadSector(1);
byte oldChk1 = AcornMapChecksum(sector, 255);
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
OldMapSector1 oldMap1 =
(OldMapSector1)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(OldMapSector1));
OldMapSector1 oldMap1 = Helpers.Marshal.ByteArrayToStructureLittleEndian<OldMapSector1>(sector);
// According to documentation map1 MUST start on sector 1. On ADFS-D it starts at 0x100, not on sector 1 (0x400)
if(oldMap0.checksum == oldChk0 && oldMap1.checksum != oldChk1 && sector.Length >= 512)
@@ -287,8 +269,7 @@ namespace DiscImageChef.Filesystems
byte[] tmp = new byte[256];
Array.Copy(sector, 256, tmp, 0, 256);
oldChk1 = AcornMapChecksum(tmp, 255);
ptr = GCHandle.Alloc(tmp, GCHandleType.Pinned);
oldMap1 = (OldMapSector1)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(OldMapSector1));
oldMap1 = Helpers.Marshal.ByteArrayToStructureLittleEndian<OldMapSector1>(tmp);
}
if(oldMap0.checksum == oldChk0 && oldMap1.checksum == oldChk1 && oldMap0.checksum != 0 &&
@@ -325,9 +306,7 @@ namespace DiscImageChef.Filesystems
sector = tmp;
}
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
OldDirectory oldRoot =
(OldDirectory)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(OldDirectory));
OldDirectory oldRoot = Helpers.Marshal.ByteArrayToStructureLittleEndian<OldDirectory>(sector);
if(oldRoot.header.magic == OLD_DIR_MAGIC && oldRoot.tail.magic == OLD_DIR_MAGIC)
namebytes = oldRoot.tail.name;
@@ -348,9 +327,7 @@ namespace DiscImageChef.Filesystems
sector = tmp;
}
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
oldRoot = (OldDirectory)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(),
typeof(OldDirectory));
oldRoot = Helpers.Marshal.ByteArrayToStructureLittleEndian<OldDirectory>(sector);
if(oldRoot.header.magic == OLD_DIR_MAGIC && oldRoot.tail.magic == OLD_DIR_MAGIC)
namebytes = oldRoot.tail.name;
@@ -366,10 +343,7 @@ namespace DiscImageChef.Filesystems
sector = tmp;
}
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
NewDirectory newRoot =
(NewDirectory)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(),
typeof(NewDirectory));
NewDirectory newRoot = Helpers.Marshal.ByteArrayToStructureLittleEndian<NewDirectory>(sector);
if(newRoot.header.magic == NEW_DIR_MAGIC && newRoot.tail.magic == NEW_DIR_MAGIC)
namebytes = newRoot.tail.title;
}
@@ -418,16 +392,12 @@ namespace DiscImageChef.Filesystems
if(newChk == sector[0] && newChk != 0)
{
ptr = GCHandle.Alloc(sector, GCHandleType.Pinned);
NewMap nmap = (NewMap)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(NewMap));
ptr.Free();
NewMap nmap = Helpers.Marshal.ByteArrayToStructureLittleEndian<NewMap>(sector);
drSb = nmap.discRecord;
}
else if(bootChk == bootSector[0x1FF])
{
ptr = GCHandle.Alloc(bootSector, GCHandleType.Pinned);
BootBlock bBlock = (BootBlock)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(BootBlock));
ptr.Free();
BootBlock bBlock = Helpers.Marshal.ByteArrayToStructureLittleEndian<BootBlock>(sector);
drSb = bBlock.discRecord;
}
else return;

View File

@@ -98,10 +98,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
if(debug) catalogMs.Write(catSectorB, 0, catSectorB.Length);
// Read the catalog sector
IntPtr catPtr = Marshal.AllocHGlobal(256);
Marshal.Copy(catSectorB, 0, catPtr, 256);
CatalogSector catSector = (CatalogSector)Marshal.PtrToStructure(catPtr, typeof(CatalogSector));
Marshal.FreeHGlobal(catPtr);
CatalogSector catSector = Helpers.Marshal.ByteArrayToStructureLittleEndian<CatalogSector>(catSectorB);
foreach(FileEntry entry in catSector.entries.Where(entry => entry.extentTrack > 0))
{

View File

@@ -179,10 +179,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
if(debug) tsListMs.Write(tsSectorB, 0, tsSectorB.Length);
// Read the track/sector list sector
IntPtr tsPtr = Marshal.AllocHGlobal(256);
Marshal.Copy(tsSectorB, 0, tsPtr, 256);
TrackSectorList tsSector = (TrackSectorList)Marshal.PtrToStructure(tsPtr, typeof(TrackSectorList));
Marshal.FreeHGlobal(tsPtr);
TrackSectorList tsSector = Helpers.Marshal.ByteArrayToStructureLittleEndian<TrackSectorList>(tsSectorB);
if(tsSector.sectorOffset > expectedBlock)
{

View File

@@ -52,11 +52,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
int spt = imagePlugin.Info.Sectors == 455 ? 13 : 16;
byte[] vtocB = imagePlugin.ReadSector((ulong)(17 * spt));
vtoc = new Vtoc();
IntPtr vtocPtr = Marshal.AllocHGlobal(256);
Marshal.Copy(vtocB, 0, vtocPtr, 256);
vtoc = (Vtoc)Marshal.PtrToStructure(vtocPtr, typeof(Vtoc));
Marshal.FreeHGlobal(vtocPtr);
vtoc = Helpers.Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocB);
return vtoc.catalogSector < spt && vtoc.maxTrackSectorPairsPerSector <= 122 &&
vtoc.sectorsPerTrack == spt && vtoc.bytesPerSector == 256;
@@ -73,11 +69,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
spt = imagePlugin.Info.Sectors == 455 ? 13 : 16;
byte[] vtocB = imagePlugin.ReadSector((ulong)(17 * spt));
vtoc = new Vtoc();
IntPtr vtocPtr = Marshal.AllocHGlobal(256);
Marshal.Copy(vtocB, 0, vtocPtr, 256);
vtoc = (Vtoc)Marshal.PtrToStructure(vtocPtr, typeof(Vtoc));
Marshal.FreeHGlobal(vtocPtr);
vtoc = Helpers.Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocB);
sb.AppendLine("Apple DOS File System");
sb.AppendLine();

View File

@@ -77,11 +77,7 @@ namespace DiscImageChef.Filesystems.AppleDOS
// Read the VTOC
vtocBlocks = device.ReadSector((ulong)(17 * sectorsPerTrack));
vtoc = new Vtoc();
IntPtr vtocPtr = Marshal.AllocHGlobal(256);
Marshal.Copy(vtocBlocks, 0, vtocPtr, 256);
vtoc = (Vtoc)Marshal.PtrToStructure(vtocPtr, typeof(Vtoc));
Marshal.FreeHGlobal(vtocPtr);
vtoc = Helpers.Marshal.ByteArrayToStructureLittleEndian<Vtoc>(vtocBlocks);
track1UsedByFiles = false;
track2UsedByFiles = false;

View File

@@ -94,10 +94,7 @@ namespace DiscImageChef.Filesystems
byte[] sbSector = new byte[AFS_SUPERBLOCK_SIZE];
Array.Copy(tmp, offset, sbSector, 0, AFS_SUPERBLOCK_SIZE);
GCHandle handle = GCHandle.Alloc(sbSector, GCHandleType.Pinned);
AtheosSuperBlock afsSb =
(AtheosSuperBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(AtheosSuperBlock));
handle.Free();
AtheosSuperBlock afsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<AtheosSuperBlock>(sbSector);
sb.AppendLine("Atheos filesystem");

View File

@@ -129,9 +129,7 @@ namespace DiscImageChef.Filesystems
if(littleEndian)
{
GCHandle handle = GCHandle.Alloc(sbSector, GCHandleType.Pinned);
besb = (BeSuperBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(BeSuperBlock));
handle.Free();
besb = Helpers.Marshal.ByteArrayToStructureLittleEndian<BeSuperBlock>(sbSector);
}
else besb = Helpers.Marshal.ByteArrayToStructureBigEndian<BeSuperBlock>(sbSector);

View File

@@ -67,9 +67,7 @@ namespace DiscImageChef.Filesystems
try
{
GCHandle handle = GCHandle.Alloc(sector, GCHandleType.Pinned);
btrfsSb = (SuperBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SuperBlock));
handle.Free();
btrfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<SuperBlock>(sector);
}
catch { return false; }
@@ -94,9 +92,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(sbSectorOff + partition.Start, sbSectorSize);
GCHandle handle = GCHandle.Alloc(sector, GCHandleType.Pinned);
SuperBlock btrfsSb = (SuperBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SuperBlock));
handle.Free();
SuperBlock btrfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<SuperBlock>(sector);
DicConsole.DebugWriteLine("BTRFS Plugin", "btrfsSb.checksum = {0}", btrfsSb.checksum);
DicConsole.DebugWriteLine("BTRFS Plugin", "btrfsSb.uuid = {0}", btrfsSb.uuid);

View File

@@ -63,11 +63,7 @@ namespace DiscImageChef.Filesystems
if(imagePlugin.Info.Sectors == 3200)
{
sector = imagePlugin.ReadSector(1560);
CommodoreHeader cbmHdr = new CommodoreHeader();
IntPtr cbmHdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbmHdr));
Marshal.Copy(sector, 0, cbmHdrPtr, Marshal.SizeOf(cbmHdr));
cbmHdr = (CommodoreHeader)Marshal.PtrToStructure(cbmHdrPtr, typeof(CommodoreHeader));
Marshal.FreeHGlobal(cbmHdrPtr);
CommodoreHeader cbmHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian<CommodoreHeader>(sector);
if(cbmHdr.diskDosVersion == 0x44 && cbmHdr.dosVersion == 0x33 && cbmHdr.diskVersion == 0x44)
return true;
@@ -75,11 +71,7 @@ namespace DiscImageChef.Filesystems
else
{
sector = imagePlugin.ReadSector(357);
CommodoreBam cbmBam = new CommodoreBam();
IntPtr cbmBamPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbmBam));
Marshal.Copy(sector, 0, cbmBamPtr, Marshal.SizeOf(cbmBam));
cbmBam = (CommodoreBam)Marshal.PtrToStructure(cbmBamPtr, typeof(CommodoreBam));
Marshal.FreeHGlobal(cbmBamPtr);
CommodoreBam cbmBam = Helpers.Marshal.ByteArrayToStructureLittleEndian<CommodoreBam>(sector);
if(cbmBam.dosVersion == 0x41 && (cbmBam.doubleSided == 0x00 || cbmBam.doubleSided == 0x80) &&
cbmBam.unused1 == 0x00 && cbmBam.directoryTrack == 0x12) return true;
@@ -106,11 +98,7 @@ namespace DiscImageChef.Filesystems
if(imagePlugin.Info.Sectors == 3200)
{
sector = imagePlugin.ReadSector(1560);
CommodoreHeader cbmHdr = new CommodoreHeader();
IntPtr cbmHdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbmHdr));
Marshal.Copy(sector, 0, cbmHdrPtr, Marshal.SizeOf(cbmHdr));
cbmHdr = (CommodoreHeader)Marshal.PtrToStructure(cbmHdrPtr, typeof(CommodoreHeader));
Marshal.FreeHGlobal(cbmHdrPtr);
CommodoreHeader cbmHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian<CommodoreHeader>(sector);
sbInformation.AppendFormat("Directory starts at track {0} sector {1}", cbmHdr.directoryTrack,
cbmHdr.directorySector).AppendLine();
@@ -131,11 +119,7 @@ namespace DiscImageChef.Filesystems
else
{
sector = imagePlugin.ReadSector(357);
CommodoreBam cbmBam = new CommodoreBam();
IntPtr cbmBamPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cbmBam));
Marshal.Copy(sector, 0, cbmBamPtr, Marshal.SizeOf(cbmBam));
cbmBam = (CommodoreBam)Marshal.PtrToStructure(cbmBamPtr, typeof(CommodoreBam));
Marshal.FreeHGlobal(cbmBamPtr);
CommodoreBam cbmBam = Helpers.Marshal.ByteArrayToStructureLittleEndian<CommodoreBam>(sector);
sbInformation.AppendFormat("Directory starts at track {0} sector {1}", cbmBam.directoryTrack,
cbmBam.directorySector).AppendLine();

View File

@@ -71,10 +71,8 @@ namespace DiscImageChef.Filesystems.CPM
for(int off = 0; off < directory.Length; off += 32)
{
IntPtr dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, off, dirPtr, 32);
DirectoryEntry entry = (DirectoryEntry)Marshal.PtrToStructure(dirPtr, typeof(DirectoryEntry));
Marshal.FreeHGlobal(dirPtr);
DirectoryEntry entry =
Helpers.Marshal.ByteArrayToStructureLittleEndian<DirectoryEntry>(directory, off, 32);
if((entry.statusUser & 0x7F) < 0x20)
{

View File

@@ -180,11 +180,8 @@ namespace DiscImageChef.Filesystems.CPM
if(sig1 == 0x4D2F5043 && sig2 == 0x004B5344 && sig3 == sig1) amsSbOffset = 0x80;
// Read the superblock
IntPtr amsPtr = Marshal.AllocHGlobal(16);
Marshal.Copy(sector, amsSbOffset, amsPtr, 16);
AmstradSuperBlock amsSb =
(AmstradSuperBlock)Marshal.PtrToStructure(amsPtr, typeof(AmstradSuperBlock));
Marshal.FreeHGlobal(amsPtr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<AmstradSuperBlock>(sector, amsSbOffset, 16);
// Check that format byte and sidedness indicate the same number of sizes
if(amsSb.format == 0 && (amsSb.sidedness & 0x02) == 0 ||
@@ -300,11 +297,8 @@ namespace DiscImageChef.Filesystems.CPM
if(sum == 0)
{
// Read the superblock
HardDiskSuperBlock hddSb = new HardDiskSuperBlock();
IntPtr hddPtr = Marshal.AllocHGlobal(Marshal.SizeOf(hddSb));
Marshal.Copy(sector, 0, hddPtr, Marshal.SizeOf(hddSb));
hddSb = (HardDiskSuperBlock)Marshal.PtrToStructure(hddPtr, typeof(HardDiskSuperBlock));
Marshal.FreeHGlobal(hddPtr);
HardDiskSuperBlock hddSb =
Helpers.Marshal.ByteArrayToStructureLittleEndian<HardDiskSuperBlock>(sector);
// Calculate volume size
sectorSize = (ulong)(hddSb.recordsPerSector * 128);

View File

@@ -216,7 +216,6 @@ namespace DiscImageChef.Filesystems.CPM
passwordCache = new Dictionary<string, byte[]>();
DicConsole.DebugWriteLine("CP/M Plugin", "Traversing directory.");
IntPtr dirPtr;
// For each directory entry
for(int dOff = 0; dOff < directory.Length; dOff += 32)
@@ -224,11 +223,8 @@ namespace DiscImageChef.Filesystems.CPM
if((directory[dOff] & 0x7F) < 0x10)
if(allocationBlocks.Count > 256)
{
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
DirectoryEntry16 entry =
(DirectoryEntry16)Marshal.PtrToStructure(dirPtr, typeof(DirectoryEntry16));
Marshal.FreeHGlobal(dirPtr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<DirectoryEntry16>(directory, dOff, 32);
bool hidden = (entry.statusUser & 0x80) == 0x80;
bool rdOnly = (entry.filename[0] & 0x80) == 0x80 || (entry.extension[0] & 0x80) == 0x80;
@@ -314,10 +310,8 @@ namespace DiscImageChef.Filesystems.CPM
}
else
{
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
DirectoryEntry entry = (DirectoryEntry)Marshal.PtrToStructure(dirPtr, typeof(DirectoryEntry));
Marshal.FreeHGlobal(dirPtr);
DirectoryEntry entry =
Helpers.Marshal.ByteArrayToStructureLittleEndian<DirectoryEntry>(directory, dOff, 32);
bool hidden = (entry.statusUser & 0x80) == 0x80;
bool rdOnly = (entry.filename[0] & 0x80) == 0x80 || (entry.extension[0] & 0x80) == 0x80;
@@ -404,10 +398,8 @@ namespace DiscImageChef.Filesystems.CPM
// A password entry (or a file entry in PDOS, but this does not handle that case)
else if((directory[dOff] & 0x7F) >= 0x10 && (directory[dOff] & 0x7F) < 0x20)
{
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
PasswordEntry entry = (PasswordEntry)Marshal.PtrToStructure(dirPtr, typeof(PasswordEntry));
Marshal.FreeHGlobal(dirPtr);
PasswordEntry entry =
Helpers.Marshal.ByteArrayToStructureLittleEndian<PasswordEntry>(directory, dOff, 32);
int user = entry.userNumber & 0x0F;
@@ -450,11 +442,8 @@ namespace DiscImageChef.Filesystems.CPM
switch(directory[dOff] & 0x7F)
{
case 0x20:
LabelEntry labelEntry;
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
labelEntry = (LabelEntry)Marshal.PtrToStructure(dirPtr, typeof(LabelEntry));
Marshal.FreeHGlobal(dirPtr);
LabelEntry labelEntry =
Helpers.Marshal.ByteArrayToStructureLittleEndian<LabelEntry>(directory, dOff, 32);
// The volume label defines if one of the fields in CP/M 3 timestamp is a creation or an
// access time
@@ -486,10 +475,8 @@ namespace DiscImageChef.Filesystems.CPM
if(directory[dOff + 10] == 0x00 && directory[dOff + 20] == 0x00 &&
directory[dOff + 30] == 0x00 && directory[dOff + 31] == 0x00)
{
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
DateEntry dateEntry = (DateEntry)Marshal.PtrToStructure(dirPtr, typeof(DateEntry));
Marshal.FreeHGlobal(dirPtr);
DateEntry dateEntry =
Helpers.Marshal.ByteArrayToStructureLittleEndian<DateEntry>(directory, dOff, 32);
FileEntryInfo fInfo;
@@ -541,11 +528,9 @@ namespace DiscImageChef.Filesystems.CPM
// However, if this byte is 0, timestamp is in Z80DOS or DOS+ format
else if(directory[dOff + 1] == 0x00)
{
dirPtr = Marshal.AllocHGlobal(32);
Marshal.Copy(directory, dOff, dirPtr, 32);
TrdPartyDateEntry trdPartyDateEntry =
(TrdPartyDateEntry)Marshal.PtrToStructure(dirPtr, typeof(TrdPartyDateEntry));
Marshal.FreeHGlobal(dirPtr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<TrdPartyDateEntry>(directory, dOff,
32);
FileEntryInfo fInfo;

View File

@@ -77,10 +77,7 @@ namespace DiscImageChef.Filesystems
switch(magic)
{
case CRAM_MAGIC:
IntPtr crSbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(crSb));
Marshal.Copy(sector, 0, crSbPtr, Marshal.SizeOf(crSb));
crSb = (CramSuperBlock)Marshal.PtrToStructure(crSbPtr, typeof(CramSuperBlock));
Marshal.FreeHGlobal(crSbPtr);
crSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<CramSuperBlock>(sector);
break;
case CRAM_CIGAM:
crSb = Helpers.Marshal.ByteArrayToStructureBigEndian<CramSuperBlock>(sector);

View File

@@ -60,11 +60,7 @@ namespace DiscImageChef.Filesystems
if(sector.Length != 128) return false;
VolumeLabel vol = new VolumeLabel();
IntPtr volPtr = Marshal.AllocHGlobal(Marshal.SizeOf(vol));
Marshal.Copy(sector, 0, volPtr, Marshal.SizeOf(vol));
vol = (VolumeLabel)Marshal.PtrToStructure(volPtr, typeof(VolumeLabel));
Marshal.FreeHGlobal(volPtr);
VolumeLabel vol = Helpers.Marshal.ByteArrayToStructureLittleEndian<VolumeLabel>(sector);
return ecma67_magic.SequenceEqual(vol.labelIdentifier) && vol.labelNumber == 1 && vol.recordLength == 0x31;
}
@@ -77,11 +73,7 @@ namespace DiscImageChef.Filesystems
StringBuilder sbInformation = new StringBuilder();
VolumeLabel vol = new VolumeLabel();
IntPtr volPtr = Marshal.AllocHGlobal(Marshal.SizeOf(vol));
Marshal.Copy(sector, 0, volPtr, Marshal.SizeOf(vol));
vol = (VolumeLabel)Marshal.PtrToStructure(volPtr, typeof(VolumeLabel));
Marshal.FreeHGlobal(volPtr);
VolumeLabel vol = Helpers.Marshal.ByteArrayToStructureLittleEndian<VolumeLabel>(sector);
sbInformation.AppendLine("ECMA-67");

View File

@@ -72,10 +72,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
if(sector.Length < Marshal.SizeOf(f2fsSb)) return false;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(f2fsSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(f2fsSb));
f2fsSb = (F2FS_Superblock)Marshal.PtrToStructure(sbPtr, typeof(F2FS_Superblock));
Marshal.FreeHGlobal(sbPtr);
f2fsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<F2FS_Superblock>(sector);
return f2fsSb.magic == F2FS_MAGIC;
}
@@ -98,10 +95,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
if(sector.Length < Marshal.SizeOf(f2fsSb)) return;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(f2fsSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(f2fsSb));
f2fsSb = (F2FS_Superblock)Marshal.PtrToStructure(sbPtr, typeof(F2FS_Superblock));
Marshal.FreeHGlobal(sbPtr);
f2fsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<F2FS_Superblock>(sector);
if(f2fsSb.magic != F2FS_MAGIC) return;

View File

@@ -516,43 +516,17 @@ namespace DiscImageChef.Filesystems
if(imagePlugin.Info.SectorSize >= 256 && !useHumanBpb)
{
IntPtr bpbPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(512);
System.Runtime.InteropServices.Marshal.Copy(bpbSector, 0, bpbPtr, 512);
atariBpb =
(AtariParameterBlock)
System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(AtariParameterBlock));
msxBpb =
(MsxParameterBlock)
System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(MsxParameterBlock));
dos2Bpb =
(BiosParameterBlock2)
System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(BiosParameterBlock2));
dos30Bpb =
(BiosParameterBlock30)
System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(BiosParameterBlock30));
dos32Bpb =
(BiosParameterBlock32)
System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(BiosParameterBlock32));
dos33Bpb =
(BiosParameterBlock33)
System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(BiosParameterBlock33));
shortEbpb =
(BiosParameterBlockShortEbpb)
System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(BiosParameterBlockShortEbpb));
ebpb =
(BiosParameterBlockEbpb)
System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(BiosParameterBlockEbpb));
shortFat32Bpb =
(Fat32ParameterBlockShort)
System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(Fat32ParameterBlockShort));
fat32Bpb =
(Fat32ParameterBlock)
System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(Fat32ParameterBlock));
apricotBpb =
(ApricotLabel)System.Runtime.InteropServices.Marshal.PtrToStructure(bpbPtr, typeof(ApricotLabel));
System.Runtime.InteropServices.Marshal.FreeHGlobal(bpbPtr);
atariBpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<AtariParameterBlock>(bpbSector);
msxBpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<MsxParameterBlock>(bpbSector);
dos2Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<BiosParameterBlock2>(bpbSector);
dos30Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<BiosParameterBlock30>(bpbSector);
dos32Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<BiosParameterBlock32>(bpbSector);
dos33Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<BiosParameterBlock33>(bpbSector);
shortEbpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<BiosParameterBlockShortEbpb>(bpbSector);
ebpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<BiosParameterBlockEbpb>(bpbSector);
shortFat32Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<Fat32ParameterBlockShort>(bpbSector);
fat32Bpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<Fat32ParameterBlock>(bpbSector);
apricotBpb = Helpers.Marshal.ByteArrayToStructureLittleEndian<ApricotLabel>(bpbSector);
int bitsInBpsAtari = CountBits.Count(atariBpb.bps);
int bitsInBpsMsx = CountBits.Count(msxBpb.bps);
@@ -1122,12 +1096,7 @@ namespace DiscImageChef.Filesystems
if(fat32Bpb.fsinfo_sector + partition.Start <= partition.End)
{
byte[] fsinfoSector = imagePlugin.ReadSector(fat32Bpb.fsinfo_sector + partition.Start);
IntPtr fsinfoPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(512);
System.Runtime.InteropServices.Marshal.Copy(fsinfoSector, 0, fsinfoPtr, 512);
FsInfoSector fsInfo =
(FsInfoSector)
System.Runtime.InteropServices.Marshal.PtrToStructure(fsinfoPtr, typeof(FsInfoSector));
System.Runtime.InteropServices.Marshal.FreeHGlobal(fsinfoPtr);
FsInfoSector fsInfo = Helpers.Marshal.ByteArrayToStructureLittleEndian<FsInfoSector>(fsinfoSector);
if(fsInfo.signature1 == FSINFO_SIGNATURE1 && fsInfo.signature2 == FSINFO_SIGNATURE2 &&
fsInfo.signature3 == FSINFO_SIGNATURE3)
@@ -1560,12 +1529,8 @@ namespace DiscImageChef.Filesystems
// Not a volume label
if(rootDirectory[i + 0x0B] != 0x08 && rootDirectory[i + 0x0B] != 0x28) continue;
IntPtr entryPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(32);
System.Runtime.InteropServices.Marshal.Copy(rootDirectory, i, entryPtr, 32);
DirectoryEntry entry =
(DirectoryEntry)
System.Runtime.InteropServices.Marshal.PtrToStructure(entryPtr, typeof(DirectoryEntry));
System.Runtime.InteropServices.Marshal.FreeHGlobal(entryPtr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<DirectoryEntry>(rootDirectory, i, 32);
byte[] fullname = new byte[11];
Array.Copy(entry.filename, 0, fullname, 0, 8);

View File

@@ -205,10 +205,7 @@ namespace DiscImageChef.Filesystems
// Fun with seeking follows on superblock reading!
ufs_sb_sectors = imagePlugin.ReadSectors(sb_offset, sb_size_in_sectors);
IntPtr sbPtr = Marshal.AllocHGlobal(ufs_sb_sectors.Length);
Marshal.Copy(ufs_sb_sectors, 0, sbPtr, ufs_sb_sectors.Length);
UFSSuperBlock ufs_sb = (UFSSuperBlock)Marshal.PtrToStructure(sbPtr, typeof(UFSSuperBlock));
Marshal.FreeHGlobal(sbPtr);
UFSSuperBlock ufs_sb = Helpers.Marshal.ByteArrayToStructureLittleEndian<UFSSuperBlock>(ufs_sb_sectors);
UFSSuperBlock bs_sfu = Helpers.Marshal.ByteArrayToStructureBigEndian<UFSSuperBlock>(ufs_sb_sectors);
if(bs_sfu.fs_magic == UFS_MAGIC && ufs_sb.fs_magic == UFS_CIGAM ||

View File

@@ -93,10 +93,7 @@ namespace DiscImageChef.Filesystems
if(magic == HAMMER_FSBUF_VOLUME)
{
GCHandle handle = GCHandle.Alloc(sbSector, GCHandleType.Pinned);
hammerSb = (HammerSuperBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(HammerSuperBlock));
handle.Free();
hammerSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<HammerSuperBlock>(sbSector);
}
else hammerSb = Helpers.Marshal.ByteArrayToStructureBigEndian<HammerSuperBlock>(sbSector);

View File

@@ -76,21 +76,12 @@ namespace DiscImageChef.Filesystems
byte[] hpfsSpSector =
imagePlugin.ReadSector(17 + partition.Start); // Seek to spareblock, on logical sector 17
IntPtr bpbPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(hpfsBpbSector, 0, bpbPtr, 512);
HpfsBiosParameterBlock hpfsBpb =
(HpfsBiosParameterBlock)Marshal.PtrToStructure(bpbPtr, typeof(HpfsBiosParameterBlock));
Marshal.FreeHGlobal(bpbPtr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<HpfsBiosParameterBlock>(hpfsBpbSector);
IntPtr sbPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(hpfsSbSector, 0, sbPtr, 512);
HpfsSuperBlock hpfsSb = (HpfsSuperBlock)Marshal.PtrToStructure(sbPtr, typeof(HpfsSuperBlock));
Marshal.FreeHGlobal(sbPtr);
HpfsSuperBlock hpfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<HpfsSuperBlock>(hpfsSbSector);
IntPtr spPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(hpfsSpSector, 0, spPtr, 512);
HpfsSpareBlock hpfsSp = (HpfsSpareBlock)Marshal.PtrToStructure(spPtr, typeof(HpfsSpareBlock));
Marshal.FreeHGlobal(spPtr);
HpfsSpareBlock hpfsSp = Helpers.Marshal.ByteArrayToStructureLittleEndian<HpfsSpareBlock>(hpfsSpSector);
if(StringHandlers.CToString(hpfsBpb.fs_type) != "HPFS " || hpfsSb.magic1 != 0xF995E849 ||
hpfsSb.magic2 != 0xFA53E9C5 || hpfsSp.magic1 != 0xF9911849 ||

View File

@@ -65,10 +65,8 @@ namespace DiscImageChef.Filesystems
if(hpofsBpbSector.Length < 512) return false;
IntPtr bpbPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(hpofsBpbSector, 0, bpbPtr, 512);
BiosParameterBlock bpb = (BiosParameterBlock)Marshal.PtrToStructure(bpbPtr, typeof(BiosParameterBlock));
Marshal.FreeHGlobal(bpbPtr);
BiosParameterBlock bpb =
Helpers.Marshal.ByteArrayToStructureLittleEndian<BiosParameterBlock>(hpofsBpbSector);
return bpb.fs_type.SequenceEqual(hpofsType);
}
@@ -88,11 +86,8 @@ namespace DiscImageChef.Filesystems
byte[] volInfoSector =
imagePlugin.ReadSector(14 + partition.Start); // Seek to volume information block, on logical sector 14
IntPtr bpbPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(hpofsBpbSector, 0, bpbPtr, 512);
BiosParameterBlock bpb = (BiosParameterBlock)Marshal.PtrToStructure(bpbPtr, typeof(BiosParameterBlock));
Marshal.FreeHGlobal(bpbPtr);
BiosParameterBlock bpb =
Helpers.Marshal.ByteArrayToStructureLittleEndian<BiosParameterBlock>(hpofsBpbSector);
MediaInformationBlock mib =
Helpers.Marshal.ByteArrayToStructureBigEndian<MediaInformationBlock>(medInfoSector);
VolumeInformationBlock vib =

View File

@@ -148,20 +148,15 @@ namespace DiscImageChef.Filesystems.ISO9660
{
case 0:
{
IntPtr ptr = Marshal.AllocHGlobal(2048);
Marshal.Copy(vdSector, hsOff, ptr, 2048 - hsOff);
bvd = (BootRecord)Marshal.PtrToStructure(ptr, typeof(BootRecord));
Marshal.FreeHGlobal(ptr);
bvd = Helpers.Marshal.ByteArrayToStructureLittleEndian<BootRecord>(vdSector, hsOff, 2048 - hsOff);
bootSpec = "Unknown";
if(Encoding.GetString(bvd.Value.system_id).Substring(0, 23) == "EL TORITO SPECIFICATION")
{
bootSpec = "El Torito";
ptr = Marshal.AllocHGlobal(2048);
Marshal.Copy(vdSector, hsOff, ptr, 2048 - hsOff);
torito = (ElToritoBootRecord)Marshal.PtrToStructure(ptr, typeof(ElToritoBootRecord));
Marshal.FreeHGlobal(ptr);
torito = Helpers
.Marshal.ByteArrayToStructureLittleEndian<ElToritoBootRecord>(vdSector, hsOff, 2048 - hsOff);
}
break;
@@ -170,33 +165,24 @@ namespace DiscImageChef.Filesystems.ISO9660
{
if(highSierra)
{
IntPtr ptr = Marshal.AllocHGlobal(2048);
Marshal.Copy(vdSector, 0, ptr, 2048);
hsvd =
(HighSierraPrimaryVolumeDescriptor)
Marshal.PtrToStructure(ptr, typeof(HighSierraPrimaryVolumeDescriptor));
Marshal.FreeHGlobal(ptr);
Helpers.Marshal
.ByteArrayToStructureLittleEndian<HighSierraPrimaryVolumeDescriptor>(vdSector);
}
else if(cdi)
fsvd =
Helpers.Marshal.ByteArrayToStructureBigEndian<FileStructureVolumeDescriptor>(vdSector);
else
{
IntPtr ptr = Marshal.AllocHGlobal(2048);
Marshal.Copy(vdSector, 0, ptr, 2048);
pvd = (PrimaryVolumeDescriptor)Marshal.PtrToStructure(ptr, typeof(PrimaryVolumeDescriptor));
Marshal.FreeHGlobal(ptr);
pvd = Helpers.Marshal.ByteArrayToStructureLittleEndian<PrimaryVolumeDescriptor>(vdSector);
}
break;
}
case 2:
{
IntPtr ptr = Marshal.AllocHGlobal(2048);
Marshal.Copy(vdSector, 0, ptr, 2048);
PrimaryVolumeDescriptor svd =
(PrimaryVolumeDescriptor)Marshal.PtrToStructure(ptr, typeof(PrimaryVolumeDescriptor));
Marshal.FreeHGlobal(ptr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<PrimaryVolumeDescriptor>(vdSector);
// Check if this is Joliet
if(svd.escape_sequences[0] == '%' && svd.escape_sequences[1] == '/')
@@ -273,11 +259,9 @@ namespace DiscImageChef.Filesystems.ISO9660
// Walk thru root directory to see system area extensions in use
while(rootOff + Marshal.SizeOf(typeof(DirectoryRecord)) < rootDir.Length && !cdi)
{
DirectoryRecord record = new DirectoryRecord();
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(record));
Marshal.Copy(rootDir, rootOff, ptr, Marshal.SizeOf(record));
record = (DirectoryRecord)Marshal.PtrToStructure(ptr, typeof(DirectoryRecord));
Marshal.FreeHGlobal(ptr);
DirectoryRecord record =
Helpers.Marshal.ByteArrayToStructureLittleEndian<DirectoryRecord>(rootDir, rootOff,
Marshal.SizeOf(typeof(DirectoryRecord)));
int saOff = Marshal.SizeOf(record) + record.name_len;
saOff += saOff % 2;
@@ -570,21 +554,18 @@ namespace DiscImageChef.Filesystems.ISO9660
if(vdSector[toritoOff] != 1) goto exit_torito;
IntPtr ptr = Marshal.AllocHGlobal(EL_TORITO_ENTRY_SIZE);
Marshal.Copy(vdSector, toritoOff, ptr, EL_TORITO_ENTRY_SIZE);
ElToritoValidationEntry valentry =
(ElToritoValidationEntry)Marshal.PtrToStructure(ptr, typeof(ElToritoValidationEntry));
Marshal.FreeHGlobal(ptr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<ElToritoValidationEntry>(vdSector, toritoOff,
EL_TORITO_ENTRY_SIZE);
if(valentry.signature != EL_TORITO_MAGIC) goto exit_torito;
toritoOff += EL_TORITO_ENTRY_SIZE;
ptr = Marshal.AllocHGlobal(EL_TORITO_ENTRY_SIZE);
Marshal.Copy(vdSector, toritoOff, ptr, EL_TORITO_ENTRY_SIZE);
ElToritoInitialEntry initialEntry =
(ElToritoInitialEntry)Marshal.PtrToStructure(ptr, typeof(ElToritoInitialEntry));
Marshal.FreeHGlobal(ptr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<ElToritoInitialEntry>(vdSector, toritoOff,
EL_TORITO_ENTRY_SIZE);
initialEntry.boot_type = (ElToritoEmulation)((byte)initialEntry.boot_type & 0xF);
DicConsole.DebugWriteLine("DEBUG (ISO9660 plugin)", "initialEntry.load_rba = {0}",
@@ -649,11 +630,9 @@ namespace DiscImageChef.Filesystems.ISO9660
while(toritoOff < vdSector.Length && (vdSector[toritoOff] == (byte)ElToritoIndicator.Header ||
vdSector[toritoOff] == (byte)ElToritoIndicator.LastHeader))
{
ptr = Marshal.AllocHGlobal(EL_TORITO_ENTRY_SIZE);
Marshal.Copy(vdSector, toritoOff, ptr, EL_TORITO_ENTRY_SIZE);
ElToritoSectionHeaderEntry sectionHeader =
(ElToritoSectionHeaderEntry)Marshal.PtrToStructure(ptr, typeof(ElToritoSectionHeaderEntry));
Marshal.FreeHGlobal(ptr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<ElToritoSectionHeaderEntry>(vdSector, toritoOff,
EL_TORITO_ENTRY_SIZE);
toritoOff += EL_TORITO_ENTRY_SIZE;
isoMetadata.AppendFormat("Boot section {0}:", SECTION_COUNTER);
@@ -663,11 +642,9 @@ namespace DiscImageChef.Filesystems.ISO9660
for(int entryCounter = 1; entryCounter <= sectionHeader.entries && toritoOff < vdSector.Length;
entryCounter++)
{
ptr = Marshal.AllocHGlobal(EL_TORITO_ENTRY_SIZE);
Marshal.Copy(vdSector, toritoOff, ptr, EL_TORITO_ENTRY_SIZE);
ElToritoSectionEntry sectionEntry =
(ElToritoSectionEntry)Marshal.PtrToStructure(ptr, typeof(ElToritoSectionEntry));
Marshal.FreeHGlobal(ptr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<ElToritoSectionEntry>(vdSector, toritoOff,
EL_TORITO_ENTRY_SIZE);
toritoOff += EL_TORITO_ENTRY_SIZE;
isoMetadata.AppendFormat("\tEntry {0}:", entryCounter);
@@ -731,12 +708,9 @@ namespace DiscImageChef.Filesystems.ISO9660
while(toritoOff < vdSector.Length)
{
ptr = Marshal.AllocHGlobal(EL_TORITO_ENTRY_SIZE);
Marshal.Copy(vdSector, toritoOff, ptr, EL_TORITO_ENTRY_SIZE);
ElToritoSectionEntryExtension sectionExtension =
(ElToritoSectionEntryExtension)
Marshal.PtrToStructure(ptr, typeof(ElToritoSectionEntryExtension));
Marshal.FreeHGlobal(ptr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<ElToritoSectionEntryExtension>(vdSector, toritoOff,
EL_TORITO_ENTRY_SIZE);
toritoOff += EL_TORITO_ENTRY_SIZE;
if(!sectionExtension.extension_flags.HasFlag(ElToritoFlags.Continued)) break;

View File

@@ -58,11 +58,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSector(partition.Start + bootSectors);
if(sector.Length < 512) return false;
JfsSuperBlock jfsSb = new JfsSuperBlock();
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(jfsSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(jfsSb));
jfsSb = (JfsSuperBlock)Marshal.PtrToStructure(sbPtr, typeof(JfsSuperBlock));
Marshal.FreeHGlobal(sbPtr);
JfsSuperBlock jfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<JfsSuperBlock>(sector);
return jfsSb.s_magic == JFS_MAGIC;
}
@@ -77,11 +73,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSector(partition.Start + bootSectors);
if(sector.Length < 512) return;
JfsSuperBlock jfsSb = new JfsSuperBlock();
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(jfsSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(jfsSb));
jfsSb = (JfsSuperBlock)Marshal.PtrToStructure(sbPtr, typeof(JfsSuperBlock));
Marshal.FreeHGlobal(sbPtr);
JfsSuperBlock jfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<JfsSuperBlock>(sector);
sb.AppendLine("JFS filesystem");
sb.AppendFormat("Version {0}", jfsSb.s_version).AppendLine();

View File

@@ -89,10 +89,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + location, sbSize);
if(sector.Length < Marshal.SizeOf(locusSb)) return false;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(locusSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(locusSb));
locusSb = (Locus_Superblock)Marshal.PtrToStructure(sbPtr, typeof(Locus_Superblock));
Marshal.FreeHGlobal(sbPtr);
locusSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<Locus_Superblock>(sector);
DicConsole.DebugWriteLine("Locus plugin", "magic at {1} = 0x{0:X8}", locusSb.s_magic, location);
@@ -121,10 +118,7 @@ namespace DiscImageChef.Filesystems
sector = imagePlugin.ReadSectors(partition.Start + location, sbSize);
if(sector.Length < Marshal.SizeOf(locusSb)) return;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(locusSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(locusSb));
locusSb = (Locus_Superblock)Marshal.PtrToStructure(sbPtr, typeof(Locus_Superblock));
Marshal.FreeHGlobal(sbPtr);
locusSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<Locus_Superblock>(sector);
if(locusSb.s_magic == LOCUS_MAGIC || locusSb.s_magic == LOCUS_CIGAM ||
locusSb.s_magic == LOCUS_MAGIC_OLD || locusSb.s_magic == LOCUS_CIGAM_OLD) break;

View File

@@ -60,10 +60,7 @@ namespace DiscImageChef.Filesystems
byte[] bk0 = imagePlugin.ReadSector(0 + partition.Start);
GCHandle handle = GCHandle.Alloc(bk0, GCHandleType.Pinned);
MicroDosBlock0 block0 =
(MicroDosBlock0)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(MicroDosBlock0));
handle.Free();
MicroDosBlock0 block0 = Helpers.Marshal.ByteArrayToStructureLittleEndian<MicroDosBlock0>(bk0);
return block0.label == MAGIC && block0.mklabel == MAGIC2;
}
@@ -78,10 +75,7 @@ namespace DiscImageChef.Filesystems
byte[] bk0 = imagePlugin.ReadSector(0 + partition.Start);
GCHandle handle = GCHandle.Alloc(bk0, GCHandleType.Pinned);
MicroDosBlock0 block0 =
(MicroDosBlock0)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(MicroDosBlock0));
handle.Free();
MicroDosBlock0 block0 = Helpers.Marshal.ByteArrayToStructureLittleEndian<MicroDosBlock0>(bk0);
sb.AppendLine("MicroDOS filesystem");
sb.AppendFormat("Volume has {0} blocks ({1} bytes)", block0.blocks, block0.blocks * 512).AppendLine();

View File

@@ -232,10 +232,7 @@ namespace DiscImageChef.Filesystems
if(littleEndian)
{
GCHandle handle = GCHandle.Alloc(minixSbSector, GCHandleType.Pinned);
mnxSb = (Minix3SuperBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(Minix3SuperBlock));
handle.Free();
mnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<Minix3SuperBlock>(minixSbSector);
}
else mnxSb = Helpers.Marshal.ByteArrayToStructureBigEndian<Minix3SuperBlock>(minixSbSector);
@@ -269,11 +266,7 @@ namespace DiscImageChef.Filesystems
if(littleEndian)
{
GCHandle handle = GCHandle.Alloc(minixSbSector, GCHandleType.Pinned);
mnxSb = (MinixSuperBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(),
typeof(MinixSuperBlock));
handle.Free();
}
mnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<MinixSuperBlock>(minixSbSector); }
else mnxSb = Helpers.Marshal.ByteArrayToStructureBigEndian<MinixSuperBlock>(minixSbSector);
sb.AppendLine(minixVersion);

View File

@@ -67,10 +67,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
if(sector.Length < Marshal.SizeOf(nilfsSb)) return false;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(nilfsSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(nilfsSb));
nilfsSb = (NILFS2_Superblock)Marshal.PtrToStructure(sbPtr, typeof(NILFS2_Superblock));
Marshal.FreeHGlobal(sbPtr);
nilfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<NILFS2_Superblock>(sector);
return nilfsSb.magic == NILFS2_MAGIC;
}
@@ -93,10 +90,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
if(sector.Length < Marshal.SizeOf(nilfsSb)) return;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(nilfsSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(nilfsSb));
nilfsSb = (NILFS2_Superblock)Marshal.PtrToStructure(sbPtr, typeof(NILFS2_Superblock));
Marshal.FreeHGlobal(sbPtr);
nilfsSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<NILFS2_Superblock>(sector);
if(nilfsSb.magic != NILFS2_MAGIC) return;

View File

@@ -82,10 +82,7 @@ namespace DiscImageChef.Filesystems
byte[] ntfsBpb = imagePlugin.ReadSector(0 + partition.Start);
IntPtr bpbPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(ntfsBpb, 0, bpbPtr, 512);
NtfsBootBlock ntfsBb = (NtfsBootBlock)Marshal.PtrToStructure(bpbPtr, typeof(NtfsBootBlock));
Marshal.FreeHGlobal(bpbPtr);
NtfsBootBlock ntfsBb = Helpers.Marshal.ByteArrayToStructureLittleEndian<NtfsBootBlock>(ntfsBpb);
sb.AppendFormat("{0} bytes per sector", ntfsBb.bps).AppendLine();
sb.AppendFormat("{0} sectors per cluster ({1} bytes)", ntfsBb.spc, ntfsBb.spc * ntfsBb.bps).AppendLine();

View File

@@ -99,10 +99,7 @@ namespace DiscImageChef.Filesystems
byte[] hbSector = imagePlugin.ReadSector(1 + partition.Start);
GCHandle handle = GCHandle.Alloc(hbSector, GCHandleType.Pinned);
OdsHomeBlock homeblock =
(OdsHomeBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(OdsHomeBlock));
handle.Free();
OdsHomeBlock homeblock = Helpers.Marshal.ByteArrayToStructureLittleEndian<OdsHomeBlock>(hbSector);
// Optical disc
if(imagePlugin.Info.XmlMediaType == XmlMediaType.OpticalDisc &&
@@ -115,9 +112,7 @@ namespace DiscImageChef.Filesystems
hbSector = new byte[0x200];
Array.Copy(tmp, 0x200, hbSector, 0, 0x200);
handle = GCHandle.Alloc(hbSector, GCHandleType.Pinned);
homeblock = (OdsHomeBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(OdsHomeBlock));
handle.Free();
homeblock = Helpers.Marshal.ByteArrayToStructureLittleEndian<OdsHomeBlock>(hbSector);
if(StringHandlers.CToString(homeblock.format) != "DECFILE11A " &&
StringHandlers.CToString(homeblock.format) != "DECFILE11B ") return;

View File

@@ -70,11 +70,7 @@ namespace DiscImageChef.Filesystems
information = "";
byte[] sector = imagePlugin.ReadSectors(partition.Start, 2);
PcfxHeader header = new PcfxHeader();
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(header));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(header));
header = (PcfxHeader)Marshal.PtrToStructure(sbPtr, typeof(PcfxHeader));
Marshal.FreeHGlobal(sbPtr);
PcfxHeader header = Helpers.Marshal.ByteArrayToStructureLittleEndian<PcfxHeader>(sector);
string date;
DateTime dateTime = DateTime.MinValue;

View File

@@ -60,10 +60,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSector(partition.Start + 1);
if(sector.Length < 512) return false;
IntPtr sbPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(sector, 0, sbPtr, 512);
QNX4_Superblock qnxSb = (QNX4_Superblock)Marshal.PtrToStructure(sbPtr, typeof(QNX4_Superblock));
Marshal.FreeHGlobal(sbPtr);
QNX4_Superblock qnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<QNX4_Superblock>(sector);
// Check root directory name
if(!qnx4_rootDir_fname.SequenceEqual(qnxSb.rootDir.di_fname)) return false;
@@ -94,10 +91,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSector(partition.Start + 1);
if(sector.Length < 512) return;
IntPtr sbPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(sector, 0, sbPtr, 512);
QNX4_Superblock qnxSb = (QNX4_Superblock)Marshal.PtrToStructure(sbPtr, typeof(QNX4_Superblock));
Marshal.FreeHGlobal(sbPtr);
QNX4_Superblock qnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<QNX4_Superblock>(sector);
// Too much useless information
/*

View File

@@ -62,17 +62,10 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + bootSectors, sectors);
if(sector.Length < QNX6_SUPER_BLOCK_SIZE) return false;
QNX6_AudiSuperBlock audiSb = new QNX6_AudiSuperBlock();
IntPtr audiPtr = Marshal.AllocHGlobal(Marshal.SizeOf(audiSb));
Marshal.Copy(audiSector, 0, audiPtr, Marshal.SizeOf(audiSb));
audiSb = (QNX6_AudiSuperBlock)Marshal.PtrToStructure(audiPtr, typeof(QNX6_AudiSuperBlock));
Marshal.FreeHGlobal(audiPtr);
QNX6_AudiSuperBlock audiSb =
Helpers.Marshal.ByteArrayToStructureLittleEndian<QNX6_AudiSuperBlock>(audiSector);
QNX6_SuperBlock qnxSb = new QNX6_SuperBlock();
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(qnxSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(qnxSb));
qnxSb = (QNX6_SuperBlock)Marshal.PtrToStructure(sbPtr, typeof(QNX6_SuperBlock));
Marshal.FreeHGlobal(sbPtr);
QNX6_SuperBlock qnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<QNX6_SuperBlock>(sector);
return qnxSb.magic == QNX6_MAGIC || audiSb.magic == QNX6_MAGIC;
}
@@ -90,17 +83,10 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + bootSectors, sectors);
if(sector.Length < QNX6_SUPER_BLOCK_SIZE) return;
QNX6_AudiSuperBlock audiSb = new QNX6_AudiSuperBlock();
IntPtr audiPtr = Marshal.AllocHGlobal(Marshal.SizeOf(audiSb));
Marshal.Copy(audiSector, 0, audiPtr, Marshal.SizeOf(audiSb));
audiSb = (QNX6_AudiSuperBlock)Marshal.PtrToStructure(audiPtr, typeof(QNX6_AudiSuperBlock));
Marshal.FreeHGlobal(audiPtr);
QNX6_AudiSuperBlock audiSb =
Helpers.Marshal.ByteArrayToStructureLittleEndian<QNX6_AudiSuperBlock>(audiSector);
QNX6_SuperBlock qnxSb = new QNX6_SuperBlock();
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(qnxSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(qnxSb));
qnxSb = (QNX6_SuperBlock)Marshal.PtrToStructure(sbPtr, typeof(QNX6_SuperBlock));
Marshal.FreeHGlobal(sbPtr);
QNX6_SuperBlock qnxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<QNX6_SuperBlock>(sector);
bool audi = audiSb.magic == QNX6_MAGIC;

View File

@@ -76,10 +76,7 @@ namespace DiscImageChef.Filesystems
byte[] hbSector = imagePlugin.ReadSector(1 + partition.Start);
GCHandle handle = GCHandle.Alloc(hbSector, GCHandleType.Pinned);
RT11HomeBlock homeblock =
(RT11HomeBlock)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(RT11HomeBlock));
handle.Free();
RT11HomeBlock homeblock = Helpers.Marshal.ByteArrayToStructureLittleEndian<RT11HomeBlock>(hbSector);
/* TODO: Is this correct?
* Assembler:

View File

@@ -63,10 +63,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize);
if(sector.Length < Marshal.SizeOf(refsVhdr)) return false;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(refsVhdr));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(refsVhdr));
refsVhdr = (RefsVolumeHeader)Marshal.PtrToStructure(sbPtr, typeof(RefsVolumeHeader));
Marshal.FreeHGlobal(sbPtr);
refsVhdr = Helpers.Marshal.ByteArrayToStructureLittleEndian<RefsVolumeHeader>(sector);
return refsVhdr.identifier == FSRS && ArrayHelpers.ArrayIsNullOrEmpty(refsVhdr.mustBeZero) &&
refsVhdr.signature.SequenceEqual(refsSignature);
@@ -87,10 +84,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize);
if(sector.Length < Marshal.SizeOf(refsVhdr)) return;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(refsVhdr));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(refsVhdr));
refsVhdr = (RefsVolumeHeader)Marshal.PtrToStructure(sbPtr, typeof(RefsVolumeHeader));
Marshal.FreeHGlobal(sbPtr);
refsVhdr = Helpers.Marshal.ByteArrayToStructureLittleEndian<RefsVolumeHeader>(sector);
DicConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.jump empty? = {0}",
ArrayHelpers.ArrayIsNullOrEmpty(refsVhdr.jump));

View File

@@ -71,10 +71,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
if(sector.Length < Marshal.SizeOf(reiserSb)) return false;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(reiserSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(reiserSb));
reiserSb = (Reiser_Superblock)Marshal.PtrToStructure(sbPtr, typeof(Reiser_Superblock));
Marshal.FreeHGlobal(sbPtr);
reiserSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<Reiser_Superblock>(sector);
return reiser35_magic.SequenceEqual(reiserSb.magic) || reiser36_magic.SequenceEqual(reiserSb.magic) ||
reiserJr_magic.SequenceEqual(reiserSb.magic);
@@ -98,10 +95,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
if(sector.Length < Marshal.SizeOf(reiserSb)) return;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(reiserSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(reiserSb));
reiserSb = (Reiser_Superblock)Marshal.PtrToStructure(sbPtr, typeof(Reiser_Superblock));
Marshal.FreeHGlobal(sbPtr);
reiserSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<Reiser_Superblock>(sector);
if(!reiser35_magic.SequenceEqual(reiserSb.magic) && !reiser36_magic.SequenceEqual(reiserSb.magic) &&
!reiserJr_magic.SequenceEqual(reiserSb.magic)) return;

View File

@@ -72,10 +72,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
if(sector.Length < Marshal.SizeOf(reiserSb)) return false;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(reiserSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(reiserSb));
reiserSb = (Reiser4_Superblock)Marshal.PtrToStructure(sbPtr, typeof(Reiser4_Superblock));
Marshal.FreeHGlobal(sbPtr);
reiserSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<Reiser4_Superblock>(sector);
return reiser4_magic.SequenceEqual(reiserSb.magic);
}
@@ -98,10 +95,7 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize);
if(sector.Length < Marshal.SizeOf(reiserSb)) return;
IntPtr sbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(reiserSb));
Marshal.Copy(sector, 0, sbPtr, Marshal.SizeOf(reiserSb));
reiserSb = (Reiser4_Superblock)Marshal.PtrToStructure(sbPtr, typeof(Reiser4_Superblock));
Marshal.FreeHGlobal(sbPtr);
reiserSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<Reiser4_Superblock>(sector);
if(!reiser4_magic.SequenceEqual(reiserSb.magic)) return;

View File

@@ -77,10 +77,7 @@ namespace DiscImageChef.Filesystems
switch(magic)
{
case SQUASH_MAGIC:
IntPtr sqSbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(sqSb));
Marshal.Copy(sector, 0, sqSbPtr, Marshal.SizeOf(sqSb));
sqSb = (SquashSuperBlock)Marshal.PtrToStructure(sqSbPtr, typeof(SquashSuperBlock));
Marshal.FreeHGlobal(sqSbPtr);
sqSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<SquashSuperBlock>(sector);
break;
case SQUASH_CIGAM:
sqSb = Helpers.Marshal.ByteArrayToStructureBigEndian<SquashSuperBlock>(sector);

View File

@@ -73,13 +73,7 @@ namespace DiscImageChef.Filesystems
foreach(ulong position in positions.Where(position => position + partition.Start < partition.End))
{
sector = imagePlugin.ReadSector(position);
anchor = new AnchorVolumeDescriptorPointer();
IntPtr anchorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(anchor));
Marshal.Copy(sector, 0, anchorPtr, Marshal.SizeOf(anchor));
anchor =
(AnchorVolumeDescriptorPointer)Marshal.PtrToStructure(anchorPtr,
typeof(AnchorVolumeDescriptorPointer));
Marshal.FreeHGlobal(anchorPtr);
anchor = Helpers.Marshal.ByteArrayToStructureLittleEndian<AnchorVolumeDescriptorPointer>(sector);
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.tagIdentifier = {0}", anchor.tag.tagIdentifier);
DicConsole.DebugWriteLine("UDF Plugin", "anchor.tag.descriptorVersion = {0}",
@@ -129,11 +123,8 @@ namespace DiscImageChef.Filesystems
if(tagId == TagIdentifier.LogicalVolumeDescriptor)
{
LogicalVolumeDescriptor lvd = new LogicalVolumeDescriptor();
IntPtr lvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvd));
Marshal.Copy(sector, 0, lvdPtr, Marshal.SizeOf(lvd));
lvd = (LogicalVolumeDescriptor)Marshal.PtrToStructure(lvdPtr, typeof(LogicalVolumeDescriptor));
Marshal.FreeHGlobal(lvdPtr);
LogicalVolumeDescriptor lvd =
Helpers.Marshal.ByteArrayToStructureLittleEndian<LogicalVolumeDescriptor>(sector);
return UDF_Magic.SequenceEqual(lvd.domainIdentifier.identifier);
}
@@ -164,13 +155,7 @@ namespace DiscImageChef.Filesystems
foreach(ulong position in positions)
{
sector = imagePlugin.ReadSector(position);
anchor = new AnchorVolumeDescriptorPointer();
IntPtr anchorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(anchor));
Marshal.Copy(sector, 0, anchorPtr, Marshal.SizeOf(anchor));
anchor =
(AnchorVolumeDescriptorPointer)Marshal.PtrToStructure(anchorPtr,
typeof(AnchorVolumeDescriptorPointer));
Marshal.FreeHGlobal(anchorPtr);
anchor = Helpers.Marshal.ByteArrayToStructureLittleEndian<AnchorVolumeDescriptorPointer>(sector);
if(anchor.tag.tagIdentifier ==
TagIdentifier.AnchorVolumeDescriptorPointer &&
@@ -201,18 +186,10 @@ namespace DiscImageChef.Filesystems
switch(tagId)
{
case TagIdentifier.LogicalVolumeDescriptor:
IntPtr lvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvd));
Marshal.Copy(sector, 0, lvdPtr, Marshal.SizeOf(lvd));
lvd = (LogicalVolumeDescriptor)
Marshal.PtrToStructure(lvdPtr, typeof(LogicalVolumeDescriptor));
Marshal.FreeHGlobal(lvdPtr);
lvd = Helpers.Marshal.ByteArrayToStructureLittleEndian<LogicalVolumeDescriptor>(sector);
break;
case TagIdentifier.PrimaryVolumeDescriptor:
IntPtr pvdPtr = Marshal.AllocHGlobal(Marshal.SizeOf(pvd));
Marshal.Copy(sector, 0, pvdPtr, Marshal.SizeOf(pvd));
pvd = (PrimaryVolumeDescriptor)
Marshal.PtrToStructure(pvdPtr, typeof(PrimaryVolumeDescriptor));
Marshal.FreeHGlobal(pvdPtr);
pvd = Helpers.Marshal.ByteArrayToStructureLittleEndian<PrimaryVolumeDescriptor>(sector);
break;
}
}
@@ -222,24 +199,18 @@ namespace DiscImageChef.Filesystems
}
sector = imagePlugin.ReadSector(lvd.integritySequenceExtent.location);
IntPtr lvidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvid));
Marshal.Copy(sector, 0, lvidPtr, Marshal.SizeOf(lvid));
lvid =
(LogicalVolumeIntegrityDescriptor)
Marshal.PtrToStructure(lvidPtr, typeof(LogicalVolumeIntegrityDescriptor));
Marshal.FreeHGlobal(lvidPtr);
lvid = Helpers.Marshal.ByteArrayToStructureLittleEndian<LogicalVolumeIntegrityDescriptor>(sector);
if(lvid.tag.tagIdentifier == TagIdentifier.LogicalVolumeIntegrityDescriptor &&
lvid.tag.tagLocation == lvd.integritySequenceExtent.location)
{
IntPtr lvidiuPtr = Marshal.AllocHGlobal(Marshal.SizeOf(lvidiu));
Marshal.Copy(sector, (int)(lvid.numberOfPartitions * 8 + 80), lvidiuPtr, Marshal.SizeOf(lvidiu));
lvidiu =
(LogicalVolumeIntegrityDescriptorImplementationUse)Marshal.PtrToStructure(lvidiuPtr,
typeof(
LogicalVolumeIntegrityDescriptorImplementationUse
));
Marshal.FreeHGlobal(lvidiuPtr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<LogicalVolumeIntegrityDescriptorImplementationUse>(sector,
(int)(lvid
.numberOfPartitions *
8 + 80),
Marshal
.SizeOf(lvidiu));
}
else lvid = new LogicalVolumeIntegrityDescriptor();

View File

@@ -75,11 +75,7 @@ namespace DiscImageChef.Filesystems
ulong vmfsSuperOff = VMFS_BASE / imagePlugin.Info.SectorSize;
byte[] sector = imagePlugin.ReadSector(partition.Start + vmfsSuperOff);
VolumeInfo volInfo = new VolumeInfo();
IntPtr volInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(volInfo));
Marshal.Copy(sector, 0, volInfoPtr, Marshal.SizeOf(volInfo));
volInfo = (VolumeInfo)Marshal.PtrToStructure(volInfoPtr, typeof(VolumeInfo));
Marshal.FreeHGlobal(volInfoPtr);
VolumeInfo volInfo = Helpers.Marshal.ByteArrayToStructureLittleEndian<VolumeInfo>(sector);
StringBuilder sbInformation = new StringBuilder();

View File

@@ -73,11 +73,7 @@ namespace DiscImageChef.Filesystems
ulong vmfsSuperOff = VXFS_BASE / imagePlugin.Info.SectorSize;
byte[] sector = imagePlugin.ReadSector(partition.Start + vmfsSuperOff);
VxSuperBlock vxSb = new VxSuperBlock();
IntPtr vxSbPtr = Marshal.AllocHGlobal(Marshal.SizeOf(vxSb));
Marshal.Copy(sector, 0, vxSbPtr, Marshal.SizeOf(vxSb));
vxSb = (VxSuperBlock)Marshal.PtrToStructure(vxSbPtr, typeof(VxSuperBlock));
Marshal.FreeHGlobal(vxSbPtr);
VxSuperBlock vxSb = Helpers.Marshal.ByteArrayToStructureLittleEndian<VxSuperBlock>(sector);
StringBuilder sbInformation = new StringBuilder();

View File

@@ -64,10 +64,7 @@ namespace DiscImageChef.Filesystems
if(sbSizeInSectors + partition.Start >= partition.End) return false;
byte[] sbSector = imagePlugin.ReadSectors(partition.Start, sbSizeInSectors);
IntPtr sbPtr = Marshal.AllocHGlobal(sbSizeInBytes);
Marshal.Copy(sbSector, 0, sbPtr, sbSizeInBytes);
XiaSuperBlock supblk = (XiaSuperBlock)Marshal.PtrToStructure(sbPtr, typeof(XiaSuperBlock));
Marshal.FreeHGlobal(sbPtr);
XiaSuperBlock supblk = Helpers.Marshal.ByteArrayToStructureLittleEndian<XiaSuperBlock>(sbSector);
return supblk.s_magic == XIAFS_SUPER_MAGIC;
}
@@ -85,10 +82,7 @@ namespace DiscImageChef.Filesystems
if(sbSizeInBytes % imagePlugin.Info.SectorSize > 0) sbSizeInSectors++;
byte[] sbSector = imagePlugin.ReadSectors(partition.Start, sbSizeInSectors);
IntPtr sbPtr = Marshal.AllocHGlobal(sbSizeInBytes);
Marshal.Copy(sbSector, 0, sbPtr, sbSizeInBytes);
XiaSuperBlock supblk = (XiaSuperBlock)Marshal.PtrToStructure(sbPtr, typeof(XiaSuperBlock));
Marshal.FreeHGlobal(sbPtr);
XiaSuperBlock supblk = Helpers.Marshal.ByteArrayToStructureLittleEndian<XiaSuperBlock>(sbSector);
sb.AppendFormat("{0} bytes per zone", supblk.s_zone_size).AppendLine();
sb.AppendFormat("{0} zones in volume ({1} bytes)", supblk.s_nzones, supblk.s_nzones * supblk.s_zone_size)

View File

@@ -121,20 +121,9 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize);
if(sector.Length < Marshal.SizeOf(newHdr)) return false;
IntPtr oldPtr = Marshal.AllocHGlobal(Marshal.SizeOf(oldHdr));
Marshal.Copy(sector, 0, oldPtr, Marshal.SizeOf(oldHdr));
oldHdr = (spcl16)Marshal.PtrToStructure(oldPtr, typeof(spcl16));
Marshal.FreeHGlobal(oldPtr);
IntPtr aixPtr = Marshal.AllocHGlobal(Marshal.SizeOf(aixHdr));
Marshal.Copy(sector, 0, aixPtr, Marshal.SizeOf(aixHdr));
aixHdr = (spcl_aix)Marshal.PtrToStructure(aixPtr, typeof(spcl_aix));
Marshal.FreeHGlobal(aixPtr);
IntPtr newPtr = Marshal.AllocHGlobal(Marshal.SizeOf(newHdr));
Marshal.Copy(sector, 0, newPtr, Marshal.SizeOf(newHdr));
newHdr = (s_spcl)Marshal.PtrToStructure(newPtr, typeof(s_spcl));
Marshal.FreeHGlobal(newPtr);
oldHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian<spcl16>(sector);
aixHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian<spcl_aix>(sector);
newHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian<s_spcl>(sector);
DicConsole.DebugWriteLine("dump(8) plugin", "old magic = 0x{0:X8}", oldHdr.c_magic);
DicConsole.DebugWriteLine("dump(8) plugin", "aix magic = 0x{0:X8}", aixHdr.c_magic);
@@ -164,20 +153,9 @@ namespace DiscImageChef.Filesystems
byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize);
if(sector.Length < Marshal.SizeOf(newHdr)) return;
IntPtr oldPtr = Marshal.AllocHGlobal(Marshal.SizeOf(oldHdr));
Marshal.Copy(sector, 0, oldPtr, Marshal.SizeOf(oldHdr));
oldHdr = (spcl16)Marshal.PtrToStructure(oldPtr, typeof(spcl16));
Marshal.FreeHGlobal(oldPtr);
IntPtr aixPtr = Marshal.AllocHGlobal(Marshal.SizeOf(aixHdr));
Marshal.Copy(sector, 0, aixPtr, Marshal.SizeOf(aixHdr));
aixHdr = (spcl_aix)Marshal.PtrToStructure(aixPtr, typeof(spcl_aix));
Marshal.FreeHGlobal(aixPtr);
IntPtr newPtr = Marshal.AllocHGlobal(Marshal.SizeOf(newHdr));
Marshal.Copy(sector, 0, newPtr, Marshal.SizeOf(newHdr));
newHdr = (s_spcl)Marshal.PtrToStructure(newPtr, typeof(s_spcl));
Marshal.FreeHGlobal(newPtr);
oldHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian<spcl16>(sector);
aixHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian<spcl_aix>(sector);
newHdr = Helpers.Marshal.ByteArrayToStructureLittleEndian<s_spcl>(sector);
bool useOld = false;
bool useAix = false;

View File

@@ -60,10 +60,7 @@ namespace DiscImageChef.Filesystems
byte[] vbrSector = imagePlugin.ReadSector(0 + partition.Start);
if(vbrSector.Length < 512) return false;
IntPtr vbrPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(vbrSector, 0, vbrPtr, 512);
VolumeBootRecord vbr = (VolumeBootRecord)Marshal.PtrToStructure(vbrPtr, typeof(VolumeBootRecord));
Marshal.FreeHGlobal(vbrPtr);
VolumeBootRecord vbr = Helpers.Marshal.ByteArrayToStructureLittleEndian<VolumeBootRecord>(vbrSector);
return signature.SequenceEqual(vbr.signature);
}
@@ -78,23 +75,14 @@ namespace DiscImageChef.Filesystems
XmlFsType = new FileSystemType();
byte[] vbrSector = imagePlugin.ReadSector(0 + partition.Start);
IntPtr vbrPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(vbrSector, 0, vbrPtr, 512);
VolumeBootRecord vbr = (VolumeBootRecord)Marshal.PtrToStructure(vbrPtr, typeof(VolumeBootRecord));
Marshal.FreeHGlobal(vbrPtr);
VolumeBootRecord vbr = Helpers.Marshal.ByteArrayToStructureLittleEndian<VolumeBootRecord>(vbrSector);
byte[] parametersSector = imagePlugin.ReadSector(9 + partition.Start);
IntPtr parametersPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(parametersSector, 0, parametersPtr, 512);
OemParameterTable parametersTable =
(OemParameterTable)Marshal.PtrToStructure(parametersPtr, typeof(OemParameterTable));
Marshal.FreeHGlobal(parametersPtr);
Helpers.Marshal.ByteArrayToStructureLittleEndian<OemParameterTable>(parametersSector);
byte[] chkSector = imagePlugin.ReadSector(11 + partition.Start);
IntPtr chkPtr = Marshal.AllocHGlobal(512);
Marshal.Copy(chkSector, 0, chkPtr, 512);
ChecksumSector chksector = (ChecksumSector)Marshal.PtrToStructure(chkPtr, typeof(ChecksumSector));
Marshal.FreeHGlobal(chkPtr);
ChecksumSector chksector = Helpers.Marshal.ByteArrayToStructureLittleEndian<ChecksumSector>(chkSector);
sb.AppendLine("Microsoft exFAT");
sb.AppendFormat("Partition offset: {0}", vbr.offset).AppendLine();

View File

@@ -209,10 +209,7 @@ namespace DiscImageChef.Filesystems
byte[] sbSector = imagePlugin.ReadSectors(sbSectorOff + partition.Start, sbSizeInSectors);
byte[] sblock = new byte[sbSizeInBytes];
Array.Copy(sbSector, sbOff, sblock, 0, sbSizeInBytes);
IntPtr sbPtr = Marshal.AllocHGlobal(sbSizeInBytes);
Marshal.Copy(sblock, 0, sbPtr, sbSizeInBytes);
ext2FSSuperBlock supblk = (ext2FSSuperBlock)Marshal.PtrToStructure(sbPtr, typeof(ext2FSSuperBlock));
Marshal.FreeHGlobal(sbPtr);
ext2FSSuperBlock supblk = Helpers.Marshal.ByteArrayToStructureLittleEndian<ext2FSSuperBlock>(sblock);
XmlFsType = new FileSystemType();