REFACTOR: Reformat code.

This commit is contained in:
2017-12-19 20:33:03 +00:00
parent 77edc7c91c
commit e6f6ace80b
704 changed files with 82627 additions and 83641 deletions

View File

@@ -57,19 +57,17 @@ namespace DiscImageChef.PartPlugins
PluginUUID = new Guid("36405F8D-4F1A-07F5-209C-223D735D6D22");
}
public override bool GetInformation(ImagePlugins.ImagePlugin imagePlugin, out List<CommonTypes.Partition> partitions, ulong sectorOffset)
public override bool GetInformation(ImagePlugins.ImagePlugin imagePlugin,
out List<CommonTypes.Partition> partitions, ulong sectorOffset)
{
uint sector_size;
if(imagePlugin.GetSectorSize() == 2352 || imagePlugin.GetSectorSize() == 2448)
sector_size = 2048;
else
sector_size = imagePlugin.GetSectorSize();
if(imagePlugin.GetSectorSize() == 2352 || imagePlugin.GetSectorSize() == 2448) sector_size = 2048;
else sector_size = imagePlugin.GetSectorSize();
partitions = new List<CommonTypes.Partition>();
if(sectorOffset + 2 >= imagePlugin.GetSectors())
return false;
if(sectorOffset + 2 >= imagePlugin.GetSectors()) return false;
byte[] ddm_sector = imagePlugin.ReadSector(sectorOffset);
AppleDriverDescriptorMap ddm;
@@ -83,9 +81,8 @@ namespace DiscImageChef.PartPlugins
ddm_sector = tmp;
max_drivers = 29;
}
else if(sector_size < 256)
return false;
else if(sector_size < 256) return false;
ddm = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleDriverDescriptorMap>(ddm_sector);
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbSig = 0x{0:X4}", ddm.sbSig);
@@ -108,13 +105,15 @@ namespace DiscImageChef.PartPlugins
byte[] tmp = new byte[8];
Array.Copy(ddm_sector, 18 + i * 8, tmp, 0, 8);
ddm.sbMap[i] = BigEndianMarshal.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, i);
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbMap[{1}].ddType = {0}", ddm.sbMap[i].ddType, i);
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,
i);
DicConsole.DebugWriteLine("AppleMap Plugin", "ddm.sbMap[{1}].ddType = {0}", ddm.sbMap[i].ddType,
i);
if(ddm.sbMap[i].ddSize == 0) continue;
if(ddm.sbMap[i].ddSize == 0)
continue;
CommonTypes.Partition part = new CommonTypes.Partition()
{
Size = (ulong)(ddm.sbMap[i].ddSize * 512),
@@ -125,8 +124,7 @@ namespace DiscImageChef.PartPlugins
Type = "Apple_Driver"
};
if((ddm.sbMap[i].ddSize * 512) % sector_size > 0)
part.Length++;
if((ddm.sbMap[i].ddSize * 512) % sector_size > 0) part.Length++;
partitions.Add(part);
@@ -136,24 +134,29 @@ namespace DiscImageChef.PartPlugins
}
byte[] part_sector = imagePlugin.ReadSector(1 + sectorOffset);
AppleOldDevicePartitionMap old_map = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleOldDevicePartitionMap>(part_sector);
AppleOldDevicePartitionMap old_map =
BigEndianMarshal.ByteArrayToStructureBigEndian<AppleOldDevicePartitionMap>(part_sector);
// This is the easy one, no sector size mixing
if(old_map.pdSig == APM_MAGIC_OLD)
{
for(int i = 2; i < part_sector.Length; i+=12)
for(int i = 2; i < part_sector.Length; i += 12)
{
byte[] tmp = new byte[12];
Array.Copy(part_sector, i, tmp, 0, 12);
AppleMapOldPartitionEntry old_entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapOldPartitionEntry>(tmp);
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdStart = {0}", old_entry.pdStart, (i - 2) / 12);
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdSize = {0}", old_entry.pdSize, (i - 2) / 12);
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdFSID = 0x{0:X8}", old_entry.pdFSID, (i - 2) / 12);
AppleMapOldPartitionEntry old_entry =
BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapOldPartitionEntry>(tmp);
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdStart = {0}", old_entry.pdStart,
(i - 2) / 12);
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdSize = {0}", old_entry.pdSize,
(i - 2) / 12);
DicConsole.DebugWriteLine("AppleMap Plugin", "old_map.sbMap[{1}].pdFSID = 0x{0:X8}",
old_entry.pdFSID, (i - 2) / 12);
if(old_entry.pdSize == 0 && old_entry.pdFSID == 0)
{
if(old_entry.pdStart == 0)
break;
if(old_entry.pdStart == 0) break;
continue;
}
@@ -167,10 +170,8 @@ namespace DiscImageChef.PartPlugins
Scheme = Name
};
if(old_entry.pdFSID == HFS_MAGIC_OLD)
part.Type = "Apple_HFS";
else
part.Type = string.Format("0x{0:X8}", old_entry.pdFSID);
if(old_entry.pdFSID == HFS_MAGIC_OLD) part.Type = "Apple_HFS";
else part.Type = string.Format("0x{0:X8}", old_entry.pdFSID);
partitions.Add(part);
@@ -190,7 +191,7 @@ namespace DiscImageChef.PartPlugins
if(sector_size > 512)
{
byte[] tmp = new byte[512];
Array.Copy(ddm_sector, 512, tmp, 0, 512);
Array.Copy(ddm_sector, 512, tmp, 0, 512);
entry = BigEndianMarshal.ByteArrayToStructureBigEndian<AppleMapPartitionEntry>(tmp);
// Check for a partition entry that's 512-byte aligned
if(entry.signature == APM_MAGIC)
@@ -212,8 +213,7 @@ namespace DiscImageChef.PartPlugins
skip_ddm = sector_size;
sectors_to_read = entry_count + 2;
}
else
return partitions.Count > 0;
else return partitions.Count > 0;
}
}
else
@@ -227,8 +227,7 @@ namespace DiscImageChef.PartPlugins
skip_ddm = sector_size;
sectors_to_read = entry_count + 2;
}
else
return partitions.Count > 0;
else return partitions.Count > 0;
}
byte[] entries = imagePlugin.ReadSectors(sectorOffset, sectors_to_read);
@@ -253,19 +252,29 @@ namespace DiscImageChef.PartPlugins
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entries = {1}", i, entry.entries);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].start = {1}", i, entry.start);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].sectors = {1}", i, entry.sectors);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].name = \"{1}\"", i, StringHandlers.CToString(entry.name));
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].type = \"{1}\"", i, StringHandlers.CToString(entry.type));
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_data_block = {1}", i, entry.first_data_block);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].name = \"{1}\"", i,
StringHandlers.CToString(entry.name));
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].type = \"{1}\"", i,
StringHandlers.CToString(entry.type));
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_data_block = {1}", i,
entry.first_data_block);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].data_sectors = {1}", i, entry.data_sectors);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].flags = {1}", i, (AppleMapFlags)entry.flags);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_boot_block = {1}", i, entry.first_boot_block);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].flags = {1}", i,
(AppleMapFlags)entry.flags);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].first_boot_block = {1}", i,
entry.first_boot_block);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].boot_size = {1}", i, entry.boot_size);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address = 0x{1:X8}", i, entry.load_address);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address2 = 0x{1:X8}", i, entry.load_address2);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point = 0x{1:X8}", i, entry.entry_point);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point2 = 0x{1:X8}", i, entry.entry_point2);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address = 0x{1:X8}", i,
entry.load_address);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].load_address2 = 0x{1:X8}", i,
entry.load_address2);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point = 0x{1:X8}", i,
entry.entry_point);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].entry_point2 = 0x{1:X8}", i,
entry.entry_point2);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].checksum = 0x{1:X8}", i, entry.checksum);
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].processor = \"{1}\"", i, StringHandlers.CToString(entry.processor));
DicConsole.DebugWriteLine("AppleMap Plugin", "dpme[{0}].processor = \"{1}\"", i,
StringHandlers.CToString(entry.processor));
AppleMapFlags flags = (AppleMapFlags)entry.flags;
@@ -287,22 +296,17 @@ namespace DiscImageChef.PartPlugins
Scheme = Name
};
sb.AppendLine("Partition flags:");
if(flags.HasFlag(AppleMapFlags.Valid))
sb.AppendLine("Partition is valid.");
if(flags.HasFlag(AppleMapFlags.Allocated))
sb.AppendLine("Partition entry is allocated.");
if(flags.HasFlag(AppleMapFlags.InUse))
sb.AppendLine("Partition is in use.");
if(flags.HasFlag(AppleMapFlags.Bootable))
sb.AppendLine("Partition is bootable.");
if(flags.HasFlag(AppleMapFlags.Readable))
sb.AppendLine("Partition is readable.");
if(flags.HasFlag(AppleMapFlags.Writable))
sb.AppendLine("Partition is writable.");
if(flags.HasFlag(AppleMapFlags.Valid)) sb.AppendLine("Partition is valid.");
if(flags.HasFlag(AppleMapFlags.Allocated)) sb.AppendLine("Partition entry is allocated.");
if(flags.HasFlag(AppleMapFlags.InUse)) sb.AppendLine("Partition is in use.");
if(flags.HasFlag(AppleMapFlags.Bootable)) sb.AppendLine("Partition is bootable.");
if(flags.HasFlag(AppleMapFlags.Readable)) sb.AppendLine("Partition is readable.");
if(flags.HasFlag(AppleMapFlags.Writable)) sb.AppendLine("Partition is writable.");
if(flags.HasFlag(AppleMapFlags.Bootable))
{
sb.AppendFormat("First boot sector: {0}", (entry.first_boot_block * entry_size) / sector_size).AppendLine();
sb.AppendFormat("First boot sector: {0}",
(entry.first_boot_block * entry_size) / sector_size).AppendLine();
sb.AppendFormat("Boot is {0} bytes.", entry.boot_size).AppendLine();
sb.AppendFormat("Boot load address: 0x{0:X8}", entry.load_address).AppendLine();
sb.AppendFormat("Boot entry point: 0x{0:X8}", entry.entry_point).AppendLine();
@@ -314,7 +318,8 @@ namespace DiscImageChef.PartPlugins
}
_partition.Description = sb.ToString();
if(_partition.Start < imagePlugin.ImageInfo.sectors && _partition.End < imagePlugin.ImageInfo.sectors)
if(_partition.Start < imagePlugin.ImageInfo.sectors &&
_partition.End < imagePlugin.ImageInfo.sectors)
{
partitions.Add(_partition);
sequence++;
@@ -322,14 +327,18 @@ namespace DiscImageChef.PartPlugins
// Some CD and DVDs end with an Apple_Free that expands beyond the disc size...
else if(_partition.Start < imagePlugin.ImageInfo.sectors)
{
DicConsole.DebugWriteLine("AppleMap Plugin", "Cutting last partition end ({0}) to media size ({1})", _partition.End, imagePlugin.ImageInfo.sectors - 1);
DicConsole.DebugWriteLine("AppleMap Plugin",
"Cutting last partition end ({0}) to media size ({1})",
_partition.End, imagePlugin.ImageInfo.sectors - 1);
_partition.Length = imagePlugin.ImageInfo.sectors - _partition.Start;
partitions.Add(_partition);
sequence++;
}
else
{
DicConsole.DebugWriteLine("AppleMap Plugin", "Not adding partition becaus start ({0}) is outside media size ({1})", _partition.Start, imagePlugin.ImageInfo.sectors - 1);
DicConsole.DebugWriteLine("AppleMap Plugin",
"Not adding partition becaus start ({0}) is outside media size ({1})",
_partition.Start, imagePlugin.ImageInfo.sectors - 1);
}
}
}
@@ -356,8 +365,7 @@ namespace DiscImageChef.PartPlugins
/// <summary>Number of entries of the driver descriptor</summary>
public ushort sbDrvrCount;
/// <summary>Entries of the driver descriptor</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 61)]
public AppleDriverEntry[] sbMap;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 61)] public AppleDriverEntry[] sbMap;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
@@ -377,8 +385,7 @@ namespace DiscImageChef.PartPlugins
/// <summary>Signature <see cref="APM_MAGIC_OLD"/></summary>
public ushort pdSig;
/// <summary>Entries of the driver descriptor</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 42)]
public AppleMapOldPartitionEntry[] pdMap;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 42)] public AppleMapOldPartitionEntry[] pdMap;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
@@ -421,7 +428,6 @@ namespace DiscImageChef.PartPlugins
Reserved = 0xBFFFFC00,
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct AppleMapPartitionEntry
{
@@ -436,11 +442,9 @@ namespace DiscImageChef.PartPlugins
/// <summary>Number of sectos of the partition</summary>
public uint sectors;
/// <summary>Partition name, 32 bytes, null-padded</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] name;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] name;
/// <summary>Partition type. 32 bytes, null-padded</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public byte[] type;
/// <summary>First sector of the data area</summary>
public uint first_data_block;
/// <summary>Number of sectors of the data area</summary>
@@ -462,11 +466,9 @@ namespace DiscImageChef.PartPlugins
/// <summary>Boot code checksum</summary>
public uint checksum;
/// <summary>Processor type, 16 bytes, null-padded</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] processor;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] processor;
/// <summary>Boot arguments</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public uint[] boot_arguments;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public uint[] boot_arguments;
}
}
}