2017-09-21 18:29:35 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Partimage.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Disk image plugins.
|
2017-09-21 18:29:35 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Manages partimage disk images.
|
2017-09-21 18:29:35 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2017-09-21 18:29:35 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2017-09-21 18:29:35 +01:00
|
|
|
|
using DiscImageChef.CommonTypes;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Enums;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Exceptions;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Extents;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Structs;
|
2017-09-21 18:29:35 +01:00
|
|
|
|
using DiscImageChef.Console;
|
2018-01-28 20:29:46 +00:00
|
|
|
|
using Schemas;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
#pragma warning disable 649
|
2017-09-21 18:29:35 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.DiscImages
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class Partimage : IMediaImage
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
|
const int MAX_DESCRIPTION = 4096;
|
|
|
|
|
|
const int MAX_HOSTNAMESIZE = 128;
|
|
|
|
|
|
const int MAX_DEVICENAMELEN = 512;
|
|
|
|
|
|
const int MAX_UNAMEINFOLEN = 65; //SYS_NMLN
|
|
|
|
|
|
const int MBR_SIZE_WHOLE = 512;
|
|
|
|
|
|
const int MAX_DESC_MODEL = 128;
|
|
|
|
|
|
const int MAX_DESC_GEOMETRY = 1024;
|
|
|
|
|
|
const int MAX_DESC_IDENTIFY = 4096;
|
|
|
|
|
|
const int CHECK_FREQUENCY = 65536;
|
2017-12-20 17:15:26 +00:00
|
|
|
|
const string MAGIC_BEGIN_LOCALHEADER = "MAGIC-BEGIN-LOCALHEADER";
|
2018-01-28 20:29:46 +00:00
|
|
|
|
const string MAGIC_BEGIN_DATABLOCKS = "MAGIC-BEGIN-DATABLOCKS";
|
|
|
|
|
|
const string MAGIC_BEGIN_BITMAP = "MAGIC-BEGIN-BITMAP";
|
|
|
|
|
|
const string MAGIC_BEGIN_MBRBACKUP = "MAGIC-BEGIN-MBRBACKUP";
|
|
|
|
|
|
const string MAGIC_BEGIN_TAIL = "MAGIC-BEGIN-TAIL";
|
|
|
|
|
|
const string MAGIC_BEGIN_INFO = "MAGIC-BEGIN-INFO";
|
|
|
|
|
|
const string MAGIC_BEGIN_EXT000 = "MAGIC-BEGIN-EXT000"; // reserved for future use
|
|
|
|
|
|
const string MAGIC_BEGIN_EXT001 = "MAGIC-BEGIN-EXT001"; // reserved for future use
|
|
|
|
|
|
const string MAGIC_BEGIN_EXT002 = "MAGIC-BEGIN-EXT002"; // reserved for future use
|
|
|
|
|
|
const string MAGIC_BEGIN_EXT003 = "MAGIC-BEGIN-EXT003"; // reserved for future use
|
|
|
|
|
|
const string MAGIC_BEGIN_EXT004 = "MAGIC-BEGIN-EXT004"; // reserved for future use
|
|
|
|
|
|
const string MAGIC_BEGIN_EXT005 = "MAGIC-BEGIN-EXT005"; // reserved for future use
|
|
|
|
|
|
const string MAGIC_BEGIN_EXT006 = "MAGIC-BEGIN-EXT006"; // reserved for future use
|
|
|
|
|
|
const string MAGIC_BEGIN_EXT007 = "MAGIC-BEGIN-EXT007"; // reserved for future use
|
|
|
|
|
|
const string MAGIC_BEGIN_EXT008 = "MAGIC-BEGIN-EXT008"; // reserved for future use
|
|
|
|
|
|
const string MAGIC_BEGIN_EXT009 = "MAGIC-BEGIN-EXT009"; // reserved for future use
|
|
|
|
|
|
const string MAGIC_BEGIN_VOLUME = "PaRtImAgE-VoLuMe";
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
const uint MAX_CACHE_SIZE = 16777216;
|
|
|
|
|
|
const uint MAX_CACHED_SECTORS = MAX_CACHE_SIZE / 512;
|
|
|
|
|
|
readonly byte[] partimageMagic =
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
0x50, 0x61, 0x52, 0x74, 0x49, 0x6D, 0x41, 0x67, 0x45, 0x2D, 0x56, 0x6F, 0x4C, 0x75, 0x4D, 0x65, 0x00, 0x00,
|
|
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
|
|
|
|
};
|
2018-01-28 20:29:46 +00:00
|
|
|
|
byte[] bitmap;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
PartimageMainHeader cMainHeader;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
PartimageHeader cVolumeHeader;
|
2018-01-28 20:29:46 +00:00
|
|
|
|
long dataOff;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
ExtentsULong extents;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Dictionary<ulong, ulong> extentsOff;
|
2018-01-28 20:29:46 +00:00
|
|
|
|
ImageInfo imageInfo;
|
|
|
|
|
|
Stream imageStream;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
Dictionary<ulong, byte[]> sectorCache;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
public Partimage()
|
|
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo = new ImageInfo
|
2017-12-22 06:55:04 +00:00
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
|
ReadableSectorTags = new List<SectorTagType>(),
|
|
|
|
|
|
ReadableMediaTags = new List<MediaTagType>(),
|
|
|
|
|
|
HasPartitions = false,
|
|
|
|
|
|
HasSessions = false,
|
|
|
|
|
|
Application = "Partimage",
|
|
|
|
|
|
ApplicationVersion = null,
|
|
|
|
|
|
Creator = null,
|
|
|
|
|
|
Comments = null,
|
|
|
|
|
|
MediaManufacturer = null,
|
|
|
|
|
|
MediaModel = null,
|
|
|
|
|
|
MediaSerialNumber = null,
|
|
|
|
|
|
MediaBarcode = null,
|
|
|
|
|
|
MediaPartNumber = null,
|
|
|
|
|
|
MediaSequence = 0,
|
|
|
|
|
|
LastMediaSequence = 0,
|
|
|
|
|
|
DriveManufacturer = null,
|
|
|
|
|
|
DriveModel = null,
|
|
|
|
|
|
DriveSerialNumber = null,
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DriveFirmwareRevision = null
|
|
|
|
|
|
};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public ImageInfo Info => imageInfo;
|
2017-12-26 02:51:10 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public string Name => "Partimage disk image";
|
2018-01-28 20:29:46 +00:00
|
|
|
|
public Guid Id => new Guid("AAFDB99D-2B77-49EA-831C-C9BB58C68C95");
|
2017-12-26 06:05:12 +00:00
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public string Format => "Partimage";
|
2017-12-26 06:05:12 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Partition> Partitions =>
|
2017-12-26 02:51:10 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> Tracks =>
|
2017-12-26 02:51:10 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Session> Sessions =>
|
2017-12-26 02:51:10 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public bool Identify(IFilter imageFilter)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
|
|
if(stream.Length < 512) return false;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] pHdrB = new byte[Marshal.SizeOf(cVolumeHeader)];
|
|
|
|
|
|
stream.Read(pHdrB, 0, Marshal.SizeOf(cVolumeHeader));
|
2018-06-22 08:08:38 +01:00
|
|
|
|
cVolumeHeader = new PartimageHeader();
|
2017-12-20 17:15:26 +00:00
|
|
|
|
IntPtr headerPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cVolumeHeader));
|
|
|
|
|
|
Marshal.Copy(pHdrB, 0, headerPtr, Marshal.SizeOf(cVolumeHeader));
|
|
|
|
|
|
cVolumeHeader = (PartimageHeader)Marshal.PtrToStructure(headerPtr, typeof(PartimageHeader));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Marshal.FreeHGlobal(headerPtr);
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
return partimageMagic.SequenceEqual(cVolumeHeader.magic);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public bool Open(IFilter imageFilter)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
|
|
|
|
if(stream.Length < 512) return false;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
byte[] hdrB = new byte[Marshal.SizeOf(cVolumeHeader)];
|
|
|
|
|
|
stream.Read(hdrB, 0, Marshal.SizeOf(cVolumeHeader));
|
2018-06-22 08:08:38 +01:00
|
|
|
|
cVolumeHeader = new PartimageHeader();
|
2017-12-20 17:15:26 +00:00
|
|
|
|
IntPtr headerPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cVolumeHeader));
|
|
|
|
|
|
Marshal.Copy(hdrB, 0, headerPtr, Marshal.SizeOf(cVolumeHeader));
|
|
|
|
|
|
cVolumeHeader = (PartimageHeader)Marshal.PtrToStructure(headerPtr, typeof(PartimageHeader));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Marshal.FreeHGlobal(headerPtr);
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CVolumeHeader.magic = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cVolumeHeader.magic));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CVolumeHeader.version = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cVolumeHeader.version));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CVolumeHeader.volumeNumber = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cVolumeHeader.volumeNumber);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CVolumeHeader.identificator = {0:X16}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cVolumeHeader.identificator);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
// TODO: Support multifile volumes
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(cVolumeHeader.volumeNumber > 0)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new FeatureSupportedButNotImplementedImageException("Support for multiple volumes not supported");
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
hdrB = new byte[Marshal.SizeOf(cMainHeader)];
|
|
|
|
|
|
stream.Read(hdrB, 0, Marshal.SizeOf(cMainHeader));
|
|
|
|
|
|
cMainHeader = new PartimageMainHeader();
|
2018-01-28 20:29:46 +00:00
|
|
|
|
headerPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cMainHeader));
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Marshal.Copy(hdrB, 0, headerPtr, Marshal.SizeOf(cMainHeader));
|
|
|
|
|
|
cMainHeader = (PartimageMainHeader)Marshal.PtrToStructure(headerPtr, typeof(PartimageMainHeader));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Marshal.FreeHGlobal(headerPtr);
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szFileSystem = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szFileSystem));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szPartDescription = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szPartDescription));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szOriginalDevice = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szOriginalDevice));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szFirstImageFilepath = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szFirstImageFilepath));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szUnameSysname = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szUnameSysname));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szUnameNodename = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szUnameNodename));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szUnameRelease = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szUnameRelease));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szUnameVersion = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szUnameVersion));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szUnameMachine = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szUnameMachine));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwCompression = {0} ({1})",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwCompression, (uint)cMainHeader.dwCompression);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwMainFlags = {0}", cMainHeader.dwMainFlags);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_sec = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.Second);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_min = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.Minute);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_hour = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.Hour);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_mday = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.DayOfMonth);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_mon = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.Month);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_year = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.Year);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_wday = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.DayOfWeek);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_yday = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.DayOfYear);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_isdst = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.IsDst);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_gmtoffsec = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.GmtOff);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate.tm_zone = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dateCreate.Timezone);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
DateTime dateCreate = new DateTime(1900 + (int)cMainHeader.dateCreate.Year,
|
2017-12-20 17:15:26 +00:00
|
|
|
|
(int)cMainHeader.dateCreate.Month + 1,
|
|
|
|
|
|
(int)cMainHeader.dateCreate.DayOfMonth, (int)cMainHeader.dateCreate.Hour,
|
|
|
|
|
|
(int)cMainHeader.dateCreate.Minute, (int)cMainHeader.dateCreate.Second);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dateCreate = {0}", dateCreate);
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.qwPartSize = {0}", cMainHeader.qwPartSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szHostname = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szHostname));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.szVersion = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(cMainHeader.szVersion));
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwMbrCount = {0}", cMainHeader.dwMbrCount);
|
2018-01-28 20:29:46 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwMbrSize = {0}", cMainHeader.dwMbrSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwEncryptAlgo = {0} ({1})",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwEncryptAlgo, (uint)cMainHeader.dwEncryptAlgo);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "ArrayIsNullOrEmpty(CMainHeader.cHashTestKey) = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
ArrayHelpers.ArrayIsNullOrEmpty(cMainHeader.cHashTestKey));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwReservedFuture000 = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwReservedFuture000);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwReservedFuture001 = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwReservedFuture001);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwReservedFuture002 = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwReservedFuture002);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwReservedFuture003 = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwReservedFuture003);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwReservedFuture004 = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwReservedFuture004);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwReservedFuture005 = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwReservedFuture005);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwReservedFuture006 = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwReservedFuture006);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwReservedFuture007 = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwReservedFuture007);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwReservedFuture008 = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwReservedFuture008);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.dwReservedFuture009 = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
cMainHeader.dwReservedFuture009);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "ArrayIsNullOrEmpty(CMainHeader.cReserved) = {0}",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
ArrayHelpers.ArrayIsNullOrEmpty(cMainHeader.cReserved));
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CMainHeader.crc = 0x{0:X8}", cMainHeader.crc);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
// partimage 0.6.1 does not support them either
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(cMainHeader.dwEncryptAlgo != PEncryption.None)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ImageNotSupportedException("Encrypted images are currently not supported.");
|
|
|
|
|
|
|
|
|
|
|
|
string magic;
|
|
|
|
|
|
|
|
|
|
|
|
// Skip MBRs
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(cMainHeader.dwMbrCount > 0)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
hdrB = new byte[MAGIC_BEGIN_MBRBACKUP.Length];
|
|
|
|
|
|
stream.Read(hdrB, 0, MAGIC_BEGIN_MBRBACKUP.Length);
|
|
|
|
|
|
magic = StringHandlers.CToString(hdrB);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!magic.Equals(MAGIC_BEGIN_MBRBACKUP)) throw new ImageNotSupportedException("Cannot find MBRs");
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
stream.Seek(cMainHeader.dwMbrSize * cMainHeader.dwMbrCount, SeekOrigin.Current);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Skip extended headers and their CRC fields
|
|
|
|
|
|
stream.Seek((MAGIC_BEGIN_EXT000.Length + 4) * 10, SeekOrigin.Current);
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
hdrB = new byte[MAGIC_BEGIN_LOCALHEADER.Length];
|
|
|
|
|
|
stream.Read(hdrB, 0, MAGIC_BEGIN_LOCALHEADER.Length);
|
|
|
|
|
|
magic = StringHandlers.CToString(hdrB);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!magic.Equals(MAGIC_BEGIN_LOCALHEADER)) throw new ImageNotSupportedException("Cannot find local header");
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
hdrB = new byte[Marshal.SizeOf(typeof(CLocalHeader))];
|
|
|
|
|
|
stream.Read(hdrB, 0, Marshal.SizeOf(typeof(CLocalHeader)));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
headerPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CLocalHeader)));
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Marshal.Copy(hdrB, 0, headerPtr, Marshal.SizeOf(typeof(CLocalHeader)));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
CLocalHeader localHeader = (CLocalHeader)Marshal.PtrToStructure(headerPtr, typeof(CLocalHeader));
|
|
|
|
|
|
Marshal.FreeHGlobal(headerPtr);
|
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CLocalHeader.qwBlockSize = {0}", localHeader.qwBlockSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CLocalHeader.qwUsedBlocks = {0}", localHeader.qwUsedBlocks);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CLocalHeader.qwBlocksCount = {0}",
|
|
|
|
|
|
localHeader.qwBlocksCount);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CLocalHeader.qwBitmapSize = {0}", localHeader.qwBitmapSize);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CLocalHeader.qwBadBlocksCount = {0}",
|
|
|
|
|
|
localHeader.qwBadBlocksCount);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CLocalHeader.szLabel = {0}",
|
|
|
|
|
|
StringHandlers.CToString(localHeader.szLabel));
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "ArrayIsNullOrEmpty(CLocalHeader.cReserved) = {0}",
|
|
|
|
|
|
ArrayHelpers.ArrayIsNullOrEmpty(localHeader.cReserved));
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "CLocalHeader.crc = 0x{0:X8}", localHeader.crc);
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
hdrB = new byte[MAGIC_BEGIN_BITMAP.Length];
|
|
|
|
|
|
stream.Read(hdrB, 0, MAGIC_BEGIN_BITMAP.Length);
|
|
|
|
|
|
magic = StringHandlers.CToString(hdrB);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!magic.Equals(MAGIC_BEGIN_BITMAP)) throw new ImageNotSupportedException("Cannot find bitmap");
|
|
|
|
|
|
|
|
|
|
|
|
bitmap = new byte[localHeader.qwBitmapSize];
|
|
|
|
|
|
stream.Read(bitmap, 0, (int)localHeader.qwBitmapSize);
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
hdrB = new byte[MAGIC_BEGIN_INFO.Length];
|
|
|
|
|
|
stream.Read(hdrB, 0, MAGIC_BEGIN_INFO.Length);
|
|
|
|
|
|
magic = StringHandlers.CToString(hdrB);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!magic.Equals(MAGIC_BEGIN_INFO)) throw new ImageNotSupportedException("Cannot find info block");
|
|
|
|
|
|
|
|
|
|
|
|
// Skip info block and its checksum
|
|
|
|
|
|
stream.Seek(16384 + 4, SeekOrigin.Current);
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
hdrB = new byte[MAGIC_BEGIN_DATABLOCKS.Length];
|
|
|
|
|
|
stream.Read(hdrB, 0, MAGIC_BEGIN_DATABLOCKS.Length);
|
|
|
|
|
|
magic = StringHandlers.CToString(hdrB);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!magic.Equals(MAGIC_BEGIN_DATABLOCKS)) throw new ImageNotSupportedException("Cannot find data blocks");
|
|
|
|
|
|
|
|
|
|
|
|
dataOff = stream.Position;
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "dataOff = {0}", dataOff);
|
|
|
|
|
|
|
|
|
|
|
|
// Seek to tail
|
|
|
|
|
|
stream.Seek(-(Marshal.SizeOf(typeof(CMainTail)) + MAGIC_BEGIN_TAIL.Length), SeekOrigin.End);
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
hdrB = new byte[MAGIC_BEGIN_TAIL.Length];
|
|
|
|
|
|
stream.Read(hdrB, 0, MAGIC_BEGIN_TAIL.Length);
|
|
|
|
|
|
magic = StringHandlers.CToString(hdrB);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(!magic.Equals(MAGIC_BEGIN_TAIL))
|
|
|
|
|
|
throw new
|
|
|
|
|
|
ImageNotSupportedException("Cannot find tail. Multiple volumes are not supported or image is corrupt.");
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "Filling extents");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
DateTime start = DateTime.Now;
|
|
|
|
|
|
extents = new ExtentsULong();
|
|
|
|
|
|
extentsOff = new Dictionary<ulong, ulong>();
|
2018-01-28 20:29:46 +00:00
|
|
|
|
bool current = (bitmap[0] & (1 << (0 % 8))) != 0;
|
|
|
|
|
|
ulong blockOff = 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
ulong extentStart = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for(ulong i = 1; i <= localHeader.qwBlocksCount; i++)
|
|
|
|
|
|
{
|
2017-12-20 17:38:12 +00:00
|
|
|
|
bool next = (bitmap[i / 8] & (1 << (int)(i % 8))) != 0;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
// Flux
|
|
|
|
|
|
if(next != current)
|
|
|
|
|
|
if(next)
|
|
|
|
|
|
{
|
|
|
|
|
|
extentStart = i;
|
|
|
|
|
|
extentsOff.Add(i, ++blockOff);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
extents.Add(extentStart, i);
|
2018-01-28 20:29:46 +00:00
|
|
|
|
extentsOff.TryGetValue(extentStart, out ulong _);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(next && current) blockOff++;
|
|
|
|
|
|
|
|
|
|
|
|
current = next;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DateTime end = DateTime.Now;
|
|
|
|
|
|
DicConsole.DebugWriteLine("Partimage plugin", "Took {0} seconds to fill extents",
|
|
|
|
|
|
(end - start).TotalSeconds);
|
|
|
|
|
|
|
|
|
|
|
|
sectorCache = new Dictionary<ulong, byte[]>();
|
|
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
imageInfo.CreationTime = dateCreate;
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
2018-01-28 20:29:46 +00:00
|
|
|
|
imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
|
|
|
|
|
|
imageInfo.Sectors = localHeader.qwBlocksCount + 1;
|
|
|
|
|
|
imageInfo.SectorSize = (uint)localHeader.qwBlockSize;
|
|
|
|
|
|
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
|
|
|
|
|
imageInfo.MediaType = MediaType.GENERIC_HDD;
|
|
|
|
|
|
imageInfo.Version = StringHandlers.CToString(cMainHeader.szVersion);
|
|
|
|
|
|
imageInfo.Comments = StringHandlers.CToString(cMainHeader.szPartDescription);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
imageInfo.ImageSize =
|
2017-12-19 20:33:03 +00:00
|
|
|
|
(ulong)(stream.Length - (dataOff + Marshal.SizeOf(typeof(CMainTail)) + MAGIC_BEGIN_TAIL.Length));
|
|
|
|
|
|
imageStream = stream;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(sectorAddress > imageInfo.Sectors - 1)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
2017-12-21 17:58:51 +00:00
|
|
|
|
$"Sector address {sectorAddress} not found");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
if((bitmap[sectorAddress / 8] & (1 << (int)(sectorAddress % 8))) == 0)
|
2017-12-26 06:05:12 +00:00
|
|
|
|
return new byte[imageInfo.SectorSize];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-22 06:55:04 +00:00
|
|
|
|
if(sectorCache.TryGetValue(sectorAddress, out byte[] sector)) return sector;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
ulong blockOff = BlockOffset(sectorAddress);
|
|
|
|
|
|
|
|
|
|
|
|
// Offset of requested sector is:
|
|
|
|
|
|
// Start of data +
|
|
|
|
|
|
long imageOff = dataOff +
|
|
|
|
|
|
// How many stored bytes to skip
|
2017-12-26 06:05:12 +00:00
|
|
|
|
(long)(blockOff * imageInfo.SectorSize) +
|
2017-12-19 20:33:03 +00:00
|
|
|
|
// How many bytes of CRC blocks to skip
|
2017-12-26 06:05:12 +00:00
|
|
|
|
(long)(blockOff / (CHECK_FREQUENCY / imageInfo.SectorSize)) *
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Marshal.SizeOf(typeof(CCheck));
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
sector = new byte[imageInfo.SectorSize];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
imageStream.Seek(imageOff, SeekOrigin.Begin);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageStream.Read(sector, 0, (int)imageInfo.SectorSize);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2018-07-01 22:51:06 +01:00
|
|
|
|
if(sectorCache.Count > MAX_CACHED_SECTORS) sectorCache.Clear();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
sectorCache.Add(sectorAddress, sector);
|
|
|
|
|
|
|
|
|
|
|
|
return sector;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(sectorAddress > imageInfo.Sectors - 1)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress),
|
2017-12-21 17:58:51 +00:00
|
|
|
|
$"Sector address {sectorAddress} not found");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(sectorAddress + length > imageInfo.Sectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
|
|
|
|
|
|
|
|
|
|
|
MemoryStream ms = new MemoryStream();
|
|
|
|
|
|
|
|
|
|
|
|
bool allEmpty = true;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
for(uint i = 0; i < length; i++)
|
2017-12-20 17:38:12 +00:00
|
|
|
|
if((bitmap[sectorAddress / 8] & (1 << (int)(sectorAddress % 8))) != 0)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
allEmpty = false;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(allEmpty) return new byte[imageInfo.SectorSize * length];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
for(uint i = 0; i < length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] sector = ReadSector(sectorAddress + i);
|
|
|
|
|
|
ms.Write(sector, 0, sector.Length);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ms.ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadDiskTag(MediaTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(Session session)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(ushort session)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
|
|
|
|
|
out List<ulong> unknownLbas)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
for(ulong i = 0; i < imageInfo.Sectors; i++) unknownLbas.Add(i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
|
|
|
|
|
out List<ulong> unknownLbas)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: All blocks contain a CRC32 that's incompatible with current implementation. Need to check for compatibility.
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifyMediaImage()
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
public List<DumpHardwareType> DumpHardware => null;
|
|
|
|
|
|
public CICMMetadataType CicmMetadata => null;
|
|
|
|
|
|
|
|
|
|
|
|
ulong BlockOffset(ulong sectorAddress)
|
|
|
|
|
|
{
|
|
|
|
|
|
extents.GetStart(sectorAddress, out ulong extentStart);
|
|
|
|
|
|
extentsOff.TryGetValue(extentStart, out ulong extentStartingOffset);
|
|
|
|
|
|
return extentStartingOffset + (sectorAddress - extentStart);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Partimage disk image header, little-endian
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct PartimageHeader
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Magic, <see cref="Partimage.partimageMagic" />
|
|
|
|
|
|
/// </summary>
|
2018-01-28 20:29:46 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
|
|
|
|
|
|
public byte[] magic;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Source filesystem
|
|
|
|
|
|
/// </summary>
|
2018-01-28 20:29:46 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
|
|
|
|
|
|
public byte[] version;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Volume number
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public uint volumeNumber;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Image identifier
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ulong identificator;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Empty space
|
|
|
|
|
|
/// </summary>
|
2018-01-28 20:29:46 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 404)]
|
|
|
|
|
|
public byte[] reserved;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct PortableTm
|
|
|
|
|
|
{
|
|
|
|
|
|
public uint Second;
|
|
|
|
|
|
public uint Minute;
|
|
|
|
|
|
public uint Hour;
|
|
|
|
|
|
public uint DayOfMonth;
|
|
|
|
|
|
public uint Month;
|
|
|
|
|
|
public uint Year;
|
|
|
|
|
|
public uint DayOfWeek;
|
|
|
|
|
|
public uint DayOfYear;
|
|
|
|
|
|
public uint IsDst;
|
|
|
|
|
|
|
|
|
|
|
|
public uint GmtOff;
|
|
|
|
|
|
public uint Timezone;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum PCompression : uint
|
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
|
None = 0,
|
|
|
|
|
|
Gzip = 1,
|
2017-12-24 00:12:31 +00:00
|
|
|
|
Bzip2 = 2,
|
2018-01-28 20:29:46 +00:00
|
|
|
|
Lzo = 3
|
2017-12-24 00:12:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum PEncryption : uint
|
|
|
|
|
|
{
|
|
|
|
|
|
None = 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Partimage CMainHeader
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct PartimageMainHeader
|
|
|
|
|
|
{
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 512)]
|
|
|
|
|
|
public byte[] szFileSystem; // ext2fs, ntfs, reiserfs, ...
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_DESCRIPTION)]
|
|
|
|
|
|
public byte[] szPartDescription; // user description of the partition
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_DEVICENAMELEN)]
|
|
|
|
|
|
public byte[] szOriginalDevice; // original partition name
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4095)]
|
|
|
|
|
|
public byte[] szFirstImageFilepath; //MAXPATHLEN]; // for splitted image files
|
|
|
|
|
|
|
|
|
|
|
|
// system and hardware infos
|
2018-01-28 20:29:46 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_UNAMEINFOLEN)]
|
|
|
|
|
|
public byte[] szUnameSysname;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_UNAMEINFOLEN)]
|
|
|
|
|
|
public byte[] szUnameNodename;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_UNAMEINFOLEN)]
|
|
|
|
|
|
public byte[] szUnameRelease;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_UNAMEINFOLEN)]
|
|
|
|
|
|
public byte[] szUnameVersion;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_UNAMEINFOLEN)]
|
|
|
|
|
|
public byte[] szUnameMachine;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
public PCompression dwCompression; // COMPRESS_XXXXXX
|
2018-01-28 20:29:46 +00:00
|
|
|
|
public uint dwMainFlags;
|
|
|
|
|
|
public PortableTm dateCreate; // date of image creation
|
|
|
|
|
|
public ulong qwPartSize; // size of the partition in bytes
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_HOSTNAMESIZE)]
|
|
|
|
|
|
public byte[] szHostname;
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
|
|
|
|
|
|
public byte[] szVersion; // version of the image file
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
// MBR backup
|
|
|
|
|
|
public uint dwMbrCount; // how many MBR are saved in the image file
|
2018-01-28 20:29:46 +00:00
|
|
|
|
public uint dwMbrSize; // size of a MBR record (allow to change the size in the next versions)
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
// future encryption support
|
|
|
|
|
|
public PEncryption dwEncryptAlgo; // algo used to encrypt data
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
|
|
|
|
|
public byte[] cHashTestKey; // used to test the password without giving it
|
|
|
|
|
|
|
|
|
|
|
|
// reserved for future use (save DiskLabel, Extended partitions, ...)
|
|
|
|
|
|
public uint dwReservedFuture000;
|
|
|
|
|
|
public uint dwReservedFuture001;
|
|
|
|
|
|
public uint dwReservedFuture002;
|
|
|
|
|
|
public uint dwReservedFuture003;
|
|
|
|
|
|
public uint dwReservedFuture004;
|
|
|
|
|
|
public uint dwReservedFuture005;
|
|
|
|
|
|
public uint dwReservedFuture006;
|
|
|
|
|
|
public uint dwReservedFuture007;
|
|
|
|
|
|
public uint dwReservedFuture008;
|
|
|
|
|
|
public uint dwReservedFuture009;
|
|
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6524)]
|
|
|
|
|
|
public byte[] cReserved; // Adjust to fit with total header size
|
|
|
|
|
|
|
|
|
|
|
|
public uint crc;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct CMbr // must be 1024
|
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MBR_SIZE_WHOLE)]
|
|
|
|
|
|
public byte[] cData;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public uint dwDataCRC;
|
2018-01-28 20:29:46 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_DEVICENAMELEN)]
|
|
|
|
|
|
public byte[] szDevice; // ex: "hda"
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
// disk identificators
|
|
|
|
|
|
ulong qwBlocksCount;
|
2018-01-28 20:29:46 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_DESC_MODEL)]
|
|
|
|
|
|
public byte[] szDescModel;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
2018-01-28 20:29:46 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 884)]
|
|
|
|
|
|
public byte[] cReserved; // for future use
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
//public byte[] szDescGeometry[MAX_DESC_GEOMETRY];
|
|
|
|
|
|
//public byte[] szDescIdentify[MAX_DESC_IDENTIFY];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct CCheck
|
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
2018-06-22 08:08:38 +01:00
|
|
|
|
byte[] cMagic; // must be 'C','H','K'
|
|
|
|
|
|
public uint dwCRC; // CRC of the CHECK_FREQUENCY blocks
|
|
|
|
|
|
public ulong qwPos; // number of the last block written
|
2017-12-24 00:12:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct CLocalHeader // size must be 16384 (adjust the reserved data)
|
|
|
|
|
|
{
|
|
|
|
|
|
public ulong qwBlockSize;
|
|
|
|
|
|
public ulong qwUsedBlocks;
|
|
|
|
|
|
public ulong qwBlocksCount;
|
|
|
|
|
|
public ulong qwBitmapSize; // bytes in the bitmap
|
|
|
|
|
|
public ulong qwBadBlocksCount;
|
2018-01-28 20:29:46 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
|
|
|
|
|
|
public byte[] szLabel;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16280)]
|
|
|
|
|
|
public byte[] cReserved; // Adjust to fit with total header size
|
|
|
|
|
|
|
|
|
|
|
|
public uint crc;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct CMainTail // size must be 16384 (adjust the reserved data)
|
|
|
|
|
|
{
|
|
|
|
|
|
public ulong qwCRC;
|
2018-01-28 20:29:46 +00:00
|
|
|
|
public uint dwVolumeNumber;
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16372)]
|
|
|
|
|
|
public byte[] cReserved; // Adjust to fit with total header size
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|