47 lines
1009 B
C
47 lines
1009 B
C
#include "../includes/woody.h"
|
|
|
|
int get_elf_file(t_elf_content *woody)
|
|
{
|
|
int fd;
|
|
off_t off;
|
|
|
|
fd = open(woody->file_path, O_RDONLY);
|
|
if (fd < 0)
|
|
{
|
|
ft_printf("Error: Failed to open \'%s\'\n", woody->file_path);
|
|
return EXIT_FAILURE;
|
|
}
|
|
off = lseek(fd, 0, SEEK_END);
|
|
if (off == -1)
|
|
{
|
|
close(fd);
|
|
ft_printf("Error: Failed to read file offset \'%s\'\n", woody->file_path);
|
|
return EXIT_FAILURE;
|
|
}
|
|
woody->file_size = off;
|
|
woody->file = mmap(NULL, woody->file_size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0);
|
|
if (woody->file == MAP_FAILED)
|
|
{
|
|
close(fd);
|
|
ft_printf("Error: Failed to map file \'%s\'\n", woody->file_path);
|
|
return EXIT_FAILURE;
|
|
}
|
|
close(fd);
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
int main(int ac, char **av)
|
|
{
|
|
t_elf_content woody;
|
|
if (ac != 2)
|
|
{
|
|
return ft_put_error("Woody_woodpacker take 1 argument\n");
|
|
}
|
|
woody.file_path = av[1];
|
|
int ret = get_elf_file(&woody);
|
|
if (ret == EXIT_FAILURE)
|
|
return ret;
|
|
return prepare_injection(&woody);
|
|
}
|
|
|