diff options
Diffstat (limited to 'src/format/format.c')
-rw-r--r-- | src/format/format.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/src/format/format.c b/src/format/format.c index 5478d3c..2256160 100644 --- a/src/format/format.c +++ b/src/format/format.c @@ -49,6 +49,9 @@ static void g_binary_format_class_init(GBinFormatClass *); /* Initialise une instance de format binaire générique. */ static void g_binary_format_init(GBinFormat *); +/* Retire un symbole de la collection du format binaire. */ +static void _g_binary_format_remove_symbol(GBinFormat *, size_t); + /* Indique le type défini pour un format binaire générique. */ @@ -222,6 +225,96 @@ void g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol) /****************************************************************************** * * +* Paramètres : format = informations chargées à compléter. * +* index = indice du symbole à retirer de la liste. * +* * +* Description : Retire un symbole de la collection du format binaire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void _g_binary_format_remove_symbol(GBinFormat *format, size_t index) +{ + GBinSymbol *symbol; /* Symbole visé par l'opération*/ + GBinRoutine *routine; /* Eventuelle routine associée */ + size_t i; /* Boucle de parcours */ + + /** + * TODO : envoyer un signal pour avertir les opérandes concernées. + */ + + symbol = format->symbols[index]; + + switch (g_binary_symbol_get_target_type(symbol)) + { + case STP_ROUTINE: + case STP_ENTRY_POINT: + + routine = g_binary_symbol_get_routine(symbol); + + for (i = 0; i < format->routines_count; i++) + if (format->routines[i] == routine) + break; + + assert(i < format->routines_count); + + if ((i + 1) < format->routines_count) + memmove(&format->routines[i], &format->routines[i + 1], + (format->routines_count - i - 1) * sizeof(GBinRoutine *)); + + format->routines = (GBinRoutine **)realloc(format->routines, + --format->routines_count * sizeof(GBinRoutine *)); + + break; + + default: + break; + + } + + assert(index < format->symbols_count); + + if ((index + 1) < format->symbols_count) + memmove(&format->symbols[index], &format->symbols[index + 1], + (format->symbols_count - index - 1) * sizeof(GBinSymbol *)); + + format->symbols = (GBinSymbol **)realloc(format->symbols, + --format->symbols_count * sizeof(GBinSymbol *)); + +} + + +/****************************************************************************** +* * +* Paramètres : format = informations chargées à compléter. * +* symbol = symbole à retirer de la liste. * +* * +* Description : Retire un symbole de la collection du format binaire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_binary_format_remove_symbol(GBinFormat *format, GBinSymbol *symbol) +{ + size_t i; /* Boucle de parcours */ + + for (i = 0; i < format->symbols_count; i++) + if (format->symbols[i] == symbol) + break; + + _g_binary_format_remove_symbol(format, i); + +} + + +/****************************************************************************** +* * * Paramètres : format = informations chargées à consulter. * * count = taille du tableau créé. [OUT] * * * @@ -480,6 +573,53 @@ void g_binary_format_add_routine(GBinFormat *format, GBinRoutine *routine) /****************************************************************************** * * +* Paramètres : format = informations chargées à compléter. * +* routine = routine à ajouter à la liste. * +* * +* Description : Retire une routine de la collection du format binaire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_binary_format_remove_routine(GBinFormat *format, GBinRoutine *routine) +{ + size_t index; /* Indice trouvé à utiliser */ + size_t i; /* Boucle de parcours */ + GBinSymbol *symbol; /* Symbole en cours d'analyse */ + + index = format->symbols_count; + + for (i = 0; i < format->symbols_count && index == format->symbols_count; i++) + { + symbol = format->symbols[i]; + + switch (g_binary_symbol_get_target_type(symbol)) + { + case STP_ROUTINE: + case STP_ENTRY_POINT: + + if (g_binary_symbol_get_routine(symbol) == routine) + index = i; + + break; + + default: + break; + + } + + } + + _g_binary_format_remove_symbol(format, index); + +} + + +/****************************************************************************** +* * * Paramètres : format = informations chargées à consulter. * * count = taille du tableau créé. [OUT] * * * |