diff --git a/nm-otool/Makefile b/nm-otool/Makefile index 1c1dfcce..76ed4024 100644 --- a/nm-otool/Makefile +++ b/nm-otool/Makefile @@ -6,7 +6,7 @@ # By: jhalford +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2017/02/19 03:29:38 by jhalford #+# #+# # -# Updated: 2017/02/20 15:38:45 by jhalford ### ########.fr # +# Updated: 2017/03/01 16:00:29 by jhalford ### ########.fr # # # # **************************************************************************** # diff --git a/nm-otool/includes/ft_nm_otool.h b/nm-otool/includes/ft_nm_otool.h index fabf0927..99a5ef20 100644 --- a/nm-otool/includes/ft_nm_otool.h +++ b/nm-otool/includes/ft_nm_otool.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/20 14:36:10 by jhalford #+# #+# */ -/* Updated: 2017/02/20 16:10:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 17:52:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ # define IS_MAGIC_64(x) (x == MH_MAGIC_64 || x == MH_CIGAM_64) # define IS_FAT(x) (x == FAT_MAGIC || x == FAT_CIGAM) -void dump_symtab(struct symtab_command *sym, void *file); +void dump_symtab(struct symtab_command *sym, struct dysymtab_command *dysym, void *file); void *hexdump(void *addr, unsigned int offset, unsigned int size); #endif diff --git a/nm-otool/src/dump_symtab.c b/nm-otool/src/dump_symtab.c index 9bc878d1..4e26ffa2 100644 --- a/nm-otool/src/dump_symtab.c +++ b/nm-otool/src/dump_symtab.c @@ -6,23 +6,56 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/20 13:20:22 by jhalford #+# #+# */ -/* Updated: 2017/02/20 15:03:38 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 17:55:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_nm_otool.h" -void dump_symtab(struct symtab_command *sym, void *file) +void dump_symtab(struct symtab_command *sym, struct dysymtab_command *dysym, void *file) { - int i; - int nsyms; - char *stringtable; - struct nlist_64 *array; + int i; + int nsyms; + char *stringtable; + char *string; + struct nlist_64 *array; + struct dylib_reference *ref; nsyms = sym->nsyms; array = file + sym->symoff; - stringtable = (void*)file + sym->stroff; - ft_printf("{und}LC_SYMTAB w/ [%d] symbols:{eoc}\n", sym->nsyms); - for (i = 0; i < nsyms; ++i) + stringtable = file + sym->stroff; + ft_printf("LC_SYMTAB [%d] symbols:\n", sym->nsyms); + i = 0; + while (++i < nsyms) + { ft_printf("%s\n", stringtable + array[i].n_un.n_strx); + } + ft_putendl(""); + + ft_printf("ilocalsym %i\n", dysym->ilocalsym); + ft_printf("nlocalsym %i\n", dysym->nlocalsym); + + ft_printf("iextdefsym %i\n", dysym->iextdefsym); + ft_printf("nextdefsym %i\n", dysym->nextdefsym); + + ft_printf("iundefsym %i\n", dysym->iundefsym); + ft_printf("nundefsym %i\n", dysym->nundefsym); + + i = -1; + ft_printf("LC_DYSYMTAB ntoc=[%d]\n", dysym->ntoc); + ft_printf("LC_DYSYMTAB nmodtab=[%d]\n", dysym->nmodtab); + ft_printf("LC_DYSYMTAB nextrefsyms=[%d]\n", dysym->nextrefsyms); + ft_printf("LC_DYSYMTAB nmodtab=[%d]\n", dysym->nmodtab); + ft_printf("LC_DYSYMTAB nindirectsyms=[%d]\n", dysym->nindirectsyms); + ft_printf("LC_DYSYMTAB nextrel=[%d]\n", dysym->nextrel); + ft_printf("LC_DYSYMTAB nlocrel=[%d]\n", dysym->nlocrel); + ft_putendl(""); + ref = file + dysym->indirectsymoff; + while (++i < (int)dysym->nindirectsyms) + { + string = stringtable + array[ref->isym].n_un.n_strx; + ft_printf("%i: %s,%#x\n", ref->isym, string, ref->flags); + ref += 1; + } + (void)file; } diff --git a/nm-otool/src/ft_nm.c b/nm-otool/src/ft_nm.c index 7c65ba42..e68ba7a1 100644 --- a/nm-otool/src/ft_nm.c +++ b/nm-otool/src/ft_nm.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 03:09:12 by jhalford #+# #+# */ -/* Updated: 2017/02/20 16:45:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 17:53:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,25 +34,34 @@ void dump_segment_64(struct segment_command_64 *seg, void *file) } } +void print_output(int nsyms, int symoff, int stroff, void *ptr); + void dump_mach_header_64(void *file) { uint32_t ncmds; uint32_t i; struct load_command *lc; + struct symtab_command *symtab; + struct dysymtab_command *dysymtab; struct mach_header_64 *header = file; ncmds = header->ncmds; lc = (void*)(header + 1); - ft_printf("{blu}{inv}mach_header_64 w/ [%d] load_commands{eoc}\n", ncmds); + /* ft_printf("{blu}{inv}mach_header_64 w/ [%d] load_commands{eoc}\n", ncmds); */ for (i = 0; i < ncmds; i++) { - ft_printf("{yel}{inv}load_command #%d: %#x{eoc}\n", i, lc->cmd); - if (lc->cmd & LC_SYMTAB) - dump_symtab((struct symtab_command*)lc, file); - else if (lc->cmd & LC_SEGMENT_64) - dump_segment_64((struct segment_command_64*)lc, file); + /* ft_printf("{yel}{inv}load_command #%d: %#x{eoc}\n", i, lc->cmd); */ + if (lc->cmd == LC_SYMTAB) + symtab = (struct symtab_command*)lc; + /* dump_symtab((struct symtab_command*)lc, file); */ + else if (lc->cmd == LC_DYSYMTAB) + dysymtab = (struct dysymtab_command*)lc; + /* dump_dysymtab((struct dysymtab_command*)lc, file); */ + /* else if (lc->cmd == LC_SEGMENT_64) */ + /* dump_segment_64((struct segment_command_64*)lc, file); */ lc = (void*)lc + lc->cmdsize; } + dump_symtab(symtab, dysymtab, file); } void dump_fat_header(void *file) diff --git a/nm-otool/src/ft_otool.c b/nm-otool/src/ft_otool.c index e164d8b6..250a0b84 100644 --- a/nm-otool/src/ft_otool.c +++ b/nm-otool/src/ft_otool.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/20 14:08:14 by jhalford #+# #+# */ -/* Updated: 2017/02/20 16:27:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 17:51:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/src/hexdump.c b/nm-otool/src/hexdump.c index ca6c12c3..617e7844 100644 --- a/nm-otool/src/hexdump.c +++ b/nm-otool/src/hexdump.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/20 15:14:33 by jhalford #+# #+# */ -/* Updated: 2017/02/20 16:52:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/01 15:37:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/tests/test_facile b/nm-otool/tests/test_facile new file mode 100755 index 00000000..58a820c3 Binary files /dev/null and b/nm-otool/tests/test_facile differ diff --git a/nm-otool/tests/test_facile.c b/nm-otool/tests/test_facile.c new file mode 100644 index 00000000..aab6b7a6 --- /dev/null +++ b/nm-otool/tests/test_facile.c @@ -0,0 +1,7 @@ +#include + +int main(void) +{ + puts("Test facile"); + return (0); +} diff --git a/nm-otool/tests/test_moins_facile b/nm-otool/tests/test_moins_facile new file mode 100755 index 00000000..54af8251 Binary files /dev/null and b/nm-otool/tests/test_moins_facile differ diff --git a/nm-otool/tests/test_moins_facile.c b/nm-otool/tests/test_moins_facile.c new file mode 100644 index 00000000..b619639a --- /dev/null +++ b/nm-otool/tests/test_moins_facile.c @@ -0,0 +1,9 @@ +#include + +int une_globale = 40; + +int main(void) +{ + printf("La globale vaut: %d\n", une_globale); + return (0); +}