This commit is contained in:
2019-03-31 20:52:06 +01:00
parent b255303607
commit 701bc2cedc
16 changed files with 1276 additions and 1349 deletions

View File

@@ -5,6 +5,7 @@ set(CMAKE_C_STANDARD 99)
add_compile_definitions(__STDC_FORMAT_MACROS=1)
add_library(dicformat SHARED include/dicformat/consts.h include/dicformat/enums.h include/dic.h include/dicformat.h
include/dicformat/decls.h include/dicformat/structs.h src/identify.c src/open.c include/dicformat/context.h src/close.c include/dicformat/errors.h src/read.c src/crc64.c src/cst.c src/ecc_cd.c src/helpers.c)
include/dicformat/decls.h include/dicformat/structs.h src/identify.c src/open.c include/dicformat/context.h
src/close.c include/dicformat/errors.h src/read.c src/crc64.c src/cst.c src/ecc_cd.c src/helpers.c)
include_directories(include include/dicformat)

File diff suppressed because it is too large Load Diff

View File

@@ -36,11 +36,11 @@
#define LIBDICFORMAT_MAJOR_VERSION 1
#define LIBDICFORMAT_MINOR_VERSION 0
#include "dicformat/errors.h"
#include "dicformat/consts.h"
#include "dicformat/enums.h"
#include "dicformat/decls.h"
#include "dicformat/structs.h"
#include "dicformat/context.h"
#include "dicformat/decls.h"
#include "dicformat/enums.h"
#include "dicformat/errors.h"
#include "dicformat/structs.h"
#endif //LIBDICFORMAT_DICFORMAT_H
#endif // LIBDICFORMAT_DICFORMAT_H

View File

@@ -37,7 +37,8 @@
/** Magic identidier = "DICMFMT". */
#define DIC_MAGIC 0x544D52464D434944
/** Image format version. A change in this number indicates an incompatible change to the format that prevents older implementations from reading it correctly, if at all. */
/** Image format version. A change in this number indicates an incompatible change to the format that prevents older
* implementations from reading it correctly, if at all. */
#define DICF_VERSION 1
/** Maximum read cache size, 256MiB. */
#define MAX_CACHE_SIZE 256 * 1024 * 1024
@@ -59,6 +60,6 @@
#define CRC64_ECMA_POLY 0xC96C5795D7870F42
#define CRC64_ECMA_SEED 0xFFFFFFFFFFFFFFFF
#endif //LIBDICFORMAT_CONSTS_H
#endif // LIBDICFORMAT_CONSTS_H
#pragma clang diagnostic pop

View File

@@ -32,68 +32,68 @@
#ifndef LIBDICFORMAT_CONTEXT_H
#define LIBDICFORMAT_CONTEXT_H
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
typedef struct dicformatContext
{
uint64_t magic;
uint8_t libraryMajorVersion;
uint8_t libraryMinorVersion;
FILE *imageStream;
DicHeader header;
struct dataLinkedList *mediaTagsHead;
struct dataLinkedList *mediaTagsTail;
uint8_t *sectorPrefix;
uint8_t *sectorPrefixCorrected;
uint8_t *sectorSuffix;
uint8_t *sectorSuffixCorrected;
uint8_t *sectorSubchannel;
uint8_t *mode2Subheaders;
uint8_t shift;
bool inMemoryDdt;
uint64_t *userDataDdt;
size_t mappedMemoryDdtSize;
uint32_t *sectorPrefixDdt;
uint32_t *sectorSuffixDdt;
GeometryBlockHeader geometryBlock;
MetadataBlockHeader metadataBlockHeader;
uint8_t *metadataBlock;
TracksHeader tracksHeader;
TrackEntry *trackEntries;
CicmMetadataBlock cicmBlockHeader;
uint8_t *cicmBlock;
DumpHardwareHeader dumpHardwareHeader;
uint64_t magic;
uint8_t libraryMajorVersion;
uint8_t libraryMinorVersion;
FILE * imageStream;
DicHeader header;
struct dataLinkedList * mediaTagsHead;
struct dataLinkedList * mediaTagsTail;
uint8_t * sectorPrefix;
uint8_t * sectorPrefixCorrected;
uint8_t * sectorSuffix;
uint8_t * sectorSuffixCorrected;
uint8_t * sectorSubchannel;
uint8_t * mode2Subheaders;
uint8_t shift;
bool inMemoryDdt;
uint64_t * userDataDdt;
size_t mappedMemoryDdtSize;
uint32_t * sectorPrefixDdt;
uint32_t * sectorSuffixDdt;
GeometryBlockHeader geometryBlock;
MetadataBlockHeader metadataBlockHeader;
uint8_t * metadataBlock;
TracksHeader tracksHeader;
TrackEntry * trackEntries;
CicmMetadataBlock cicmBlockHeader;
uint8_t * cicmBlock;
DumpHardwareHeader dumpHardwareHeader;
struct DumpHardwareEntriesWithData *dumpHardwareEntriesWithData;
struct ImageInfo imageInfo;
CdEccContext *eccCdContext;
uint8_t numberOfDataTracks;
TrackEntry *dataTracks;
bool *readableSectorTags;
struct ImageInfo imageInfo;
CdEccContext * eccCdContext;
uint8_t numberOfDataTracks;
TrackEntry * dataTracks;
bool * readableSectorTags;
} dicformatContext;
typedef struct dataLinkedList
{
struct dataLinkedList *previous;
struct dataLinkedList *next;
uint8_t *data;
int32_t type;
uint32_t length;
uint8_t * data;
int32_t type;
uint32_t length;
} dataLinkedList;
typedef struct DumpHardwareEntriesWithData
{
DumpHardwareEntry entry;
DumpHardwareEntry entry;
struct DumpExtent *extents;
uint8_t *manufacturer;
uint8_t *model;
uint8_t *revision;
uint8_t *firmware;
uint8_t *serial;
uint8_t *softwareName;
uint8_t *softwareVersion;
uint8_t *softwareOperatingSystem;
uint8_t * manufacturer;
uint8_t * model;
uint8_t * revision;
uint8_t * firmware;
uint8_t * serial;
uint8_t * softwareName;
uint8_t * softwareVersion;
uint8_t * softwareOperatingSystem;
} DumpHardwareEntriesWithData;
#pragma pack(push, 1)
@@ -106,4 +106,4 @@ typedef struct DumpExtent
#pragma pack(pop)
#endif //LIBDICFORMAT_CONTEXT_H
#endif // LIBDICFORMAT_CONTEXT_H

View File

@@ -33,9 +33,9 @@
#ifndef LIBDICFORMAT_DECLS_H
#define LIBDICFORMAT_DECLS_H
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
int identify(const char *filename);
@@ -71,37 +71,37 @@ bool ecc_cd_is_suffix_correct(void *context, const uint8_t *sector);
bool ecc_cd_is_suffix_correct_mode2(void *context, const uint8_t *sector);
bool ecc_cd_check(void *context,
bool ecc_cd_check(void * context,
const uint8_t *address,
const uint8_t *data,
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
const uint8_t *ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset);
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset);
void ecc_cd_write(void *context,
void ecc_cd_write(void * context,
const uint8_t *address,
const uint8_t *data,
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
uint8_t *ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset);
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
uint8_t * ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset);
void ecc_cd_write_sector(void *context,
void ecc_cd_write_sector(void * context,
const uint8_t *address,
const uint8_t *data,
uint8_t *ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset);
uint8_t * ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset);
void cd_lba_to_msf(int64_t pos, uint8_t *minute, uint8_t *second, uint8_t *frame);
@@ -117,4 +117,4 @@ int32_t GetMediaTagTypeForDataType(int32_t type);
int32_t GetXmlMediaType(int32_t type);
#endif //LIBDICFORMAT_DECLS_H
#endif // LIBDICFORMAT_DECLS_H

View File

