From 2a26c1506192468be6c4cd06465bee861d87db51 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Mon, 27 Jan 2025 01:20:19 +0100 Subject: elf: simple elf-parser for dynamic symbols --- test/elf_parser.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/elf_parser.cc (limited to 'test/elf_parser.cc') diff --git a/test/elf_parser.cc b/test/elf_parser.cc new file mode 100644 index 0000000..6f16639 --- /dev/null +++ b/test/elf_parser.cc @@ -0,0 +1,59 @@ +#include "elf_parser.h" + +#include +#include + +#include + +#include "elf_parser/libtest-32.h" +#include "elf_parser/libtest-64.h" + +void dump_dynsyms(const unsigned char* bytes, size_t len) { + auto elf = elf::parse(bytes, len); + + elf->dynsyms([](const char* name, char type, char bind) { // NOLINT + const char* bind_str = ""; + switch (bind) { + case STB_GLOBAL: + bind_str = "GLOBAL"; + break; + case STB_LOCAL: + bind_str = "LOCAL"; + break; + case STB_WEAK: + bind_str = "WEAK"; + break; + default: + break; + } + + const char* type_str = ""; + switch (type) { + case STT_NOTYPE: + type_str = "NOTYPE"; + break; + case STT_FUNC: + type_str = "FUNC"; + break; + case STT_OBJECT: + type_str = "OBJECT"; + break; + case STT_SECTION: + type_str = "SECTION"; + break; + case STT_FILE: + type_str = "FILE"; + break; + default: + break; + } + + printf("syms type: %10s bind: %10s name: %s\n", type_str, bind_str, name); + return true; + }); +} + +int main() { + dump_dynsyms(libtest_32_so, libtest_32_so_len); + dump_dynsyms(libtest_64_so, libtest_64_so_len); +} -- cgit v1.2.3