diff --git a/nm-otool/includes/ft_nm.h b/nm-otool/includes/ft_nm.h index d5dc6f4e..ea8107c1 100644 --- a/nm-otool/includes/ft_nm.h +++ b/nm-otool/includes/ft_nm.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 11:44:40 by jhalford #+# #+# */ -/* Updated: 2017/11/07 11:57:35 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 16:02:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,6 +52,7 @@ # define NM_OFORMAT (1 << 9) # define NM_MFORMAT (1 << 10) +typedef struct s_fdata t_fdata; typedef enum e_symtype t_symtype; typedef struct s_symbolmap t_symbolmap; typedef struct s_machodata t_machodata; diff --git a/nm-otool/includes/ft_nm_otool.h b/nm-otool/includes/ft_nm_otool.h index ae568324..da29185d 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/11/07 15:13:41 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 16:02:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,14 +26,21 @@ # include # include -typedef unsigned int t_u; +# include "ft_nm.h" +# include "ft_otool.h" + +# include "mach_64.h" +# include "mach.h" +# include "ppc.h" + typedef struct s_fdata t_fdata; +typedef unsigned int t_u; # define IS_MACH_64(x) (*(t_u*)x == MH_MAGIC_64||*(t_u*)x == MH_CIGAM_64) # define IS_MACH_32(x) (*(t_u*)x == MH_MAGIC||*(t_u*)x == MH_CIGAM) # define IS_FAT(x) (*(t_u*)x == FAT_MAGIC||*(t_u*)x == FAT_CIGAM) # define IS_REV(x) ({t_u m=*(t_u*)x;m==MH_CIGAM||m==MH_CIGAM_64||m==FAT_CIGAM;}) -# define MC(ptr) memcheck(data->file, ptr, sizeof(ptr), __FUNCTION__, __LINE__) +# define MC(ptr) memcheck(data->file, ptr, sizeof(ptr)) struct s_fdata { @@ -44,17 +51,8 @@ struct s_fdata char *filename; }; -# include "ft_nm.h" -# include "ft_otool.h" - -# include "mach_64.h" -# include "mach.h" -# include "ppc.h" - -uint64_t endian(uint64_t n, uint8_t size); - void *fat_extract(struct fat_header *fat, char *aname); -/* void memcheck(t_fdata *file, void *ptr, size_t size); */ -void memcheck(t_fdata *file, void *ptr, size_t size, const char *function, int line); +uint64_t endian(uint64_t n, uint8_t size); +void memcheck(t_fdata *file, void *ptr, size_t size); #endif diff --git a/nm-otool/includes/mach.h b/nm-otool/includes/mach.h index 1ded12e9..4a97ff01 100644 --- a/nm-otool/includes/mach.h +++ b/nm-otool/includes/mach.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* mach.h :+: :+: :+: */ +/* mach.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/26 18:39:31 by jhalford #+# #+# */ -/* Updated: 2017/11/07 15:26:18 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 16:02:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,13 +14,14 @@ # define MACH_H typedef struct s_symbol t_symbol; +typedef struct s_fdata t_fdata; struct s_symbol { - int pos; - t_symtype type; - char *string; - struct nlist nlist; + int pos; + t_symtype type; + char *string; + struct nlist nlist; struct section *section; }; diff --git a/nm-otool/includes/mach_64.h b/nm-otool/includes/mach_64.h index 2019645f..74bf0563 100644 --- a/nm-otool/includes/mach_64.h +++ b/nm-otool/includes/mach_64.h @@ -6,13 +6,14 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/26 18:39:31 by jhalford #+# #+# */ -/* Updated: 2017/11/07 15:26:18 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 16:01:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MACH_64_H # define MACH_64_H +typedef struct s_fdata t_fdata; typedef struct s_symbol_64 t_symbol_64; struct s_symbol_64 diff --git a/nm-otool/srcs/fat.c b/nm-otool/srcs/fat.c index c2fd1b20..798793bb 100644 --- a/nm-otool/srcs/fat.c +++ b/nm-otool/srcs/fat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 16:31:48 by jhalford #+# #+# */ -/* Updated: 2017/11/07 14:29:26 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 15:55:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,8 @@ void *fat_extract(struct fat_header *fat, char *aname) { - uint32_t narch; - struct fat_arch *obj; + uint32_t narch; + struct fat_arch *obj; const NXArchInfo *arch; narch = endian(fat->nfat_arch, 32); diff --git a/nm-otool/srcs/mach/get_section.c b/nm-otool/srcs/mach/get_section.c index f3d6c4cb..58cde991 100644 --- a/nm-otool/srcs/mach/get_section.c +++ b/nm-otool/srcs/mach/get_section.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* get_section.c :+: :+: :+: */ +/* get_section.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 11:00:40 by jhalford #+# #+# */ -/* Updated: 2017/11/07 15:26:47 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 15:55:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,10 @@ void *get_segment(t_machodata *data, char *lookup) { - uint32_t i; - struct load_command *lc; + uint32_t i; + struct load_command *lc; struct segment_command *seg; - uint32_t ncmds; + uint32_t ncmds; MC(lc = (void*)((struct mach_header*)data->file->file + 1)); i = -1; @@ -37,9 +37,9 @@ void *get_segment(t_machodata *data, char *lookup) void *get_section(t_machodata *data, char *lookup) { - uint32_t i; - uint32_t j; - struct load_command *lc; + uint32_t i; + uint32_t j; + struct load_command *lc; struct segment_command *seg; struct section *sect; diff --git a/nm-otool/srcs/mach/mach.c b/nm-otool/srcs/mach/mach.c index 7c9395e4..11f1a549 100644 --- a/nm-otool/srcs/mach/mach.c +++ b/nm-otool/srcs/mach/mach.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* mach.c :+: :+: :+: */ +/* mach.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/23 16:06:44 by jhalford #+# #+# */ -/* Updated: 2017/11/07 15:29:43 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 15:56:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,8 +35,8 @@ static void symtab_parse(t_machodata *data, struct symtab_command *symtab) static void seg_parse(t_machodata *data, struct segment_command *seg) { - uint32_t nsects; - uint32_t i; + uint32_t nsects; + uint32_t i; struct section *sect; nsects = endian(seg->nsects, 32); @@ -51,9 +51,9 @@ static void seg_parse(t_machodata *data, struct segment_command *seg) void mach_parse(t_machodata *data) { - uint32_t ncmds; - uint32_t i; - struct load_command *lc; + uint32_t ncmds; + uint32_t i; + struct load_command *lc; struct mach_header *header; header = data->file->file; diff --git a/nm-otool/srcs/mach/otool_mach.c b/nm-otool/srcs/mach/otool_mach.c index d48f8b05..89535865 100644 --- a/nm-otool/srcs/mach/otool_mach.c +++ b/nm-otool/srcs/mach/otool_mach.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* otool_mach.c :+: :+: :+: */ +/* otool_mach.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 11:04:06 by jhalford #+# #+# */ -/* Updated: 2017/11/07 15:27:26 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 15:55:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ extern int g_rev; void otool_mach(t_fdata *data) { struct section *sect; - t_machodata mach; + t_machodata mach; mach.file = data; if (data->flag & OTOOL_TEXT) diff --git a/nm-otool/srcs/mach/symbol_filter.c b/nm-otool/srcs/mach/symbol_filter.c index 9d7f71fb..e19803f1 100644 --- a/nm-otool/srcs/mach/symbol_filter.c +++ b/nm-otool/srcs/mach/symbol_filter.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* symbol_filter.c :+: :+: :+: */ +/* symbol_filter.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/26 18:31:27 by jhalford #+# #+# */ -/* Updated: 2017/10/31 16:36:55 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 15:56:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/srcs/mach/symbol_format.c b/nm-otool/srcs/mach/symbol_format.c index 08983141..175ab93f 100644 --- a/nm-otool/srcs/mach/symbol_format.c +++ b/nm-otool/srcs/mach/symbol_format.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* symbol_format.c :+: :+: :+: */ +/* symbol_format.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/11/01 12:37:07 by jhalford #+# #+# */ -/* Updated: 2017/11/07 13:57:06 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 15:56:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/srcs/mach/symbol_init.c b/nm-otool/srcs/mach/symbol_init.c index 760627d9..f87bfaa7 100644 --- a/nm-otool/srcs/mach/symbol_init.c +++ b/nm-otool/srcs/mach/symbol_init.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* symbol_init.c :+: :+: :+: */ +/* symbol_init.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/26 18:07:28 by jhalford #+# #+# */ -/* Updated: 2017/11/07 15:30:01 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 15:56:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/srcs/mach_64/mach_64.c b/nm-otool/srcs/mach_64/mach_64.c index 7fa768c8..2f43a4e6 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/11/07 15:29:43 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 15:57:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,8 @@ static void symtab_64_parse(t_machodata *data, struct symtab_command *symtab) data->symtab = symtab; MC(stringtable = data->file->file + endian(symtab->stroff, 32)); - MC(array = (struct nlist_64*)(data->file->file + endian(symtab->symoff, 32))); + MC(array = (struct nlist_64*)(data->file->file + + endian(symtab->symoff, 32))); nsyms = endian(symtab->nsyms, 32); i = -1; while (++i < nsyms) diff --git a/nm-otool/srcs/memcheck.c b/nm-otool/srcs/memcheck.c index 588dd1e4..6feb4bd7 100644 --- a/nm-otool/srcs/memcheck.c +++ b/nm-otool/srcs/memcheck.c @@ -6,19 +6,17 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/11/07 11:24:09 by jhalford #+# #+# */ -/* Updated: 2017/11/07 15:19:34 by jhalford ### ########.fr */ +/* Updated: 2017/11/07 15:57:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_nm_otool.h" -void memcheck(t_fdata *file, void *ptr, size_t size, const char *function, int line) +void memcheck(t_fdata *file, void *ptr, size_t size) { if (ptr <= file->file || (ptr + size) >= file->eof) { - ft_dprintf(2, "%s:%i ", function, line); ft_dprintf(2, "%s: is corrupted\n", file->filename); - ft_dprintf(2, "%p - %p (%zu) - %p --> %zu after end\n", file->file, ptr, size, file->eof, ptr - file->eof); exit(1); } }