/* 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 . */ #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; }