64 lines
2.0 KiB
C
64 lines
2.0 KiB
C
#include "ft_nm.h"
|
|
|
|
int nm32(t_mapped_file mapped_file) {
|
|
(void)mapped_file;
|
|
return FT_NM_SUCCESS;
|
|
}
|
|
|
|
int nm64(t_mapped_file mapped_file) {
|
|
Elf64_Ehdr header;
|
|
if (get_header64(mapped_file, &header) == FT_NM_FAILURE) {
|
|
return FT_NM_FAILURE;
|
|
}
|
|
printf("Header:\n");
|
|
printf("Version: %d\n", header.e_version);
|
|
printf("Entry point: %ld\n", header.e_entry);
|
|
printf("Program header offset: ");
|
|
fflush(stdout);
|
|
ft_printf("X", header.e_phoff);
|
|
ft_putchar('\n');
|
|
printf("Section header offset: ");
|
|
fflush(stdout);
|
|
ft_printf("X", header.e_shoff);
|
|
ft_putchar('\n');
|
|
printf("Header size: %d\n", header.e_ehsize);
|
|
printf("Program header entry size: %d\n", header.e_phentsize);
|
|
printf("Program header num: %d\n", header.e_phnum);
|
|
printf("Section header entry size: %d\n", header.e_shentsize);
|
|
printf("Section header num: %d\n", header.e_shnum);
|
|
printf("Section header string table index: %d\n", header.e_shstrndx);
|
|
/*
|
|
for (int i = 0; i < header.e_phnum; i++) {
|
|
uint64_t addr = header.e_phoff + header.e_phentsize * i;
|
|
Elf64_Phdr phstr;
|
|
ft_memcpy(&phstr, mapped_file.ptr + addr, header.e_phentsize);
|
|
ft_printf("X", phstr.p_offset);
|
|
ft_putchar('\n');
|
|
char *str = ft_strdup(mapped_file.ptr + phstr.p_offset + 1);
|
|
ft_putstr(str);
|
|
ft_putchar('\n');
|
|
}
|
|
*/
|
|
uint64_t addr = header.e_shoff + header.e_shentsize * header.e_shstrndx;
|
|
ft_printf("sX", "addr: ", addr);
|
|
Elf64_Shdr shstrtb;
|
|
ft_memcpy(&shstrtb, mapped_file.ptr + addr, header.e_shentsize);
|
|
ft_printf("sX", "offset: ", shstrtb.sh_offset);
|
|
for (int i = 0; i < header.e_shnum; i++) {
|
|
uint64_t addr = header.e_shoff + header.e_shentsize * i;
|
|
Elf64_Shdr sh;
|
|
ft_memcpy(&sh, mapped_file.ptr + addr, header.e_shentsize);
|
|
/*ft_printf("X", sh.sh_offset);
|
|
ft_putchar('\n');
|
|
ft_printf("X", sh.sh_name);
|
|
ft_putchar('\n');*/
|
|
char *str = ft_strdup(mapped_file.ptr + shstrtb.sh_offset + sh.sh_name);
|
|
//ft_putstr(str);
|
|
ft_printf("x x ss", sh.sh_name, sh.sh_offset, str, "\n");
|
|
free(str);
|
|
//ft_putchar('\n');
|
|
}
|
|
return FT_NM_SUCCESS;
|
|
}
|
|
|