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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue