// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // // Filename : ImagePlugin.cs // Author(s) : Natalia Portillo // // Component : Disc image plugins. // // --[ Description ] ---------------------------------------------------------- // // Defines methods to be used by disc image plugins and several constants. // // --[ 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 . // // ---------------------------------------------------------------------------- // Copyright © 2011-2016 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; using DiscImageChef.CommonTypes; namespace DiscImageChef.ImagePlugins { /// /// Abstract class to implement disk image reading plugins. /// public abstract class ImagePlugin { /// Plugin name. public string Name; /// Plugin UUID. public Guid PluginUUID; /// Image information public ImageInfo ImageInfo; protected ImagePlugin() { } // Basic image handling functions /// /// Identifies the image. /// /// true, if image was identified, false otherwise. /// Image path. public abstract bool IdentifyImage(string imagePath); /// /// Opens the image. /// /// true, if image was opened, false otherwise. /// Image path. public abstract bool OpenImage(string imagePath); /// /// Asks the disk image plugin if the image contains partitions /// /// true, if the image contains partitions, false otherwise. public abstract bool ImageHasPartitions(); // Image size functions /// /// Gets the size of the image, without headers. /// /// The image size. public abstract UInt64 GetImageSize(); /// /// Gets the number of sectors in the image. /// /// Sectors in image. public abstract UInt64 GetSectors(); /// /// Returns the size of the biggest sector, counting user data only. /// /// Biggest sector size (user data only). public abstract UInt32 GetSectorSize(); // Image reading functions /// /// Reads a disk tag. /// /// Disk tag /// Tag type to read. public abstract byte[] ReadDiskTag(MediaTagType tag); /// /// Reads a sector's user data. /// /// The sector's user data. /// Sector address (LBA). public abstract byte[] ReadSector(UInt64 sectorAddress); /// /// Reads a sector's tag. /// /// The sector's tag. /// Sector address (LBA). /// Tag type. public abstract byte[] ReadSectorTag(UInt64 sectorAddress, SectorTagType tag); /// /// Reads a sector's user data, relative to track. /// /// The sector's user data. /// Sector address (relative LBA). /// Track. public abstract byte[] ReadSector(UInt64 sectorAddress, UInt32 track); /// /// Reads a sector's tag, relative to track. /// /// The sector's tag. /// Sector address (relative LBA). /// Track. /// Tag type. public abstract byte[] ReadSectorTag(UInt64 sectorAddress, UInt32 track, SectorTagType tag); /// /// Reads user data from several sectors. /// /// The sectors user data. /// Starting sector address (LBA). /// How many sectors to read. public abstract byte[] ReadSectors(UInt64 sectorAddress, UInt32 length); /// /// Reads tag from several sectors. /// /// The sectors tag. /// Starting sector address (LBA). /// How many sectors to read. /// Tag type. public abstract byte[] ReadSectorsTag(UInt64 sectorAddress, UInt32 length, SectorTagType tag); /// /// Reads user data from several sectors, relative to track. /// /// The sectors user data. /// Starting sector address (relative LBA). /// How many sectors to read. /// Track. public abstract byte[] ReadSectors(UInt64 sectorAddress, UInt32 length, UInt32 track); /// /// Reads tag from several sectors, relative to track. /// /// The sectors tag. /// Starting sector address (relative LBA). /// How many sectors to read. /// Track. /// Tag type. public abstract byte[] ReadSectorsTag(UInt64 sectorAddress, UInt32 length, UInt32 track, SectorTagType tag); /// /// Reads a complete sector (user data + all tags). /// /// The complete sector. Format depends on disk type. /// Sector address (LBA). public abstract byte[] ReadSectorLong(UInt64 sectorAddress); /// /// Reads a complete sector (user data + all tags), relative to track. /// /// The complete sector. Format depends on disk type. /// Sector address (relative LBA). /// Track. public abstract byte[] ReadSectorLong(UInt64 sectorAddress, UInt32 track); /// /// Reads several complete sector (user data + all tags). /// /// The complete sectors. Format depends on disk type. /// Starting sector address (LBA). /// How many sectors to read. public abstract byte[] ReadSectorsLong(UInt64 sectorAddress, UInt32 length); /// /// Reads several complete sector (user data + all tags), relative to track. /// /// The complete sectors. Format depends on disk type. /// Starting sector address (relative LBA). /// How many sectors to read. /// Track. public abstract byte[] ReadSectorsLong(UInt64 sectorAddress, UInt32 length, UInt32 track); // Image information functions /// /// Gets the image format. /// /// The image format. public abstract string GetImageFormat(); /// /// Gets the image version. /// /// The image version. public abstract string GetImageVersion(); /// /// Gets the application that created the image. /// /// The application that created the image. public abstract string GetImageApplication(); /// /// Gets the version of the application that created the image. /// /// The version of the application that created the image. public abstract string GetImageApplicationVersion(); /// /// Gets the image creator. /// /// Who created the image. public abstract string GetImageCreator(); /// /// Gets the image creation time. /// /// The image creation time. public abstract DateTime GetImageCreationTime(); /// /// Gets the image last modification time. /// /// The image last modification time. public abstract DateTime GetImageLastModificationTime(); /// /// Gets the name of the image. /// /// The image name. public abstract string GetImageName(); /// /// Gets the image comments. /// /// The image comments. public abstract string GetImageComments(); // Functions to get information from disk represented by image /// /// Gets the media manufacturer. /// /// The media manufacturer. public abstract string GetMediaManufacturer(); /// /// Gets the media model. /// /// The media model. public abstract string GetMediaModel(); /// /// Gets the media serial number. /// /// The media serial number. public abstract string GetMediaSerialNumber(); /// /// Gets the media (or product) barcode. /// /// The media barcode. public abstract string GetMediaBarcode(); /// /// Gets the media part number. /// /// The media part number. public abstract string GetMediaPartNumber(); /// /// Gets the type of the media. /// /// The media type. public abstract MediaType GetMediaType(); /// /// Gets the media sequence. /// /// The media sequence, starting at 1. public abstract int GetMediaSequence(); /// /// Gets the last media in the sequence. /// /// The last media in the sequence. public abstract int GetLastDiskSequence(); // Functions to get information from drive used to create image /// /// Gets the manufacturer of the drive used to create the image. /// /// The drive manufacturer. public abstract string GetDriveManufacturer(); /// /// Gets the model of the drive used to create the image. /// /// The drive model. public abstract string GetDriveModel(); /// /// Gets the serial number of the drive used to create the image. /// /// The drive serial number. public abstract string GetDriveSerialNumber(); // Partitioning functions /// /// Gets an array partitions. Typically only useful for optical disc /// images where each track and index means a different partition, as /// reads can be relative to them. /// /// The partitions. public abstract List GetPartitions(); /// /// Gets the disc track extents (start, length). /// /// The track extents. public abstract List GetTracks(); /// /// Gets the disc track extents for a specified session. /// /// The track exents for that session. /// Session. public abstract List GetSessionTracks(Session session); /// /// Gets the disc track extents for a specified session. /// /// The track exents for that session. /// Session. public abstract List GetSessionTracks(UInt16 session); /// /// Gets the sessions (optical discs only). /// /// The sessions. public abstract List GetSessions(); /// /// Verifies a sector. /// /// True if correct, false if incorrect, null if uncheckable. /// Sector address (LBA). public abstract bool? VerifySector(UInt64 sectorAddress); /// /// Verifies a sector, relative to track. /// /// True if correct, false if incorrect, null if uncheckable. /// Sector address (relative LBA). /// Track. public abstract bool? VerifySector(UInt64 sectorAddress, UInt32 track); /// /// Verifies several sectors. /// /// True if all are correct, false if any is incorrect, null if any is uncheckable. /// Starting sector address (LBA). /// How many sectors to read. /// List of incorrect sectors /// List of uncheckable sectors public abstract bool? VerifySectors(UInt64 sectorAddress, UInt32 length, out List FailingLBAs, out List UnknownLBAs); /// /// Verifies several sectors, relative to track. /// /// True if all are correct, false if any is incorrect, null if any is uncheckable. /// Starting sector address (relative LBA). /// How many sectors to read. /// Track. /// List of incorrect sectors /// List of uncheckable sectors public abstract bool? VerifySectors(UInt64 sectorAddress, UInt32 length, UInt32 track, out List FailingLBAs, out List UnknownLBAs); /// /// Verifies media image internal checksum. /// /// True if correct, false if incorrect, null if there is no internal checksum available public abstract bool? VerifyMediaImage(); // CD flags bitmask /// Track is quadraphonic. public const byte CDFlagsFourChannel = 0x20; /// Track is non-audio (data). public const byte CDFlagsDataTrack = 0x10; /// Track is copy protected. public const byte CDFlagsCopyPrevent = 0x08; /// Track has pre-emphasis. public const byte CDFlagsPreEmphasis = 0x04; } /// /// Track (as partitioning element) types. /// public enum TrackType { /// Audio track Audio, /// Data track (not any of the below defined ones) Data, /// Data track, compact disc mode 1 CDMode1, /// Data track, compact disc mode 2, formless CDMode2Formless, /// Data track, compact disc mode 2, form 1 CDMode2Form1, /// Data track, compact disc mode 2, form 2 CDMode2Form2 }; /// /// Track defining structure. /// public struct Track { /// Track number, 1-started public UInt32 TrackSequence; /// Partition type public TrackType TrackType; /// Track starting sector public UInt64 TrackStartSector; /// Track ending sector public UInt64 TrackEndSector; /// Track pre-gap public UInt64 TrackPregap; /// Session this track belongs to public UInt16 TrackSession; /// Information that does not find space in this struct public string TrackDescription; /// Indexes, 00 to 99 and sector offset public Dictionary Indexes; /// Which file stores this track public string TrackFile; /// Starting at which byte is this track stored public ulong TrackFileOffset; /// What kind of file is storing this track public string TrackFileType; /// How many main channel / user data bytes are per sector in this track public int TrackBytesPerSector; /// How many main channel bytes per sector are in the file with this track public int TrackRawBytesPerSector; /// Which file stores this track's subchannel public string TrackSubchannelFile; /// Starting at which byte are this track's subchannel stored public ulong TrackSubchannelOffset; /// Type of subchannel stored for this track public TrackSubchannelType TrackSubchannelType; } /// /// Type of subchannel in track /// public enum TrackSubchannelType { /// /// Track does not has subchannel dumped, or it's not a CD /// None, /// /// Subchannel is packed and error corrected /// Packed, /// /// Subchannel is interleaved /// Raw, /// /// Subchannel is packed and comes interleaved with main channel in same file /// PackedInterleaved, /// /// Subchannel is interleaved and comes interleaved with main channel in same file /// RawInterleaved } /// /// Session defining structure. /// public struct Session { /// Session number, 1-started public UInt16 SessionSequence; /// First track present on this session public UInt32 StartTrack; /// Last track present on this session public UInt32 EndTrack; /// First sector present on this session public UInt64 StartSector; /// Last sector present on this session public UInt64 EndSector; } /// /// Metadata present for each sector (aka, "tag"). /// public enum SectorTagType { /// Apple's GCR sector tags, 12 bytes AppleSectorTag, /// Sync frame from CD sector, 12 bytes CDSectorSync, /// CD sector header, 4 bytes CDSectorHeader, /// CD mode 2 sector subheader CDSectorSubHeader, /// CD sector EDC, 4 bytes CDSectorEDC, /// CD sector ECC P, 172 bytes CDSectorECC_P, /// CD sector ECC Q, 104 bytes CDSectorECC_Q, /// CD sector ECC (P and Q), 276 bytes CDSectorECC, /// CD sector subchannel, 96 bytes CDSectorSubchannel, /// CD track ISRC, string, 12 bytes CDTrackISRC, /// CD track text, string, 13 bytes CDTrackText, /// CD track flags, 1 byte CDTrackFlags, /// DVD sector copyright information DVD_CMI }; /// /// Metadata present for each media. /// public enum MediaTagType { /// CD table of contents CD_TOC, /// CD session information CD_SessionInfo, /// CD full table of contents CD_FullTOC, /// CD PMA CD_PMA, /// CD Adress-Time-In-Pregroove CD_ATIP, /// CD-Text CD_TEXT, /// CD Media Catalogue Number CD_MCN, /// DVD/HD DVD Physical Format Information DVD_PFI, /// DVD Lead-in Copyright Management Information DVD_CMI, /// DVD disc key DVD_DiscKey, /// DVD/HD DVD Burst Cutting Area DVD_BCA, /// DVD/HD DVD Lead-in Disc Manufacturer Information DVD_DMI, /// Media identifier DVD_MediaIdentifier, /// Media key block DVD_MKB, /// DVD-RAM/HD DVD-RAM DDS information DVDRAM_DDS, /// DVD-RAM/HD DVD-RAM Medium status DVDRAM_MediumStatus, /// DVD-RAM/HD DVD-RAM Spare area information DVDRAM_SpareArea, /// DVD-R/-RW/HD DVD-R RMD in last border-out DVDR_RMD, /// Pre-recorded information from DVD-R/-RW lead-in DVDR_PreRecordedInfo, /// DVD-R/-RW/HD DVD-R media identifier DVDR_MediaIdentifier, /// DVD-R/-RW/HD DVD-R physical format information DVDR_PFI, /// ADIP information DVD_ADIP, /// HD DVD Lead-in copyright protection information HDDVD_CPI, /// HD DVD-R Medium Status HDDVD_MediumStatus, /// DVD+/-R DL Layer capacity DVDDL_LayerCapacity, /// DVD-R DL Middle Zone start address DVDDL_MiddleZoneAddress, /// DVD-R DL Jump Interval Size DVDDL_JumpIntervalSize, /// DVD-R DL Start LBA of the manual layer jump DVDDL_ManualLayerJumpLBA, /// Blu-ray Disc Information BD_DI, /// Blu-ray Burst Cutting Area BD_BCA, /// Blu-ray Disc Definition Structure BD_DDS, /// Blu-ray Cartridge Status BD_CartridgeStatus, /// Blu-ray Status of Spare Area BD_SpareArea, /// AACS volume identifier AACS_VolumeIdentifier, /// AACS pre-recorded media serial number AACS_SerialNumber, /// AACS media identifier AACS_MediaIdentifier, /// Lead-in AACS media key block AACS_MKB, /// AACS data keys AACS_DataKeys, /// LBA extents flagged for bus encryption by AACS AACS_LBAExtents, /// CPRM media key block in Lead-in AACS_CPRM_MKB, /// Recognized layer formats in hybrid discs Hybrid_RecognizedLayers, /// Disc write protection status MMC_WriteProtection, /// Disc standard information MMC_DiscInformation, /// Disc track resources information MMC_TrackResourcesInformation, /// BD-R Pseudo-overwrite information MMC_POWResourcesInformation, /// SCSI INQUIRY response SCSI_INQUIRY, /// ATA IDENTIFY DEVICE response ATA_IDENTIFY, /// ATA IDENTIFY PACKET DEVICE response ATAPI_IDENTIFY, /// PCMCIA/CardBus Card Information Structure PCMCIA_CIS, /// SecureDigital / MMC CID SD_CID, /// SecureDigital / MMC CSD SD_CSD, /// SecureDigital Extended CSD SD_ExtendedCSD }; /// /// Enumeration of media types defined in CICM metadata /// public enum XmlMediaType { /// /// Purely optical discs /// OpticalDisc, /// /// Media that is physically block-based or abstracted like that /// BlockMedia, /// /// Media that can be accessed by-byte or by-bit, like chips /// LinearMedia, /// /// Media that can only store data when it is modulated to audio /// AudioMedia } /// /// Feature is supported by image but not implemented yet. /// [Serializable] public class FeatureSupportedButNotImplementedImageException : Exception { /// /// Feature is supported by image but not implemented yet. /// /// Message. /// Inner. public FeatureSupportedButNotImplementedImageException(string message, Exception inner) : base(message, inner) { } /// /// Feature is supported by image but not implemented yet. /// /// Message. public FeatureSupportedButNotImplementedImageException(string message) : base(message) { } /// /// Feature is supported by image but not implemented yet. /// /// Info. /// Context. protected FeatureSupportedButNotImplementedImageException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { if(info == null) throw new ArgumentNullException("info"); } } /// /// Feature is not supported by image. /// [Serializable] public class FeatureUnsupportedImageException : Exception { /// /// Feature is not supported by image. /// /// Message. /// Inner. public FeatureUnsupportedImageException(string message, Exception inner) : base(message, inner) { } /// /// Feature is not supported by image. /// /// Message. public FeatureUnsupportedImageException(string message) : base(message) { } /// /// Feature is not supported by image. /// /// Info. /// Context. protected FeatureUnsupportedImageException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { if(info == null) throw new ArgumentNullException("info"); } } /// /// Feature is supported by image but not present on it. /// [Serializable] public class FeatureNotPresentImageException : Exception { /// /// Feature is supported by image but not present on it. /// /// Message. /// Inner. public FeatureNotPresentImageException(string message, Exception inner) : base(message, inner) { } /// /// Feature is supported by image but not present on it. /// /// Message. public FeatureNotPresentImageException(string message) : base(message) { } /// /// Feature is supported by image but not present on it. /// /// Info. /// Context. protected FeatureNotPresentImageException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { if(info == null) throw new ArgumentNullException("info"); } } /// /// Feature is supported by image but not by the disc it represents. /// [Serializable] public class FeaturedNotSupportedByDiscImageException : Exception { /// /// Feature is supported by image but not by the disc it represents. /// /// Message. /// Inner. public FeaturedNotSupportedByDiscImageException(string message, Exception inner) : base(message, inner) { } /// /// Feature is supported by image but not by the disc it represents. /// /// Message. public FeaturedNotSupportedByDiscImageException(string message) : base(message) { } /// /// Feature is supported by image but not by the disc it represents. /// /// Info. /// Context. protected FeaturedNotSupportedByDiscImageException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { if(info == null) throw new ArgumentNullException("info"); } } /// /// Corrupt, incorrect or unhandled feature found on image /// [Serializable] public class ImageNotSupportedException : Exception { /// /// Corrupt, incorrect or unhandled feature found on image /// /// Message. /// Inner. public ImageNotSupportedException(string message, Exception inner) : base(message, inner) { } /// /// Corrupt, incorrect or unhandled feature found on image /// /// Message. public ImageNotSupportedException(string message) : base(message) { } /// /// Corrupt, incorrect or unhandled feature found on image /// /// Info. /// Context. protected ImageNotSupportedException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { if(info == null) throw new ArgumentNullException("info"); } } }