summaryrefslogtreecommitdiffstats
path: root/utils/imxtools
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-08-04 15:03:29 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-08-06 21:24:38 +0200
commite4c9eaa7e8f247eb0623350e5d15d542ca665e17 (patch)
tree2d169448038eb4767a730c5cb8bb38dd1b2f7ec6 /utils/imxtools
parent76446dda459e2696d2a772d77ab4ed585901de13 (diff)
downloadrockbox-e4c9eaa7e8f247eb0623350e5d15d542ca665e17.tar.gz
rockbox-e4c9eaa7e8f247eb0623350e5d15d542ca665e17.tar.bz2
rockbox-e4c9eaa7e8f247eb0623350e5d15d542ca665e17.zip
sbtools: add helper to determine if a file is a valid ELF image
Change-Id: Ie0e9c05569ca9b02fd36f31fd7323f02b14e1b60
Diffstat (limited to 'utils/imxtools')
-rw-r--r--utils/imxtools/sbtools/elf.c13
-rw-r--r--utils/imxtools/sbtools/elf.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/utils/imxtools/sbtools/elf.c b/utils/imxtools/sbtools/elf.c
index 226057bc19..a0b249570a 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)
{
diff --git a/utils/imxtools/sbtools/elf.h b/utils/imxtools/sbtools/elf.h
index 403bab0712..cabe764e45 100644
--- a/utils/imxtools/sbtools/elf.h
+++ b/utils/imxtools/sbtools/elf.h
@@ -94,6 +94,8 @@ bool elf_get_start_addr(struct elf_params_t *params, uint32_t *addr);
int elf_get_nr_sections(struct elf_params_t *params);
void elf_release(struct elf_params_t *params);
+bool elf_guess(elf_read_fn_t read, void *user);
+
/* standard implementation of read/write/printf functions
* with user being a FILE* pointer */
void elf_std_printf(void *user, bool error, const char *fmt, ...);