@@ -7,211 +7,215 @@
typedef enum
{
/** Not compressed */
None = 0, /** LZMA */
Lzma = 1, /** FLAC */
Flac = 2, /** LZMA in Claunia Subchannel Transform processed data */
LzmaClauniaSubchannelTransform = 3
None = 0, /** LZMA */
Lzma = 1, /** FLAC */
Flac = 2, /** LZMA in Claunia Subchannel Transform processed data */
LzmaClauniaSubchannelTransform = 3
} CompressionType;
/** List of known data types */
typedef enum
{
/** No data */
NoData = 0,
NoData = 0,
/** User data */
UserData = 1,
UserData = 1,
/** CompactDisc partial Table of Contents */
CompactDiscPartialToc = 2,
CompactDiscPartialToc = 2,
/** CompactDisc session information */
CompactDiscSessionInfo = 3,
CompactDiscSessionInfo = 3,
/** CompactDisc Table of Contents */
CompactDiscToc = 4,
CompactDiscToc = 4,
/** CompactDisc Power Management Area */
CompactDiscPma = 5,
CompactDiscPma = 5,
/** CompactDisc Absolute Time In Pregroove */
CompactDiscAtip = 6,
CompactDiscAtip = 6,
/** CompactDisc Lead-in's CD-Text */
CompactDiscLeadInCdText = 7,
CompactDiscLeadInCdText = 7,
/** DVD Physical Format Information */
DvdPfi = 8,
DvdPfi = 8,
/** DVD Lead-in's Copyright Management Information */
DvdLeadInCmi = 9,
DvdLeadInCmi = 9,
/** DVD Disc Key */
DvdDiscKey = 10,
DvdDiscKey = 10,
/** DVD Burst Cutting Area */
DvdBca = 11,
DvdBca = 11,
/** DVD DMI */
DvdDmi = 12,
DvdDmi = 12,
/** DVD Media Identifier */
DvdMediaIdentifier = 13,
DvdMediaIdentifier = 13,
/** DVD Media Key Block */
DvdMediaKeyBlock = 14,
DvdMediaKeyBlock = 14,
/** DVD-RAM Disc Definition Structure */
DvdRamDds = 15,
DvdRamDds = 15,
/** DVD-RAM Medium Status */
DvdRamMediumStatus = 16,
DvdRamMediumStatus = 16,
/** DVD-RAM Spare Area Information */
DvdRamSpareArea = 17,
DvdRamSpareArea = 17,
/** DVD-R RMD */
DvdRRmd = 18,
DvdRRmd = 18,
/** DVD-R Pre-recorded Information */
DvdRPrerecordedInfo = 19,
DvdRPrerecordedInfo = 19,
/** DVD-R Media Identifier */
DvdRMediaIdentifier = 20,
DvdRMediaIdentifier = 20,
/** DVD-R Physical Format Information */
DvdRPfi = 21,
DvdRPfi = 21,
/** DVD ADress In Pregroove */
DvdAdip = 22,
DvdAdip = 22,
/** HD DVD Copy Protection Information */
HdDvdCpi = 23,
HdDvdCpi = 23,
/** HD DVD Medium Status */
HdDvdMediumStatus = 24,
HdDvdMediumStatus = 24,
/** DVD DL Layer Capacity */
DvdDlLayerCapacity = 25,
DvdDlLayerCapacity = 25,
/** DVD DL Middle Zone Address */
DvdDlMiddleZoneAddress = 26,
DvdDlMiddleZoneAddress = 26,
/** DVD DL Jump Interval Size */
DvdDlJumpIntervalSize = 27,
DvdDlJumpIntervalSize = 27,
/** DVD DL Manual Layer Jump LBA */
DvdDlManualLayerJumpLba = 28,
DvdDlManualLayerJumpLba = 28,
/** Bluray Disc Information */
BlurayDi = 29,
BlurayDi = 29,
/** Bluray Burst Cutting Area */
BlurayBca = 30,
BlurayBca = 30,
/** Bluray Disc Definition Structure */
BlurayDds = 31,
BlurayDds = 31,
/** Bluray Cartridge Status */
BlurayCartridgeStatus = 32,
BlurayCartridgeStatus = 32,
/** Bluray Spare Area Information */
BluraySpareArea = 33,
BluraySpareArea = 33,
/** AACS Volume Identifier */
AacsVolumeIdentifier = 34,
AacsVolumeIdentifier = 34,
/** AACS Serial Number */
AacsSerialNumber = 35,
AacsSerialNumber = 35,
/** AACS Media Identifier */
AacsMediaIdentifier = 36,
AacsMediaIdentifier = 36,
/** AACS Media Key Block */
AacsMediaKeyBlock = 37,
AacsMediaKeyBlock = 37,
/** AACS Data Keys */
AacsDataKeys = 38,
AacsDataKeys = 38,
/** AACS LBA Extents */
AacsLbaExtents = 39,
AacsLbaExtents = 39,
/** CPRM Media Key Block */
CprmMediaKeyBlock = 40,
CprmMediaKeyBlock = 40,
/** Recognized Layers */
HybridRecognizedLayers = 41,
HybridRecognizedLayers = 41,
/** MMC Write Protection */
ScsiMmcWriteProtection = 42,
ScsiMmcWriteProtection = 42,
/** MMC Disc Information */
ScsiMmcDiscInformation = 43,
ScsiMmcDiscInformation = 43,
/** MMC Track Resources Information */
ScsiMmcTrackResourcesInformation = 44,
ScsiMmcTrackResourcesInformation = 44,
/** MMC POW Resources Information */
ScsiMmcPowResourcesInformation = 45,
ScsiMmcPowResourcesInformation = 45,
/** SCSI INQUIRY RESPONSE */
ScsiInquiry = 46,
ScsiInquiry = 46,
/** SCSI MODE PAGE 2Ah */
ScsiModePage2A = 47,
ScsiModePage2A = 47,
/** ATA IDENTIFY response */
AtaIdentify = 48,
AtaIdentify = 48,
/** ATAPI IDENTIFY response */
AtapiIdentify = 49,
AtapiIdentify = 49,
/** PCMCIA CIS */
PcmciaCis = 50,
PcmciaCis = 50,
/** SecureDigital CID */
SecureDigitalCid = 51,
SecureDigitalCid = 51,
/** SecureDigital CSD */
SecureDigitalCsd = 52,
SecureDigitalCsd = 52,
/** SecureDigital SCR */
SecureDigitalScr = 53,
SecureDigitalScr = 53,
/** SecureDigital OCR */
SecureDigitalOcr = 54,
SecureDigitalOcr = 54,
/** MultiMediaCard CID */
MultiMediaCardCid = 55,
MultiMediaCardCid = 55,
/** MultiMediaCard CSD */
MultiMediaCardCsd = 56,
MultiMediaCardCsd = 56,
/** MultiMediaCard OCR */
MultiMediaCardOcr = 57,
MultiMediaCardOcr = 57,
/** MultiMediaCard Extended CSD */
MultiMediaCardExtendedCsd = 58,
MultiMediaCardExtendedCsd = 58,
/** Xbox Security Sector */
XboxSecuritySector = 59,
XboxSecuritySector = 59,
/** Floppy Lead-out */
FloppyLeadOut = 60,
FloppyLeadOut = 60,
/** Dvd Disc Control Block */
DvdDiscControlBlock = 61,
DvdDiscControlBlock = 61,
/** CompactDisc First track pregap */
CompactDiscFirstTrackPregap = 62,
CompactDiscFirstTrackPregap = 62,
/** CompactDisc Lead-out */
CompactDiscLeadOut = 63,
CompactDiscLeadOut = 63,
/** SCSI MODE SENSE (6) response */
ScsiModeSense6 = 64,
ScsiModeSense6 = 64,
/** SCSI MODE SENSE (10) response */
ScsiModeSense10 = 65,
ScsiModeSense10 = 65,
/** USB descriptors */
UsbDescriptors = 66,
UsbDescriptors = 66,
/** Xbox DMI */
XboxDmi = 67,
XboxDmi = 67,
/** Xbox Physical Format Information */
XboxPfi = 68,
XboxPfi = 68,
/** CompactDisc sector prefix (sync, header */
CdSectorPrefix = 69,
CdSectorPrefix = 69,
/** CompactDisc sector suffix (edc, ecc p, ecc q) */
CdSectorSuffix = 70,
CdSectorSuffix = 70,
/** CompactDisc subchannel */
CdSectorSubchannel = 71,
CdSectorSubchannel = 71,
/** Apple Profile (20 byte) tag */
AppleProfileTag = 72,
AppleProfileTag = 72,
/** Apple Sony (12 byte) tag */
AppleSonyTag = 73,
AppleSonyTag = 73,
/** Priam Data Tower (24 byte) tag */
PriamDataTowerTag = 74,
PriamDataTowerTag = 74,
/** CompactDisc Media Catalogue Number (as in Lead-in), 13 bytes, ASCII */
CompactDiscMediaCatalogueNumber = 75,
CompactDiscMediaCatalogueNumber = 75,
/** CompactDisc sector prefix (sync, header), only incorrect stored */
CdSectorPrefixCorrected = 76,
CdSectorPrefixCorrected = 76,
/** CompactDisc sector suffix (edc, ecc p, ecc q), only incorrect stored */
CdSectorSuffixCorrected = 77,
CdSectorSuffixCorrected = 77,
/** CompactDisc MODE 2 subheader */
CompactDiscMode2Subheader = 78,
CompactDiscMode2Subheader = 78,
/** CompactDisc Lead-in */
CompactDiscLeadIn = 79
CompactDiscLeadIn = 79
} DataType;
/** List of known blocks types */
typedef enum
{
/** Block containing data */
DataBlock = 0x4B4C4244,
DataBlock = 0x4B4C4244,
/** Block containing a deduplication table */
DeDuplicationTable = 0X2A544444,
DeDuplicationTable = 0X2A544444,
/** Block containing the index */
IndexBlock = 0X58444E49,
IndexBlock = 0X58444E49,
/** Block containing logical geometry */
GeometryBlock = 0x4D4F4547,
GeometryBlock = 0x4D4F4547,
/** Block containing metadata */
MetadataBlock = 0x4154454D,
MetadataBlock = 0x4154454D,
/** Block containing optical disc tracks */
TracksBlock = 0x534B5254,
TracksBlock = 0x534B5254,
/** Block containing CICM XML metadata */
CicmBlock = 0x4D434943,
CicmBlock = 0x4D434943,
/** Block containing contents checksums */
ChecksumBlock = 0x4D534B43,
ChecksumBlock = 0x4D534B43,
/** TODO: Block containing data position measurements */
DataPositionMeasurementBlock = 0x2A4D5044,
DataPositionMeasurementBlock = 0x2A4D5044,
/** TODO: Block containing a snapshot index */
SnapshotBlock = 0x50414E53,
SnapshotBlock = 0x50414E53,
/** TODO: Block containing how to locate the parent image */
ParentBlock = 0x50524E54,
ParentBlock = 0x50524E54,
/** Block containing an array of hardware used to create the image */
DumpHardwareBlock = 0x2A504D44,
DumpHardwareBlock = 0x2A504D44,
/** TODO: Block containing list of files for a tape image */
TapeFileBlock = 0x454C4654
TapeFileBlock = 0x454C4654
} BlockType;
typedef enum
{
Invalid = 0, Md5 = 1, Sha1 = 2, Sha256 = 3, SpamSum = 4
Invalid = 0,
Md5 = 1,
Sha1 = 2,
Sha256 = 3,
SpamSum = 4
} ChecksumAlgorithm;
typedef enum
@@ -227,12 +231,12 @@ typedef enum
typedef enum
{
/** Audio track */
Audio = 0, /** Data track (not any of the below defined ones) */
Data = 1, /** Data track, compact disc mode 1 */
CdMode1 = 2, /** Data track, compact disc mode 2, formless */
CdMode2Formless = 3, /** Data track, compact disc mode 2, form 1 */
CdMode2Form1 = 4, /** Data track, compact disc mode 2, form 2 */
CdMode2Form2 = 5
Audio = 0, /** Data track (not any of the below defined ones) */
Data = 1, /** Data track, compact disc mode 1 */
CdMode1 = 2, /** Data track, compact disc mode 2, formless */
CdMode2Formless = 3, /** Data track, compact disc mode 2, form 1 */
CdMode2Form1 = 4, /** Data track, compact disc mode 2, form 2 */
CdMode2Form2 = 5
} TrackType;
typedef enum
@@ -248,19 +252,19 @@ typedef enum
/**
* Purely optical discs
*/
OpticalDisc = 0, /**
* Media that is physically block-based or abstracted like that
OpticalDisc = 0, /**
* Media that is physically block-based or abstracted like that
*/
BlockMedia = 1, /**
* Media that can be accessed by-byte or by-bit, like chips
*/
LinearMedia = 2, /**
* Media that can only store data when it is modulated to audio
*/
AudioMedia = 3
*/
BlockMedia = 1, /**
* Media that can be accessed by-byte or by-bit, like chips
*/
LinearMedia = 2, /**
* Media that can only store data when it is modulated to audio
*/
AudioMedia = 3
} XmlMediaType;
#endif //LIBDICFORMAT_ENUMS_H
#endif // LIBDICFORMAT_ENUMS_H
#pragma clang diagnostic pop

