summaryrefslogtreecommitdiff
path: root/src/arch/dalvik/operands
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
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')
-rw-r--r--src/arch/dalvik/operands/Makefile.am20
-rw-r--r--src/arch/dalvik/operands/args.c189
-rw-r--r--src/arch/dalvik/operands/args.h61
-rw-r--r--src/arch/dalvik/operands/pool.c240
-rw-r--r--src/arch/dalvik/operands/pool.h79
-rw-r--r--src/arch/dalvik/operands/register.c212
-rw-r--r--src/arch/dalvik/operands/register.h59
-rw-r--r--src/arch/dalvik/operands/target.c194
-rw-r--r--src/arch/dalvik/operands/target.h61
9 files changed, 1115 insertions, 0 deletions
diff --git a/src/arch/dalvik/operands/Makefile.am b/src/arch/dalvik/operands/Makefile.am
new file mode 100644
index 0000000..b6cba3c
--- /dev/null
+++ b/src/arch/dalvik/operands/Makefile.am
@@ -0,0 +1,20 @@
+
+noinst_LTLIBRARIES = libarchdalvikoperands.la
+
+libarchdalvikoperands_la_SOURCES = \
+ args.h args.c \
+ pool.h pool.c \
+ register.h register.c \
+ target.h target.c
+
+libarchdalvik_la_CFLAGS = $(AM_CFLAGS)
+
+
+INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CPPFLAGS =
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
+
+
+SUBDIRS =
diff --git a/src/arch/dalvik/operands/args.c b/src/arch/dalvik/operands/args.c
new file mode 100644
index 0000000..367a718
--- /dev/null
+++ b/src/arch/dalvik/operands/args.c
@@ -0,0 +1,189 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * args.c - listes d'opérandes rassemblées en arguments
+ *
+ * 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 "args.h"
+
+
+#include "../../operand-int.h"
+
+
+
+/* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */
+struct _GDalvikArgsOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ GArchOperand **args; /* Liste d'arguments */
+ size_t count; /* Taille de cette liste */
+
+};
+
+
+/* Définition d'un opérande visant une liste d'opérandes Dalvik (classe) */
+struct _GDalvikArgsOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des listes d'opérandes Dalvik. */
+static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *);
+
+/* Initialise une instance de liste d'opérandes Dalvik. */
+static void g_dalvik_args_operand_init(GDalvikArgsOperand *);
+
+/* Traduit un opérande en version humainement lisible. */
+static void g_dalvik_args_operand_print(const GDalvikArgsOperand *, GBufferLine *, AsmSyntax);
+
+
+
+/* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */
+G_DEFINE_TYPE(GDalvikArgsOperand, g_dalvik_args_operand, G_TYPE_ARCH_OPERAND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des listes d'opérandes Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_args_operand_class_init(GDalvikArgsOperandClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance de liste d'opérandes Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_args_operand_init(GDalvikArgsOperand *operand)
+{
+ GArchOperand *parent; /* Instance parente */
+
+ parent = G_ARCH_OPERAND(operand);
+
+ parent->print = (operand_print_fc)g_dalvik_args_operand_print;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée un réceptacle pour opérandes Dalvik servant d'arguments.*
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_dalvik_args_operand_new(void)
+{
+ GDalvikArgsOperand *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_DALVIK_ARGS_OPERAND, NULL);
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* 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_args_operand_print(const GDalvikArgsOperand *operand, GBufferLine *line, AsmSyntax syntax)
+{
+ size_t i; /* Boucle de parcours */
+
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, "{", 1, RTT_HOOK);
+
+ if (operand->count > 0)
+ {
+ g_arch_operand_print(operand->args[0], line, syntax);
+
+ for (i = 1; i < operand->count; i++)
+ {
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, ",", 1, RTT_PUNCT);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, " ", 1, RTT_RAW);
+
+ g_arch_operand_print(operand->args[i], line, syntax);
+
+ }
+
+ }
+
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, "}", 1, RTT_HOOK);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à compléter. *
+* arg = nouvel argument pour un appel. *
+* *
+* Description : Ajoute un élément à la liste d'arguments Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_dalvik_args_operand_add(GDalvikArgsOperand *operand, GArchOperand *arg)
+{
+ operand->args = (GArchOperand **)realloc(operand->args,
+ ++operand->count * sizeof(GArchOperand *));
+
+ operand->args[operand->count - 1] = arg;
+
+}
diff --git a/src/arch/dalvik/operands/args.h b/src/arch/dalvik/operands/args.h
new file mode 100644
index 0000000..87ec9ae
--- /dev/null
+++ b/src/arch/dalvik/operands/args.h
@@ -0,0 +1,61 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * args.h - prototypes pour les listes d'opérandes rassemblées en arguments
+ *
+ * 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/>.
+ */
+
+
+#ifndef _ARCH_DALVIK_OPERANDS_ARGS_H
+#define _ARCH_DALVIK_OPERANDS_ARGS_H
+
+
+#include <glib-object.h>
+
+
+#include "../../operand.h"
+
+
+
+#define G_TYPE_DALVIK_ARGS_OPERAND g_dalvik_args_operand_get_type()
+#define G_DALVIK_ARGS_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_args_operand_get_type(), GDalvikArgsOperand))
+#define G_IS_DALVIK_ARGS_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_args_operand_get_type()))
+#define G_DALVIK_ARGS_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_ARGS_OPERAND, GDalvikArgsOperandClass))
+#define G_IS_DALVIK_ARGS_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_ARGS_OPERAND))
+#define G_DALVIK_ARGS_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_ARGS_OPERAND, GDalvikArgsOperandClass))
+
+
+/* Définition d'un opérande visant une liste d'opérandes Dalvik (instance) */
+typedef struct _GDalvikArgsOperand GDalvikArgsOperand;
+
+/* Définition d'un opérande visant une liste d'opérandes Dalvik (classe) */
+typedef struct _GDalvikArgsOperandClass GDalvikArgsOperandClass;
+
+
+/* Indique le type défini par la GLib pour une liste d'arguments Dalvik. */
+GType g_dalvik_args_operand_get_type(void);
+
+/* Crée un réceptacle pour opérandes Dalvik servant d'arguments. */
+GArchOperand *g_dalvik_args_operand_new(void);
+
+/* Ajoute un élément à la liste d'arguments Dalvik. */
+void g_dalvik_args_operand_add(GDalvikArgsOperand *, GArchOperand *);
+
+
+
+#endif /* _ARCH_DALVIK_OPERANDS_ARGS_H */
diff --git a/src/arch/dalvik/operands/pool.c b/src/arch/dalvik/operands/pool.c
new file mode 100644
index 0000000..a7b264b
--- /dev/null
+++ b/src/arch/dalvik/operands/pool.c
@@ -0,0 +1,240 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * pool.c - opérandes pointant vers la table des constantes
+ *
+ * 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 "pool.h"
+
+
+#include "../../operand-int.h"
+
+
+
+/* Définition d'un opérande visant un élément de table de constantes Dalvik (instance) */
+struct _GDalvikPoolOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ DalvikPoolType type; /* Type de table visée */
+ uint32_t index; /* Indice de l'élément visé */
+
+};
+
+
+/* Définition d'un opérande visant un élément de table de constantes Dalvik (classe) */
+struct _GDalvikPoolOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des opérandes de constante Dalvik. */
+static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *);
+
+/* Initialise une instance d'opérande de constante Dalvik. */
+static void g_dalvik_pool_operand_init(GDalvikPoolOperand *);
+
+/* Traduit un opérande en version humainement lisible. */
+static void g_dalvik_pool_operand_print(const GDalvikPoolOperand *, GBufferLine *, AsmSyntax);
+
+
+
+/* Indique le type défini par la GLib pour un un élément de table de constantes Dalvik. */
+G_DEFINE_TYPE(GDalvikPoolOperand, g_dalvik_pool_operand, G_TYPE_ARCH_OPERAND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des opérandes de constante Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_pool_operand_class_init(GDalvikPoolOperandClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance d'opérande de constante Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_pool_operand_init(GDalvikPoolOperand *operand)
+{
+ GArchOperand *parent; /* Instance parente */
+
+ parent = G_ARCH_OPERAND(operand);
+
+ parent->print = (operand_print_fc)g_dalvik_pool_operand_print;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type de table visée avec la référence. *
+* data = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* len = taille totale des données à analyser. *
+* 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 élément constant Dalvik. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_dalvik_pool_operand_new(DalvikPoolType type, const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, SourceEndian endian)
+{
+ GDalvikPoolOperand *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_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_POOL_OPERAND, NULL);
+
+ result->type = type;
+ result->index = (size == MDS_8_BITS ? index8 : index16);
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* 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_pool_operand_print(const GDalvikPoolOperand *operand, GBufferLine *line, AsmSyntax syntax)
+{
+ char value[20]; /* Chaîne à imprimer */
+ size_t len; /* Taille de l'élément inséré */
+
+ switch (operand->type)
+ {
+ case DPT_NONE:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, "????", 4, RTT_SECTION);
+ break;
+ case DPT_STRING:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, "string", 6, RTT_SECTION);
+ break;
+ case DPT_TYPE:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, "type", 4, RTT_SECTION);
+ break;
+ case DPT_PROTO:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, "proto", 5, RTT_SECTION);
+ break;
+ case DPT_FIELD:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, "field", 5, RTT_SECTION);
+ break;
+ case DPT_METHOD:
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, "method", 6, RTT_SECTION);
+ break;
+ }
+
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, "@", 1, RTT_SIGNS);
+
+ len = snprintf(value, 20, "%d", operand->index);
+ g_buffer_line_insert_text(line, BLC_ASSEMBLY, value, len, RTT_IMMEDIATE);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* *
+* Description : Indique la nature de la table de constantes visée ici. *
+* *
+* Retour : Type de table constantes visée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+DalvikPoolType g_dalvik_pool_operand_get_pool_type(const GDalvikPoolOperand *operand)
+{
+ return operand->type;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à consulter. *
+* *
+* Description : Indique l'indice de l'élément dans la table de constantes. *
+* *
+* Retour : Indice de l'élément visé dans la table de constantes. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+uint32_t g_dalvik_pool_operand_get_index(const GDalvikPoolOperand *operand)
+{
+ return operand->index;
+
+}
diff --git a/src/arch/dalvik/operands/pool.h b/src/arch/dalvik/operands/pool.h
new file mode 100644
index 0000000..b74692d
--- /dev/null
+++ b/src/arch/dalvik/operands/pool.h
@@ -0,0 +1,79 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * pool.h - prototypes pour les opérandes pointant vers la table des constantes
+ *
+ * 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/>.
+ */
+
+
+#ifndef _ARCH_DALVIK_OPERANDS_POOL_H
+#define _ARCH_DALVIK_OPERANDS_POOL_H
+
+
+#include <glib-object.h>
+#include <stdint.h>
+
+
+#include "../../operand.h"
+#include "../../../common/endianness.h"
+
+
+
+#define G_TYPE_DALVIK_POOL_OPERAND g_dalvik_pool_operand_get_type()
+#define G_DALVIK_POOL_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_pool_operand_get_type(), GDalvikPoolOperand))
+#define G_IS_DALVIK_POOL_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_pool_operand_get_type()))
+#define G_DALVIK_POOL_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_POOL_OPERAND, GDalvikPoolOperandClass))
+#define G_IS_DALVIK_POOL_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_POOL_OPERAND))
+#define G_DALVIK_POOL_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_POOL_OPERAND, GDalvikPoolOperandClass))
+
+
+/* Définition d'un opérande visant un élément de table de constantes Dalvik (instance) */
+typedef struct _GDalvikPoolOperand GDalvikPoolOperand;
+
+/* Définition d'un opérande visant un élément de table de constantes Dalvik (classe) */
+typedef struct _GDalvikPoolOperandClass GDalvikPoolOperandClass;
+
+
+/* Type de table de constantes */
+typedef enum _DalvikPoolType
+{
+ DPT_NONE = 0x0,
+ DPT_STRING = 0x1,
+ DPT_TYPE = 0x2,
+ DPT_PROTO = 0x3,
+ DPT_FIELD = 0x4,
+ DPT_METHOD = 0x5
+
+} DalvikPoolType;
+
+
+/* Indique le type défini par la GLib pour un un élément de table de constantes Dalvik. */
+GType g_dalvik_pool_operand_get_type(void);
+
+/* Crée un opérande visant un élément constant Dalvik. */
+GArchOperand *g_dalvik_pool_operand_new(DalvikPoolType, const bin_t *, off_t *, off_t, MemoryDataSize, SourceEndian);
+
+/* Indique la nature de la table de constantes visée ici. */
+DalvikPoolType g_dalvik_pool_operand_get_pool_type(const GDalvikPoolOperand *);
+
+/* Indique l'indice de l'élément dans la table de constantes. */
+uint32_t g_dalvik_pool_operand_get_index(const GDalvikPoolOperand *);
+
+
+
+#endif /* _ARCH_DALVIK_OPERANDS_POOL_H */
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);
+
+}
diff --git a/src/arch/dalvik/operands/register.h b/src/arch/dalvik/operands/register.h
new file mode 100644
index 0000000..00b05fb
--- /dev/null
+++ b/src/arch/dalvik/operands/register.h
@@ -0,0 +1,59 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * register.h - prototypes pour les 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/>.
+ */
+
+
+#ifndef _ARCH_DALVIK_OPERANDS_REGISTER_H
+#define _ARCH_DALVIK_OPERANDS_REGISTER_H
+
+
+#include <glib-object.h>
+
+
+#include "../../operand.h"
+#include "../../../common/endianness.h"
+
+
+
+#define G_TYPE_DALVIK_REGISTER_OPERAND g_dalvik_register_operand_get_type()
+#define G_DALVIK_REGISTER_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_register_operand_get_type(), GDalvikRegisterOperand))
+#define G_IS_DALVIK_REGISTER_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_register_operand_get_type()))
+#define G_DALVIK_REGISTER_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_REGISTER_OPERAND, GDalvikRegisterOperandClass))
+#define G_IS_DALVIK_REGISTER_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_REGISTER_OPERAND))
+#define G_DALVIK_REGISTER_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_REGISTER_OPERAND, GDalvikRegisterOperandClass))
+
+
+/* Définition d'un opérande visant un registre Dalvik (instance) */
+typedef struct _GDalvikRegisterOperand GDalvikRegisterOperand;
+
+/* Définition d'un opérande visant un registre Dalvik (classe) */
+typedef struct _GDalvikRegisterOperandClass GDalvikRegisterOperandClass;
+
+
+/* Indique le type défini par la GLib pour un opérande de registre Dalvik. */
+GType g_dalvik_register_operand_get_type(void);
+
+/* Crée un opérande visant un registre Dalvik. */
+GArchOperand *g_dalvik_register_operand_new(const bin_t *, off_t *, off_t, bool *, MemoryDataSize, SourceEndian);
+
+
+
+#endif /* _ARCH_DALVIK_OPERANDS_REGISTER_H */
diff --git a/src/arch/dalvik/operands/target.c b/src/arch/dalvik/operands/target.c
new file mode 100644
index 0000000..9b82ba2
--- /dev/null
+++ b/src/arch/dalvik/operands/target.c
@@ -0,0 +1,194 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * target.c - opérandes visant une adresse de code
+ *
+ * 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 "target.h"
+
+
+#include "../../operand-int.h"
+
+
+
+/* Définition d'un opérande visant une adresse de code Dalvik (instance) */
+struct _GDalvikTargetOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ GImmOperand *immediate; /* Adresse visée reconstituée */
+
+};
+
+
+/* Définition d'un opérande visant une adresse de code Dalvik (classe) */
+struct _GDalvikTargetOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des opérandes de ciblage de code Dalvik. */
+static void g_dalvik_target_operand_class_init(GDalvikTargetOperandClass *);
+
+/* Initialise une instance d'opérande de ciblage de code Dalvik. */
+static void g_dalvik_target_operand_init(GDalvikTargetOperand *);
+
+/* Traduit un opérande en version humainement lisible. */
+static void g_dalvik_target_operand_print(const GDalvikTargetOperand *, GBufferLine *, AsmSyntax);
+
+
+
+/* Indique le type défini par la GLib pour un opérande de ciblage de code Dalvik. */
+G_DEFINE_TYPE(GDalvikTargetOperand, g_dalvik_target_operand, G_TYPE_ARCH_OPERAND);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des opérandes de ciblage de code Dalvik.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_target_operand_class_init(GDalvikTargetOperandClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance d'opérande de ciblage de code Dalvik.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_dalvik_target_operand_init(GDalvikTargetOperand *operand)
+{
+ GArchOperand *parent; /* Instance parente */
+
+ parent = G_ARCH_OPERAND(operand);
+
+ parent->print = (operand_print_fc)g_dalvik_target_operand_print;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : data = flux de données à analyser. *
+* pos = position courante dans ce flux. [OUT] *
+* len = taille totale des données à analyser. *
+* size = taille de l'opérande. *
+* endian = ordre des bits dans la source. *
+* base = adresse de référence pour le calcul. *
+* *
+* Description : Crée un opérande visant un instruction Dalvik. *
+* *
+* Retour : Opérande mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchOperand *g_dalvik_target_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, SourceEndian endian, vmpa_t base)
+{
+ GDalvikTargetOperand *result; /* Structure à retourner */
+ int8_t val8; /* Valeur sur 8 bits */
+ int16_t val16; /* Valeur sur 16 bits */
+ int32_t val32; /* Valeur sur 32 bits */
+ vmpa_t address; /* Adresse finale visée */
+
+ switch (size)
+ {
+ case MDS_8_BITS_SIGNED:
+ read_s8(&val8, data, pos, len, endian);
+ address = base + val8 * sizeof(uint16_t);
+ break;
+ case MDS_16_BITS_SIGNED:
+ read_s16(&val16, data, pos, len, endian);
+ address = base + val16 * sizeof(uint16_t);
+ break;
+ case MDS_32_BITS_SIGNED:
+ read_s32(&val32, data, pos, len, endian);
+ address = base + val32 * sizeof(uint16_t);
+ break;
+ default:
+ return NULL;
+ break;
+ }
+
+ result = g_object_new(G_TYPE_DALVIK_TARGET_OPERAND, NULL);
+ result->immediate = G_IMM_OPERAND(g_imm_operand_new_from_value(MDS_32_BITS/*FIXME*/, (uint32_t)address/* FIXME */));
+
+ return G_ARCH_OPERAND(result);
+
+}
+
+
+/******************************************************************************
+* *
+* 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_target_operand_print(const GDalvikTargetOperand *operand, GBufferLine *line, AsmSyntax syntax)
+{
+ g_arch_operand_print(G_ARCH_OPERAND(operand->immediate), line, syntax);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande à traiter. *
+* *
+* Description : Fournit l'adresse représentée par une opérande Dalvik. *
+* *
+* Retour : Valeur portée par l'opérande. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const GImmOperand *g_dalvik_target_operand_get_value(const GDalvikTargetOperand *operand)
+{
+ return operand->immediate;
+
+}
diff --git a/src/arch/dalvik/operands/target.h b/src/arch/dalvik/operands/target.h
new file mode 100644
index 0000000..9b1641c
--- /dev/null
+++ b/src/arch/dalvik/operands/target.h
@@ -0,0 +1,61 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * target.h - prototypes pour les opérandes visant une adresse de code
+ *
+ * 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/>.
+ */
+
+
+#ifndef _ARCH_DALVIK_OPERANDS_TARGET_H
+#define _ARCH_DALVIK_OPERANDS_TARGET_H
+
+
+#include <glib-object.h>
+
+
+#include "../../immediate.h"
+
+
+
+#define G_TYPE_DALVIK_TARGET_OPERAND g_dalvik_target_operand_get_type()
+#define G_DALVIK_TARGET_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_target_operand_get_type(), GDalvikTargetOperand))
+#define G_IS_DALVIK_TARGET_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_target_operand_get_type()))
+#define G_DALVIK_TARGET_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_TARGET_OPERAND, GDalvikTargetOperandClass))
+#define G_IS_DALVIK_TARGET_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_TARGET_OPERAND))
+#define G_DALVIK_TARGET_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_TARGET_OPERAND, GDalvikTargetOperandClass))
+
+
+/* Définition d'un opérande visant une adresse de code Dalvik (instance) */
+typedef struct _GDalvikTargetOperand GDalvikTargetOperand;
+
+/* Définition d'un opérande visant une adresse de code Dalvik (classe) */
+typedef struct _GDalvikTargetOperandClass GDalvikTargetOperandClass;
+
+
+/* Indique le type défini par la GLib pour un opérande de ciblage de code Dalvik. */
+GType g_dalvik_target_operand_get_type(void);
+
+/* Crée un opérande visant un instruction Dalvik. */
+GArchOperand *g_dalvik_target_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize, SourceEndian, vmpa_t);
+
+/* Fournit l'adresse représentée par une opérande Dalvik. */
+const GImmOperand *g_dalvik_target_operand_get_value(const GDalvikTargetOperand *);
+
+
+
+#endif /* _ARCH_DALVIK_OPERANDS_TARGET_H */