summaryrefslogtreecommitdiff
path: root/src/panels/breaks.c
blob: 5562ae0fcf90a871dfb1a718bc708831503fa331 (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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458

/* Chrysalide - Outil d'analyse de fichiers binaires
 * breaks.c - panneau d'affichage des points d'arrêt
 *
 * Copyright (C) 2010-2018 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  Chrysalide 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.
 *
 *  Chrysalide 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 "breaks.h"


#include "panel-int.h"
#include "../debug/break.h"
#include "../gtkext/easygtk.h"
#include "../gtkext/support.h"



#define _(str) str


/* Panneau d'affichage des points d'arrêt (instance) */
struct _GBreaksPanel
{
    GEditorPanel parent;                    /* A laisser en premier        */

    GtkTreeView *treeview;                  /* Composant d'affichage       */
    GtkTreeStore *store;                    /* Modèle de gestion           */

    GLoadedBinary *binary;                  /* Binaire en cours d'étude    */

};


/* Panneau d'affichage des points d'arrêt (classe) */
struct _GBreaksPanelClass
{
    GEditorPanelClass parent;               /* A laisser en premier        */

};


/* Colonnes de la liste des symboles */
typedef enum _BreaksColumn
{
    BKC_POINT,                              /* Point d'arrêt de référence  */
    BKC_ICON,                               /* Statut du point d'arrêt     */
    BKC_ADDRESS,                            /* Adresse mémoire du symbole  */
    BKC_STRING,                             /* Désignation humaine         */

    BKC_COUNT                               /* Nombre de colonnes          */

} BreaksColumn;


/* Initialise la classe des panneaux de points d'arrêt. */
static void g_breaks_panel_class_init(GBreaksPanelClass *);

/* Initialise une instance de panneau de points d'arrêt. */
static void g_breaks_panel_init(GBreaksPanel *);

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




/* Intègre à l'affichage un groupe de points d'arrêt. */
static void add_bp_group_to_breaks_panel(GLoadedBinary *, GBreakGroup *, GBreaksPanel *);

/* Réagit à une nouvelle création de point d'arrêt. */
static void refresh_breaks_panel_on_bp_added(GBreakGroup *, GBreakPoint *, GBreaksPanel *);

/* Réagit à une suppression de point d'arrêt. */
static void refresh_breaks_panel_on_bp_removed(GBreakGroup *, GBreakPoint *, GBreaksPanel *);

/* Réagit à une modification de point d'arrêt. */
static void refresh_breaks_panel_on_bp_changed(GBreakGroup *, GBreakPoint *, GBreaksPanel *);




/* Retrouve un point d'arrêt dans la liste affichée. */
static bool find_breakpoint_in_breaks_panel(GBreaksPanel *, GBreakPoint *, GtkTreeIter *);



/* Indique le type défini pour un panneau d'affichage des points d'arrêt. */
G_DEFINE_TYPE(GBreaksPanel, g_breaks_panel, G_TYPE_EDITOR_PANEL);


/******************************************************************************
*                                                                             *
*  Paramètres  : klass = classe à initialiser.                                *
*                                                                             *
*  Description : Initialise la classe des panneaux de points d'arrêt.         *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_breaks_panel_class_init(GBreaksPanelClass *klass)
{

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = instance à initialiser.                              *
*                                                                             *
*  Description : Initialise une instance de panneau de points d'arrêt.        *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_breaks_panel_init(GBreaksPanel *panel)
{
    GEditorPanel *base;                     /* Version basique d'instance  */
    GObject *ref;                           /* Espace de référencement     */
    GtkWidget *toolbar;                     /* Barre d'outils              */
    GtkWidget *button;                      /* Bouton de cette même barre  */
    GtkWidget *separator;                   /* Barre de séparation vert.   */
    GtkWidget *scrollwnd;                   /* Support défilant            */
    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     */




    base = G_EDITOR_PANEL(panel);

    base->name = _("Breakpoints");
    base->reload_binary = (reload_for_new_binary_fc)reload_breaks_for_new_binary;

    base->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
    gtk_widget_show(base->widget);

    ref = G_OBJECT(base->widget);
    g_object_set_data(ref, "panel", panel);

    scrollwnd = gtk_scrolled_window_new(NULL, NULL);
    gtk_widget_show(scrollwnd);
    gtk_box_pack_start(GTK_BOX(base->widget), scrollwnd, TRUE, TRUE, 0);

    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwnd), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwnd), GTK_SHADOW_IN);

    panel->store = gtk_tree_store_new(BKC_COUNT, G_TYPE_OBJECT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);

    treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(panel->store));
    gtk_widget_show(treeview);
    gtk_container_add(GTK_CONTAINER(scrollwnd), treeview);

    panel->treeview = GTK_TREE_VIEW(treeview);

    g_object_unref(G_OBJECT(panel->store));

    column = gtk_tree_view_column_new();
    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();
    gtk_tree_view_column_set_title(column, _("Address"));

    renderer = gtk_cell_renderer_pixbuf_new();
    gtk_tree_view_column_pack_start(column, renderer, FALSE);
    gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", BKC_ICON);

    renderer = gtk_cell_renderer_text_new();
    gtk_tree_view_column_pack_start(column, renderer, TRUE);
    gtk_tree_view_column_add_attribute(column, renderer, "text", BKC_ADDRESS);

    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);




    //renderer = gtk_cell_renderer_text_new();
    //column = gtk_tree_view_column_new_with_attributes(_("Address"), renderer, "text", BKC_ADDRESS, NULL);
    //gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes(_("String"), renderer, "text", BKC_STRING, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);




}


