elf_errorstatus elf_init(struct elf_binary *elf, const char *image_input, size_t size)
{
ELF_HANDLE_DECL(elf_shdr) shdr;
- uint64_t i, count, section, offset, link;
+ unsigned i, count, section, link;
+ uint64_t offset;
if ( !elf_is_elfbinary(image_input, size) )
{
continue;
link = elf_uval(elf, shdr, sh_link);
- if ( link == SHN_UNDEF || link >= elf_shdr_count(elf) )
+ if ( link == SHN_UNDEF || link >= count )
/* out-of-bounds link value. */
break;
void elf_parse_binary(struct elf_binary *elf)
{
ELF_HANDLE_DECL(elf_phdr) phdr;
- uint64_t low = -1;
- uint64_t high = 0;
- uint64_t i, count, paddr, memsz;
+ uint64_t low = -1, high = 0, paddr, memsz;
+ unsigned i, count;
- count = elf_uval(elf, elf->ehdr, e_phnum);
+ count = elf_phdr_count(elf);
for ( i = 0; i < count; i++ )
{
phdr = elf_phdr_by_index(elf, i);
elf_errorstatus elf_load_binary(struct elf_binary *elf)
{
ELF_HANDLE_DECL(elf_phdr) phdr;
- uint64_t i, count, paddr, offset, filesz, memsz;
+ uint64_t paddr, offset, filesz, memsz;
+ unsigned i, count;
elf_ptrval dest;
/*
* Let bizarre ELFs write the output image up to twice; this
*/
uint64_t remain_allow_copy = (uint64_t)elf->dest_size * 2;
- count = elf_uval(elf, elf->ehdr, e_phnum);
+ count = elf_phdr_count(elf);
for ( i = 0; i < count; i++ )
{
phdr = elf_phdr_by_index(elf, i);
remain_allow_copy -= memsz;
elf_msg(elf,
- "ELF: phdr %" PRIu64 " at %#"ELF_PRPTRVAL" -> %#"ELF_PRPTRVAL"\n",
+ "ELF: phdr %u at %#"ELF_PRPTRVAL" -> %#"ELF_PRPTRVAL"\n",
i, dest, (elf_ptrval)(dest + filesz));
if ( elf_load_image(elf, dest, ELF_IMAGE_BASE(elf) + offset, filesz, memsz) != 0 )
return -1;
ELF_HANDLE_DECL(elf_shdr) elf_shdr_by_name(struct elf_binary *elf, const char *name)
{
- uint64_t count = elf_shdr_count(elf);
+ unsigned i, count = elf_shdr_count(elf);
ELF_HANDLE_DECL(elf_shdr) shdr;
const char *sname;
- unsigned i;
for ( i = 1; i < count; i++ )
{
ELF_HANDLE_DECL(elf_shdr) elf_shdr_by_index(struct elf_binary *elf, unsigned index)
{
- uint64_t count = elf_shdr_count(elf);
+ unsigned count = elf_shdr_count(elf);
elf_ptrval ptr;
if ( index >= count )
ELF_HANDLE_DECL(elf_phdr) elf_phdr_by_index(struct elf_binary *elf, unsigned index)
{
- uint64_t count = elf_uval(elf, elf->ehdr, e_phnum);
+ unsigned count = elf_phdr_count(elf);
elf_ptrval ptr;
if ( index >= count )