diff --git a/.vscode/launch.json b/.vscode/launch.json index fd8fdd1..f1029b6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -64,6 +64,22 @@ "environment": [], "externalConsole": false, "MIMode": "gdb", + "osx": { + "MIMode": "lldb" + } + }, + { + "name": "ar", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/debug_bld/ft_nm", + "args": ["${workspaceFolder}/debug_bld/subprojects/libft/libft.a"], + "preLaunchTask": "build", + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", "osx": { "MIMode": "lldb" } diff --git a/src/ar.c b/src/ar.c index bdece4b..c0cc65a 100644 --- a/src/ar.c +++ b/src/ar.c @@ -1,6 +1,31 @@ #include "ft_nm.h" +#include "libft.h" +#include + void ar(t_nm_file *file) { - (void)file; + struct ar_hdr *runner; + char *long_name; + size_t offset; + t_nm_file obj; + + + runner = file->file + SARMAG; + while ((void *)runner < file->file + file->size) + { + if (ft_strncmp(runner->ar_name, AR_EFMT1, 3) == 0) + { + offset = ft_atoi(&runner->ar_name[3]); + long_name = (char *)runner + sizeof(struct ar_hdr); + ft_putstr("\n"); + ft_putstr(long_name); + ft_putstr("\n"); + obj.file = (void *)((size_t)runner + sizeof(struct ar_hdr) + offset); + obj.size = ft_atoi(runner->ar_size) - offset; + if (*(uint32_t *)obj.file == MH_MAGIC_64) + macho64(&obj); + } + runner = (struct ar_hdr *)((size_t)runner + ft_atoi(runner->ar_size) + sizeof(struct ar_hdr)); + } } \ No newline at end of file diff --git a/src/main.c b/src/main.c index 42d153e..8dc5f9e 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: gtertysh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/13 14:52:27 by gtertysh #+# #+# */ -/* Updated: 2019/07/27 19:35:42 by gtertysh ### ########.fr */ +/* Updated: 2019/07/31 21:37:00 by gtertysh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ void hanldle_file(const char *filename) t_nm_file file; uint32_t magic; + // create dispatch table for this bullshit init_file(&file); open_file(filename, &file); magic = *(uint32_t *)file.file; @@ -28,6 +29,8 @@ void hanldle_file(const char *filename) macho32(&file); else if (magic == FAT_CIGAM) fat(&file); + else if (ft_strncmp(file.file, ARMAG, SARMAG) == 0) + ar(&file); else ft_putstr("invalid magic number."); close_file(&file);