View File

@@ -27,4 +27,4 @@
#define DICF_STATUS_SECTOR_WITH_ERRORS 2
#define DICF_STATUS_SECTOR_DELETED 3
#endif //LIBDICFORMAT_ERRORS_H
#endif // LIBDICFORMAT_ERRORS_H

View File

@@ -37,34 +37,35 @@
#pragma pack(push, 1)
#include <stdint.h>
#include <stdbool.h>
#include <dic.h>
#include "enums.h"
#include <dic.h>
#include <stdbool.h>
#include <stdint.h>
/**Header, at start of file */
typedef struct DicHeader
{
/**Header identifier, <see cref="DIC_MAGIC" /> */
uint64_t identifier;
/**UTF-16LE name of the application that created the image */
uint8_t application[64];
uint8_t application[64];
/**Image format major version. A new major version means a possibly incompatible change of format */
uint8_t imageMajorVersion;
uint8_t imageMajorVersion;
/**Image format minor version. A new minor version indicates a compatible change of format */
uint8_t imageMinorVersion;
uint8_t imageMinorVersion;
/**Major version of the application that created the image */
uint8_t applicationMajorVersion;
uint8_t applicationMajorVersion;
/**Minor version of the application that created the image */
uint8_t applicationMinorVersion;
uint8_t applicationMinorVersion;
/**Type of media contained on image */
uint32_t mediaType;
/**Offset to index */
uint64_t indexOffset;
/**Windows filetime (100 nanoseconds since 1601/01/01 00:00:00 UTC) of image creation time */
int64_t creationTime;
int64_t creationTime;
/**Windows filetime (100 nanoseconds since 1601/01/01 00:00:00 UTC) of image last written time */
int64_t lastWrittenTime;
int64_t lastWrittenTime;
} DicHeader;
/**Header for a deduplication table. Table follows it */
@@ -77,7 +78,7 @@ typedef struct DdtHeader
/**Compression algorithm used to compress the DDT */
uint16_t compression;
/**Each entry is ((uint8_t offset in file) &lt;&lt; shift) + (sector offset in block) */
uint8_t shift;
uint8_t shift;
/**How many entries are in the table */
uint64_t entries;
/**Compressed length for the DDT */
@@ -151,9 +152,9 @@ typedef struct MetadataBlockHeader
/**Size in uint8_ts of this whole metadata block */
uint32_t blockSize;
/**Sequence of media set this media beint64_ts to */
int32_t mediaSequence;
int32_t mediaSequence;
/**Total number of media on the media set this media beint64_ts to */
int32_t lastMediaSequence;
int32_t lastMediaSequence;
/**Offset to start of creator string from start of this block */
uint32_t creatorOffset;
/**Length in uint8_ts of the null-terminated UTF-16LE creator string */
@@ -291,14 +292,14 @@ typedef struct ChecksumHeader
/**Length in uint8_ts of the block */
uint32_t length;
/**How many checksums follow */
uint8_t entries;
uint8_t entries;
} ChecksumHeader;
/**Checksum entry, followed by checksum data itself */
typedef struct ChecksumEntry
{
/**Checksum algorithm */
uint8_t type;
uint8_t type;
/**Length in uint8_ts of checksum that follows this structure */
uint32_t length;
} ChecksumEntry;
@@ -312,14 +313,14 @@ typedef struct Crc64Context
typedef struct CdEccContext
{
bool initedEdc;
uint8_t *eccBTable;
uint8_t *eccFTable;
bool initedEdc;
uint8_t * eccBTable;
uint8_t * eccFTable;
uint32_t *edcTable;
} CdEccContext;
#pragma pack(pop)
#endif //LIBDICFORMAT_STRUCTS_H
#endif // LIBDICFORMAT_STRUCTS_H
#pragma clang diagnostic pop

View File

@@ -30,10 +30,10 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
#include <stdio.h>
#include <dicformat.h>
#include <malloc.h>
#include <errno.h>
#include <malloc.h>
#include <stdio.h>
#include <sys/mman.h>
int close(void *context)
@@ -54,8 +54,7 @@ int close(void *context)
}
// This may do nothing if imageStream is NULL, but as the behaviour is undefined, better sure than sorry
if(ctx->imageStream != NULL)
fclose(ctx->imageStream);
if(ctx->imageStream != NULL) fclose(ctx->imageStream);
free(ctx->sectorPrefix);
free(ctx->sectorPrefixCorrected);
@@ -82,10 +81,7 @@ int close(void *context)
free(ctx->mediaTagsHead);
}
if(!ctx->inMemoryDdt)
{
munmap(ctx->userDataDdt, ctx->mappedMemoryDdtSize);
}
if(!ctx->inMemoryDdt) { munmap(ctx->userDataDdt, ctx->mappedMemoryDdtSize); }
free(ctx->sectorPrefixDdt);
free(ctx->sectorSuffixDdt);

View File

