diff options
Diffstat (limited to 'src/format')
-rw-r--r-- | src/format/elf/elf-int.c | 56 | ||||
-rw-r--r-- | src/format/elf/elf-int.h | 2 | ||||
-rw-r--r-- | src/format/elf/elf.c | 2 | ||||
-rw-r--r-- | src/format/elf/helper_x86.c | 4 | ||||
-rw-r--r-- | src/format/elf/strings.c | 2 | ||||
-rw-r--r-- | src/format/elf/symbols.c | 4 | ||||
-rw-r--r-- | src/format/format.c | 3 | ||||
-rw-r--r-- | src/format/symbol.c | 64 | ||||
-rw-r--r-- | src/format/symbol.h | 12 |
9 files changed, 137 insertions, 12 deletions
diff --git a/src/format/elf/elf-int.c b/src/format/elf/elf-int.c index 353ae05..17aeaf2 100644 --- a/src/format/elf/elf-int.c +++ b/src/format/elf/elf-int.c @@ -27,11 +27,13 @@ #include <string.h> +#include "../../arch/raw.h" + + /****************************************************************************** * * -* Paramètres : content = contenu binaire à parcourir. * -* length = taille du contenu en question. * +* Paramètres : format = informations chargées à consulter. * * header = en-tête à déterminer. [OUT] * * is_32b = indique si le format est en 32 ou 64 bits. [OUT] * * endian = boutisme reconnu dans le format. [OUT] * @@ -44,10 +46,27 @@ * * ******************************************************************************/ -bool read_elf_header(const bin_t *content, off_t length, elf_header *header, bool *is_32b, SourceEndian *endian) +bool read_elf_header(GElfFormat *format, elf_header *header, bool *is_32b, SourceEndian *endian) { bool result; /* Bilan à retourner */ + const bin_t *content; /* Contenu binaire à lire */ + off_t length; /* Taille totale du contenu */ off_t pos; /* Position de lecture */ + GArchInstruction *instr; /* Instruction décodée */ + + + vmpa2t *pos2; + + + GBinSymbol *symbol; + + size_t i; /* Boucle de parcours */ + GArchOperand *operand; /* Opérande à venir modifier */ + + + + content = G_BIN_FORMAT(format)->content; + length = G_BIN_FORMAT(format)->length; result = (length >= EI_NIDENT); @@ -89,6 +108,37 @@ bool read_elf_header(const bin_t *content, off_t length, elf_header *header, boo break; } + + pos2 = make_vmpa(0, 0x123); + + + + instr = g_raw_instruction_new_array(content, MDS_8_BITS, 4, pos2, 4, *endian); + + + for (i = 1; i < 4; i++) + { + operand = g_arch_instruction_get_operand(instr, i); + g_imm_operand_set_display(G_IMM_OPERAND(operand), IOD_CHAR); + } + + + + + symbol = g_binary_symbol_new(STP_OBJECT, "toto", 0); + + printf("TOTO\n"); + + g_binary_symbol_attach_instruction(symbol, instr); + g_binary_format_add_symbol(format, symbol); + + + + + + + + if (*is_32b) { result &= read_u16(&header->hdr32.e_type, content, &pos, length, *endian); diff --git a/src/format/elf/elf-int.h b/src/format/elf/elf-int.h index 77548da..783d27e 100644 --- a/src/format/elf/elf-int.h +++ b/src/format/elf/elf-int.h @@ -53,7 +53,7 @@ struct _GElfFormatClass /* Procède à la lecture de l'en-tête d'un contenu binaire ELF. */ -bool read_elf_header(const bin_t *, off_t, elf_header *, bool *, SourceEndian *); +bool read_elf_header(GElfFormat *, elf_header *, bool *, SourceEndian *); /* Procède à la lecture d'une en-tête de programme ELF. */ bool read_elf_program_header(const GElfFormat *, off_t *, elf_phdr *); diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c index e618658..4a56c52 100644 --- a/src/format/elf/elf.c +++ b/src/format/elf/elf.c @@ -176,7 +176,7 @@ GBinFormat *g_elf_format_new(const bin_t *content, off_t length) g_binary_format_set_content(G_BIN_FORMAT(result), content, length); - if (!read_elf_header(content, length, &result->header, &result->is_32b, &result->endian)) + if (!read_elf_header(result, &result->header, &result->is_32b, &result->endian)) { /* TODO */ return NULL; diff --git a/src/format/elf/helper_x86.c b/src/format/elf/helper_x86.c index 7d85311..d921592 100644 --- a/src/format/elf/helper_x86.c +++ b/src/format/elf/helper_x86.c @@ -295,7 +295,7 @@ void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instru g_binary_routine_set_address(routine, address); - g_binary_format_add_routine(G_BIN_FORMAT(format), routine); + ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine); /* Symbole uniquement */ @@ -403,7 +403,7 @@ void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instru g_binary_routine_set_address(routine, address); - g_binary_format_add_routine(G_BIN_FORMAT(format), routine); + ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine); /* Symbole uniquement */ diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c index b75c014..09bd442 100644 --- a/src/format/elf/strings.c +++ b/src/format/elf/strings.c @@ -174,7 +174,7 @@ bool parse_elf_string_data(GElfFormat *format, off_t start, off_t size, vmpa_t a symbol = g_binary_symbol_new(STP_STRING, NULL, address + i - start); g_binary_symbol_set_alt_name(symbol, strndup((const char *)&content[i], end - i)); - g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); + ///// reactiver g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); i = end; result = true; diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c index 02197a0..c480c51 100644 --- a/src/format/elf/symbols.c +++ b/src/format/elf/symbols.c @@ -223,7 +223,7 @@ static bool load_elf_internal_symbols(GElfFormat *format) g_binary_routine_set_address(routine, ELF_SYM(format, sym, st_value)); g_binary_routine_set_size(routine, ELF_SYM(format, sym, st_size)); - g_binary_format_add_routine(G_BIN_FORMAT(format), routine); + ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine); /* Symbole uniquement */ @@ -231,7 +231,7 @@ static bool load_elf_internal_symbols(GElfFormat *format) g_binary_symbol_attach_routine(symbol, routine); - g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); + ///// reactiver g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); } diff --git a/src/format/format.c b/src/format/format.c index 4b5dfb5..8771c46 100644 --- a/src/format/format.c +++ b/src/format/format.c @@ -193,6 +193,9 @@ const bin_t *g_binary_format_get_content(const GBinFormat *format, off_t *length void g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) { + + printf("current :: %d (%p)\n", (int)format->symbols_count, format->symbols); + format->symbols = (GBinSymbol **)realloc(format->symbols, ++format->symbols_count * sizeof(GBinSymbol *)); diff --git a/src/format/symbol.c b/src/format/symbol.c index 467bfd2..b478dc7 100644 --- a/src/format/symbol.c +++ b/src/format/symbol.c @@ -42,6 +42,7 @@ struct _GBinSymbol union { + GArchInstruction *instr; /* Instruction correspondante */ GBinRoutine *routine; /* Compléments pour fonction */ } extra; @@ -178,6 +179,14 @@ const char *g_binary_symbol_to_string(const GBinSymbol *symbol) } +vmpa_t g_binary_symbol_get_address(const GBinSymbol *symbol) +{ + + return 0; + +} + + /****************************************************************************** * * * Paramètres : symbol = symbole à venir consulter. * @@ -190,9 +199,19 @@ const char *g_binary_symbol_to_string(const GBinSymbol *symbol) * * ******************************************************************************/ -vmpa_t g_binary_symbol_get_address(const GBinSymbol *symbol) +const vmpa2t *g_binary_symbol_get_address2(const GBinSymbol *symbol) { - return symbol->address; + const vmpa2t *result; /* Localisation à retourner */ + + switch (symbol->type) + { + case STP_DATA: + result = g_arch_instruction_get_location2(symbol->extra.instr, NULL); + break; + + } + + return result; } @@ -270,3 +289,44 @@ void g_binary_symbol_attach_routine(GBinSymbol *symbol, GBinRoutine *routine) symbol->extra.routine = routine; } + + +/****************************************************************************** +* * +* Paramètres : symbol = symbole à venir consulter. * +* instr = représentation du symbole associé. * +* * +* Description : Attache l'instruction associée au symbole. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_binary_symbol_attach_instruction(GBinSymbol *symbol, GArchInstruction *instr) +{ + symbol->type = STP_DATA; + + symbol->extra.instr = instr; + +} + + +/****************************************************************************** +* * +* Paramètres : symbol = symbole à venir consulter. * +* * +* Description : Fournit l'éventuelle instruction associée au symbole. * +* * +* Retour : - * +* * +* Remarques : Il n'y a pas de transfert de propriété ici ! * +* * +******************************************************************************/ + +GArchInstruction *g_binary_symbol_get_instruction(const GBinSymbol *symbol) +{ + return symbol->extra.instr; + +} diff --git a/src/format/symbol.h b/src/format/symbol.h index 7f0cd1c..bfbf541 100644 --- a/src/format/symbol.h +++ b/src/format/symbol.h @@ -35,6 +35,7 @@ /* Types de symbole */ typedef enum _SymbolType { + STP_DATA, /* Données brutes */ STP_OBJECT, /* Objet quelconque */ STP_FUNCTION, /* Simple morceau de code */ STP_STRING /* Chaîne de caractères */ @@ -71,6 +72,11 @@ const char *g_binary_symbol_to_string(const GBinSymbol *); /* Fournit l'adresse associée à un symbole. */ vmpa_t g_binary_symbol_get_address(const GBinSymbol *); + +/* Fournit l'adresse associée à un symbole. */ +const vmpa2t *g_binary_symbol_get_address2(const GBinSymbol *); + + /* Fournit la taille officielle d'un symbole. */ off_t g_binary_symbol_get_size(const GBinSymbol *); @@ -80,6 +86,12 @@ void g_binary_symbol_set_alt_name(GBinSymbol *, char *); /* Attache la routine associée au symbole. */ void g_binary_symbol_attach_routine(GBinSymbol *, GBinRoutine *); +/* Attache l'instruction associée au symbole. */ +void g_binary_symbol_attach_instruction(GBinSymbol *, GArchInstruction *); + +/* Fournit l'éventuelle instruction associée au symbole. */ +GArchInstruction *g_binary_symbol_get_instruction(const GBinSymbol *); + #endif /* _FORMAT_SYMBOL_H */ |