diff options
Diffstat (limited to 'src/format/format.c')
-rw-r--r-- | src/format/format.c | 189 |
1 files changed, 182 insertions, 7 deletions
diff --git a/src/format/format.c b/src/format/format.c index 5b96b59..88367f6 100644 --- a/src/format/format.c +++ b/src/format/format.c @@ -64,6 +64,9 @@ static void g_binary_format_delete_duplicated_symbols(GBinFormat *); /* Recherche le symbole associé à une adresse. */ static bool _g_binary_format_find_symbol(const GBinFormat *, const vmpa2t *, __compar_fn_t, size_t *, GBinSymbol **); +/* Recherche un symbole particulier. */ +static bool __g_binary_format_find_symbol(const GBinFormat *, const void *, __compar_fn_t, size_t *, GBinSymbol **); + /* Indique le type défini pour un format binaire générique. */ @@ -369,6 +372,31 @@ void g_binary_format_activate_disassembling_context(GBinFormat *format, GProcCon } +/****************************************************************************** +* * +* Paramètres : format = description de l'exécutable à manipuler. * +* status = barre de statut à tenir informée. * +* * +* Description : Réalise un traitement post-désassemblage. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_binary_format_complete_analysis(GBinFormat *format, GtkStatusStack *status) +{ + GBinFormatClass *class; /* Classe de l'instance */ + + class = G_BIN_FORMAT_GET_CLASS(format); + + if (class->complete != NULL) + class->complete(format, status); + +} + + /* ---------------------------------------------------------------------------------- */ /* RASSEMBLEMENT ET GESTION DE SYMBOLES */ @@ -450,6 +478,26 @@ void g_binary_format_lock_unlock_symbols_wr(GBinFormat *format, bool state) * * * Paramètres : format = architecture à consulter via la procédure. * * * +* Description : Assure qu'un verrou est bien posé pour l'accès aux symboles. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#ifndef NDEBUG +void g_binary_format_check_for_symbols_lock(const GBinFormat *format) +{ + assert(g_atomic_int_get(&format->sym_locked) > 0); + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : format = architecture à consulter via la procédure. * +* * * Description : Fournit la marque de dernière modification des symboles. * * * * Retour : Marque de la dernière modification de la liste de symboles. * @@ -882,11 +930,6 @@ bool g_binary_format_find_symbol_by_label(GBinFormat *format, const char *label, static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t *addr, __compar_fn_t fn, size_t *index, GBinSymbol **symbol) { - bool result; /* Bilan à retourner */ - void *found; /* Résultat de recherches */ - - assert(g_atomic_int_get(&format->sym_locked) > 0); - /** * Pour ce qui est des justifications quant à la vérification suivante, * se référer aux commentaires placés dans g_binary_format_add_symbol(). @@ -894,7 +937,35 @@ static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t assert(has_phys_addr(addr)); - found = bsearch(addr, format->symbols, format->sym_count, sizeof(GBinSymbol *), fn); + return __g_binary_format_find_symbol(format, addr, fn, index, symbol); + +} + + +/****************************************************************************** +* * +* Paramètres : format = informations chargées à consulter. * +* key = clef fournie pour distinguer les éléments. * +* fn = méthode de comparaison des symboles. * +* index = indice de l'éventuel symbole trouvé ou NULL. [OUT] * +* symbol = éventuel symbole trouvé à déréfenrencer. [OUT] * +* * +* Description : Recherche un symbole particulier. * +* * +* Retour : true si l'opération a été un succès, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool __g_binary_format_find_symbol(const GBinFormat *format, const void *key, __compar_fn_t fn, size_t *index, GBinSymbol **symbol) +{ + bool result; /* Bilan à retourner */ + void *found; /* Résultat de recherches */ + + assert(g_atomic_int_get(&format->sym_locked) > 0); + + found = bsearch(key, format->symbols, format->sym_count, sizeof(GBinSymbol *), fn); if (found != NULL) { @@ -913,8 +984,11 @@ static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t else { - *symbol = NULL; + if (symbol != NULL) + *symbol = NULL; + result = false; + } return result; @@ -926,6 +1000,45 @@ static bool _g_binary_format_find_symbol(const GBinFormat *format, const vmpa2t * * * Paramètres : format = informations chargées à consulter. * * addr = adresse à cibler lors des recherches. * +* index = indice de l'éventuel symbole trouvé. [OUT] * +* * +* Description : Recherche l'indice du symbole correspondant à une adresse. * +* * +* Retour : true si l'opération a été un succès, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_binary_format_find_symbol_index_at(GBinFormat *format, const vmpa2t *addr, size_t *index) +{ + bool result; /* Bilan à retourner */ + + int find_symbol(const vmpa2t *addr, const GBinSymbol **sym) + { + const mrange_t *range; /* Espace mémoire parcouru */ + + range = g_binary_symbol_get_range(*sym); + + return cmp_vmpa(addr, get_mrange_addr(range)); + + } + + g_binary_format_lock_symbols_rd(format); + + result = _g_binary_format_find_symbol(format, addr, (__compar_fn_t)find_symbol, index, NULL); + + g_binary_format_unlock_symbols_rd(format); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : format = informations chargées à consulter. * +* addr = adresse à cibler lors des recherches. * * symbol = éventuel symbole trouvé à déréfenrencer. [OUT] * * * * Description : Recherche le symbole correspondant à une adresse. * @@ -1056,6 +1169,68 @@ bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, /****************************************************************************** * * * Paramètres : format = informations chargées à consulter. * +* range = zone à cibler lors des recherches. * +* index = indice de l'éventuel symbole trouvé. [OUT] * +* * +* Description : Recherche le premier symbole inclus dans une zone mémoire. * +* * +* Retour : true si l'opération a été un succès, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_binary_format_find_first_symbol_inside(GBinFormat *format, const mrange_t *range, size_t *index) +{ + bool result; /* Bilan à retourner */ + const GBinSymbol *prev; /* Symbole précédent */ + const mrange_t *srange; /* Espace mémoire associé */ + int ret; /* Bilan de comparaison */ + + int find_symbol(const mrange_t *ref_range, const GBinSymbol **sym) + { + const mrange_t *sym_range; /* Espace mémoire parcouru */ + + int ret; + + sym_range = g_binary_symbol_get_range(*sym); + + ret = cmp_mrange_with_vmpa(ref_range, get_mrange_addr(sym_range)); + + ret *= -1; + + return ret; + + } + + g_rw_lock_reader_lock(&format->syms_lock); + + result = __g_binary_format_find_symbol(format, range, (__compar_fn_t)find_symbol, index, NULL); + + if (result) + while (*index > 0) + { + prev = format->symbols[*index - 1]; + srange = g_binary_symbol_get_range(prev); + + ret = cmp_mrange_with_vmpa(range, get_mrange_addr(srange)); + assert(ret <= 0); + + if (ret < 0) break; + else (*index)--; + + } + + g_rw_lock_reader_unlock(&format->syms_lock); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : format = informations chargées à consulter. * * addr = adresse à cibler lors des recherches. * * strict = indication de tolérance acceptée. * * symbol = éventuel symbole trouvé à déréfenrencer. [OUT] * |