mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Compare commits
12 Commits
v1.0.0-alp
...
v1.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
10be636fd2
|
|||
|
b4da7d9fb2
|
|||
|
f9eec04d08
|
|||
|
94e44ef304
|
|||
|
d6ea7db911
|
|||
|
0326c81a91
|
|||
|
542cc58eba
|
|||
|
6ec945203b
|
|||
|
7a4992a243
|
|||
|
4899b4c24a
|
|||
|
d66e45aed3
|
|||
|
e7921b3278
|
@@ -287,9 +287,9 @@ endif()
|
|||||||
# Check for math library
|
# Check for math library
|
||||||
include(CheckLibraryExists)
|
include(CheckLibraryExists)
|
||||||
|
|
||||||
check_library_exists(m log "" HAVE_LIB_M)
|
check_library_exists(m cos "" HAVE_LIB_M)
|
||||||
if(HAVE_LIB_M)
|
if(HAVE_LIB_M)
|
||||||
TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE(aaruformat m)
|
target_link_libraries(aaruformat m)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Find Doxygen for documentation generation
|
# Find Doxygen for documentation generation
|
||||||
|
|||||||
@@ -292,6 +292,7 @@ typedef struct aaruformat_context
|
|||||||
bool is_writing; ///< True if context opened/created for writing.
|
bool is_writing; ///< True if context opened/created for writing.
|
||||||
bool rewinded; ///< True if stream has been rewound after open (write path).
|
bool rewinded; ///< True if stream has been rewound after open (write path).
|
||||||
bool writing_long; ///< True if writing long sectors
|
bool writing_long; ///< True if writing long sectors
|
||||||
|
bool block_zero_written; ///< True if block zero has been written (writing path).
|
||||||
|
|
||||||
/* Options */
|
/* Options */
|
||||||
uint32_t lzma_dict_size; ///< LZMA dictionary size (writing path).
|
uint32_t lzma_dict_size; ///< LZMA dictionary size (writing path).
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>libaaruformat</id>
|
<id>libaaruformat</id>
|
||||||
<version>1.0.0-alpha.3</version>
|
<version>1.0.0-alpha.7</version>
|
||||||
<description>Library for management of AaruFormat images.</description>
|
<description>Library for management of AaruFormat images.</description>
|
||||||
<authors>claunia</authors>
|
<authors>claunia</authors>
|
||||||
<projectUrl>https://github.com/aaru-dps/libaaruformat</projectUrl>
|
<projectUrl>https://github.com/aaru-dps/libaaruformat</projectUrl>
|
||||||
|
|||||||
@@ -61,19 +61,19 @@ static void reset_dump_hardware_context(aaruformat_context *ctx)
|
|||||||
memset(&ctx->dump_hardware_header, 0, sizeof(ctx->dump_hardware_header));
|
memset(&ctx->dump_hardware_header, 0, sizeof(ctx->dump_hardware_header));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_dump_string(FILE *stream, const char *field_name, uint32_t length, uint32_t *remaining,
|
static bool read_dump_string(FILE *stream, const char *field_name, const uint32_t length, uint32_t *remaining,
|
||||||
uint8_t **destination)
|
uint8_t **destination)
|
||||||
{
|
{
|
||||||
if(length == 0) return true;
|
if(length == 0) return true;
|
||||||
|
|
||||||
if(remaining == NULL || *remaining < length)
|
if(*remaining < length)
|
||||||
{
|
{
|
||||||
TRACE("Dump hardware %s length %u exceeds remaining payload %u", field_name, length,
|
TRACE("Dump hardware %s length %u exceeds remaining payload %u", field_name, length,
|
||||||
remaining == NULL ? 0 : *remaining);
|
remaining == NULL ? 0 : *remaining);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *buffer = (uint8_t *)malloc((size_t)length + 1);
|
uint8_t *buffer = malloc(length);
|
||||||
|
|
||||||
if(buffer == NULL)
|
if(buffer == NULL)
|
||||||
{
|
{
|
||||||
@@ -81,7 +81,7 @@ static bool read_dump_string(FILE *stream, const char *field_name, uint32_t leng
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes_read = fread(buffer, 1, length, stream);
|
const size_t bytes_read = fread(buffer, 1, length, stream);
|
||||||
|
|
||||||
if(bytes_read != length)
|
if(bytes_read != length)
|
||||||
{
|
{
|
||||||
@@ -90,7 +90,6 @@ static bool read_dump_string(FILE *stream, const char *field_name, uint32_t leng
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer[length] = 0;
|
|
||||||
*remaining -= length;
|
*remaining -= length;
|
||||||
*destination = buffer;
|
*destination = buffer;
|
||||||
|
|
||||||
@@ -125,7 +124,7 @@ void process_dumphw_block(aaruformat_context *ctx, const IndexEntry *entry)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fseek(ctx->imageStream, (long)entry->offset, SEEK_SET) < 0 || ftell(ctx->imageStream) != entry->offset)
|
if(fseek(ctx->imageStream, entry->offset, SEEK_SET) < 0 || ftell(ctx->imageStream) != entry->offset)
|
||||||
{
|
{
|
||||||
FATAL("Could not seek to %" PRIu64 " as indicated by index entry...", entry->offset);
|
FATAL("Could not seek to %" PRIu64 " as indicated by index entry...", entry->offset);
|
||||||
reset_dump_hardware_context(ctx);
|
reset_dump_hardware_context(ctx);
|
||||||
@@ -166,7 +165,7 @@ void process_dumphw_block(aaruformat_context *ctx, const IndexEntry *entry)
|
|||||||
|
|
||||||
if(payload_length > 0)
|
if(payload_length > 0)
|
||||||
{
|
{
|
||||||
uint8_t *payload = (uint8_t *)malloc(payload_length);
|
uint8_t *payload = malloc(payload_length);
|
||||||
|
|
||||||
if(payload == NULL)
|
if(payload == NULL)
|
||||||
{
|
{
|
||||||
@@ -230,8 +229,7 @@ void process_dumphw_block(aaruformat_context *ctx, const IndexEntry *entry)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DumpHardwareEntriesWithData *entries =
|
DumpHardwareEntriesWithData *entries = calloc(header.entries, sizeof(DumpHardwareEntriesWithData));
|
||||||
(DumpHardwareEntriesWithData *)calloc(header.entries, sizeof(DumpHardwareEntriesWithData));
|
|
||||||
|
|
||||||
if(entries == NULL)
|
if(entries == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1645,6 +1645,8 @@ static void write_sector_subchannel(const aaruformat_context *ctx)
|
|||||||
else
|
else
|
||||||
subchannel_block.cmpCrc64 = aaruf_crc64_data(buffer, subchannel_block.cmpLength);
|
subchannel_block.cmpCrc64 = aaruf_crc64_data(buffer, subchannel_block.cmpLength);
|
||||||
|
|
||||||
|
if(subchannel_block.compression != None) subchannel_block.cmpLength += LZMA_PROPERTIES_LENGTH;
|
||||||
|
|
||||||
// Write header
|
// Write header
|
||||||
if(fwrite(&subchannel_block, sizeof(BlockHeader), 1, ctx->imageStream) == 1)
|
if(fwrite(&subchannel_block, sizeof(BlockHeader), 1, ctx->imageStream) == 1)
|
||||||
{
|
{
|
||||||
@@ -3456,7 +3458,7 @@ static void write_dumphw_block(aaruformat_context *ctx)
|
|||||||
if(buffer == NULL) return;
|
if(buffer == NULL) return;
|
||||||
|
|
||||||
// Start to iterate and copy the data
|
// Start to iterate and copy the data
|
||||||
size_t offset = 0;
|
size_t offset = sizeof(DumpHardwareHeader);
|
||||||
for(int i = 0; i < ctx->dump_hardware_header.entries; i++)
|
for(int i = 0; i < ctx->dump_hardware_header.entries; i++)
|
||||||
{
|
{
|
||||||
size_t entry_size = sizeof(DumpHardwareEntry) +
|
size_t entry_size = sizeof(DumpHardwareEntry) +
|
||||||
|
|||||||
27
src/dump.c
27
src/dump.c
@@ -249,7 +249,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_get_dumphw(void *context, uint8_t *buffer, s
|
|||||||
*length = required_length;
|
*length = required_length;
|
||||||
|
|
||||||
// Start to iterate and copy the data
|
// Start to iterate and copy the data
|
||||||
size_t offset = 0;
|
size_t offset = sizeof(DumpHardwareHeader);
|
||||||
for(uint32_t i = 0; i < ctx->dump_hardware_header.entries; i++)
|
for(uint32_t i = 0; i < ctx->dump_hardware_header.entries; i++)
|
||||||
{
|
{
|
||||||
size_t entry_size = sizeof(DumpHardwareEntry);
|
size_t entry_size = sizeof(DumpHardwareEntry);
|
||||||
@@ -620,17 +620,20 @@ AARU_EXPORT int32_t AARU_CALL aaruf_set_dumphw(void *context, uint8_t *data, siz
|
|||||||
|
|
||||||
size_t pos = sizeof(DumpHardwareHeader);
|
size_t pos = sizeof(DumpHardwareHeader);
|
||||||
|
|
||||||
#define COPY_STRING_FIELD(field) \
|
#define COPY_STRING_FIELD(field) \
|
||||||
do { \
|
do { \
|
||||||
const size_t field##_length = copy[e].entry.field##Length; \
|
const size_t field##_length = copy[e].entry.field##Length; \
|
||||||
if(field##_length > 0) \
|
if(field##_length > 0) \
|
||||||
{ \
|
{ \
|
||||||
if(field##_length > length - pos) goto invalid_data; \
|
if(field##_length > length - pos) goto invalid_data; \
|
||||||
copy[e].field = (uint8_t *)calloc(1, field##_length + 1); \
|
/* Allocate only field##_length bytes, since input is NUL-terminated */ \
|
||||||
if(copy[e].field == NULL) goto free_copy_and_error; \
|
copy[e].field = (uint8_t *)calloc(1, field##_length); \
|
||||||
memcpy(copy[e].field, data + pos, field##_length); \
|
if(copy[e].field == NULL) goto free_copy_and_error; \
|
||||||
pos += field##_length; \
|
memcpy(copy[e].field, data + pos, field##_length); \
|
||||||
} \
|
/* Ensure NUL-termination in case input is malformed */ \
|
||||||
|
copy[e].field[field##_length - 1] = '\0'; \
|
||||||
|
pos += field##_length; \
|
||||||
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
for(uint32_t e = 0; e < header.entries; e++)
|
for(uint32_t e = 0; e < header.entries; e++)
|
||||||
|
|||||||
58
src/write.c
58
src/write.c
@@ -150,19 +150,24 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector(void *context, uint64_t sector_
|
|||||||
{
|
{
|
||||||
if(sector_address <= ctx->last_written_block)
|
if(sector_address <= ctx->last_written_block)
|
||||||
{
|
{
|
||||||
TRACE("Rewinded");
|
if(sector_address == 0 && !ctx->block_zero_written)
|
||||||
ctx->rewinded = true;
|
ctx->block_zero_written = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TRACE("Rewinded");
|
||||||
|
ctx->rewinded = true;
|
||||||
|
|
||||||
// Disable MD5 calculation
|
// Disable MD5 calculation
|
||||||
if(ctx->calculating_md5) ctx->calculating_md5 = false;
|
if(ctx->calculating_md5) ctx->calculating_md5 = false;
|
||||||
// Disable SHA1 calculation
|
// Disable SHA1 calculation
|
||||||
if(ctx->calculating_sha1) ctx->calculating_sha1 = false;
|
if(ctx->calculating_sha1) ctx->calculating_sha1 = false;
|
||||||
// Disable SHA256 calculation
|
// Disable SHA256 calculation
|
||||||
if(ctx->calculating_sha256) ctx->calculating_sha256 = false;
|
if(ctx->calculating_sha256) ctx->calculating_sha256 = false;
|
||||||
// Disable SpamSum calculation
|
// Disable SpamSum calculation
|
||||||
if(ctx->calculating_spamsum) ctx->calculating_spamsum = false;
|
if(ctx->calculating_spamsum) ctx->calculating_spamsum = false;
|
||||||
// Disable BLAKE3 calculation
|
// Disable BLAKE3 calculation
|
||||||
if(ctx->calculating_blake3) ctx->calculating_blake3 = false;
|
if(ctx->calculating_blake3) ctx->calculating_blake3 = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ctx->last_written_block = sector_address;
|
ctx->last_written_block = sector_address;
|
||||||
@@ -642,19 +647,24 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector_long(void *context, uint64_t se
|
|||||||
{
|
{
|
||||||
if(sector_address <= ctx->last_written_block)
|
if(sector_address <= ctx->last_written_block)
|
||||||
{
|
{
|
||||||
TRACE("Rewinded");
|
if(sector_address == 0 && !ctx->block_zero_written)
|
||||||
ctx->rewinded = true;
|
ctx->block_zero_written = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TRACE("Rewinded");
|
||||||
|
ctx->rewinded = true;
|
||||||
|
|
||||||
// Disable MD5 calculation
|
// Disable MD5 calculation
|
||||||
if(ctx->calculating_md5) ctx->calculating_md5 = false;
|
if(ctx->calculating_md5) ctx->calculating_md5 = false;
|
||||||
// Disable SHA1 calculation
|
// Disable SHA1 calculation
|
||||||
if(ctx->calculating_sha1) ctx->calculating_sha1 = false;
|
if(ctx->calculating_sha1) ctx->calculating_sha1 = false;
|
||||||
// Disable SHA256 calculation
|
// Disable SHA256 calculation
|
||||||
if(ctx->calculating_sha256) ctx->calculating_sha256 = false;
|
if(ctx->calculating_sha256) ctx->calculating_sha256 = false;
|
||||||
// Disable SpamSum calculation
|
// Disable SpamSum calculation
|
||||||
if(ctx->calculating_spamsum) ctx->calculating_spamsum = false;
|
if(ctx->calculating_spamsum) ctx->calculating_spamsum = false;
|
||||||
// Disable BLAKE3 calculation
|
// Disable BLAKE3 calculation
|
||||||
if(ctx->calculating_blake3) ctx->calculating_blake3 = false;
|
if(ctx->calculating_blake3) ctx->calculating_blake3 = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ctx->last_written_block = sector_address;
|
ctx->last_written_block = sector_address;
|
||||||
|
|||||||
@@ -89,13 +89,7 @@ int info(const char *path)
|
|||||||
printf("Library version: %d.%d\n", ctx->library_major_version, ctx->library_minor_version);
|
printf("Library version: %d.%d\n", ctx->library_major_version, ctx->library_minor_version);
|
||||||
printf("AaruFormat header:\n");
|
printf("AaruFormat header:\n");
|
||||||
printf("\tIdentifier: %8.8s\n", (char *)&ctx->header.identifier);
|
printf("\tIdentifier: %8.8s\n", (char *)&ctx->header.identifier);
|
||||||
|
printf("\tApplication: %s\n", ctx->header.application);
|
||||||
strBuffer = malloc(65);
|
|
||||||
memset(strBuffer, 0, 65);
|
|
||||||
ucnv_convert(NULL, "UTF-16LE", strBuffer, 64, ctx->header.application, 64, &u_error_code);
|
|
||||||
if(u_error_code == U_ZERO_ERROR) printf("\tApplication: %s\n", strBuffer);
|
|
||||||
free(strBuffer);
|
|
||||||
|
|
||||||
printf("\tApplication version: %d.%d\n", ctx->header.applicationMajorVersion, ctx->header.applicationMinorVersion);
|
printf("\tApplication version: %d.%d\n", ctx->header.applicationMajorVersion, ctx->header.applicationMinorVersion);
|
||||||
printf("\tImage format version: %d.%d\n", ctx->header.imageMajorVersion, ctx->header.imageMinorVersion);
|
printf("\tImage format version: %d.%d\n", ctx->header.imageMajorVersion, ctx->header.imageMinorVersion);
|
||||||
printf("\tMedia type: %u (%s)\n", ctx->header.mediaType, media_type_to_string(ctx->header.mediaType));
|
printf("\tMedia type: %u (%s)\n", ctx->header.mediaType, media_type_to_string(ctx->header.mediaType));
|
||||||
|
|||||||
Reference in New Issue
Block a user