ELF processing
From: ness (e_mc_h2_at_web.de)
Date: 09/25/05
- Next message: Ulrich Eckhardt: "Re: ELF processing"
- Previous message: Sibi: "Freeblock Scheduler in Linux?"
- Next in thread: Ulrich Eckhardt: "Re: ELF processing"
- Reply: Ulrich Eckhardt: "Re: ELF processing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 25 Sep 2005 00:48:06 -0700
I try to do some ELF processing, It works fine with some files, and
some don't work. I don't understand that.
The piece of code where I parse the file:
assert(argc == 2);
int fd = open(argv[1],O_RDONLY);
assert(fd != -1);
caddr_t addr = mmap(0,15000,PROT_READ,MAP_SHARED,fd,0);
assert((long)addr != -1);
Elf64_Ehdr* elf = (Elf64_Ehdr*)addr;
assert( elf->e_ident[EI_MAG0] == ELFMAG0
&& elf->e_ident[EI_MAG1] == ELFMAG1
&& elf->e_ident[EI_MAG2] == ELFMAG2
&& elf->e_ident[EI_MAG3] == ELFMAG3);
printf("ist ELF-Datei\n");
assert(elf->e_shstrndx != SHN_UNDEF);
assert(elf->e_shstrndx<elf->e_shnum);
printf("%i sections, %i ist der string table\n",elf->e_shnum,
elf->e_shstrndx);
assert(elf->e_shstrndx <= elf->e_shnum);
Elf64_Shdr* strtable = (Elf64_Shdr*)(addr + elf->e_shoff +
elf->e_shstrndx * elf->e_shentsize);
assert(strtable->sh_type == SHT_STRTAB);
assert(strtable->sh_size != 0);
printf("\n");
Elf64_Shdr* tmpsh;
unsigned i;
for(i=1;i<elf->e_shnum;++i)
{
tmpsh = (Elf64_Shdr*)(addr + elf->e_shoff+ i * elf->e_shentsize);
printf("%s\t%i\n",(char*)(addr+strtable->sh_offset) +
tmpsh->sh_name,tmpsh->sh_addr);
};
It terminates with "Assertion `strtable->sh_type == 3' failed". (The
line "assert(strtable->sh_type == SHT_STRTAB);")
- Next message: Ulrich Eckhardt: "Re: ELF processing"
- Previous message: Sibi: "Freeblock Scheduler in Linux?"
- Next in thread: Ulrich Eckhardt: "Re: ELF processing"
- Reply: Ulrich Eckhardt: "Re: ELF processing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]