summaryrefslogtreecommitdiff
path: root/src/arch/dalvik/operands/register.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-12-21 00:51:14 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-12-21 00:51:14 (GMT)
commitdbec8e8af5f296f0b95cd9c07e7d96b1a4277137 (patch)
tree4c5a9307bc4f0c168911e86459de5a51baaac226 /src/arch/dalvik/operands/register.c
parent56deaf395c65658102ef0111cfc072d65335331a (diff)
Redefined all existing kinds of Dalvik operands in a proper way.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@203 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/dalvik/operands/register.c')
-rw-r--r--src/arch/dalvik/operands/register.c212
1 files changed, 212 insertions, 0 deletions
diff --git a/src/arch/dalvik/operands/register.c b/src/arch/dalvik/operands/register.c
new file mode 100644
index 0000000..22c210e
--- /dev/null
+++ b/src/arch/dalvik/operands/register.c
@@ -0,0 +1,212 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * register.c - opérandes visant un registre Dalvik
+ *
+ * Copyright (C) 2010 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 "register.h"
+
+
+#include "../register.h"
+#include "../../operand-int.h"
+
+
+
+/* Définition d'un opérande visant un registre Dalvik (instance) */
+struct _GDalvikRegisterOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ GDalvikRegister *reg; /* Registre représenté */
+
+};
+
+
+/* Définition d'un opérande visant un registre Dalvik (classe) */
+struct _GDalvikRegisterOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des opérandes de registre Dalvik. */
+static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *);
+
+/* Initialise une instance d'opérande de registre Dalvik. */
+static void g_dalvik_register_operand_init(GDalvikRegisterOperand *);
+
+/* Compare un opérande avec un autre. */
+static bool g_dalvik_register_operand_compare(const GDalvikRegisterOperand *, const GDalvikRegisterOperand *);
+
+/* Traduit un opérande en version humainement lisible. */
+static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *, GBufferLine *, AsmSyntax);
+
+
+
+
+/* Indique le type défini par la GLib pour un opérande de registre Dalvik. */
+G_DEFINE_TYPE(GDalvikRegisterOperand, g_dalvik_register_operand, G_TYPE_ARCH_OPERAND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des opérandes de registre Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_register_operand_class_init(GDalvikRegisterOperandClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance d'opérande de registre Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_register_operand_init(GDalvikRegisterOperand *operand)
+{
+ GArchOperand *parent; /* Instance parente */
+
+ parent = G_ARCH_OPERAND(operand);
+
+ parent->compare = (operand_compare_fc)g_dalvik_register_operand_compare;
+ parent->print = (operand_print_fc)g_dalvik_register_operand_print;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : data = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* len = taille totale des données à analyser. *
+* low = position éventuelle des 4 bits visés. [OUT] *
+* size = taille de l'opérande, et donc du registre. *
+* endian = ordre des bits dans la source. *
+* *
+* Description : Crée un opérande visant un registre Dalvik. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_dalvik_register_operand_new(const bin_t *data, off_t *pos, off_t len, bool *low, MemoryDataSize size, SourceEndian endian)
+{
+ GDalvikRegisterOperand *result; /* Structure à retourner */
+ uint8_t index8; /* Indice sur 8 bits */
+ uint16_t index16; /* Indice sur 16 bits */
+ bool test; /* Bilan de lecture */
+
+ switch (size)
+ {
+ case MDS_4_BITS:
+ test = read_u4(&index8, data, pos, len, low, endian);
+ break;
+ case MDS_8_BITS:
+ test = read_u8(&index8, data, pos, len, endian);
+ break;
+ case MDS_16_BITS:
+ test = read_u16(&index16, data, pos, len, endian);
+ break;
+ default:
+ test = false;
+ break;
+ }
+
+ if (!test)
+ return NULL;
+
+ result = g_object_new(G_TYPE_DALVIK_REGISTER_OPERAND, NULL);
+
+ switch (size)
+ {
+ case MDS_4_BITS:
+ case MDS_8_BITS:
+ result->reg = g_dalvik_register_new(index8);
+ break;
+ case MDS_16_BITS:
+ result->reg = g_dalvik_register_new(index16);
+ break;
+ default:
+ break;
+ }
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* 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_dalvik_register_operand_compare(const GDalvikRegisterOperand *a, const GDalvikRegisterOperand *b)
+{
+ return g_dalvik_register_compare(a->reg, b->reg);
+
+}
+
+
+/******************************************************************************
+* *
+* 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_dalvik_register_operand_print(const GDalvikRegisterOperand *operand, GBufferLine *line, AsmSyntax syntax)
+{
+ g_dalvik_pool_operand_print(operand->reg, line, syntax);
+
+}