Skip to content

Commit

Permalink
Create a second tools file
Browse files Browse the repository at this point in the history
  • Loading branch information
Medno committed Apr 30, 2019
1 parent 7dfef56 commit 768c036
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 31 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@
# By: pchadeni <[email protected]> # : # #
# # # # # # # #
# Created: 2018/01/08 14:57:58 by pchadeni # # # # #
# Updated: 2019/04/12 17:53:44 by pchadeni ### ########.fr #
# Updated: 2019/04/30 15:05:06 by pchadeni ### ########.fr #
# #
# **************************************************************************** #

Expand All @@ -29,6 29,7 @@ MAIN_SRCS = type.c \
print.c \
print_nm.c \
tools.c \
tools_2.c \
symbols_struct.c \
handle_fat.c \
handle_archive.c \
Expand Down
2 changes: 2 additions & 0 deletions inc/lib_nm_otool.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 151,8 @@ 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 free_array(t_fhead *head, uint32_t end);
uint8_t get_length_value(uint64_t value);
uint8_t handle_macho(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);
Expand Down
43 changes: 13 additions & 30 deletions srcs/handle_macho_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 6,21 @@
/* By: pchadeni <[email protected]> # : # */
/* # # # # # # */
/* Created: 2019/04/04 17:05:35 by pchadeni # # # # */
/* Updated: 2019/04/30 13:27:32 by pchadeni ### ########.fr */
/* Updated: 2019/04/30 16:39:02 by pchadeni ### ########.fr */
/* */
/* ************************************************************************** */

#include "lib_nm_otool.h"

uint8_t free_array(t_fhead *head, uint32_t end)
uint8_t dup_stab_name(t_fhead *head, uint8_t bs, char *str, uint32_t i)
{
uint32_t i;

i = 0;
while (i < end)
{
free(head->macho.arr[i].name);
i ;
}
return (1);
}

uint8_t get_length_value(uint64_t value)
{
uint8_t res;
char *itoa_str;

itoa_str = ft_itoa_base(value, 16);
res = ft_strlen(itoa_str);
free(itoa_str);
return (res);
if (bs)
head->macho.arr[i].name = ft_strdup("bad string index");
else
head->macho.arr[i].name = ft_strdup(str);
if (!head->macho.arr[i].name)
return (1);
return (0);
}

uint8_t handle_32(t_fhead *head, char *str_tab, uint32_t strsize, uint32_t soff)
Expand All @@ -49,10 36,8 @@ uint8_t handle_32(t_fhead *head, char *str_tab, uint32_t strsize, uint32_t soff)
strx = to_big_endian(head->macho.l_endian, nl->n_un.n_strx);
if (strx > strsize && head->opts & FT_OTOOL)
return (free_array(head, i));
else if (strx > strsize)
head->macho.arr[i].name = ft_strdup("bad string index");
else
head->macho.arr[i].name = ft_strdup(strx str_tab);
else if (dup_stab_name(head, strx > strsize, strx str_tab, i))
return (free_array(head, i));
head->macho.arr[i].type = nl->n_type;
head->macho.arr[i].sect = nl->n_sect;
head->macho.arr[i].value =
Expand All @@ -78,10 63,8 @@ uint8_t handle_64(t_fhead *head, char *str_tab, uint32_t strsize, uint32_t soff)
strx = to_big_endian(head->macho.l_endian, nl_64->n_un.n_strx);
if (strx > strsize && (head->opts & FT_OTOOL) && !(head->opts & OPT_H))
return (free_array(head, i));
else if (strx > strsize)
head->macho.arr[i].name = ft_strdup("bad string index");
else
head->macho.arr[i].name = ft_strdup(strx str_tab);
else if (dup_stab_name(head, strx > strsize, strx str_tab, i))
return (free_array(head, i));
head->macho.arr[i].type = nl_64->n_type;
head->macho.arr[i].sect = nl_64->n_sect;
head->macho.arr[i].value =
Expand Down
37 changes: 37 additions & 0 deletions srcs/tools_2.c
Original file line number Diff line number Diff line change
@@ -0,0 1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tools_2.c : : : : : : */
/* : : : */
/* By: pchadeni <[email protected]> # : # */
/* # # # # # # */
/* Created: 2019/04/30 14:54:57 by pchadeni # # # # */
/* Updated: 2019/04/30 14:55:34 by pchadeni ### ########.fr */
/* */
/* ************************************************************************** */

#include "lib_nm_otool.h"

uint8_t free_array(t_fhead *head, uint32_t end)
{
uint32_t i;

i = 0;
while (i < end)
{
free(head->macho.arr[i].name);
i ;
}
return (1);
}

uint8_t get_length_value(uint64_t value)
{
uint8_t res;
char *itoa_str;

itoa_str = ft_itoa_base(value, 16);
res = ft_strlen(itoa_str);
free(itoa_str);
return (res);
}

0 comments on commit 768c036

Please sign in to comment.