forked from len0rd/rockbox
sbtools: add helper to determine if a file is a valid ELF image
Change-Id: Ie0e9c05569ca9b02fd36f31fd7323f02b14e1b60
This commit is contained in:
parent
76446dda45
commit
e4c9eaa7e8
2 changed files with 15 additions and 0 deletions
|
@ -551,6 +551,19 @@ void elf_write_file(struct elf_params_t *params, elf_write_fn_t write,
|
||||||
free(strtbl_content);
|
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,
|
bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read,
|
||||||
elf_printf_fn_t printf, void *user)
|
elf_printf_fn_t printf, void *user)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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);
|
int elf_get_nr_sections(struct elf_params_t *params);
|
||||||
void elf_release(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
|
/* standard implementation of read/write/printf functions
|
||||||
* with user being a FILE* pointer */
|
* with user being a FILE* pointer */
|
||||||
void elf_std_printf(void *user, bool error, const char *fmt, ...);
|
void elf_std_printf(void *user, bool error, const char *fmt, ...);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue