summaryrefslogtreecommitdiff
path: root/src/gui/tb/source.c
blob: d5318c4eaca3f656edb0c40849d877b1772d667a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

/* Chrysalide - Outil d'analyse de fichiers binaires
 * source.c - sélection du fichier ciblé lors d'une décompilation
 *
 * Copyright (C) 2010-2013 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  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 "source.h"


#include <i18n.h>


#include "toolbar.h"
#include "../editem-int.h"
#include "../../format/format.h"
#include "../../gtkext/easygtk.h"
#include "../../gtkext/gtkbufferview.h"
#include "../../gtkext/gtksourceview.h"



/* Construit l'élément GTK pour une barre d'outils. */
static GtkWidget *build_source_tb_widget(GObject *);

/* Réagit à un changement du binaire courant. */
static void update_source_item_binary(GEditorItem *, GLoadedBinary *);

/* Réagit à un changement de panneau d'affichage courant. */
static void update_source_item_view(GEditorItem *, GtkViewPanel *);

/* Réagit à un changement de sélection de la source courante. */
static void change_selected_source(GtkComboBox *, GObject *);



/******************************************************************************
*                                                                             *
*  Paramètres  : ref = espace de référencement global.                        *
*                                                                             *
*  Description : Construit l'élément GTK pour une barre d'outils.             *
*                                                                             *
*  Retour      : Adresse du composant mis en place.                           *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static GtkWidget *build_source_tb_widget(GObject *ref)
{
    GtkWidget *result;                      /* Composant à retourner       */
    GtkWidget *handlebox;                   /* Support relocalisable       */
    GtkWidget *hbox;                        /* Support interne             */
    GtkWidget *label;                       /* Etiquette d'introduction    */
    GtkWidget *comboboxentry;               /* Liste de fichiers           */

    result = GTK_WIDGET(gtk_tool_item_new());
    gtk_widget_show(result);

    handlebox = gtk_handle_box_new();
    gtk_widget_show(handlebox);
    gtk_container_add(GTK_CONTAINER(result), handlebox);

    hbox = gtk_hbox_new(FALSE, 0);
    gtk_widget_show(hbox);
    gtk_container_add(GTK_CONTAINER(handlebox), hbox);

    label = qck_create_label(G_OBJECT(result), "label", _(" Source: "));
    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);

    comboboxentry = qck_create_combobox2(G_OBJECT(result), "combo",
                                        G_CALLBACK(change_selected_source), ref);
    gtk_box_pack_start(GTK_BOX(hbox), comboboxentry, TRUE, TRUE, 0);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : ref = espace de référencement global.                        *
*                                                                             *
*  Description : Crée une sélection de fichier réactive pour barre d'outils.  *
*                                                                             *
*  Retour      : Adresse de la structure d'encadrement mise en place.         *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GEditorItem *create_source_tb_item(GObject *ref)
{
    GEditorItem *result;                    /* Structure à retourner       */
    GtkWidget *widget;                      /* Composant affiché à l'écran */

    widget = build_source_tb_widget(ref);

    result = g_toolbar_item_new(ref, "source", widget, _("Source files"));

    result->update_binary = update_source_item_binary;
    result->update_view = update_source_item_view;

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : item   = élément réactif sollicité.                          *
*                binary = binaire chargé nouvellement affiché.                *
*                                                                             *
*  Description : Réagit à un changement du binaire courant.                   *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void update_source_item_binary(GEditorItem *item, GLoadedBinary *binary)
{
    GtkComboBoxText *combo;                 /* Liste de sélection          */
    GtkTreeModel *model;                    /* Gestionnaire d'éléments     */
    GtkTreeIter iter;                       /* Boucle de parcours #2       */
    GExeFormat *format;                     /* Format d'exécutable associé */
    size_t count;                           /* Quantité de fichiers        */
    size_t defsrc;                          /* Fichier source principal    */
    const char * const *files;              /* Liste de fichiers source    */
    size_t i;                               /* Boucle de parcours #2       */

    combo = GTK_COMBO_BOX_TEXT(g_object_get_data(G_OBJECT(item->widget), "combo"));

    /* Réinitialisation */

    g_signal_handlers_block_by_func(combo, G_CALLBACK(change_selected_source), item->ref);

    /* FIXME : 3.0 */
    //gtk_combo_box_text_remove_all(combo);

    model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));

    while (gtk_tree_model_get_iter_first(model, &iter))
        gtk_combo_box_text_remove(combo, 0);

    /* Inscriptions */

    format = g_loaded_binary_get_format(binary);
    files = g_binary_format_get_source_files(G_BIN_FORMAT(format), &count, &defsrc);

    for (i = 0; i < count; i++)
        gtk_combo_box_text_append_text(combo, files[i]);

    /* Réactivation */

    g_signal_handlers_unblock_by_func(combo, G_CALLBACK(change_selected_source), item->ref);

    //gtk_combo_box_set_active(combo, defsrc);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : item = élément réactif sollicité.                            *
*                view = nouveau panneau d'affichage actif.                    *
*                                                                             *
*  Description : Réagit à un changement de panneau d'affichage courant.       *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void update_source_item_view(GEditorItem *item, GtkViewPanel *view)
{
    gtk_widget_set_sensitive(item->widget, GTK_IS_SOURCE_VIEW(view));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : widget = composant GTK en cause.                             *
*                ref    = espace de référencement global.                     *
*                                                                             *
*  Description : Réagit à un changement de sélection de la source courante.   *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void change_selected_source(GtkComboBox *widget, GObject *ref)
{
#if 0
    gint index;                             /* Nouvelle source ciblée      */
    GLoadedBinary *binary;                  /* Binaire chargé courant      */
    GCodeBuffer *buffer;                    /* Nouveau tampon à présenter  */
    GtkBufferView *view;                    /* Afficheur de tampons        */

    index = gtk_combo_box_get_active(widget);

    binary = G_LOADED_BINARY(g_object_get_data(ref, "current_binary"));
    buffer = g_loaded_binary_get_decompiled_buffer(binary, index);

    view = GTK_BUFFER_VIEW(g_object_get_data(ref, "current_view"));
    if (GTK_IS_BUFFER_VIEW(view))
        gtk_buffer_view_attach_buffer(view, buffer,
                                      g_loaded_binary_display_decomp_lines(binary), NULL);
#endif
}