66 lines
2.2 KiB
C
66 lines
2.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* symbol_64_init.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2017/10/26 18:07:28 by jhalford #+# #+# */
|
|
/* Updated: 2017/10/26 18:23:24 by jhalford ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "ft_nm_otool.h"
|
|
|
|
t_machodata *g_data;
|
|
|
|
int symbol_64_init(t_symbol_64 *symbol,
|
|
char *stringtable, struct nlist_64 *array, int i)
|
|
{
|
|
symbol->type = 0;
|
|
symbol->pos = i;
|
|
symbol->nlist = array + i;
|
|
symbol->string = stringtable + array[i].n_un.n_strx;
|
|
return (0);
|
|
}
|
|
|
|
static int symbol_64_gettype(int type_mask,
|
|
struct nlist_64 *nlist, struct section_64 *section)
|
|
{
|
|
if (nlist->n_type & N_STAB)
|
|
return (SYM_STAB);
|
|
else if (type_mask == N_UNDF && nlist->n_type & N_EXT && nlist->n_value)
|
|
return (SYM_COMMON);
|
|
else if (type_mask == N_UNDF)
|
|
return (SYM_UNDF);
|
|
else if (type_mask == N_ABS)
|
|
return (SYM_ABS);
|
|
else if (type_mask == N_SECT && ft_strequ("__text", section->sectname))
|
|
return (SYM_TEXT);
|
|
else if (type_mask == N_SECT && ft_strequ("__data", section->sectname))
|
|
return (SYM_DATA);
|
|
else if (type_mask == N_SECT && ft_strequ("__bss", section->sectname))
|
|
return (SYM_BSS);
|
|
else if (type_mask == N_INDR)
|
|
return (SYM_INDR);
|
|
else
|
|
return (SYM_OTHER);
|
|
}
|
|
|
|
int symbol_64_set(t_symbol_64 *sym, t_machodata *data)
|
|
{
|
|
t_list *lst;
|
|
|
|
if (sym->nlist->n_sect)
|
|
{
|
|
lst = ft_lst_at(data->sects, sym->nlist->n_sect - 1);
|
|
sym->section = *(struct section_64**)(lst->content);
|
|
}
|
|
else
|
|
sym->section = NULL;
|
|
sym->type = symbol_64_gettype(
|
|
sym->nlist->n_type & N_TYPE,
|
|
sym->nlist,
|
|
sym->section);
|
|
return (0);
|
|
}
|