/* Copyright (C) 2008 Emmanuel Varoquaux
This file is part of XOS.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
#ifndef ELF_H
#define ELF_H
#include
#include
/* type de relocations */
enum {RT_NONE, RT_REL, RT_RELA};
struct program_data_struct {
struct {
unsigned program_header_table : 1;
unsigned dynamic_array : 1;
unsigned interpreter_name : 1;
} contents;
Elf32_Addr program_header_table_vaddr;
Elf32_Addr load_vaddr;
size_t mem_size;
Elf32_Addr dynamic_array_vaddr;
Elf32_Addr interpreter_name_vaddr;
};
struct dynamic_data_struct {
/* chaines de caracteres */
const char *string_table;
/* dependences */
const char *soname;
const char **needed_list;
int needed_list_size;
const char *rpath;
const char *runpath;
/* symboles */
const Elf32_Sym *symbol_table;
const Elf32_Word *symbol_hash_table;
/* relocations */
Elf32_Addr *global_offset_table;
unsigned symbolic : 1;
unsigned textrel : 1;
unsigned bind_now : 1;
const Elf32_Rel *rel_relocation_table;
int rel_relocation_table_size;
const Elf32_Rela *rela_relocation_table;
int rela_relocation_table_size;
int plt_relocation_type;
union {
const Elf32_Rel *rel;
const Elf32_Rela *rela;
} plt_relocation_table;
int plt_relocation_table_size;
/* constructeurs et destructeurs */
void (**preinit_func_array)();
int preinit_func_array_size;
void (*init_func)();
void (**init_func_array)();
int init_func_array_size;
void (*fini_func)();
void (**fini_func_array)();
int fini_func_array_size;
};
void fread_elf_header(Elf32_Ehdr *elf_header, FILE *fp, const char *filename);
void fread_program_header_table(Elf32_Phdr *program_header_table, size_t count, FILE *fp, const char *filename);
void clear_program_data(struct program_data_struct *program_data);
void read_program_header_table(const Elf32_Phdr *program_header_table, int count, struct program_data_struct *program_data, const char *filename);
void clear_dynamic_data(struct dynamic_data_struct *dynamic_data);
void dispose_dynamic_data(struct dynamic_data_struct *dynamic_data);
void read_dynamic_array(const Elf32_Dyn *dynamic_array, void *base_address, struct dynamic_data_struct *dynamic_data);
#endif