summaryrefslogtreecommitdiff
path: root/src/gui/panels/binary.c
blob: aba0c7f153ccc5d80139837be968cb533068415e (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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

/* Chrysalide - Outil d'analyse de fichiers binaires
 * welcome.c - panneau d'affichage de contenus d'un binaire, bruts ou non
 *
 * Copyright (C) 2024 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 "binary.h"


#include "binary-int.h"
#include "../window.h"
#include "../../analysis/contents/file.h"
#include "../../gtkext/helpers.h"
#include "../../gtkext/hexview.h"



/* ------------------------- COEUR D'UN PANNEAU D'AFFICHAGE ------------------------- */


/* Initialise la classe des panneaux pour binaires. */
static void gtk_binary_panel_class_init(GtkBinaryPanelClass *);

/* Initialise une instance de panneau pour binaire. */
static void gtk_binary_panel_init(GtkBinaryPanel *);

/* Supprime toutes les références externes. */
static void gtk_binary_panel_dispose(GtkBinaryPanel *);

/* Procède à la libération totale de la mémoire. */
static void gtk_binary_panel_finalize(GtkBinaryPanel *);



/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */






/* ---------------------- MANIPULATIONS D'UN PANNEAU GRAPHIQUE ---------------------- */


/* Initialise la classe des panneaux graphiques pour binaires. */
static void g_binary_panel_class_init(GBinaryPanelClass *);

/* Initialise une instance de panneau graphique pour binaire. */
static void g_binary_panel_init(GBinaryPanel *);

/* Supprime toutes les références externes. */
static void g_binary_panel_dispose(GBinaryPanel *);

/* Procède à la libération totale de la mémoire. */
static void g_binary_panel_finalize(GBinaryPanel *);



/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */


/* Fournit une indication sur la personnalité du panneau. */
static PanelItemPersonality g_binary_panel_get_personality(const GBinaryPanel *);

/* Fournit un composant pour lancer l'activité d'un panneau. */
static GtkWidget *g_binary_panel_get_launcher(GBinaryPanel *);

/* Fournit un composant pour paramétrer l'activité d'un panneau. */
static GtkWidget *g_binary_panel_get_properties(GBinaryPanel *);

/* Ouvre une boîte de dialogue pour récupérer un fichier. */
static void g_binary_panel_on_new_file_entry_icon_release(GtkEntry *, GtkEntryIconPosition, GBinaryPanel *);

/* Fournit un composant représentant un panneau graphique. */
static GtkTiledPanel *g_binary_panel_get_panel(GBinaryPanel *, GtkWidget *);



/* ---------------------------------------------------------------------------------- */
/*                           COEUR D'UN PANNEAU D'AFFICHAGE                           */
/* ---------------------------------------------------------------------------------- */


/* Indique le type défini pour un panneau d'accueil. */
G_DEFINE_TYPE(GtkBinaryPanel, gtk_binary_panel, GTK_TYPE_TILED_PANEL);


/******************************************************************************
*                                                                             *
*  Paramètres  : class = classe à initialiser.                                *
*                                                                             *
*  Description : Initialise la classe des panneaux pour binaires.             *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void gtk_binary_panel_class_init(GtkBinaryPanelClass *class)
{
    GObjectClass *object;                   /* Autre version de la classe  */
    GtkWidgetClass *widget;                 /* Classe de haut niveau       */

    object = G_OBJECT_CLASS(class);

    object->dispose = (GObjectFinalizeFunc/* ! */)gtk_binary_panel_dispose;
    object->finalize = (GObjectFinalizeFunc)gtk_binary_panel_finalize;

    widget = GTK_WIDGET_CLASS(class);

    gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/panels/binary.ui");

    gtk_widget_class_bind_template_child(widget, GtkBinaryPanel, hex_scroll);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = instance à initialiser.                              *
*                                                                             *
*  Description : Initialise une instance de panneau pour binaire.             *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void gtk_binary_panel_init(GtkBinaryPanel *panel)
{
    gtk_widget_init_template(GTK_WIDGET(panel));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = instance d'objet GLib à traiter.                     *
*                                                                             *
*  Description : Supprime toutes les références externes.                     *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void gtk_binary_panel_dispose(GtkBinaryPanel *panel)
{
    gtk_widget_dispose_template(GTK_WIDGET(panel), GTK_TYPE_BINARY_PANEL);

    G_OBJECT_CLASS(gtk_binary_panel_parent_class)->dispose(G_OBJECT(panel));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = instance d'objet GLib à traiter.                     *
*                                                                             *
*  Description : Procède à la libération totale de la mémoire.                *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void gtk_binary_panel_finalize(GtkBinaryPanel *panel)
{
    G_OBJECT_CLASS(gtk_binary_panel_parent_class)->finalize(G_OBJECT(panel));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : content = contenu brut à exposer.                            *
*                                                                             *
*  Description : Crée une nouvelle instance de panneau pour binaire.          *
*                                                                             *
*  Retour      : Composant GTK mis en place.                                  *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GtkTiledPanel *gtk_binary_panel_new_for_content(GBinContent *content)
{
    GtkTiledPanel *result;                  /* Instance à retourner        */
    GtkHexView *view;                       /* Composant d'affichage       */

    result = g_object_new(GTK_TYPE_BINARY_PANEL, NULL);

    view = gtk_hex_view_new(content);
    gtk_scrolled_window_set_child(GTK_BINARY_PANEL(result)->hex_scroll, GTK_WIDGET(view));

    return result;

}



/* ---------------------------------------------------------------------------------- */
/*                       IMPLEMENTATION DES FONCTIONS DE CLASSE                       */
/* ---------------------------------------------------------------------------------- */









/* ---------------------------------------------------------------------------------- */
/*                        MANIPULATIONS D'UN PANNEAU GRAPHIQUE                        */
/* ---------------------------------------------------------------------------------- */


/* Indique le type défini pour une manipulation de panneau pour binaires. */
G_DEFINE_TYPE(GBinaryPanel, g_binary_panel, G_TYPE_PANEL_ITEM);


/******************************************************************************
*                                                                             *
*  Paramètres  : class = classe à initialiser.                                *
*                                                                             *
*  Description : Initialise la classe des panneaux graphiques pour binaires.  *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_binary_panel_class_init(GBinaryPanelClass *class)
{
    GObjectClass *object;                   /* Autre version de la classe  */
    GPanelItemClass *panel;                 /* Encore une autre vision...  */

    object = G_OBJECT_CLASS(class);

    object->dispose = (GObjectFinalizeFunc/* ! */)g_binary_panel_dispose;
    object->finalize = (GObjectFinalizeFunc)g_binary_panel_finalize;

    panel = G_PANEL_ITEM_CLASS(class);

    panel->get_personality = (get_panel_item_personality_cb)g_binary_panel_get_personality;
    panel->get_launcher = (get_panel_item_widget_cb)g_binary_panel_get_launcher;
    panel->get_properties = (get_panel_item_widget_cb)g_binary_panel_get_properties;
    panel->get_panel = (get_panel_item_panel_cb)g_binary_panel_get_panel;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = instance à initialiser.                              *
*                                                                             *
*  Description : Initialise une instance de panneau graphique pour binaire.   *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_binary_panel_init(GBinaryPanel *panel)
{

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = instance d'objet GLib à traiter.                     *
*                                                                             *
*  Description : Supprime toutes les références externes.                     *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_binary_panel_dispose(GBinaryPanel *panel)
{
    G_OBJECT_CLASS(g_binary_panel_parent_class)->dispose(G_OBJECT(panel));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = instance d'objet GLib à traiter.                     *
*                                                                             *
*  Description : Procède à la libération totale de la mémoire.                *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_binary_panel_finalize(GBinaryPanel *panel)
{
    G_OBJECT_CLASS(g_binary_panel_parent_class)->finalize(G_OBJECT(panel));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : -                                                            *
*                                                                             *
*  Description : Constitue une définition de manipulation de panneau.         *
*                                                                             *
*  Retour      : Définition de propriétés mise en place.                      *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GPanelItem *g_binary_panel_new(void)
{
    GPanelItem *result;                     /* Structure à retourner       */

    result = g_object_new(G_TYPE_BINARY_PANEL, NULL);

    return result;

}



/* ---------------------------------------------------------------------------------- */
/*                       IMPLEMENTATION DES FONCTIONS DE CLASSE                       */
/* ---------------------------------------------------------------------------------- */


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = définition de panneau à consulter.                   *
*                                                                             *
*  Description : Fournit une indication sur la personnalité du panneau.       *
*                                                                             *
*  Retour      : Identifiant lié à la nature du panneau.                      *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static PanelItemPersonality g_binary_panel_get_personality(const GBinaryPanel *panel)
{
    PanelItemPersonality result;            /* Personnalité à retourner    */

    result = PIP_MAIN_PANEL;

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = définition de panneau à manipuler.                   *
*                                                                             *
*  Description : Fournit un composant pour lancer l'activité d'un panneau.    *
*                                                                             *
*  Retour      : Composant GTK (déjà ?) mis en place.                         *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static GtkWidget *g_binary_panel_get_launcher(GBinaryPanel *panel)
{
    GtkWidget *result;                      /* Composant à retourner       */
    GtkBuilder *builder;                    /* Constructeur d'UI           */

    builder = gtk_builder_new_from_resource("/re/chrysalide/framework/gui/panels/binary-launch.ui");

    result = GTK_WIDGET(gtk_builder_get_object(builder, "launcher"));
    ref_object(result);

    unref_object(builder);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = définition de panneau à manipuler.                   *
*                                                                             *
*  Description : Fournit un composant pour paramétrer l'activité d'un panneau.*
*                                                                             *
*  Retour      : Composant GTK (déjà ?) mis en place.                         *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static GtkWidget *g_binary_panel_get_properties(GBinaryPanel *panel)
{
    GtkWidget *result;                      /* Composant à retourner       */
    GtkBuilderScope *scope;                 /* Fonctions pour signaux      */
    GtkBuilderCScope *cscope;               /* Fonctions pour signaux      */
    GtkBuilder *builder;                    /* Constructeur d'UI           */
#ifndef NDEBUG
    gboolean status;                        /* Bilan d'un chargement       */
#endif

    scope = gtk_builder_cscope_new();
    cscope = GTK_BUILDER_CSCOPE(scope);

    gtk_builder_cscope_add_callback_symbol(cscope, BUILDER_CB(g_binary_panel_on_new_file_entry_icon_release));

    builder = gtk_builder_new();
    gtk_builder_set_scope(builder, scope);
    gtk_builder_set_current_object(builder, G_OBJECT(panel));

#ifndef NDEBUG
    status = gtk_builder_add_from_resource(builder, "/re/chrysalide/framework/gui/panels/binary-props.ui", NULL);
    assert(status);
#else
    gtk_builder_add_from_resource(builder, "/re/chrysalide/framework/gui/panels/binary-props.ui", NULL);
#endif

    result = GTK_WIDGET(gtk_builder_get_object(builder, "properties"));
    ref_object(result);

    unref_object(builder);
    unref_object(scope);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : entry    = zone de saisie concernée par l'appel.             *
*                icon_pos = position de l'icone incrustée dans la zone.       *
*                panel    = définition de panneau à manipuler.                *
*                                                                             *
*  Description : Ouvre une boîte de dialogue pour récupérer un fichier.       *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_binary_panel_on_new_file_entry_icon_release(GtkEntry *entry, GtkEntryIconPosition icon_pos, GBinaryPanel *panel)
{
    GtkRoot *root;                          /* Racine du composant         */
    GtkTiledPanel *tiled;                   /* Panneau d'affichage complet */

    root = gtk_widget_get_root(GTK_WIDGET(entry));

    tiled = g_binary_panel_get_panel(panel, NULL);

    gtk_framework_window_add(GTK_FRAMEWORK_WINDOW(root), tiled);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : panel = définition de panneau à manipuler.                   *
*                props = éventuels éléments graphiques de paramétrages.       *
*                                                                             *
*  Description : Fournit un composant représentant un panneau graphique.      *
*                                                                             *
*  Retour      : Composant GTK (déjà ?) mis en place.                         *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static GtkTiledPanel *g_binary_panel_get_panel(GBinaryPanel *panel, GtkWidget *props)
{
    GtkTiledPanel *result;                  /* Composant à retourner       */
    GBinContent *content;                   /* Contenu binaire à afficher  */

    content = g_file_content_new("/bin/id");

    result = gtk_binary_panel_new_for_content(content);

    unref_object(content);

    return result;

}