Implement support for reading file format header version 2.

This commit is contained in:
2025-08-02 20:23:32 +01:00
parent 9a5a994702
commit b504c8392d
10 changed files with 71 additions and 46 deletions

View File

@@ -219,7 +219,7 @@ int32_t process_data_block(aaruformatContext *ctx, IndexEntry *entry)
crc64 = aaruf_crc64_data(data, blockHeader.length);
// Due to how C# wrote it, it is effectively reversed
if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64);
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != blockHeader.crc64)
{

View File

@@ -79,7 +79,7 @@ void process_dumphw_block(aaruformatContext *ctx, const IndexEntry *entry)
crc64 = aaruf_crc64_data(data, ctx->dumpHardwareHeader.length);
// Due to how C# wrote it, it is effectively reversed
if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64);
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != ctx->dumpHardwareHeader.crc64)
{

View File

@@ -87,7 +87,7 @@ void process_tracks_block(aaruformatContext *ctx, const IndexEntry *entry)
crc64 = aaruf_crc64_data((const uint8_t *)ctx->trackEntries, ctx->tracksHeader.entries * sizeof(TrackEntry));
// Due to how C# wrote it, it is effectively reversed
if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64);
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != ctx->tracksHeader.crc64)
{

View File

@@ -107,7 +107,7 @@ int32_t verify_index_v1(aaruformatContext *ctx)
crc64 = aaruf_crc64_data((const uint8_t *)index_entries, sizeof(IndexEntry) * index_header.entries);
// Due to how C# wrote it, it is effectively reversed
if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64);
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != index_header.crc64)
{

View File

@@ -107,7 +107,7 @@ int32_t verify_index_v2(aaruformatContext *ctx)
crc64 = aaruf_crc64_data((const uint8_t *)index_entries, sizeof(IndexEntry) * index_header.entries);
// Due to how C# wrote it, it is effectively reversed
if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64);
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != index_header.crc64)
{

View File

@@ -76,6 +76,21 @@ void *aaruf_open(const char *filepath)
return NULL;
}
// Read new header version
if(ctx->header.imageMajorVersion >= AARUF_VERSION_V2)
{
fseek(ctx->imageStream, 0, SEEK_SET);
readBytes = fread(&ctx->header, 1, sizeof(AaruHeaderV2), ctx->imageStream);
if(readBytes != sizeof(AaruHeaderV2))
{
free(ctx);
errno = AARUF_ERROR_FILE_TOO_SMALL;
return NULL;
}
}
if(ctx->header.imageMajorVersion > AARUF_VERSION)
{
free(ctx);

View File

@@ -137,7 +137,7 @@ int32_t aaruf_verify_image(void *context)
aaruf_crc64_final(crc64_context, &crc64);
// Due to how C# wrote it, it is effectively reversed
if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64);
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != block_header.cmpCrc64)
{
@@ -180,7 +180,7 @@ int32_t aaruf_verify_image(void *context)
aaruf_crc64_final(crc64_context, &crc64);
// Due to how C# wrote it, it is effectively reversed
if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64);
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != ddt_header.cmpCrc64)
{
@@ -214,7 +214,7 @@ int32_t aaruf_verify_image(void *context)
aaruf_crc64_final(crc64_context, &crc64);
// Due to how C# wrote it, it is effectively reversed
if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64);
if(ctx->header.imageMajorVersion <= AARUF_VERSION_V1) crc64 = bswap_64(crc64);
if(crc64 != tracks_header.crc64)
{