@@ -30,10 +30,10 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
#include <stdint.h>
#include <malloc.h>
#include <string.h>
#include <dicformat.h>
#include <malloc.h>
#include <stdint.h>
#include <string.h>
void *crc64_init(uint64_t polynomial, uint64_t seed)
{
@@ -41,8 +41,7 @@ void *crc64_init(uint64_t polynomial, uint64_t seed)
ctx = malloc(sizeof(Crc64Context));
if(ctx == NULL)
return NULL;
if(ctx == NULL) return NULL;
memset(ctx, 1, sizeof(Crc64Context));
@@ -52,7 +51,7 @@ void *crc64_init(uint64_t polynomial, uint64_t seed)
for(int i = 0; i < 256; i++)
{
uint64_t entry = (uint64_t)i;
for(int j = 0; j < 8; j++)
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (entry >> 1) ^ polynomial;
else
@@ -64,18 +63,13 @@ void *crc64_init(uint64_t polynomial, uint64_t seed)
return ctx;
}
void *crc64_init_ecma(void)
{
return crc64_init(CRC64_ECMA_POLY, CRC64_ECMA_SEED);
}
void *crc64_init_ecma(void) { return crc64_init(CRC64_ECMA_POLY, CRC64_ECMA_SEED); }
void crc64_update(void *context, const uint8_t *data, size_t len)
{
Crc64Context *ctx = context;
for(size_t i = 0; i < len; i++)
ctx->hashInt = (ctx->hashInt >> 8) ^ ctx->table[data[i] ^ (ctx->hashInt & 0xFF)];
for(size_t i = 0; i < len; i++) ctx->hashInt = (ctx->hashInt >> 8) ^ ctx->table[data[i] ^ (ctx->hashInt & 0xFF)];
}
uint64_t crc64_final(void *context)
@@ -93,7 +87,7 @@ uint64_t crc64_data(const uint8_t *data, size_t len, uint64_t polynomial, uint64
for(int i = 0; i < 256; i++)
{
uint64_t entry = (uint64_t)i;
for(int j = 0; j < 8; j++)
for(int j = 0; j < 8; j++)
if((entry & 1) == 1)
entry = (entry >> 1) ^ polynomial;
else
@@ -102,8 +96,7 @@ uint64_t crc64_data(const uint8_t *data, size_t len, uint64_t polynomial, uint64
table[i] = entry;
}
for(size_t i = 0; i < len; i++)
hashInt = (hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xFF)];
for(size_t i = 0; i < len; i++) hashInt = (hashInt >> 8) ^ table[data[i] ^ (hashInt & 0xFF)];
return hashInt ^ seed;
}
@@ -112,4 +105,3 @@ uint64_t crc64_data_ecma(const uint8_t *data, size_t len)
{
return crc64_data(data, len, CRC64_ECMA_POLY, CRC64_ECMA_SEED);
}

View File

@@ -30,24 +30,23 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
#include <stdint.h>
#include <malloc.h>
#include <dicformat.h>
#include <malloc.h>
#include <stdint.h>
#include <string.h>
int32_t cst_transform(const uint8_t *interleaved, uint8_t *sequential, size_t length)
{
uint8_t *p, *q, *r, *s, *t, *u, *v, *w;
size_t qStart;
size_t rStart;
size_t sStart;
size_t tStart;
size_t uStart;
size_t vStart;
size_t wStart;
size_t qStart;
size_t rStart;
size_t sStart;
size_t tStart;
size_t uStart;
size_t vStart;
size_t wStart;
if(interleaved == NULL || sequential == NULL)
return DICF_ERROR_BUFFER_TOO_SMALL;
if(interleaved == NULL || sequential == NULL) return DICF_ERROR_BUFFER_TOO_SMALL;
p = malloc(length / 8);
q = malloc(length / 8);
@@ -172,16 +171,15 @@ int32_t cst_transform(const uint8_t *interleaved, uint8_t *sequential, size_t le
int32_t cst_untransform(const uint8_t *sequential, uint8_t *interleaved, size_t length)
{
uint8_t *p, *q, *r, *s, *t, *u, *v, *w;
size_t qStart;
size_t rStart;
size_t sStart;
size_t tStart;
size_t uStart;
size_t vStart;
size_t wStart;
size_t qStart;
size_t rStart;
size_t sStart;
size_t tStart;
size_t uStart;
size_t vStart;
size_t wStart;
if(interleaved == NULL || sequential == NULL)
return DICF_ERROR_BUFFER_TOO_SMALL;
if(interleaved == NULL || sequential == NULL) return DICF_ERROR_BUFFER_TOO_SMALL;
p = malloc(length / 8);
q = malloc(length / 8);

View File

@@ -31,21 +31,20 @@
// ECC algorithm from ECM(c) 2002-2011 Neill Corlett
// ****************************************************************************/
#include <stdint.h>
#include <malloc.h>
#include <string.h>
#include <stdbool.h>
#include <dicformat.h>
#include <malloc.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
void *ecc_cd_init()
{
CdEccContext *context;
uint32_t edc, i, j;
uint32_t edc, i, j;
context = (CdEccContext *)malloc(sizeof(CdEccContext));
if(context == NULL)
return NULL;
if(context == NULL) return NULL;
context->eccFTable = (uint8_t *)malloc(sizeof(uint8_t) * 256);
@@ -75,12 +74,11 @@ void *ecc_cd_init()
for(i = 0; i < 256; i++)
{
edc = i;
j = (uint32_t)((i << 1) ^ ((i & 0x80) == 0x80 ? 0x11D : 0));
edc = i;
j = (uint32_t)((i << 1) ^ ((i & 0x80) == 0x80 ? 0x11D : 0));
context->eccFTable[i] = (uint8_t)j;
context->eccBTable[i ^ j] = (uint8_t)i;
for(j = 0; j < 8; j++)
edc = (edc >> 1) ^ ((edc & 1) > 0 ? 0xD8018001 : 0);
for(j = 0; j < 8; j++) edc = (edc >> 1) ^ ((edc & 1) > 0 ? 0xD8018001 : 0);
context->edcTable[i] = edc;
}
@@ -92,42 +90,32 @@ void *ecc_cd_init()
bool ecc_cd_is_suffix_correct(void *context, const uint8_t *sector)
{
CdEccContext *ctx;
uint32_t storedEdc, edc, calculatedEdc;
int size, pos;
uint32_t storedEdc, edc, calculatedEdc;
int size, pos;
if(context == NULL || sector == NULL)
return false;
if(context == NULL || sector == NULL) return false;
ctx = (CdEccContext *)context;
if(!ctx->initedEdc)
return false;
if(!ctx->initedEdc) return false;
if(sector[0x814] != 0x00 ||
// reserved (8 bytes)
sector[0x815] != 0x00 ||
sector[0x816] != 0x00 ||
sector[0x817] != 0x00 ||
sector[0x818] != 0x00 ||
sector[0x819] != 0x00 ||
sector[0x81A] != 0x00 ||
sector[0x81B] != 0x00)
sector[0x815] != 0x00 || sector[0x816] != 0x00 || sector[0x817] != 0x00 || sector[0x818] != 0x00 ||
sector[0x819] != 0x00 || sector[0x81A] != 0x00 || sector[0x81B] != 0x00)
return false;
bool correctEccP = ecc_cd_check(context, sector, sector, 86, 24, 2, 86, sector, 0xC, 0x10, 0x81C);
if(!correctEccP)
return false;
if(!correctEccP) return false;
bool correctEccQ = ecc_cd_check(context, sector, sector, 52, 43, 86, 88, sector, 0xC, 0x10, 0x81C + 0xAC);
if(!correctEccQ)
return false;
bool correctEccQ = ecc_cd_check(context, sector, sector, 52, 43, 86, 88, sector, 0xC, 0x10, 0x81C + 0xAC);
if(!correctEccQ) return false;
storedEdc = sector[0x810]; // TODO: Check casting
edc = 0;
size = 0x810;
pos = 0;
for(; size > 0; size--)
edc = (edc >> 8) ^ ctx->edcTable[(edc ^ sector[pos++]) & 0xFF];
storedEdc = sector[0x810]; // TODO: Check casting
edc = 0;
size = 0x810;
pos = 0;
for(; size > 0; size--) edc = (edc >> 8) ^ ctx->edcTable[(edc ^ sector[pos++]) & 0xFF];
calculatedEdc = edc;
return calculatedEdc == storedEdc;
@@ -136,115 +124,102 @@ bool ecc_cd_is_suffix_correct(void *context, const uint8_t *sector)
bool ecc_cd_is_suffix_correct_mode2(void *context, const uint8_t *sector)
{
CdEccContext *ctx;
uint32_t storedEdc, edc, calculatedEdc;
int size, pos;
uint8_t zeroaddress[4];
uint32_t storedEdc, edc, calculatedEdc;
int size, pos;
uint8_t zeroaddress[4];
if(context == NULL || sector == NULL)
return false;
if(context == NULL || sector == NULL) return false;
ctx = (CdEccContext *)context;
if(!ctx->initedEdc)
return false;
if(!ctx->initedEdc) return false;
memset(&zeroaddress, 4, sizeof(uint8_t));
bool correctEccP = ecc_cd_check(context, zeroaddress, sector, 86, 24, 2, 86, sector, 0, 0x10, 0x81C);
if(!correctEccP)
return false;
if(!correctEccP) return false;
bool
correctEccQ =
ecc_cd_check(context, zeroaddress, sector, 52, 43, 86, 88, sector, 0, 0x10, 0x81C + 0xAC);
if(!correctEccQ)
return false;
bool correctEccQ = ecc_cd_check(context, zeroaddress, sector, 52, 43, 86, 88, sector, 0, 0x10, 0x81C + 0xAC);
if(!correctEccQ) return false;
storedEdc = sector[0x818]; // TODO: Check cast
edc = 0;
size = 0x808;
pos = 0x10;
for(; size > 0; size--)
edc = (edc >> 8) ^ ctx->edcTable[(edc ^ sector[pos++]) & 0xFF];
storedEdc = sector[0x818]; // TODO: Check cast
edc = 0;
size = 0x808;
pos = 0x10;
for(; size > 0; size--) edc = (edc >> 8) ^ ctx->edcTable[(edc ^ sector[pos++]) & 0xFF];
calculatedEdc = edc;
return calculatedEdc == storedEdc;
}
bool ecc_cd_check(void *context,
bool ecc_cd_check(void * context,
const uint8_t *address,
const uint8_t *data,
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
const uint8_t *ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset)
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset)
{
CdEccContext *ctx;
uint32_t size, major, idx, minor;
uint8_t eccA, eccB, temp;
uint32_t size, major, idx, minor;
uint8_t eccA, eccB, temp;
if(context == NULL || address == NULL || data == NULL || ecc == NULL)
return false;
if(context == NULL || address == NULL || data == NULL || ecc == NULL) return false;
ctx = (CdEccContext *)context;
if(!ctx->initedEdc)
return false;
if(!ctx->initedEdc) return false;
size = majorCount * minorCount;
size = majorCount * minorCount;
for(major = 0; major < majorCount; major++)
{
idx = (major >> 1) * majorMult + (major & 1);
eccA = 0;
eccB = 0;
idx = (major >> 1) * majorMult + (major & 1);
eccA = 0;
eccB = 0;
for(minor = 0; minor < minorCount; minor++)
{
temp = idx < 4 ? address[idx + addressOffset] : data[idx + dataOffset - 4];
idx += minorInc;
if(idx >= size)
idx -= size;
if(idx >= size) idx -= size;
eccA ^= temp;
eccB ^= temp;
eccA = ctx->eccFTable[eccA];
}
eccA = ctx->eccBTable[ctx->eccFTable[eccA] ^ eccB];
if(ecc[major + eccOffset] != eccA || ecc[major + majorCount + eccOffset] != (eccA ^ eccB))
return false;
if(ecc[major + eccOffset] != eccA || ecc[major + majorCount + eccOffset] != (eccA ^ eccB)) return false;
}
return true;
}
void ecc_cd_write(void *context,
void ecc_cd_write(void * context,
const uint8_t *address,
const uint8_t *data,
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
uint8_t *ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset)
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
uint8_t * ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset)
{
CdEccContext *ctx;
uint32_t size, major, idx, minor;
uint8_t eccA, eccB, temp;
uint32_t size, major, idx, minor;
uint8_t eccA, eccB, temp;
if(context == NULL || address == NULL || data == NULL || ecc == NULL)
return;
if(context == NULL || address == NULL || data == NULL || ecc == NULL) return;
ctx = (CdEccContext *)context;
if(!ctx->initedEdc)
return;
if(!ctx->initedEdc) return;
size = majorCount * minorCount;
size = majorCount * minorCount;
for(major = 0; major < majorCount; major++)
{
idx = (major >> 1) * majorMult + (major & 1);
@@ -255,28 +230,27 @@ void ecc_cd_write(void *context,
{
temp = idx < 4 ? address[idx + addressOffset] : data[idx + dataOffset - 4];
idx += minorInc;
if(idx >= size)
idx -= size;
if(idx >= size) idx -= size;
eccA ^= temp;
eccB ^= temp;
eccA = ctx->eccFTable[eccA];
}
eccA = ctx->eccBTable[ctx->eccFTable[eccA] ^ eccB];
eccA = ctx->eccBTable[ctx->eccFTable[eccA] ^ eccB];
ecc[major + eccOffset] = eccA;
ecc[major + majorCount + eccOffset] = (eccA ^ eccB);
}
}
void ecc_cd_write_sector(void *context,
void ecc_cd_write_sector(void * context,
const uint8_t *address,
const uint8_t *data,
uint8_t *ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset)
uint8_t * ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset)
{
ecc_cd_write(context, address, data, 86, 24, 2, 86, ecc, addressOffset, dataOffset, eccOffset); // P
ecc_cd_write(context, address, data, 86, 24, 2, 86, ecc, addressOffset, dataOffset, eccOffset); // P
ecc_cd_write(context, address, data, 52, 43, 86, 88, ecc, addressOffset, dataOffset, eccOffset + 0xAC); // Q
}
@@ -287,14 +261,13 @@ void cd_lba_to_msf(int64_t pos, uint8_t *minute, uint8_t *second, uint8_t *frame
*frame = (uint8_t)((pos + 150) % 75);
}
void ecc_cd_reconstruct_prefix(uint8_t *sector, // must point to a full 2352-byte sector
uint8_t type, int64_t lba)
uint8_t type,
int64_t lba)
{
uint8_t minute, second, frame;
if(sector == NULL)
return;
if(sector == NULL) return;
//
// Sync
@@ -345,34 +318,36 @@ void ecc_cd_reconstruct_prefix(uint8_t *sector, // must point to a full 2352-byt
}
}
void ecc_cd_reconstruct(void *context, uint8_t *sector, // must point to a full 2352-byte sector
uint8_t type)
void ecc_cd_reconstruct(void * context,
uint8_t *sector, // must point to a full 2352-byte sector
uint8_t type)
{
uint32_t computedEdc;
uint8_t zeroaddress[4];
CdEccContext *ctx;
if(context == NULL || sector == NULL)
return;
if(context == NULL || sector == NULL) return;
ctx = (CdEccContext *)context;
if(!ctx->initedEdc)
return;
if(!ctx->initedEdc) return;
switch(type)
{
//
// Compute EDC
//
case CdMode1:computedEdc = edc_cd_compute(context, 0, sector, 0x810, 0);
case CdMode1:
computedEdc = edc_cd_compute(context, 0, sector, 0x810, 0);
memcpy(sector + 0x810, &computedEdc, 4);
break;
case CdMode2Form1:computedEdc = edc_cd_compute(context, 0, sector, 0x808, 0x10);
case CdMode2Form1:
computedEdc = edc_cd_compute(context, 0, sector, 0x808, 0x10);
memcpy(sector + 0x818, &computedEdc, 4);
break;
case CdMode2Form2:computedEdc = edc_cd_compute(context, 0, sector, 0x91C, 0x10);
case CdMode2Form2:
computedEdc = edc_cd_compute(context, 0, sector, 0x91C, 0x10);
memcpy(sector + 0x92C, &computedEdc, 4);
break;
default: return;
@@ -399,8 +374,7 @@ void ecc_cd_reconstruct(void *context, uint8_t *sector, // must point to a full
sector[0x81B] = 0x00;
ecc_cd_write_sector(context, sector, sector, sector, 0xC, 0x10, 0x81C);
break;
case CdMode2Form1:ecc_cd_write_sector(context, zeroaddress, sector, sector, 0, 0x10, 0x81C);
break;
case CdMode2Form1: ecc_cd_write_sector(context, zeroaddress, sector, sector, 0, 0x10, 0x81C); break;
default: return;
}
@@ -413,16 +387,13 @@ uint32_t edc_cd_compute(void *context, uint32_t edc, const uint8_t *src, int siz
{
CdEccContext *ctx;
if(context == NULL || src == NULL)
return 0;
if(context == NULL || src == NULL) return 0;
ctx = (CdEccContext *)context;
if(!ctx->initedEdc)
return 0;
if(!ctx->initedEdc) return 0;
for(; size > 0; size--)
edc = (edc >> 8) ^ ctx->edcTable[(edc ^ src[pos++]) & 0xFF];
for(; size > 0; size--) edc = (edc >> 8) ^ ctx->edcTable[(edc ^ src[pos++]) & 0xFF];
return edc;
}

View File

@@ -30,9 +30,9 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
#include <dicformat.h>
#include <errno.h>
#include <stdio.h>
#include <dicformat.h>
//! Identifies a file as dicformat, using path
/*!
@@ -47,8 +47,7 @@ int identify(const char *filename)
stream = fopen(filename, "rb");
if(stream == NULL)
return errno;
if(stream == NULL) return errno;
int ret = identifyStream(stream);
@@ -72,11 +71,9 @@ int identifyStream(FILE *imageStream)
size_t ret = fread(&header, sizeof(DicHeader), 1, imageStream);
if(ret < sizeof(DicHeader))
return 0;
if(ret < sizeof(DicHeader)) return 0;
if(header.identifier == DIC_MAGIC && header.imageMajorVersion <= DICF_VERSION)
return 100;
if(header.identifier == DIC_MAGIC && header.imageMajorVersion <= DICF_VERSION) return 100;
return 0;
}

View File

@@ -30,32 +30,31 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
#include <stdio.h>
#include <dicformat.h>
#include <malloc.h>
#include <errno.h>
#include <inttypes.h>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
void *open(const char *filepath)
{
dicformatContext *ctx;
int errorNo;
size_t readBytes;
long pos;
IndexHeader idxHeader;
IndexEntry *idxEntries;
uint8_t *data;
uint32_t *cdDdt;
uint64_t crc64;
uint8_t temp8u;
int errorNo;
size_t readBytes;
long pos;
IndexHeader idxHeader;
IndexEntry * idxEntries;
uint8_t * data;
uint32_t * cdDdt;
uint64_t crc64;
uint8_t temp8u;
ctx = (dicformatContext *)malloc(sizeof(dicformatContext));
memset(ctx, 0, sizeof(dicformatContext));
if(ctx == NULL)
return NULL;
if(ctx == NULL) return NULL;
ctx->imageStream = fopen(filepath, "rb");
@@ -159,7 +158,8 @@ void *open(const char *filepath)
return NULL;
}
fprintf(stderr, "libdicformat: Index at %"PRIu64" contains %d entries", ctx->header.indexOffset, idxHeader.entries);
fprintf(
stderr, "libdicformat: Index at %" PRIu64 " contains %d entries", ctx->header.indexOffset, idxHeader.entries);
idxEntries = (IndexEntry *)malloc(sizeof(IndexEntry) * idxHeader.entries);
@@ -186,13 +186,14 @@ void *open(const char *filepath)
for(int i = 0; i < idxHeader.entries; i++)
{
fprintf(stderr, "libdicformat: Block type %4.4s with data type %4.4s is indexed to be at %"PRIu64"",
fprintf(stderr,
"libdicformat: Block type %4.4s with data type %4.4s is indexed to be at %" PRIu64 "",
(char *)&idxEntries[i].blockType,
(char *)&idxEntries[i].dataType,
idxEntries[i].offset);
}
bool foundUserDataDdt = false;
bool foundUserDataDdt = false;
ctx->imageInfo.ImageSize = 0;
for(int i = 0; i < idxHeader.entries; i++)
{
@@ -201,7 +202,7 @@ void *open(const char *filepath)
if(pos < 0 || ftell(ctx->imageStream) != idxEntries[i].offset)
{
fprintf(stderr,
"libdicformat: Could not seek to %"PRIu64" as indicated by index entry %d, continuing...",
"libdicformat: Could not seek to %" PRIu64 " as indicated by index entry %d, continuing...",
idxEntries[i].offset,
i);
@@ -215,14 +216,13 @@ void *open(const char *filepath)
{
case DataBlock:
// NOP block, skip
if(idxEntries[i].dataType == NoData)
break;
if(idxEntries[i].dataType == NoData) break;
readBytes = fread(&blockHeader, sizeof(BlockHeader), 1, ctx->imageStream);
if(readBytes != sizeof(BlockHeader))
{
fprintf(stderr, "libdicformat: Could not read block header at %"PRIu64"", idxEntries[i].offset);
fprintf(stderr, "libdicformat: Could not read block header at %" PRIu64 "", idxEntries[i].offset);
break;
}
@@ -241,7 +241,7 @@ void *open(const char *filepath)
if(blockHeader.identifier != idxEntries[i].blockType)
{
fprintf(stderr,
"libdicformat: Incorrect identifier for data block at position %"PRIu64"",
"libdicformat: Incorrect identifier for data block at position %" PRIu64 "",
idxEntries[i].offset);
break;
}
@@ -249,14 +249,16 @@ void *open(const char *filepath)
if(blockHeader.type != idxEntries[i].dataType)
{
fprintf(stderr,
"libdicformat: Expected block with data type %4.4s at position %"PRIu64" but found data type %4.4s",
"libdicformat: Expected block with data type %4.4s at position %" PRIu64
" but found data type %4.4s",
(char *)&idxEntries[i].blockType,
idxEntries[i].offset,
(char *)&blockHeader.type);
break;
}
fprintf(stderr, "libdicformat: Found data block with type %4.4s at position %"PRIu64"",
fprintf(stderr,
"libdicformat: Found data block with type %4.4s at position %" PRIu64 "",
(char *)&idxEntries[i].blockType,
idxEntries[i].offset);
@@ -290,7 +292,8 @@ void *open(const char *filepath)
if(crc64 != blockHeader.crc64)
{
fprintf(stderr,
"libdicformat: Incorrect CRC found: 0x%"PRIx64" found, expected 0x%"PRIx64", continuing...",
"libdicformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64
", continuing...",
crc64,
blockHeader.crc64);
break;
@@ -303,10 +306,7 @@ void *open(const char *filepath)
{
case CdSectorPrefix:
case CdSectorPrefixCorrected:
if(idxEntries[i].dataType == CdSectorPrefixCorrected)
{
ctx->sectorPrefixCorrected = data;
}
if(idxEntries[i].dataType == CdSectorPrefixCorrected) { ctx->sectorPrefixCorrected = data; }
else
ctx->sectorPrefix = data;
@@ -327,16 +327,17 @@ void *open(const char *filepath)
ctx->readableSectorTags[CdSectorEccQ] = true;
ctx->readableSectorTags[CdSectorEdc] = true;
break;
case CdSectorSubchannel:ctx->sectorSubchannel = data;
case CdSectorSubchannel:
ctx->sectorSubchannel = data;
ctx->readableSectorTags[CdSectorSubchannel] = true;
break;
case AppleProfileTag:
case AppleSonyTag:
case PriamDataTowerTag:ctx->sectorSubchannel = data;
case PriamDataTowerTag:
ctx->sectorSubchannel = data;
ctx->readableSectorTags[AppleSectorTag] = true;
break;
case CompactDiscMode2Subheader:ctx->mode2Subheaders = data;
break;
case CompactDiscMode2Subheader: ctx->mode2Subheaders = data; break;
default:
if(ctx->mediaTagsHead != NULL)
{
@@ -359,8 +360,7 @@ void *open(const char *filepath)
// If we mediaTag is NULL means we have arrived the end of the list without finding a duplicate
// or the list was empty
if(mediaTag != NULL)
break;
if(mediaTag != NULL) break;
mediaTag = (dataLinkedList *)malloc(sizeof(dataLinkedList));
@@ -375,10 +375,7 @@ void *open(const char *filepath)
mediaTag->data = data;
mediaTag->length = blockHeader.length;
if(ctx->mediaTagsHead == NULL)
{
ctx->mediaTagsHead = mediaTag;
}
if(ctx->mediaTagsHead == NULL) { ctx->mediaTagsHead = mediaTag; }
else
{
mediaTag->previous = ctx->mediaTagsTail;
@@ -391,11 +388,12 @@ void *open(const char *filepath)
}
break;
case DeDuplicationTable:readBytes = fread(&ddtHeader, sizeof(DdtHeader), 1, ctx->imageStream);
case DeDuplicationTable:
readBytes = fread(&ddtHeader, sizeof(DdtHeader), 1, ctx->imageStream);
if(readBytes != sizeof(DdtHeader))
{
fprintf(stderr, "libdicformat: Could not read block header at %"PRIu64"", idxEntries[i].offset);
fprintf(stderr, "libdicformat: Could not read block header at %" PRIu64 "", idxEntries[i].offset);
break;
}
@@ -412,14 +410,14 @@ void *open(const char *filepath)
// Check for DDT compression
switch(ddtHeader.compression)
{
case None:ctx->mappedMemoryDdtSize = sizeof(uint64_t) * ddtHeader.entries;
ctx->userDataDdt =
mmap(NULL,
ctx->mappedMemoryDdtSize,
PROT_READ,
MAP_SHARED,
fileno(ctx->imageStream),
idxEntries[i].offset + sizeof(ddtHeader));
case None:
ctx->mappedMemoryDdtSize = sizeof(uint64_t) * ddtHeader.entries;
ctx->userDataDdt = mmap(NULL,
ctx->mappedMemoryDdtSize,
PROT_READ,
MAP_SHARED,
fileno(ctx->imageStream),
idxEntries[i].offset + sizeof(ddtHeader));
if(ctx->userDataDdt == MAP_FAILED)
{
@@ -436,7 +434,6 @@ void *open(const char *filepath)
blockHeader.compression);
foundUserDataDdt = false;
break;
}
}
else if(idxEntries[i].dataType == CdSectorPrefixCorrected ||
@@ -444,7 +441,8 @@ void *open(const char *filepath)
{
switch(ddtHeader.compression)
{
case None:cdDdt = (uint32_t *)malloc(ddtHeader.entries * sizeof(uint32_t));
case None:
cdDdt = (uint32_t *)malloc(ddtHeader.entries * sizeof(uint32_t));
if(mediaTag == NULL)
{
@@ -478,7 +476,8 @@ void *open(const char *filepath)
}
break;
// Logical geometry block. It doesn't have a CRC coz, well, it's not so important
case GeometryBlock:readBytes = fread(&ctx->geometryBlock, sizeof(GeometryBlockHeader), 1, ctx->imageStream);
case GeometryBlock:
readBytes = fread(&ctx->geometryBlock, sizeof(GeometryBlockHeader), 1, ctx->imageStream);
if(readBytes != sizeof(GeometryBlockHeader))
{
@@ -504,11 +503,8 @@ void *open(const char *filepath)
break;
// Metadata block
case MetadataBlock: readBytes =
fread(&ctx->metadataBlockHeader,
sizeof(MetadataBlockHeader),
1,
ctx->imageStream);
case MetadataBlock:
readBytes = fread(&ctx->metadataBlockHeader, sizeof(MetadataBlockHeader), 1, ctx->imageStream);
if(readBytes != sizeof(MetadataBlockHeader))
{
@@ -521,7 +517,7 @@ void *open(const char *filepath)
{
memset(&ctx->metadataBlockHeader, 0, sizeof(MetadataBlockHeader));
fprintf(stderr,
"libdicformat: Incorrect identifier for data block at position %"PRIu64"",
"libdicformat: Incorrect identifier for data block at position %" PRIu64 "",
idxEntries[i].offset);
break;
}
@@ -558,7 +554,7 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.creatorLength > 0 &&
ctx->metadataBlockHeader.creatorOffset + ctx->metadataBlockHeader.creatorLength <=
ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.Creator = (uint8_t *)malloc(ctx->metadataBlockHeader.creatorLength);
if(ctx->imageInfo.Creator != NULL)
@@ -571,7 +567,7 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.commentsLength > 0 &&
ctx->metadataBlockHeader.commentsOffset + ctx->metadataBlockHeader.commentsLength <=
ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.Comments = (uint8_t *)malloc(ctx->metadataBlockHeader.commentsLength);
if(ctx->imageInfo.Comments != NULL)
@@ -584,7 +580,7 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.mediaTitleLength > 0 &&
ctx->metadataBlockHeader.mediaTitleOffset + ctx->metadataBlockHeader.mediaTitleLength <=
ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.MediaTitle = (uint8_t *)malloc(ctx->metadataBlockHeader.mediaTitleLength);
if(ctx->imageInfo.MediaTitle != NULL)
@@ -597,10 +593,11 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.mediaManufacturerLength > 0 &&
ctx->metadataBlockHeader.mediaManufacturerOffset +
ctx->metadataBlockHeader.mediaManufacturerLength <= ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.mediaManufacturerLength <=
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.MediaManufacturer =
(uint8_t *)malloc(ctx->metadataBlockHeader.mediaManufacturerLength);
(uint8_t *)malloc(ctx->metadataBlockHeader.mediaManufacturerLength);
if(ctx->imageInfo.MediaManufacturer != NULL)
{
memcpy(ctx->imageInfo.MediaManufacturer,
@@ -611,7 +608,7 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.mediaModelLength > 0 &&
ctx->metadataBlockHeader.mediaModelOffset + ctx->metadataBlockHeader.mediaModelLength <=
ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.MediaModel = (uint8_t *)malloc(ctx->metadataBlockHeader.mediaModelOffset);
if(ctx->imageInfo.MediaModel != NULL)
@@ -624,10 +621,11 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.mediaSerialNumberLength > 0 &&
ctx->metadataBlockHeader.mediaSerialNumberOffset +
ctx->metadataBlockHeader.mediaSerialNumberLength <= ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.mediaSerialNumberLength <=
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.MediaSerialNumber =
(uint8_t *)malloc(ctx->metadataBlockHeader.mediaSerialNumberLength);
(uint8_t *)malloc(ctx->metadataBlockHeader.mediaSerialNumberLength);
if(ctx->imageInfo.MediaSerialNumber != NULL)
{
memcpy(ctx->imageInfo.MediaSerialNumber,
@@ -638,7 +636,7 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.mediaBarcodeLength > 0 &&
ctx->metadataBlockHeader.mediaBarcodeOffset + ctx->metadataBlockHeader.mediaBarcodeLength <=
ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.MediaBarcode = (uint8_t *)malloc(ctx->metadataBlockHeader.mediaBarcodeLength);
if(ctx->imageInfo.MediaBarcode != NULL)
@@ -651,7 +649,7 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.mediaPartNumberLength > 0 &&
ctx->metadataBlockHeader.mediaPartNumberOffset + ctx->metadataBlockHeader.mediaPartNumberLength <=
ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.MediaPartNumber = (uint8_t *)malloc(ctx->metadataBlockHeader.mediaPartNumberLength);
if(ctx->imageInfo.MediaPartNumber != NULL)
@@ -664,10 +662,11 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.driveManufacturerLength > 0 &&
ctx->metadataBlockHeader.driveManufacturerOffset +
ctx->metadataBlockHeader.driveManufacturerLength <= ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.driveManufacturerLength <=
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.DriveManufacturer =
(uint8_t *)malloc(ctx->metadataBlockHeader.driveManufacturerLength);
(uint8_t *)malloc(ctx->metadataBlockHeader.driveManufacturerLength);
if(ctx->imageInfo.DriveManufacturer != NULL)
{
memcpy(ctx->imageInfo.DriveManufacturer,
@@ -678,7 +677,7 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.driveModelLength > 0 &&
ctx->metadataBlockHeader.driveModelOffset + ctx->metadataBlockHeader.driveModelLength <=
ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.DriveModel = (uint8_t *)malloc(ctx->metadataBlockHeader.driveModelLength);
if(ctx->imageInfo.DriveModel != NULL)
@@ -691,10 +690,11 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.driveSerialNumberLength > 0 &&
ctx->metadataBlockHeader.driveSerialNumberOffset +
ctx->metadataBlockHeader.driveSerialNumberLength <= ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.driveSerialNumberLength <=
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.DriveSerialNumber =
(uint8_t *)malloc(ctx->metadataBlockHeader.driveSerialNumberLength);
(uint8_t *)malloc(ctx->metadataBlockHeader.driveSerialNumberLength);
if(ctx->imageInfo.DriveSerialNumber != NULL)
{
memcpy(ctx->imageInfo.DriveSerialNumber,
@@ -705,10 +705,11 @@ void *open(const char *filepath)
if(ctx->metadataBlockHeader.driveManufacturerLength > 0 &&
ctx->metadataBlockHeader.driveFirmwareRevisionOffset +
ctx->metadataBlockHeader.driveManufacturerLength <= ctx->metadataBlockHeader.blockSize)
ctx->metadataBlockHeader.driveManufacturerLength <=
ctx->metadataBlockHeader.blockSize)
{
ctx->imageInfo.DriveFirmwareRevision =
(uint8_t *)malloc(ctx->metadataBlockHeader.driveFirmwareRevisionLength);
(uint8_t *)malloc(ctx->metadataBlockHeader.driveFirmwareRevisionLength);
if(ctx->imageInfo.DriveFirmwareRevision != NULL)
{
memcpy(ctx->imageInfo.DriveFirmwareRevision,
@@ -718,7 +719,8 @@ void *open(const char *filepath)
}
break;
case TracksBlock: readBytes = fread(&ctx->tracksHeader, sizeof(TracksHeader), 1, ctx->imageStream);
case TracksBlock:
readBytes = fread(&ctx->tracksHeader, sizeof(TracksHeader), 1, ctx->imageStream);
if(readBytes != sizeof(TracksHeader))
{
@@ -731,7 +733,7 @@ void *open(const char *filepath)
{
memset(&ctx->tracksHeader, 0, sizeof(TracksHeader));
fprintf(stderr,
"libdicformat: Incorrect identifier for data block at position %"PRIu64"",
"libdicformat: Incorrect identifier for data block at position %" PRIu64 "",
idxEntries[i].offset);
}
@@ -756,19 +758,19 @@ void *open(const char *filepath)
}
crc64 =
crc64_data_ecma((const uint8_t *)ctx->trackEntries,
ctx->tracksHeader.entries * sizeof(TrackEntry));
crc64_data_ecma((const uint8_t *)ctx->trackEntries, ctx->tracksHeader.entries * sizeof(TrackEntry));
if(crc64 != ctx->tracksHeader.crc64)
{
fprintf(stderr,
"libdicformat: Incorrect CRC found: 0x%"PRIx64" found, expected 0x%"PRIx64", continuing...",
"libdicformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64
", continuing...",
crc64,
ctx->tracksHeader.crc64);
break;
}
fprintf(stderr,
"libdicformat: Found %d tracks at position %"PRIu64".",
"libdicformat: Found %d tracks at position %" PRIu64 ".",
ctx->tracksHeader.entries,
idxEntries[i].offset);
@@ -788,25 +790,23 @@ void *open(const char *filepath)
{
ctx->dataTracks = (TrackEntry *)malloc(sizeof(TrackEntry) * temp8u);
if(ctx->dataTracks == NULL)
break;
if(ctx->dataTracks == NULL) break;
ctx->numberOfDataTracks = temp8u;
for(i = 0, temp8u = 0; i < ctx->tracksHeader.entries; i++)
{
if(ctx->trackEntries[i].sequence > 99)
continue;
if(ctx->trackEntries[i].sequence > 99) continue;
memcpy(&ctx->dataTracks[ctx->trackEntries[i].sequence],
&ctx->trackEntries[i],
sizeof(TrackEntry));
memcpy(
&ctx->dataTracks[ctx->trackEntries[i].sequence], &ctx->trackEntries[i], sizeof(TrackEntry));
}
}
break;
// CICM XML metadata block
case CicmBlock:readBytes = fread(&ctx->cicmBlockHeader, sizeof(CicmMetadataBlock), 1, ctx->imageStream);
case CicmBlock:
readBytes = fread(&ctx->cicmBlockHeader, sizeof(CicmMetadataBlock), 1, ctx->imageStream);
if(readBytes != sizeof(CicmMetadataBlock))
{
@@ -819,7 +819,7 @@ void *open(const char *filepath)
{
memset(&ctx->cicmBlockHeader, 0, sizeof(CicmMetadataBlock));
fprintf(stderr,
"libdicformat: Incorrect identifier for data block at position %"PRIu64"",
"libdicformat: Incorrect identifier for data block at position %" PRIu64 "",
idxEntries[i].offset);
}
@@ -844,14 +844,11 @@ void *open(const char *filepath)
fprintf(stderr, "libdicformat: Could not read CICM XML metadata block, continuing...");
}
fprintf(stderr, "libdicformat: Found CICM XML metadata block %"PRIu64".", idxEntries[i].offset);
fprintf(stderr, "libdicformat: Found CICM XML metadata block %" PRIu64 ".", idxEntries[i].offset);
break;
// Dump hardware block
case DumpHardwareBlock: readBytes =
fread(&ctx->dumpHardwareHeader,
sizeof(DumpHardwareHeader),
1,
ctx->imageStream);
case DumpHardwareBlock:
readBytes = fread(&ctx->dumpHardwareHeader, sizeof(DumpHardwareHeader), 1, ctx->imageStream);
if(readBytes != sizeof(DumpHardwareHeader))
{
@@ -864,7 +861,7 @@ void *open(const char *filepath)
{
memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader));
fprintf(stderr,
"libdicformat: Incorrect identifier for data block at position %"PRIu64"",
"libdicformat: Incorrect identifier for data block at position %" PRIu64 "",
idxEntries[i].offset);
}
@@ -880,7 +877,8 @@ void *open(const char *filepath)
{
free(data);
fprintf(stderr,
"libdicformat: Incorrect CRC found: 0x%"PRIx64" found, expected 0x%"PRIx64", continuing...",
"libdicformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64
", continuing...",
crc64,
ctx->dumpHardwareHeader.crc64);
break;
@@ -891,9 +889,8 @@ void *open(const char *filepath)
fseek(ctx->imageStream, -readBytes, SEEK_CUR);
}
ctx->dumpHardwareEntriesWithData =
(DumpHardwareEntriesWithData *)malloc(sizeof(DumpHardwareEntriesWithData) *
ctx->dumpHardwareHeader.entries);
ctx->dumpHardwareEntriesWithData = (DumpHardwareEntriesWithData *)malloc(
sizeof(DumpHardwareEntriesWithData) * ctx->dumpHardwareHeader.entries);
if(ctx->dumpHardwareEntriesWithData == NULL)
{
@@ -908,11 +905,8 @@ void *open(const char *filepath)
for(uint16_t e = 0; e < ctx->dumpHardwareHeader.entries; e++)
{
readBytes =
fread(&ctx->dumpHardwareEntriesWithData[e].entry,
sizeof(DumpHardwareEntry),
1,
ctx->imageStream);
readBytes = fread(
&ctx->dumpHardwareEntriesWithData[e].entry, sizeof(DumpHardwareEntry), 1, ctx->imageStream);
if(readBytes != sizeof(DumpHardwareEntry))
{
@@ -924,22 +918,22 @@ void *open(const char *filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength > 0)
{
ctx->dumpHardwareEntriesWithData[e].manufacturer =
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength);
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength);
if(ctx->dumpHardwareEntriesWithData[e].manufacturer != NULL)
{
readBytes =
fread(&ctx->dumpHardwareEntriesWithData[e].manufacturer,
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength,
1,
ctx->imageStream);
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].manufacturer,
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength,
1,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength)
{
free(ctx->dumpHardwareEntriesWithData[e].manufacturer);
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength = 0;
fprintf(stderr,
"libdicformat: Could not read dump hardware block entry manufacturer, continuing...");
"libdicformat: Could not read dump hardware block entry manufacturer, "
"continuing...");
}
}
}
@@ -947,15 +941,14 @@ void *open(const char *filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.modelLength > 0)
{
ctx->dumpHardwareEntriesWithData[e].model =
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.modelLength);
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.modelLength);
if(ctx->dumpHardwareEntriesWithData[e].model != NULL)
{
readBytes =
fread(&ctx->dumpHardwareEntriesWithData[e].model,
ctx->dumpHardwareEntriesWithData[e].entry.modelLength,
1,
ctx->imageStream);
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].model,
ctx->dumpHardwareEntriesWithData[e].entry.modelLength,
1,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.modelLength)
{
@@ -970,22 +963,22 @@ void *open(const char *filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength > 0)
{
ctx->dumpHardwareEntriesWithData[e].revision =
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength);
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength);
if(ctx->dumpHardwareEntriesWithData[e].revision != NULL)
{
readBytes =
fread(&ctx->dumpHardwareEntriesWithData[e].revision,
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength,
1,
ctx->imageStream);
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].revision,
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength,
1,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.revisionLength)
{
free(ctx->dumpHardwareEntriesWithData[e].revision);
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength = 0;
fprintf(stderr,
"libdicformat: Could not read dump hardware block entry revision, continuing...");
fprintf(
stderr,
"libdicformat: Could not read dump hardware block entry revision, continuing...");
}
}
}
@@ -993,22 +986,22 @@ void *open(const char *filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength > 0)
{
ctx->dumpHardwareEntriesWithData[e].firmware =
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength);
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength);
if(ctx->dumpHardwareEntriesWithData[e].firmware != NULL)
{
readBytes =
fread(&ctx->dumpHardwareEntriesWithData[e].firmware,
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength,
1,
ctx->imageStream);
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].firmware,
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength,
1,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength)
{
free(ctx->dumpHardwareEntriesWithData[e].firmware);
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength = 0;
fprintf(stderr,
"libdicformat: Could not read dump hardware block entry firmware, continuing...");
fprintf(
stderr,
"libdicformat: Could not read dump hardware block entry firmware, continuing...");
}
}
}
@@ -1016,15 +1009,14 @@ void *open(const char *filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.serialLength > 0)
{
ctx->dumpHardwareEntriesWithData[e].serial =
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.serialLength);
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.serialLength);
if(ctx->dumpHardwareEntriesWithData[e].serial != NULL)
{
readBytes =
fread(&ctx->dumpHardwareEntriesWithData[e].serial,
ctx->dumpHardwareEntriesWithData[e].entry.serialLength,
1,
ctx->imageStream);
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].serial,
ctx->dumpHardwareEntriesWithData[e].entry.serialLength,
1,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.serialLength)
{
@@ -1039,22 +1031,22 @@ void *open(const char *filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength > 0)
{
ctx->dumpHardwareEntriesWithData[e].softwareName =
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength);
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength);
if(ctx->dumpHardwareEntriesWithData[e].softwareName != NULL)
{
readBytes =
fread(&ctx->dumpHardwareEntriesWithData[e].softwareName,
ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength,
1,
ctx->imageStream);
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].softwareName,
ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength,
1,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength)
{
free(ctx->dumpHardwareEntriesWithData[e].softwareName);
ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength = 0;
fprintf(stderr,
"libdicformat: Could not read dump hardware block entry software name, continuing...");
"libdicformat: Could not read dump hardware block entry software name, "
"continuing...");
}
}
}
@@ -1062,22 +1054,22 @@ void *open(const char *filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength > 0)
{
ctx->dumpHardwareEntriesWithData[e].softwareVersion =
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength);
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength);
if(ctx->dumpHardwareEntriesWithData[e].softwareVersion != NULL)
{
readBytes =
fread(&ctx->dumpHardwareEntriesWithData[e].softwareVersion,
ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength,
1,
ctx->imageStream);
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].softwareVersion,
ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength,
1,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength)
{
free(ctx->dumpHardwareEntriesWithData[e].softwareVersion);
ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength = 0;
fprintf(stderr,
"libdicformat: Could not read dump hardware block entry software version, continuing...");
"libdicformat: Could not read dump hardware block entry software version, "
"continuing...");
}
}
}
@@ -1085,42 +1077,41 @@ void *open(const char *filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength > 0)
{
ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem =
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry
.softwareOperatingSystemLength);
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength);
if(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem != NULL)
{
readBytes =
fread(&ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem,
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength,
1,
ctx->imageStream);
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem,
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength,
1,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength)
{
free(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem);
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength = 0;
fprintf(stderr,
"libdicformat: Could not read dump hardware block entry manufacturer, continuing...");
"libdicformat: Could not read dump hardware block entry manufacturer, "
"continuing...");
}
}
}
ctx->dumpHardwareEntriesWithData[e].extents =
(DumpExtent *)malloc(sizeof(DumpExtent) * ctx->dumpHardwareEntriesWithData->entry.extents);
(DumpExtent *)malloc(sizeof(DumpExtent) * ctx->dumpHardwareEntriesWithData->entry.extents);
if(ctx->dumpHardwareEntriesWithData[e].extents == NULL)
{
fprintf(stderr,
"libdicformat: Could not allocate memory for dump hardware block extents, continuing...");
fprintf(
stderr,
"libdicformat: Could not allocate memory for dump hardware block extents, continuing...");
continue;
}
readBytes =
fread(ctx->dumpHardwareEntriesWithData[e].extents,
sizeof(DumpExtent),
ctx->dumpHardwareEntriesWithData[e].entry.extents,
ctx->imageStream);
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].extents,
sizeof(DumpExtent),
ctx->dumpHardwareEntriesWithData[e].entry.extents,
ctx->imageStream);
if(readBytes != sizeof(DumpExtent) * ctx->dumpHardwareEntriesWithData->entry.extents)
{
@@ -1135,7 +1126,7 @@ void *open(const char *filepath)
break;
default:
fprintf(stderr,
"libdicformat: Unhandled block type %4.4s with data type %4.4s is indexed to be at %"PRIu64"",
"libdicformat: Unhandled block type %4.4s with data type %4.4s is indexed to be at %" PRIu64 "",
(char *)&idxEntries[i].blockType,
(char *)&idxEntries[i].dataType,
idxEntries[i].offset);
@@ -1156,7 +1147,7 @@ void *open(const char *filepath)
ctx->imageInfo.LastModificationTime = ctx->header.lastWrittenTime;
ctx->imageInfo.XmlMediaType = GetXmlMediaType(ctx->header.mediaType);
if(ctx->geometryBlock.identifier != GeometryBlock/* && ctx->imageInfo.XmlMediaType == XmlMediaType.BlockMedia*/)
if(ctx->geometryBlock.identifier != GeometryBlock && ctx->imageInfo.XmlMediaType == BlockMedia)
{
ctx->imageInfo.Cylinders = (uint32_t)(ctx->imageInfo.Sectors / 16 / 63);
ctx->imageInfo.Heads = 16;

View File

@@ -37,16 +37,14 @@
int32_t read_media_tag(void *context, uint8_t *data, int32_t tag, uint32_t *length)
{
dicformatContext *ctx;
dataLinkedList *item;
dataLinkedList * item;
if(context == NULL)
return DICF_ERROR_NOT_DICFORMAT;
if(context == NULL) return DICF_ERROR_NOT_DICFORMAT;
ctx = context;
// Not a libdicformat context
if(ctx->magic != DIC_MAGIC)
return DICF_ERROR_NOT_DICFORMAT;
if(ctx->magic != DIC_MAGIC) return DICF_ERROR_NOT_DICFORMAT;
item = ctx->mediaTagsHead;
@@ -74,25 +72,22 @@ int32_t read_media_tag(void *context, uint8_t *data, int32_t tag, uint32_t *leng
int32_t read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32_t *length)
{
dicformatContext *ctx;
uint64_t ddtEntry;
uint32_t offsetMask;
uint64_t offset;
uint64_t blockOffset;
BlockHeader blockHeader;
uint8_t *block;
size_t readBytes;
uint64_t ddtEntry;
uint32_t offsetMask;
uint64_t offset;
uint64_t blockOffset;
BlockHeader blockHeader;
uint8_t * block;
size_t readBytes;
if(context == NULL)
return DICF_ERROR_NOT_DICFORMAT;
if(context == NULL) return DICF_ERROR_NOT_DICFORMAT;
ctx = context;
// Not a libdicformat context
if(ctx->magic != DIC_MAGIC)
return DICF_ERROR_NOT_DICFORMAT;
if(ctx->magic != DIC_MAGIC) return DICF_ERROR_NOT_DICFORMAT;
if(sectorAddress > ctx->imageInfo.Sectors - 1)
return DICF_ERROR_SECTOR_OUT_OF_BOUNDS;
if(sectorAddress > ctx->imageInfo.Sectors - 1) return DICF_ERROR_SECTOR_OUT_OF_BOUNDS;
ddtEntry = ctx->userDataDdt[sectorAddress];
offsetMask = (uint32_t)((1 << ctx->shift) - 1);
@@ -114,8 +109,7 @@ int32_t read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32
fseek(ctx->imageStream, blockOffset, SEEK_SET);
readBytes = fread(&blockHeader, sizeof(BlockHeader), 1, ctx->imageStream);
if(readBytes != sizeof(BlockHeader))
return DICF_ERROR_CANNOT_READ_HEADER;
if(readBytes != sizeof(BlockHeader)) return DICF_ERROR_CANNOT_READ_HEADER;
if(data == NULL || *length < blockHeader.sectorSize)
{
@@ -126,9 +120,9 @@ int32_t read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32
// Decompress block
switch(blockHeader.compression)
{
case None:block = (uint8_t *)malloc(blockHeader.length);
if(block == NULL)
return DICF_ERROR_NOT_ENOUGH_MEMORY;
case None:
block = (uint8_t *)malloc(blockHeader.length);
if(block == NULL) return DICF_ERROR_NOT_ENOUGH_MEMORY;
readBytes = fread(block, blockHeader.length, 1, ctx->imageStream);
@@ -139,7 +133,7 @@ int32_t read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32
}
break;
default:return DICF_ERROR_UNSUPPORTED_COMPRESSION;
default: return DICF_ERROR_UNSUPPORTED_COMPRESSION;
}
// Check if cache needs to be emptied
@@ -157,26 +151,21 @@ int32_t read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32
int32_t read_track_sector(void *context, uint8_t *data, uint64_t sectorAddress, uint32_t *length, uint8_t track)
{
dicformatContext *ctx;
int i;
int i;
if(context == NULL)
return DICF_ERROR_NOT_DICFORMAT;
if(context == NULL) return DICF_ERROR_NOT_DICFORMAT;
ctx = context;
// Not a libdicformat context
if(ctx->magic != DIC_MAGIC)
return DICF_ERROR_NOT_DICFORMAT;
if(ctx->magic != DIC_MAGIC) return DICF_ERROR_NOT_DICFORMAT;
if(ctx->imageInfo.XmlMediaType != OpticalDisc)
return DICF_ERROR_INCORRECT_MEDIA_TYPE;
if(ctx->imageInfo.XmlMediaType != OpticalDisc) return DICF_ERROR_INCORRECT_MEDIA_TYPE;
for(i = 0; i < ctx->numberOfDataTracks; i++)
{
if(ctx->dataTracks[i].sequence == track)
{
return read_sector(context, ctx->dataTracks[i].start + sectorAddress, data, length);
}
{ return read_sector(context, ctx->dataTracks[i].start + sectorAddress, data, length); }
}
return DICF_ERROR_TRACK_NOT_FOUND;
@@ -185,22 +174,20 @@ int32_t read_track_sector(void *context, uint8_t *data, uint64_t sectorAddress,
int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, uint32_t *length)
{
dicformatContext *ctx;
uint32_t bareLength;
uint32_t tagLength;
uint8_t *bareData;
int32_t res;
TrackEntry trk;
int i;
bool trkFound;
uint32_t bareLength;
uint32_t tagLength;
uint8_t * bareData;
int32_t res;
TrackEntry trk;
int i;
bool trkFound;
if(context == NULL)
return DICF_ERROR_NOT_DICFORMAT;
if(context == NULL) return DICF_ERROR_NOT_DICFORMAT;
ctx = context;
// Not a libdicformat context
if(ctx->magic != DIC_MAGIC)
return DICF_ERROR_NOT_DICFORMAT;
if(ctx->magic != DIC_MAGIC) return DICF_ERROR_NOT_DICFORMAT;
switch(ctx->imageInfo.XmlMediaType)
{
@@ -219,13 +206,11 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
bareData = (uint8_t *)malloc(bareLength);
if(bareData == NULL)
return DICF_ERROR_NOT_ENOUGH_MEMORY;
if(bareData == NULL) return DICF_ERROR_NOT_ENOUGH_MEMORY;
res = read_sector(context, sectorAddress, bareData, &bareLength);
if(res < DICF_STATUS_OK)
return res;
if(res < DICF_STATUS_OK) return res;
trkFound = false;
@@ -239,15 +224,14 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
}
}
if(!trkFound)
return DICF_ERROR_TRACK_NOT_FOUND;
if(!trkFound) return DICF_ERROR_TRACK_NOT_FOUND;
switch(trk.type)
{
case Audio:
case Data:memcpy(bareData, data, bareLength);
return res;
case CdMode1:memcpy(bareData, data + 16, 2048);
case Data: memcpy(bareData, data, bareLength); return res;
case CdMode1:
memcpy(bareData, data + 16, 2048);
if(ctx->sectorPrefix != NULL)
memcpy(data, ctx->sectorPrefix + (sectorAddress * 16), 16);
@@ -266,7 +250,7 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
{
memcpy(data,
ctx->sectorPrefixCorrected +
((ctx->sectorPrefixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 16,
((ctx->sectorPrefixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 16,
16);
}
}
@@ -279,7 +263,6 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
{
if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
{
ecc_cd_reconstruct(ctx->eccCdContext, data, trk.type);
res = DICF_STATUS_OK;
}
@@ -291,7 +274,7 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
{
memcpy(data + 2064,
ctx->sectorSuffixCorrected +
((ctx->sectorSuffixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 288,
((ctx->sectorSuffixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 288,
288);
}
}
@@ -319,7 +302,7 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
{
memcpy(data,
ctx->sectorPrefixCorrected +
((ctx->sectorPrefixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 16,
((ctx->sectorPrefixDdt[sectorAddress] & CD_DFIX_MASK) - 1) * 16,
16);
}
}
@@ -352,7 +335,7 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
memcpy(data + 16, bareData, 2336);
return res;
default:return DICF_ERROR_INVALID_TRACK_FORMAT;
default: return DICF_ERROR_INVALID_TRACK_FORMAT;
}
case BlockMedia:
switch(ctx->imageInfo.MediaType)
@@ -363,21 +346,17 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
case AppleSonyDS:
case AppleWidget:
case PriamDataTower:
if(ctx->sectorSubchannel == NULL)
return read_sector(context, sectorAddress, data, length);
if(ctx->sectorSubchannel == NULL) return read_sector(context, sectorAddress, data, length);
switch(ctx->imageInfo.MediaType)
{
case AppleFileWare:
case AppleProfile:
case AppleWidget:tagLength = 20;
break;
case AppleWidget: tagLength = 20; break;
case AppleSonySS:
case AppleSonyDS:tagLength = 12;
break;
case PriamDataTower:tagLength = 24;
break;
default:return DICF_ERROR_INCORRECT_MEDIA_TYPE;
case AppleSonyDS: tagLength = 12; break;
case PriamDataTower: tagLength = 24; break;
default: return DICF_ERROR_INCORRECT_MEDIA_TYPE;
}
bareLength = 512;
@@ -390,13 +369,11 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
bareData = malloc(bareLength);
if(bareData == NULL)
return DICF_ERROR_NOT_ENOUGH_MEMORY;
if(bareData == NULL) return DICF_ERROR_NOT_ENOUGH_MEMORY;
res = read_sector(context, sectorAddress, bareData, &bareLength);
if(bareLength != 512)
return res;
if(bareLength != 512) return res;
memcpy(data, ctx->sectorSubchannel + sectorAddress * tagLength, tagLength);
memcpy(data, bareData, 512);
@@ -404,9 +381,8 @@ int32_t read_sector_long(void *context, uint8_t *data, uint64_t sectorAddress, u
free(bareData);
return res;
default:return DICF_ERROR_INCORRECT_MEDIA_TYPE;
default: return DICF_ERROR_INCORRECT_MEDIA_TYPE;
}
default:return DICF_ERROR_INCORRECT_MEDIA_TYPE;
default: return DICF_ERROR_INCORRECT_MEDIA_TYPE;
}
}