diff options
Diffstat (limited to 'tools/d2c/format/manager.c')
-rw-r--r-- | tools/d2c/format/manager.c | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/tools/d2c/format/manager.c b/tools/d2c/format/manager.c new file mode 100644 index 0000000..070b70c --- /dev/null +++ b/tools/d2c/format/manager.c @@ -0,0 +1,145 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * manager.c - enregistrement de la définition des opérandes attendus + * + * 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 "manager.h" + + +#include <malloc.h> + + +#include "../helpers.h" + + + +/* Mémorisation de la définition d'opérandes */ +struct _operands_format +{ + char *type; /* Définitions des opérandes */ + +}; + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Crée un nouveau gestionnaire de définitions d'opérandes. * +* * +* Retour : Nouvelle structure prête à emploi. * +* * +* Remarques : - * +* * +******************************************************************************/ + +operands_format *create_operands_format(void) +{ + operands_format *result; /* Définition vierge à renvoyer*/ + + result = (operands_format *)calloc(1, sizeof(operands_format)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : format = gestionnaire de définition d'opérandes à libérer. * +* * +* Description : Supprime de la mémoire un gestionnaire de définitions. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void delete_operands_format(operands_format *format) +{ + if (format->type != NULL) + free(format->type); + + free(format); + +} + + +/****************************************************************************** +* * +* Paramètres : format = gestionnaire de définition d'opérandes à traiter. * +* type = définitions des opérandes à charger. * +* * +* Description : Précise le type d'opérandes dont la définition est à charger.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void set_operands_format_type(operands_format *format, char *type) +{ + if (format->type != NULL) + free(format->type); + + format->type = make_string_upper(type); + +} + + +/****************************************************************************** +* * +* Paramètres : spec = spécification servant de base à l'opération. * +* fd = descripteur d'un flux ouvert en écriture. * +* arch = architecture visée par l'opération. * +* prefix = préfixe pour le type de définitions d'opérandes. * +* exit = exprime le besoin d'une voie de sortie. [OUT] * +* * +* Description : Définit le chargement des opérandes prévus par la définition.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool define_operands_loading(const operands_format *format, int fd, const char *arch, const char *prefix, bool *exit) +{ + if (format->type == NULL) + { + fprintf(stderr, "Error: no type defined for operands.\n"); + return false; + } + + *exit = true; + + dprintf(fd, "\tif (!%s_read_operands(result, format, content, pos, endian, %s%s))\n", + arch, prefix, format->type); + + dprintf(fd, "\t\tgoto bad_exit;\n"); + dprintf(fd, "\n"); + + return true; + +} |