mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Compare commits
7 Commits
v1.0.0-alp
...
v1.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
10be636fd2
|
|||
|
b4da7d9fb2
|
|||
|
f9eec04d08
|
|||
|
94e44ef304
|
|||
|
d6ea7db911
|
|||
|
0326c81a91
|
|||
|
542cc58eba
|
@@ -292,6 +292,7 @@ typedef struct aaruformat_context
|
||||
bool is_writing; ///< True if context opened/created for writing.
|
||||
bool rewinded; ///< True if stream has been rewound after open (write path).
|
||||
bool writing_long; ///< True if writing long sectors
|
||||
bool block_zero_written; ///< True if block zero has been written (writing path).
|
||||
|
||||
/* Options */
|
||||
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">
|
||||
<metadata>
|
||||
<id>libaaruformat</id>
|
||||
<version>1.0.0-alpha.5</version>
|
||||
<version>1.0.0-alpha.7</version>
|
||||
<description>Library for management of AaruFormat images.</description>
|
||||
<authors>claunia</authors>
|
||||
<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));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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,
|
||||
remaining == NULL ? 0 : *remaining);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t *buffer = (uint8_t *)malloc((size_t)length + 1);
|
||||
uint8_t *buffer = malloc(length);
|
||||
|
||||
if(buffer == NULL)
|
||||
{
|
||||
@@ -81,7 +81,7 @@ static bool read_dump_string(FILE *stream, const char *field_name, uint32_t leng
|
||||
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)
|
||||
{
|
||||
@@ -90,7 +90,6 @@ static bool read_dump_string(FILE *stream, const char *field_name, uint32_t leng
|
||||
return false;
|
||||
}
|
||||
|
||||
buffer[length] = 0;
|
||||
*remaining -= length;
|
||||
*destination = buffer;
|
||||
|
||||
@@ -125,7 +124,7 @@ void process_dumphw_block(aaruformat_context *ctx, const IndexEntry *entry)
|
||||
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);
|
||||
reset_dump_hardware_context(ctx);
|
||||
@@ -166,7 +165,7 @@ void process_dumphw_block(aaruformat_context *ctx, const IndexEntry *entry)
|
||||
|
||||
if(payload_length > 0)
|
||||
{
|
||||
uint8_t *payload = (uint8_t *)malloc(payload_length);
|
||||
uint8_t *payload = malloc(payload_length);
|
||||
|
||||
if(payload == NULL)
|
||||
{
|
||||
@@ -230,8 +229,7 @@ void process_dumphw_block(aaruformat_context *ctx, const IndexEntry *entry)
|
||||
return;
|
||||
}
|
||||
|
||||
DumpHardwareEntriesWithData *entries =
|
||||
(DumpHardwareEntriesWithData *)calloc(header.entries, sizeof(DumpHardwareEntriesWithData));
|
||||
DumpHardwareEntriesWithData *entries = calloc(header.entries, sizeof(DumpHardwareEntriesWithData));
|
||||
|
||||
if(entries == NULL)
|
||||
{
|
||||
|
||||
@@ -3458,7 +3458,7 @@ static void write_dumphw_block(aaruformat_context *ctx)
|
||||
if(buffer == NULL) return;
|
||||
|
||||
// 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++)
|
||||
{
|
||||
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;
|
||||
|
||||
// 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++)
|
||||
{
|
||||
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);
|
||||
|
||||
#define COPY_STRING_FIELD(field) \
|
||||
do { \
|
||||
const size_t field##_length = copy[e].entry.field##Length; \
|
||||
if(field##_length > 0) \
|
||||
{ \
|
||||
if(field##_length > length - pos) goto invalid_data; \
|
||||
copy[e].field = (uint8_t *)calloc(1, field##_length + 1); \
|
||||
if(copy[e].field == NULL) goto free_copy_and_error; \
|
||||
memcpy(copy[e].field, data + pos, field##_length); \
|
||||
pos += field##_length; \
|
||||
} \
|
||||
#define COPY_STRING_FIELD(field) \
|
||||
do { \
|
||||
const size_t field##_length = copy[e].entry.field##Length; \
|
||||
if(field##_length > 0) \
|
||||
{ \
|
||||
if(field##_length > length - pos) goto invalid_data; \
|
||||
/* Allocate only field##_length bytes, since input is NUL-terminated */ \
|
||||
copy[e].field = (uint8_t *)calloc(1, field##_length); \
|
||||
if(copy[e].field == NULL) goto free_copy_and_error; \
|
||||
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)
|
||||
|
||||
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)
|
||||
{
|
||||
TRACE("Rewinded");
|
||||
ctx->rewinded = true;
|
||||
if(sector_address == 0 && !ctx->block_zero_written)
|
||||
ctx->block_zero_written = true;
|
||||
else
|
||||
{
|
||||
TRACE("Rewinded");
|
||||
ctx->rewinded = true;
|
||||
|
||||
// Disable MD5 calculation
|
||||
if(ctx->calculating_md5) ctx->calculating_md5 = false;
|
||||
// Disable SHA1 calculation
|
||||
if(ctx->calculating_sha1) ctx->calculating_sha1 = false;
|
||||
// Disable SHA256 calculation
|
||||
if(ctx->calculating_sha256) ctx->calculating_sha256 = false;
|
||||
// Disable SpamSum calculation
|
||||
if(ctx->calculating_spamsum) ctx->calculating_spamsum = false;
|
||||
// Disable BLAKE3 calculation
|
||||
if(ctx->calculating_blake3) ctx->calculating_blake3 = false;
|
||||
// Disable MD5 calculation
|
||||
if(ctx->calculating_md5) ctx->calculating_md5 = false;
|
||||
// Disable SHA1 calculation
|
||||
if(ctx->calculating_sha1) ctx->calculating_sha1 = false;
|
||||
// Disable SHA256 calculation
|
||||
if(ctx->calculating_sha256) ctx->calculating_sha256 = false;
|
||||
// Disable SpamSum calculation
|
||||
if(ctx->calculating_spamsum) ctx->calculating_spamsum = false;
|
||||
// Disable BLAKE3 calculation
|
||||
if(ctx->calculating_blake3) ctx->calculating_blake3 = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
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)
|
||||
{
|
||||
TRACE("Rewinded");
|
||||
ctx->rewinded = true;
|
||||
if(sector_address == 0 && !ctx->block_zero_written)
|
||||
ctx->block_zero_written = true;
|
||||
else
|
||||
{
|
||||
TRACE("Rewinded");
|
||||
ctx->rewinded = true;
|
||||
|
||||
// Disable MD5 calculation
|
||||
if(ctx->calculating_md5) ctx->calculating_md5 = false;
|
||||
// Disable SHA1 calculation
|
||||
if(ctx->calculating_sha1) ctx->calculating_sha1 = false;
|
||||
// Disable SHA256 calculation
|
||||
if(ctx->calculating_sha256) ctx->calculating_sha256 = false;
|
||||
// Disable SpamSum calculation
|
||||
if(ctx->calculating_spamsum) ctx->calculating_spamsum = false;
|
||||
// Disable BLAKE3 calculation
|
||||
if(ctx->calculating_blake3) ctx->calculating_blake3 = false;
|
||||
// Disable MD5 calculation
|
||||
if(ctx->calculating_md5) ctx->calculating_md5 = false;
|
||||
// Disable SHA1 calculation
|
||||
if(ctx->calculating_sha1) ctx->calculating_sha1 = false;
|
||||
// Disable SHA256 calculation
|
||||
if(ctx->calculating_sha256) ctx->calculating_sha256 = false;
|
||||
// Disable SpamSum calculation
|
||||
if(ctx->calculating_spamsum) ctx->calculating_spamsum = false;
|
||||
// Disable BLAKE3 calculation
|
||||
if(ctx->calculating_blake3) ctx->calculating_blake3 = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
ctx->last_written_block = sector_address;
|
||||
|
||||
Reference in New Issue
Block a user