diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2014-11-15 00:34:32 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2014-11-15 00:34:32 (GMT) |
commit | f7add23a8bcb6d4e0c594ce13fe224829759041c (patch) | |
tree | 4b903cfa3f64bac5c21a270f9fbe2db7d7a6adbf /tools/d2c/macros.c | |
parent | 44e6aa9039585ad95fb9c6f21535d89457563297 (diff) |
Given the d2c compiler its own directory.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@420 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'tools/d2c/macros.c')
-rw-r--r-- | tools/d2c/macros.c | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/tools/d2c/macros.c b/tools/d2c/macros.c new file mode 100644 index 0000000..b1c44f0 --- /dev/null +++ b/tools/d2c/macros.c @@ -0,0 +1,167 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * pproc.c - remplacements à la volée de chaînes de caractères + * + * Copyright (C) 2014 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * OpenIDA 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. + * + * OpenIDA 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 Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "pproc.h" + + +#include <malloc.h> + + + + + + +/* Conversion des chaînes en chaînes */ +typedef struct _string_exch +{ + const char *src; /* Chaîne à trouver */ + const char *dest; /* Chaîne de remplacement */ + +} string_exch; + + +/* Pré-processeur avec support des macros */ +struct _pre_processor +{ + string_exch *macros; /* Remplacements de chaînes */ + size_t macros_count; /* Nombre de ces remplacements */ + + + +} + + + + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Crée un nouveau suivi de l'encodage d'une instruction. * +* * +* Retour : Nouvelle structure prête à emploi. * +* * +* Remarques : - * +* * +******************************************************************************/ + +encoding_spec *create_encoding_spec(void) +{ + encoding_spec *result; /* Définition vierge à renvoyer*/ + + result = (encoding_spec *)calloc(1, sizeof(encoding_spec)); + + result->bits = create_coding_bits(); + result->syntax = create_asm_syntax(); + result->conversions = create_conv_list(); + result->rules = create_decoding_rules(); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : spec = spécification d'encodage à libérer de la mémoire. * +* * +* Description : Supprime de la mémoire un suivi d'encodage d'une instruction.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void delete_encoding_spec(encoding_spec *spec) +{ + delete_coding_bits(spec->bits); + delete_asm_syntax(spec->syntax); + delete_conv_list(spec->conversions); + delete_decoding_rules(spec->rules); + + free(spec); + +} + + + +/****************************************************************************** +* * +* Paramètres : coder = gestion par la machine en remplacement de l'humain. * +* src = chaîne à remplacer dans les définitions. * +* dest = chaîne de remplacement. * +* * +* Description : Constitue la matière d'un système de macros. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void define_macro_for_coder(rented_coder *coder, const char *src, const char *dest) +{ + string_exch *macro; /* Nouvelle macro à constituer */ + + coder->macros = (string_exch *)realloc(coder->macros, ++coder->macros_count * sizeof(string_exch)); + + macro = &coder->macros[coder->macros_count - 1]; + + macro->src = src; + macro->dest = dest; + +} + + +/****************************************************************************** +* * +* Paramètres : coder = gestion par la machine en remplacement de l'humain. * +* src = chaîne à remplacer dans les définitions. * +* * +* Description : Recherche l'existence d'une macro pour un remplacement. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static const char *find_macro_in_coder(const rented_coder *coder, const char *src) +{ + const char *result; /* Trouvaille à renvoyer */ + size_t i; /* Boucle de parcours */ + + result = NULL; + + for (i = 0; i < coder->macros_count && result == NULL; i++) + if (strcmp(coder->macros[i].src, src) == 0) + result = coder->macros[i].dest; + + return result; + +} + + |