diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-07-09 00:21:44 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-07-09 00:21:44 +0200 |
commit | 4d31db6c00833898828c90d100c7dde4a016e233 (patch) | |
tree | 0125f54fd5ad19c9baf733b6d60d665d968c0f18 | |
parent | 439ad448bdaf638a305f5c9cb966a96d6e4489ac (diff) | |
download | bxgen-4d31db6c00833898828c90d100c7dde4a016e233.zip |
Update symbol table decoding
-rwxr-xr-x | bxgen.c | 89 |
1 files changed, 64 insertions, 25 deletions
@@ -752,7 +752,7 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data memcpy(buf0_, l->name, l->name_size); printf("\nReading `%s` library...\n\n", buf0_); - i64 n = 0; + i64 n = 0, current_offset = 0; // Read AR // @@ -760,6 +760,7 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data u8 magic[8]; n = io_read(f, sizeof magic, magic, io_user_data); if (n == 0) continue; + current_offset += n; assert(magic[0] == '!'); assert(magic[1] == '<'); @@ -770,10 +771,12 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data assert(magic[6] == '>'); assert(magic[7] == '\n'); - u32 static offsets[10000] = { 0 }; - i64 file_count = 1; + u32 static offsets[10000] = { 0 }; + c8 static symbols[10000][256] = { 0 }; + b8 static found[10000] = { 0 }; + i64 num_symbols = 1; - for (i64 k = 0;;) { + for (;;) { c8 id[17] = { 0 }; c8 timestamp[13] = { 0 }; c8 owner[7] = { 0 }; @@ -782,13 +785,15 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data c8 size[11] = { 0 }; c8 end[2] = { 0 }; - n = io_read(f, (sizeof id) - 1, id, io_user_data); if (n == 0) break; - n = io_read(f, (sizeof timestamp) - 1, timestamp, io_user_data); if (n == 0) break; - n = io_read(f, (sizeof owner) - 1, owner, io_user_data); if (n == 0) break; - n = io_read(f, (sizeof group) - 1, group, io_user_data); if (n == 0) break; - n = io_read(f, (sizeof mode) - 1, mode, io_user_data); if (n == 0) break; - n = io_read(f, (sizeof size) - 1, size, io_user_data); if (n == 0) break; - n = io_read(f, sizeof end, end, io_user_data); if (n == 0) break; + i64 file_offset = current_offset; + + n = io_read(f, (sizeof id) - 1, id, io_user_data); if (n == 0) break; current_offset += n; + n = io_read(f, (sizeof timestamp) - 1, timestamp, io_user_data); if (n == 0) break; current_offset += n; + n = io_read(f, (sizeof owner) - 1, owner, io_user_data); if (n == 0) break; current_offset += n; + n = io_read(f, (sizeof group) - 1, group, io_user_data); if (n == 0) break; current_offset += n; + n = io_read(f, (sizeof mode) - 1, mode, io_user_data); if (n == 0) break; current_offset += n; + n = io_read(f, (sizeof size) - 1, size, io_user_data); if (n == 0) break; current_offset += n; + n = io_read(f, sizeof end, end, io_user_data); if (n == 0) break; current_offset += n; assert(end[0] == '\x60'); assert(end[1] == '\x0a'); @@ -799,19 +804,21 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data u32 count_be; n = io_read(f, 4, &count_be, io_user_data); if (n == 0) break; + current_offset += n; - file_count = + num_symbols = (( count_be & 0xffu) << 24) | (((count_be >> 8) & 0xffu) << 16) | (((count_be >> 16) & 0xffu) << 8) | ((count_be >> 24) & 0xffu); - printf("Symbol table - %lld symbols.\n\n", file_count); - assert(file_count <= (i64) (sizeof offsets / sizeof *offsets)); + printf("Symbol table - %lld symbols.\n\n", num_symbols); + assert(num_symbols <= (i64) (sizeof offsets / sizeof *offsets)); - for (u32 j = 0; j < file_count; ++j) { + for (u32 j = 0; j < num_symbols; ++j) { u32 offset_be; n = io_read(f, 4, &offset_be, io_user_data); if (n == 0) break; + current_offset += n; offsets[j] = (( offset_be & 0xffu) << 24) | @@ -823,25 +830,27 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data i64 byte_count = 0; - for (u32 j = 0; j < file_count; ++j) { - for (;;) { + for (u32 j = 0; j < num_symbols; ++j) { + i64 symbol_size = 0; + for (;; ++symbol_size) { c8 c; n = io_read(f, 1, &c, io_user_data); if (n == 0) break; + current_offset += n; ++byte_count; if (c == '\0') break; - printf("%c", c); + assert(symbol_size < 256); + if (symbol_size < 256) + symbols[j][symbol_size] = c; } if (n == 0) break; - printf(" "); } if (n == 0) break; - printf("\n"); - if ((byte_count & 1) == 1) { // align n = io_seek(f, 1, IO_SEEK_CURSOR, io_user_data); if (n == 0) break; + current_offset += n; } } else if (strcmp(id, "// ") == 0) { // String table @@ -854,12 +863,30 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data ++byte_count; // align n = io_seek(f, byte_count, IO_SEEK_CURSOR, io_user_data); if (n == 0) break; + current_offset += n; } else { if (strstr(id, "/") != NULL) *strstr(id, "/") = '\0'; if (strstr(size, " ") != NULL) *strstr(size, " ") = '\0'; - printf("%08x: %-16s - %5s bytes\n", offsets[k], id, size); + + b8 symbol_found = 0; + for (i64 symbol_index = 0; symbol_index < num_symbols; ++symbol_index) + if (offsets[symbol_index] == file_offset) { + printf("%08x: %-16s - %-50s- %5s bytes\n", + (u32) file_offset, + id, + symbols[symbol_index], + size); + found[symbol_index] = 1; + symbol_found = 1; + } + if (!symbol_found) + printf("%08x: %-16s - %-50s- %5s bytes\n", + (u32) file_offset, + id, + "<SYMBOLS NOT FOUND>", + size); // Skip file // @@ -869,12 +896,24 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data ++byte_count; // align n = io_seek(f, byte_count, IO_SEEK_CURSOR, io_user_data); if (n == 0) break; - - if (++k == file_count) - break; + current_offset += n; } } + b8 all_found = 1; + + for (i64 symbol_index = 0; symbol_index < num_symbols; ++symbol_index) + if (!found[symbol_index]) { + printf(" ? : %-16s - %-50s\n", + "<FILE NOT FOUND>", + symbols[symbol_index]); + all_found = 0; + } + + printf("\n"); + if (all_found) + printf("All files found!\n"); + io_close(f, io_user_data); } } |