|
|
@ -1,90 +1,90 @@ |
|
|
|
#include "ft_re.h" |
|
|
|
|
|
|
|
void display_64_section_header(t_elf64 *nm, int i) { |
|
|
|
printf( |
|
|
|
ft_printf( |
|
|
|
" [Nr] Name Type Addr Off Size " |
|
|
|
" " |
|
|
|
"ES Flg Lk Inf Al\n"); |
|
|
|
printf(" [%2d] ", i); |
|
|
|
printf("%-18s", nm->string_table + nm->shdr[i].sh_name); |
|
|
|
printf("%-16s", get_section_type(nm->shdr[i].sh_type)); |
|
|
|
printf("%016lx ", nm->shdr[i].sh_addr); |
|
|
|
printf("%06lx ", nm->shdr[i].sh_offset); |
|
|
|
printf("%06lx ", nm->shdr[i].sh_size); |
|
|
|
printf("%02lx ", nm->shdr[i].sh_entsize); |
|
|
|
printf("%3s ", get_section_flags(nm->shdr[i].sh_flags)); |
|
|
|
printf("%02x ", nm->shdr[i].sh_link); |
|
|
|
printf("%02x ", nm->shdr[i].sh_info); |
|
|
|
printf("%02lx\n", nm->shdr[i].sh_addralign); |
|
|
|
ft_printf(" [%2d] ", i); |
|
|
|
ft_printf("%-18s", nm->string_table + nm->shdr[i].sh_name); |
|
|
|
ft_printf("%-16s", get_section_type(nm->shdr[i].sh_type)); |
|
|
|
ft_printf("%016lx ", nm->shdr[i].sh_addr); |
|
|
|
ft_printf("%06lx ", nm->shdr[i].sh_offset); |
|
|
|
ft_printf("%06lx ", nm->shdr[i].sh_size); |
|
|
|
ft_printf("%02lx ", nm->shdr[i].sh_entsize); |
|
|
|
ft_printf("%3s ", get_section_flags(nm->shdr[i].sh_flags)); |
|
|
|
ft_printf("%02x ", nm->shdr[i].sh_link); |
|
|
|
ft_printf("%02x ", nm->shdr[i].sh_info); |
|
|
|
ft_printf("%02lx\n", nm->shdr[i].sh_addralign); |
|
|
|
} |
|
|
|
|
|
|
|
void display_64_header(t_elf64 *nm) { |
|
|
|
printf("ELF Header:\n"); |
|
|
|
printf(" Magic: "); |
|
|
|
for (int i = 0; i < EI_NIDENT; i++) printf("%02x ", nm->ehdr->e_ident[i]); |
|
|
|
printf("\n Class: ELF64\n"); |
|
|
|
printf( |
|
|
|
ft_printf("ELF Header:\n"); |
|
|
|
ft_printf(" Magic: "); |
|
|
|
for (int i = 0; i < EI_NIDENT; i++)ft_printf("%02x ", nm->ehdr->e_ident[i]); |
|
|
|
ft_printf("\n Class: ELF64\n"); |
|
|
|
ft_printf( |
|
|
|
" Data: 2's complement, little endian\n"); |
|
|
|
printf(" Version: 1 (current)\n"); |
|
|
|
printf(" OS/ABI: UNIX - System V\n"); |
|
|
|
printf(" ABI Version: 0\n"); |
|
|
|
printf(" Version: 0x%016x\n", |
|
|
|
ft_printf(" Version: 1 (current)\n"); |
|
|
|
ft_printf(" OS/ABI: UNIX - System V\n"); |
|
|
|
ft_printf(" ABI Version: 0\n"); |
|
|
|
ft_printf(" Version: 0x%016x\n", |
|
|
|
nm->ehdr->e_version); |
|
|
|
printf(" Entry point address: 0x%016lx\n", |
|
|
|
ft_printf(" Entry point address: 0x%016lx\n", |
|
|
|
nm->ehdr->e_entry); |
|
|
|
printf(" Start of program headers: %ld (bytes into file)\n", |
|
|
|
ft_printf(" Start of program headers: %ld (bytes into file)\n", |
|
|
|
nm->ehdr->e_phoff); |
|
|
|
printf(" Start of section headers: %ld (bytes into file)\n", |
|
|
|
ft_printf(" Start of section headers: %ld (bytes into file)\n", |
|
|
|
nm->ehdr->e_shoff); |
|
|
|
printf(" Flags: 0x%016x\n", nm->ehdr->e_flags); |
|
|
|
printf(" Size of this header: %d (bytes)\n", |
|
|
|
ft_printf(" Flags: 0x%016x\n", nm->ehdr->e_flags); |
|
|
|
ft_printf(" Size of this header: %d (bytes)\n", |
|
|
|
nm->ehdr->e_ehsize); |
|
|
|
printf(" Size of program headers: %d (bytes)\n", |
|
|
|
ft_printf(" Size of program headers: %d (bytes)\n", |
|
|
|
nm->ehdr->e_phentsize); |
|
|
|
printf(" Number of program headers: %d\n", nm->ehdr->e_phnum); |
|
|
|
printf(" Size of section headers: %d (bytes)\n", |
|
|
|
ft_printf(" Number of program headers: %d\n", nm->ehdr->e_phnum); |
|
|
|
ft_printf(" Size of section headers: %d (bytes)\n", |
|
|
|
nm->ehdr->e_shentsize); |
|
|
|
printf(" Number of section headers: %d\n", nm->ehdr->e_shnum); |
|
|
|
printf(" Section header string table index: %d\n", nm->ehdr->e_shstrndx); |
|
|
|
ft_printf(" Number of section headers: %d\n", nm->ehdr->e_shnum); |
|
|
|
ft_printf(" Section header string table index: %d\n", nm->ehdr->e_shstrndx); |
|
|
|
} |
|
|
|
|
|
|
|
int print_64_symtab(t_elf64 *nm) { |
|
|
|
int sym_num = nm->symtab_end - nm->symtab; |
|
|
|
|
|
|
|
printf("Symbol table '%s' contains %d entries:\n", nm->file, sym_num); |
|
|
|
printf("Contents of the (%s) section: \n", |
|
|
|
ft_printf("Symbol table '%s' contains %d entries:\n", nm->file, sym_num); |
|
|
|
ft_printf("Contents of the (%s) section: \n", |
|
|
|
nm->string_table + nm->shdr[nm->ehdr->e_shstrndx].sh_name); |
|
|
|
printf( |
|
|
|
ft_printf( |
|
|
|
"| Num: |Value |Size |Type |Bind |Vis " |
|
|
|
" |Ndx0x |Ndx " |
|
|
|
" |shndxty |shndxfl|nmChar |Name\n"); |
|
|
|
for (int i = 0; i < sym_num; i++) { |
|
|
|
int id = nm->opts.p == 0 ? nm->ordered_sym_ids[i] : i; |
|
|
|
printf("| %4d: ", id); |
|
|
|
printf("|%16lx ", nm->symtab[id].st_value); |
|
|
|
printf("|%16lx ", nm->symtab[id].st_size); |
|
|
|
printf("|%-6s ", get_sym_type(ELF64_ST_TYPE(nm->symtab[id].st_info))); |
|
|
|
printf("|%-6s ", get_sym_bind(ELF64_ST_BIND(nm->symtab[id].st_info))); |
|
|
|
printf("|%-7s ", |
|
|
|
ft_printf("| %4d: ", id); |
|
|
|
ft_printf("|%16lx ", nm->symtab[id].st_value); |
|
|
|
ft_printf("|%16lx ", nm->symtab[id].st_size); |
|
|
|
ft_printf("|%-6s ", get_sym_type(ELF64_ST_TYPE(nm->symtab[id].st_info))); |
|
|
|
ft_printf("|%-6s ", get_sym_bind(ELF64_ST_BIND(nm->symtab[id].st_info))); |
|
|
|
ft_printf("|%-7s ", |
|
|
|
get_sym_vis(ELF64_ST_VISIBILITY(nm->symtab[id].st_other))); |
|
|
|
printf("|%5d", nm->symtab[id].st_shndx); |
|
|
|
printf("|%7s ", get_sym_shndx(nm->symtab[id].st_shndx)); |
|
|
|
ft_printf("|%5d", nm->symtab[id].st_shndx); |
|
|
|
ft_printf("|%7s ", get_sym_shndx(nm->symtab[id].st_shndx)); |
|
|
|
if (nm->symtab[id].st_shndx < nm->ehdr->e_shnum) { |
|
|
|
printf("|%8s", |
|
|
|
ft_printf("|%8s", |
|
|
|
get_sh_type(nm->shdr[nm->symtab[id].st_shndx].sh_type)); |
|
|
|
printf("|%8s", |
|
|
|
ft_printf("|%8s", |
|
|
|
get_sh_flag(nm->shdr[nm->symtab[id].st_shndx].sh_flags)); |
|
|
|
} else { |
|
|
|
printf("|%8c", ' '); |
|
|
|
printf("|%8c", ' '); |
|
|
|
ft_printf("|%8c", ' '); |
|
|
|
ft_printf("|%8c", ' '); |
|
|
|
} |
|
|
|
printf("|%6c ", nm->sym_types[id]); |
|
|
|
printf("|%s\n", nm->sym_names[id]); |
|
|
|
ft_printf("|%6c ", nm->sym_types[id]); |
|
|
|
ft_printf("|%s\n", nm->sym_names[id]); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
int parse_64_symtab(t_elf64 *nm) { |
|
|
|
nt parse_64_symtab(t_elf64 *nm) { |
|
|
|
Elf64_Shdr *shdr = &nm->shdr[nm->ehdr->e_shstrndx]; |
|
|
|
nm->string_table = (char *)(nm->ptr + shdr->sh_offset); |
|
|
|
for (int i = 0; i < nm->ehdr->e_shnum; i++) { |
|
|
@ -136,7 +136,7 @@ int ft_re64(char *filename, int filesize, char *file, t_opts opts) { |
|
|
|
|
|
|
|
// check if file is complete
|
|
|
|
if (nm.ehdr->e_shoff + nm.ehdr->e_shnum * nm.ehdr->e_shentsize > nm.size) { |
|
|
|
fprintf(stderr, "bfd plugin: %s: file too short\n", nm.file); |
|
|
|
ft_fprintf(stderr, "bfd plugin: %s: file too short\n", nm.file); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|