diff options
Diffstat (limited to 'src/analysis/binary.c')
-rw-r--r-- | src/analysis/binary.c | 327 |
1 files changed, 255 insertions, 72 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c index 7b0e528..5b2caf0 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -35,6 +35,7 @@ #include <i18n.h> +#include "loaded-int.h" #include "routine.h" #include "db/client.h" //#include "decomp/decompiler.h" @@ -47,7 +48,11 @@ #include "../core/global.h" #include "../core/params.h" #include "../core/processors.h" -#include "../glibext/chrysamarshal.h" +//#include "../glibext/chrysamarshal.h" +#include "../gtkext/easygtk.h" +#include "../gtkext/gtkblockdisplay.h" +#include "../gtkext/gtkdisplaypanel.h" +#include "../gtkext/gtkgraphdisplay.h" #include "../gui/panels/log.h" @@ -98,7 +103,6 @@ struct _GLoadedBinaryClass /* Signaux */ void (* disassembly_done) (GLoadedBinary *); - void (* display_changed) (GLoadedBinary *, BinaryView, BufferLineColumn); }; @@ -109,6 +113,9 @@ static void g_loaded_binary_class_init(GLoadedBinaryClass *); /* Initialise une description de fichier binaire. */ static void g_loaded_binary_init(GLoadedBinary *); +/* Procède à l'initialisation de l'interface de contenu chargé. */ +static void g_loaded_binary_interface_init(GLoadedContentInterface *); + /* Supprime toutes les références externes. */ static void g_loaded_binary_dispose(GLoadedBinary *); @@ -145,6 +152,28 @@ static bool g_loaded_binary_connect_remote(GLoadedBinary *); static void _g_loaded_binary_analyse(GLoadedBinary *, disassembly_ack_fc); +/* ---------------------- GESTION SOUS FORME DE CONTENU CHARGE ---------------------- */ + + +/* Fournit le désignation associée à l'élément chargé. */ +static const char *g_loaded_binary_describe(const GLoadedBinary *, bool); + +/* Détermine le nombre de vues disponibles pour un contenu. */ +static unsigned int g_loaded_binary_count_views(const GLoadedBinary *); + +/* Met en place la vue demandée pour un contenu binaire. */ +static GtkWidget *g_loaded_binary_build_view(GLoadedBinary *, unsigned int); + +/* Retrouve l'indice correspondant à la vue donnée d'un contenu. */ +static unsigned int g_loaded_binary_get_view_index(GLoadedBinary *, GtkWidget *); + +/* Fournit toutes les options d'affichage pour un contenu. */ +bool * const g_loaded_binary_get_all_display_options(const GLoadedBinary *, unsigned int); + +/* Définit une option d'affichage pour un contenu chargé. */ +static bool g_loaded_binary_set_display_option(GLoadedBinary *, unsigned int, unsigned int, bool); + + /* ---------------------------------------------------------------------------------- */ /* ENCADREMENTS D'UN BINAIRE CHARGE */ @@ -152,7 +181,8 @@ static void _g_loaded_binary_analyse(GLoadedBinary *, disassembly_ack_fc); /* Indique le type défini pour une description de fichier binaire. */ -G_DEFINE_TYPE(GLoadedBinary, g_loaded_binary, G_TYPE_OBJECT); +G_DEFINE_TYPE_WITH_CODE(GLoadedBinary, g_loaded_binary, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(G_TYPE_LOADED_CONTENT, g_loaded_binary_interface_init)); /****************************************************************************** @@ -184,14 +214,6 @@ static void g_loaded_binary_class_init(GLoadedBinaryClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - g_signal_new("display-changed", - G_TYPE_LOADED_BINARY, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GLoadedBinaryClass, display_changed), - NULL, NULL, - g_cclosure_user_marshal_VOID__ENUM_ENUM, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); - } @@ -237,6 +259,32 @@ static void g_loaded_binary_init(GLoadedBinary *binary) /****************************************************************************** * * +* Paramètres : iface = interface GLib à initialiser. * +* * +* Description : Procède à l'initialisation de l'interface de contenu chargé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_loaded_binary_interface_init(GLoadedContentInterface *iface) +{ + iface->describe = (describe_loaded_fc)g_loaded_binary_describe; + + iface->count_views = (count_loaded_views_fc)g_loaded_binary_count_views; + iface->build_view = (build_loaded_view_fc)g_loaded_binary_build_view; + iface->get_view_index = (get_loaded_view_index_fc)g_loaded_binary_get_view_index; + + iface->get_all_options = (get_all_loaded_options_fc)g_loaded_binary_get_all_display_options; + iface->set_option = (set_loaded_option_fc)g_loaded_binary_set_display_option; + +} + + +/****************************************************************************** +* * * Paramètres : binary = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * @@ -499,6 +547,7 @@ GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const ch * xdoc = structure XML en cours d'édition. * * context = contexte à utiliser pour les recherches. * * path = chemin d'accès réservé au binaire. * +* base = référence au lieu d'enregistrement du projet. * * * * Description : Ecrit une sauvegarde du binaire dans un fichier XML. * * * @@ -508,13 +557,12 @@ GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const ch * * ******************************************************************************/ -bool g_loaded_binary_save(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path) +bool g_loaded_binary_save(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path, const char *base) { bool result; /* Bilan à faire remonter */ char *content_path; /* Partie "Contenus" */ char *access; /* Chemin d'accès à un élément */ GBinContent *content; /* Contenu à référencer */ - const gchar *hash; /* Empreinte à mémoriser */ size_t debugs_count; /* Quantité de formats liés */ size_t i; /* Boucle de parcours */ GDbgFormat *debug; /* Informations de débogage */ @@ -524,33 +572,28 @@ bool g_loaded_binary_save(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathC content_path = strdup(path); content_path = stradd(content_path, "/Contents"); - access = strdup(content_path); - access = stradd(access, "/Main"); + asprintf(&access, "%s/Main", content_path); content = g_binary_format_get_content(G_BIN_FORMAT(binary->format)); - hash = g_binary_content_get_checksum(content); + result = g_binary_content_save(content, xdoc, context, access, base); g_object_unref(G_OBJECT(content)); - result = add_content_to_node(xdoc, context, access, hash); - free(access); debugs_count = g_exe_format_count_debug_info(binary->format); - for (i = 0; i < debugs_count; i++) + for (i = 0; i < debugs_count && result; i++) { asprintf(&access, "%s/DebugInfo[position()=%zu]", content_path, i); debug = g_exe_format_get_debug_info(binary->format, i); content = g_binary_format_get_content(G_BIN_FORMAT(debug)); - hash = g_binary_content_get_checksum(content); + result = g_binary_content_save(content, xdoc, context, access, base); g_object_unref(G_OBJECT(content)); g_object_unref(G_OBJECT(debug)); - result &= add_content_to_node(xdoc, context, access, hash); - free(access); } @@ -1625,56 +1668,6 @@ GCodeBuffer *g_loaded_binary_get_decompiled_buffer(const GLoadedBinary *binary, /****************************************************************************** * * -* Paramètres : binary = élément binaire à mettre à jour. * -* view = type de représentation visée. * -* col = indice de colonne dont l'affichage est à modifier. * -* state = nouvel état de l'affichage. * -* * -* Description : Définit si une colonne donnée doit apparaître dans le rendu. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_loaded_binary_set_column_display(GLoadedBinary *binary, BinaryView view, BufferLineColumn col, bool state) -{ - bool old; /* Ancien état à remplacer */ - - old = binary->col_display[view][col]; - - if (state != old) - { - binary->col_display[view][col] = state; - g_signal_emit_by_name(binary, "display-changed", view, col); - } - -} - - -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à consulter. * -* view = type de représentation visée. * -* * -* Description : Indique quelles colonnes doivent apparaître dans le rendu. * -* * -* Retour : Consigne d'affichage. [OUT] * -* * -* Remarques : - * -* * -******************************************************************************/ - -const bool *g_loaded_binary_get_column_display(GLoadedBinary *binary, BinaryView view) -{ - return binary->col_display[view]; - -} - - -/****************************************************************************** -* * * Paramètres : binary = élément binaire à consulter. * * * * Description : Indique si les lignes doivent apparaître dans le rendu. * @@ -1760,3 +1753,193 @@ void ack_completed_disassembly(GDelayedDisassembly *disass, GLoadedBinary *binar g_signal_emit_by_name(binary, "disassembly-done"); } + + + +/* ---------------------------------------------------------------------------------- */ +/* GESTION SOUS FORME DE CONTENU CHARGE */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : binary = élément chargé à consulter. * +* long = précise s'il s'agit d'une version longue ou non. * +* * +* Description : Fournit le désignation associée à l'élément chargé. * +* * +* Retour : Description courante. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static const char *g_loaded_binary_describe(const GLoadedBinary *binary, bool full) +{ + const char *result; /* Description à retourner */ + GBinContent *content; /* Contenu binaire mannipulé */ + + content = g_binary_format_get_content(G_BIN_FORMAT(binary->format)); + + result = g_binary_content_describe(content, full); + + g_object_unref(G_OBJECT(content)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : binary = contenu chargé à consulter. * +* * +* Description : Détermine le nombre de vues disponibles pour un contenu. * +* * +* Retour : Quantité strictement positive. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static unsigned int g_loaded_binary_count_views(const GLoadedBinary *binary) +{ + return BVW_COUNT; + +} + + +/****************************************************************************** +* * +* Paramètres : binary = contenu chargé à consulter. * +* index = indice de la vue ciblée. * +* * +* Description : Met en place la vue demandée pour un contenu binaire. * +* * +* Retour : Composant graphique nouveau. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GtkWidget *g_loaded_binary_build_view(GLoadedBinary *binary, unsigned int index) +{ + GtkWidget *result; /* Support à retourner */ + GtkWidget *display; /* Composant d'affichage */ + + assert(index < g_loaded_binary_count_views(binary)); + + switch (index) + { + case BVW_BLOCK: + display = gtk_block_display_new(); + break; + + case BVW_GRAPH: + display = gtk_graph_display_new(); + break; + + default: + assert(false); + break; + } + + gtk_widget_show(display); + + g_loaded_panel_set_content(G_LOADED_PANEL(display), G_LOADED_CONTENT(binary)); + + result = qck_create_scrolled_window(NULL, NULL); + gtk_container_add(GTK_CONTAINER(result), display); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : binary = contenu chargé à consulter. * +* index = composant graphique en place. * +* * +* Description : Retrouve l'indice correspondant à la vue donnée d'un contenu.* +* * +* Retour : Indice de la vue représentée, ou -1 en cas d'erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static unsigned int g_loaded_binary_get_view_index(GLoadedBinary *binary, GtkWidget *view) +{ + unsigned int result; /* Indice à retourner */ + + if (GTK_IS_BLOCK_DISPLAY(view)) + result = BVW_BLOCK; + + else if (GTK_IS_GRAPH_DISPLAY(view)) + result = BVW_GRAPH; + + else + { + assert(false); + result = -1; + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : binary = contenu chargé à consulter. * +* index = composant graphique à cibler. * +* * +* Description : Fournit toutes les options d'affichage pour un contenu. * +* * +* Retour : Tableau de paramètres en accès libre. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool * const g_loaded_binary_get_all_display_options(const GLoadedBinary *binary, unsigned int index) +{ + return binary->col_display[index]; + +} + + +/****************************************************************************** +* * +* Paramètres : binary = contenu chargé à consulter. * +* index = composant graphique à cibler. * +* option = type de paramètre à manipuler. * +* state = valeur dudit paramètre. * +* * +* Description : Définit une option d'affichage pour un contenu chargé. * +* * +* Retour : true si un changement a été effectué, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_loaded_binary_set_display_option(GLoadedBinary *binary, unsigned int index, unsigned int option, bool state) +{ + bool result; /* Variation à faire remonter */ + bool old; /* Ancien état à remplacer */ + + old = binary->col_display[index][option]; + + if (state != old) + { + binary->col_display[index][option] = state; + result = true; + } + + else result = false; + + return result; + +} |