I think the title is pretty clear.
I noticed that .strtab and .shstrtab have the same type and flags (SHT_STRTAB and SHF_STRINGS).
Idx Name Size VMA LMA File off Algn EntSize Info Type Flags 400. .strtab 9933 0 0 af2e 0 1 0 3 32 401. .shstrtab 1472 0 0 d5fb 0 1 0 3 32
It's true that in the ELF header the last item tells me which one is .shstrtab
--Index of the section header string table: [401]
I have a loop that goes through all sections, copying and relocating and whatever it's needed.
for ( i = 0; i < header->e_shnum; i++){ switch (section_header[i].sh_type ){ [ other cases ... ] case SHT_STRTAB: if ( i != header->e_shstrndx ){ strtab = section_header[i]; } break; } }
But this only works when there are max 2 SHT_STRTABs. If someone could confirm that there are
only 2 SHT_STRTABs or that the .shstrtab is always the last one I could just avoid iterating the last
section [header->e_shnum - 1] and save the other SHT_STRTAB I find as .strtab.
case SHT_STRTAB: strtab = section_header[i]; break;
Thank you.