summaryrefslogtreecommitdiff
path: root/src/arch/operands
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/operands')
-rw-r--r--src/arch/operands/Makefile.am23
-rw-r--r--src/arch/operands/register-int.h54
-rw-r--r--src/arch/operands/register.c382
-rw-r--r--src/arch/operands/register.h69
4 files changed, 528 insertions, 0 deletions
diff --git a/src/arch/operands/Makefile.am b/src/arch/operands/Makefile.am
new file mode 100644
index 0000000..fb43a22
--- /dev/null
+++ b/src/arch/operands/Makefile.am
@@ -0,0 +1,23 @@
+
+noinst_LTLIBRARIES = libarchoperands.la
+
+libarchoperands_la_SOURCES = \
+ register-int.h \
+ register.h register.c
+
+libarchoperands_la_LIBADD =
+
+libarchoperands_la_LDFLAGS =
+
+
+devdir = $(includedir)/chrysalide/$(subdir:src/%=%)
+
+dev_HEADERS = $(libarchoperands_la_SOURCES:%c=)
+
+
+AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
+
+AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS)
+
+
+SUBDIRS =
diff --git a/src/arch/operands/register-int.h b/src/arch/operands/register-int.h
new file mode 100644
index 0000000..348e2a3
--- /dev/null
+++ b/src/arch/operands/register-int.h
@@ -0,0 +1,54 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * register-int.h - définitions internes pour la représentation générique d'un registre
+ *
+ * Copyright (C) 2012-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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ARCH_OPERANDS_REGISTER_INT_H
+#define _ARCH_OPERANDS_REGISTER_INT_H
+
+
+#include "register.h"
+
+
+#include "../operand-int.h"
+
+
+
+/* Définition d'un opérande visant un registre (instance) */
+struct _GRegisterOperand
+{
+ GArchOperand parent; /* Instance parente */
+
+ GArchRegister *reg; /* Registre représenté */
+ bool is_written; /* Changement de contenu */
+
+};
+
+/* Définition d'un opérande visant un registre (classe) */
+struct _GRegisterOperandClass
+{
+ GArchOperandClass parent; /* Classe parente */
+
+};
+
+
+
+#endif /* _ARCH_OPERANDS_REGISTER_INT_H */
diff --git a/src/arch/operands/register.c b/src/arch/operands/register.c
new file mode 100644
index 0000000..e890fd6
--- /dev/null
+++ b/src/arch/operands/register.c
@@ -0,0 +1,382 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * registers.c - aides auxiliaires relatives aux registres Dalvik
+ *
+ * Copyright (C) 2012-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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "register.h"
+
+
+#include "register-int.h"
+#include "../storage.h"
+
+
+
+/* ------------------------- REGISTRE SOUS FORME D'OPERANDE ------------------------- */
+
+
+/* Initialise la classe des opérandes de registre. */
+static void g_register_operand_class_init(GRegisterOperandClass *);
+
+/* Initialise une instance d'opérande de registre. */
+static void g_register_operand_init(GRegisterOperand *);
+
+/* Supprime toutes les références externes. */
+static void g_register_operand_dispose(GRegisterOperand *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_register_operand_finalize(GRegisterOperand *);
+
+/* Compare un opérande avec un autre. */
+static int g_register_operand_compare(const GRegisterOperand *, const GRegisterOperand *);
+
+/* Traduit un opérande en version humainement lisible. */
+static void g_register_operand_print(const GRegisterOperand *, GBufferLine *, AsmSyntax);
+
+
+
+/* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */
+
+
+/* Charge un opérande depuis une mémoire tampon. */
+static bool g_register_operand_unserialize(GRegisterOperand *, GAsmStorage *, GBinFormat *, packed_buffer *);
+
+/* Sauvegarde un opérande dans une mémoire tampon. */
+static bool g_register_operand_serialize(const GRegisterOperand *, GAsmStorage *, packed_buffer *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* REGISTRE SOUS FORME D'OPERANDE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini par la GLib pour un opérande de registre Dalvik. */
+G_DEFINE_TYPE(GRegisterOperand, g_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_register_operand_class_init(GRegisterOperandClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GArchOperandClass *operand; /* Version de classe parente */
+
+ object = G_OBJECT_CLASS(klass);
+ operand = G_ARCH_OPERAND_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_register_operand_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_register_operand_finalize;
+
+ operand = G_ARCH_OPERAND_CLASS(klass);
+
+ operand->compare = (operand_compare_fc)g_register_operand_compare;
+ operand->print = (operand_print_fc)g_register_operand_print;
+
+ operand->unserialize = (unserialize_operand_fc)g_register_operand_unserialize;
+ operand->serialize = (serialize_operand_fc)g_register_operand_serialize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = instance à initialiser. *
+* *
+* Description : Initialise une instance d'opérande de registre Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_register_operand_init(GRegisterOperand *operand)
+{
+ operand->reg = NULL;
+ operand->is_written = false;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_register_operand_dispose(GRegisterOperand *operand)
+{
+ if (operand->reg != NULL)
+ g_object_unref(G_OBJECT(operand->reg));
+
+ G_OBJECT_CLASS(g_register_operand_parent_class)->dispose(G_OBJECT(operand));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_register_operand_finalize(GRegisterOperand *operand)
+{
+ G_OBJECT_CLASS(g_register_operand_parent_class)->finalize(G_OBJECT(operand));
+
+}
+
+
+/******************************************************************************
+* *
+* 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 int g_register_operand_compare(const GRegisterOperand *a, const GRegisterOperand *b)
+{
+ int result; /* Bilan à retourner */
+
+ result = g_arch_register_compare(a->reg, b->reg);
+
+ return 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_register_operand_print(const GRegisterOperand *operand, GBufferLine *line, AsmSyntax syntax)
+{
+ g_arch_register_print(operand->reg, line, syntax);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande représentant un registre. *
+* *
+* Description : Fournit le registre Dalvik associé à l'opérande. *
+* *
+* Retour : Représentation interne du registre. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchRegister *g_register_operand_get_register(const GRegisterOperand *operand)
+{
+ GArchRegister *result; /* Instance à retourner */
+
+ result = operand->reg;
+
+ if (result != NULL)
+ g_object_ref(G_OBJECT(result));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* 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_register_operand_mark_as_written(GRegisterOperand *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_register_operand_is_written(const GRegisterOperand *operand)
+{
+ return operand->is_written;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* TRANSPOSITIONS VIA CACHE DES OPERANDES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande d'assemblage à constituer. *
+* storage = mécanisme de sauvegarde à manipuler. *
+* format = format binaire chargé associé à l'architecture. *
+* pbuf = zone tampon à remplir. *
+* *
+* Description : Charge un opérande depuis une mémoire tampon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_register_operand_unserialize(GRegisterOperand *operand, GAsmStorage *storage, GBinFormat *format, packed_buffer *pbuf)
+{
+ bool result; /* Bilan à retourner */
+ GArchOperandClass *parent; /* Classe parente à consulter */
+ off64_t pos; /* Position dans le flux */
+ packed_buffer reg_pbuf; /* Tampon des données à écrire */
+ GArchRegister *reg; /* Registre restauré */
+
+ parent = G_ARCH_OPERAND_CLASS(g_register_operand_parent_class);
+
+ result = parent->unserialize(G_ARCH_OPERAND(operand), storage, format, pbuf);
+
+ if (result)
+ result = extract_packed_buffer(pbuf, &pos, sizeof(off64_t), true);
+
+ if (result)
+ {
+ init_packed_buffer(&reg_pbuf);
+
+ result = g_asm_storage_load_register_data(storage, &reg_pbuf, pos);
+
+ if (result)
+ {
+ reg = g_arch_register_load(storage, &reg_pbuf);
+ result = (reg != NULL);
+ }
+
+ if (result)
+ operand->reg = reg;
+
+ exit_packed_buffer(&reg_pbuf);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = opérande d'assemblage à consulter. *
+* storage = mécanisme de sauvegarde à manipuler. *
+* pbuf = zone tampon à remplir. *
+* *
+* Description : Sauvegarde un opérande dans une mémoire tampon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_register_operand_serialize(const GRegisterOperand *operand, GAsmStorage *storage, packed_buffer *pbuf)
+{
+ bool result; /* Bilan à retourner */
+ GArchOperandClass *parent; /* Classe parente à consulter */
+ off64_t pos; /* Position dans le flux */
+ packed_buffer reg_pbuf; /* Tampon des données à écrire */
+
+ parent = G_ARCH_OPERAND_CLASS(g_register_operand_parent_class);
+
+ result = parent->serialize(G_ARCH_OPERAND(operand), storage, pbuf);
+
+ if (result)
+ {
+ init_packed_buffer(&reg_pbuf);
+
+ result = g_arch_register_store(operand->reg, storage, &reg_pbuf);
+
+ if (result)
+ result = g_asm_storage_store_register_data(storage, &reg_pbuf, &pos);
+
+ if (result)
+ result = extend_packed_buffer(pbuf, &pos, sizeof(off64_t), true);
+
+ exit_packed_buffer(&reg_pbuf);
+
+ }
+
+ return result;
+
+}
diff --git a/src/arch/operands/register.h b/src/arch/operands/register.h
new file mode 100644
index 0000000..e4693b1
--- /dev/null
+++ b/src/arch/operands/register.h
@@ -0,0 +1,69 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * register.h - prototypes pour les aides auxiliaires relatives aux registres Dalvik
+ *
+ * Copyright (C) 2012-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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ARCH_OPERANDS_REGISTER_H
+#define _ARCH_OPERANDS_REGISTER_H
+
+
+#include <glib-object.h>
+#include <stdbool.h>
+
+
+#include "../operand.h"
+#include "../register.h"
+
+
+
+/* ------------------------- REGISTRE SOUS FORME D'OPERANDE ------------------------- */
+
+
+#define G_TYPE_REGISTER_OPERAND g_register_operand_get_type()
+#define G_REGISTER_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_REGISTER_OPERAND, GRegisterOperand))
+#define G_IS_REGISTER_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_REGISTER_OPERAND))
+#define G_REGISTER_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_REGISTER_OPERAND, GRegisterOperandClass))
+#define G_IS_REGISTER_OPERAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_REGISTER_OPERAND))
+#define G_REGISTER_OPERAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_REGISTER_OPERAND, GRegisterOperandClass))
+
+
+/* Définition d'un opérande visant un registre (instance) */
+typedef struct _GRegisterOperand GRegisterOperand;
+
+/* Définition d'un opérande visant un registre (classe) */
+typedef struct _GRegisterOperandClass GRegisterOperandClass;
+
+
+/* Indique le type défini par la GLib pour un opérande de registre. */
+GType g_register_operand_get_type(void);
+
+/* Fournit le registre associé à l'opérande. */
+GArchRegister *g_register_operand_get_register(const GRegisterOperand *);
+
+/* Marque l'opérande comme étant écrit plutôt que consulté. */
+void g_register_operand_mark_as_written(GRegisterOperand *);
+
+/* Indique le type d'accès réalisé sur l'opérande. */
+bool g_register_operand_is_written(const GRegisterOperand *);
+
+
+
+#endif /* _ARCH_OPERANDS_REGISTER_H */