diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2013-06-30 13:01:38 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2013-06-30 13:01:38 (GMT) |
commit | e5314b83cf2521f4a1fee5d3cbb5011d7ac7bff7 (patch) | |
tree | 3af6d5b430d3a07753e273e9ddb1ff656e706661 /src/arch/arm/v456/operands/content.c | |
parent | 0f3bbcb376ee4f76142ac4ddf729403fecac2641 (diff) |
Provided first basic support for a few ARM instructions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@354 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/arm/v456/operands/content.c')
-rw-r--r-- | src/arch/arm/v456/operands/content.c | 257 |
1 files changed, 257 insertions, 0 deletions
diff --git a/src/arch/arm/v456/operands/content.c b/src/arch/arm/v456/operands/content.c new file mode 100644 index 0000000..1ffceae --- /dev/null +++ b/src/arch/arm/v456/operands/content.c @@ -0,0 +1,257 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * content.c - opérandes visant un registre ARM v4/5/6 + * + * Copyright (C) 2013 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * 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 "content.h" + + +#include "../../../operand-int.h" + + + +/* Définition d'un opérande visant un registre ARM v4/5/6 (instance) */ +struct _GArmV456ContentOperand +{ + GArchOperand parent; /* Instance parente */ + + GArmV456Register *reg; /* Registre représenté */ + GImmOperand *offset; /* Décallage à appliquer */ + + bool add; /* Mise à jour du registre ? */ + + bool is_written; /* Changement de contenu */ + +}; + + +/* Définition d'un opérande visant un registre ARM v4/5/6 (classe) */ +struct _GArmV456ContentOperandClass +{ + GArchOperandClass parent; /* Classe parente */ + +}; + + +/* Initialise la classe des opérandes de registre ARM v4/5/6. */ +static void g_armv456_content_operand_class_init(GArmV456ContentOperandClass *); + +/* Initialise une instance d'opérande de registre ARM v4/5/6. */ +static void g_armv456_content_operand_init(GArmV456ContentOperand *); + +/* Compare un opérande avec un autre. */ +static bool g_armv456_content_operand_compare(const GArmV456ContentOperand *, const GArmV456ContentOperand *); + +/* Traduit un opérande en version humainement lisible. */ +static void g_armv456_content_operand_print(const GArmV456ContentOperand *, GBufferLine *, AsmSyntax); + + + +/* Indique le type défini par la GLib pour un opérande de registre ARM v4/5/6. */ +G_DEFINE_TYPE(GArmV456ContentOperand, g_armv456_content_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des opérandes de registre ARM v4/5/6. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv456_content_operand_class_init(GArmV456ContentOperandClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : operand = instance à initialiser. * +* * +* Description : Initialise une instance d'opérande de registre ARM v4/5/6. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv456_content_operand_init(GArmV456ContentOperand *operand) +{ + GArchOperand *parent; /* Instance parente */ + + parent = G_ARCH_OPERAND(operand); + + parent->compare = (operand_compare_fc)g_armv456_content_operand_compare; + parent->print = (operand_print_fc)g_armv456_content_operand_print; + + operand->is_written = false; + +} + + +/****************************************************************************** +* * +* Paramètres : reg = registre déjà en place. * +* offset = décallage à appliquer. * +* add = sens du décallage. * +* * +* Description : Crée un opérande visant un registre ARM v4/5/6. * +* * +* Retour : Opérande mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *g_armv456_content_operand_new(GArmV456Register *reg, GImmOperand *offset, bool add) +{ + GArmV456ContentOperand *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_ARMV456_CONTENT_OPERAND, NULL); + + result->reg = reg; + result->offset = offset; + + result->add = add; + + return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande représentant un registre. * +* * +* Description : Fournit le registre ARM v4/5/6 associé à l'opérande. * +* * +* Retour : Représentation interne du registre. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArmV456Register *g_armv456_content_operand_get(const GArmV456ContentOperand *operand) +{ + return operand->reg; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier opérande à consulter. * +* b = second opérande à consulter. * +* * +* Description : Compare un opérande avec un autre. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_armv456_content_operand_compare(const GArmV456ContentOperand *a, const GArmV456ContentOperand *b) +{ + return false;//(g_armv456_content_compare(a->reg, b->reg) == 0); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à traiter. * +* line = ligne tampon où imprimer l'opérande donné. * +* syntax = type de représentation demandée. * +* * +* Description : Traduit un opérande en version humainement lisible. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_armv456_content_operand_print(const GArmV456ContentOperand *operand, GBufferLine *line, AsmSyntax syntax) +{ + g_buffer_line_insert_text(line, BLC_ASSEMBLY, "[", 1, RTT_HOOK); + + g_armv456_register_print(operand->reg, line, syntax); + + if (!g_imm_operand_is_null(operand->offset)) + { + g_buffer_line_insert_text(line, BLC_ASSEMBLY, ",", 1, RTT_PUNCT); + g_buffer_line_insert_text(line, BLC_ASSEMBLY, " ", 1, RTT_RAW); + + if (!operand->add) + g_buffer_line_insert_text(line, BLC_ASSEMBLY, "-", 1, RTT_SIGNS); + + g_arch_operand_print(G_ARCH_OPERAND(operand->offset), line, syntax); + + } + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, "]", 1, RTT_HOOK); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande représentant un registre à mettre à jour. * +* * +* Description : Marque l'opérande comme étant écrit plutôt que consulté. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_armv456_content_operand_mark_as_written(GArmV456ContentOperand *operand) +{ + operand->is_written = true; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande représentant un registre à consulter. * +* * +* Description : Indique le type d'accès réalisé sur l'opérande. * +* * +* Retour : Type d'accès : true en cas d'écriture, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_armv456_content_operand_is_written(const GArmV456ContentOperand *operand) +{ + return operand->is_written; + +} |