diff --git a/nm-otool/Makefile b/nm-otool/Makefile index 20284f03..ad3c9049 100644 --- a/nm-otool/Makefile +++ b/nm-otool/Makefile @@ -34,8 +34,6 @@ NM_OBJ = $(OBJ_DIR)ft_nm.o OTOOL_OBJ = $(OBJ_DIR)ft_otool.o SRC_BASE = \ -bswap.c\ -dump_symtab.c\ endianness.c\ fat.c\ ft_nm.c\ @@ -57,7 +55,8 @@ 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 +mach_64/symbol_64_sort.c\ +ppc/otool_ppc.c SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) OBJS = $(addprefix $(OBJ_DIR), $($(notdir SRC_BASE):.c=.o)) diff --git a/nm-otool/includes/ft_nm.h b/nm-otool/includes/ft_nm.h index 6490aecd..56caab6f 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/10/30 12:00:49 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:19:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,4 +92,6 @@ struct s_symbolmap char *s; }; +void nm_single_file(void *file, t_nmdata *data); + #endif diff --git a/nm-otool/includes/ft_nm_otool.h b/nm-otool/includes/ft_nm_otool.h index 2aa924c8..d3cc5e94 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/31 16:03:56 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:20:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,19 +31,18 @@ # include "mach_64.h" # include "mach.h" +# include "ppc.h" -# define IS_MACH_64(x) (*(uint32_t*)x == MH_MAGIC_64 || *(uint32_t*)x == MH_CIGAM_64) -# define IS_MACH_32(x) (*(uint32_t*)x == MH_MAGIC || *(uint32_t*)x == MH_CIGAM) -# define IS_FAT(x) (*(uint32_t*)x == FAT_MAGIC || *(uint32_t*)x == FAT_CIGAM) -# define IS_REV(x) (*(uint32_t*)x == MH_CIGAM || *(uint32_t*)x == MH_CIGAM_64 || *(uint32_t*)x == FAT_CIGAM) +typedef unsigned int t_u; -uint64_t endian(uint64_t n, uint8_t size); -uint8_t bswap_8(uint8_t x); -uint16_t bswap_16(uint16_t x); -uint32_t bswap_32(uint32_t x); -uint64_t bswap_64(uint64_t x); +# 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;}) -void *fat_extract(struct fat_header *fat, +uint64_t endian(uint64_t n, uint8_t size); + +void *fat_extract(struct fat_header *fat, cpu_type_t cputype, cpu_subtype_t cpusubtype); diff --git a/nm-otool/includes/ft_otool.h b/nm-otool/includes/ft_otool.h index 1305b42c..aa2477b1 100644 --- a/nm-otool/includes/ft_otool.h +++ b/nm-otool/includes/ft_otool.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 11:46:23 by jhalford #+# #+# */ -/* Updated: 2017/10/31 19:15:26 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:19:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,4 +30,6 @@ struct s_otooldata char *filename; }; +void otool_single_file(void *file, t_otooldata *data); + #endif diff --git a/nm-otool/includes/mach.h b/nm-otool/includes/mach.h index e0bb12eb..d64ecc9e 100644 --- a/nm-otool/includes/mach.h +++ b/nm-otool/includes/mach.h @@ -1,44 +1,44 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* mach.h :+: :+: :+: */ +/* mach.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/10/26 18:39:31 by jhalford #+# #+# */ -/* Updated: 2017/10/31 16:30:06 by jhalford ### ########.fr */ +/* Created: 2017/11/01 12:03:56 by jhalford #+# #+# */ +/* Updated: 2017/11/01 12:08:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef MACH_H +#ifndef MACH_H # define MACH_H typedef struct s_symbol t_symbol; -struct s_symbol +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; }; -int symbol_init(t_symbol *symbol, +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); +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(struct mach_header *file, + char *lookup); +void mach_parse(t_machodata *data); -void nm_mach(struct mach_header *file, +void nm_mach(struct mach_header *file, t_nmdata *data); -void otool_mach(void *file, t_otooldata *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 5a00a36d..39a7deec 100644 --- a/nm-otool/includes/mach_64.h +++ b/nm-otool/includes/mach_64.h @@ -6,39 +6,39 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/26 18:39:31 by jhalford #+# #+# */ -/* Updated: 2017/10/31 16:30:06 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:08:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef MACH_64_H +#ifndef MACH_64_H # define MACH_64_H typedef struct s_symbol_64 t_symbol_64; -struct s_symbol_64 +struct s_symbol_64 { - int pos; - t_symtype type; - char *string; - struct nlist_64 nlist; - struct section_64 *section; + int pos; + t_symtype type; + char *string; + struct nlist_64 nlist; + struct section_64 *section; }; -int symbol_64_init(t_symbol_64 *symbol, +int symbol_64_init(t_symbol_64 *symbol, char *stringtable, struct nlist_64 *array, int i); -int symbol_64_set(t_symbol_64 *symbol, t_machodata *data); -void symbol_64_free(void *data, size_t size); -int symbol_64_sort(t_list **syms, t_flag flag); -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 *get_section_64(void *file, char *segname, - char *sectname); -void mach_64_parse(t_machodata *data); +int symbol_64_set(t_symbol_64 *symbol, t_machodata *data); +void symbol_64_free(void *data, size_t size); +int symbol_64_sort(t_list **syms, t_flag flag); +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 *get_section_64(struct mach_header_64 *file, + char *lookup); +void mach_64_parse(t_machodata *data); -void nm_mach_64(struct mach_header_64 *file, +void nm_mach_64(struct mach_header_64 *file, t_nmdata *data); -void otool_mach_64(void *file, t_otooldata *data); +void otool_mach_64(void *file, t_otooldata *data); #endif diff --git a/nm-otool/includes/ppc.h b/nm-otool/includes/ppc.h new file mode 100644 index 00000000..197c1f92 --- /dev/null +++ b/nm-otool/includes/ppc.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ppc.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/11/01 11:38:10 by jhalford #+# #+# */ +/* Updated: 2017/11/01 11:38:29 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef PPC_H +# define PPC_H + +void otool_ppc(void *file, t_otooldata *data); + +#endif diff --git a/nm-otool/libft/Makefile b/nm-otool/libft/Makefile index 893f7397..32e48f9d 100644 --- a/nm-otool/libft/Makefile +++ b/nm-otool/libft/Makefile @@ -108,6 +108,7 @@ lst/lst_insert_sort.c\ lst/pop.c\ lst/push.c\ lst/top.c\ +math/bswap.c\ math/ft_addrcmp.c\ math/ft_ilen.c\ math/ft_ilen_base.c\ @@ -144,6 +145,7 @@ printing/ft_putendl.c\ printing/ft_putnbr.c\ printing/ft_putstr.c\ printing/hexdump.c\ +printing/hexdump_int.c\ rs/rs.c\ sstr/ft_sstradd.c\ sstr/ft_sstrcat.c\ diff --git a/nm-otool/libft/includes/libft.h b/nm-otool/libft/includes/libft.h index 62d9e52f..faaecec6 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/30 11:25:37 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:58:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -89,8 +89,11 @@ 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, uint32_t offset, uint32_t size); -void *hexdump_64(void *addr, uint64_t offset, uint64_t size); +void *hexdump(void *addr, uint32_t offset, uint32_t size, int swap); +void *hexdump_64(void *addr, uint64_t offset, uint64_t size, int swap); + +void *hexdump_int(void *addr, uint32_t offset, uint32_t size, int swap); +void *hexdump_64_int(void *addr, uint64_t offset, uint64_t size, int swap); void *ft_realloc(void *data, int size); diff --git a/nm-otool/libft/includes/math.h b/nm-otool/libft/includes/math.h index e65b0b98..f2472db2 100644 --- a/nm-otool/libft/includes/math.h +++ b/nm-otool/libft/includes/math.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 15:41:59 by jhalford #+# #+# */ -/* Updated: 2017/10/30 15:43:39 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 11:53:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,18 +21,23 @@ # define FT_MAX(a, b) ((a) > (b) ? (a) : (b)) # define FT_DIST(a, b) FT_ABS((a) - (b)) -char *ft_itoa(int n); -char *ft_itoa_base(int nbr, char *base, char *flags); -char *ft_lltoa_base(long long nbr, char *base, char *flags); -char *ft_ulltoa_base(unsigned long long nbr, char *base); -char *ft_uitoa_base(unsigned int nbr, char *base); -size_t ft_ilen(int n); -size_t ft_ilen_base(int n, int base); -size_t ft_uilen(unsigned int n); -size_t ft_lllen(long long n); -size_t ft_lllen_base(long long n, int base); +char *ft_itoa(int n); +char *ft_itoa_base(int nbr, char *base, char *flags); +char *ft_lltoa_base(long long nbr, char *base, char *flags); +char *ft_ulltoa_base(unsigned long long nbr, char *base); +char *ft_uitoa_base(unsigned int nbr, char *base); +size_t ft_ilen(int n); +size_t ft_ilen_base(int n, int base); +size_t ft_uilen(unsigned int n); +size_t ft_lllen(long long n); +size_t ft_lllen_base(long long n, int base); -int ft_addrcmp(void *a, void *b); -void *id(void *data); +int ft_addrcmp(void *a, void *b); +void *id(void *data); + +uint8_t bswap_8(uint8_t x); +uint16_t bswap_16(uint16_t x); +uint32_t bswap_32(uint32_t x); +uint64_t bswap_64(uint64_t x); #endif diff --git a/nm-otool/libft/srcs/lst/ft_lstsort.c b/nm-otool/libft/srcs/lst/ft_lstsort.c index 2f5a1c02..7658825d 100644 --- a/nm-otool/libft/srcs/lst/ft_lstsort.c +++ b/nm-otool/libft/srcs/lst/ft_lstsort.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 11:09:58 by jhalford #+# #+# */ -/* Updated: 2017/10/31 19:05:46 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:41:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,6 @@ void ft_lstsort(t_list **begin_list, int (*cmp)()) indirect = begin_list; if (!*begin_list) return ; - int i = 0; while (*indirect && (*indirect)->next) { if ((*cmp)((*indirect)->content, (*indirect)->next->content) > 0) @@ -32,7 +31,6 @@ void ft_lstsort(t_list **begin_list, int (*cmp)()) *indirect = tmp2; (*indirect)->next = tmp; indirect = begin_list; - i = 0; } else indirect = &(*indirect)->next; diff --git a/nm-otool/srcs/bswap.c b/nm-otool/libft/srcs/math/bswap.c similarity index 90% rename from nm-otool/srcs/bswap.c rename to nm-otool/libft/srcs/math/bswap.c index e1f9821c..07c6b43b 100644 --- a/nm-otool/srcs/bswap.c +++ b/nm-otool/libft/srcs/math/bswap.c @@ -6,11 +6,11 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 15:20:32 by jhalford #+# #+# */ -/* Updated: 2017/10/30 15:53:14 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:38:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ -#include "ft_nm_otool.h" +#include "libft.h" inline uint8_t bswap_8(uint8_t x) { @@ -19,8 +19,7 @@ inline uint8_t bswap_8(uint8_t x) inline uint16_t bswap_16(uint16_t x) { - return (( (x >> 8) & 0xffu) | ( - (x & 0xffu) << 8)); + return (((x >> 8) & 0xffu) | ((x & 0xffu) << 8)); } inline uint32_t bswap_32(uint32_t x) diff --git a/nm-otool/libft/srcs/printing/hexdump.c b/nm-otool/libft/srcs/printing/hexdump.c index 0482145a..b139b588 100644 --- a/nm-otool/libft/srcs/printing/hexdump.c +++ b/nm-otool/libft/srcs/printing/hexdump.c @@ -6,14 +6,14 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/07 17:56:14 by jhalford #+# #+# */ -/* Updated: 2017/10/30 11:25:51 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:57:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "libft.h" -static void print_hex_contents(void *addr, uint64_t size) +static void print_hex_contents(void *addr, uint64_t size, int swap) { void *a; @@ -22,43 +22,43 @@ static void print_hex_contents(void *addr, uint64_t size) { if ((uint64_t)(a - addr) >= size) break ; + else if (swap) + ft_printf("%02x", bswap_8(*(uint8_t*)a)); else - ft_printf("%02x", *(unsigned char*)a); + ft_printf("%02x", *(uint8_t*)a); ft_putchar(' '); a++; } } -void *hexdump(void *addr, uint32_t offset, uint32_t size) +void *hexdump(void *addr, uint32_t offset, uint32_t size, int swap) { void *a; - /* addr += offset; */ a = addr; if (addr == NULL) return (addr); while ((uint32_t)(a - addr) < size) { ft_printf("%08llx\t", (a - addr) + offset); - print_hex_contents(a, (uint64_t)(size - (a - addr))); + print_hex_contents(a, (size - (a - addr)), swap); ft_putchar('\n'); a += 16; } return (addr); } -void *hexdump_64(void *addr, uint64_t offset, uint64_t size) +void *hexdump_64(void *addr, uint64_t offset, uint64_t size, int swap) { 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))); + print_hex_contents(a, (size - (a - addr)), swap); ft_putchar('\n'); a += 16; } diff --git a/nm-otool/libft/srcs/printing/hexdump_int.c b/nm-otool/libft/srcs/printing/hexdump_int.c new file mode 100644 index 00000000..51d8d522 --- /dev/null +++ b/nm-otool/libft/srcs/printing/hexdump_int.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hexdump_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/11/01 12:57:21 by jhalford #+# #+# */ +/* Updated: 2017/11/01 12:59:57 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +static void print_hex_contents(void *addr, uint64_t size, int swap) +{ + void *a; + + a = addr; + while (a - addr < 16) + { + if ((uint64_t)(a - addr) >= size) + break ; + else if (swap) + ft_printf("%08x", bswap_32(*(uint64_t*)a)); + else + ft_printf("%08x", *(uint64_t*)a); + ft_putchar(' '); + a += 4; + } +} + +void *hexdump_int(void *addr, uint32_t offset, uint32_t size, int swap) +{ + void *a; + + a = addr; + if (addr == NULL) + return (addr); + while ((uint32_t)(a - addr) < size) + { + ft_printf("%08llx\t", (a - addr) + offset); + print_hex_contents(a, (size - (a - addr)), swap); + ft_putchar('\n'); + a += 16; + } + return (addr); +} + +void *hexdump_64_int(void *addr, uint64_t offset, uint64_t size, + int swap) +{ + void *a; + + 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)), swap); + ft_putchar('\n'); + a += 16; + } + return (addr); +} diff --git a/nm-otool/scripts/gen_mach.sh b/nm-otool/scripts/gen_mach.sh index 2701d4b2..fa16074d 100755 --- a/nm-otool/scripts/gen_mach.sh +++ b/nm-otool/scripts/gen_mach.sh @@ -1,5 +1,5 @@ #!/bin/sh for file in $@; do - sed s/_64//g $@ > $(sed s/_64//g <<< "$@") + sed s/_64//g $file > $(sed s/_64//g <<< "$file") done diff --git a/nm-otool/scripts/nmdiff.sh b/nm-otool/scripts/nmdiff.sh index 07283c24..b0dad9a5 100755 --- a/nm-otool/scripts/nmdiff.sh +++ b/nm-otool/scripts/nmdiff.sh @@ -1,7 +1,7 @@ #!/usr/bin/env zsh diff <(./ft_nm $@) <(nm $@) if [ $? -eq 0 ]; then - echo "nm $@\t OK ✅ " + echo "OK ✅ nm $@" else - echo "nm $@\t ERROR ✅ " + echo "ERROR ✅ nm $@" fi diff --git a/nm-otool/scripts/otooldiff.sh b/nm-otool/scripts/otooldiff.sh index 34e75f56..8f2a38a1 100755 --- a/nm-otool/scripts/otooldiff.sh +++ b/nm-otool/scripts/otooldiff.sh @@ -1,7 +1,7 @@ #!/usr/bin/env zsh diff <(./ft_otool $@) <(otool $@) if [ $? -eq 0 ]; then - echo "otool $@\t OK ✅ " + echo "OK ✅ otool $@" else - echo "otool $@\t ERROR ✅ " + echo "ERROR ❎ otool $@" fi diff --git a/nm-otool/srcs/dump_symtab.c b/nm-otool/srcs/dump_symtab.c deleted file mode 100644 index 6c345c83..00000000 --- a/nm-otool/srcs/dump_symtab.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* dump_symtab.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/25 19:39:15 by jhalford #+# #+# */ -/* Updated: 2017/10/23 16:49:46 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_nm_otool.h" - -void dump_dysymtab(t_machodata *data, struct dysymtab_command *dysymtab) -{ - (void)data; - ft_printf("{blu}{inv}struct dysymtab_command{eoc}\n"); - ft_printf("ilocalsym %i\n", dysymtab->ilocalsym); - ft_printf("nlocalsym %i\n", dysymtab->nlocalsym); - ft_printf("iextdefsym %i\n", dysymtab->iextdefsym); - ft_printf("nextdefsym %i\n", dysymtab->nextdefsym); - ft_printf("iundefsym %i\n", dysymtab->iundefsym); - ft_printf("nundefsym %i\n", dysymtab->nundefsym); - ft_printf("---------------\n"); - ft_printf("ntoc %i\n", dysymtab->ntoc); - ft_printf("nmodtab %i\n", dysymtab->nmodtab); - ft_printf("nextrefsyms %i\n", dysymtab->nextrefsyms); - ft_printf("nmodtab %i\n", dysymtab->nmodtab); - ft_printf("nindirectsims %i\n", dysymtab->nindirectsyms); - ft_printf("nextrel %i\n", dysymtab->nextrel); - ft_printf("nlocrel %i\n", dysymtab->nlocrel); - ft_putendl(""); -} diff --git a/nm-otool/srcs/fat.c b/nm-otool/srcs/fat.c index 5a4f82ce..cc388817 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/10/31 17:45:48 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:23:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,12 @@ void *fat_extract(struct fat_header *fat, cpu_type_t cputype, cpu_subtype_t cpusubtype) { - uint32_t narch; + uint32_t narch; struct fat_arch *arch; narch = endian(fat->nfat_arch, 32); arch = (struct fat_arch*)(fat + 1); - while (narch--) + while (narch--) { if ((int32_t)endian(arch->cputype, 32) == cputype && (int32_t)endian(arch->cpusubtype, 32) & cpusubtype) diff --git a/nm-otool/srcs/ft_nm.c b/nm-otool/srcs/ft_nm.c index 7095d4db..cceda8ab 100644 --- a/nm-otool/srcs/ft_nm.c +++ b/nm-otool/srcs/ft_nm.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 03:09:12 by jhalford #+# #+# */ -/* Updated: 2017/10/31 19:45:02 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:52:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,27 +33,26 @@ t_cliopts g_nm_opts[] = {0, 0, 0, 0, 0, 0}, }; -void nm_single_file(void *file, t_nmdata *data); - void nm_fat_file(struct fat_header *fat, t_nmdata *data) { - uint32_t narch; - struct fat_arch *obj; + uint32_t narch; + struct fat_arch *obj; + const NXArchInfo *arch; g_rev = IS_REV(fat); - obj = fat_extract(fat, CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL); - if (obj) + if ((obj = fat_extract(fat, CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL))) nm_single_file(obj, data); else { narch = endian(fat->nfat_arch, 32); obj = (struct fat_arch*)(fat + 1); - while (narch--) + while (narch--) { - const NXArchInfo *arch = NXGetArchInfoFromCpuType( + arch = NXGetArchInfoFromCpuType( endian(obj->cputype, 32), endian(obj->cpusubtype, 32)); - ft_printf("\n%s (for architecture %s):\n", data->filename, arch->name); + ft_printf("\n%s (for architecture %s):\n", + data->filename, arch->name); nm_single_file((void*)fat + endian(obj->offset, 32), data); g_rev = IS_REV(fat); ++obj; @@ -63,6 +62,8 @@ void nm_fat_file(struct fat_header *fat, t_nmdata *data) void nm_single_file(void *file, t_nmdata *data) { + const NXArchInfo *arch; + g_rev = IS_REV(file); if (IS_MACH_32(file)) nm_mach(file, data); @@ -70,13 +71,13 @@ void nm_single_file(void *file, t_nmdata *data) nm_mach_64(file, data); else { - const NXArchInfo *arch = NXGetArchInfoFromCpuType( + arch = NXGetArchInfoFromCpuType( endian(*((int32_t*)file + 1), 32), endian(*((int32_t*)file + 2), 32)); if (arch) ft_printf("{red}%s unsupported architecture{eoc}\n", arch->name); else - ft_dprintf(2, "unknown architecture, magic=%#x\n", *((int32_t*)file)); + ft_dprintf(2, "unknown arch: magic=%#x\n", *((int32_t*)file)); } } @@ -88,13 +89,9 @@ int nm(int ac, char **av, t_nmdata data) void *file; i = data.av_data - av; - while (i < ac && av[i]) + while (i < ac && (data.filename = av[i])) { - g_rev = 0; - data.filename = av[i]; - if ((fd = open((data.filename), O_RDONLY)) < 0) - return (1); - if ((fstat(fd, &buf)) < 0) + if ((fd = open(data.filename, O_RDONLY)) < 0 || fstat(fd, &buf) < 0) return (1); if ((file = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) diff --git a/nm-otool/srcs/ft_otool.c b/nm-otool/srcs/ft_otool.c index dfd06545..19059982 100644 --- a/nm-otool/srcs/ft_otool.c +++ b/nm-otool/srcs/ft_otool.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/20 14:08:14 by jhalford #+# #+# */ -/* Updated: 2017/10/31 19:45:03 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:33:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,29 +20,30 @@ t_cliopts g_otool_opts[] = }; int g_rev = 0; -void otool_single_file(void *file, t_otooldata *data); - void otool_fat_file(struct fat_header *fat, t_otooldata *data) { - uint32_t narch; - struct fat_arch *obj; + uint32_t narch; + struct fat_arch *obj; + const NXArchInfo *arch; g_rev = IS_REV(fat); - obj = fat_extract(fat, CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL); - if (obj) + if ((obj = fat_extract(fat, CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL))) + { + ft_printf("%s:\n", data->filename); otool_single_file(obj, data); + } else { narch = endian(fat->nfat_arch, 32); obj = (struct fat_arch*)(fat + 1); - while (narch--) + while (narch--) { - const NXArchInfo *arch = NXGetArchInfoFromCpuType( + g_rev = IS_REV(fat); + arch = NXGetArchInfoFromCpuType( endian(obj->cputype, 32), endian(obj->cpusubtype, 32)); - ft_printf("\n%s (for architecture %s):\n", data->filename, arch->name); + ft_printf("%s (architecture %s):\n", data->filename, arch->name); otool_single_file((void*)fat + endian(obj->offset, 32), data); - g_rev = IS_REV(fat); ++obj; } } @@ -50,21 +51,25 @@ void otool_fat_file(struct fat_header *fat, t_otooldata *data) void otool_single_file(void *file, t_otooldata *data) { + const NXArchInfo *arch; + g_rev = IS_REV(file); - if (IS_MACH_32(file)) - otool_mach(file, data); - else if (IS_MACH_64(file)) - otool_mach_64(file, data); - else + arch = NXGetArchInfoFromCpuType( + endian(*((int32_t*)file + 1), 32), + endian(*((int32_t*)file + 2), 32)); + if (arch) { - const NXArchInfo *arch = NXGetArchInfoFromCpuType( - endian(*((int32_t*)file + 1), 32), - endian(*((int32_t*)file + 2), 32)); - if (arch) - ft_printf("{red}%s unsupported architecture{eoc}\n", arch->name); + if (ft_strcmp(arch->name, "ppc") == 0) + otool_ppc(file, data); + else if (IS_MACH_32(file)) + otool_mach(file, data); + else if (IS_MACH_64(file)) + otool_mach_64(file, data); else - ft_dprintf(2, "unknown architecture, magic=%#x\n", *((int32_t*)file)); + ft_printf("{red}%s unsupported architecture{eoc}\n", arch->name); } + else + ft_dprintf(2, "unknown architecture, magic=%#x\n", *((int32_t*)file)); } int otool(int ac, char **av, t_otooldata data) @@ -75,12 +80,9 @@ int otool(int ac, char **av, t_otooldata data) void *file; i = data.av_data - av; - while (i < ac && av[i]) + while (i < ac && (data.filename = av[i])) { - ft_printf("%s:\n", av[i]); - if ((fd = open((av[i]), O_RDONLY)) < 0) - return (1); - if ((fstat(fd, &buf)) < 0) + if ((fd = open((av[i]), O_RDONLY)) < 0 || fstat(fd, &buf) < 0) return (1); if ((file = mmap(NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) @@ -88,7 +90,10 @@ int otool(int ac, char **av, t_otooldata data) if (IS_FAT(file)) otool_fat_file(file, &data); else + { + ft_printf("%s:\n", data.filename); otool_single_file(file, &data); + } if (munmap(file, buf.st_size)) return (1); i++; diff --git a/nm-otool/srcs/mach/get_section.c b/nm-otool/srcs/mach/get_section.c index 480ec801..c8796cbf 100644 --- a/nm-otool/srcs/mach/get_section.c +++ b/nm-otool/srcs/mach/get_section.c @@ -1,52 +1,68 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* get_section.c :+: :+: :+: */ +/* get_section.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 11:00:40 by jhalford #+# #+# */ -/* Updated: 2017/10/30 12:18:02 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:11:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_nm_otool.h" -void *get_segment(void *file, char *lookup) +void *get_segment(struct mach_header *file, char *lookup) { uint32_t i; struct load_command *lc; - struct segment_command *seg; + struct segment_command *seg; + uint32_t ncmds; - lc = (void*)((struct mach_header*)file + 1); + lc = (void*)(file + 1); i = -1; - while (++i < ((struct mach_header*)file)->ncmds) + ncmds = endian(file->ncmds, 32); + DG("ncmds=%i", ncmds); + while (++i < ncmds) { - if (lc->cmd & LC_SEGMENT) + DG("i=%i", i); + if (endian(lc->cmd, 32) & LC_SEGMENT) { seg = (struct segment_command*)lc; + DG("segment: %s", seg->segname); if (ft_strcmp(seg->segname, lookup) == 0) return (seg); } - lc = (void*)lc + lc->cmdsize; + lc = (void*)lc + endian(lc->cmdsize, 32); } return (NULL); } -void *get_section(void *file, char *segname, char *sectname) +void *get_section(struct mach_header *file, char *lookup) { + uint32_t i; uint32_t j; - struct segment_command *seg; - struct section *sect; + struct load_command *lc; + struct segment_command *seg; + struct section *sect; - seg = get_segment(file, segname); - sect = (void*)(seg + 1); - j = -1; - while (++j < seg->nsects) + lc = (void*)(file + 1); + i = -1; + while (++i < endian(file->ncmds, 32)) { - if (ft_strcmp(sect->sectname, sectname) == 0) - return (sect); - sect = sect + 1; + if (endian(lc->cmd, 32) & LC_SEGMENT) + { + seg = (struct segment_command*)lc; + sect = (void*)(seg + 1); + j = -1; + while (++j < endian(seg->nsects, 32)) + { + if (ft_strcmp(sect->sectname, lookup) == 0) + return (sect); + sect = sect + 1; + } + } + lc = (void*)lc + endian(lc->cmdsize, 32); } return (NULL); } diff --git a/nm-otool/srcs/mach/mach.c b/nm-otool/srcs/mach/mach.c index be8ab8df..7dc0aaab 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/10/31 17:46:14 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:09:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,7 +52,7 @@ void mach_parse(t_machodata *data) uint32_t ncmds; uint32_t i; struct load_command *lc; - struct mach_header *header; + struct mach_header *header; header = data->file; ncmds = endian(header->ncmds, 32); diff --git a/nm-otool/srcs/mach/nm_mach.c b/nm-otool/srcs/mach/nm_mach.c index b87bf1a8..539655c3 100644 --- a/nm-otool/srcs/mach/nm_mach.c +++ b/nm-otool/srcs/mach/nm_mach.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* nm_mach.c :+: :+: :+: */ +/* nm_mach.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 11:03:04 by jhalford #+# #+# */ -/* Updated: 2017/10/30 11:31:38 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:10:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/srcs/mach/otool_mach.c b/nm-otool/srcs/mach/otool_mach.c index 4188921c..ac5f7e65 100644 --- a/nm-otool/srcs/mach/otool_mach.c +++ b/nm-otool/srcs/mach/otool_mach.c @@ -1,35 +1,39 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* otool_mach.c :+: :+: :+: */ +/* otool_mach.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 11:04:06 by jhalford #+# #+# */ -/* Updated: 2017/10/30 12:16:36 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:58:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_nm_otool.h" +extern int g_rev; + 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))) + if ((sect = get_section(file, SECT_TEXT))) { ft_printf("Contents of (%s,%s) section\n", SEG_TEXT, SECT_TEXT); - hexdump(file + sect->offset, sect->addr, sect->size); + hexdump(file + endian(sect->offset, 32), + endian(sect->addr, 32), endian(sect->size, 32), g_rev); } } if (data->flag & OTOOL_DATA) { - if ((sect = get_section(file, SEG_DATA, SECT_DATA))) + if ((sect = get_section(file, SECT_DATA))) { ft_printf("Contents of (%s,%s) section\n", SEG_DATA, SECT_DATA); - hexdump(file + sect->offset, sect->addr, sect->size); + hexdump(file + endian(sect->offset, 32), + endian(sect->addr, 32), endian(sect->size, 32), g_rev); } } } diff --git a/nm-otool/srcs/mach/symbol_filter.c b/nm-otool/srcs/mach/symbol_filter.c index 089c7026..84f6cd3f 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:23 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:11:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/srcs/mach/symbol_format.c b/nm-otool/srcs/mach/symbol_format.c index 02141dd5..80fdedef 100644 --- a/nm-otool/srcs/mach/symbol_format.c +++ b/nm-otool/srcs/mach/symbol_format.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* symbol_format.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/11/01 12:33:27 by jhalford #+# #+# */ +/* Updated: 2017/11/01 12:33:27 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "ft_nm_otool.h" t_symbolmap g_symbolmap[] = diff --git a/nm-otool/srcs/mach/symbol_free.c b/nm-otool/srcs/mach/symbol_free.c index 6905fdac..5cb6ee04 100644 --- a/nm-otool/srcs/mach/symbol_free.c +++ b/nm-otool/srcs/mach/symbol_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/26 17:06:23 by jhalford #+# #+# */ -/* Updated: 2017/10/26 18:38:31 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:11:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/srcs/mach/symbol_init.c b/nm-otool/srcs/mach/symbol_init.c index 2aa970ac..4480ceb6 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/10/31 16:42:20 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:36:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/srcs/mach_64/get_section_64.c b/nm-otool/srcs/mach_64/get_section_64.c index c31dc658..17295a38 100644 --- a/nm-otool/srcs/mach_64/get_section_64.c +++ b/nm-otool/srcs/mach_64/get_section_64.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 11:00:40 by jhalford #+# #+# */ -/* Updated: 2017/10/31 19:58:07 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:37:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,21 +38,31 @@ void *get_segment_64(struct mach_header_64 *file, char *lookup) return (NULL); } -void *get_section_64(void *file, char *segname, char *sectname) +void *get_section_64(struct mach_header_64 *file, char *lookup) { + uint32_t i; uint32_t j; + struct load_command *lc; struct segment_command_64 *seg; struct section_64 *sect; - if (!(seg = get_segment_64(file, segname))) - return (NULL); - sect = (void*)(seg + 1); - j = -1; - while (++j < endian(seg->nsects, 32)) + lc = (void*)(file + 1); + i = -1; + while (++i < endian(file->ncmds, 32)) { - if (ft_strcmp(sect->sectname, sectname) == 0) - return (sect); - sect = sect + 1; + if (endian(lc->cmd, 32) & LC_SEGMENT_64) + { + seg = (struct segment_command_64*)lc; + sect = (void*)(seg + 1); + j = -1; + while (++j < endian(seg->nsects, 32)) + { + if (ft_strcmp(sect->sectname, lookup) == 0) + return (sect); + sect = sect + 1; + } + } + lc = (void*)lc + endian(lc->cmdsize, 32); } return (NULL); } diff --git a/nm-otool/srcs/mach_64/mach_64.c b/nm-otool/srcs/mach_64/mach_64.c index 5fc37676..2957c37c 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/31 18:06:12 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:36:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ static void symtab_64_parse(t_machodata *data, struct symtab_command *symtab) stringtable = data->file + endian(symtab->stroff, 32); array = (struct nlist_64*)(data->file + endian(symtab->symoff, 32)); i = -1; - while (++i < (int)endian(symtab->nsyms,32)) + while (++i < (int)endian(symtab->nsyms, 32)) { symbol_64_init(&symbol, stringtable, array, i); symbol_64_set(&symbol, data); diff --git a/nm-otool/srcs/mach_64/otool_mach_64.c b/nm-otool/srcs/mach_64/otool_mach_64.c index 7ee25b24..c42c8f18 100644 --- a/nm-otool/srcs/mach_64/otool_mach_64.c +++ b/nm-otool/srcs/mach_64/otool_mach_64.c @@ -6,38 +6,34 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/10/30 11:04:06 by jhalford #+# #+# */ -/* Updated: 2017/10/31 19:31:45 by jhalford ### ########.fr */ +/* Updated: 2017/11/01 12:58:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_nm_otool.h" +extern int g_rev; + void otool_mach_64(void *file, t_otooldata *data) { struct section_64 *sect; - DG("check"); if (data->flag & OTOOL_TEXT) { - DG("check"); - if ((sect = get_section_64(file, SEG_TEXT, SECT_TEXT))) + if ((sect = get_section_64(file, SECT_TEXT))) { - DG("check"); ft_printf("Contents of (%s,%s) section\n", SEG_TEXT, SECT_TEXT); - DG("check"); - DG("hexdump: %i %i %i", sect->offset, sect->addr, sect->size); hexdump_64(file + endian(sect->offset, 32), - endian(sect->addr, 32), endian(sect->size, 32)); + endian(sect->addr, 32), endian(sect->size, 32), g_rev); } - DG("check"); } if (data->flag & OTOOL_DATA) { - if ((sect = get_section_64(file, SEG_DATA, SECT_DATA))) + if ((sect = get_section_64(file, SECT_DATA))) { ft_printf("Contents of (%s,%s) section\n", SEG_DATA, SECT_DATA); hexdump_64(file + endian(sect->offset, 32), - endian(sect->addr, 32), endian(sect->size, 32)); + endian(sect->addr, 32), endian(sect->size, 32), g_rev); } } } diff --git a/nm-otool/srcs/mach_64/symbol_64_format.c b/nm-otool/srcs/mach_64/symbol_64_format.c index 1900b1e9..48abd6f9 100644 --- a/nm-otool/srcs/mach_64/symbol_64_format.c +++ b/nm-otool/srcs/mach_64/symbol_64_format.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* symbol_64_format.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/11/01 12:37:07 by jhalford #+# #+# */ +/* Updated: 2017/11/01 12:37:07 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "ft_nm_otool.h" t_symbolmap g_symbolmap_64[] = diff --git a/nm-otool/srcs/ppc/otool_ppc.c b/nm-otool/srcs/ppc/otool_ppc.c new file mode 100644 index 00000000..18725fef --- /dev/null +++ b/nm-otool/srcs/ppc/otool_ppc.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* otool_ppc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/11/01 11:32:36 by jhalford #+# #+# */ +/* Updated: 2017/11/01 12:58:28 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_nm_otool.h" + +extern int g_rev; + +void otool_ppc(void *file, t_otooldata *data) +{ + struct section *sect; + + if (data->flag & OTOOL_TEXT) + { + if ((sect = get_section(file, SECT_TEXT))) + { + ft_printf("Contents of (%s,%s) section\n", SEG_TEXT, SECT_TEXT); + hexdump_int(file + endian(sect->offset, 32), + endian(sect->addr, 32), endian(sect->size, 32), g_rev); + } + } + if (data->flag & OTOOL_DATA) + { + if ((sect = get_section(file, SECT_DATA))) + { + ft_printf("Contents of (%s,%s) section\n", SEG_DATA, SECT_DATA); + hexdump_int(file + endian(sect->offset, 32), + endian(sect->addr, 32), endian(sect->size, 32), g_rev); + } + } +}