mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
General code cleanup and style refactor.
This commit is contained in:
@@ -30,8 +30,6 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -42,6 +40,8 @@ using Aaru.CommonTypes.Interfaces;
|
||||
using Aaru.Console;
|
||||
using Aaru.Helpers;
|
||||
|
||||
namespace Aaru.DiscImages;
|
||||
|
||||
public sealed partial class Vhdx
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@@ -53,7 +53,7 @@ public sealed partial class Vhdx
|
||||
if(stream.Length < 512)
|
||||
return ErrorNumber.InvalidArgument;
|
||||
|
||||
var vhdxIdB = new byte[Marshal.SizeOf<Identifier>()];
|
||||
byte[] vhdxIdB = new byte[Marshal.SizeOf<Identifier>()];
|
||||
stream.EnsureRead(vhdxIdB, 0, Marshal.SizeOf<Identifier>());
|
||||
_id = Marshal.ByteArrayToStructureLittleEndian<Identifier>(vhdxIdB);
|
||||
|
||||
@@ -63,7 +63,7 @@ public sealed partial class Vhdx
|
||||
_imageInfo.Application = Encoding.Unicode.GetString(_id.creator);
|
||||
|
||||
stream.Seek(64 * 1024, SeekOrigin.Begin);
|
||||
var vHdrB = new byte[Marshal.SizeOf<Header>()];
|
||||
byte[] vHdrB = new byte[Marshal.SizeOf<Header>()];
|
||||
stream.EnsureRead(vHdrB, 0, Marshal.SizeOf<Header>());
|
||||
_vHdr = Marshal.ByteArrayToStructureLittleEndian<Header>(vHdrB);
|
||||
|
||||
@@ -83,7 +83,7 @@ public sealed partial class Vhdx
|
||||
}
|
||||
|
||||
stream.Seek(192 * 1024, SeekOrigin.Begin);
|
||||
var vRegTableB = new byte[Marshal.SizeOf<RegionTableHeader>()];
|
||||
byte[] vRegTableB = new byte[Marshal.SizeOf<RegionTableHeader>()];
|
||||
stream.EnsureRead(vRegTableB, 0, Marshal.SizeOf<RegionTableHeader>());
|
||||
_vRegHdr = Marshal.ByteArrayToStructureLittleEndian<RegionTableHeader>(vRegTableB);
|
||||
|
||||
@@ -104,9 +104,9 @@ public sealed partial class Vhdx
|
||||
|
||||
_vRegs = new RegionTableEntry[_vRegHdr.entries];
|
||||
|
||||
for(var i = 0; i < _vRegs.Length; i++)
|
||||
for(int i = 0; i < _vRegs.Length; i++)
|
||||
{
|
||||
var vRegB = new byte[System.Runtime.InteropServices.Marshal.SizeOf(_vRegs[i])];
|
||||
byte[] vRegB = new byte[System.Runtime.InteropServices.Marshal.SizeOf(_vRegs[i])];
|
||||
stream.EnsureRead(vRegB, 0, System.Runtime.InteropServices.Marshal.SizeOf(_vRegs[i]));
|
||||
_vRegs[i] = Marshal.ByteArrayToStructureLittleEndian<RegionTableEntry>(vRegB);
|
||||
|
||||
@@ -116,8 +116,8 @@ public sealed partial class Vhdx
|
||||
_metadataOffset = (long)_vRegs[i].offset;
|
||||
else if((_vRegs[i].flags & REGION_FLAGS_REQUIRED) == REGION_FLAGS_REQUIRED)
|
||||
{
|
||||
AaruConsole.
|
||||
ErrorWriteLine($"Found unsupported and required region Guid {_vRegs[i].guid}, not proceeding with image.");
|
||||
AaruConsole.ErrorWriteLine($"Found unsupported and required region Guid {_vRegs[i].guid
|
||||
}, not proceeding with image.");
|
||||
|
||||
return ErrorNumber.InvalidArgument;
|
||||
}
|
||||
@@ -140,15 +140,15 @@ public sealed partial class Vhdx
|
||||
uint fileParamsOff = 0, vdSizeOff = 0, p83Off = 0, logOff = 0, physOff = 0, parentOff = 0;
|
||||
|
||||
stream.Seek(_metadataOffset, SeekOrigin.Begin);
|
||||
var metTableB = new byte[Marshal.SizeOf<MetadataTableHeader>()];
|
||||
byte[] metTableB = new byte[Marshal.SizeOf<MetadataTableHeader>()];
|
||||
stream.EnsureRead(metTableB, 0, Marshal.SizeOf<MetadataTableHeader>());
|
||||
_vMetHdr = Marshal.ByteArrayToStructureLittleEndian<MetadataTableHeader>(metTableB);
|
||||
|
||||
_vMets = new MetadataTableEntry[_vMetHdr.entries];
|
||||
|
||||
for(var i = 0; i < _vMets.Length; i++)
|
||||
for(int i = 0; i < _vMets.Length; i++)
|
||||
{
|
||||
var vMetB = new byte[System.Runtime.InteropServices.Marshal.SizeOf(_vMets[i])];
|
||||
byte[] vMetB = new byte[System.Runtime.InteropServices.Marshal.SizeOf(_vMets[i])];
|
||||
stream.EnsureRead(vMetB, 0, System.Runtime.InteropServices.Marshal.SizeOf(_vMets[i]));
|
||||
_vMets[i] = Marshal.ByteArrayToStructureLittleEndian<MetadataTableEntry>(vMetB);
|
||||
|
||||
@@ -166,8 +166,8 @@ public sealed partial class Vhdx
|
||||
parentOff = _vMets[i].offset;
|
||||
else if((_vMets[i].flags & METADATA_FLAGS_REQUIRED) == METADATA_FLAGS_REQUIRED)
|
||||
{
|
||||
AaruConsole.
|
||||
ErrorWriteLine($"Found unsupported and required metadata Guid {_vMets[i].itemId}, not proceeding with image.");
|
||||
AaruConsole.ErrorWriteLine($"Found unsupported and required metadata Guid {_vMets[i].itemId
|
||||
}, not proceeding with image.");
|
||||
|
||||
return ErrorNumber.InvalidArgument;
|
||||
}
|
||||
@@ -248,23 +248,23 @@ public sealed partial class Vhdx
|
||||
(_vFileParms.flags & FILE_FLAGS_HAS_PARENT) == FILE_FLAGS_HAS_PARENT)
|
||||
{
|
||||
stream.Seek(parentOff + _metadataOffset, SeekOrigin.Begin);
|
||||
var vParHdrB = new byte[Marshal.SizeOf<ParentLocatorHeader>()];
|
||||
byte[] vParHdrB = new byte[Marshal.SizeOf<ParentLocatorHeader>()];
|
||||
stream.EnsureRead(vParHdrB, 0, Marshal.SizeOf<ParentLocatorHeader>());
|
||||
_vParHdr = Marshal.ByteArrayToStructureLittleEndian<ParentLocatorHeader>(vParHdrB);
|
||||
|
||||
if(_vParHdr.locatorType != _parentTypeVhdxGuid)
|
||||
{
|
||||
AaruConsole.
|
||||
ErrorWriteLine($"Found unsupported and required parent locator type {_vParHdr.locatorType}, not proceeding with image.");
|
||||
AaruConsole.ErrorWriteLine($"Found unsupported and required parent locator type {_vParHdr.locatorType
|
||||
}, not proceeding with image.");
|
||||
|
||||
return ErrorNumber.NotSupported;
|
||||
}
|
||||
|
||||
_vPars = new ParentLocatorEntry[_vParHdr.keyValueCount];
|
||||
|
||||
for(var i = 0; i < _vPars.Length; i++)
|
||||
for(int i = 0; i < _vPars.Length; i++)
|
||||
{
|
||||
var vParB = new byte[System.Runtime.InteropServices.Marshal.SizeOf(_vPars[i])];
|
||||
byte[] vParB = new byte[System.Runtime.InteropServices.Marshal.SizeOf(_vPars[i])];
|
||||
stream.EnsureRead(vParB, 0, System.Runtime.InteropServices.Marshal.SizeOf(_vPars[i]));
|
||||
_vPars[i] = Marshal.ByteArrayToStructureLittleEndian<ParentLocatorEntry>(vParB);
|
||||
}
|
||||
@@ -280,12 +280,12 @@ public sealed partial class Vhdx
|
||||
_vParHdr.locatorType == _parentTypeVhdxGuid)
|
||||
{
|
||||
_parentImage = new Vhdx();
|
||||
var parentWorks = false;
|
||||
bool parentWorks = false;
|
||||
|
||||
foreach(ParentLocatorEntry parentEntry in _vPars)
|
||||
{
|
||||
stream.Seek(parentEntry.keyOffset + _metadataOffset, SeekOrigin.Begin);
|
||||
var tmpKey = new byte[parentEntry.keyLength];
|
||||
byte[] tmpKey = new byte[parentEntry.keyLength];
|
||||
stream.EnsureRead(tmpKey, 0, tmpKey.Length);
|
||||
string entryType = Encoding.Unicode.GetString(tmpKey);
|
||||
|
||||
@@ -294,7 +294,7 @@ public sealed partial class Vhdx
|
||||
if(string.Compare(entryType, RELATIVE_PATH_KEY, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
stream.Seek(parentEntry.valueOffset + _metadataOffset, SeekOrigin.Begin);
|
||||
var tmpVal = new byte[parentEntry.valueLength];
|
||||
byte[] tmpVal = new byte[parentEntry.valueLength];
|
||||
stream.EnsureRead(tmpVal, 0, tmpVal.Length);
|
||||
string entryValue = Encoding.Unicode.GetString(tmpVal);
|
||||
|
||||
@@ -338,7 +338,7 @@ public sealed partial class Vhdx
|
||||
string.Compare(entryType, ABSOLUTE_WIN32_PATH_KEY, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
stream.Seek(parentEntry.valueOffset + _metadataOffset, SeekOrigin.Begin);
|
||||
var tmpVal = new byte[parentEntry.valueLength];
|
||||
byte[] tmpVal = new byte[parentEntry.valueLength];
|
||||
stream.EnsureRead(tmpVal, 0, tmpVal.Length);
|
||||
string entryValue = Encoding.Unicode.GetString(tmpVal);
|
||||
|
||||
@@ -391,13 +391,13 @@ public sealed partial class Vhdx
|
||||
batEntries = sectorBitmapBlocks * (_chunkRatio - 1);
|
||||
}
|
||||
else
|
||||
batEntries = (long)(_dataBlocks + (_dataBlocks - 1) / (ulong)_chunkRatio);
|
||||
batEntries = (long)(_dataBlocks + ((_dataBlocks - 1) / (ulong)_chunkRatio));
|
||||
|
||||
AaruConsole.DebugWriteLine("VHDX plugin", "Reading BAT");
|
||||
|
||||
long readChunks = 0;
|
||||
_blockAllocationTable = new ulong[_dataBlocks];
|
||||
var batB = new byte[batEntries * 8];
|
||||
byte[] batB = new byte[batEntries * 8];
|
||||
stream.Seek(_batOffset, SeekOrigin.Begin);
|
||||
stream.EnsureRead(batB, 0, batB.Length);
|
||||
|
||||
@@ -407,14 +407,14 @@ public sealed partial class Vhdx
|
||||
if(readChunks == _chunkRatio)
|
||||
{
|
||||
if(_hasParent)
|
||||
_sectorBitmapPointers[skipSize / 8] = BitConverter.ToUInt64(batB, (int)(i * 8 + skipSize));
|
||||
_sectorBitmapPointers[skipSize / 8] = BitConverter.ToUInt64(batB, (int)((i * 8) + skipSize));
|
||||
|
||||
readChunks = 0;
|
||||
skipSize += 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
_blockAllocationTable[i] = BitConverter.ToUInt64(batB, (int)(i * 8 + skipSize));
|
||||
_blockAllocationTable[i] = BitConverter.ToUInt64(batB, (int)((i * 8) + skipSize));
|
||||
readChunks++;
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ public sealed partial class Vhdx
|
||||
break;
|
||||
case SECTOR_BITMAP_PRESENT:
|
||||
stream.Seek((long)((pt & BAT_FILE_OFFSET_MASK) * 1048576), SeekOrigin.Begin);
|
||||
var bmp = new byte[1048576];
|
||||
byte[] bmp = new byte[1048576];
|
||||
stream.EnsureRead(bmp, 0, bmp.Length);
|
||||
sectorBmpMs.Write(bmp, 0, bmp.Length);
|
||||
|
||||
@@ -441,8 +441,8 @@ public sealed partial class Vhdx
|
||||
default:
|
||||
if((pt & BAT_FLAGS_MASK) != 0)
|
||||
{
|
||||
AaruConsole.
|
||||
ErrorWriteLine($"Unsupported sector bitmap block flags (0x{pt & BAT_FLAGS_MASK:X16}) found, not proceeding.");
|
||||
AaruConsole.ErrorWriteLine($"Unsupported sector bitmap block flags (0x{pt & BAT_FLAGS_MASK
|
||||
:X16}) found, not proceeding.");
|
||||
|
||||
return ErrorNumber.InvalidArgument;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user