This commit is contained in:
Jack Halford 2017-11-07 16:03:11 +01:00
parent 3301d5880c
commit b78cb8431a
13 changed files with 55 additions and 55 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/30 11:44:40 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_OFORMAT (1 << 9)
# define NM_MFORMAT (1 << 10) # define NM_MFORMAT (1 << 10)
typedef struct s_fdata t_fdata;
typedef enum e_symtype t_symtype; typedef enum e_symtype t_symtype;
typedef struct s_symbolmap t_symbolmap; typedef struct s_symbolmap t_symbolmap;
typedef struct s_machodata t_machodata; typedef struct s_machodata t_machodata;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/20 14:36:10 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 <mach-o/fat.h> # include <mach-o/fat.h>
# include <mach-o/arch.h> # include <mach-o/arch.h>
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 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_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_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_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 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 struct s_fdata
{ {
@ -44,17 +51,8 @@ struct s_fdata
char *filename; 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 *fat_extract(struct fat_header *fat, char *aname);
/* void memcheck(t_fdata *file, void *ptr, size_t size); */ uint64_t endian(uint64_t n, uint8_t size);
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);
#endif #endif

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* mach.h :+: :+: :+: */ /* mach.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/26 18:39:31 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 # define MACH_H
typedef struct s_symbol t_symbol; typedef struct s_symbol t_symbol;
typedef struct s_fdata t_fdata;
struct s_symbol struct s_symbol
{ {
int pos; int pos;
t_symtype type; t_symtype type;
char *string; char *string;
struct nlist nlist; struct nlist nlist;
struct section *section; struct section *section;
}; };

View file

@ -6,13 +6,14 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/26 18:39:31 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 #ifndef MACH_64_H
# define MACH_64_H # define MACH_64_H
typedef struct s_fdata t_fdata;
typedef struct s_symbol_64 t_symbol_64; typedef struct s_symbol_64 t_symbol_64;
struct s_symbol_64 struct s_symbol_64

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/30 16:31:48 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) void *fat_extract(struct fat_header *fat, char *aname)
{ {
uint32_t narch; uint32_t narch;
struct fat_arch *obj; struct fat_arch *obj;
const NXArchInfo *arch; const NXArchInfo *arch;
narch = endian(fat->nfat_arch, 32); narch = endian(fat->nfat_arch, 32);

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* get_section.c :+: :+: :+: */ /* get_section.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/30 11:00:40 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) void *get_segment(t_machodata *data, char *lookup)
{ {
uint32_t i; uint32_t i;
struct load_command *lc; struct load_command *lc;
struct segment_command *seg; struct segment_command *seg;
uint32_t ncmds; uint32_t ncmds;
MC(lc = (void*)((struct mach_header*)data->file->file + 1)); MC(lc = (void*)((struct mach_header*)data->file->file + 1));
i = -1; i = -1;
@ -37,9 +37,9 @@ void *get_segment(t_machodata *data, char *lookup)
void *get_section(t_machodata *data, char *lookup) void *get_section(t_machodata *data, char *lookup)
{ {
uint32_t i; uint32_t i;
uint32_t j; uint32_t j;
struct load_command *lc; struct load_command *lc;
struct segment_command *seg; struct segment_command *seg;
struct section *sect; struct section *sect;

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* mach.c :+: :+: :+: */ /* mach.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/23 16:06:44 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) static void seg_parse(t_machodata *data, struct segment_command *seg)
{ {
uint32_t nsects; uint32_t nsects;
uint32_t i; uint32_t i;
struct section *sect; struct section *sect;
nsects = endian(seg->nsects, 32); 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) void mach_parse(t_machodata *data)
{ {
uint32_t ncmds; uint32_t ncmds;
uint32_t i; uint32_t i;
struct load_command *lc; struct load_command *lc;
struct mach_header *header; struct mach_header *header;
header = data->file->file; header = data->file->file;

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* otool_mach.c :+: :+: :+: */ /* otool_mach.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/30 11:04:06 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) void otool_mach(t_fdata *data)
{ {
struct section *sect; struct section *sect;
t_machodata mach; t_machodata mach;
mach.file = data; mach.file = data;
if (data->flag & OTOOL_TEXT) if (data->flag & OTOOL_TEXT)

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* symbol_filter.c :+: :+: :+: */ /* symbol_filter.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/26 18:31:27 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* symbol_format.c :+: :+: :+: */ /* symbol_format.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/01 12:37:07 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* symbol_init.c :+: :+: :+: */ /* symbol_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/26 18:07:28 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/23 16:06:44 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; data->symtab = symtab;
MC(stringtable = data->file->file + endian(symtab->stroff, 32)); 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); nsyms = endian(symtab->nsyms, 32);
i = -1; i = -1;
while (++i < nsyms) while (++i < nsyms)

View file

@ -6,19 +6,17 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/07 11:24:09 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" #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) 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, "%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); exit(1);
} }
} }