summaryrefslogtreecommitdiff
path: root/bxgen.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-07-09 05:34:11 +0200
committerMitya Selivanov <automainint@guattari.tech>2024-07-09 05:34:11 +0200
commit4547b8a4d881ebc65dfd8c6d7ddb9213a488d0dd (patch)
tree58e31ac8eb99c37af8aa9f7a82c4435c5299b11f /bxgen.c
parentb25e2ea8093067faa6e9bbc094e4a6a042c97cd1 (diff)
downloadbxgen-4547b8a4d881ebc65dfd8c6d7ddb9213a488d0dd.zip
Update ELF sections decoding
Diffstat (limited to 'bxgen.c')
-rwxr-xr-xbxgen.c111
1 files changed, 63 insertions, 48 deletions
diff --git a/bxgen.c b/bxgen.c
index a5ddbe9..cdade85 100755
--- a/bxgen.c
+++ b/bxgen.c
@@ -951,58 +951,60 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data
byte_count -= n; \
} while (0)
- u16 type;
- u16 machine;
- u32 ver;
- u64 entry;
- u64 program_header_offset;
- u64 section_header_offset;
- u32 flags;
- u16 elf_header_size;
- u16 program_header_size;
- u16 program_header_count;
- u16 section_header_size;
- u16 section_header_count;
+ i64 section_offset;
+ u16 section_count;
u16 strings_index;
- READ(type);
- READ(machine);
- READ(ver);
- READ(entry);
- READ(program_header_offset);
- READ(section_header_offset);
- READ(flags);
- READ(elf_header_size);
- READ(program_header_size);
- READ(program_header_count);
- READ(section_header_size);
- READ(section_header_count);
- READ(strings_index);
-
- assert(type == 1); // relocatable
- assert(machine == elf_machine);
- assert(ver == 1); // current version
- assert(entry == 0);
- assert(program_header_offset == 0);
- assert(flags == 0);
- assert(elf_header_size == 64);
- assert(program_header_size == 0);
- assert(program_header_count == 0);
- assert(section_header_size == 64);
-
- // TODO read string table
+ // ELF header
+ //
+ {
+ u16 type;
+ u16 machine;
+ u32 ver;
+ u64 entry;
+ u64 program_header_offset;
+ u64 section_header_offset;
+ u32 flags;
+ u16 elf_header_size;
+ u16 program_header_size;
+ u16 program_header_count;
+ u16 section_header_size;
- i64 section_offset = section_header_offset - (current_offset - begin_offset);
+ READ(type);
+ READ(machine);
+ READ(ver);
+ READ(entry);
+ READ(program_header_offset);
+ READ(section_header_offset);
+ READ(flags);
+ READ(elf_header_size);
+ READ(program_header_size);
+ READ(program_header_count);
+ READ(section_header_size);
+ READ(section_count);
+ READ(strings_index);
+
+ assert(type == 1); // relocatable
+ assert(machine == elf_machine);
+ assert(ver == 1); // current version
+ assert(entry == 0);
+ assert(program_header_offset == 0);
+ assert(flags == 0);
+ assert(elf_header_size == 64);
+ assert(program_header_size == 0);
+ assert(program_header_count == 0);
+ assert(section_header_size == 64);
+
+ section_offset = section_header_offset - (current_offset - begin_offset);
+ }
- printf(" ^ Section header offset: %lld (+%lld)\n", section_header_offset, section_offset);
- printf(" ^ Section headers: %d\n", section_header_count);
- printf(" ^ Strings index: %d\n", strings_index);
+ // TODO read string table
io_seek(f, section_offset, IO_SEEK_CURSOR, io_user_data);
byte_count -= section_offset;
current_offset += section_offset;
- for (u16 i = 0; i < section_header_count; ++i) {
+ for (u16 i = 0; i < section_count; ++i) {
u32 name;
u32 type;
u64 flags;
@@ -1025,8 +1027,19 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data
READ(addralign);
READ(entsize);
+ printf("[%2d] %-3d", i, name);
+
+ if ((flags & 4) == 4)
+ printf(" Executable");
+
+ if (type == 2)
+ printf(" Symbols");
+
if (type == 3) {
- printf("\n String table - %lld bytes\n ", size);
+ printf(" String table");
+ if (i == strings_index)
+ printf(" - section names");
+ printf("\n\n ");
i64 prev_offset = current_offset;
io_seek(f, begin_offset + offset, IO_SEEK_BEGIN, io_user_data);
@@ -1035,20 +1048,22 @@ void unit_write(Pool *pool, i64 unit, u16 target, i64 io_out, void *io_user_data
assert(size < sizeof buf);
n = io_read(f, size, buf, io_user_data); if (n == 0) break;
- for (u64 j = 0; j < size; ++j) {
+ for (u64 j = 1; j < size; ++j) {
+ if (buf[j - 1] == '\0')
+ printf("%-3lld : ", j);
if (buf[j] != '\0')
printf("%c", buf[j]);
- else if (j > 0 && buf[j - 1] == '\0')
+ else if (buf[j - 1] == '\0')
printf("<EMPTY>\n ");
else
printf("\n ");
}
- printf("\n");
-
io_seek(f, prev_offset, IO_SEEK_BEGIN, io_user_data);
current_offset = prev_offset;
}
+
+ printf("\n");
}
io_seek(f, byte_count, IO_SEEK_CURSOR, io_user_data);