summaryrefslogtreecommitdiff
path: root/plugins/arm
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2021-08-21 15:07:38 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2021-08-21 15:07:38 (GMT)
commitbae8c01323703d467ed2cce07c8bf8fd70f7816a (patch)
treea4e180f9d82ed3f7312dcf52b4517cb7580b83e5 /plugins/arm
parent9ed9405f37244832570f48b42dced1c92704ba3d (diff)
Define all architecture instructions as serializable.
Diffstat (limited to 'plugins/arm')
-rw-r--r--plugins/arm/instruction.c121
-rw-r--r--plugins/arm/v7/instruction.c109
2 files changed, 230 insertions, 0 deletions
diff --git a/plugins/arm/instruction.c b/plugins/arm/instruction.c
index 4872aba..c42250f 100644
--- a/plugins/arm/instruction.c
+++ b/plugins/arm/instruction.c
@@ -29,6 +29,7 @@
#include <string.h>
+#include <analysis/db/misc/rlestr.h>
#include <common/extstr.h>
#include <core/logs.h>
@@ -62,6 +63,17 @@ static bool g_arm_instruction_serialize(GArmInstruction *, GAsmStorage *, packed
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Charge un contenu depuis une mémoire tampon. */
+static bool g_arm_instruction_load(GArmInstruction *, GObjectStorage *, packed_buffer_t *);
+
+/* Sauvegarde un contenu dans une mémoire tampon. */
+static bool g_arm_instruction_store(GArmInstruction *, GObjectStorage *, packed_buffer_t *);
+
+
+
/* Indique le type défini pour une représentation d'une instruction ARM. */
G_DEFINE_TYPE(GArmInstruction, g_arm_instruction, G_TYPE_ARCH_INSTRUCTION);
@@ -93,6 +105,9 @@ static void g_arm_instruction_class_init(GArmInstructionClass *klass)
instr->unserialize = (unserialize_instruction_fc)g_arm_instruction_unserialize;
instr->serialize = (serialize_instruction_fc)g_arm_instruction_serialize;
+ instr->load = (load_instruction_fc)g_arm_instruction_load;
+ instr->store = (store_instruction_fc)g_arm_instruction_store;
+
}
@@ -382,3 +397,109 @@ static bool g_arm_instruction_serialize(GArmInstruction *instr, GAsmStorage *sto
return result;
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = élément GLib à constuire. *
+* storage = conservateur de données à manipuler ou NULL. *
+* pbuf = zone tampon à lire. *
+* *
+* Description : Charge un contenu depuis une mémoire tampon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_arm_instruction_load(GArmInstruction *instr, GObjectStorage *storage, packed_buffer_t *pbuf)
+{
+ bool result; /* Bilan à retourner */
+ GArchInstructionClass *parent; /* Classe parente à consulter */
+ rle_string str; /* Chaîne à charger */
+ uleb128_t value; /* Valeur ULEB128 à charger */
+
+ parent = G_ARCH_INSTRUCTION_CLASS(g_arm_instruction_parent_class);
+
+ result = parent->load(G_ARCH_INSTRUCTION(instr), storage, pbuf);
+
+ if (result)
+ {
+ setup_empty_rle_string(&str);
+
+ result = unpack_rle_string(&str, pbuf);
+
+ if (result)
+ {
+ result = (get_rle_string(&str) != NULL);
+
+ if (result)
+ result = g_arm_instruction_extend_keyword(instr, get_rle_string(&str));
+
+ exit_rle_string(&str);
+
+ }
+
+ }
+
+ if (result)
+ {
+ result = unpack_uleb128(&value, pbuf);
+
+ if (result)
+ instr->cond = value;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = élément GLib à consulter. *
+* storage = conservateur de données à manipuler ou NULL. *
+* pbuf = zone tampon à remplir. *
+* *
+* Description : Sauvegarde un contenu dans une mémoire tampon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_arm_instruction_store(GArmInstruction *instr, GObjectStorage *storage, packed_buffer_t *pbuf)
+{
+ bool result; /* Bilan à retourner */
+ GArchInstructionClass *parent; /* Classe parente à consulter */
+ rle_string str; /* Chaîne à conserver */
+
+ parent = G_ARCH_INSTRUCTION_CLASS(g_arm_instruction_parent_class);
+
+ result = parent->store(G_ARCH_INSTRUCTION(instr), storage, pbuf);
+
+ if (result)
+ {
+ init_static_rle_string(&str, instr->suffix);
+
+ result = pack_rle_string(&str, pbuf);
+
+ exit_rle_string(&str);
+
+ }
+
+ if (result)
+ result = pack_uleb128((uleb128_t []){ instr->cond }, pbuf);
+
+ return result;
+
+}
diff --git a/plugins/arm/v7/instruction.c b/plugins/arm/v7/instruction.c
index 30a5bd8..eb4a082 100644
--- a/plugins/arm/v7/instruction.c
+++ b/plugins/arm/v7/instruction.c
@@ -97,6 +97,17 @@ static bool g_armv7_instruction_serialize(GArmV7Instruction *, GAsmStorage *, pa
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
+
+
+/* Charge un contenu depuis une mémoire tampon. */
+static bool g_armv7_instruction_load(GArmV7Instruction *, GObjectStorage *, packed_buffer_t *);
+
+/* Sauvegarde un contenu dans une mémoire tampon. */
+static bool g_armv7_instruction_store(GArmV7Instruction *, GObjectStorage *, packed_buffer_t *);
+
+
+
/* Indique le type défini pour une représentation d'une instruction ARMv7. */
G_DEFINE_TYPE(GArmV7Instruction, g_armv7_instruction, G_TYPE_ARM_INSTRUCTION);
@@ -132,6 +143,9 @@ static void g_armv7_instruction_class_init(GArmV7InstructionClass *klass)
instr->unserialize = (unserialize_instruction_fc)g_armv7_instruction_unserialize;
instr->serialize = (serialize_instruction_fc)g_armv7_instruction_serialize;
+ instr->load = (load_instruction_fc)g_armv7_instruction_load;
+ instr->store = (store_instruction_fc)g_armv7_instruction_store;
+
}
@@ -506,3 +520,98 @@ static bool g_armv7_instruction_serialize(GArmV7Instruction *instr, GAsmStorage
return result;
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = élément GLib à constuire. *
+* storage = conservateur de données à manipuler ou NULL. *
+* pbuf = zone tampon à lire. *
+* *
+* Description : Charge un contenu depuis une mémoire tampon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_armv7_instruction_load(GArmV7Instruction *instr, GObjectStorage *storage, packed_buffer_t *pbuf)
+{
+ bool result; /* Bilan à retourner */
+ GArchInstructionClass *parent; /* Classe parente à consulter */
+ uleb128_t value; /* Valeur ULEB128 à charger */
+ uint8_t boolean; /* Valeur booléenne */
+
+ parent = G_ARCH_INSTRUCTION_CLASS(g_armv7_instruction_parent_class);
+
+ result = parent->load(G_ARCH_INSTRUCTION(instr), storage, pbuf);
+
+ if (result)
+ result = unpack_uleb128(&value, pbuf);
+
+ if (result)
+ instr->sid = value;
+
+ if (result)
+ result = extract_packed_buffer(pbuf, &instr->encoding, sizeof(char), false);
+
+ if (result)
+ {
+ result = extract_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false);
+
+ if (result)
+ instr->setflags = (boolean == 1 ? true : false);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = élément GLib à consulter. *
+* storage = conservateur de données à manipuler ou NULL. *
+* pbuf = zone tampon à remplir. *
+* *
+* Description : Sauvegarde un contenu dans une mémoire tampon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_armv7_instruction_store(GArmV7Instruction *instr, GObjectStorage *storage, packed_buffer_t *pbuf)
+{
+ bool result; /* Bilan à retourner */
+ GArchInstructionClass *parent; /* Classe parente à consulter */
+ uint8_t boolean; /* Valeur booléenne */
+
+ parent = G_ARCH_INSTRUCTION_CLASS(g_armv7_instruction_parent_class);
+
+ result = parent->store(G_ARCH_INSTRUCTION(instr), storage, pbuf);
+
+ if (result)
+ result = pack_uleb128((uleb128_t []){ instr->sid }, pbuf);
+
+ if (result)
+ result = extend_packed_buffer(pbuf, &instr->encoding, sizeof(char), false);
+
+ if (result)
+ {
+ boolean = (instr->setflags ? 1 : 0);
+ result = extend_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false);
+ }
+
+ return result;
+
+}