diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-12-26 23:52:44 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-12-26 23:52:44 (GMT) |
commit | 2c28d59fb3671c0fdd1987784076d4968c58b651 (patch) | |
tree | a301f6cd9c1fd9f92191fba7fe7b59a7e3a01b5a /src/analysis/project.c | |
parent | 67b4887317b7394d63b543aa48cb368406374103 (diff) |
Created the GLoadedContent interface to load all kinds of content.
Diffstat (limited to 'src/analysis/project.c')
-rw-r--r-- | src/analysis/project.c | 491 |
1 files changed, 91 insertions, 400 deletions
diff --git a/src/analysis/project.c b/src/analysis/project.c index cb1c70a..a5b59ab 100644 --- a/src/analysis/project.c +++ b/src/analysis/project.c @@ -33,15 +33,13 @@ #include <i18n.h> +#include "loaded.h" #include "loading.h" #include "../common/xml.h" #include "../core/global.h" #include "../core/params.h" -#include "../glibext/signal.h" -#include "../gtkext/easygtk.h" #include "../glibext/delayed-int.h" -#include "../gtkext/gtkblockdisplay.h" -#include "../gtkext/gtkgraphdisplay.h" +#include "../glibext/signal.h" #include "../gui/core/panels.h" #include "../gui/panels/log.h" #include "../gui/panels/panel.h" @@ -78,13 +76,9 @@ struct _GStudyProject char *filename; /* Lieu d'enregistrement */ - loaded_content *contents; /* Contenus binaires chargés */ - size_t contents_count; /* Nombre de ces contenus */ - GMutex cnt_mutex; /* Modification de la liste */ - - loaded_binary **binaries; /* Fichiers binaires associés */ - size_t binaries_count; /* Nombre de ces fichiers */ - GMutex bin_mutex; /* Modification de la liste */ + GLoadedContent **contents; /* Contenus chargés et intégrés*/ + size_t count; /* Quantité de ces contenus */ + GMutex mutex; /* Encadrement des accès */ }; @@ -94,6 +88,11 @@ struct _GStudyProjectClass { GObjectClass parent; /* A laisser en premier */ + /* Signaux */ + + void (* content_added) (GStudyProject *, GLoadedContent *); + void (* content_removed) (GStudyProject *, GLoadedContent *); + }; @@ -103,17 +102,6 @@ static void g_study_project_class_init(GStudyProjectClass *); /*Initialise une instance de projet d'étude. */ static void g_study_project_init(GStudyProject *); -/* Assure un positionnement initial idéal. */ -static gboolean scroll_for_the_first_time(GtkWidget *, GdkEvent *, GLoadedBinary *); - - - -/* ----------------------- VUES ET BASCULEMENT ENTRE LES VUES ----------------------- */ - - -/* Met en place un ensemble de vues pour un binaire. */ -GPanelItem *_setup_new_panel_item_for_binary(GStudyProject *, GLoadedBinary *, BinaryView, GtkDisplayPanel **); - /* ---------------------------------------------------------------------------------- */ @@ -139,6 +127,21 @@ G_DEFINE_TYPE(GStudyProject, g_study_project, G_TYPE_OBJECT); static void g_study_project_class_init(GStudyProjectClass *klass) { + g_signal_new("content-added", + G_TYPE_STUDY_PROJECT, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GStudyProjectClass, content_added), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, G_TYPE_OBJECT); + + g_signal_new("content-removed", + G_TYPE_STUDY_PROJECT, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GStudyProjectClass, content_removed), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, G_TYPE_OBJECT); } @@ -157,9 +160,7 @@ static void g_study_project_class_init(GStudyProjectClass *klass) static void g_study_project_init(GStudyProject *project) { - g_mutex_init(&project->cnt_mutex); - - g_mutex_init(&project->bin_mutex); + g_mutex_init(&project->mutex); } @@ -201,6 +202,10 @@ GStudyProject *g_study_project_new(void) GStudyProject *g_study_project_open(const char *filename) { + return NULL; + +#if 0 + GStudyProject *result; /* Adresse à retourner */ xmlDocPtr xdoc; /* Structure XML chargée */ xmlXPathContextPtr context; /* Contexte pour les XPath */ @@ -318,6 +323,8 @@ GStudyProject *g_study_project_open(const char *filename) return result; +#endif + } @@ -336,50 +343,31 @@ GStudyProject *g_study_project_open(const char *filename) bool g_study_project_save(GStudyProject *project, const char *filename) { + return false; + +#if 0 + bool result; /* Bilan à retourner */ xmlDocPtr xdoc; /* Document XML à créer */ xmlXPathContextPtr context; /* Contexte pour les recherches*/ const char *final; /* Lieu d'enregistrement final */ size_t i; /* Boucle de parcours */ - size_t access_len; /* Taille d'un chemin interne */ char *access; /* Chemin pour une sous-config.*/ result = create_new_xml_file(&xdoc, &context); - result &= (ensure_node_exist(xdoc, context, "/ChrysalideProject") != NULL); + if (result) + result = (ensure_node_exist(xdoc, context, "/ChrysalideProject") != NULL); final = filename != NULL ? filename : project->filename; - /* Enregistrement des contenus binaires attachés */ - - for (i = 0; i < project->contents_count && result; i++) - { - if (project->contents[i].state == PCS_INTERNAL) continue; - - access_len = strlen("/ChrysalideProject/Contents/Content[position()=") + SIZE_T_MAXLEN + strlen("]") + 1; - - access = calloc(access_len, sizeof(char)); - snprintf(access, access_len, "/ChrysalideProject/Contents/Content[position()=%zu]", i + 1); - - result = g_binary_content_save(project->contents[i].content, xdoc, context, access, final); - - if (result) - result = add_long_attribute_to_node(xdoc, context, access, "state", project->contents[i].state); - - free(access); - - } - /* Enregistrement des binaires analysés */ for (i = 0; i < project->binaries_count && result; i++) { - access_len = strlen("/ChrysalideProject/Binaries/Binary[position()=") + SIZE_T_MAXLEN + strlen("]") + 1; - - access = calloc(access_len, sizeof(char)); - snprintf(access, access_len, "/ChrysalideProject/Binaries/Binary[position()=%zu]", i + 1); + asprintf(&access, "/ChrysalideProject/Binaries/Binary[position()=%zu]", i + 1); - result = g_loaded_binary_save(project->binaries[i]->binary, xdoc, context, access); + result = g_loaded_binary_save(project->binaries[i]->binary, xdoc, context, access, final); free(access); @@ -400,6 +388,8 @@ bool g_study_project_save(GStudyProject *project, const char *filename) return result; +#endif + } @@ -438,6 +428,8 @@ const char *g_study_project_get_filename(const GStudyProject *project) void g_study_project_add_binary_content(GStudyProject *project, GBinContent *content, ProjectContentState state) { +#if 0 + loaded_content *new; /* Nouveau contenu à définir */ g_mutex_lock(&project->cnt_mutex); @@ -454,6 +446,7 @@ void g_study_project_add_binary_content(GStudyProject *project, GBinContent *con g_mutex_unlock(&project->cnt_mutex); +#endif } @@ -473,6 +466,10 @@ void g_study_project_add_binary_content(GStudyProject *project, GBinContent *con GBinContent *g_study_project_find_binary_content_by_hash(GStudyProject *project, const char *hash) { + return NULL; + +#if 0 + GBinContent *result; /* Trouvaille à retourner */ size_t i; /* Boucle de parcours */ GBinContent *iter; /* Contenu binaire analysé */ @@ -499,6 +496,8 @@ GBinContent *g_study_project_find_binary_content_by_hash(GStudyProject *project, return result; +#endif + } @@ -524,7 +523,7 @@ void ack_loaded_binary(GBinaryLoader *loader, GStudyProject *project) if (binary != NULL) { g_signal_connect_to_main_swapped(binary, "disassembly-done", - G_CALLBACK(g_study_project_attach_binary), project, + G_CALLBACK(g_study_project_attach_content), project, g_cclosure_marshal_VOID__VOID); g_loaded_binary_analyse(binary); @@ -536,43 +535,10 @@ void ack_loaded_binary(GBinaryLoader *loader, GStudyProject *project) /****************************************************************************** * * -* Paramètres : widget = composant d'affichage nouvellement porté à l'écran. * -* event = informations liées à l'événement. * -* binary = fichier binaire à associer au projet actuel. * -* * -* Description : Assure un positionnement initial idéal. * -* * -* Retour : FALSE. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static gboolean scroll_for_the_first_time(GtkWidget *widget, GdkEvent *event, GLoadedBinary *binary) -{ - GExeFormat *format; /* Format associé au binaire */ - vmpa2t target; /* Position initiale à viser */ - - g_signal_handlers_disconnect_by_func(widget, G_CALLBACK(scroll_for_the_first_time), binary); - - format = g_loaded_binary_get_format(binary); - - if (g_exe_format_get_main_address(format, &target)) - gtk_display_panel_request_move(GTK_DISPLAY_PANEL(widget), &target); - - g_object_unref(G_OBJECT(format)); - - return FALSE; - -} - - -/****************************************************************************** -* * -* Paramètres : project = project à effacer de la mémoire. * -* binary = fichier binaire à associer au projet actuel. * +* Paramètres : project = project à manipuler. * +* content = contenu chargé à associer au projet actuel. * * * -* Description : Attache un fichier donné à un projet donné. * +* Description : Attache un contenu donné à un projet donné. * * * * Retour : - * * * @@ -580,48 +546,28 @@ static gboolean scroll_for_the_first_time(GtkWidget *widget, GdkEvent *event, GL * * ******************************************************************************/ -void g_study_project_attach_binary(GStudyProject *project, GLoadedBinary *binary) +void g_study_project_attach_content(GStudyProject *project, GLoadedContent *content) { - loaded_binary *new; /* Nouveau binaire à présenter */ - GtkDisplayPanel *display; /* Composant d'affichage */ - GPanelItem *panel; /* Nouveau panneau associé */ - - /* Mise en place */ - - new = (loaded_binary *)calloc(1, sizeof(loaded_binary)); - - new->binary = binary; - - /* Enregistrement dans le projet */ + g_mutex_lock(&project->mutex); - g_mutex_lock(&project->bin_mutex); + project->contents = (GLoadedContent **)realloc(project->contents, + ++project->count * sizeof(GLoadedContent *)); - project->binaries = (loaded_binary **)realloc(project->binaries, - ++project->binaries_count * sizeof(loaded_binary *)); + project->contents[project->count - 1] = content; - project->binaries[project->binaries_count - 1] = new; + g_mutex_unlock(&project->mutex); - /* Premier affichage */ - - panel = _setup_new_panel_item_for_binary(project, binary, BVW_BLOCK, &display); - - g_mutex_unlock(&project->bin_mutex); - - g_signal_connect(display, "size-allocate", G_CALLBACK(scroll_for_the_first_time), binary); - - g_panel_item_dock(panel); - - update_project_area(project); + g_signal_emit_by_name(project, "content-added", content); } /****************************************************************************** * * -* Paramètres : project = project à effacer de la mémoire. * -* binary = fichier binaire à dissocier au projet actuel. * +* Paramètres : project = project à manipuler. * +* content = contenu chargé à dissocier du projet actuel. * * * -* Description : Détache un fichier donné à un projet donné. * +* Description : Détache un contenu donné d'un projet donné. * * * * Retour : - * * * @@ -629,29 +575,27 @@ void g_study_project_attach_binary(GStudyProject *project, GLoadedBinary *binary * * ******************************************************************************/ -void g_study_project_detach_binary(GStudyProject *project, GLoadedBinary *binary) +void g_study_project_detach_content(GStudyProject *project, GLoadedContent *content) { - //GtkDockPanel *dpanel; /* Support de panneaux */ - //GDockItem *ditem; /* Support d'affichage utilisé */ size_t i; /* Boucle de parcours */ - //dpanel = GTK_DOCK_PANEL(g_object_get_data(project->ref, "binpanel")); - //ditem = gtk_dock_panel_get_item_from_binary(project, binary); FIXME !! - - //gtk_dock_panel_remove_item(dpanel, ditem); + g_mutex_lock(&project->mutex); + for (i = 0; i < project->count; i++) + if (project->contents[i] == content) break; + if ((i + 1) < project->count) + memmove(&project->contents[i], &project->contents[i + 1], + (project->count - i - 1) * sizeof(GLoadedContent *)); - for (i = 0; i < project->binaries_count; i++) - if (project->binaries[i]->binary == binary) break; + project->contents = (GLoadedContent **)realloc(project->contents, + --project->count * sizeof(GLoadedContent *)); - if ((i + 1) < project->binaries_count) - memmove(&project->binaries[i], &project->binaries[i + 1], (project->binaries_count - i - 1) * sizeof(loaded_binary *)); + g_mutex_unlock(&project->mutex); - project->binaries = (loaded_binary **)realloc(project->binaries, - --project->binaries_count * sizeof(loaded_binary *)); + g_signal_emit_by_name(project, "content-removed", content); - update_project_area(project); + g_object_unref(G_OBJECT(content)); } @@ -670,6 +614,7 @@ void g_study_project_detach_binary(GStudyProject *project, GLoadedBinary *binary void g_study_project_display(const GStudyProject *project) { +#if 0 size_t i; /* Boucle de parcours #1 */ loaded_binary *handled; /* Binaire prise en compte */ size_t j; /* Boucle de parcours #2 */ @@ -682,7 +627,7 @@ void g_study_project_display(const GStudyProject *project) g_panel_item_dock(handled->items[j]); } - +#endif } @@ -700,6 +645,7 @@ void g_study_project_display(const GStudyProject *project) void g_study_project_hide(const GStudyProject *project) { +#if 0 size_t i; /* Boucle de parcours #1 */ loaded_binary *handled; /* Binaire prise en compte */ size_t j; /* Boucle de parcours #2 */ @@ -712,16 +658,16 @@ void g_study_project_hide(const GStudyProject *project) g_panel_item_undock(handled->items[j]); } - +#endif } /****************************************************************************** * * * Paramètres : project = projet dont le contenu est à afficher. * -* count = nombre de binaires pris en compte. [OUT] * +* count = nombre de contenus pris en compte. [OUT] * * * -* Description : Fournit l'ensemble des binaires associés à un projet. * +* Description : Fournit l'ensemble des contenus associés à un projet. * * * * Retour : Liste à libérer de la mémoire. * * * @@ -729,278 +675,23 @@ void g_study_project_hide(const GStudyProject *project) * * ******************************************************************************/ -GLoadedBinary **g_study_project_get_binaries(const GStudyProject *project, size_t *count) +GLoadedContent **g_study_project_get_contents(GStudyProject *project, size_t *count) { - GLoadedBinary **result; /* Tableau à retourner */ + GLoadedContent **result; /* Tableau à retourner */ size_t i; /* Boucle de parcours */ - *count = project->binaries_count; - result = (GLoadedBinary **)calloc(*count, sizeof(GLoadedBinary *)); + g_mutex_lock(&project->mutex); + + *count = project->count; + result = (GLoadedContent **)calloc(*count, sizeof(GLoadedContent *)); for (i = 0; i < *count; i++) { - result[i] = project->binaries[i]->binary; + result[i] = project->contents[i]; g_object_ref(G_OBJECT(result[i])); } - return result; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* VUES ET BASCULEMENT ENTRE LES VUES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : project = zone d'inscription du nouveau panneau. * -* binary = fichier binaire dont les vues sont à créer. * -* wanted = interface de visualisation demandée. * -* panel = interface de visualisation principale. [OUT] * -* * -* Description : Met en place un ensemble de vues pour un binaire. * -* * -* Retour : Panneau mis en place et prêt à être inséré. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GPanelItem *_setup_new_panel_item_for_binary(GStudyProject *project, GLoadedBinary *binary, BinaryView wanted, GtkDisplayPanel **panel) -{ - GPanelItem *result; /* Nouveau panneau à renvoyer */ - size_t k; /* Boucle de parcours #3 */ - loaded_binary *handled; /* Dossier de suivi à compléter*/ - GtkDisplayPanel *displays[BVW_COUNT]; /* Composants pour l'affichage */ - BinaryView i; /* Boucle de parcours #1 */ - GtkWidget *display; /* Affichage du binaire */ - GtkWidget *scroll; /* Surface d'exposition */ - GtkWidget *selected; /* Interface de prédilection */ - const char *name; /* Titre associé au binaire */ - const char *lname; /* Description du binaire */ - BinaryView j; /* Boucle de parcours #2 */ - - /* Recherche du dossier correspondant */ - - for (k = 0; k < project->binaries_count; k++) - if (project->binaries[k]->binary == binary) - break; - - assert(k < project->binaries_count); - - handled = project->binaries[k]; - - /* Créations */ - - for (i = 0; i < BVW_COUNT; i++) - { - /* Préparation du support visuel */ - - switch (i) - { - case BVW_BLOCK: - display = gtk_block_display_new(); - break; - case BVW_GRAPH: - display = gtk_graph_display_new(); - break; - default: /* GCC ! */ - break; - } - - gtk_widget_show(display); - - displays[i] = GTK_DISPLAY_PANEL(display); - - gtk_display_panel_attach_binary(displays[i], binary, i); - - /* Intégration finale dans un support défilant */ - - scroll = qck_create_scrolled_window(NULL, NULL); - gtk_container_add(GTK_CONTAINER(scroll), display); - - if (i == wanted) - { - selected = scroll; - *panel = GTK_DISPLAY_PANEL(display); - } - - } - - /* Support graphique final */ - - name = g_loaded_binary_get_name(binary, false); - lname = g_loaded_binary_get_name(binary, true); - - result = g_panel_item_new(PIP_BINARY_VIEW, name, lname, selected, true, "N"); - register_panel_item(result, get_main_configuration()); - - handled->items = (GPanelItem **)realloc(handled->items, ++handled->count * sizeof(GPanelItem *)); - handled->items[handled->count - 1] = result; - - /* Etablissement des liens */ - - for (i = 0; i < BVW_COUNT; i++) - for (j = 0; j < BVW_COUNT; j++) - { - if (j == i) - continue; - - switch (j) - { - case BVW_BLOCK: - g_object_set_data(G_OBJECT(displays[i]), "block_alt_view", displays[j]); - break; - case BVW_GRAPH: - g_object_set_data(G_OBJECT(displays[i]), "graph_alt_view", displays[j]); - break; - default: /* GCC ! */ - break; - } - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : project = zone d'inscription du nouveau panneau. * -* binary = fichier binaire dont les vues sont à créer. * -* wanted = interface de visualisation demandée. * -* panel = interface de visualisation principale. [OUT] * -* * -* Description : Met en place un ensemble de vues pour un binaire. * -* * -* Retour : Panneau mis en place et prêt à être inséré. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GPanelItem *setup_new_panel_item_for_binary(GStudyProject *project, GLoadedBinary *binary, BinaryView wanted, GtkDisplayPanel **panel) -{ - GPanelItem *result; /* Nouveau panneau à renvoyer */ - - /** - * La liste des binaires pris en charge ne doit pas évoluer en cours - * de traitement. On place donc le verrou adapté... - */ - - g_mutex_lock(&project->bin_mutex); - - result = _setup_new_panel_item_for_binary(project, binary, wanted, panel); - - g_mutex_unlock(&project->bin_mutex); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : panel = panneau affichant un contenu binaire. * -* * -* Description : Fournit la station d'accueil d'un panneau d'affichage. * -* * -* Retour : Composant GTK fourni sans transfert de propriété. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkDockStation *get_dock_station_for_view_panel(GtkDisplayPanel *panel) -{ - GtkWidget *result; /* Support trouvé à retourner */ - - /** - * La hiérarchie des composants empilés est la suivante : - * - * - GtkBlockView / GtkGraphView / GtkSourceView (avec GtkViewport intégré) - * - GtkScrolledWindow - * - GtkDockStation - * - */ - - result = gtk_widget_get_parent(GTK_WIDGET(panel)); /* ScrolledWindow */ - result = gtk_widget_get_parent(result); /* DockStation */ - - return GTK_DOCK_STATION(result); - -} - - -/****************************************************************************** -* * -* Paramètres : panel = panneau affichant un contenu binaire. * -* * -* Description : Fournit le support défilant d'un panneau d'affichage. * -* * -* Retour : Composant GTK fourni sans transfert de propriété. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkWidget *get_scroll_window_for_view_panel(GtkDisplayPanel *panel) -{ - GtkWidget *result; /* Support trouvé à retourner */ - - /** - * La hiérarchie des composants empilés est la suivante : - * - * - GtkBlockView / GtkGraphView / GtkSourceView (avec GtkViewport intégré) - * - GtkScrolledWindow - * - GtkDockStation - * - */ - - result = gtk_widget_get_parent(GTK_WIDGET(panel)); /* ScrolledWindow */ - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : panel = panneau affichant un contenu binaire. * -* view = autre vision recherchée. * -* * -* Description : Fournit une vision alternative d'un panneau d'affichage. * -* * -* Retour : Composant GTK fourni sans transfert de propriété. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GtkDisplayPanel *get_alt_view_for_view_panel(GtkDisplayPanel *panel, BinaryView view) -{ - GtkDisplayPanel *result; /* Panneau visé à renvoyer */ - - switch (view) - { - case BVW_BLOCK: - result = GTK_DISPLAY_PANEL(g_object_get_data(G_OBJECT(panel), "block_alt_view")); - break; - case BVW_GRAPH: - result = GTK_DISPLAY_PANEL(g_object_get_data(G_OBJECT(panel), "graph_alt_view")); - break; - default: - assert(false); - result = NULL; - break; - } - - if (result != NULL) - g_object_ref(G_OBJECT(result)); + g_mutex_unlock(&project->mutex); return result; |