From 33b7b25abeb107327b234c1fbfcc6cb3b19fe26a Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 30 Oct 2017 12:26:34 +0100 Subject: [PATCH] finished 32 bit stuff --- nm-otool/Makefile | 48 ++++++------ nm-otool/gen_mach.sh | 5 ++ nm-otool/includes/ft_nm.h | 95 +++++++++++++++++++++++ nm-otool/includes/ft_nm_otool.h | 96 ++--------------------- nm-otool/includes/ft_otool.h | 26 +++++++ nm-otool/includes/mach.h | 44 +++++++++++ nm-otool/includes/mach_64.h | 9 ++- nm-otool/libft/includes/cliopts.h | 2 +- nm-otool/libft/includes/error.h | 4 +- nm-otool/libft/includes/libft.h | 5 +- nm-otool/libft/srcs/printing/hexdump.c | 32 ++++++-- nm-otool/otooldiff.sh | 8 ++ nm-otool/srcs/ft_nm.c | 8 +- nm-otool/srcs/ft_otool.c | 99 +++++++++++------------- nm-otool/srcs/mach/get_section.c | 52 +++++++++++++ nm-otool/srcs/mach/mach.c | 71 +++++++++++++++++ nm-otool/srcs/mach/nm_mach.c | 26 +++++++ nm-otool/srcs/mach/otool_mach.c | 35 +++++++++ nm-otool/srcs/mach/symbol_filter.c | 45 +++++++++++ nm-otool/srcs/mach/symbol_format.c | 88 +++++++++++++++++++++ nm-otool/srcs/mach/symbol_free.c | 23 ++++++ nm-otool/srcs/mach/symbol_init.c | 66 ++++++++++++++++ nm-otool/srcs/mach/symbol_sort.c | 39 ++++++++++ nm-otool/srcs/mach_64/get_section_64.c | 52 +++++++++++++ nm-otool/srcs/mach_64/mach_64.c | 15 +--- nm-otool/srcs/mach_64/nm_mach_64.c | 26 +++++++ nm-otool/srcs/mach_64/otool_mach_64.c | 35 +++++++++ nm-otool/srcs/mach_64/symbol_64_format.c | 6 +- 28 files changed, 857 insertions(+), 203 deletions(-) create mode 100755 nm-otool/gen_mach.sh create mode 100644 nm-otool/includes/ft_nm.h create mode 100644 nm-otool/includes/ft_otool.h create mode 100644 nm-otool/includes/mach.h create mode 100755 nm-otool/otooldiff.sh create mode 100644 nm-otool/srcs/mach/get_section.c create mode 100644 nm-otool/srcs/mach/mach.c create mode 100644 nm-otool/srcs/mach/nm_mach.c create mode 100644 nm-otool/srcs/mach/otool_mach.c create mode 100644 nm-otool/srcs/mach/symbol_filter.c create mode 100644 nm-otool/srcs/mach/symbol_format.c create mode 100644 nm-otool/srcs/mach/symbol_free.c create mode 100644 nm-otool/srcs/mach/symbol_init.c create mode 100644 nm-otool/srcs/mach/symbol_sort.c create mode 100644 nm-otool/srcs/mach_64/get_section_64.c create mode 100644 nm-otool/srcs/mach_64/nm_mach_64.c create mode 100644 nm-otool/srcs/mach_64/otool_mach_64.c diff --git a/nm-otool/Makefile b/nm-otool/Makefile index 814198a0..1a8bae55 100644 --- a/nm-otool/Makefile +++ b/nm-otool/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/10/26 19:15:02 by jhalford ### ########.fr # +# Updated: 2017/10/30 12:22:10 by jhalford ### ########.fr # # # # **************************************************************************** # @@ -34,21 +34,27 @@ NM_OBJ = $(OBJ_DIR)ft_nm.o OTOOL_OBJ = $(OBJ_DIR)ft_otool.o SRC_BASE = \ -ft_otool.c\ -mach_64/symbol_64_init.c\ -mach_64/symbol_64_filter.c\ -mach_64/symbol_64_sort.c\ -mach_64/mach_64.c\ -mach_64/symbol_64_free.c\ -mach_64/symbol_64_format.c\ -mach_32/symbol_32_free.c\ -mach_32/symbol_32_sort.c\ -mach_32/mach_32.c\ -mach_32/symbol_32_format.c\ -mach_32/symbol_32_filter.c\ -mach_32/symbol_32_init.c\ +dump_symtab.c\ ft_nm.c\ -dump_symtab.c +ft_otool.c\ +mach/get_section.c\ +mach/mach.c\ +mach/nm_mach.c\ +mach/otool_mach.c\ +mach/symbol_filter.c\ +mach/symbol_format.c\ +mach/symbol_free.c\ +mach/symbol_init.c\ +mach/symbol_sort.c\ +mach_64/get_section_64.c\ +mach_64/mach_64.c\ +mach_64/nm_mach_64.c\ +mach_64/otool_mach_64.c\ +mach_64/symbol_64_filter.c\ +mach_64/symbol_64_format.c\ +mach_64/symbol_64_free.c\ +mach_64/symbol_64_init.c\ +mach_64/symbol_64_sort.c SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) OBJS = $(addprefix $(OBJ_DIR), $($(notdir SRC_BASE):.c=.o)) @@ -57,22 +63,12 @@ OBJS := $(filter-out $(OTOOL_OBJ), $(OBJS)) NB = $(words $(SRC_BASE)) INDEX = 0 -MACH_64_SRC := $(wildcard $(SRC_DIR)mach_64/*) -MACH_64_SRC += $(INC_DIR)mach_64.h -MACH_SRC := $(subst _64,_32, $(MACH_64_SRC)) - SHELL := /bin/bash all: @make -C $(LIBFT_DIR) @make -j $(NAME) -# $(SRC_DIR)/mach/%.c: $(SRC_DIR)/mach_64/%.c -$(MACH_SRC): - @mkdir -p $(SRC_DIR)/mach_32 - @echo "$@ ---> $(subst _32,_64, $@)" - @sed s/_64/_32/g $(subst _32,_64, $@) > $@ - ft_nm: $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) $(NM_OBJ) @$(CC) $(OBJS) -o $@ \ -I $(INC_DIR) \ @@ -129,6 +125,6 @@ re: fclean all relib: fcleanlib $(LIBFT_LIB) -.PHONY : fclean clean re relib cleanlib fcleanlib $(MACH_SRC) +.PHONY : fclean clean re relib cleanlib fcleanlib -include $(OBJS:.o=.d) diff --git a/nm-otool/gen_mach.sh b/nm-otool/gen_mach.sh new file mode 100755 index 00000000..2701d4b2 --- /dev/null +++ b/nm-otool/gen_mach.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +for file in $@; do + sed s/_64//g $@ > $(sed s/_64//g <<< "$@") +done diff --git a/nm-otool/includes/ft_nm.h b/nm-otool/includes/ft_nm.h new file mode 100644 index 00000000..6490aecd --- /dev/null +++ b/nm-otool/includes/ft_nm.h @@ -0,0 +1,95 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_nm.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/30 11:44:40 by jhalford #+# #+# */ +/* Updated: 2017/10/30 12:00:49 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_NM_H +# define FT_NM_H + +/* +** sorting flags +** -r reverse sort +** -n numerical sort (as opposed to alphabetical) +** -p don't sort +*/ + +# define NM_NOSORT (1 << 0) +# define NM_NSORT (1 << 1) +# define NM_ASORT (1 << 2) +# define NM_RSORT (1 << 3) + +/* +** filtering flags +** -a show all symbols +** -g filter-out local symbols +** -U filter-out undefined symbols +** -u show only undefined symbols +*/ + +# define NM_ALL (1 << 4) +# define NM_NO_LOCAL (1 << 5) +# define NM_NO_UNDF (1 << 6) +# define NM_ONLY_UNDF (1 << 7) + +/* +** formating flags +** -o prepend file name on each line +** -m Display the N_SECT type symbols (Mach-O symbols) as (segment_name, +** section_name) followed by either external or non-external and then +** the symbol name. Undefined, common, absolute and indirect symbols +** get displayed as (undefined), (common), (absolute), and (indirect), +** respectively. +*/ + +# define NM_FULL (1 << 8) +# define NM_OFORMAT (1 << 9) +# define NM_MFORMAT (1 << 10) + +typedef struct s_nmdata t_nmdata; +typedef enum e_symtype t_symtype; +typedef struct s_symbolmap t_symbolmap; +typedef struct s_machodata t_machodata; + +struct s_nmdata +{ + t_flag flag; + char **av_data; + char *filename; +}; + +enum e_symtype +{ + SYM_UNDF, + SYM_ABS, + SYM_TEXT, + SYM_DATA, + SYM_BSS, + SYM_COMMON, + SYM_STAB, + SYM_OTHER, + SYM_INDR, +}; + +struct s_machodata +{ + void *file; + t_list *sects; + t_list *symbols; + struct symtab_command *symtab; + struct dysymtab_command *dysymtab; +}; + +struct s_symbolmap +{ + char c; + char *s; +}; + +#endif diff --git a/nm-otool/includes/ft_nm_otool.h b/nm-otool/includes/ft_nm_otool.h index 41adf892..dafd2569 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/10/26 18:42:47 by jhalford ### ########.fr */ +/* Updated: 2017/10/30 12:00:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,95 +25,15 @@ # include # include +# include "ft_nm.h" +# include "ft_otool.h" + +# include "mach_64.h" +# include "mach.h" + + # define IS_MACH_64(x) (x == MH_MAGIC_64 || x == MH_CIGAM_64) # define IS_MACH_32(x) (x == MH_MAGIC || x == MH_CIGAM) # define IS_FAT(x) (x == FAT_MAGIC || x == FAT_CIGAM) -/* -** sorting flags -** -r reverse sort -** -n numerical sort (as opposed to alphabetical) -** -p don't sort -*/ - -# define NM_NOSORT (1 << 0) -# define NM_NSORT (1 << 1) -# define NM_ASORT (1 << 2) -# define NM_RSORT (1 << 3) - -/* -** filtering flags -** -a show all symbols -** -g filter-out local symbols -** -U filter-out undefined symbols -** -u show only undefined symbols -*/ - -# define NM_ALL (1 << 4) -# define NM_NO_LOCAL (1 << 5) -# define NM_NO_UNDF (1 << 6) -# define NM_ONLY_UNDF (1 << 7) - -/* -** formating flags -** -o prepend file name on each line -** -m Display the N_SECT type symbols (Mach-O symbols) as (segment_name, -** section_name) followed by either external or non-external and then -** the symbol name. Undefined, common, absolute and indirect symbols -** get displayed as (undefined), (common), (absolute), and (indirect), -** respectively. -*/ - -# define NM_FULL (1 << 8) -# define NM_OFORMAT (1 << 9) -# define NM_MFORMAT (1 << 10) - -typedef struct s_nmdata t_nmdata; -typedef enum e_symtype t_symtype; -typedef struct s_symbolmap t_symbolmap; -typedef struct s_machodata t_machodata; - -struct s_nmdata -{ - t_flag flag; - char **av_data; - char *filename; -}; - -enum e_symtype -{ - SYM_UNDF, - SYM_ABS, - SYM_TEXT, - SYM_DATA, - SYM_BSS, - SYM_COMMON, - SYM_STAB, - SYM_OTHER, - SYM_INDR, -}; - -struct s_machodata -{ - void *file; - t_list *sects; - t_list *symbols; - struct symtab_command *symtab; - struct dysymtab_command *dysymtab; -}; - -struct s_symbolmap -{ - char c; - char *s; -}; - -# include "mach_64.h" - -void dump_dysymtab(t_machodata *data, - struct dysymtab_command *dysymtab); - -extern t_symbolmap g_symbolmap[]; -extern t_machodata *g_data; - #endif diff --git a/nm-otool/includes/ft_otool.h b/nm-otool/includes/ft_otool.h new file mode 100644 index 00000000..a152c3ea --- /dev/null +++ b/nm-otool/includes/ft_otool.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_otool.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/30 11:46:23 by jhalford #+# #+# */ +/* Updated: 2017/10/30 12:00:39 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_OTOOL_H +# define FT_OTOOL_H + +/* +** otool flags +** -t show text section +** -d show data section +*/ +# define OTOOL_TEXT (1 << 0) +# define OTOOL_DATA (1 << 1) + +typedef t_data_template t_otooldata; + +#endif diff --git a/nm-otool/includes/mach.h b/nm-otool/includes/mach.h new file mode 100644 index 00000000..b5831d18 --- /dev/null +++ b/nm-otool/includes/mach.h @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mach.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/26 18:39:31 by jhalford #+# #+# */ +/* Updated: 2017/10/30 12:17:17 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MACH_H +# define MACH_H + +typedef struct s_symbol t_symbol; + +struct s_symbol +{ + int pos; + t_symtype type; + char *string; + struct nlist *nlist; + struct section *section; +}; + +int symbol_init(t_symbol *symbol, + char *stringtable, struct nlist *array, int i); +int symbol_set(t_symbol *symbol, t_machodata *data); +void symbol_free(void *data, size_t size); +int symbol_sort(t_list **syms, t_flag flag); +int symbol_filter(t_list **syms, t_flag flag); +int is_external(t_symbol *s); +int is_not_external(t_symbol *s); +int symbol_format(t_symbol *symbol, t_nmdata *data); +void *get_section(void *file, char *segname, + char *sectname); +void mach_parse(t_machodata *data); + +void nm_mach(struct mach_header *file, + t_nmdata *data); +void otool_mach(void *file, t_otooldata *data); + +#endif diff --git a/nm-otool/includes/mach_64.h b/nm-otool/includes/mach_64.h index 77d08c88..edd41aa4 100644 --- a/nm-otool/includes/mach_64.h +++ b/nm-otool/includes/mach_64.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/26 18:39:31 by jhalford #+# #+# */ -/* Updated: 2017/10/26 18:43:32 by jhalford ### ########.fr */ +/* Updated: 2017/10/30 12:22:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,12 @@ int symbol_64_filter(t_list **syms, t_flag flag); int is_external_64(t_symbol_64 *s); int is_not_external_64(t_symbol_64 *s); int symbol_64_format(t_symbol_64 *symbol, t_nmdata *data); -void mach_64_dump(struct mach_header_64 *file, +void *get_section_64(void *file, char *segname, + char *sectname); +void mach_64_parse(t_machodata *data); + +void nm_mach_64(struct mach_header_64 *file, t_nmdata *data); +void otool_mach_64(void *file, t_otooldata *data); #endif diff --git a/nm-otool/libft/includes/cliopts.h b/nm-otool/libft/includes/cliopts.h index 31eecca6..2184debe 100644 --- a/nm-otool/libft/includes/cliopts.h +++ b/nm-otool/libft/includes/cliopts.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */ -/* Updated: 2017/10/07 18:04:53 by jhalford ### ########.fr */ +/* Updated: 2017/10/30 11:54:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/libft/includes/error.h b/nm-otool/libft/includes/error.h index 3780ad8f..b70a1020 100644 --- a/nm-otool/libft/includes/error.h +++ b/nm-otool/libft/includes/error.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */ -/* Updated: 2017/05/15 17:37:29 by ariard ### ########.fr */ +/* Updated: 2017/10/30 10:06:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ */ # define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}" # define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__ -# define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__) +# define DG(s, ...) ft_dprintf(STDERR,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__) /* ** DEBUG with no malloc diff --git a/nm-otool/libft/includes/libft.h b/nm-otool/libft/includes/libft.h index 1b4b5402..62d9e52f 100644 --- a/nm-otool/libft/includes/libft.h +++ b/nm-otool/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2017/10/07 18:07:31 by jhalford ### ########.fr */ +/* Updated: 2017/10/30 11:25:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -89,7 +89,8 @@ int ft_putendl_fd(char const *s, int fd); int ft_putnbr_fd(long n, int fd); int ft_putnbr_hex_fd(long n, int fd); -void *hexdump(void *addr, unsigned int offset, unsigned int size); +void *hexdump(void *addr, uint32_t offset, uint32_t size); +void *hexdump_64(void *addr, uint64_t offset, uint64_t size); void *ft_realloc(void *data, int size); diff --git a/nm-otool/libft/srcs/printing/hexdump.c b/nm-otool/libft/srcs/printing/hexdump.c index de933085..0482145a 100644 --- a/nm-otool/libft/srcs/printing/hexdump.c +++ b/nm-otool/libft/srcs/printing/hexdump.c @@ -6,21 +6,21 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/07 17:56:14 by jhalford #+# #+# */ -/* Updated: 2017/10/07 17:56:40 by jhalford ### ########.fr */ +/* Updated: 2017/10/30 11:25:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "libft.h" -static void print_hex_contents(void *addr, unsigned int size) +static void print_hex_contents(void *addr, uint64_t size) { void *a; a = addr; while (a - addr < 16) { - if ((a - addr) >= size) + if ((uint64_t)(a - addr) >= size) break ; else ft_printf("%02x", *(unsigned char*)a); @@ -29,17 +29,35 @@ static void print_hex_contents(void *addr, unsigned int size) } } -void *hexdump(void *addr, unsigned int offset, unsigned int size) +void *hexdump(void *addr, uint32_t offset, uint32_t size) { void *a; - addr += offset; + /* addr += offset; */ a = addr; if (addr == NULL) return (addr); - while ((a - addr) < size) + while ((uint32_t)(a - addr) < size) { - ft_printf("%0*llx\t", 16, (a - addr) + (unsigned long)offset); + ft_printf("%08llx\t", (a - addr) + offset); + print_hex_contents(a, (uint64_t)(size - (a - addr))); + ft_putchar('\n'); + a += 16; + } + return (addr); +} + +void *hexdump_64(void *addr, uint64_t offset, uint64_t size) +{ + void *a; + + /* addr += offset; */ + a = addr; + if (addr == NULL) + return (addr); + while ((uint64_t)(a - addr) < size) + { + ft_printf("%016llx\t", (a - addr) + offset); print_hex_contents(a, (size - (a - addr))); ft_putchar('\n'); a += 16; diff --git a/nm-otool/otooldiff.sh b/nm-otool/otooldiff.sh new file mode 100755 index 00000000..202109b8 --- /dev/null +++ b/nm-otool/otooldiff.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env zsh +make +diff <(./ft_otool $@) <(otool -t $@) +if [ $? -eq 0 ]; then + echo "OK ✅" +else + echo "ERROR ❎" +fi diff --git a/nm-otool/srcs/ft_nm.c b/nm-otool/srcs/ft_nm.c index 8139a656..fe01b787 100644 --- a/nm-otool/srcs/ft_nm.c +++ b/nm-otool/srcs/ft_nm.c @@ -6,12 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 03:09:12 by jhalford #+# #+# */ -/* Updated: 2017/10/26 18:46:22 by jhalford ### ########.fr */ +/* Updated: 2017/10/30 12:26:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_nm_otool.h" -#define NM_USAGE "usage: nm [-agmnpruU]" +#define NM_USAGE "usage: nm [-agmnpruU] filename ..." t_machodata *g_data = NULL; @@ -41,9 +41,9 @@ int nm_file(void *file, t_nmdata *data) magic = *(int*)file; if (IS_MACH_32(magic)) - mach_64_dump(file, data); + nm_mach(file, data); else if (IS_MACH_64(magic)) - mach_64_dump(file, data); + nm_mach_64(file, data); else if (IS_FAT(magic)) ft_printf("{red}unsupported arch:{eoc} magic=%#x(FAT)\n", magic); else diff --git a/nm-otool/srcs/ft_otool.c b/nm-otool/srcs/ft_otool.c index 10cefb19..25883f24 100644 --- a/nm-otool/srcs/ft_otool.c +++ b/nm-otool/srcs/ft_otool.c @@ -6,79 +6,70 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/20 14:08:14 by jhalford #+# #+# */ -/* Updated: 2017/10/23 16:37:45 by jhalford ### ########.fr */ +/* Updated: 2017/10/30 12:26:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_nm_otool.h" +#define OTOOL_USAGE "usage: otool [-dt] filename ..." -void *get_text_section(void *file) +t_cliopts g_otool_opts[] = { - uint32_t i; - uint32_t j; - struct load_command *lc; - struct segment_command_64 *seg; - struct section_64 *sect; + {'t', NULL, OTOOL_TEXT, 0, NULL, 0}, + {'d', NULL, OTOOL_DATA, 0, NULL, 0}, +}; - lc = (void*)((struct mach_header_64*)file + 1); - i = -1; - while (++i < ((struct mach_header_64*)file)->ncmds) - { - if (lc->cmd & LC_SEGMENT_64) - { - seg = (struct segment_command_64*)lc; - sect = (void*)(seg + 1); - j = -1; - while (++j < seg->nsects) - { - if (ft_strcmp(sect->sectname, "__text") == 0) - return (sect); - sect = sect + 1; - } - } - lc = (void*)lc + lc->cmdsize; - } - return (NULL); -} - -void otool(void *file) +void otool_file(void *file, t_otooldata *data) { uint32_t magic; - struct section_64 *sect; magic = *(int *)file; - if (IS_FAT(magic)) - ft_printf("fat binary not supported yet\n"); + if (IS_MACH_32(magic)) + otool_mach(file, data); else if (IS_MACH_64(magic)) - { - sect = get_text_section(file); - ft_printf("Contents of (__TEXT,__text) section\n"); - hexdump(file, sect->offset, sect->size); - } + otool_mach_64(file, data); + else if (IS_FAT(magic)) + ft_printf("fat binary not supported yet\n"); else ft_printf("{red}unsupported architecture:{eoc} magic = %#x\n", magic); } -int main(int ac, char **av) +int otool(int ac, char **av, t_otooldata data) { - int fd; - char *file; - struct stat buf; + int i; + struct stat buf; + int fd; + char *file; - if (ac != 2) + i = data.av_data - av; + while (i < ac && av[i]) { - ft_dprintf(2, "USAGE PLACEHOLDER\n"); - return (1); + if (!(data.flag & NM_OFORMAT) && ac - (data.av_data - av) > 1) + ft_printf("%s:\n", av[i]); + if ((fd = open((av[i]), O_RDONLY)) < 0) + return (1); + if ((fstat(fd, &buf)) < 0) + return (1); + if ((file = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) + == MAP_FAILED) + return (1); + otool_file(file, &data); + if (munmap(file, buf.st_size)) + return (1); + i++; } - if ((fd = open(av[1], O_RDONLY)) < 0) - return (1); - if ((fstat(fd, &buf)) < 0) - return (1); - if ((file = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) - == MAP_FAILED) - return (1); - otool(file); - if (munmap(file, buf.st_size)) - return (1); return (0); } + +int main(int ac, char **av) +{ + t_otooldata data; + + if (cliopts_get(av, g_otool_opts, &data)) + { + ft_perror("ft_otool"); + ft_dprintf(2, OTOOL_USAGE"\n"); + return (1); + } + return (otool(ac, av, data)); +} diff --git a/nm-otool/srcs/mach/get_section.c b/nm-otool/srcs/mach/get_section.c new file mode 100644 index 00000000..480ec801 --- /dev/null +++ b/nm-otool/srcs/mach/get_section.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_section.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/30 11:00:40 by jhalford #+# #+# */ +/* Updated: 2017/10/30 12:18:02 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +void *get_segment(void *file, char *lookup) +{ + uint32_t i; + struct load_command *lc; + struct segment_command *seg; + + lc = (void*)((struct mach_header*)file + 1); + i = -1; + while (++i < ((struct mach_header*)file)->ncmds) + { + if (lc->cmd & LC_SEGMENT) + { + seg = (struct segment_command*)lc; + if (ft_strcmp(seg->segname, lookup) == 0) + return (seg); + } + lc = (void*)lc + lc->cmdsize; + } + return (NULL); +} + +void *get_section(void *file, char *segname, char *sectname) +{ + uint32_t j; + struct segment_command *seg; + struct section *sect; + + seg = get_segment(file, segname); + sect = (void*)(seg + 1); + j = -1; + while (++j < seg->nsects) + { + if (ft_strcmp(sect->sectname, sectname) == 0) + return (sect); + sect = sect + 1; + } + return (NULL); +} diff --git a/nm-otool/srcs/mach/mach.c b/nm-otool/srcs/mach/mach.c new file mode 100644 index 00000000..66e66ebe --- /dev/null +++ b/nm-otool/srcs/mach/mach.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mach.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/23 16:06:44 by jhalford #+# #+# */ +/* Updated: 2017/10/30 11:32:11 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +static void symtab_parse(t_machodata *data, struct symtab_command *symtab) +{ + int i; + t_symbol symbol; + char *stringtable; + struct nlist *array; + + data->symtab = symtab; + stringtable = data->file + symtab->stroff; + array = (struct nlist*)(data->file + symtab->symoff); + i = -1; + while (++i < (int)symtab->nsyms) + { + symbol_init(&symbol, stringtable, array, i); + symbol_set(&symbol, data); + ft_lsteadd(&data->symbols, ft_lstnew(&symbol, sizeof(symbol))); + } +} + +static void seg_parse(t_machodata *data, struct segment_command *seg) +{ + uint32_t nsects; + uint32_t i; + struct section *sect; + + nsects = seg->nsects; + sect = (void*)(seg + 1); + i = -1; + while (++i < nsects) + { + ft_lsteadd(&data->sects, ft_lstnew(§, sizeof(sect))); + sect = sect + 1; + } +} + +void mach_parse(t_machodata *data) +{ + uint32_t ncmds; + uint32_t i; + struct load_command *lc; + struct mach_header *header; + + header = data->file; + ncmds = header->ncmds; + lc = (void*)(header + 1); + i = -1; + while (++i < ncmds) + { + if (lc->cmd == LC_SYMTAB) + symtab_parse(data, (struct symtab_command*)lc); + else if (lc->cmd == LC_DYSYMTAB) + data->dysymtab = (struct dysymtab_command*)lc; + else if (lc->cmd == LC_SEGMENT) + seg_parse(data, (struct segment_command*)lc); + lc = (void*)lc + lc->cmdsize; + } +} diff --git a/nm-otool/srcs/mach/nm_mach.c b/nm-otool/srcs/mach/nm_mach.c new file mode 100644 index 00000000..b87bf1a8 --- /dev/null +++ b/nm-otool/srcs/mach/nm_mach.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* nm_mach.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/30 11:03:04 by jhalford #+# #+# */ +/* Updated: 2017/10/30 11:31:38 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +void nm_mach(struct mach_header *file, t_nmdata *data) +{ + t_machodata mach; + + mach.sects = NULL; + mach.symbols = NULL; + mach.file = file; + mach_parse(&mach); + symbol_sort(&mach.symbols, data->flag); + symbol_filter(&mach.symbols, data->flag); + ft_lstiter(mach.symbols, symbol_format, data); +} diff --git a/nm-otool/srcs/mach/otool_mach.c b/nm-otool/srcs/mach/otool_mach.c new file mode 100644 index 00000000..4188921c --- /dev/null +++ b/nm-otool/srcs/mach/otool_mach.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* otool_mach.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/30 11:04:06 by jhalford #+# #+# */ +/* Updated: 2017/10/30 12:16:36 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +void otool_mach(void *file, t_otooldata *data) +{ + struct section *sect; + + if (data->flag & OTOOL_TEXT) + { + if ((sect = get_section(file, SEG_TEXT, SECT_TEXT))) + { + ft_printf("Contents of (%s,%s) section\n", SEG_TEXT, SECT_TEXT); + hexdump(file + sect->offset, sect->addr, sect->size); + } + } + if (data->flag & OTOOL_DATA) + { + if ((sect = get_section(file, SEG_DATA, SECT_DATA))) + { + ft_printf("Contents of (%s,%s) section\n", SEG_DATA, SECT_DATA); + hexdump(file + sect->offset, sect->addr, sect->size); + } + } +} diff --git a/nm-otool/srcs/mach/symbol_filter.c b/nm-otool/srcs/mach/symbol_filter.c new file mode 100644 index 00000000..315a3540 --- /dev/null +++ b/nm-otool/srcs/mach/symbol_filter.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* symbol_filter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/26 18:31:27 by jhalford #+# #+# */ +/* Updated: 2017/10/26 18:44:51 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +int cmp_symtype(t_symbol *sym, void *type) +{ + return ((1 << sym->type) & *(uint64_t*)type); +} + +inline int is_not_external(t_symbol *s) +{ + return (!(s->nlist->n_type & N_EXT)); +} + +inline int is_external(t_symbol *s) +{ + return (s->nlist->n_type & N_EXT); +} + +int symbol_filter(t_list **symbols, t_flag flag) +{ + uint64_t allowed_syms; + + allowed_syms = ~(1 << SYM_STAB); + if (flag & NM_ALL) + allowed_syms |= (1 << SYM_STAB); + if (flag & NM_NO_UNDF) + allowed_syms &= ~(1 << SYM_UNDF); + if (flag & NM_ONLY_UNDF) + allowed_syms &= (1 << SYM_UNDF); + ft_lst_filterout(symbols, &allowed_syms, cmp_symtype, symbol_free); + if (flag & NM_NO_LOCAL) + ft_lst_filterout(symbols, NULL, is_external, symbol_free); + return (0); +} diff --git a/nm-otool/srcs/mach/symbol_format.c b/nm-otool/srcs/mach/symbol_format.c new file mode 100644 index 00000000..f087a291 --- /dev/null +++ b/nm-otool/srcs/mach/symbol_format.c @@ -0,0 +1,88 @@ +#include "ft_nm_otool.h" + +t_symbolmap g_symbolmap[] = +{ + {'U', "undefined"}, + {'A', "absolute"}, + {'T', "segname missing"}, + {'D', "segname missing"}, + {'B', "segname missing"}, + {'C', "common"}, + {'-', "?"}, + {'S', "segname missing"}, + {'I', "indirect"}, +}; + +void symbol_format_desc(t_symbol *symbol) +{ + if (symbol->nlist->n_desc & REFERENCED_DYNAMICALLY) + ft_printf(" [referenced dynamically]"); + if (is_external(symbol)) + ft_printf(" external"); + else + { + ft_printf(" non-external"); + if (symbol->nlist->n_type & N_PEXT) + ft_printf(" (was a private external)"); + } +} + +void symbol_format_m(t_symbol *symbol) +{ + t_symbolmap map; + + map = g_symbolmap[symbol->type]; + ft_printf(" (%s%c%s)", + symbol->section ? symbol->section->segname : map.s, + symbol->section ? ',' : 0, + symbol->section ? symbol->section->sectname : ""); + symbol_format_desc(symbol); +} + +void symbol_format_full(t_symbol *symbol) +{ + ft_printf("\t%i %03b|%b|%x|%b \t%i(%s) \t%04x", + 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_sect, symbol->section->sectname, + symbol->nlist->n_desc); +} + +void symbol_format_dfl(t_symbol *symbol) +{ + t_symbolmap map; + + map = g_symbolmap[symbol->type]; + if (is_external(symbol)) + ft_printf(" %c", map.c); + else + ft_printf(" %c", map.c + 'a' - 'A'); + if (symbol->type == SYM_STAB) + ft_printf(" %02x %04b %#x", + symbol->nlist->n_sect, symbol->nlist->n_desc, + symbol->nlist->n_type); +} + +int symbol_format(t_symbol *symbol, t_nmdata *data) +{ + if (data->flag & NM_OFORMAT) + ft_printf("%s: ", data->filename); + if (!(data->flag & NM_ONLY_UNDF)) + { + if (symbol->type == SYM_UNDF) + ft_printf("%8s", " "); + else + ft_printf("%08llx", symbol->nlist->n_value); + if (data->flag & NM_MFORMAT) + symbol_format_m(symbol); + else if (data->flag & NM_FULL) + symbol_format_full(symbol); + else + symbol_format_dfl(symbol); + } + ft_printf(" %s\n", symbol->string); + return (0); +} diff --git a/nm-otool/srcs/mach/symbol_free.c b/nm-otool/srcs/mach/symbol_free.c new file mode 100644 index 00000000..6905fdac --- /dev/null +++ b/nm-otool/srcs/mach/symbol_free.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* symbol_free.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/26 17:06:23 by jhalford #+# #+# */ +/* Updated: 2017/10/26 18:38:31 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +void symbol_free(void *data, size_t size) +{ + t_symbol *symbol; + + symbol = data; + (void)size; + if (symbol) + free(symbol); +} diff --git a/nm-otool/srcs/mach/symbol_init.c b/nm-otool/srcs/mach/symbol_init.c new file mode 100644 index 00000000..e429219f --- /dev/null +++ b/nm-otool/srcs/mach/symbol_init.c @@ -0,0 +1,66 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* symbol_init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/26 18:07:28 by jhalford #+# #+# */ +/* Updated: 2017/10/26 18:23:24 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +t_machodata *g_data; + +int symbol_init(t_symbol *symbol, + char *stringtable, struct nlist *array, int i) +{ + symbol->type = 0; + symbol->pos = i; + symbol->nlist = array + i; + symbol->string = stringtable + array[i].n_un.n_strx; + return (0); +} + +static int symbol_gettype(int type_mask, + struct nlist *nlist, struct section *section) +{ + if (nlist->n_type & N_STAB) + return (SYM_STAB); + else if (type_mask == N_UNDF && nlist->n_type & N_EXT && nlist->n_value) + return (SYM_COMMON); + else if (type_mask == N_UNDF) + return (SYM_UNDF); + else if (type_mask == N_ABS) + return (SYM_ABS); + else if (type_mask == N_SECT && ft_strequ("__text", section->sectname)) + return (SYM_TEXT); + else if (type_mask == N_SECT && ft_strequ("__data", section->sectname)) + return (SYM_DATA); + else if (type_mask == N_SECT && ft_strequ("__bss", section->sectname)) + return (SYM_BSS); + else if (type_mask == N_INDR) + return (SYM_INDR); + else + return (SYM_OTHER); +} + +int symbol_set(t_symbol *sym, t_machodata *data) +{ + t_list *lst; + + if (sym->nlist->n_sect) + { + lst = ft_lst_at(data->sects, sym->nlist->n_sect - 1); + sym->section = *(struct section**)(lst->content); + } + else + sym->section = NULL; + sym->type = symbol_gettype( + sym->nlist->n_type & N_TYPE, + sym->nlist, + sym->section); + return (0); +} diff --git a/nm-otool/srcs/mach/symbol_sort.c b/nm-otool/srcs/mach/symbol_sort.c new file mode 100644 index 00000000..25ba55ae --- /dev/null +++ b/nm-otool/srcs/mach/symbol_sort.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* symbol_sort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/27 20:33:02 by jhalford #+# #+# */ +/* Updated: 2017/10/26 18:46:04 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +static int sym_asort(t_symbol *sym1, t_symbol *sym2) +{ + return (ft_strcmp(sym1->string, sym2->string)); +} + +static int sym_nsort(t_symbol *sym1, t_symbol *sym2) +{ + if (sym1->nlist->n_value == sym2->nlist->n_value) + return (sym_asort(sym1, sym2)); + return (sym1->nlist->n_value > sym2->nlist->n_value ? 1 : -1); +} + +int symbol_sort(t_list **syms, t_flag flag) +{ + if (!(flag & NM_NOSORT)) + { + if (flag & NM_ASORT) + ft_lstsort(syms, sym_asort); + else if (flag & NM_NSORT) + ft_lstsort(syms, sym_nsort); + if (flag & NM_RSORT) + ft_lst_reverse(syms); + } + return (0); +} diff --git a/nm-otool/srcs/mach_64/get_section_64.c b/nm-otool/srcs/mach_64/get_section_64.c new file mode 100644 index 00000000..ca857d5c --- /dev/null +++ b/nm-otool/srcs/mach_64/get_section_64.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_section_64.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/30 11:00:40 by jhalford #+# #+# */ +/* Updated: 2017/10/30 12:18:02 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +void *get_segment_64(void *file, char *lookup) +{ + uint32_t i; + struct load_command *lc; + struct segment_command_64 *seg; + + lc = (void*)((struct mach_header_64*)file + 1); + i = -1; + while (++i < ((struct mach_header_64*)file)->ncmds) + { + if (lc->cmd & LC_SEGMENT_64) + { + seg = (struct segment_command_64*)lc; + if (ft_strcmp(seg->segname, lookup) == 0) + return (seg); + } + lc = (void*)lc + lc->cmdsize; + } + return (NULL); +} + +void *get_section_64(void *file, char *segname, char *sectname) +{ + uint32_t j; + struct segment_command_64 *seg; + struct section_64 *sect; + + seg = get_segment_64(file, segname); + sect = (void*)(seg + 1); + j = -1; + while (++j < seg->nsects) + { + if (ft_strcmp(sect->sectname, sectname) == 0) + return (sect); + sect = sect + 1; + } + return (NULL); +} diff --git a/nm-otool/srcs/mach_64/mach_64.c b/nm-otool/srcs/mach_64/mach_64.c index fccdd902..33c813ab 100644 --- a/nm-otool/srcs/mach_64/mach_64.c +++ b/nm-otool/srcs/mach_64/mach_64.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/23 16:06:44 by jhalford #+# #+# */ -/* Updated: 2017/10/26 18:45:25 by jhalford ### ########.fr */ +/* Updated: 2017/10/30 11:32:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,16 +69,3 @@ void mach_64_parse(t_machodata *data) lc = (void*)lc + lc->cmdsize; } } - -void mach_64_dump(struct mach_header_64 *file, t_nmdata *data) -{ - t_machodata mach; - - mach.sects = NULL; - mach.symbols = NULL; - mach.file = file; - mach_64_parse(&mach); - symbol_64_sort(&mach.symbols, data->flag); - symbol_64_filter(&mach.symbols, data->flag); - ft_lstiter(mach.symbols, symbol_64_format, data); -} diff --git a/nm-otool/srcs/mach_64/nm_mach_64.c b/nm-otool/srcs/mach_64/nm_mach_64.c new file mode 100644 index 00000000..79adbab2 --- /dev/null +++ b/nm-otool/srcs/mach_64/nm_mach_64.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* nm_mach_64.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/30 11:03:04 by jhalford #+# #+# */ +/* Updated: 2017/10/30 11:35:53 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +void nm_mach_64(struct mach_header_64 *file, t_nmdata *data) +{ + t_machodata mach; + + mach.sects = NULL; + mach.symbols = NULL; + mach.file = file; + mach_64_parse(&mach); + symbol_64_sort(&mach.symbols, data->flag); + symbol_64_filter(&mach.symbols, data->flag); + ft_lstiter(mach.symbols, symbol_64_format, data); +} diff --git a/nm-otool/srcs/mach_64/otool_mach_64.c b/nm-otool/srcs/mach_64/otool_mach_64.c new file mode 100644 index 00000000..63b75fb8 --- /dev/null +++ b/nm-otool/srcs/mach_64/otool_mach_64.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* otool_mach_64.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/30 11:04:06 by jhalford #+# #+# */ +/* Updated: 2017/10/30 12:16:36 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +void otool_mach_64(void *file, t_otooldata *data) +{ + struct section_64 *sect; + + if (data->flag & OTOOL_TEXT) + { + if ((sect = get_section_64(file, SEG_TEXT, SECT_TEXT))) + { + ft_printf("Contents of (%s,%s) section\n", SEG_TEXT, SECT_TEXT); + hexdump_64(file + sect->offset, sect->addr, sect->size); + } + } + if (data->flag & OTOOL_DATA) + { + if ((sect = get_section_64(file, SEG_DATA, SECT_DATA))) + { + ft_printf("Contents of (%s,%s) section\n", SEG_DATA, SECT_DATA); + hexdump_64(file + sect->offset, sect->addr, sect->size); + } + } +} diff --git a/nm-otool/srcs/mach_64/symbol_64_format.c b/nm-otool/srcs/mach_64/symbol_64_format.c index 9c0e8f19..34dae43a 100644 --- a/nm-otool/srcs/mach_64/symbol_64_format.c +++ b/nm-otool/srcs/mach_64/symbol_64_format.c @@ -1,6 +1,6 @@ #include "ft_nm_otool.h" -t_symbolmap g_symbolmap[] = +t_symbolmap g_symbolmap_64[] = { {'U', "undefined"}, {'A', "absolute"}, @@ -31,7 +31,7 @@ void symbol_64_format_m(t_symbol_64 *symbol) { t_symbolmap map; - map = g_symbolmap[symbol->type]; + map = g_symbolmap_64[symbol->type]; ft_printf(" (%s%c%s)", symbol->section ? symbol->section->segname : map.s, symbol->section ? ',' : 0, @@ -55,7 +55,7 @@ void symbol_64_format_dfl(t_symbol_64 *symbol) { t_symbolmap map; - map = g_symbolmap[symbol->type]; + map = g_symbolmap_64[symbol->type]; if (is_external_64(symbol)) ft_printf(" %c", map.c); else