simple fat
This commit is contained in:
parent
6159ea6e71
commit
7274e13075
6 changed files with 59 additions and 5 deletions
16
.vscode/launch.json
vendored
16
.vscode/launch.json
vendored
|
@ -48,6 +48,22 @@
|
|||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"osx": {
|
||||
"MIMode": "lldb"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "fat",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/debug_bld/ft_nm",
|
||||
"args": ["/usr/bin/javah"],
|
||||
"preLaunchTask": "build",
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"osx": {
|
||||
"MIMode": "lldb"
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/05/06 22:37:16 by foton #+# #+# */
|
||||
/* Updated: 2019/07/27 18:10:09 by gtertysh ### ########.fr */
|
||||
/* Updated: 2019/07/27 19:50:54 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include <mach-o/loader.h>
|
||||
#include <mach-o/nlist.h>
|
||||
#include <mach-o/fat.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct symtab_command t_symtab_command;
|
||||
|
@ -35,7 +36,6 @@ typedef struct s_nm_file
|
|||
void *file;
|
||||
uint32_t size;
|
||||
int fd;
|
||||
const char *filename;
|
||||
} t_nm_file;
|
||||
|
||||
typedef struct s_nm_mach_64
|
||||
|
@ -73,6 +73,10 @@ void close_file
|
|||
t_nm_file *file
|
||||
);
|
||||
|
||||
void fat
|
||||
(
|
||||
t_nm_file *file
|
||||
);
|
||||
|
||||
void macho64
|
||||
(
|
||||
|
|
|
@ -32,6 +32,7 @@ sources = [
|
|||
'src/nm_file.c',
|
||||
'src/macho64.c',
|
||||
'src/macho32.c',
|
||||
'src/fat.c',
|
||||
'src/print_address.c',
|
||||
'src/find_symbol_table_command.c',
|
||||
]
|
||||
|
|
33
src/fat.c
Normal file
33
src/fat.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "ft_nm.h"
|
||||
#include "libft.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void fat(t_nm_file *file)
|
||||
{
|
||||
struct fat_arch *arch_runner;
|
||||
struct fat_header *header;
|
||||
t_nm_file arch_file;
|
||||
uint32_t i;
|
||||
|
||||
header = (struct fat_header *)file->file;
|
||||
|
||||
if (header->magic != FAT_CIGAM)
|
||||
{
|
||||
ft_putstr_fd("only 32bit big endian fat binaries supported\n",
|
||||
STDERR_FILENO);
|
||||
exit(1);
|
||||
}
|
||||
arch_runner = file->file + sizeof(struct fat_header);
|
||||
i = 0;
|
||||
while (i < OSSwapInt32(header->nfat_arch))
|
||||
{
|
||||
if (OSSwapInt32(arch_runner->cputype) == CPU_TYPE_X86_64)
|
||||
{
|
||||
arch_file.file = file->file + OSSwapInt32(arch_runner->offset);
|
||||
arch_file.size = OSSwapInt32(arch_runner->size);
|
||||
macho64(&arch_file);
|
||||
}
|
||||
arch_runner = arch_runner + sizeof(struct fat_arch);
|
||||
i++;
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/07/13 14:52:27 by gtertysh #+# #+# */
|
||||
/* Updated: 2019/07/27 17:57:52 by gtertysh ### ########.fr */
|
||||
/* Updated: 2019/07/27 19:35:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -26,6 +26,8 @@ void hanldle_file(const char *filename)
|
|||
macho64(&file);
|
||||
else if (magic == MH_MAGIC)
|
||||
macho32(&file);
|
||||
else if (magic == FAT_CIGAM)
|
||||
fat(&file);
|
||||
else
|
||||
ft_putstr("invalid magic number.");
|
||||
close_file(&file);
|
||||
|
|
|
@ -12,7 +12,6 @@ void init_file(t_nm_file *file)
|
|||
{
|
||||
file->fd = -1;
|
||||
file->file = NULL;
|
||||
file->filename = NULL;
|
||||
file->size = 0;
|
||||
}
|
||||
|
||||
|
@ -20,7 +19,6 @@ void open_file(const char *filename, t_nm_file *file)
|
|||
{
|
||||
struct stat stat_buff;
|
||||
|
||||
file->filename = filename;
|
||||
file->fd = open(filename, O_RDONLY);
|
||||
if (file->fd == -1)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue