diff options
Diffstat (limited to 'src/format/symbol.c')
-rw-r--r-- | src/format/symbol.c | 244 |
1 files changed, 51 insertions, 193 deletions
diff --git a/src/format/symbol.c b/src/format/symbol.c index ba0c327..0b300bd 100644 --- a/src/format/symbol.c +++ b/src/format/symbol.c @@ -121,6 +121,7 @@ static void g_binary_symbol_class_init(GBinSymbolClass *klass) static void g_binary_symbol_init(GBinSymbol *symbol) { + g_binary_symbol_set_target_type(symbol, STP_COUNT); } @@ -162,8 +163,6 @@ static void g_binary_symbol_interface_init(GLineGeneratorInterface *iface) static void g_binary_symbol_dispose(GBinSymbol *symbol) { - /* TODO... */ - G_OBJECT_CLASS(g_binary_symbol_parent_class)->dispose(G_OBJECT(symbol)); } @@ -183,7 +182,8 @@ static void g_binary_symbol_dispose(GBinSymbol *symbol) static void g_binary_symbol_finalize(GBinSymbol *symbol) { - free(symbol->alt); + if (symbol->alt != NULL) + free(symbol->alt); G_OBJECT_CLASS(g_binary_symbol_parent_class)->finalize(G_OBJECT(symbol)); @@ -192,7 +192,8 @@ static void g_binary_symbol_finalize(GBinSymbol *symbol) /****************************************************************************** * * -* Paramètres : type = type de symbole à créer. * +* Paramètres : range = espace couvert par le nouveau symbole. * +* type = type de symbole à créer. * * * * Description : Crée un nouveau symbole d'exécutable. * * * @@ -202,13 +203,14 @@ static void g_binary_symbol_finalize(GBinSymbol *symbol) * * ******************************************************************************/ -GBinSymbol *g_binary_symbol_new(SymbolType type) +GBinSymbol *g_binary_symbol_new(const mrange_t *range, SymbolType type) { GBinSymbol *result; /* Nouveau symbole à renvoyer */ result = g_object_new(G_TYPE_BIN_SYMBOL, NULL); - result->type = type; + g_binary_symbol_set_range(result, range); + g_binary_symbol_set_target_type(result, type); return result; @@ -231,23 +233,8 @@ GBinSymbol *g_binary_symbol_new(SymbolType type) int g_binary_symbol_cmp(const GBinSymbol * const *a, const GBinSymbol * const *b) { int result; /* Bilan à retourner */ - const mrange_t *ra; /* Emplacement du symbole A */ - const mrange_t *rb; /* Emplacement du symbole B */ - - ra = g_binary_symbol_get_range(*a); - rb = g_binary_symbol_get_range(*b); - if (ra == NULL && rb == NULL) - result = 0; - - else if (ra != NULL && rb == NULL) - result = 1; - - else if (ra == NULL && rb != NULL) - result = -1; - - else - result = cmp_mrange(ra, rb); + result = cmp_mrange(&(*a)->range, &(*b)->range); return result; @@ -270,15 +257,8 @@ int g_binary_symbol_cmp(const GBinSymbol * const *a, const GBinSymbol * const *b int g_binary_symbol_cmp_with_vmpa(const GBinSymbol *symbol, const vmpa2t *addr) { int result; /* Bilan à retourner */ - const mrange_t *range; /* Emplacement du symbole */ - - range = g_binary_symbol_get_range(symbol); - if (range == NULL) - result = 1; - - else - result = cmp_mrange_with_vmpa(range, addr); + result = cmp_mrange_with_vmpa(&symbol->range, addr); return result; @@ -287,69 +267,10 @@ int g_binary_symbol_cmp_with_vmpa(const GBinSymbol *symbol, const vmpa2t *addr) /****************************************************************************** * * -* Paramètres : symbol = symbole à venir consulter. * -* * -* Description : Fournit le type du symbole. * -* * -* Retour : Type de symbole représenté. * -* * -* Remarques : - * -* * -******************************************************************************/ - -SymbolType g_binary_symbol_get_target_type(const GBinSymbol *symbol) -{ - return symbol->type; - -} - - -/****************************************************************************** -* * -* Paramètres : symbol = symbole à venir consulter. * +* Paramètres : symbol = symbole à mettre à jour. * +* range = plage mémoire ou physique déclarée. * * * -* Description : Fournit un étiquette pour viser un symbole. * -* * -* Retour : Chaîne de caractères renvoyant au symbole. * -* * -* Remarques : - * -* * -******************************************************************************/ - -const char *g_binary_symbol_get_label(const GBinSymbol *symbol) -{ - const char *result; /* Etiquette à retourner */ - - if (symbol->alt != NULL) - return symbol->alt; - - result = NULL; - - switch (symbol->type) - { - case STP_ROUTINE: - case STP_ENTRY_POINT: - case STP_CODE_LABEL: - result = g_binary_routine_get_declarator(symbol->extra.routine, false); - break; - - default: - result = NULL; - break; - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : symbol = symbole à venir consulter. * -* alt = désignation humaine alternative à favoriser. * -* * -* Description : Définit un autre nom pour le symbole. * +* Description : Définit la couverture physique / en mémoire d'un symbole. * * * * Retour : - * * * @@ -357,15 +278,9 @@ const char *g_binary_symbol_get_label(const GBinSymbol *symbol) * * ******************************************************************************/ -void g_binary_symbol_set_alt_label(GBinSymbol *symbol, const char *alt) +void g_binary_symbol_set_range(GBinSymbol *symbol, const mrange_t *range) { - if (symbol->alt != NULL) - free(symbol->alt); - - if (alt == NULL) - symbol->alt = NULL; - else - symbol->alt = strdup(alt); + copy_mrange(&symbol->range, range); } @@ -384,42 +299,17 @@ void g_binary_symbol_set_alt_label(GBinSymbol *symbol, const char *alt) const mrange_t *g_binary_symbol_get_range(const GBinSymbol *symbol) { - const mrange_t *result; /* Plage à retourner */ - - result = NULL; - - switch (symbol->type) - { - case STP_DATA: - case STP_RO_STRING: - result = g_arch_instruction_get_range(symbol->extra.instr); - break; - - case STP_ROUTINE: - case STP_ENTRY_POINT: - case STP_CODE_LABEL: - result = g_binary_routine_get_range(symbol->extra.routine); - break; - - default: - /* FIXME : assert(0); */ - result = NULL; - break; - - } - - return result; + return &symbol->range; } /****************************************************************************** * * -* Paramètres : symbol = symbole à venir consulter. * -* routine = prototype de la fonction représentée. * -* type = (nouveau) type du symbole attaché. * +* Paramètres : symbol = symbole à venir modifier. * +* type = type de symbole représenté. * * * -* Description : Attache la routine associée au symbole. * +* Description : Définit le type du symbole. * * * * Retour : - * * * @@ -427,83 +317,58 @@ const mrange_t *g_binary_symbol_get_range(const GBinSymbol *symbol) * * ******************************************************************************/ -void _g_binary_symbol_attach_routine(GBinSymbol *symbol, GBinRoutine *routine, SymbolType type) +void g_binary_symbol_set_target_type(GBinSymbol *symbol, SymbolType type) { - if (symbol->extra.routine != NULL) - g_object_unref(G_OBJECT(symbol->extra.routine)); - symbol->type = type; - symbol->extra.routine = routine; - } /****************************************************************************** * * -* Paramètres : symbol = symbole à venir consulter. * -* routine = prototype de la fonction représentée. * +* Paramètres : symbol = symbole à venir consulter. * * * -* Description : Attache la routine associée au symbole. * +* Description : Fournit le type du symbole. * * * -* Retour : - * +* Retour : Type de symbole représenté. * * * * Remarques : - * * * ******************************************************************************/ -void g_binary_symbol_attach_routine(GBinSymbol *symbol, GBinRoutine *routine) +SymbolType g_binary_symbol_get_target_type(const GBinSymbol *symbol) { - _g_binary_symbol_attach_routine(symbol, routine, symbol->type); + return symbol->type; } /****************************************************************************** * * -* Paramètres : symbol = symbole à venir manipuler. * -* instr = représentation du symbole associé. * +* Paramètres : symbol = symbole à venir consulter. * * * -* Description : Attache l'instruction associée au symbole. * +* Description : Fournit une étiquette pour viser un symbole. * * * -* Retour : - * +* Retour : Chaîne de caractères renvoyant au symbole. * * * * Remarques : - * * * ******************************************************************************/ -void g_binary_symbol_attach_instruction(GBinSymbol *symbol, GArchInstruction *instr) +const char *g_binary_symbol_get_label(GBinSymbol *symbol) { - if (symbol->type != STP_RO_STRING) - symbol->type = STP_DATA; - - symbol->extra.instr = instr; - -} - - -/****************************************************************************** -* * -* Paramètres : symbol = symbole à venir consulter. * -* * -* Description : Fournit l'éventuelle routine associée au symbole. * -* * -* Retour : Instance GLib en place ou NULL si aucune. * -* * -* Remarques : Il n'y a pas de transfert de propriété ici ! * -* * -******************************************************************************/ + const char *result; /* Etiquette à retourner */ -GBinRoutine *g_binary_symbol_get_routine(const GBinSymbol *symbol) -{ - /* TODO : rajouter des assert() sur le type de symbole */ + if (symbol->alt != NULL) + result = symbol->alt; - /* TODO : ref() */ + else if (G_BIN_SYMBOL_GET_CLASS(symbol)->get_label != NULL) + result = G_BIN_SYMBOL_GET_CLASS(symbol)->get_label(symbol); - if (symbol->type != STP_ROUTINE && symbol->type != STP_ENTRY_POINT) - return NULL; + else + result = NULL; - return symbol->extra.routine; + return result; } @@ -511,22 +376,25 @@ GBinRoutine *g_binary_symbol_get_routine(const GBinSymbol *symbol) /****************************************************************************** * * * Paramètres : symbol = symbole à venir consulter. * +* alt = désignation humaine alternative à favoriser. * * * -* Description : Fournit l'éventuelle instruction associée au symbole. * +* Description : Définit un autre nom pour le symbole. * * * -* Retour : Instance GLib en place ou NULL si aucune. * +* Retour : - * * * -* Remarques : Il n'y a pas de transfert de propriété ici ! * +* Remarques : - * * * ******************************************************************************/ -GArchInstruction *g_binary_symbol_get_instruction(const GBinSymbol *symbol) +void g_binary_symbol_set_alt_label(GBinSymbol *symbol, const char *alt) { - /* TODO : rajouter des assert() sur le type de symbole */ - - /* TODO : ref() */ + if (symbol->alt != NULL) + free(symbol->alt); - return symbol->extra.instr; + if (alt == NULL) + symbol->alt = NULL; + else + symbol->alt = strdup(alt); } @@ -600,11 +468,7 @@ static size_t g_binary_symbol_count_lines(const GBinSymbol *symbol) void g_binary_symbol_compute_addr(const GBinSymbol *symbol, gint x, vmpa2t *addr, size_t index, size_t repeat) { - const mrange_t *range; /* Emplacement à manipuler */ - - range = g_binary_symbol_get_range(symbol); - - copy_vmpa(addr, get_mrange_addr(range)); + copy_vmpa(addr, get_mrange_addr(&symbol->range)); } @@ -627,11 +491,8 @@ void g_binary_symbol_compute_addr(const GBinSymbol *symbol, gint x, vmpa2t *addr static int g_binary_symbol_contains_addr(const GBinSymbol *symbol, const vmpa2t *addr, size_t index, size_t repeat) { int result; /* Conclusion à retourner */ - const mrange_t *range; /* Emplacement à manipuler */ - - range = g_binary_symbol_get_range(symbol); - result = cmp_mrange_with_vmpa(range, addr); + result = cmp_mrange_with_vmpa(&symbol->range, addr); return result; @@ -677,12 +538,9 @@ static BufferLineFlags g_binary_symbol_get_flags(const GBinSymbol *symbol, size_ static void g_binary_symbol_print(GBinSymbol *symbol, GBufferLine *line, size_t index, size_t repeat, const GBinContent *content) { - const mrange_t *range; /* Emplacement à manipuler */ const char *label; /* Etiquette à insérer */ - range = g_binary_symbol_get_range(symbol); - - g_buffer_line_fill_vmpa(line, get_mrange_addr(range), MDS_32_BITS_UNSIGNED, MDS_32_BITS_UNSIGNED); + g_buffer_line_fill_vmpa(line, get_mrange_addr(&symbol->range), MDS_32_BITS_UNSIGNED, MDS_32_BITS_UNSIGNED); label = g_binary_symbol_get_label(symbol); |