summaryrefslogtreecommitdiff
path: root/plugins/arm/v7/instruction.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/arm/v7/instruction.c')
-rw-r--r--plugins/arm/v7/instruction.c284
1 files changed, 284 insertions, 0 deletions
diff --git a/plugins/arm/v7/instruction.c b/plugins/arm/v7/instruction.c
new file mode 100644
index 0000000..d9e4275
--- /dev/null
+++ b/plugins/arm/v7/instruction.c
@@ -0,0 +1,284 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * instruction.c - gestion des instructions ARMv7
+ *
+ * Copyright (C) 2014-2017 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide 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.
+ *
+ * Chrysalide 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 "instruction.h"
+
+
+#include <assert.h>
+#ifndef NDEBUG
+# include <string.h>
+#endif
+
+
+#include "../instruction-int.h"
+
+
+
+/* Définition d'une instruction d'architecture ARMv7 (instance) */
+struct _GArmV7Instruction
+{
+ GArmInstruction parent; /* Instance parente */
+
+ char encoding; /* Encodage de l'instruction */
+
+ bool setflags; /* Mise à jour des drapeaux */
+
+};
+
+
+/* Définition d'une instruction d'architecture ARMv7 (classe) */
+struct _GArmV7InstructionClass
+{
+ GArmInstructionClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des instructions ARMv7. */
+static void g_armv7_instruction_class_init(GArmV7InstructionClass *);
+
+/* Initialise une instance d'instruction ARMv7. */
+static void g_armv7_instruction_init(GArmV7Instruction *);
+
+/* Supprime toutes les références externes. */
+static void g_armv7_instruction_dispose(GArmV7Instruction *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_armv7_instruction_finalize(GArmV7Instruction *);
+
+/* Indique l'encodage d'une instruction de façon détaillée. */
+static const char *g_armv7_instruction_get_encoding(const GArmV7Instruction *);
+
+
+/* Indique le type défini pour une représentation d'une instruction ARMv7. */
+G_DEFINE_TYPE(GArmV7Instruction, g_armv7_instruction, G_TYPE_ARM_INSTRUCTION);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des instructions ARMv7. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_armv7_instruction_class_init(GArmV7InstructionClass *klass)
+{
+ GObjectClass *object_class; /* Autre version de la classe */
+ GArchInstructionClass *instr; /* Encore une autre vision... */
+
+ object_class = G_OBJECT_CLASS(klass);
+ instr = G_ARCH_INSTRUCTION_CLASS(klass);
+
+ object_class->dispose = (GObjectFinalizeFunc/* ! */)g_armv7_instruction_dispose;
+ object_class->finalize = (GObjectFinalizeFunc)g_armv7_instruction_finalize;
+
+ instr->get_encoding = (get_instruction_encoding_fc)g_armv7_instruction_get_encoding;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instance à initialiser. *
+* *
+* Description : Initialise une instance d'instruction ARMv7. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_armv7_instruction_init(GArmV7Instruction *instr)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_armv7_instruction_dispose(GArmV7Instruction *instr)
+{
+ G_OBJECT_CLASS(g_armv7_instruction_parent_class)->dispose(G_OBJECT(instr));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_armv7_instruction_finalize(GArmV7Instruction *instr)
+{
+ G_OBJECT_CLASS(g_armv7_instruction_parent_class)->finalize(G_OBJECT(instr));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : keyword = définition du nom humaine de l'instruction. *
+* *
+* Description : Crée une instruction pour l'architecture ARMv7. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchInstruction *g_armv7_instruction_new(const char *keyword)
+{
+ GArchInstruction *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_ARMV7_INSTRUCTION, NULL);
+
+ G_ARM_INSTRUCTION(result)->keyword = keyword;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction quelconque à consulter. *
+* *
+* Description : Indique l'encodage d'une instruction de façon détaillée. *
+* *
+* Retour : Description humaine de l'encodage utilisé. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_armv7_instruction_get_encoding(const GArmV7Instruction *instr)
+{
+ const char *result; /* Description à retourner */
+
+ switch (instr->encoding)
+ {
+ case 't':
+ result = "Thumb/16";
+ break;
+
+ case 'T':
+ result = "Thumb/32";
+ break;
+
+ default:
+ result = "ARM";
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction quelconque à modifier. *
+* encoding = encodage de l'instruction. *
+* *
+* Description : Précise l'encodage d'une instruction ARMv7 dans le détail. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_armv7_instruction_set_encoding(GArmV7Instruction *instr, const char *encoding)
+{
+ assert(strlen(encoding) == 1);
+ assert(encoding[0] == 'A' || encoding[0] == 'T' || encoding[0] == 't');
+
+ instr->encoding = encoding[0];
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction ARMv7 à mettre à jour. *
+* set = statut à enregistrer. *
+* *
+* Description : Définit si une instruction ARMv7 met à jour les drapeaux. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_armv7_instruction_define_setflags(GArmV7Instruction *instr, bool set)
+{
+ instr->setflags = set;
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction ARMv7 à consulter. *
+* *
+* Description : Indique si une instruction ARMv7 met à jour les drapeaux. *
+* *
+* Retour : Statut des incidences de l'instruction. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_armv7_instruction_get_setflags(const GArmV7Instruction *instr)
+{
+ return instr->setflags;
+
+}