diff --git a/nm-otool/Makefile b/nm-otool/Makefile index cc5e15fb..cea02344 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/03/26 15:37:30 by jhalford ### ########.fr # +# Updated: 2017/03/27 20:21:47 by jhalford ### ########.fr # # # # **************************************************************************** # @@ -104,14 +104,14 @@ clean: cleanlib: @make -C $(LIBFT_DIR) clean -fclean: clean +fclean: clean @$(RM) $(NAME) @printf "\r\e[38;5;196m❌ fclean $(NAME).\e[0m\e[K\n" fcleanlib: cleanlib @make -C $(LIBFT_DIR) fclean -re: fclean all +re: fclean relib all relib: fcleanlib $(LIBFT_LIB) diff --git a/nm-otool/includes/ft_nm_otool.h b/nm-otool/includes/ft_nm_otool.h index cdea18fd..f8630674 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/03/26 19:12:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 20:59:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -108,12 +108,11 @@ void symbol_free(void *data, size_t size); int symbol_format(t_symbol *symbol); int symbol_format_full(t_symbol *symbol); int sym_format_undf(t_symbolmap map, t_symbol *symbol); -int sym_format_text(t_symbolmap map, t_symbol *symbol); int sym_format_stab(t_symbolmap map, t_symbol *symbol); void mach_64_parse(t_machodata *data); void dump_dysymtab(t_machodata *data, struct dysymtab_command *dysymtab); -void *hexdump(void *addr, unsigned int offset, unsigned int size); +void *hexdump(void *addr, unsigned int offset, unsigned int size); #endif diff --git a/nm-otool/src/ft_nm.c b/nm-otool/src/ft_nm.c index ab30aa87..56391a19 100644 --- a/nm-otool/src/ft_nm.c +++ b/nm-otool/src/ft_nm.c @@ -6,11 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 03:09:12 by jhalford #+# #+# */ -/* Updated: 2017/03/26 19:12:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 20:59:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_nm_otool.h" +#define NM_USAGE "usage: nm [-a]" t_machodata *g_data = NULL; @@ -20,7 +21,7 @@ t_cliopts g_nm_opts[] = {'p', NULL, NM_NOSORT, 0, NULL, 0}, {'r', NULL, NM_RSORT, 0, NULL, 0}, - {0xff, "full", NM_FULL | NM_ALL, 0, NULL, 0}, + {0xff, "full", NM_FULL, 0, NULL, 0}, {'g', NULL, 0, 0, NULL, 0}, {'u', NULL, 0, 0, NULL, 0}, {'a', NULL, NM_ALL, 0, NULL, 0}, @@ -78,7 +79,7 @@ int main(int ac, char **av) if (cliopts_get(av, g_nm_opts, &data)) { ft_perror(); - ft_dprintf(2, "USAGE PLACEHOLDER\n"); + ft_dprintf(2, NM_USAGE); return (1); } i = data.av_data - av; diff --git a/nm-otool/src/ft_otool.c b/nm-otool/src/ft_otool.c index 9cbdcb03..10b870ed 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/03/26 19:10:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 20:41:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,7 +47,7 @@ void otool(void *file) struct section_64 *sect; if (is_fat) - ft_printf("fat binary: not supported yet.\n"); + ft_printf("fat binary not supported yet\n"); else if (is_64) { sect = get_text_section(file); diff --git a/nm-otool/src/symbol_filter.c b/nm-otool/src/symbol_filter.c index 8bee61da..b5fa99f6 100644 --- a/nm-otool/src/symbol_filter.c +++ b/nm-otool/src/symbol_filter.c @@ -1,4 +1,5 @@ -/* ************************************************************************** */ +/* + ************************************************************************** */ /* */ /* ::: :::::::: */ /* symbol_filter.c :+: :+: :+: */ diff --git a/nm-otool/src/symbol_format.c b/nm-otool/src/symbol_format.c index 2e137513..1c37c718 100644 --- a/nm-otool/src/symbol_format.c +++ b/nm-otool/src/symbol_format.c @@ -4,7 +4,7 @@ t_symbolmap g_symbolmap[] = { {'U', sym_format_undf}, {'A', NULL}, - {'T', sym_format_text}, + {'T', NULL}, {'D', NULL}, {'B', NULL}, {'C', NULL}, @@ -20,15 +20,6 @@ int sym_format_undf(t_symbolmap map, t_symbol *symbol) return (0); } -int sym_format_text(t_symbolmap map, t_symbol *symbol) -{ - char c; - - c = symbol->nlist->n_type & N_EXT ? 'T' : 't'; - ft_printf("%016llx %c %s\n", symbol->nlist->n_value, map.c, symbol->string); - return (0); -} - int sym_format_stab(t_symbolmap map, t_symbol *symbol) { struct nlist_64 *stab; @@ -47,7 +38,8 @@ int symbol_format_full(t_symbol *symbol) symbol->pos, (symbol->nlist->n_type & N_STAB) >> 5, (symbol->nlist->n_type & N_PEXT) >> 4, - symbol->nlist->n_type & N_TYPE, symbol->nlist->n_type & N_EXT, + symbol->nlist->n_type & N_TYPE, + symbol->nlist->n_type & N_EXT, symbol->nlist->n_sect, symbol->section->sectname, symbol->nlist->n_desc, symbol->nlist->n_value, symbol->string); @@ -57,6 +49,7 @@ int symbol_format_full(t_symbol *symbol) int symbol_format(t_symbol *symbol) { t_symbolmap map; + char c; map = g_symbolmap[symbol->type]; @@ -64,8 +57,9 @@ int symbol_format(t_symbol *symbol) map.format(map, symbol); else { + c = symbol->nlist->n_type & N_EXT ? map.c : map.c + 32; ft_printf("%016llx %c %s\n", - symbol->nlist->n_value, map.c, symbol->string); + symbol->nlist->n_value, c, symbol->string); } return (0); } diff --git a/nm-otool/src/symbol_init.c b/nm-otool/src/symbol_init.c index 0848c421..94812851 100644 --- a/nm-otool/src/symbol_init.c +++ b/nm-otool/src/symbol_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 21:22:06 by jhalford #+# #+# */ -/* Updated: 2017/03/26 16:50:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 20:36:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,15 +40,15 @@ int symbol_set(t_symbol *symbol, t_machodata *data) symbol->type = SYM_COMMON; else if (type_mask == N_UNDF) symbol->type = SYM_UNDF; - else if (type_mask == N_SECT && ft_strcmp("__TEXT", symbol->section->segname) == 0) - symbol->type = SYM_TEXT; - else if (type_mask == N_SECT && ft_strcmp("__DATA", symbol->section->segname) == 0) - symbol->type = SYM_DATA; else if (type_mask == N_ABS) symbol->type = SYM_ABS; + else if (type_mask == N_SECT && ft_strcmp("__text", symbol->section->sectname) == 0) + symbol->type = SYM_TEXT; + else if (type_mask == N_SECT && ft_strcmp("__data", symbol->section->sectname) == 0) + symbol->type = SYM_DATA; else if (type_mask == N_INDR) symbol->type = SYM_INDR; else - symbol->type = SYM_UNDF; + symbol->type = SYM_OTHER; return (0); } diff --git a/nm-otool/src/symbol_sort.c b/nm-otool/src/symbol_sort.c index 872eb3d1..a85923dd 100644 --- a/nm-otool/src/symbol_sort.c +++ b/nm-otool/src/symbol_sort.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/26 15:03:55 by jhalford #+# #+# */ -/* Updated: 2017/03/26 19:20:49 by jhalford ### ########.fr */ +/* Created: 2017/03/27 20:33:02 by jhalford #+# #+# */ +/* Updated: 2017/03/27 20:33:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/tests/compile.sh b/nm-otool/tests/compile.sh deleted file mode 100644 index c5f0233b..00000000 --- a/nm-otool/tests/compile.sh +++ /dev/null @@ -1 +0,0 @@ -gcc -g3 stabs_define.c -w -o stabs_define diff --git a/nm-otool/tests/stabs_define.c b/nm-otool/tests/stabs_define.c deleted file mode 100644 index 505a50d8..00000000 --- a/nm-otool/tests/stabs_define.c +++ /dev/null @@ -1,23 +0,0 @@ -#define NONE 42 -#define TWO(a, b) (a + (a) + 2 * b) -#define ONE(c) (c + 19) - -main(int argc, char *argv[]) -{ - func(NONE, TWO(10, 11)); - func(NONE, ONE(23)); - -#undef ONE -#define ONE(c) (c + 23) - - func(NONE, ONE(-23)); - - return (0); -} - -int global; - -func(int arg1, int arg2) -{ - global = arg1 + arg2; -} diff --git a/nm-otool/tests/test_facile b/nm-otool/tests/test_facile deleted file mode 100755 index 58a820c3..00000000 Binary files a/nm-otool/tests/test_facile and /dev/null differ diff --git a/nm-otool/tests/test_facile.c b/nm-otool/tests/test_facile.c deleted file mode 100644 index aab6b7a6..00000000 --- a/nm-otool/tests/test_facile.c +++ /dev/null @@ -1,7 +0,0 @@ -#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 deleted file mode 100755 index 54af8251..00000000 Binary files a/nm-otool/tests/test_moins_facile and /dev/null differ diff --git a/nm-otool/tests/test_moins_facile.c b/nm-otool/tests/test_moins_facile.c deleted file mode 100644 index b619639a..00000000 --- a/nm-otool/tests/test_moins_facile.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int une_globale = 40; - -int main(void) -{ - printf("La globale vaut: %d\n", une_globale); - return (0); -}