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

@ -6,7 +6,7 @@
/* 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,6 +14,7 @@
# 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
{ {

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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

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:56:16 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* 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

@ -6,7 +6,7 @@
/* 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

@ -6,7 +6,7 @@
/* 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);
} }
} }