Created
September 19, 2016 03:39
-
-
Save errzey/8c4b28d3e2f3a3a39e8bf00f8d36d744 to your computer and use it in GitHub Desktop.
ELF section / symbol crawler in 20 lines of code using liblz_elf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <liblz.h> | |
#include <liblz/lzapi.h> | |
#include <liblz/lz_elf.h> | |
static int __print_symbol(lz_elf_symbol * symbol, void * args) { | |
printf(" Symbol name: %s\n", lz_elf_symbol_get_name(symbol)); | |
return 0; | |
} | |
static int __print_section(lz_elf_section * section, void * arg) { | |
printf("Section name : %s\nSections count: %zu\n", lz_elf_section_get_name(section), lz_elf_section_get_nsyms(section)); | |
return lz_elf_section_symbols_foreach(elf_z, section, __print_symbol, arg); | |
} | |
int main(int argc, char ** argv) { | |
lz_elf * elf; | |
lz_elf_sections * sections; | |
lz_assert(lz_elf_init() == 0); | |
lz_assert((elf = lz_elf_fopen(argv[1])) != NULL); | |
lz_assert((sections = lz_elf_get_sections(elf)) != NULL); | |
return lz_elf_section_foreach(sections, __print_section, elf); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment