basic idea of ar
This commit is contained in:
parent
d122896244
commit
d991383a26
3 changed files with 46 additions and 2 deletions
16
.vscode/launch.json
vendored
16
.vscode/launch.json
vendored
|
@ -64,6 +64,22 @@
|
||||||
"environment": [],
|
"environment": [],
|
||||||
"externalConsole": false,
|
"externalConsole": false,
|
||||||
"MIMode": "gdb",
|
"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": {
|
"osx": {
|
||||||
"MIMode": "lldb"
|
"MIMode": "lldb"
|
||||||
}
|
}
|
||||||
|
|
27
src/ar.c
27
src/ar.c
|
@ -1,6 +1,31 @@
|
||||||
#include "ft_nm.h"
|
#include "ft_nm.h"
|
||||||
|
#include "libft.h"
|
||||||
|
#include <ar.h>
|
||||||
|
|
||||||
|
|
||||||
void ar(t_nm_file *file)
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
|
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/07/13 14:52:27 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;
|
t_nm_file file;
|
||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
|
|
||||||
|
// create dispatch table for this bullshit
|
||||||
init_file(&file);
|
init_file(&file);
|
||||||
open_file(filename, &file);
|
open_file(filename, &file);
|
||||||
magic = *(uint32_t *)file.file;
|
magic = *(uint32_t *)file.file;
|
||||||
|
@ -28,6 +29,8 @@ void hanldle_file(const char *filename)
|
||||||
macho32(&file);
|
macho32(&file);
|
||||||
else if (magic == FAT_CIGAM)
|
else if (magic == FAT_CIGAM)
|
||||||
fat(&file);
|
fat(&file);
|
||||||
|
else if (ft_strncmp(file.file, ARMAG, SARMAG) == 0)
|
||||||
|
ar(&file);
|
||||||
else
|
else
|
||||||
ft_putstr("invalid magic number.");
|
ft_putstr("invalid magic number.");
|
||||||
close_file(&file);
|
close_file(&file);
|
||||||
|
|
Loading…
Reference in a new issue