我正在写一个程序来模拟elfdump -ecps
目前,它打印出ELF头,程序头和节头正确,但我卡在符号表的最后几部分组成。
所期望的输出是在的格式:
Symbol Table Section: .dynsym
index value size type bind oth ver shndx name
[0] 0x00000000 0x00000000 NOTY LOCL D 0 UNDEF
[1] 0x00025c0c 0x00000000 FUNC GLOB D 2 UNDEF .udiv
[2] 0x00025e00 0x00000140 OBJT WEAK D 1 .bss _iob
[3] 0x00025b24 0x00000000 OBJT GLOB P 1 .got _GLOBAL_OFFSET_TABLE_
[4] 0x00013a44 0x0000001c FUNC GLOB D 1 .init _init
...
你能告诉我哪里有超视距,版本,shndx和名称被发现?
到目前为止,我打印出来有以下几点:
//for each entry in the symbol table
for(i=0; i<num_sym; i++)
{
//read the current symbol
fread(&mysym,sizeof(Elf32_Sym),1,fp);
idx=mysym.st_name;
//multiple lines to get formatting correct
//prints index in brackets right aligned
char buf[12];
sprintf(buf, "[%d]", i);
printf("%10s", buf);
//value
printf(" 0x%.8x", mysym.st_value);
//size
printf(" 0x%.8x", mysym.st_size);
//type
switch (ELF32_ST_TYPE(mysym.st_info)) {
case 0:
printf(" NOTY");
break;
case 1:
printf(" OBJT");
break;
case 2:
printf(" FUNC");
break;
case 3:
printf(" SECT");
break;
case 4:
printf(" FILE");
break;
default:
break;
}
//bind
switch(ELF32_ST_BIND(mysym.st_info))
{
case 0: printf(" LOCL");
break;
case 1: printf(" GLOB");
break;
case 2: printf(" WEAK");
break;
case 3: printf(" NUM");
break;
default:
break;
}
//TODO: oth
//TODO: ver
//TODO: shndx
//TODO: name
}
我一直在通过阅读http://docs.oracle.com/cd/E19457-01/801-6737/801-6737.pdf (第5章),但一直没能找到任何有用的