summaryrefslogtreecommitdiff
path: root/src/arch/dalvik
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2016-11-27 23:35:47 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2016-11-27 23:35:47 (GMT)
commit7d6d3acb65586ad9512a38b58c16b9a21cdf98e0 (patch)
tree9ae21078e24c997b80a24d8d71ed5ad1be74c850 /src/arch/dalvik
parent3eacf14cc395e7fd0ab5dd5e9d22bb93a6a02979 (diff)
Saved memory space by sharing arch GObjects.
Diffstat (limited to 'src/arch/dalvik')
-rw-r--r--src/arch/dalvik/Makefile.am1
-rw-r--r--src/arch/dalvik/core.c72
-rw-r--r--src/arch/dalvik/core.h40
-rw-r--r--src/arch/dalvik/operands/register.c5
-rw-r--r--src/arch/dalvik/register.c148
-rw-r--r--src/arch/dalvik/register.h16
6 files changed, 267 insertions, 15 deletions
diff --git a/src/arch/dalvik/Makefile.am b/src/arch/dalvik/Makefile.am
index 0d1fa88..b97e7d8 100644
--- a/src/arch/dalvik/Makefile.am
+++ b/src/arch/dalvik/Makefile.am
@@ -3,6 +3,7 @@ noinst_LTLIBRARIES = libarchdalvik.la
libarchdalvik_la_SOURCES = \
context.h context.c \
+ core.h core.c \
fetch.h fetch.c \
helpers.h \
instruction-def.h \
diff --git a/src/arch/dalvik/core.c b/src/arch/dalvik/core.c
new file mode 100644
index 0000000..ba07c97
--- /dev/null
+++ b/src/arch/dalvik/core.c
@@ -0,0 +1,72 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * core.c - chargement et déchargement des mécanismes internes de l'architecture Dalvik
+ *
+ * Copyright (C) 2016 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 "core.h"
+
+
+#include "register.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Met en place les mécanismes internes de l'architecture. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool init_dalvik_core(void)
+{
+ bool result; /* Bilan à renvoyer */
+
+ result = true;
+
+ result &= init_dalvik_register_sharing();
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Supprime les mécanismes internes de l'architecture Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void exit_dalvik_core(void)
+{
+ exit_dalvik_register_sharing();
+
+}
diff --git a/src/arch/dalvik/core.h b/src/arch/dalvik/core.h
new file mode 100644
index 0000000..e7a5e1e
--- /dev/null
+++ b/src/arch/dalvik/core.h
@@ -0,0 +1,40 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * core.h - prototypes pour le chargement et le déchargement des mécanismes internes de l'architecture Dalvik
+ *
+ * Copyright (C) 2016 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/>.
+ */
+
+
+#ifndef _ARCH_DALVIK_CORE_H
+#define _ARCH_DALVIK_CORE_H
+
+
+#include <stdbool.h>
+
+
+
+/* Met en place les mécanismes internes de l'architecture. */
+bool init_dalvik_core(void);
+
+/* Supprime les mécanismes internes de l'architecture Dalvik. */
+void exit_dalvik_core(void);
+
+
+
+#endif /* _ARCH_DALVIK_CORE_H */
diff --git a/src/arch/dalvik/operands/register.c b/src/arch/dalvik/operands/register.c
index 61961a7..1fc5782 100644
--- a/src/arch/dalvik/operands/register.c
+++ b/src/arch/dalvik/operands/register.c
@@ -25,6 +25,7 @@
#include "../../operand-int.h"
+#include "../../register.h"
@@ -278,7 +279,7 @@ GDalvikRegister *g_dalvik_register_operand_get(const GDalvikRegisterOperand *ope
static bool g_dalvik_register_operand_compare(const GDalvikRegisterOperand *a, const GDalvikRegisterOperand *b)
{
- return (g_dalvik_register_compare(a->reg, b->reg) == 0);
+ return (g_arch_register_compare(G_ARCH_REGISTER(a->reg), G_ARCH_REGISTER(b->reg)) == 0);
}
@@ -299,7 +300,7 @@ static bool g_dalvik_register_operand_compare(const GDalvikRegisterOperand *a, c
static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *operand, GBufferLine *line, AsmSyntax syntax)
{
- g_dalvik_register_print(operand->reg, line, syntax);
+ g_arch_register_print(G_ARCH_REGISTER(operand->reg), line, syntax);
}
diff --git a/src/arch/dalvik/register.c b/src/arch/dalvik/register.c
index ed1b8c6..d112a86 100644
--- a/src/arch/dalvik/register.c
+++ b/src/arch/dalvik/register.c
@@ -28,9 +28,13 @@
#include "../register-int.h"
+#include "../sharing/manager.h"
+/* ------------------------- ENCADREMENT DE REGISTRES BRUTS ------------------------- */
+
+
/* Représentation d'un registre Dalvik (instance) */
struct _GDalvikRegister
{
@@ -58,9 +62,34 @@ static void g_dalvik_register_class_init(GDalvikRegisterClass *);
/* Initialise une instance de registre Dalvik. */
static void g_dalvik_register_init(GDalvikRegister *);
+/* Initialise un nouvel objet partagé avec des informations. */
+static bool g_dalvik_register_do_init(GDalvikRegister *, const uint16_t *);
+
+/* Indique l'objet partagé correspond à une description donnée. */
+static gboolean g_dalvik_register_compare_info(const GDalvikRegister *, const uint16_t *);
+
/* Produit une empreinte à partir d'un registre. */
static guint g_dalvik_register_hash(const GDalvikRegister *);
+/* Compare un registre avec un autre. */
+static int g_dalvik_register_compare(const GDalvikRegister *, const GDalvikRegister *);
+
+/* Traduit un registre en version humainement lisible. */
+static void g_dalvik_register_print(const GDalvikRegister *, GBufferLine *, AsmSyntax);
+
+
+
+/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */
+
+
+/* Gestionnaire des partages d'instances */
+static GShareManager *_dalvik_register_manager = NULL;
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* ENCADREMENT DE REGISTRES BRUTS */
+/* ---------------------------------------------------------------------------------- */
/* Indique le type défini pour une représentation d'un registre Dalvik. */
@@ -85,6 +114,9 @@ static void g_dalvik_register_class_init(GDalvikRegisterClass *klass)
register_class = G_ARCH_REGISTER_CLASS(klass);
+ register_class->init = (init_shared_fc)g_dalvik_register_do_init;
+ register_class->cmp_info = (compare_shared_info_fc)g_dalvik_register_compare_info;
+
register_class->hash = (reg_hash_fc)g_dalvik_register_hash;
register_class->compare = (reg_compare_fc)g_dalvik_register_compare;
register_class->print = (reg_print_fc)g_dalvik_register_print;
@@ -126,9 +158,11 @@ GDalvikRegister *g_dalvik_register_new(uint16_t index)
{
GDalvikRegister *result; /* Structure à retourner */
- result = g_object_new(G_TYPE_DALVIK_REGISTER, NULL);
+ result = G_DALVIK_REGISTER(g_share_manager_get(_dalvik_register_manager, &index));
+
+ //result = g_object_new(G_TYPE_DALVIK_REGISTER, NULL);
- result->index = index;
+ //result->index = index;
return result;
@@ -137,19 +171,46 @@ GDalvikRegister *g_dalvik_register_new(uint16_t index)
/******************************************************************************
* *
-* Paramètres : reg = registre à consulter. *
+* Paramètres : reg = objet partagé à initialiser. *
+* index = indice du registre correspondant. *
* *
-* Description : Fournit l'indice d'un registre Dalvik. *
+* Description : Initialise un nouvel objet partagé avec des informations. *
* *
-* Retour : Inditifiant représentant le registre. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-uint16_t g_dalvik_register_get_index(const GDalvikRegister *reg)
+static bool g_dalvik_register_do_init(GDalvikRegister *reg, const uint16_t *index)
{
- return reg->index;
+ reg->index = *index;
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : reg = objet partagé à consulter. *
+* index = indice du registre correspondant. *
+* *
+* Description : Indique l'objet partagé correspond à une description donnée. *
+* *
+* Retour : true si les détails centraux sont partagés, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static gboolean g_dalvik_register_compare_info(const GDalvikRegister *reg, const uint16_t *index)
+{
+ bool result; /* Bilan à retourner */
+
+ result = (reg->index == *index);
+
+ return result;
}
@@ -186,14 +247,16 @@ static guint g_dalvik_register_hash(const GDalvikRegister *reg)
* *
******************************************************************************/
-int g_dalvik_register_compare(const GDalvikRegister *a, const GDalvikRegister *b)
+static int g_dalvik_register_compare(const GDalvikRegister *a, const GDalvikRegister *b)
{
int result; /* Bilan à retourner */
if (a->index < b->index)
result = -1;
+
else if (a->index > b->index)
result = 1;
+
else
result = 0;
@@ -216,7 +279,7 @@ int g_dalvik_register_compare(const GDalvikRegister *a, const GDalvikRegister *b
* *
******************************************************************************/
-void g_dalvik_register_print(const GDalvikRegister *reg, GBufferLine *line, AsmSyntax syntax)
+static void g_dalvik_register_print(const GDalvikRegister *reg, GBufferLine *line, AsmSyntax syntax)
{
char key[MAX_REGNAME_LEN]; /* Mot clef principal */
size_t klen; /* Taille de ce mot clef */
@@ -240,3 +303,70 @@ void g_dalvik_register_print(const GDalvikRegister *reg, GBufferLine *line, AsmS
g_buffer_line_append_text(line, BLC_ASSEMBLY, key, klen, RTT_REGISTER, NULL);
}
+
+
+/******************************************************************************
+* *
+* Paramètres : reg = registre à consulter. *
+* *
+* Description : Fournit l'indice d'un registre Dalvik. *
+* *
+* Retour : Inditifiant représentant le registre. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+uint16_t g_dalvik_register_get_index(const GDalvikRegister *reg)
+{
+ return reg->index;
+
+}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* PARTAGES DE CONTENUS UNIQUES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Met en place les mécanismes de partage des registres Dalvik. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool init_dalvik_register_sharing(void)
+{
+ _dalvik_register_manager = g_share_manager_new(G_TYPE_DALVIK_REGISTER);
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Supprime les mécanismes de partage des registres Dalvik. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void exit_dalvik_register_sharing(void)
+{
+
+
+
+
+}
diff --git a/src/arch/dalvik/register.h b/src/arch/dalvik/register.h
index 989df6c..ab7368f 100644
--- a/src/arch/dalvik/register.h
+++ b/src/arch/dalvik/register.h
@@ -34,6 +34,9 @@
+/* ------------------------- ENCADREMENT DE REGISTRES BRUTS ------------------------- */
+
+
#define G_TYPE_DALVIK_REGISTER g_dalvik_register_get_type()
#define G_DALVIK_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_register_get_type(), GDalvikRegister))
#define G_IS_DALVIK_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_register_get_type()))
@@ -58,11 +61,16 @@ GDalvikRegister *g_dalvik_register_new(uint16_t);
/* Fournit l'indice d'un registre Dalvik. */
uint16_t g_dalvik_register_get_index(const GDalvikRegister *);
-/* Compare un registre avec un autre. */
-int g_dalvik_register_compare(const GDalvikRegister *, const GDalvikRegister *);
-/* Traduit un registre en version humainement lisible. */
-void g_dalvik_register_print(const GDalvikRegister *, GBufferLine *, AsmSyntax);
+
+/* -------------------------- PARTAGES DE CONTENUS UNIQUES -------------------------- */
+
+
+/* Met en place les mécanismes de partage des registres Dalvik. */
+bool init_dalvik_register_sharing(void);
+
+/* Supprime les mécanismes de partage des registres Dalvik. */
+void exit_dalvik_register_sharing(void);