I am supposed to fetch the field pc_begin and pc_range from the .eh_frame section of the elf file. The format of this section is described in here: https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA/ehframechpt.html
I have the starting address of the section with me:
for (int i = 0; i < ehdr->e_shnum; i++) {
if(strcmp((sh_strtab_p + shdrs[i].sh_name),".eh_frame") == 0){
size = shdrs[i].sh_size;
addr= shdrs[i].sh_addr;
}
}
This addr is in uint64_t type. Using this address as the starting point, I have been reading 4bytes of data to fetch the length field of CIE/FDE record and 8bytes to get the extended length field.
static uint64_t start = addr;
for(uint64_t start= addr;start < (addr+size);){
uint32_t initial_length= ReadFourBytes(start);
start += 4;
if (initial_length == 0xffffffff) {
initial_length =ReadEightBytes(start);
start += 8;
}
else if ( initial_length == 0){
printf("No CFI information\n");
exit(0);
}
else{
}
static uint64_t temp_addr= start;
uint32_t CIE_id = ReadFourBytes(start);
if (CIE_id == 0){
printf("CIE record\n");
start = start + initial_length;
continue;
}
else{
printf("Fde record\n");
start+=4;
uint64_t pc_begin= ReadEightBytes(start);
printf("PC_Begin %x", pc_begin);
start+=8;
uint64_t Size= ReadEightBytes(start) - Address;
printf(" %x\n",Size);
start = temp_addr + initial_length;
}
}
To keep proceeding and to read other fields, I need to increment my start variable. I know this isn't the proper code.
I have been working on this for quite sometime. Any kind of help would be appreciated and gladly accepted.
User contributions licensed under CC BY-SA 3.0