mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Split dump hardware block processing from open to a separate file.
This commit is contained in:
@@ -113,7 +113,8 @@ add_library(aaruformat SHARED include/aaruformat/consts.h include/aaruformat/enu
|
||||
src/blocks/data.c
|
||||
src/ddt/ddt_v1.c
|
||||
src/blocks/metadata.c
|
||||
src/blocks/optical.c)
|
||||
src/blocks/optical.c
|
||||
src/blocks/dump.c)
|
||||
|
||||
include_directories(include include/aaruformat)
|
||||
|
||||
|
||||
@@ -31,5 +31,6 @@ void process_metadata_block(aaruformatContext *ctx, const IndexEntry *entry
|
||||
void process_geometry_block(aaruformatContext *ctx, const IndexEntry *entry);
|
||||
void process_tracks_block(aaruformatContext *ctx, const IndexEntry *entry);
|
||||
void process_cicm_block(aaruformatContext *ctx, const IndexEntry *entry);
|
||||
void process_dumphw_block(aaruformatContext *ctx, const IndexEntry *entry);
|
||||
|
||||
#endif // LIBAARUFORMAT_INTERNAL_H
|
||||
|
||||
316
src/blocks/dump.c
Normal file
316
src/blocks/dump.c
Normal file
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* This file is part of the Aaru Data Preservation Suite.
|
||||
* Copyright (c) 2019-2025 Natalia Portillo.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "aaruformat.h"
|
||||
|
||||
void process_dumphw_block(aaruformatContext *ctx, const IndexEntry *entry)
|
||||
{
|
||||
int pos = 0;
|
||||
size_t readBytes = 0;
|
||||
uint64_t crc64 = 0;
|
||||
uint16_t e = 0;
|
||||
uint8_t *data = NULL;
|
||||
|
||||
// Check if the context and image stream are valid
|
||||
if(ctx == NULL || ctx->imageStream == NULL)
|
||||
{
|
||||
fprintf(stderr, "Invalid context or image stream.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Seek to block
|
||||
pos = fseek(ctx->imageStream, entry->offset, SEEK_SET);
|
||||
if(pos < 0 || ftell(ctx->imageStream) != entry->offset)
|
||||
{
|
||||
fprintf(stderr, "libaaruformat: Could not seek to %" PRIu64 " as indicated by index entry...\n", entry->offset);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Even if those two checks shall have been done before
|
||||
readBytes = fread(&ctx->dumpHardwareHeader, 1, sizeof(DumpHardwareHeader), ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(DumpHardwareHeader))
|
||||
{
|
||||
memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader));
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block header, continuing...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareHeader.identifier != DumpHardwareBlock)
|
||||
{
|
||||
memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader));
|
||||
fprintf(stderr, "libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n", entry->offset);
|
||||
}
|
||||
|
||||
data = (uint8_t *)malloc(ctx->dumpHardwareHeader.length);
|
||||
|
||||
if(data == NULL)
|
||||
{
|
||||
memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader));
|
||||
fprintf(stderr, "libaaruformat: Could not allocate memory for dump hardware block, continuing...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
readBytes = fread(data, 1, ctx->dumpHardwareHeader.length, ctx->imageStream);
|
||||
|
||||
if(readBytes == ctx->dumpHardwareHeader.length)
|
||||
{
|
||||
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(crc64 != ctx->dumpHardwareHeader.crc64)
|
||||
{
|
||||
free(data);
|
||||
fprintf(stderr,
|
||||
"libaaruformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64 ", continuing...\n",
|
||||
crc64, ctx->dumpHardwareHeader.crc64);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
free(data);
|
||||
fseek(ctx->imageStream, -(long)readBytes, SEEK_CUR);
|
||||
|
||||
ctx->dumpHardwareEntriesWithData =
|
||||
(DumpHardwareEntriesWithData *)malloc(sizeof(DumpHardwareEntriesWithData) * ctx->dumpHardwareHeader.entries);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData == NULL)
|
||||
{
|
||||
memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader));
|
||||
fprintf(stderr, "libaaruformat: Could not allocate memory for dump hardware block, continuing...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(ctx->dumpHardwareEntriesWithData, 0, sizeof(DumpHardwareEntriesWithData) * ctx->dumpHardwareHeader.entries);
|
||||
|
||||
for(e = 0; e < ctx->dumpHardwareHeader.entries; e++)
|
||||
{
|
||||
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].entry, 1, sizeof(DumpHardwareEntry), ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(DumpHardwareEntry))
|
||||
{
|
||||
ctx->dumpHardwareHeader.entries = e;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry, continuing...\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].manufacturer =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].manufacturer != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.manufacturer[ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength] = 0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].manufacturer, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].manufacturer);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry manufacturer, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.modelLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].model =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.modelLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].model != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].model[ctx->dumpHardwareEntriesWithData[e].entry.modelLength] = 0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].model, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.modelLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.modelLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].model);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.modelLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry model, continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].revision =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].revision != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].revision[ctx->dumpHardwareEntriesWithData[e].entry.revisionLength] =
|
||||
0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].revision, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.revisionLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].revision);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry revision, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].firmware =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].firmware != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].firmware[ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength] =
|
||||
0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].firmware, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].firmware);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry firmware, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.serialLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].serial =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.serialLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].serial != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].serial[ctx->dumpHardwareEntriesWithData[e].entry.serialLength] = 0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].serial, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.serialLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.serialLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].serial);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.serialLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry serial, continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].softwareName =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].softwareName != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.softwareName[ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength] = 0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].softwareName, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].softwareName);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry software name, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].softwareVersion =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].softwareVersion != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.softwareVersion[ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength] = 0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].softwareVersion, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].softwareVersion);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry software version, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.softwareOperatingSystem[ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength] =
|
||||
0;
|
||||
readBytes =
|
||||
fread(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry manufacturer, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx->dumpHardwareEntriesWithData[e].extents =
|
||||
(DumpExtent *)malloc(sizeof(DumpExtent) * ctx->dumpHardwareEntriesWithData->entry.extents);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].extents == NULL)
|
||||
{
|
||||
fprintf(stderr, "libaaruformat: Could not allocate memory for dump hardware block extents, "
|
||||
"continuing...\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].extents, sizeof(DumpExtent),
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.extents, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData->entry.extents)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].extents);
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block extents, continuing...\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: qsort()
|
||||
}
|
||||
}
|
||||
290
src/open.c
290
src/open.c
@@ -22,10 +22,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
#include "internal.h"
|
||||
@@ -38,9 +34,7 @@ void *aaruf_open(const char *filepath)
|
||||
size_t readBytes = 0;
|
||||
long pos = 0;
|
||||
uint8_t *data = NULL;
|
||||
uint64_t crc64 = 0;
|
||||
int i = 0, j = 0;
|
||||
uint16_t e = 0;
|
||||
ChecksumHeader checksum_header;
|
||||
ChecksumEntry const *checksum_entry = NULL;
|
||||
uint32_t signature = 0;
|
||||
@@ -241,289 +235,7 @@ void *aaruf_open(const char *filepath)
|
||||
break;
|
||||
// Dump hardware block
|
||||
case DumpHardwareBlock:
|
||||
readBytes = fread(&ctx->dumpHardwareHeader, 1, sizeof(DumpHardwareHeader), ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(DumpHardwareHeader))
|
||||
{
|
||||
memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader));
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block header, continuing...\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareHeader.identifier != DumpHardwareBlock)
|
||||
{
|
||||
memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader));
|
||||
fprintf(stderr, "libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
|
||||
entry->offset);
|
||||
}
|
||||
|
||||
data = (uint8_t *)malloc(ctx->dumpHardwareHeader.length);
|
||||
|
||||
if(data == NULL)
|
||||
{
|
||||
memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader));
|
||||
fprintf(stderr,
|
||||
"libaaruformat: Could not allocate memory for dump hardware block, continuing...\n");
|
||||
break;
|
||||
}
|
||||
|
||||
readBytes = fread(data, 1, ctx->dumpHardwareHeader.length, ctx->imageStream);
|
||||
|
||||
if(readBytes == ctx->dumpHardwareHeader.length)
|
||||
{
|
||||
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(crc64 != ctx->dumpHardwareHeader.crc64)
|
||||
{
|
||||
free(data);
|
||||
fprintf(stderr,
|
||||
"libaaruformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64
|
||||
", continuing...\n",
|
||||
crc64, ctx->dumpHardwareHeader.crc64);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(data);
|
||||
fseek(ctx->imageStream, -(long)readBytes, SEEK_CUR);
|
||||
|
||||
ctx->dumpHardwareEntriesWithData = (DumpHardwareEntriesWithData *)malloc(
|
||||
sizeof(DumpHardwareEntriesWithData) * ctx->dumpHardwareHeader.entries);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData == NULL)
|
||||
{
|
||||
memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader));
|
||||
fprintf(stderr,
|
||||
"libaaruformat: Could not allocate memory for dump hardware block, continuing...\n");
|
||||
break;
|
||||
}
|
||||
|
||||
memset(ctx->dumpHardwareEntriesWithData, 0,
|
||||
sizeof(DumpHardwareEntriesWithData) * ctx->dumpHardwareHeader.entries);
|
||||
|
||||
for(e = 0; e < ctx->dumpHardwareHeader.entries; e++)
|
||||
{
|
||||
readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].entry, 1, sizeof(DumpHardwareEntry),
|
||||
ctx->imageStream);
|
||||
|
||||
if(readBytes != sizeof(DumpHardwareEntry))
|
||||
{
|
||||
ctx->dumpHardwareHeader.entries = e;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry, continuing...\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].manufacturer =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].manufacturer != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.manufacturer[ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength] = 0;
|
||||
readBytes =
|
||||
fread(ctx->dumpHardwareEntriesWithData[e].manufacturer, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].manufacturer);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry manufacturer, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.modelLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].model =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.modelLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].model != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.model[ctx->dumpHardwareEntriesWithData[e].entry.modelLength] = 0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].model, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.modelLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.modelLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].model);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.modelLength = 0;
|
||||
fprintf(
|
||||
stderr,
|
||||
"libaaruformat: Could not read dump hardware block entry model, continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].revision =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].revision != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.revision[ctx->dumpHardwareEntriesWithData[e].entry.revisionLength] = 0;
|
||||
readBytes =
|
||||
fread(ctx->dumpHardwareEntriesWithData[e].revision, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.revisionLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].revision);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry revision, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].firmware =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].firmware != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.firmware[ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength] = 0;
|
||||
readBytes =
|
||||
fread(ctx->dumpHardwareEntriesWithData[e].firmware, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].firmware);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry firmware, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.serialLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].serial =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.serialLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].serial != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.serial[ctx->dumpHardwareEntriesWithData[e].entry.serialLength] = 0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].serial, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.serialLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.serialLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].serial);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.serialLength = 0;
|
||||
fprintf(
|
||||
stderr,
|
||||
"libaaruformat: Could not read dump hardware block entry serial, continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].softwareName =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].softwareName != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.softwareName[ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength] = 0;
|
||||
readBytes =
|
||||
fread(ctx->dumpHardwareEntriesWithData[e].softwareName, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].softwareName);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength = 0;
|
||||
fprintf(stderr,
|
||||
"libaaruformat: Could not read dump hardware block entry software name, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].softwareVersion =
|
||||
(uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].softwareVersion != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e]
|
||||
.softwareVersion[ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength] = 0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].softwareVersion, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength,
|
||||
ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].softwareVersion);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength = 0;
|
||||
fprintf(stderr,
|
||||
"libaaruformat: Could not read dump hardware block entry software version, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength > 0)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem = (uint8_t *)malloc(
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength + 1);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem != NULL)
|
||||
{
|
||||
ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem
|
||||
[ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength] = 0;
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem, 1,
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength,
|
||||
ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem);
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength = 0;
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block entry manufacturer, "
|
||||
"continuing...\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx->dumpHardwareEntriesWithData[e].extents =
|
||||
(DumpExtent *)malloc(sizeof(DumpExtent) * ctx->dumpHardwareEntriesWithData->entry.extents);
|
||||
|
||||
if(ctx->dumpHardwareEntriesWithData[e].extents == NULL)
|
||||
{
|
||||
fprintf(stderr, "libaaruformat: Could not allocate memory for dump hardware block extents, "
|
||||
"continuing...\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].extents, sizeof(DumpExtent),
|
||||
ctx->dumpHardwareEntriesWithData[e].entry.extents, ctx->imageStream);
|
||||
|
||||
if(readBytes != ctx->dumpHardwareEntriesWithData->entry.extents)
|
||||
{
|
||||
free(ctx->dumpHardwareEntriesWithData[e].extents);
|
||||
fprintf(stderr, "libaaruformat: Could not read dump hardware block extents, continuing...\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: qsort()
|
||||
}
|
||||
process_dumphw_block(ctx, entry);
|
||||
|
||||
break;
|
||||
case ChecksumBlock:
|
||||
|
||||
Reference in New Issue
Block a user