diff options
| author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-08-04 15:03:29 +0200 |
|---|---|---|
| committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-08-06 21:24:38 +0200 |
| commit | e4c9eaa7e8f247eb0623350e5d15d542ca665e17 (patch) | |
| tree | 2d169448038eb4767a730c5cb8bb38dd1b2f7ec6 /utils/imxtools/sbtools/elf.c | |
| parent | 76446dda459e2696d2a772d77ab4ed585901de13 (diff) | |
| download | rockbox-e4c9eaa7e8f247eb0623350e5d15d542ca665e17.zip rockbox-e4c9eaa7e8f247eb0623350e5d15d542ca665e17.tar.gz rockbox-e4c9eaa7e8f247eb0623350e5d15d542ca665e17.tar.bz2 rockbox-e4c9eaa7e8f247eb0623350e5d15d542ca665e17.tar.xz | |
sbtools: add helper to determine if a file is a valid ELF image
Change-Id: Ie0e9c05569ca9b02fd36f31fd7323f02b14e1b60
Diffstat (limited to 'utils/imxtools/sbtools/elf.c')
| -rw-r--r-- | utils/imxtools/sbtools/elf.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/utils/imxtools/sbtools/elf.c b/utils/imxtools/sbtools/elf.c index 226057b..a0b2495 100644 --- a/utils/imxtools/sbtools/elf.c +++ b/utils/imxtools/sbtools/elf.c @@ -551,6 +551,19 @@ void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, free(strtbl_content); } +bool elf_guess(elf_read_fn_t read, void *user) +{ + /* read header */ + Elf32_Ehdr ehdr; + if(!read(user, 0, &ehdr, sizeof(ehdr))) + return false; + /* basic checks */ + return ehdr.e_ident[EI_MAG0] == ELFMAG0 && ehdr.e_ident[EI_MAG1] == ELFMAG1 && + ehdr.e_ident[EI_MAG2] == ELFMAG2 && ehdr.e_ident[EI_MAG3] == ELFMAG3 && + ehdr.e_ehsize == sizeof(ehdr) && ehdr.e_phentsize == sizeof(Elf32_Phdr) && + ehdr.e_shentsize == sizeof(Elf32_Shdr); +} + bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf, void *user) { |