/******************************************************************************
*                                                                             *
*  Paramètres  : -                                                            *
*                                                                             *
*  Description : Crée un panneau d'aperçu de graphiques.                      *
*                                                                             *
*  Retour      : Adresse de la structure mise en place.                       *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GEditorPanel *g_breaks_panel_new(void)
{
    GEditorPanel *result;                   /* Structure à retourner       */

    result = g_object_new(G_TYPE_BREAKS_PANEL, NULL);

    return G_EDITOR_PANEL(result);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel  = panneau à mettre à jour.                            *
*                binary = nouvelle instance de binaire analysé.               *
*                                                                             *
*  Description : Réagit à un changement du binaire courant.                   *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void reload_breaks_for_new_binary(GBreaksPanel *panel, GLoadedBinary *binary)
{

    printf("CHNAGE BINARY !\n");

    panel->binary = binary;

    //g_loaded_binary_for_each_bp_group(binary, (GExtFunc)add_bp_group_to_breaks_panel, panel);


}














/******************************************************************************
*                                                                             *
*  Paramètres  : binary = instance active du binaire analysé.                 *
*                group  = groupe de points d'arrêt présent dans le binaire.   *
*                panel  = panneau à mettre à jour.                            *
*                                                                             *
*  Description : Intègre à l'affichage un groupe de points d'arrêt.           *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void add_bp_group_to_breaks_panel(GLoadedBinary *binary, GBreakGroup *group, GBreaksPanel *panel)
{
    /* FIXME : bloquer toute émission de signal tant que les ajouts ne sont pas terminés. */

    g_signal_connect(group, "added",
                     G_CALLBACK(refresh_breaks_panel_on_bp_added), panel);

    g_signal_connect(group, "removed",
                     G_CALLBACK(refresh_breaks_panel_on_bp_removed), panel);

    g_break_group_for_each(group, (GExtFunc)refresh_breaks_panel_on_bp_added, panel);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : group = ensemble de points d'arrêt intervenant.              *
*                point = point d'arrêt à l'origine de la procédure.           *
*                panel = panneau à mettre à jour.                             *
*                                                                             *
*  Description : Réagit à une nouvelle création de point d'arrêt.             *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void refresh_breaks_panel_on_bp_added(GBreakGroup *group, GBreakPoint *point, GBreaksPanel *panel)
{
#if 0
    GExeFormat *format;                     /* Format associé au binaire   */
    GArchProcessor *proc;                   /* Architecture utilisée       */
    char address[VMPA_MAX_SIZE];            /* Conversion de l'adresse     */
    GtkTreeIter iter;                       /* Point d'insertion           */

    format = g_loaded_binary_get_format(panel->binary);
    proc = get_arch_processor_from_format(format);

    vmpa_to_string(g_break_point_get_address(point),
                   g_arch_processor_get_memory_size(proc),
                   address);

    gtk_tree_store_append(panel->store, &iter, NULL);
    gtk_tree_store_set(panel->store, &iter,
                       BKC_POINT, point,
                       BKC_ADDRESS, address,
                       BKC_STRING, "???",
                       -1);

    /* Pour le reste... */
    refresh_breaks_panel_on_bp_changed(group, point, panel);

    g_object_unref(G_OBJECT(format));

#endif
}


/******************************************************************************
*                                                                             *
*  Paramètres  : group = ensemble de points d'arrêt intervenant.              *
*                point = point d'arrêt à l'origine de la procédure.           *
*                panel = panneau à mettre à jour.                             *
*                                                                             *
*  Description : Réagit à une suppression de point d'arrêt.                   *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void refresh_breaks_panel_on_bp_removed(GBreakGroup *group, GBreakPoint *point, GBreaksPanel *panel)
{
    GtkTreeIter iter;                       /* Point de modification       */

    if (!find_breakpoint_in_breaks_panel(panel, point, &iter))
        return;

    gtk_tree_store_remove(panel->store, &iter);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : group = ensemble de points d'arrêt intervenant.              *
*                point = point d'arrêt à l'origine de la procédure.           *
*                panel = panneau à mettre à jour.                             *
*                                                                             *
*  Description : Réagit à une modification de point d'arrêt.                  *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void refresh_breaks_panel_on_bp_changed(GBreakGroup *group, GBreakPoint *point, GBreaksPanel *panel)
{
    GtkTreeIter iter;                       /* Point de modification       */
    GdkPixbuf *pixbuf;                      /* Tampon d'image chargé       */

    if (!find_breakpoint_in_breaks_panel(panel, point, &iter))
        return;

    pixbuf = get_pixbuf_from_file("breakpoint_normal.png");
    if (pixbuf == NULL) return;

    gtk_tree_store_set(panel->store, &iter,
                       BKC_ICON, pixbuf,
                       -1);

}










/******************************************************************************
*                                                                             *
*  Paramètres  : panel = panneau d'affichage à consulter.                     *
*                point = point d'arrêt lié à la procédure.                    *
*                                                                             *
*  Description : Retrouve un point d'arrêt dans la liste affichée.            *
*                                                                             *
*  Retour      : Bilan de la recherche.                                       *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool find_breakpoint_in_breaks_panel(GBreaksPanel *panel, GBreakPoint *point, GtkTreeIter *iter)
{
    bool result;                            /* Bilan à retourner           */
    GtkTreeIter tmp;                        /* Sauvegarde temporaire       */
    bool test;                              /* Valide la poursuite         */
    GBreakPoint *bp;                        /* Adresse à comparer          */

    result = false;

    for (test = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(panel->store), &tmp);
         test && !result;
         test = gtk_tree_model_iter_next(GTK_TREE_MODEL(panel->store), &tmp))
    {
        gtk_tree_model_get(GTK_TREE_MODEL(panel->store),
                           &tmp, BKC_POINT, &bp, -1);

        if (bp == point)
        {
            *iter = tmp;
            result = true;
        }

    }

    return result;

}