summaryrefslogtreecommitdiff
path: root/src/analysis/binary.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-07-29 00:02:49 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-07-29 00:02:49 (GMT)
commit73af1bd66e5d1a2e30d56151532710f2b28d12df (patch)
tree88f98194359accd8349193f4cbe3c4cabee24d23 /src/analysis/binary.c
parentf150f36ee0297b4499a41bbbfc06699cd2f72db5 (diff)
Improved the GDB client.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@175 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/binary.c')
-rw-r--r--src/analysis/binary.c211
1 files changed, 211 insertions, 0 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index d8199c0..f6f56c7 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -39,7 +39,9 @@
#include "line_comment.h" /* TODO : supprimer ? */
#include "line_prologue.h"
#include "routine.h"
+#include "../common/cpp.h"
#include "../common/extstr.h"
+#include "../debug/break.h"
#include "../glibext/delayed-int.h"
#include "../format/format.h"
#include "../panels/log.h"
@@ -143,6 +145,10 @@ struct _GOpenidaBinary
GRenderingLine *lines; /* Lignes de rendu en place */
GRenderingOptions *options; /* Options de désassemblage */
+ GBreakGroup **brk_groups; /* Groupes de points d'arrêt */
+ size_t brk_count; /* Taille de cette liste */
+ GBreakGroup *brk_default; /* Groupe par défaut */
+
};
/* Description de fichier binaire (classe) */
@@ -176,6 +182,16 @@ void ack_completed_disassembly(GDelayedDisassembly *, GOpenidaBinary *);
+/* ------------------------------ ELEMENTS DE DEBOGAGE ------------------------------ */
+
+
+/* Réagit à une nouvelle création de point d'arrêt. */
+static void g_openida_binary_breakpoint_added(GBreakGroup *, GBreakPoint *, GOpenidaBinary *);
+
+/* Réagit à une suppression de point d'arrêt. */
+static void g_openida_binary_breakpoint_removed(GBreakGroup *, GBreakPoint *, GOpenidaBinary *);
+
+
/* ---------------------------------------------------------------------------------- */
/* DESASSEMBLAGE DE BINAIRE DIFFERE */
@@ -707,6 +723,8 @@ static void g_openida_binary_class_init(GOpenidaBinaryClass *klass)
static void g_openida_binary_init(GOpenidaBinary *binary)
{
+ /* FIXME : à replacer ailleurs */
+ g_openida_binary_add_break_group(binary, _("default"));
}
@@ -1473,3 +1491,196 @@ void ack_completed_disassembly(GDelayedDisassembly *disass, GOpenidaBinary *bina
g_signal_emit_by_name(binary, "disassembly-done");
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* ELEMENTS DE DEBOGAGE */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = représentation de binaire à modifier. *
+* name = éventuel nom à associer au groupe. *
+* *
+* Description : Ajoute un nouveau groupe de points d'arrêt au binaire. *
+* *
+* Retour : true si l'opération s'est bien effectuée, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_openida_binary_add_break_group(GOpenidaBinary *binary, const char *name)
+{
+ bool result; /* Bilan à faire remonter */
+ const char *used; /* Désignation à utiliser */
+ size_t tmp_len; /* Longeur maximale à gérer */
+ char *tmp; /* Construction temporaire */
+ size_t i; /* Boucle de parcours */
+ const char *test; /* Nom existant à tester */
+
+ result = true;
+
+ /* Préparation du nom de scène */
+
+ if (name != NULL) used = name;
+ else
+ {
+ tmp_len = strlen(_("Group")) + 1 + SIZE_T_MAXLEN + 1;
+ tmp = (char *)calloc(tmp_len, sizeof(char));
+
+ snprintf(tmp, tmp_len, "%s %lu", _("Group"), binary->brk_count);
+
+ used = tmp;
+
+ }
+
+ /* Vérification d'unicité */
+
+ for (i = 0; i < binary->brk_count && result; i++)
+ {
+ test = g_break_group_get_name(binary->brk_groups[i]);
+
+ if (test != NULL)
+ result = (strcmp(used, test) != 0);
+
+ }
+
+ /* Mise en place finale */
+
+ if (result)
+ {
+ binary->brk_count++;
+ binary->brk_groups = (GBreakGroup **)realloc(binary->brk_groups,
+ binary->brk_count * sizeof(GBreakGroup *));
+
+ binary->brk_groups[i] = g_break_group_new();
+
+ g_break_group_set_name(binary->brk_groups[i], used);
+
+ if (binary->brk_default == NULL)
+ binary->brk_default = binary->brk_groups[i];
+
+ g_signal_connect(binary->brk_groups[i], "added",
+ G_CALLBACK(g_openida_binary_breakpoint_added), binary);
+
+ g_signal_connect(binary->brk_groups[i], "removed",
+ G_CALLBACK(g_openida_binary_breakpoint_removed), binary);
+
+ }
+
+ if (name == NULL) free(tmp);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : group = ensemble de points d'arrêt intervenant. *
+* point = point d'arrêt à l'origine de la procédure. *
+* binary = représentation de binaire à modifier. *
+* *
+* Description : Réagit à une nouvelle création de point d'arrêt. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_openida_binary_breakpoint_added(GBreakGroup *group, GBreakPoint *point, GOpenidaBinary *binary)
+{
+ GRenderingLine *line; /* Ligne à retrouver */
+
+ line = g_rendering_line_find_by_address(binary->lines, NULL,
+ g_break_point_get_address(point));
+
+ if (line != NULL)
+ g_rendering_line_toggle_flag(line, RLF_BREAK_POINT);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : group = ensemble de points d'arrêt intervenant. *
+* point = point d'arrêt à l'origine de la procédure. *
+* binary = représentation de binaire à modifier. *
+* *
+* Description : Réagit à une suppression de point d'arrêt. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_openida_binary_breakpoint_removed(GBreakGroup *group, GBreakPoint *point, GOpenidaBinary *binary)
+{
+ GRenderingLine *line; /* Ligne à retrouver */
+
+ line = g_rendering_line_find_by_address(binary->lines, NULL,
+ g_break_point_get_address(point));
+
+ if (line != NULL)
+ g_rendering_line_toggle_flag(line, RLF_BREAK_POINT);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = représentation de binaire à mettre à jour. *
+* addr = adresse mémoire à faire basculer. *
+* *
+* Description : Ajoute ou supprime un point d'arrêt dans un binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_openida_binary_toggle_breakpoint(GOpenidaBinary *binary, vmpa_t addr)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < binary->brk_count; i++)
+ if (g_break_group_has_address(binary->brk_groups[i], addr))
+ {
+ g_break_group_toggle_breakpoint(binary->brk_groups[i], addr);
+ break;
+ }
+
+ if (i == binary->brk_count)
+ g_break_group_toggle_breakpoint(binary->brk_default, addr);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = représentation de binaire à parcourir. *
+* func = fonction à appeler à chaque point trouvé. *
+* data = éventuelle donnée de l'utilisateur à joindre. *
+* *
+* Description : Parcourt l'ensemble des groupes de points d'arrêt du binaire.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_openida_binary_for_each_bp_group(GOpenidaBinary *binary, GExtFunc func, gpointer data)
+{
+ size_t i; /* Boucle de parcours */
+
+ for (i = 0; i < binary->brk_count; i++)
+ func(binary, binary->brk_groups[i], data);
+
+}