From ef3b996ad359e0da5e93184dab9200fad9105faf Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 30 Aug 2009 17:23:51 +0000 Subject: Provided a clean way to run delayed tasks. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@109 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 30 +++++ configure.ac | 1 + src/Makefile.am | 16 ++- src/analysis/binary.c | 17 ++- src/analysis/delayed.c | 299 ++++++++++++++++++---------------------------- src/analysis/delayed.h | 55 ++++++--- src/glibext/Makefile.am | 17 +++ src/glibext/delayed-int.h | 82 +++++++++++++ src/glibext/delayed.c | 226 +++++++++++++++++++++++++++++++++++ src/glibext/delayed.h | 81 +++++++++++++ src/gtkext/gtkblockview.c | 8 -- src/gtkext/gtkgraphview.c | 30 +---- src/main.c | 2 +- 13 files changed, 612 insertions(+), 252 deletions(-) create mode 100644 src/glibext/Makefile.am create mode 100644 src/glibext/delayed-int.h create mode 100644 src/glibext/delayed.c create mode 100644 src/glibext/delayed.h diff --git a/ChangeLog b/ChangeLog index a21bd1c..f09f937 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,35 @@ 09-08-30 Cyrille Bagard + * configure.ac: + Add the new Makefile from the 'src/glibext' directory to AC_CONFIG_FILES. + + * src/analysis/binary.c: + Update code. + + * src/analysis/delayed.c: + * src/analysis/delayed.h: + Update/clean the code by using the generic delayed manager. + + * src/glibext/delayed.c: + * src/glibext/delayed.h: + * src/glibext/delayed-int.h: + * src/glibext/Makefile.am: + New entries: provide a clean way to run delayed tasks. + + * src/gtkext/gtkblockview.c: + Clean and improve the gtk_block_view_set_rendering_lines() function. + + * src/gtkext/gtkgraphview.c: + Clean the gtk_graph_view_set_rendering_lines() function. + + * src/main.c: + Update code. + + * src/Makefile.am: + Create the new liboidaglibext library. Add glibext to SUBDIRS. + +09-08-30 Cyrille Bagard + * src/editor.c: Quickly fix a bug in binary view lookup. diff --git a/configure.ac b/configure.ac index c483d47..81079a7 100644 --- a/configure.ac +++ b/configure.ac @@ -248,6 +248,7 @@ AC_CONFIG_FILES([Makefile src/format/java/Makefile src/format/mangling/Makefile src/format/pe/Makefile + src/glibext/Makefile src/graph/Makefile src/gtkext/Makefile src/panel/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 3685409..95eff37 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ -lib_LTLIBRARIES = liboidadisass.la liboidagtkext.la liboidagui.la liboidaplugin.la +lib_LTLIBRARIES = liboidadisass.la liboidaglibext.la liboidagtkext.la liboidagui.la liboidaplugin.la bin_PROGRAMS=openida @@ -22,12 +22,22 @@ liboidadisass_la_LIBADD = \ format/libformat.la +#--- liboidaglibext + +liboidaglibext_la_SOURCES = + +liboidaglibext_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBGRAPH_LIBS) + +liboidaglibext_la_LIBADD = \ + glibext/libglibext.la + + #--- liboidagtkext liboidagtkext_la_SOURCES = liboidagtkext_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBGRAPH_LIBS) \ - -L.libs -loidadisass + -L.libs -loidadisass -loidaglibext liboidagtkext_la_LIBADD = \ graph/libgraph.la \ @@ -99,4 +109,4 @@ openida_LDADD = $(LIBINTL) \ # gtkext doit être traité en premier, à cause des marshals GLib -SUBDIRS = gtkext analysis arch format common debug graph panel plugins +SUBDIRS = glibext gtkext analysis arch format common debug graph panel plugins diff --git a/src/analysis/binary.c b/src/analysis/binary.c index c21b554..8cec72a 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -41,6 +41,7 @@ #include "line_prologue.h" #include "prototype.h" #include "../common/extstr.h" +#include "../glibext/delayed.h" #include "../format/format.h" #include "../panel/log.h" #include "../plugins/pglist.h" @@ -101,7 +102,7 @@ bin_t *map_binary_file(const char *, off_t *); GRenderingLine *build_binary_prologue(const char *, const uint8_t *, off_t); /* Acquitte la fin d'un désasemblage différé et complet. */ -void ack_completed_disassembly(GDelayedManager *, GOpenidaBinary *, GRenderingLine *, GOpenidaBinary *); +void ack_completed_disassembly(GDisassManager *, GOpenidaBinary *, GRenderingLine *, GOpenidaBinary *); @@ -312,24 +313,22 @@ bool g_openida_binary_save(const GOpenidaBinary *binary, xmlDocPtr xdoc, xmlXPat void g_openida_binary_analyse(GOpenidaBinary *binary) { - GDelayedManager *manager; /* Gestionnaire de différés */ + GDisassManager *manager; /* Gestionnaire de différés */ GBinPart **parts; /* Parties d'élément binaire */ size_t parts_count; /* Nombre de ces parties */ + GDelayedDisassembly *disass; /* Désassemblage à mener */ - manager = get_delayed_manager(); + manager = get_disassembly_manager(); parts = g_exe_format_get_parts(binary->format, &parts_count); qsort(parts, parts_count, sizeof(GBinPart *), g_binary_part_compare); + disass = g_delayed_disassembly_new(binary, parts, parts_count); g_signal_connect(manager, "disassembly-completed", G_CALLBACK(ack_completed_disassembly), binary); - g_delayed_manager_schedule_disassembly(manager, binary, parts, parts_count); - - - - + g_delayed_queue_schedule_work(G_WORK_QUEUE(manager), G_DELAYED_WORK(disass)); } @@ -605,7 +604,7 @@ GRenderingLine *build_binary_prologue(const char *filename, const uint8_t *data, * * ******************************************************************************/ -void ack_completed_disassembly(GDelayedManager *manager, GOpenidaBinary *binary, GRenderingLine *lines, GOpenidaBinary *user) +void ack_completed_disassembly(GDisassManager *manager, GOpenidaBinary *binary, GRenderingLine *lines, GOpenidaBinary *user) { GRenderingLine *line; /* "Première" ligne de rendu */ GPluginModule **pglist; /* Liste de greffons */ diff --git a/src/analysis/delayed.c b/src/analysis/delayed.c index 6ec03e8..0d02d39 100644 --- a/src/analysis/delayed.c +++ b/src/analysis/delayed.c @@ -24,13 +24,11 @@ #include "delayed.h" -#include - - #include "line_code.h" #include "line_comment.h" #include "../common/dllist.h" #include "../format/format.h" +#include "../glibext/delayed-int.h" #include "../gtkext/gtkextstatusbar.h" #include "../gtkext/iodamarshal.h" @@ -43,75 +41,75 @@ -/* Ensembles binaires à désassembler */ -typedef struct _disassembly_task +/* ------------------------ DESASSEMBLAGE DE BINAIRE DIFFERE ------------------------ */ + + +/* Ensembles binaires à désassembler (instance) */ +struct _GDelayedDisassembly { - GOpenidaBinary *owner; /* Destinataire final */ + GDelayedWork parent; /* A laisser en premier */ - DL_LIST_ITEM(link); /* Lien vers les maillons */ + GOpenidaBinary *binary; /* Destinataire final */ GBinPart **parts; /* Parties binaires à traiter */ size_t count; /* Nombre de ces parties */ -} disassembly_task; - +}; -#define disassembly_task_list_add_tail(new, head) dl_list_add_tail(new, head, disassembly_task, link) -#define disassembly_task_list_del(item, head) dl_list_del(item, head, disassembly_task, link) +/* Ensembles binaires à désassembler (classe) */ +struct _GDelayedDisassemblyClass +{ + GDelayedWorkClass parent; /* A laisser en premier */ +}; -/* Crée un tâche de désassemblage différé. */ -static disassembly_task *create_disassembly_task(GOpenidaBinary *, GBinPart **, size_t); -/* Efface une tâche de désassemblage de la mémoire. */ -static void delete_disassembly_task(disassembly_task *); +/* Initialise la classe des tâches de désassemblage différé. */ +static void g_delayed_disassembly_class_init(GDelayedDisassemblyClass *); +/* Initialise une tâche de désassemblage différé. */ +static void g_delayed_disassembly_init(GDelayedDisassembly *); +/* ------------------------- GESTION DES ANALYSES DIFFEREES ------------------------- */ /* Gestionnaire des analyses différées (instance) */ -struct _GDelayedManager +struct _GDisassManager { - GObject parent; /* A laisser en premier */ + GWorkQueue parent; /* A laisser en premier */ GtkExtStatusBar *statusbar; /* Barre de statut principale */ - disassembly_task *disassemblies; /* Binaires à désassembler */ - GMutex *disass_mutex; /* Verrou pour l'accès */ - GCond *disass_cond; /* Réveil pour un traitement */ - - GThread *disassemble; /* Procédures de désassemblage */ - }; /* Gestionnaire des analyses différées (classe) */ -struct _GDelayedManagerClass +struct _GDisassManagerClass { - GObjectClass parent; /* A laisser en premier */ + GWorkQueueClass parent; /* A laisser en premier */ /* Signaux */ - void (* disassembly_completed) (GDelayedManager *, GOpenidaBinary *, GRenderingLine *); + void (* disassembly_completed) (GDisassManager *, GOpenidaBinary *, GRenderingLine *); }; /* Initialise la classe des gestionnaires d'analyses différées. */ -static void g_delayed_manager_class_init(GDelayedManagerClass *); +static void g_disassembly_manager_class_init(GDisassManagerClass *); /* Initialise un gestionnaire d'analyses différées. */ -static void g_delayed_manager_init(GDelayedManager *); +static void g_disassembly_manager_init(GDisassManager *); /* Crée un gestionnaire d'analyses différées. */ -static GDelayedManager *g_delayed_manager_new(GObject *); +static GDisassManager *g_disassembly_manager_new(GObject *); /* Assure le désassemblage en différé. */ -static void *process_disassemblies(GDelayedManager *); +static void process_disassemblies(GDisassManager *, GDelayedDisassembly *); /* Procède au désassemblage basique d'un contenu binaire. */ -static GRenderingLine *disassemble_binary_parts(disassembly_task *, GBinRoutine **, size_t, GtkExtStatusBar *, guint); +static GRenderingLine *disassemble_binary_parts(GDelayedDisassembly *, GBinRoutine **, size_t, GtkExtStatusBar *, guint); /* Etablit les liens entres les différentes lignes de code. */ static void establish_links_between_lines(GRenderingLine *, GBinRoutine **, size_t, GtkExtStatusBar *, guint); @@ -124,48 +122,38 @@ static vmpa_t find_best_ending_address_for_routine(GRenderingLine *, size_t, con +/* ---------------------------------------------------------------------------------- */ +/* DESASSEMBLAGE DE BINAIRE DIFFERE */ +/* ---------------------------------------------------------------------------------- */ - +/* Indique le type défini pour les tâches de désassemblage différé. */ +G_DEFINE_TYPE(GDelayedDisassembly, g_delayed_disassembly, G_TYPE_DELAYED_WORK); /****************************************************************************** * * -* Paramètres : owner = binaire chargé en attente des résultats. * -* parts = parties binaires à désassembler. * -* count = nombre de parties à traiter. * +* Paramètres : klass = classe à initialiser. * * * -* Description : Crée un tâche de désassemblage différé. * +* Description : Initialise la classe des tâches de désassemblage différé. * * * -* Retour : Tâche créée. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -static disassembly_task *create_disassembly_task(GOpenidaBinary *owner, GBinPart **parts, size_t count) +static void g_delayed_disassembly_class_init(GDelayedDisassemblyClass *klass) { - disassembly_task *result; /* Tâche à retourner */ - - result = (disassembly_task *)calloc(1, sizeof(disassembly_task)); - - result->owner = owner; - - DL_LIST_ITEM_INIT(&result->link); - - result->parts = parts; - result->count = count; - - return result; } /****************************************************************************** * * -* Paramètres : task = tâche à libérer de la mémoire. * +* Paramètres : disass = instance à initialiser. * * * -* Description : Efface une tâche de désassemblage de la mémoire. * +* Description : Initialise une tâche de désassemblage différé. * * * * Retour : - * * * @@ -173,34 +161,50 @@ static disassembly_task *create_disassembly_task(GOpenidaBinary *owner, GBinPart * * ******************************************************************************/ -static void delete_disassembly_task(disassembly_task *task) +static void g_delayed_disassembly_init(GDelayedDisassembly *disass) { - /* TODO - result->parts = parts; - result->count = count; - */ - - free(task); } +/****************************************************************************** +* * +* Paramètres : binary = binaire chargé en attente des résultats. * +* parts = parties binaires à désassembler. * +* count = nombre de parties à traiter. * +* * +* Description : Crée une tâche de désassemblage différé. * +* * +* Retour : Tâche créée. * +* * +* Remarques : - * +* * +******************************************************************************/ +GDelayedDisassembly *g_delayed_disassembly_new(GOpenidaBinary *binary, GBinPart **parts, size_t count) +{ + GDelayedDisassembly *result; /* Tâche à retourner */ + result = g_object_new(G_TYPE_DELAYED_DISASSEMBLY, NULL); + result->binary = binary; + result->parts = parts; + result->count = count; + return result; +} - - - +/* ---------------------------------------------------------------------------------- */ +/* GESTION DES ANALYSES DIFFEREES */ +/* ---------------------------------------------------------------------------------- */ /* Indique le type défini pour le gestionnaire des analyses différées. */ -G_DEFINE_TYPE(GDelayedManager, g_delayed_manager, G_TYPE_OBJECT); +G_DEFINE_TYPE(GDisassManager, g_disassembly_manager, G_TYPE_WORK_QUEUE); /****************************************************************************** @@ -215,12 +219,12 @@ G_DEFINE_TYPE(GDelayedManager, g_delayed_manager, G_TYPE_OBJECT); * * ******************************************************************************/ -static void g_delayed_manager_class_init(GDelayedManagerClass *klass) +static void g_disassembly_manager_class_init(GDisassManagerClass *klass) { g_signal_new("disassembly-completed", - G_TYPE_DELAYED_MANAGER, + G_TYPE_DISASS_MANAGER, G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GDelayedManagerClass, disassembly_completed), + G_STRUCT_OFFSET(GDisassManagerClass, disassembly_completed), NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, G_TYPE_OPENIDA_BINARY, G_TYPE_RENDERING_LINE); @@ -240,8 +244,13 @@ static void g_delayed_manager_class_init(GDelayedManagerClass *klass) * * ******************************************************************************/ -static void g_delayed_manager_init(GDelayedManager *manager) +static void g_disassembly_manager_init(GDisassManager *manager) { + GWorkQueue *parent; /* Instance parente */ + + parent = G_WORK_QUEUE(manager); + + parent->process = (process_work_fc)process_disassemblies; } @@ -258,116 +267,76 @@ static void g_delayed_manager_init(GDelayedManager *manager) * * ******************************************************************************/ -static GDelayedManager *g_delayed_manager_new(GObject *ref) +static GDisassManager *g_disassembly_manager_new(GObject *ref) { - GDelayedManager *result; /* Adresse à retourner */ - GError *error; /* Bilan de création de thread */ + GDisassManager *result; /* Adresse à retourner */ - result = g_object_new(G_TYPE_DELAYED_MANAGER, NULL); + result = g_object_new(G_TYPE_DISASS_MANAGER, NULL); result->statusbar = g_object_get_data(ref, "statusbar"); - result->disass_mutex = g_mutex_new(); - if (result->disass_mutex == NULL) - goto dmn_error; - - result->disass_cond = g_cond_new(); - if (result->disass_cond == NULL) - goto dmn_error; - - result->disassemble = g_thread_create((GThreadFunc)process_disassemblies, result, FALSE, &error); - if (!result->disassemble) - goto dmn_error; - return result; - dmn_error: - - /* TODO */ - - return NULL; - } /****************************************************************************** * * * Paramètres : manager = gestionnaire des actions à mener. * +* disass = analyse à mener. * * * * Description : Assure le désassemblage en différé. * * * -* Retour : Bilan de l'opération. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -static void *process_disassemblies(GDelayedManager *manager) +static void process_disassemblies(GDisassManager *manager, GDelayedDisassembly *disass) { - disassembly_task *task; /* Désassemblage à effectuer */ GBinRoutine **routines; /* Liste des routines trouvées */ size_t routines_count; /* Nombre de ces routines */ guint id; /* Identifiant de statut */ GRenderingLine *lines; /* Nouvelles lignes de rendu */ - while (1) - { - g_mutex_lock(manager->disass_mutex); - - if (dl_list_empty(manager->disassemblies)) - g_cond_wait(manager->disass_cond, manager->disass_mutex); - - task = manager->disassemblies; - disassembly_task_list_del(task, &manager->disassemblies); - - g_mutex_unlock(manager->disass_mutex); + routines = g_binary_format_get_routines(G_BIN_FORMAT(g_openida_binary_get_format(disass->binary)), &routines_count); + qsort(routines, routines_count, sizeof(GBinRoutine *), g_binary_routine_rcompare); - routines = g_binary_format_get_routines(G_BIN_FORMAT(g_openida_binary_get_format(task->owner)), &routines_count); - qsort(routines, routines_count, sizeof(GBinRoutine *), g_binary_routine_rcompare); + /* Première étape */ - /* Première étape */ + id = gtk_extended_status_bar_push(manager->statusbar, _("Disassembling..."), true); - id = gtk_extended_status_bar_push(manager->statusbar, _("Disassembling..."), true); + lines = disassemble_binary_parts(disass, routines, routines_count, manager->statusbar, id); - lines = disassemble_binary_parts(task, routines, routines_count, - manager->statusbar, id); + gtk_extended_status_bar_remove(manager->statusbar, id); - gtk_extended_status_bar_remove(manager->statusbar, id); + /* Seconde étape */ - /* Seconde étape */ + id = gtk_extended_status_bar_push(manager->statusbar, _("Establishing links..."), true); - id = gtk_extended_status_bar_push(manager->statusbar, _("Establishing links..."), true); + establish_links_between_lines(lines, routines, routines_count, manager->statusbar, id); - establish_links_between_lines(lines, routines, routines_count, - manager->statusbar, id); + gtk_extended_status_bar_remove(manager->statusbar, id); - gtk_extended_status_bar_remove(manager->statusbar, id); + /* Troisième étape */ - /* Troisième étape */ + id = gtk_extended_status_bar_push(manager->statusbar, _("Finding remaining limits..."), true); - id = gtk_extended_status_bar_push(manager->statusbar, _("Finding remaining limits..."), true); + limit_all_routines(lines, routines, routines_count, manager->statusbar, id); - limit_all_routines(lines, routines, routines_count, - manager->statusbar, id); + gtk_extended_status_bar_remove(manager->statusbar, id); - gtk_extended_status_bar_remove(manager->statusbar, id); + /* Fin */ - /* Fin */ - - g_signal_emit_by_name(manager, "disassembly-completed", task->owner, lines); - - delete_disassembly_task(task); - - } - - return NULL; + g_signal_emit_by_name(manager, "disassembly-completed", disass->binary, lines); } /****************************************************************************** * * -* Paramètres : task = tâche à l'origine du traitement. * +* Paramètres : disass = tâche à l'origine du traitement. * * routines = prototypes existants à insérer. * * count = quantité de ces prototypes. * * statusbar = barre de statut avec progression à mettre à jour.* @@ -381,7 +350,7 @@ static void *process_disassemblies(GDelayedManager *manager) * * ******************************************************************************/ -static GRenderingLine *disassemble_binary_parts(disassembly_task *task, GBinRoutine **routines, size_t count, GtkExtStatusBar *statusbar, guint id) +static GRenderingLine *disassemble_binary_parts(GDelayedDisassembly *disass, GBinRoutine **routines, size_t count, GtkExtStatusBar *statusbar, guint id) { GRenderingLine *result; /* Ligne de rendu à retourner */ GArchProcessor *proc; /* Architecture du binaire */ @@ -403,25 +372,25 @@ static GRenderingLine *disassemble_binary_parts(disassembly_task *task, GBinRout result = NULL; - proc = get_arch_processor_from_format(g_openida_binary_get_format(task->owner)); - options = g_openida_binary_get_options(task->owner); - bin_data = g_openida_binary_get_data(task->owner, NULL); + proc = get_arch_processor_from_format(g_openida_binary_get_format(disass->binary)); + options = g_openida_binary_get_options(disass->binary); + bin_data = g_openida_binary_get_data(disass->binary, NULL); /* Préparation du suivi de la progression */ sum = 0; - for (i = 0; i < task->count; i++) + for (i = 0; i < disass->count; i++) { - g_binary_part_get_values(task->parts[i], NULL, &len, NULL); + g_binary_part_get_values(disass->parts[i], NULL, &len, NULL); sum += len; } done = 0; - for (i = 0; i < task->count; i++) + for (i = 0; i < disass->count; i++) { - g_binary_part_get_values(task->parts[i], &pos, &len, &base); + g_binary_part_get_values(disass->parts[i], &pos, &len, &base); /* Décodage des instructions */ @@ -695,48 +664,6 @@ static vmpa_t find_best_ending_address_for_routine(GRenderingLine *line, size_t } - - - - - - -/****************************************************************************** -* * -* Paramètres : manager = gestionnaire des actions à mener. * -* binary = élément binaire concerné par la procédure. * -* parts = blocs binaires à désassembler. * -* count = quantité de ces blocs binaires. * -* * -* Description : Place un nouveau désassemblage en attente. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_delayed_manager_schedule_disassembly(GDelayedManager *manager, GOpenidaBinary *binary, GBinPart **parts, size_t count) -{ - disassembly_task *task; /* Nouveau désassemblage */ - - task = create_disassembly_task(binary, parts, count); - - g_mutex_lock(manager->disass_mutex); - - disassembly_task_list_add_tail(task, &manager->disassemblies); - - g_cond_signal(manager->disass_cond); - - g_mutex_unlock(manager->disass_mutex); - -} - - - - - - /****************************************************************************** * * * Paramètres : manager = nouveau gestionnaire à mémoriser ou NULL. * @@ -749,9 +676,9 @@ void g_delayed_manager_schedule_disassembly(GDelayedManager *manager, GOpenidaBi * * ******************************************************************************/ -GDelayedManager *_get_delayed_manager(GDelayedManager *manager) +GDisassManager *_get_disassembly_manager(GDisassManager *manager) { - static GDelayedManager *result = NULL; /* Singleton à retourner */ + static GDisassManager *result = NULL; /* Singleton à retourner */ if (manager != NULL) result = manager; @@ -773,14 +700,14 @@ GDelayedManager *_get_delayed_manager(GDelayedManager *manager) * * ******************************************************************************/ -bool init_delayed_manager(GObject *ref) +bool init_disassembly_manager(GObject *ref) { - GDelayedManager *manager; /* Singleton à mettre en place */ + GDisassManager *manager; /* Singleton à mettre en place */ - manager = g_delayed_manager_new(ref); + manager = g_disassembly_manager_new(ref); if (manager != NULL) - _get_delayed_manager(manager); + _get_disassembly_manager(manager); return (manager != NULL); diff --git a/src/analysis/delayed.h b/src/analysis/delayed.h index 437f968..c543f0b 100644 --- a/src/analysis/delayed.h +++ b/src/analysis/delayed.h @@ -36,38 +36,61 @@ -#define G_TYPE_DELAYED_MANAGER g_delayed_manager_get_type() -#define G_DELAYED_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_delayed_manager_get_type(), GDelayedManager)) -#define G_IS_DELAYED_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_delayed_manager_get_type())) -#define G_DELAYED_MANAGER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_delayed_manager_get_type(), GDelayedManagerIface)) -#define G_DELAYED_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DELAYED_MANAGER, GDelayedManagerClass)) +/* ------------------------ DESASSEMBLAGE DE BINAIRE DIFFERE ------------------------ */ -/* Gestionnaire des analyses différées (instance) */ -typedef struct _GDelayedManager GDelayedManager; +#define G_TYPE_DELAYED_DISASSEMBLY g_delayed_disassembly_get_type() +#define G_DELAYED_DISASSEMBLY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_delayed_disassembly_get_type(), GDelayedDisassembly)) +#define G_IS_DELAYED_DISASSEMBLY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_delayed_disassembly_get_type())) +#define G_DELAYED_DISASSEMBLY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DELAYED_DISASSEMBLY, GDelayedDisassemblyClass)) +#define G_IS_DELAYED_DISASSEMBLY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DELAYED_DISASSEMBLY)) +#define G_DELAYED_DISASSEMBLY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DELAYED_DISASSEMBLY, GDelayedDisassemblyClass)) -/* Gestionnaire des analyses différées (classe) */ -typedef struct _GDelayedManagerClass GDelayedManagerClass; +/* Ensembles binaires à désassembler (instance) */ +typedef struct _GDelayedDisassembly GDelayedDisassembly; + +/* Ensembles binaires à désassembler (classe) */ +typedef struct _GDelayedDisassemblyClass GDelayedDisassemblyClass; -/* Indique le type défini pour le gestionnaire des analyses différées. */ -GType g_delayed_manager_get_type(void); -/* Place un nouveau désassemblage en attente. */ -void g_delayed_manager_schedule_disassembly(GDelayedManager *, GOpenidaBinary *, GBinPart **, size_t); +/* Indique le type défini pour les tâches de désassemblage différé. */ +GType g_delayed_disassembly_get_type(void); +/* Crée une tâche de désassemblage différé. */ +GDelayedDisassembly *g_delayed_disassembly_new(GOpenidaBinary *, GBinPart **, size_t); -#define get_delayed_manager() _get_delayed_manager(NULL) +/* ------------------------- GESTION DES ANALYSES DIFFEREES ------------------------- */ +#define G_TYPE_DISASS_MANAGER g_disassembly_manager_get_type() +#define G_DISASS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_disassembly_manager_get_type(), GDisassManager)) +#define G_IS_DISASS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_disassembly_manager_get_type())) +#define G_DISASS_MANAGER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_disassembly_manager_get_type(), GDisassManagerIface)) +#define G_DISASS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DISASS_MANAGER, GDisassManagerClass)) + + +/* Gestionnaire des analyses différées (instance) */ +typedef struct _GDisassManager GDisassManager; + +/* Gestionnaire des analyses différées (classe) */ +typedef struct _GDisassManagerClass GDisassManagerClass; + + +#define get_disassembly_manager() _get_disassembly_manager(NULL) + + +/* Indique le type défini pour le gestionnaire des analyses différées. */ +GType g_disassembly_manager_get_type(void); + /* Fournit le gestionnaire d'analyse en différé courant. */ -GDelayedManager *_get_delayed_manager(GDelayedManager *); +GDisassManager *_get_disassembly_manager(GDisassManager *); /* Procède au chargement du gestionnaire d'analyse différées. */ -bool init_delayed_manager(GObject *); +bool init_disassembly_manager(GObject *); diff --git a/src/glibext/Makefile.am b/src/glibext/Makefile.am new file mode 100644 index 0000000..334b49a --- /dev/null +++ b/src/glibext/Makefile.am @@ -0,0 +1,17 @@ + +noinst_LTLIBRARIES = libglibext.la + +libglibext_la_SOURCES = \ + delayed-int.h \ + delayed.h delayed.c + +libglibext_la_LDFLAGS = + + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = diff --git a/src/glibext/delayed-int.h b/src/glibext/delayed-int.h new file mode 100644 index 0000000..7fb8f3a --- /dev/null +++ b/src/glibext/delayed-int.h @@ -0,0 +1,82 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * delayed-int.h - définitions internes pour la gestion des travaux différés + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 . + */ + + +#include "delayed.h" + + +#include "../common/dllist.h" + + + +/* -------------------------- TACHE DIFFEREE DANS LE TEMPS -------------------------- */ + + +/* Travail différé (instance) */ +struct _GDelayedWork +{ + GObject parent; /* A laisser en premier */ + + DL_LIST_ITEM(link); /* Lien vers les maillons */ + +}; + +/* Travail différé (classe) */ +struct _GDelayedWorkClass +{ + GObjectClass parent; /* A laisser en premier */ + +}; + + +#define delayed_work_list_add_tail(new, head) dl_list_add_tail(new, head, GDelayedWork, link) +#define delayed_work_list_del(item, head) dl_list_del(item, head, GDelayedWork, link) + + + +/* ------------------------- TRAITEMENT DE TACHES DIFFEREES ------------------------- */ + + +/* Effectue le traitement d'une tâche donnée. */ +typedef void (* process_work_fc) (GWorkQueue *, GDelayedWork *); + + +/* Gestionnaire des travaux différés (instance) */ +struct _GWorkQueue +{ + GObject parent; /* A laisser en premier */ + + GDelayedWork *works; /* Tâches à mener à bien */ + GMutex *mutex; /* Verrou pour l'accès */ + GCond *cond; /* Réveil pour un traitement */ + + GThread *thread; /* Procédure de traitement */ + process_work_fc process; /* Coeur du traitement */ + +}; + +/* Gestionnaire des travaux différés (classe) */ +struct _GWorkQueueClass +{ + GObjectClass parent; /* A laisser en premier */ + +}; diff --git a/src/glibext/delayed.c b/src/glibext/delayed.c new file mode 100644 index 0000000..4388b2c --- /dev/null +++ b/src/glibext/delayed.c @@ -0,0 +1,226 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * delayed.c - gestion des travaux différés + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 . + */ + + +#include "delayed.h" + + +#include "delayed-int.h" + + + +/* -------------------------- TACHE DIFFEREE DANS LE TEMPS -------------------------- */ + + +/* Initialise la classe des travaux différés. */ +static void g_delayed_work_class_init(GDelayedWorkClass *); + +/* Initialise une instance de travail différé. */ +static void g_delayed_work_init(GDelayedWork *); + + + +/* ------------------------- TRAITEMENT DE TACHES DIFFEREES ------------------------- */ + + +/* Initialise la classe des travaux différés. */ +static void g_work_queue_class_init(GWorkQueueClass *); + +/* Initialise une instance de gestionnaire de travaux différés. */ +static void g_work_queue_init(GWorkQueue *); + +/* Assure le traitement en différé. */ +static void *g_work_queue_process(GWorkQueue *); + + + +/* ---------------------------------------------------------------------------------- */ +/* TACHE DIFFEREE DANS LE TEMPS */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini pour les travaux différés. */ +G_DEFINE_TYPE(GDelayedWork, g_delayed_work, G_TYPE_OBJECT); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des travaux différés. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_delayed_work_class_init(GDelayedWorkClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : work = instance à initialiser. * +* * +* Description : Initialise une instance de travail différé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_delayed_work_init(GDelayedWork *work) +{ + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* TRAITEMENT DE TACHES DIFFEREES */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini pour le gestionnaire des travaux différés. */ +G_DEFINE_TYPE(GWorkQueue, g_work_queue, G_TYPE_OBJECT); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des travaux différés. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_work_queue_class_init(GWorkQueueClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : queue = instance à initialiser. * +* * +* Description : Initialise une instance de gestionnaire de travaux différés. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_work_queue_init(GWorkQueue *queue) +{ + GError *error; /* Bilan de création de thread */ + + queue->mutex = g_mutex_new(); + if (queue->mutex == NULL) + goto gwqi_error; + + queue->cond = g_cond_new(); + if (queue->cond == NULL) + goto gwqi_error; + + queue->thread = g_thread_create((GThreadFunc)g_work_queue_process, queue, FALSE, &error); + if (!queue->thread) + goto gwqi_error; + + gwqi_error: + + /* TODO */ return; + +} + + +/****************************************************************************** +* * +* Paramètres : queue = gestionnaire des actions à mener. * +* * +* Description : Assure le traitement en différé. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void *g_work_queue_process(GWorkQueue *queue) +{ + GDelayedWork *work; /* Traitement à mener */ + + while (1) + { + g_mutex_lock(queue->mutex); + + if (dl_list_empty(queue->works)) + g_cond_wait(queue->cond, queue->mutex); + + work = queue->works; + delayed_work_list_del(work, &queue->works); + + g_mutex_unlock(queue->mutex); + + queue->process(queue, work); + + /* TODO : delete work */ + + } + + return NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : queu = gestionnaire des actions à mener. * +* work = nouvelle tâche à programmer, puis effectuer. * +* * +* Description : Place une nouvelle tâche en attente. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_delayed_queue_schedule_work(GWorkQueue *queue, GDelayedWork *work) +{ + g_mutex_lock(queue->mutex); + + delayed_work_list_add_tail(work, &queue->works); + + g_cond_signal(queue->cond); + + g_mutex_unlock(queue->mutex); + +} diff --git a/src/glibext/delayed.h b/src/glibext/delayed.h new file mode 100644 index 0000000..d1e3967 --- /dev/null +++ b/src/glibext/delayed.h @@ -0,0 +1,81 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * delayed.h - prototypes pour la gestion des travaux différés + * + * Copyright (C) 2009 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 . + */ + + +#ifndef _GLIBEXT_DELAYED_H +#define _GLIBEXT_DELAYED_H + + +#include + + + +/* -------------------------- TACHE DIFFEREE DANS LE TEMPS -------------------------- */ + + +#define G_TYPE_DELAYED_WORK g_delayed_work_get_type() +#define G_DELAYED_WORK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_delayed_work_get_type(), GDelayedWork)) +#define G_IS_DELAYED_WORK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_delayed_work_get_type())) +#define G_DELAYED_WORK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DELAYED_WORK, GDelayedWorkClass)) +#define G_IS_DELAYED_WORK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DELAYED_WORK)) +#define G_DELAYED_WORK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DELAYED_WORK, GDelayedWorkClass)) + + +/* Travail différé (instance) */ +typedef struct _GDelayedWork GDelayedWork; + +/* Travail différé (classe) */ +typedef struct _GDelayedWorkClass GDelayedWorkClass; + + +/* Indique le type défini pour les travaux différés. */ +GType g_delayed_work_get_type(void); + + + +/* ------------------------- TRAITEMENT DE TACHES DIFFEREES ------------------------- */ + + +#define G_TYPE_WORK_QUEUE g_work_queue_get_type() +#define G_WORK_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_work_queue_get_type(), GWorkQueue)) +#define G_IS_WORK_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_work_queue_get_type())) +#define G_WORK_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_WORK_QUEUE, GWorkQueueClass)) +#define G_IS_WORK_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_WORK_QUEUE)) +#define G_WORK_QUEUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_WORK_QUEUE, GWorkQueueClass)) + + +/* Gestionnaire des travaux différés (instance) */ +typedef struct _GWorkQueue GWorkQueue; + +/* Gestionnaire des travaux différés (classe) */ +typedef struct _GWorkQueueClass GWorkQueueClass; + + +/* Indique le type défini pour le gestionnaire des travaux différés. */ +GType g_work_queue_get_type(void); + +/* Place une nouvelle tâche en attente. */ +void g_delayed_queue_schedule_work(GWorkQueue *, GDelayedWork *); + + + +#endif /* _GLIBEXT_DELAYED_H */ diff --git a/src/gtkext/gtkblockview.c b/src/gtkext/gtkblockview.c index 99825f0..7161762 100644 --- a/src/gtkext/gtkblockview.c +++ b/src/gtkext/gtkblockview.c @@ -628,15 +628,7 @@ static void gtk_block_view_set_rendering_lines(GtkBlockView *view, GRenderingLin { g_signal_connect(iter, "rendering-line-flags-changed", G_CALLBACK(gtk_block_view_update_margin), view); - } - - g_rendering_line_update_bin_len(GTK_BIN_VIEW(view)->lines, - GTK_BIN_VIEW(view)->last, view->rendering); - for (iter = GTK_BIN_VIEW(view)->lines; - iter != NULL; - iter = g_rendering_line_get_next_iter(GTK_BIN_VIEW(view)->lines, iter, GTK_BIN_VIEW(view)->last)) - { if (iter != GTK_BIN_VIEW(view)->lines) { gtk_text_buffer_get_end_iter(view->buffer, &pos); diff --git a/src/gtkext/gtkgraphview.c b/src/gtkext/gtkgraphview.c index a6d4dd5..cc2d930 100644 --- a/src/gtkext/gtkgraphview.c +++ b/src/gtkext/gtkgraphview.c @@ -253,35 +253,7 @@ static void gtk_graph_view_reset(GtkGraphView *view) static void gtk_graph_view_set_rendering_lines(GtkGraphView *view, GRenderingLine *lines, GRenderingLine *last) { - GRenderingLine *mainl; - - view->childs = (GtkBinView **)calloc(2, sizeof(GtkBinView *)); - view->childs_count = 2; - - view->childs[0] = GTK_BIN_VIEW(gtk_block_view_new(MRD_GRAPH)); - - gtk_widget_show(GTK_WIDGET(view->childs[0])); - gtk_fixed_put(GTK_FIXED(view), GTK_WIDGET(view->childs[0]), 50, 50); - - - gtk_bin_view_set_rendering_lines(view->childs[0], GTK_BIN_VIEW(view)->binary, lines, lines); - - - - mainl = g_rendering_line_find_by_address(lines, last, 0x08048434); - - printf("mainl : %p\n", mainl); - - - view->childs[1] = GTK_BIN_VIEW(gtk_block_view_new(MRD_GRAPH)); - - gtk_widget_show(GTK_WIDGET(view->childs[1])); - gtk_fixed_put(GTK_FIXED(view), GTK_WIDGET(view->childs[1]), 100, 450); - - - gtk_bin_view_set_rendering_lines(view->childs[1], GTK_BIN_VIEW(view)->binary, mainl, mainl); - - + gtk_graph_view_reset(view); } diff --git a/src/main.c b/src/main.c index e1572d5..6466948 100644 --- a/src/main.c +++ b/src/main.c @@ -99,7 +99,7 @@ int main(int argc, char **argv) editor = create_editor(); gtk_widget_show(editor); - init_delayed_manager(G_OBJECT(editor)); + init_disassembly_manager(G_OBJECT(editor)); init_all_plugins(G_OBJECT(editor)); -- cgit v0.11.2-87-g4458