summaryrefslogtreecommitdiff
path: root/src/format
diff options
context:
space:
mode:
Diffstat (limited to 'src/format')
-rw-r--r--src/format/Makefile.am2
-rw-r--r--src/format/format.c6
-rw-r--r--src/format/format.h3
-rw-r--r--src/format/preload-int.h54
-rw-r--r--src/format/preload.c534
-rw-r--r--src/format/preload.h98
6 files changed, 695 insertions, 2 deletions
diff --git a/src/format/Makefile.am b/src/format/Makefile.am
index 3f18b88..2fef6c6 100644
--- a/src/format/Makefile.am
+++ b/src/format/Makefile.am
@@ -8,6 +8,8 @@ libformat_la_SOURCES = \
executable.h executable.c \
format-int.h \
format.h format.c \
+ preload-int.h \
+ preload.h preload.c \
symbol.h symbol.c
libformat_la_LIBADD = \
diff --git a/src/format/format.c b/src/format/format.c
index 978a3d2..11216a2 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -31,6 +31,7 @@
#include "format-int.h"
+#include "preload.h"
#include "dex/dex.h"
#include "dwarf/dwarf.h"
#include "elf/elf.h"
@@ -247,6 +248,7 @@ void g_binary_format_register_code_point(GBinFormat *format, virt_t pt, bool ent
* *
* Paramètres : format = description de l'exécutable à consulter. *
* ctx = contexte de désassemblage à préparer. *
+* status = barre de statut à tenir informée. *
* *
* Description : Fournit un contexte initialisé pour un désassemblage. *
* *
@@ -256,10 +258,12 @@ void g_binary_format_register_code_point(GBinFormat *format, virt_t pt, bool ent
* *
******************************************************************************/
-void g_binary_format_setup_disassembling_context(GBinFormat *format, GProcContext *ctx)
+void g_binary_format_setup_disassembling_context(GBinFormat *format, GProcContext *ctx, GtkStatusStack *status)
{
size_t i; /* Boucle de parcours */
+ preload_binary_format(PGA_FORMAT_PRELOAD, format, G_PRELOAD_INFO(ctx), status);
+
g_rw_lock_reader_lock(&format->pt_lock);
for (i = 0; i < format->ep_count; i++)
diff --git a/src/format/format.h b/src/format/format.h
index c2ef895..b04f11b 100644
--- a/src/format/format.h
+++ b/src/format/format.h
@@ -34,6 +34,7 @@
#include "../analysis/content.h"
#include "../analysis/routine.h"
#include "../arch/context.h"
+#include "../gtkext/gtkstatusstack.h"
@@ -65,7 +66,7 @@ SourceEndian g_binary_format_get_endianness(const GBinFormat *);
void g_binary_format_register_code_point(GBinFormat *, virt_t, bool);
/* Fournit un contexte initialisé pour un désassemblage. */
-void g_binary_format_setup_disassembling_context(GBinFormat *, GProcContext *);
+void g_binary_format_setup_disassembling_context(GBinFormat *, GProcContext *, GtkStatusStack *);
/* Ajoute un symbole à la collection du format binaire. */
bool g_binary_format_add_symbol(GBinFormat *, GBinSymbol *);
diff --git a/src/format/preload-int.h b/src/format/preload-int.h
new file mode 100644
index 0000000..ccc59e3
--- /dev/null
+++ b/src/format/preload-int.h
@@ -0,0 +1,54 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * preload.c - préchargement d'instructions à partir d'un format
+ *
+ * Copyright (C) 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_PRELOAD_INT_H
+#define _FORMAT_PRELOAD_INT_H
+
+
+#include "preload.h"
+
+
+#include "../common/array.h"
+
+
+
+/* Préchargement d'origine formatée (instance) */
+struct _GPreloadInfo
+{
+ GObject parent; /* A laisser en premier */
+
+ flat_array_t *instructions; /* Liste d'instructions */
+ flat_array_t *comments; /* Liste de commentaires */
+
+};
+
+/* Préchargement d'origine formatée (classe) */
+struct _GPreloadInfoClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+};
+
+
+
+#endif /* _FORMAT_PRELOAD_INT_H */
diff --git a/src/format/preload.c b/src/format/preload.c
new file mode 100644
index 0000000..145dfd9
--- /dev/null
+++ b/src/format/preload.c
@@ -0,0 +1,534 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * preload.c - préchargement d'instructions à partir d'un format
+ *
+ * Copyright (C) 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "preload.h"
+
+
+#include "preload-int.h"
+
+
+
+/* Initialise la classe des préchargements à partir d'un format. */
+static void g_preload_info_class_init(GPreloadInfoClass *);
+
+/* Initialise une instance de préchargement à partir de format. */
+static void g_preload_info_init(GPreloadInfo *);
+
+/* Supprime toutes les références externes. */
+static void g_preload_info_dispose(GPreloadInfo *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_preload_info_finalize(GPreloadInfo *);
+
+
+
+/* Indique le type défini pour un préchargement à partir d'un format. */
+G_DEFINE_TYPE(GPreloadInfo, g_preload_info, G_TYPE_OBJECT);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des préchargements à partir d'un format.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_preload_info_class_init(GPreloadInfoClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_preload_info_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_preload_info_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à initialiser. *
+* *
+* Description : Initialise une instance de préchargement à partir de format. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_preload_info_init(GPreloadInfo *info)
+{
+ info->instructions = NULL;
+
+ info->comments = NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_preload_info_dispose(GPreloadInfo *info)
+{
+ GArchInstruction *instr; /* Instruction à libérer */
+ GDbComment *comment; /* Commentaire à libérer */
+
+ g_preload_info_lock_instructions(info);
+
+ _g_preload_info_drain_instructions(info);
+
+ g_preload_info_unlock_instructions(info);
+
+ g_preload_info_lock_comments(info);
+
+ while (_g_preload_info_count_comments(info) > 0)
+ {
+ comment = _g_preload_info_get_comment(info, 0);
+
+ rem_item_from_flat_array(&info->comments, 0, sizeof(GDbComment *));
+
+ g_object_unref(G_OBJECT(comment));
+
+ }
+
+ g_preload_info_unlock_comments(info);
+
+ G_OBJECT_CLASS(g_preload_info_parent_class)->dispose(G_OBJECT(info));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_preload_info_finalize(GPreloadInfo *info)
+{
+ G_OBJECT_CLASS(g_preload_info_parent_class)->finalize(G_OBJECT(info));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée une nouvelle collecte d'informations préchargées. *
+* *
+* Retour : Adresse de l'instance mise en place ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GPreloadInfo *g_preload_info_new(void)
+{
+ GPreloadInfo *result; /* Nouveau preloade à renvoyer */
+
+ result = g_object_new(G_TYPE_PRELOAD_INFO, NULL);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = préchargements à mettre à jour. *
+* *
+* Description : Verrouille les accès à la liste des instructions. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_preload_info_lock_instructions(GPreloadInfo *info)
+{
+ lock_flat_array(&info->instructions);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = préchargements à mettre à jour. *
+* *
+* Description : Déverrouille les accès à la liste des instructions. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_preload_info_unlock_instructions(GPreloadInfo *info)
+{
+ unlock_flat_array(&info->instructions);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à mettre à jour. *
+* instr = instruction à venir associer. *
+* *
+* Description : Ajoute une instruction supplémentaire aux préchargements. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_preload_info_add_instruction(GPreloadInfo *info, GArchInstruction *instr)
+{
+ int cmp_instr_by_addr(const GArchInstruction **a, const GArchInstruction **b)
+ {
+ const mrange_t *range_a; /* Emplacement pour l'instr. A */
+ const mrange_t *range_b; /* Emplacement pour l'instr. B */
+
+ range_a = g_arch_instruction_get_range(*a);
+ range_b = g_arch_instruction_get_range(*b);
+
+ return cmp_vmpa(get_mrange_addr(range_a), get_mrange_addr(range_b));
+
+ }
+
+ g_preload_info_lock_instructions(info);
+
+ insert_item_into_flat_array(&info->instructions, &instr, sizeof(GArchInstruction *),
+ (__compar_fn_t)cmp_instr_by_addr);
+
+ g_preload_info_unlock_instructions(info);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à consulter. *
+* *
+* Description : Indique la quantité d'instructions préchargées disponibles. *
+* *
+* Retour : Nombre d'instructions attachées. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t _g_preload_info_count_instructions(const GPreloadInfo *info)
+{
+ size_t result; /* Décompte à retourner */
+
+ result = count_flat_array_items(info->instructions);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à consulter. *
+* index = indice de l'instruction concernée. *
+* *
+* Description : Fournit une instruction préchargée donnée. *
+* *
+* Retour : Instruction trouvée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchInstruction *_g_preload_info_get_instruction(const GPreloadInfo *info, size_t index)
+{
+ GArchInstruction *result; /* Opérande à retourner */
+ GArchInstruction **ptr; /* Adresse dans le tableau */
+
+ ptr = get_flat_array_item(info->instructions, index, sizeof(GArchInstruction *));
+
+ result = *ptr;
+
+ g_object_ref(G_OBJECT(result));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à manipuler. *
+* *
+* Description : Dépile une instruction présente dans les préchargements. *
+* *
+* Retour : Instruction retirée ou NULL si aucune. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GArchInstruction *g_preload_info_pop_instruction(GPreloadInfo *info)
+{
+ GArchInstruction *result; /* Instruction à retourner */
+ GArchInstruction **ptr; /* Adresse dans le tableau */
+
+ g_preload_info_lock_instructions(info);
+
+ if (_g_preload_info_count_instructions(info) == 0)
+ result = NULL;
+
+ else
+ {
+ ptr = get_flat_array_item(info->instructions, 0, sizeof(GArchInstruction *));
+ result = *ptr;
+
+ rem_item_from_flat_array(&info->instructions, 0, sizeof(GArchInstruction *));
+
+ }
+
+ g_preload_info_unlock_instructions(info);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à manipuler. *
+* *
+* Description : Retire des préchargements toutes les instructions. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void _g_preload_info_drain_instructions(GPreloadInfo *info)
+{
+ GArchInstruction *instr; /* Instruction à libérer */
+
+ while (_g_preload_info_count_instructions(info) > 0)
+ {
+ instr = _g_preload_info_get_instruction(info, 0);
+
+ rem_item_from_flat_array(&info->instructions, 0, sizeof(GArchInstruction *));
+
+ g_object_unref(G_OBJECT(instr));
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = préchargements à mettre à jour. *
+* *
+* Description : Verrouille les accès à la liste des commentaires. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_preload_info_lock_comments(GPreloadInfo *info)
+{
+ lock_flat_array(&info->comments);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = préchargements à mettre à jour. *
+* *
+* Description : Déverrouille les accès à la liste des commentaires. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_preload_info_unlock_comments(GPreloadInfo *info)
+{
+ unlock_flat_array(&info->comments);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à mettre à jour. *
+* comment = commentaire à venir associer. *
+* *
+* Description : Ajoute un commentaire supplémentaire aux préchargements. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_preload_info_add_comment(GPreloadInfo *info, GDbComment *comment)
+{
+ int cmp_comment_by_addr(const GDbComment * const *a, const GDbComment * const *b)
+ {
+ const vmpa2t *addr_a; /* Position du commentaire A */
+ const vmpa2t *addr_b; /* Position du commentaire B */
+
+ addr_a = g_db_comment_get_address(*a);
+ addr_b = g_db_comment_get_address(*b);
+
+ return cmp_vmpa(addr_a, addr_b);
+
+ }
+
+ g_preload_info_lock_comments(info);
+
+ insert_item_into_flat_array(&info->comments, &comment, sizeof(GDbComment *),
+ (__compar_fn_t)cmp_comment_by_addr);
+
+ g_preload_info_unlock_comments(info);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à consulter. *
+* *
+* Description : Indique la quantité de commentaires préchargés disponibles. *
+* *
+* Retour : Nombre de commentaires attachés. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t _g_preload_info_count_comments(const GPreloadInfo *info)
+{
+ size_t result; /* Décompte à retourner */
+
+ result = count_flat_array_items(info->comments);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à consulter. *
+* index = indice de l'instruction concernée. *
+* *
+* Description : Fournit un commentaire préchargé donné. *
+* *
+* Retour : Commentaire trouvé. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDbComment *_g_preload_info_get_comment(const GPreloadInfo *info, size_t index)
+{
+ GDbComment *result; /* Opérande à retourner */
+ GDbComment **ptr; /* Adresse dans le tableau */
+
+ ptr = get_flat_array_item(info->comments, index, sizeof(GDbComment *));
+
+ result = *ptr;
+
+ g_object_ref(G_OBJECT(result));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : info = instance à manipuler. *
+* *
+* Description : Dépile un commentaire présent dans les préchargements. *
+* *
+* Retour : Commentaire retiré ou NULL si aucune. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GDbComment *g_preload_info_pop_comment(GPreloadInfo *info)
+{
+ GDbComment *result; /* Instruction à retourner */
+ GDbComment **ptr; /* Adresse dans le tableau */
+
+ g_preload_info_lock_comments(info);
+
+ if (_g_preload_info_count_comments(info) == 0)
+ result = NULL;
+
+ else
+ {
+ ptr = get_flat_array_item(info->comments, 0, sizeof(GDbComment *));
+ result = *ptr;
+
+ rem_item_from_flat_array(&info->comments, 0, sizeof(GDbComment *));
+
+ }
+
+ g_preload_info_unlock_comments(info);
+
+ return result;
+
+}
diff --git a/src/format/preload.h b/src/format/preload.h
new file mode 100644
index 0000000..a915462
--- /dev/null
+++ b/src/format/preload.h
@@ -0,0 +1,98 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * preload.h - prototypes pour le préchargement d'instructions à partir d'un format
+ *
+ * Copyright (C) 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _FORMAT_PRELOAD_H
+#define _FORMAT_PRELOAD_H
+
+
+#include <glib-object.h>
+
+
+#include "../analysis/db/items/comment.h"
+#include "../arch/instruction.h"
+
+
+
+#define G_TYPE_PRELOAD_INFO g_preload_info_get_type()
+#define G_PRELOAD_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PRELOAD_INFO, GPreloadInfo))
+#define G_IS_PRELOAD_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PRELOAD_INFO))
+#define G_PRELOAD_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PRELOAD_INFO, GPreloadInfoClass))
+#define G_IS_PRELOAD_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PRELOAD_INFO))
+#define G_PRELOAD_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PRELOAD_INFO, GPreloadInfoClass))
+
+
+/* Préchargement d'origine formatée (instance) */
+typedef struct _GPreloadInfo GPreloadInfo;
+
+/* Préchargement d'origine formatée (classe) */
+typedef struct _GPreloadInfoClass GPreloadInfoClass;
+
+
+/* Indique le type défini pour un préchargement à partir d'un format. */
+GType g_preload_info_get_type(void);
+
+/* Crée une nouvelle collecte d'informations préchargées. */
+GPreloadInfo *g_preload_info_new(void);
+
+/* Verrouille les accès à la liste des instructions. */
+void g_preload_info_lock_instructions(GPreloadInfo *);
+
+/* Déverrouille les accès à la liste des instructions. */
+void g_preload_info_unlock_instructions(GPreloadInfo *);
+
+/* Ajoute une instruction supplémentaire aux préchargements. */
+void g_preload_info_add_instruction(GPreloadInfo *, GArchInstruction *);
+
+/* Indique la quantité d'instructions préchargées disponibles. */
+size_t _g_preload_info_count_instructions(const GPreloadInfo *);
+
+/* Fournit une instruction préchargée donnée. */
+GArchInstruction *_g_preload_info_get_instruction(const GPreloadInfo *, size_t);
+
+/* Dépile une instruction présente dans les préchargements. */
+GArchInstruction *g_preload_info_pop_instruction(GPreloadInfo *);
+
+/* Retire des préchargements toutes les instructions. */
+void _g_preload_info_drain_instructions(GPreloadInfo *);
+
+/* Verrouille les accès à la liste des commentaires. */
+void g_preload_info_lock_comments(GPreloadInfo *);
+
+/* Déverrouille les accès à la liste des commentaires. */
+void g_preload_info_unlock_comments(GPreloadInfo *);
+
+/* Ajoute un commentaire supplémentaire aux préchargements. */
+void g_preload_info_add_comment(GPreloadInfo *, GDbComment *);
+
+/* Indique la quantité de commentaires préchargés disponibles. */
+size_t _g_preload_info_count_comments(const GPreloadInfo *);
+
+/* Fournit un commentaire préchargé donné. */
+GDbComment *_g_preload_info_get_comment(const GPreloadInfo *, size_t);
+
+/* Dépile un commentaire présent dans les préchargements. */
+GDbComment *g_preload_info_pop_comment(GPreloadInfo *);
+
+
+
+#endif /* _FORMAT_PRELOAD_H */