82 lines
1.7 KiB
C
82 lines
1.7 KiB
C
#ifndef WOODY_H
|
|
#define WOODY_H
|
|
|
|
#include "../ft_printf/includes/ft_printf.h"
|
|
#include <stdbool.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <sys/mman.h>
|
|
#include <fcntl.h>
|
|
#include <elf.h>
|
|
#include <stdint.h>
|
|
|
|
|
|
#define JUMP "\xe9"
|
|
#define WOODY "....WOODY...."
|
|
#define JUMP_VALUE "\xda\xda\xda"
|
|
|
|
#define TEXT_OFFSET "\xba\xba\xba\xba\xba\xba\xba\xba"
|
|
#define SECTION_SIZE "\xca\xca\xca\xca\xca\xca\xca\xca"
|
|
|
|
typedef struct payload
|
|
{
|
|
char *payload;
|
|
int len;
|
|
} t_payload;
|
|
|
|
typedef struct elf32
|
|
{
|
|
Elf32_Ehdr *Ehdr;
|
|
Elf32_Phdr *Phdr;
|
|
Elf32_Shdr *Shdr;
|
|
Elf32_Shdr *text_section;
|
|
} t_elf32;
|
|
|
|
typedef struct elf64
|
|
{
|
|
Elf64_Ehdr *Ehdr;
|
|
Elf64_Phdr *Phdr;
|
|
Elf64_Shdr *Shdr;
|
|
Elf64_Shdr *text_section;
|
|
} t_elf64;
|
|
|
|
typedef struct elf_content
|
|
{
|
|
long unsigned int file_size;
|
|
char *file_path;
|
|
char *file;
|
|
t_elf32 *elf32;
|
|
t_elf64 *elf64;
|
|
} t_elf_content;
|
|
|
|
// utils.c
|
|
void *fetch(char *file, unsigned long file_size, unsigned long offset_to_data, unsigned long supposed_data_size);
|
|
int ft_put_error(char *str);
|
|
char *get_string(char *str, char *end_file);
|
|
int get_symbols_count(int sh_size, int sh_entsize);
|
|
char *get_section_name(t_elf_content *woody, int section_index);
|
|
int elf_magic_numbers(char *str);
|
|
|
|
// payload.c
|
|
t_payload *get_payload();
|
|
int insert_payload(t_elf_content *woody, t_payload *payload, size_t payload_position, unsigned int e_entry, unsigned int p_offset, unsigned int p_memsz);
|
|
|
|
// woody32.c
|
|
int get_elf_sections32(t_elf_content *woody);
|
|
int inject32(t_elf_content *woody);
|
|
|
|
// woody64.c
|
|
int get_elf_sections64(t_elf_content *woody);
|
|
int inject64(t_elf_content *woody);
|
|
|
|
|
|
// encrypt.c
|
|
void encrypt(char *file, unsigned long int offset, unsigned long int size);
|
|
|
|
#endif
|
|
|