diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/debug/debugger-int.h | 5 | ||||
-rw-r--r-- | src/debug/debugger.c | 24 | ||||
-rw-r--r-- | src/debug/debugger.h | 3 | ||||
-rw-r--r-- | src/debug/jdwp/debugger.c | 99 | ||||
-rw-r--r-- | src/debug/jdwp/tcp.c | 14 | ||||
-rw-r--r-- | src/editor.c | 4 | ||||
-rw-r--r-- | src/gui/menus/Makefile.am | 1 | ||||
-rw-r--r-- | src/gui/menus/debug.c | 128 | ||||
-rw-r--r-- | src/gui/menus/debug.h | 38 | ||||
-rw-r--r-- | src/gui/menus/help.c | 5 | ||||
-rw-r--r-- | src/gui/menus/help.h | 2 | ||||
-rw-r--r-- | src/gui/menus/menubar.c | 16 | ||||
-rw-r--r-- | src/gui/menus/menubar.h | 2 | ||||
-rw-r--r-- | src/project.c | 36 | ||||
-rw-r--r-- | src/project.h | 7 | ||||
-rw-r--r-- | src/shell.c | 2 |
16 files changed, 324 insertions, 62 deletions
diff --git a/src/debug/debugger-int.h b/src/debug/debugger-int.h index 642efd7..f27667c 100644 --- a/src/debug/debugger-int.h +++ b/src/debug/debugger-int.h @@ -32,6 +32,9 @@ +/* Procède au démarrage effectif de la session de débogage. */ +typedef bool (* attach_debugger_fc) (GBinaryDebugger *); + /* Démarre, met en pause ou tue une procédure de débogage. */ typedef bool (* basic_debugger_fc) (GBinaryDebugger *); @@ -49,6 +52,8 @@ struct _GBinaryDebugger GOpenidaBinary *binary; /* Cible à traiter */ + attach_debugger_fc attach; /* Démarre le débogueur */ + basic_debugger_fc run; /* Démarre le débogueur */ basic_debugger_fc pause; /* Met en pause le débogueur */ resume_debugger_fc resume; /* Relance le débogueur */ diff --git a/src/debug/debugger.c b/src/debug/debugger.c index 7f66a0b..4f5eb19 100644 --- a/src/debug/debugger.c +++ b/src/debug/debugger.c @@ -136,6 +136,30 @@ GBinaryDebugger *g_new_binary_debugger(DebuggerType type, GOpenidaBinary *binary * * * Description : Démarre une procédure de débogage. * * * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_binary_debugger_attach(GBinaryDebugger *debugger) +{ + bool result; /* Bilan à retourner */ + + if (debugger->attach == NULL) result = true; + else result = debugger->attach(debugger); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : debugger = débogueur à manipuler ici. * +* * +* Description : Démarre une procédure de débogage. * +* * * Retour : - * * * * Remarques : - * diff --git a/src/debug/debugger.h b/src/debug/debugger.h index 521d346..e3b90f4 100644 --- a/src/debug/debugger.h +++ b/src/debug/debugger.h @@ -76,6 +76,9 @@ GType g_binary_debugger_get_type(void); GBinaryDebugger *g_new_binary_debugger(DebuggerType, GOpenidaBinary *); /* Démarre une procédure de débogage. */ +bool g_binary_debugger_attach(GBinaryDebugger *); + +/* Démarre une procédure de débogage. */ void g_binary_debugger_run(GBinaryDebugger *); /* Reprend une procédure de débogage. */ diff --git a/src/debug/jdwp/debugger.c b/src/debug/jdwp/debugger.c index a99c6d0..829d31c 100644 --- a/src/debug/jdwp/debugger.c +++ b/src/debug/jdwp/debugger.c @@ -24,12 +24,14 @@ #include "debugger.h" -#include "packet.h" -#include "tcp.h" +#include <i18n.h> +#include "packet.h" +#include "tcp.h" #include "../debugger-int.h" #include "../stream.h" +#include "../../panels/log.h" @@ -61,6 +63,8 @@ static void g_java_debugger_class_init(GJavaDebuggerClass *); /* Procède à l'initialisation du débogueur utilisant Java. */ static void g_java_debugger_init(GJavaDebugger *); +/* Procède au démarrage effectif de la session de débogage. */ +static bool g_java_debugger_attach(GJavaDebugger *); /* Indique le type défini par la GLib pour le débogueur java. */ @@ -103,6 +107,9 @@ static void g_java_debugger_init(GJavaDebugger *debugger) GBinaryDebugger *parent; /* Instance parente */ parent = G_BINARY_DEBUGGER(debugger); + + parent->attach = (attach_debugger_fc)g_java_debugger_attach; + #if 0 parent->run = (basic_debugger_fc)g_java_debugger_run; parent->resume = (resume_debugger_fc)g_java_debugger_resume; @@ -118,7 +125,7 @@ static void g_java_debugger_init(GJavaDebugger *debugger) * Paramètres : binary = binaire représenter à déboguer. * * options = paramètres destinés au débogage. * * * -* Description : Crée un débogueur utilisant un serveur JAVA distant. * +* Description : Crée un débogueur utilisant un serveur Java distant. * * * * Retour : Instance de débogueur mise en place ou NULL. * * * @@ -140,65 +147,67 @@ GBinaryDebugger *g_java_debugger_new(GOpenidaBinary *binary, void *options) } +/****************************************************************************** +* * +* Paramètres : debugger = instance du module de débogage chargé. * +* * +* Description : Procède au démarrage effectif de la session de débogage. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ - - - - -void test_java(void) +static bool g_java_debugger_attach(GJavaDebugger *debugger) { - GBinaryDebugger *debugger; - GDebugPacket *packet; - GDebugPacket *packet2; - jdwp_payload *payload; - - printf("JDWP-start !!!!\n"); - - printf("size == %d\n", sizeof(jdwp_header)); - - - debugger = g_java_debugger_new(NULL, NULL); - + bool result; /* Bilan à retourner */ + GDebugPacket *req; /* Requête à formuler */ + GDebugPacket *ret; /* Obtention de la réponse */ + jdwp_payload *payload; /* Charge utile d'une réponse */ - g_debug_stream_connect(G_JAVA_DEBUGGER(debugger)->stream); + req = NULL; + ret = NULL; + /* Connexion physique */ - packet = g_debug_stream_get_free_packet(G_JAVA_DEBUGGER(debugger)->stream); + result = g_debug_stream_connect(debugger->stream); + if (!result) goto gjda_error; + /* Demande de version */ - g_jdwp_packet_set_request_header(G_JDWP_PACKET(packet), JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION); + req = g_debug_stream_get_free_packet(debugger->stream); - if (!g_debug_stream_send_packet(G_JAVA_DEBUGGER(debugger)->stream, packet)) - printf("erreur envoi\n"); + g_jdwp_packet_set_request_header(G_JDWP_PACKET(req), + JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION); - packet2 = g_debug_stream_recv_packet(G_JAVA_DEBUGGER(debugger)->stream, (filter_packet_fc)g_jdwp_packet_is_reply, packet); + if (!g_debug_stream_send_packet(debugger->stream, req)) + goto gjda_error; - if (!packet2) - printf("erreur réception\n"); + ret = g_debug_stream_recv_packet(debugger->stream, + (filter_packet_fc)g_jdwp_packet_is_reply, req); + if (!ret) goto gjda_error; - if (!g_jdwp_packet_parse_payload(G_JDWP_PACKET(packet2), JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION)) - printf("erreur de décodage\n"); + if (!g_jdwp_packet_parse_payload(G_JDWP_PACKET(ret), JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION)) + goto gjda_error; - payload = g_jdwp_packet_get_payload(G_JDWP_PACKET(packet2)); + payload = g_jdwp_packet_get_payload(G_JDWP_PACKET(ret)); + log_variadic_message(LMT_INFO, _("The debugger is '%s' (JRE %d.%d; VM %s)."), + payload->vs_reply.description.value, + payload->vs_reply.jdwp_major, payload->vs_reply.jdwp_minor, + payload->vs_reply.vm_version.value); + g_jdwp_packet_free_payload(G_JDWP_PACKET(ret), JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION); - printf("-----------\n"); + gjda_error: - printf("desc :: '%s'\n", payload->vs_reply.description.value); + if (req != NULL) + g_debug_stream_mark_packet_as_free(debugger->stream, req); - printf("version :: %d.%d\n", payload->vs_reply.jdwp_major, payload->vs_reply.jdwp_minor); + if (ret != NULL) + g_debug_stream_mark_packet_as_free(debugger->stream, ret); - printf("version :: '%s'\n", payload->vs_reply.vm_version.value); - printf("name :: '%s'\n", payload->vs_reply.vm_name.value); - - printf("-----------\n"); - - - - g_jdwp_packet_free_payload(G_JDWP_PACKET(packet2), JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION); - - - printf("JDWP-end !!!!\n"); + return result; } diff --git a/src/debug/jdwp/tcp.c b/src/debug/jdwp/tcp.c index 38acd29..d4ec1d7 100644 --- a/src/debug/jdwp/tcp.c +++ b/src/debug/jdwp/tcp.c @@ -32,11 +32,15 @@ #include <sys/types.h> +#include <i18n.h> + + #include "packet.h" #include "misc/header.h" #include "sets/list.h" #include "../stream-int.h" #include "../../common/net.h" +#include "../../panels/log.h" @@ -180,12 +184,14 @@ static bool g_jdwp_tcp_client_connect(GJdwpTcpClient *client) sock = connect_via_tcp(client->server, client->port, &addr); if (sock == -1) { - printf("Echec de connexion au serveur JDWP sur %s:%s\n", - client->server, client->port); + log_variadic_message(LMT_ERROR, _("Error while connecting to the JDWP server at %s:%s."), + //printf("Echec de connexion au serveur JDWP sur %s:%s\n", + client->server, client->port); return false; } - printf("Connecté à %s:%hd\n", client->server, ntohs(addr.sin_port)); + log_variadic_message(LMT_PROCESS, _("Connected to %s:%hd."), + client->server, ntohs(addr.sin_port)); if (send(sock, "JDWP-Handshake", 14, 0) != 14) goto gjtcc_error; @@ -202,7 +208,7 @@ static bool g_jdwp_tcp_client_connect(GJdwpTcpClient *client) gjtcc_error: - printf("Echec des premiers échanges !\n"); + log_simple_message(LMT_ERROR, _("Failure in the first JDWP handshake.")); close(sock); diff --git a/src/editor.c b/src/editor.c index 78d890e..4211b73 100644 --- a/src/editor.c +++ b/src/editor.c @@ -269,7 +269,7 @@ GtkWidget *create_editor(void) /* Intégration des menus */ - editem = g_menu_bar_new(ref); + editem = g_menu_bar_new(ref, accgroup); menuboard = g_editor_item_get_widget(editem); gtk_box_pack_start(GTK_BOX(vbox1), menuboard, FALSE, FALSE, 0); @@ -891,7 +891,7 @@ void mcb_view_change_support(GtkRadioMenuItem *menuitem, GObject *ref) GSList *iter; /* Boucle de parcours */ BinaryView view; /* Nouvelle vue à présenter */ GOpenidaBinary *binary; /* Edition courante */ - GtkViewPanel *pview; /* Afficheur effectif de code */ + GtkViewPanel *pview; /* Afficheur effectif de code */ GtkWidget *panel; /* Nouveau support à utiliser */ GDockItem *ditem; /* Panneau avec ses infos. */ diff --git a/src/gui/menus/Makefile.am b/src/gui/menus/Makefile.am index b9e127d..36fffc2 100644 --- a/src/gui/menus/Makefile.am +++ b/src/gui/menus/Makefile.am @@ -2,6 +2,7 @@ noinst_LTLIBRARIES = libguimenus.la libguimenus_la_SOURCES = \ + debug.h debug.c \ help.h help.c \ menubar.h menubar.c diff --git a/src/gui/menus/debug.c b/src/gui/menus/debug.c new file mode 100644 index 0000000..366d789 --- /dev/null +++ b/src/gui/menus/debug.c @@ -0,0 +1,128 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * debug.c - gestion du menu 'Débogage' + * + * Copyright (C) 2011 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 "debug.h" + + +#include <string.h> + + +#include <i18n.h> + + +#include "../../project.h" +#include "../../gtkext/easygtk.h" +#include "../../panels/log.h" + + + +/* Réagit avec le menu "Débogage -> Démarrer/Arrêter". */ +static void mcb_debug_start_stop(GtkMenuItem *, GObject *); + + + +/****************************************************************************** +* * +* Paramètres : ref = espace de référencement global. * +* accgroup = groupe d'accélérateurs pour les menus. * +* * +* Description : Construit le menu "Aide". * +* * +* Retour : Panneau de menus mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *build_menu_debug(GObject *ref, GtkAccelGroup *accgroup) +{ + GtkWidget *result; /* Support à retourner */ + GtkWidget *menubar; /* Support pour éléments */ + GtkWidget *submenuitem; /* Sous-élément de menu */ + + result = gtk_menu_item_new_with_mnemonic(_("_Debug")); + gtk_widget_show(result); + + menubar = gtk_menu_new(); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(result), menubar); + + submenuitem = qck_create_menu_item(ref, "mnu_start_stop", _("Start"), G_CALLBACK(mcb_debug_start_stop), ref); + add_accelerator_to_menu_item(submenuitem, "F9", accgroup); + gtk_container_add(GTK_CONTAINER(menubar), submenuitem); + + submenuitem = qck_create_menu_separator(); + gtk_container_add(GTK_CONTAINER(menubar), submenuitem); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : menuitem = élément de menu sélectionné. * +* ref = adresse de l'espace de référencement global. * +* * +* Description : Réagit avec le menu "Débogage -> Démarrer/Arrêter". * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void mcb_debug_start_stop(GtkMenuItem *menuitem, GObject *ref) +{ + GOpenidaBinary *binary; /* Edition courante */ + GBinaryDebugger *debugger; /* Module prêt à emploi */ + + binary = (GOpenidaBinary *)g_object_get_data(ref, "current_binary"); + debugger = get_main_debugger_for_binary(get_current_openida_project(), binary); + + if (debugger == NULL) + { + log_simple_message(LMT_ERROR, _("No available debug module for this binary !")); + return; + } + + if (strcmp(gtk_menu_item_get_label(menuitem), _("Start")) == 0) + { + if (!g_binary_debugger_attach(debugger)) + { + log_simple_message(LMT_ERROR, _("Failed to initialize the debugger.")); + return; + } + + gtk_menu_item_set_label(menuitem, _("Stop")); + + } + else + { + /* TODO */ + + gtk_menu_item_set_label(menuitem, _("Start")); + + } + +} diff --git a/src/gui/menus/debug.h b/src/gui/menus/debug.h new file mode 100644 index 0000000..7b08f60 --- /dev/null +++ b/src/gui/menus/debug.h @@ -0,0 +1,38 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * debug.h - prototypes pour la gestion du menu 'Débogage' + * + * Copyright (C) 2011 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 _GUI_MENUS_DEBUG_H +#define _GUI_MENUS_DEBUG_H + + +#include <gtk/gtk.h> + + + +/* Construit le menu "Aide". */ +GtkWidget *build_menu_debug(GObject *, GtkAccelGroup *); + + + +#endif /* _GUI_MENUS_DEBUG_H */ diff --git a/src/gui/menus/help.c b/src/gui/menus/help.c index b1fb545..eb17301 100644 --- a/src/gui/menus/help.c +++ b/src/gui/menus/help.c @@ -40,7 +40,8 @@ static void mcb_help_about(GtkMenuItem *, GObject *); /****************************************************************************** * * -* Paramètres : ref = espace de référencement global. * +* Paramètres : ref = espace de référencement global. * +* accgroup = groupe d'accélérateurs pour les menus. * * * * Description : Construit le menu "Aide". * * * @@ -50,7 +51,7 @@ static void mcb_help_about(GtkMenuItem *, GObject *); * * ******************************************************************************/ -GtkWidget *build_menu_help(GObject *ref) +GtkWidget *build_menu_help(GObject *ref, GtkAccelGroup *accgroup) { GtkWidget *result; /* Support à retourner */ GtkWidget *menubar; /* Support pour éléments */ diff --git a/src/gui/menus/help.h b/src/gui/menus/help.h index 0c2d345..675a9e7 100644 --- a/src/gui/menus/help.h +++ b/src/gui/menus/help.h @@ -31,7 +31,7 @@ /* Construit le menu "Aide". */ -GtkWidget *build_menu_help(GObject *); +GtkWidget *build_menu_help(GObject *, GtkAccelGroup *); diff --git a/src/gui/menus/menubar.c b/src/gui/menus/menubar.c index af27888..4718caa 100644 --- a/src/gui/menus/menubar.c +++ b/src/gui/menus/menubar.c @@ -25,6 +25,7 @@ #include "menubar.h" +#include "debug.h" #include "help.h" #include "../editem-int.h" @@ -104,10 +105,8 @@ static void g_menu_bar_init(GMenuBar *bar) /****************************************************************************** * * -* Paramètres : ref = espace de référencement global. * -* name = nom associé à l'élément. * -* widget = composant à présenter à l'affichage. * -* label = étiquette destinée au menu. * +* Paramètres : ref = espace de référencement global. * +* accgroup = groupe d'accélérateurs pour les menus. * * * * Description : Compose la barre de menus principale. * * * @@ -117,7 +116,7 @@ static void g_menu_bar_init(GMenuBar *bar) * * ******************************************************************************/ -GEditorItem *g_menu_bar_new(GObject *ref) +GEditorItem *g_menu_bar_new(GObject *ref, GtkAccelGroup *accgroup) { GMenuBar *result; /* Structure à retourner */ GEditorItem *item; /* Autre version de l'élément */ @@ -132,9 +131,14 @@ GEditorItem *g_menu_bar_new(GObject *ref) g_object_ref(ref); item->ref = ref; + /* Débogage */ + + menuitem = build_menu_debug(ref, accgroup); + gtk_container_add(GTK_CONTAINER(item->widget), menuitem); + /* Aide */ - menuitem = build_menu_help(ref); + menuitem = build_menu_help(ref, accgroup); gtk_container_add(GTK_CONTAINER(item->widget), menuitem); return G_EDITOR_ITEM(result); diff --git a/src/gui/menus/menubar.h b/src/gui/menus/menubar.h index e7dcf6d..ffb4c87 100644 --- a/src/gui/menus/menubar.h +++ b/src/gui/menus/menubar.h @@ -49,7 +49,7 @@ typedef struct _GMenuBarClass GMenuBarClass; GType g_menu_bar_get_type(void); /* Compose la barre de menus principale. */ -GEditorItem *g_menu_bar_new(GObject *); +GEditorItem *g_menu_bar_new(GObject *, GtkAccelGroup *); diff --git a/src/project.c b/src/project.c index 70cbef1..60767be 100644 --- a/src/project.c +++ b/src/project.c @@ -614,6 +614,42 @@ const GOpenidaBinary **get_openida_project_binaries(const openida_project *proje + + +/****************************************************************************** +* * +* Paramètres : project = projet à consulter. * +* binary = binaire chargé, encadré et concerné. * +* * +* Description : Fournit un module de débogage prêt à emploi. * +* * +* Retour : Instance prête à devenir effective. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GBinaryDebugger *get_main_debugger_for_binary(const openida_project *project, const GOpenidaBinary *binary) +{ + return g_java_debugger_new(binary, NULL); /* FIXME */ + +} + + + + + + + + + + + + + + + + /* ---------------------------------------------------------------------------------- */ /* PARTIE GRAPHIQUE DES [DE]CHARGEMENTS */ /* ---------------------------------------------------------------------------------- */ diff --git a/src/project.h b/src/project.h index 7f45c28..d9b36c1 100644 --- a/src/project.h +++ b/src/project.h @@ -29,6 +29,7 @@ #include "analysis/binary.h" +#include "debug/debugger.h" #include "gtkext/gtkviewpanel.h" #include "gtkext/gtkdockitem.h" @@ -95,6 +96,12 @@ const GOpenidaBinary **get_openida_project_binaries(const openida_project *, siz +/* Fournit un module de débogage prêt à emploi. */ +GBinaryDebugger *get_main_debugger_for_binary(const openida_project *, const GOpenidaBinary *); + + + + /* ---------------------- PARTIE GRAPHIQUE DES [DE]CHARGEMENTS ---------------------- */ diff --git a/src/shell.c b/src/shell.c index 76e26bb..78e807f 100644 --- a/src/shell.c +++ b/src/shell.c @@ -161,7 +161,7 @@ GtkWidget *build_shell_panel(GObject *ref) static void terminal_child_exited_cb(VteReaper *reaper, GPid pid, gint status, VteTerminal *term) { - vte_terminal_feed(term, _("Exit detected ; lauching an new Python shell...\n\r"), -1); + //vte_terminal_feed(term, ("Exit detected ; lauching an new Python shell...\n\r"), -1); run_new_shell_in_terminal(term); |