From bbd04bf5f23e7dca1917247cb92824805b22a2a4 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 3 Mar 2009 01:03:15 +0000 Subject: Created a system messages panel. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@50 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 32 ++++++- configure.ac | 3 +- src/Makefile.am | 3 +- src/editor.c | 5 ++ src/format/Makefile.am | 2 +- src/format/exe_format.c | 6 +- src/format/java/Makefile.am | 2 +- src/format/java/attribute.c | 11 ++- src/pan_strings.c | 2 +- src/pan_symbols.c | 2 +- src/panel/Makefile.am | 17 ++++ src/panel/log.c | 208 ++++++++++++++++++++++++++++++++++++++++++++ src/panel/log.h | 55 ++++++++++++ src/panel/panels.c | 71 +++++++++++++++ src/panel/panels.h | 51 +++++++++++ 15 files changed, 458 insertions(+), 12 deletions(-) create mode 100755 src/panel/Makefile.am create mode 100644 src/panel/log.c create mode 100644 src/panel/log.h create mode 100644 src/panel/panels.c create mode 100644 src/panel/panels.h diff --git a/ChangeLog b/ChangeLog index 698079e..6342c1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,35 @@ +2009-03-03 Cyrille Bagard + + * configure.ac: + Add the new Makefile from 'src/panel' directory to AC_CONFIG_FILES. + + * src/editor.c: + Load all registered panels and display them. + + * src/format/exe_format.c: + * src/format/java/attribute.c: + * src/format/java/Makefile.am: + * src/format/Makefile.am: + Use the new panel to log system messages. + + * src/Makefile.am: + Add panel to SUBDIRS and panel/libpanel.a to openida_LDADD. + + * src/panel/log.c: + * src/panel/log.h: + * src/panel/Makefile.am: + * src/panel/panels.c: + * src/panel/panels.h: + New entries: create a system messages panel and register it. + + * src/pan_strings.c: + * src/pan_symbols.c: + Typo. + 2009-02-18 Cyrille Bagard * configure.ac: - Add the new Makefile from 'src/analysis' directories to AC_CONFIG_FILES. + Add the new Makefile from 'src/analysis' directory to AC_CONFIG_FILES. * src/analysis/line.c: * src/analysis/line.h: @@ -85,7 +113,7 @@ 2009-01-29 Cyrille Bagard * configure.ac: - Add the new Makefile from 'src/format/pe/' directories to AC_CONFIG_FILES. + Add the new Makefile from 'src/format/pe/' directory to AC_CONFIG_FILES. * src/binary.c: Update code. diff --git a/configure.ac b/configure.ac index 4bda689..86334a5 100644 --- a/configure.ac +++ b/configure.ac @@ -191,7 +191,8 @@ AC_CONFIG_FILES([Makefile src/format/elf/Makefile src/format/java/Makefile src/format/pe/Makefile - src/gtkext/Makefile]) + src/gtkext/Makefile + src/panel/Makefile]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index e2519a9..948cc32 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,7 +36,8 @@ openida_LDADD = $(LIBINTL) \ format/java/libformatjava.a \ format/pe/libformatpe.a \ gtkext/libgtkext.a \ + panel/libpanel.a \ common/libcommon.a -SUBDIRS = analysis arch common format gtkext +SUBDIRS = analysis arch common format gtkext panel diff --git a/src/editor.c b/src/editor.c index e59a9a5..e6d7516 100644 --- a/src/editor.c +++ b/src/editor.c @@ -57,6 +57,7 @@ #include "pan_strings.h" #include "pan_symbols.h" #include "gtkext/gtkdockpanel.h" +#include "panel/panels.h" #define _(str) str @@ -592,6 +593,7 @@ GtkWidget *create_editor(void) gtk_paned_set_position (GTK_PANED (hpaned1), 600); + init_panels(); dpanel = gtk_dock_panel_new(); @@ -849,6 +851,9 @@ GtkWidget *create_editor(void) gtk_paned_pack2(GTK_PANED(vpaned1), dpanel, FALSE, FALSE); + ditem = gtk_dock_item_new(_("Messages"), get_panel(PNT_LOG)); + gtk_dock_panel_add_item(dpanel, ditem); + panel = build_strings_panel(G_OBJECT(result)); ditem = gtk_dock_item_new(_("Strings"), panel); diff --git a/src/format/Makefile.am b/src/format/Makefile.am index 67b3737..7c2c524 100644 --- a/src/format/Makefile.am +++ b/src/format/Makefile.am @@ -10,7 +10,7 @@ libformat_a_SOURCES = \ libformat_a_CFLAGS = $(AM_CFLAGS) -INCLUDES = +INCLUDES = $(LIBGTK_CFLAGS) AM_CPPFLAGS = diff --git a/src/format/exe_format.c b/src/format/exe_format.c index 1077cfe..8a03243 100644 --- a/src/format/exe_format.c +++ b/src/format/exe_format.c @@ -29,9 +29,13 @@ #include "exe_format-int.h" +#include "../panel/log.h" +#define _(str) str + + /* ------------------------ DETECTION DE FORMATS EXECUTABLES ------------------------ */ @@ -239,7 +243,7 @@ exe_format *load_new_exe_format(const uint8_t *content, off_t length) for (i = 0; i < exe_formats_count && result == NULL; i++) if (exe_formats[i].match(content, length)) { - printf(" %s is matching...\n", exe_formats[i].name); + log_variadic_message(LMT_INFO, _("%s is matching..."), exe_formats[i].name); result = exe_formats[i].load(content, length); diff --git a/src/format/java/Makefile.am b/src/format/java/Makefile.am index e3a88b2..2cb2326 100755 --- a/src/format/java/Makefile.am +++ b/src/format/java/Makefile.am @@ -12,7 +12,7 @@ libformatjava_a_SOURCES = \ libformatjava_a_CFLAGS = $(AM_CFLAGS) -INCLUDES = +INCLUDES = $(LIBGTK_CFLAGS) AM_CPPFLAGS = diff --git a/src/format/java/attribute.c b/src/format/java/attribute.c index f5947dd..0cfed92 100644 --- a/src/format/java/attribute.c +++ b/src/format/java/attribute.c @@ -31,6 +31,11 @@ #include "java-int.h" #include "pool.h" #include "../../common/endianness.h" +#include "../../panel/log.h" + + + +#define _(str) str @@ -231,12 +236,12 @@ bool load_java_attribute(java_format *format, java_attribute *attrib, off_t *pos else if (result) { result = false; - printf(" Nom d'attribut non supporté : '%s'\n", name); + log_variadic_message(LMT_BAD_BINARY, _("Attribute name not supported: '%s'"), name); } if (result && attrib_length != (*pos - saved_pos)) - printf(" indication de la taille de l'attribut '%s' non vérifiée : %d vs %d\n", - name, attrib_length, *pos - saved_pos); + log_variadic_message(LMT_BAD_BINARY, _("Size indication of the attribute '%s' not verified: %d vs %d"), + name, attrib_length, *pos - saved_pos); } diff --git a/src/pan_strings.c b/src/pan_strings.c index 0b5a951..984d0d2 100644 --- a/src/pan_strings.c +++ b/src/pan_strings.c @@ -53,7 +53,7 @@ typedef enum _StringsColumn GtkWidget *build_strings_panel(GObject *ref) { - GtkWidget *result; /* Pnneau à retourner */ + GtkWidget *result; /* Panneau à retourner */ GtkTreeStore *store; /* Modèle de gestion */ GtkWidget *treeview; /* Affichage de la liste */ GtkCellRenderer *renderer; /* Moteur de rendu de colonne */ diff --git a/src/pan_symbols.c b/src/pan_symbols.c index adc8056..a78bc44 100644 --- a/src/pan_symbols.c +++ b/src/pan_symbols.c @@ -64,7 +64,7 @@ void change_symbols_selection(GtkTreeSelection *, gpointer); GtkWidget *build_symbols_panel(GObject *ref) { - GtkWidget *result; /* Pnneau à retourner */ + GtkWidget *result; /* Panneau à retourner */ GtkTreeStore *store; /* Modèle de gestion */ GtkWidget *treeview; /* Affichage de la liste */ GtkCellRenderer *renderer; /* Moteur de rendu de colonne */ diff --git a/src/panel/Makefile.am b/src/panel/Makefile.am new file mode 100755 index 0000000..cf70076 --- /dev/null +++ b/src/panel/Makefile.am @@ -0,0 +1,17 @@ + +lib_LIBRARIES = libpanel.a + +libpanel_a_SOURCES = \ + log.h log.c \ + panels.h panels.c + +libpanel_a_CFLAGS = $(AM_CFLAGS) + + +INCLUDES = $(LIBGTK_CFLAGS) + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) + +SUBDIRS = diff --git a/src/panel/log.c b/src/panel/log.c new file mode 100644 index 0000000..f98953f --- /dev/null +++ b/src/panel/log.c @@ -0,0 +1,208 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * log.c - panneau d'affichage des messages système + * + * Copyright (C) 2006-2007 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "log.h" + + +#include +#include +#include + + +#include "panels.h" + + + +/* Colonnes de la liste des messages */ +typedef enum _LogColumn +{ + LGC_PICTURE, /* Image de représentation */ + LGC_STRING, /* Chaîne de caractères */ + + LGC_COUNT /* Nombre de colonnes */ + +} LogColumn; + + +#define _(str) str + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Construit le panneau d'affichage des messages système. * +* * +* Retour : Adresse du panneau mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *build_log_panel(void) +{ + GtkWidget *result; /* Panneau à retourner */ + GtkTreeStore *store; /* Modèle de gestion */ + GtkWidget *treeview; /* Affichage de la liste */ + GtkCellRenderer *renderer; /* Moteur de rendu de colonne */ + GtkTreeViewColumn *column; /* Colonne de la liste */ + GtkTreeSelection *select; /* Sélection dans la liste */ + + result = gtk_scrolled_window_new(NULL, NULL); + gtk_widget_show(result); + + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(result), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(result), GTK_SHADOW_IN); + + store = gtk_tree_store_new(LGC_COUNT, G_TYPE_STRING, G_TYPE_STRING); + g_object_set_data(G_OBJECT(result), "store", store); + + treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); + gtk_widget_show(treeview); + gtk_container_add(GTK_CONTAINER(result), treeview); + + g_object_unref(G_OBJECT(store)); + + column = gtk_tree_view_column_new(); + gtk_tree_view_column_set_visible(column, FALSE); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + gtk_tree_view_set_expander_column(GTK_TREE_VIEW(treeview), column); + + column = gtk_tree_view_column_new(); + + renderer = gtk_cell_renderer_pixbuf_new(); + gtk_tree_view_column_pack_start(column, renderer, FALSE); + gtk_tree_view_column_add_attribute(column, renderer, "stock-id", LGC_PICTURE); + + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_column_pack_start(column, renderer, TRUE); + gtk_tree_view_column_add_attribute(column, renderer, "text", LGC_STRING); + + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : panel = panneau à mettre à jour. * +* msg = message à faire apparaître à l'écran. * +* * +* Description : Affiche un message dans le journal des messages système. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void log_simple_message(LogMessageType type, const char *msg) +{ + GtkWidget *panel; /* Panneau à traiter */ + GtkTreeStore *store; /* Modèle de gestion */ + GtkTreeIter iter; /* Point d'insertion */ + + panel = get_panel(PNT_LOG); + store = g_object_get_data(G_OBJECT(panel), "store"); + + gtk_tree_store_append(store, &iter, NULL); + + switch (type) + { + case LMT_INFO: + gtk_tree_store_set(store, &iter, + LGC_PICTURE, "gtk-info", + LGC_STRING, msg, + -1); + break; + + case LMT_BAD_BINARY: + gtk_tree_store_set(store, &iter, + LGC_PICTURE, "gtk-dialog-warning", + LGC_STRING, msg, + -1); + break; + + } + +} + + +/****************************************************************************** +* * +* Paramètres : panel = panneau à mettre à jour. * +* fmt = format du message à faire apparaître à l'écran. * +* ... = éventuels arguments venant compléter le message. * +* * +* Description : Affiche un message dans le journal des messages système. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void log_variadic_message(LogMessageType type, const char *fmt, ...) +{ + size_t len; /* Taille tampon disponible */ + char *buffer; /* Tampon du msg reconstitué */ + int ret; /* Bilan d'une impression */ + char *ptr; /* Nouvelle allocation */ + va_list ap; /* Liste d'arguments variable */ + + len = 100; + buffer = calloc(len, sizeof(char)); + + while (buffer != NULL) + { + va_start(ap, fmt); + ret = vsnprintf(buffer, len, fmt, ap); + va_end(ap); + + if (ret >= 0 && ret < len) break; + + else + { + if (ret > -1) len += 1; /* glibc 2.1 */ + else len *= 2; /* glibc 2.0 */ + + if ((ptr = realloc(buffer, len)) == NULL) + { + free(buffer); + buffer = NULL; + } + else buffer = ptr; + + } + + } + + log_simple_message(type, buffer); + + free(buffer); + +} diff --git a/src/panel/log.h b/src/panel/log.h new file mode 100644 index 0000000..91e2c83 --- /dev/null +++ b/src/panel/log.h @@ -0,0 +1,55 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * log.h - prototypes pour le panneau d'affichage des messages système + * + * Copyright (C) 2006-2007 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PANEL_LOG_H +#define _PANEL_LOG_H + + +#include + + + +/* Type de messages disponibles */ +typedef enum _LogMessageType +{ + LMT_INFO, /* Information sur l'exécution */ + LMT_BAD_BINARY, /* Binaire malformé */ + + LMT_COUNT + +} LogMessageType; + + +/* Construit le panneau d'affichage des messages système. */ +GtkWidget *build_log_panel(void); + +/* Affiche un message dans le journal des messages système. */ +void log_simple_message(LogMessageType, const char *); + +/* Affiche un message dans le journal des messages système. */ +void log_variadic_message(LogMessageType, const char *, ...); + + + +#endif /* _PANEL_LOG_H */ diff --git a/src/panel/panels.c b/src/panel/panels.c new file mode 100644 index 0000000..a127825 --- /dev/null +++ b/src/panel/panels.c @@ -0,0 +1,71 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * panels.h - gestion des différents panneaux + * + * Copyright (C) 2006-2007 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "panels.h" + + +#include "log.h" + + + +static GtkWidget *panel_list[PNT_COUNT]; + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Procède au chargement de tous les panneaux. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void init_panels(void) +{ + panel_list[PNT_LOG] = build_log_panel(); + +} + + +/****************************************************************************** +* * +* Paramètres : id = identifiant du panneau visé. * +* * +* Description : Fournit la référence d'un panneau donné. * +* * +* Retour : Adresse du composant GTK en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *get_panel(PanelType id) +{ + return panel_list[id]; + +} diff --git a/src/panel/panels.h b/src/panel/panels.h new file mode 100644 index 0000000..87ddfa6 --- /dev/null +++ b/src/panel/panels.h @@ -0,0 +1,51 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * panels.h - prototypes pour la gestion des différents panneaux + * + * Copyright (C) 2006-2007 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _PANEL_PANELS_H +#define _PANEL_PANELS_H + + +#include + + + +/* Liste de tous les panneaux */ +typedef enum _PanelType +{ + PNT_LOG, /* Messages système */ + + PNT_COUNT + +} PanelType; + + +/* Procède au chargement de tous les panneaux. */ +void init_panels(void); + +/* Fournit la référence d'un panneau donné. */ +GtkWidget *get_panel(PanelType); + + + +#endif /* _PANEL_PANELS_H */ -- cgit v0.11.2-87-g4458