-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
24 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 6,7 @@ | |
/* By: pchadeni <[email protected]> # : # */ | ||
/* # # # # # # */ | ||
/* Created: 2019/03/27 17:49:41 by pchadeni # # # # */ | ||
/* Updated: 2019/04/15 18:01:41 by pchadeni ### ########.fr */ | ||
/* Updated: 2019/04/15 19:58:26 by pchadeni ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -144,8 144,6 @@ uint64_t to_big_endian(uint8_t l_endian, uint64_t value); | |
uint8_t init_symbols_struct(t_finfo file, t_fhead *head, char *name); | ||
|
||
uint8_t handle_macho(t_finfo file, t_fhead *head, t_sc *sc); | ||
//uint8_t handle_32(t_finfo file, t_fhead *head, t_sc *sc); | ||
//uint8_t handle_64(t_finfo file, t_fhead *head, t_sc *sc); | ||
uint8_t add_sect_64(t_finfo file, t_fhead *head, t_lc *lc); | ||
uint8_t add_sect_32(t_finfo file, t_fhead *head, t_lc *lc); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,26 6,12 @@ | |
/* By: pchadeni <[email protected]> # : # */ | ||
/* # # # # # # */ | ||
/* Created: 2019/04/03 19:45:54 by pchadeni # # # # */ | ||
/* Updated: 2019/04/12 16:17:44 by pchadeni ### ########.fr */ | ||
/* Updated: 2019/04/15 19:57:07 by pchadeni ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "lib_nm_otool.h" | ||
|
||
static uint8_t not_in_array(uint32_t *array, uint32_t value, int i) | ||
{ | ||
int j; | ||
|
||
j = 0; | ||
while (j < i) | ||
{ | ||
if (array[j] == value) | ||
return (0); | ||
j ; | ||
} | ||
return (1); | ||
} | ||
|
||
static char *find_correct_size(struct ar_hdr *ah) | ||
{ | ||
int off; | ||
|
@@ -36,7 22,7 @@ static char *find_correct_size(struct ar_hdr *ah) | |
return ((void *)ah sizeof(*ah) off); | ||
} | ||
|
||
static uint8_t for_obj(t_finfo f, t_fhead *head, uint32_t *arr, uint32_t s) | ||
static uint8_t for_obj(t_finfo f, t_fhead *head, char *first) | ||
{ | ||
uint32_t i; | ||
char *object_header; | ||
|
@@ -46,62 32,37 @@ static uint8_t for_obj(t_finfo f, t_fhead *head, uint32_t *arr, uint32_t s) | |
|
||
i = 0; | ||
ptr = head->current; | ||
while (i < s) | ||
ah = (struct ar_hdr *)(first); | ||
while ((char *)ah < ptr f.size) | ||
{ | ||
ah = (struct ar_hdr *)(ptr arr[i]); | ||
if (ptr arr[i] > ptr f.size) | ||
if ((char*)ah > ptr f.size) | ||
return (handle_error(f.name, E_CORRUPT, head->opts)); | ||
object_header = find_correct_size(ah); | ||
obj_name = (ft_strnequ(AR_EFMT1, ah->ar_name, 3)) | ||
? (void *)ah sizeof(*ah) : ah->ar_name; | ||
head->current = object_header; | ||
if (list_symbols(f, head, obj_name)) | ||
return (1); | ||
i ; | ||
ah = (void *)ah sizeof(struct ar_hdr) ft_atoi(ah->ar_size); | ||
} | ||
return (0); | ||
} | ||
|
||
static uint32_t *create_array_off(t_finfo file, t_fhead *head, uint32_t *i) | ||
{ | ||
char *n_elem; | ||
struct ranlib *ran; | ||
uint32_t nb_ranlib; | ||
uint32_t *array; | ||
|
||
if (head->current SARMAG > head->current file.size) | ||
return (NULL); | ||
n_elem = find_correct_size((struct ar_hdr *)(head->current SARMAG)); | ||
ran = (struct ranlib *)(n_elem sizeof(uint32_t)); | ||
nb_ranlib = *(uint32_t*)n_elem / sizeof(struct ranlib); | ||
if (!(array = (uint32_t *)ft_memalloc_uint(nb_ranlib))) | ||
return (NULL); | ||
while ((char *)ran < n_elem *(uint32_t *)n_elem) | ||
{ | ||
if ((char *)ran sizeof(*ran) > head->current file.size) | ||
return (NULL); | ||
if (*i == 0 || not_in_array(array, ran->ran_off, *i)) | ||
{ | ||
array[*i] = ran->ran_off; | ||
(*i) ; | ||
} | ||
ran = (void *)ran sizeof(struct ranlib); | ||
} | ||
return (array); | ||
} | ||
|
||
uint8_t handle_archive(t_finfo file, t_fhead *head) | ||
{ | ||
uint32_t *array_offset; | ||
uint32_t i; | ||
uint8_t res; | ||
uint8_t res; | ||
char *symtab_size; | ||
char *strtab_size; | ||
char *first; | ||
|
||
i = 0; | ||
head->archive = 1; | ||
if (!(array_offset = create_array_off(file, head, &i))) | ||
return (handle_error(file.name, E_CORRUPT, head->opts)); | ||
m_sort_uint(array_offset, 0, i - 1); | ||
res = for_obj(file, head, array_offset, i); | ||
free(array_offset); | ||
if (head->current SARMAG > head->current file.size) | ||
return (1); | ||
symtab_size = find_correct_size((struct ar_hdr *)(head->current SARMAG)); | ||
strtab_size = *(uint32_t *)symtab_size symtab_size sizeof(uint32_t); | ||
first = strtab_size sizeof(uint32_t) *(uint32_t *)strtab_size; | ||
if (head->current SARMAG > head->current file.size) | ||
return (1); | ||
res = for_obj(file, head, first); | ||
return (res); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 6,7 @@ | |
/* By: pchadeni <[email protected]> # : # */ | ||
/* # # # # # # */ | ||
/* Created: 2019/04/04 17:05:35 by pchadeni # # # # */ | ||
/* Updated: 2019/04/15 18:13:37 by pchadeni ### ########.fr */ | ||
/* Updated: 2019/04/15 19:57:56 by pchadeni ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -102,10 102,8 @@ uint8_t handle_macho(t_finfo file, t_fhead *head, t_sc *sc) | |
uint8_t res; | ||
|
||
str_tab = head->current to_big_endian(head->macho.l_endian, sc->stroff); | ||
if (str_tab > head->ptr file.size) | ||
return (1); | ||
if (!(head->macho.arr = | ||
(t_ulist *)malloc(sizeof(t_ulist) * head->macho.n_syms))) | ||
if (!str_tab > head->ptr file.size || (head->macho.arr = | ||
(t_ulist *)malloc(sizeof(t_ulist) * head->macho.n_syms))) | ||
return (1); | ||
strsize = to_big_endian(head->macho.l_endian, sc->strsize); | ||
symoff = to_big_endian(head->macho.l_endian, sc->symoff); | ||
|
@@ -122,29 120,5 @@ uint8_t handle_macho(t_finfo file, t_fhead *head, t_sc *sc) | |
else | ||
ft_printf("%s:\n", file.name); | ||
free(head->macho.arr); | ||
/* | ||
while (i < head->macho.n_syms) | ||
{ | ||
strx = to_big_endian(head->macho.l_endian, nl_64->n_un.n_strx); | ||
if (strx > strsize) | ||
{ | ||
if (head->opts & FT_OTOOL) | ||
return (free_error(head)); | ||
head->macho.arr[i].name = ft_strdup("bad string index"); | ||
} | ||
else | ||
head->macho.arr[i].name = ft_strdup(strx str_tab); | ||
head->macho.arr[i].type = nl_64->n_type; | ||
head->macho.arr[i].sect = nl_64->n_sect; | ||
head->macho.arr[i].value = to_big_endian(head->macho.l_endian, nl_64->n_value); | ||
if (head->macho.arr[i].value > 0xfffffffffffffff) | ||
head->macho.len_value = get_length_value(head->macho.arr[i].value); | ||
nl_64 = (void *)nl_64 sizeof(*nl_64); | ||
i ; | ||
} | ||
m_sort(head, str_tab, 0, head->macho.n_syms - 1); | ||
print_symbols(file, head, str_tab); | ||
//FREE | ||
*/ | ||
return (res); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 6,7 @@ | |
/* By: pchadeni <[email protected]> # : # */ | ||
/* # # # # # # */ | ||
/* Created: 2019/03/27 13:25:49 by pchadeni # # # # */ | ||
/* Updated: 2019/04/15 18:31:55 by pchadeni ### ########.fr */ | ||
/* Updated: 2019/04/15 19:05:55 by pchadeni ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -58,7 58,6 @@ uint8_t list_symbols(t_finfo file, t_fhead *head, char *obj_n) | |
uint32_t lc_cmdsize; | ||
|
||
i = 0; | ||
ft_printf("List -> %s\n", head->macho.obj_name); | ||
if (init_symbols_struct(file, head, obj_n)) | ||
return (handle_error(file.name, E_CORRUPT, head->opts)); | ||
lc = head->macho.lc; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 6,7 @@ | |
/* By: pchadeni <[email protected]> # : # */ | ||
/* # # # # # # */ | ||
/* Created: 2019/03/28 15:49:23 by pchadeni # # # # */ | ||
/* Updated: 2019/04/15 18:23:41 by pchadeni ### ########.fr */ | ||
/* Updated: 2019/04/15 19:05:52 by pchadeni ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -79,7 79,6 @@ void print_symbols(t_finfo f, t_fhead *h, char *st) | |
uint8_t padding; | ||
t_section *sect; | ||
|
||
ft_printf("%s output\n", f.name); | ||
padding = h->macho.is64 ? 16 : 8; | ||
print_header(f, h); | ||
if ((h->opts & FT_NM)) | ||
|