some norme
This commit is contained in:
parent
44b23be0a0
commit
cfa90b1cd8
7 changed files with 23 additions and 89 deletions
|
|
@ -38,7 +38,6 @@ dump_symtab.c\
|
||||||
fetch_header.c\
|
fetch_header.c\
|
||||||
ft_nm.c\
|
ft_nm.c\
|
||||||
ft_otool.c\
|
ft_otool.c\
|
||||||
hexdump.c\
|
|
||||||
mach_o_parse.c\
|
mach_o_parse.c\
|
||||||
symbol_filter.c\
|
symbol_filter.c\
|
||||||
symbol_format.c\
|
symbol_format.c\
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/25 19:39:15 by jhalford #+# #+# */
|
/* Created: 2017/03/25 19:39:15 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/26 15:22:52 by jhalford ### ########.fr */
|
/* Updated: 2017/10/07 18:26:32 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -32,4 +32,3 @@ void dump_dysymtab(t_machodata *data, struct dysymtab_command *dysymtab)
|
||||||
ft_printf("nlocrel %i\n", dysymtab->nlocrel);
|
ft_printf("nlocrel %i\n", dysymtab->nlocrel);
|
||||||
ft_putendl("");
|
ft_putendl("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/23 15:56:37 by jhalford #+# #+# */
|
/* Created: 2017/03/23 15:56:37 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/26 19:05:53 by jhalford ### ########.fr */
|
/* Updated: 2017/10/07 18:31:01 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -39,14 +39,15 @@ static void seg_64_parse(t_machodata *data, struct segment_command_64 *seg)
|
||||||
|
|
||||||
nsects = seg->nsects;
|
nsects = seg->nsects;
|
||||||
sect = (void*)(seg + 1);
|
sect = (void*)(seg + 1);
|
||||||
for (i = 0; i < nsects; i++)
|
i = -1;
|
||||||
|
while (++i < nsects)
|
||||||
{
|
{
|
||||||
ft_lsteadd(&data->sects, ft_lstnew(§, sizeof(sect)));
|
ft_lsteadd(&data->sects, ft_lstnew(§, sizeof(sect)));
|
||||||
sect = sect + 1;
|
sect = sect + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mach_64_parse(t_machodata *data)
|
void mach_64_parse(t_machodata *data)
|
||||||
{
|
{
|
||||||
uint32_t ncmds;
|
uint32_t ncmds;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
@ -56,7 +57,8 @@ void mach_64_parse(t_machodata *data)
|
||||||
header = data->file;
|
header = data->file;
|
||||||
ncmds = header->ncmds;
|
ncmds = header->ncmds;
|
||||||
lc = (void*)(header + 1);
|
lc = (void*)(header + 1);
|
||||||
for (i = 0; i < ncmds; i++)
|
i = -1;
|
||||||
|
while (++i < ncmds)
|
||||||
{
|
{
|
||||||
if (lc->cmd == LC_SYMTAB)
|
if (lc->cmd == LC_SYMTAB)
|
||||||
symtab_parse(data, (struct symtab_command*)lc);
|
symtab_parse(data, (struct symtab_command*)lc);
|
||||||
|
|
@ -67,23 +69,3 @@ void mach_64_parse(t_machodata *data)
|
||||||
lc = (void*)lc + lc->cmdsize;
|
lc = (void*)lc + lc->cmdsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static void fetch_fatheader(t_machodata *data) */
|
|
||||||
/* { */
|
|
||||||
/* int i; */
|
|
||||||
/* int nfat_arch; */
|
|
||||||
/* struct fat_arch *arch; */
|
|
||||||
/* struct fat_header *header; */
|
|
||||||
|
|
||||||
/* header = data->file; */
|
|
||||||
/* nfat_arch = header->nfat_arch; */
|
|
||||||
/* arch = (void*)(header + 1); */
|
|
||||||
/* ft_printf("{yel}{inv}FAT header w/ [%i] architures{eoc}\n", nfat_arch); */
|
|
||||||
/* for (i = 0; i < nfat_arch; i++) */
|
|
||||||
/* { */
|
|
||||||
/* ft_printf("CPU type=[%i]", arch->cputype); */
|
|
||||||
/* fetch_machheader64(data->file + arch->offset, data); */
|
|
||||||
/* arch += 1; */
|
|
||||||
/* } */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/20 14:08:14 by jhalford #+# #+# */
|
/* Created: 2017/02/20 14:08:14 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/27 20:41:01 by jhalford ### ########.fr */
|
/* Updated: 2017/10/07 18:35:37 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,19 +15,21 @@
|
||||||
void *get_text_section(void *file)
|
void *get_text_section(void *file)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
uint32_t j;
|
||||||
struct load_command *lc;
|
struct load_command *lc;
|
||||||
struct mach_header_64 *header = file;
|
|
||||||
struct segment_command_64 *seg;
|
struct segment_command_64 *seg;
|
||||||
struct section_64 *sect;
|
struct section_64 *sect;
|
||||||
|
|
||||||
lc = (void*)(header + 1);
|
lc = (void*)((struct mach_header_64*)file + 1);
|
||||||
for (i = 0; i < header->ncmds; i++)
|
i = -1;
|
||||||
|
while (++i < ((struct mach_header_64*)file)->ncmds)
|
||||||
{
|
{
|
||||||
if (lc->cmd & LC_SEGMENT_64)
|
if (lc->cmd & LC_SEGMENT_64)
|
||||||
{
|
{
|
||||||
seg = (struct segment_command_64*)lc;
|
seg = (struct segment_command_64*)lc;
|
||||||
sect = (void*)(seg + 1);
|
sect = (void*)(seg + 1);
|
||||||
for (i = 0; i < seg->nsects; i++)
|
j = -1;
|
||||||
|
while (++j < seg->nsects)
|
||||||
{
|
{
|
||||||
if (ft_strcmp(sect->sectname, "__text") == 0)
|
if (ft_strcmp(sect->sectname, "__text") == 0)
|
||||||
return (sect);
|
return (sect);
|
||||||
|
|
@ -41,14 +43,13 @@ void *get_text_section(void *file)
|
||||||
|
|
||||||
void otool(void *file)
|
void otool(void *file)
|
||||||
{
|
{
|
||||||
uint32_t magic = *(int *)file;
|
uint32_t magic;
|
||||||
int is_fat = IS_FAT(magic);
|
struct section_64 *sect;
|
||||||
int is_64 = IS_MAGIC_64(magic);
|
|
||||||
struct section_64 *sect;
|
|
||||||
|
|
||||||
if (is_fat)
|
magic = *(int *)file;
|
||||||
|
if (IS_FAT(magic))
|
||||||
ft_printf("fat binary not supported yet\n");
|
ft_printf("fat binary not supported yet\n");
|
||||||
else if (is_64)
|
else if (IS_MAGIC_64(magic))
|
||||||
{
|
{
|
||||||
sect = get_text_section(file);
|
sect = get_text_section(file);
|
||||||
ft_printf("Contents of (__TEXT,__text) section\n");
|
ft_printf("Contents of (__TEXT,__text) section\n");
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* hexdump.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2017/02/20 15:14:33 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2017/03/26 19:11:17 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "ft_nm_otool.h"
|
|
||||||
|
|
||||||
static void print_hex_contents(void *addr, unsigned int size)
|
|
||||||
{
|
|
||||||
void *a;
|
|
||||||
|
|
||||||
a = addr;
|
|
||||||
while (a - addr < 16)
|
|
||||||
{
|
|
||||||
if ((a - addr) >= size)
|
|
||||||
break ;
|
|
||||||
else
|
|
||||||
ft_printf("%02x", *(unsigned char*)a);
|
|
||||||
ft_putchar(' ');
|
|
||||||
a++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void *hexdump(void *addr, unsigned int offset, unsigned int size)
|
|
||||||
{
|
|
||||||
void *a;
|
|
||||||
|
|
||||||
addr += offset;
|
|
||||||
a = addr;
|
|
||||||
if (addr == NULL)
|
|
||||||
return (addr);
|
|
||||||
while ((a - addr) < size)
|
|
||||||
{
|
|
||||||
ft_printf("%0*llx\t", 16, (a - addr) + (unsigned long)offset);
|
|
||||||
print_hex_contents(a, (size - (a - addr)));
|
|
||||||
ft_putchar('\n');
|
|
||||||
a += 16;
|
|
||||||
}
|
|
||||||
return (addr);
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/25 21:22:06 by jhalford #+# #+# */
|
/* Created: 2017/03/25 21:22:06 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/27 20:36:57 by jhalford ### ########.fr */
|
/* Updated: 2017/10/07 18:35:41 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
t_machodata *g_data;
|
t_machodata *g_data;
|
||||||
|
|
||||||
int symbol_init(t_symbol *symbol, char *stringtable, struct nlist_64 *array, int i)
|
int symbol_init(t_symbol *symbol, char *stringtable, struct nlist_64 *array, int i)
|
||||||
{
|
{
|
||||||
symbol->type = 0;
|
symbol->type = 0;
|
||||||
symbol->pos = i;
|
symbol->pos = i;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/27 20:33:02 by jhalford #+# #+# */
|
/* Created: 2017/03/27 20:33:02 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/27 20:33:03 by jhalford ### ########.fr */
|
/* Updated: 2017/10/07 18:29:45 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ static int sym_nsort(t_symbol *sym1, t_symbol *sym2)
|
||||||
return (sym1->nlist->n_value > sym2->nlist->n_value ? 1 : -1);
|
return (sym1->nlist->n_value > sym2->nlist->n_value ? 1 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int symbol_sort(t_list **syms, t_flag flag)
|
int symbol_sort(t_list **syms, t_flag flag)
|
||||||
{
|
{
|
||||||
if (!(flag & NM_NOSORT))
|
if (!(flag & NM_NOSORT))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue