summaryrefslogtreecommitdiff
path: root/src/gtkext/gtkblockview.c
blob: 5e0a4cf9ee4d92ec8c37dde677a00d5b0bdd3045 (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

/* Chrysalide - Outil d'analyse de fichiers binaires
 * gtkblockview.c - affichage d'un fragment de code d'assemblage
 *
 * Copyright (C) 2008-2012 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "gtkblockview.h"


#include "gtkbufferview-int.h"



/* -------------------------- INTERACTION DIRECTE AVEC GTK -------------------------- */


/* Composant d'affichage de bloc d'assembleur (instance) */
struct _GtkBlockView
{
    GtkBufferView parent;                   /* A laisser en premier        */

};

/* Composant d'affichage de code d'assembleur (classe) */
struct _GtkBlockViewClass
{
    GtkBufferViewClass parent;              /* A laisser en premier        */

};


/* Procède à l'initialisation des afficheurs de bloc assembleur. */
static void gtk_block_view_class_init(GtkBlockViewClass *);

/* Procède à l'initialisation de l'afficheur de bloc assembleur. */
static void gtk_block_view_init(GtkBlockView *);

/* Assure la gestion des clics de souris sur le composant. */
static gboolean gtk_block_view_button_press_event(GtkBlockView *, GdkEventButton *, gpointer);

/* Redessine l'affichage suite à un changement visuel. */
static gboolean gtk_block_view_need_redraw(GBufferView *, GtkBlockView *);

/* Prend acte de l'association d'un binaire chargé. */
static void gtk_block_view_attach_binary(GtkBlockView *, GLoadedBinary *, bool *, bool *);



/* ---------------------------------------------------------------------------------- */
/*                            INTERACTION DIRECTE AVEC GTK                            */
/* ---------------------------------------------------------------------------------- */


/* Détermine le type du composant d'affichage de bloc en langage d'assemblage. */
G_DEFINE_TYPE(GtkBlockView, gtk_block_view, GTK_TYPE_BUFFER_VIEW)


/******************************************************************************
*                                                                             *
*  Paramètres  : class = classe GTK à initialiser.                            *
*                                                                             *
*  Description : Procède à l'initialisation des afficheurs de bloc assembleur.*
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void gtk_block_view_class_init(GtkBlockViewClass *class)
{

}


/******************************************************************************
*                                                                             *
*  Paramètres  : view = composant GTK à initialiser.                          *
*                                                                             *
*  Description : Procède à l'initialisation de l'afficheur de bloc assembleur.*
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void gtk_block_view_init(GtkBlockView *view)
{
    GtkViewPanel *panel;                    /* Instance parente            */

    panel = GTK_VIEW_PANEL(view);

    panel->attach = (attach_binary_fc)gtk_block_view_attach_binary;

    g_signal_connect(G_OBJECT(view), "button_press_event",
                     G_CALLBACK(gtk_block_view_button_press_event), NULL);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : -                                                            *
*                                                                             *
*  Description : Crée un nouveau composant pour l'affichage de bloc en ASM.   *
*                                                                             *
*  Retour      : Composant GTK créé.                                          *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GtkWidget *gtk_block_view_new(void)
{
    GtkBlockView *result;                   /* Composant à retourner       */

    result = g_object_new(GTK_TYPE_BLOCK_VIEW, NULL);

    return GTK_WIDGET(result);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : view  = composant GTK visé par l'opération.                  *
*                event = informations liées à l'événement.                    *
*                data  = donnée non utilisée ici.                             *
*                                                                             *
*  Description : Assure la gestion des clics de souris sur le composant.      *
*                                                                             *
*  Retour      : FALSE pour poursuivre la propagation de l'événement.         *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static gboolean gtk_block_view_button_press_event(GtkBlockView *view, GdkEventButton *event, gpointer data)
{
    GtkBufferView *bview;                   /* Autre vision du composant   */
    gint real_x;                            /* Abscisse absolue réelle     */
    gint real_y;                            /* Ordonnée absolue réelle     */

    if (event->type == GDK_2BUTTON_PRESS)
    {



        printf("I feel %s clicked with button %d\n",
               event->type == GDK_2BUTTON_PRESS ? "double" : "triple",
               event->button);

        bview = GTK_BUFFER_VIEW(view);

        real_x = event->x;
        real_y = event->y;

        gtk_buffer_view_compute_real_coord(bview, &real_x, &real_y);

        g_buffer_view_highlight_segments(gtk_buffer_view_get_buffer(bview), real_x, real_y);



    }

    return FALSE;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : view  = composant GLib interne.                              *
*                block = composant GTK d'affichage.                           *
*                                                                             *
*  Description : Redessine l'affichage suite à un changement visuel.          *
*                                                                             *
*  Retour      : FALSE pour poursuivre la propagation de l'événement.         *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static gboolean gtk_block_view_need_redraw(GBufferView *view, GtkBlockView *block)
{
    gtk_widget_queue_draw(GTK_WIDGET(block));

    return FALSE;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : view   = composant GTK à mettre à jour.                      *
*                binary = binaire associé à intégrer.                         *
*                addr   = indique si les positions doivent être affichées.    *
*                code   = indique si le code binaire doit être affiché.       *
*                                                                             *
*  Description : Prend acte de l'association d'un binaire chargé.             *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void gtk_block_view_attach_binary(GtkBlockView *view, GLoadedBinary *binary, bool *addr, bool *code)
{
    GCodeBuffer *buffer;                    /* Tampon par défaut           */
    GBufferView *bview;                     /* Vue sur ce même tampon      */

    buffer = g_loaded_binary_get_disassembled_buffer(binary);
    bview = g_buffer_view_new(buffer);

    gtk_buffer_view_attach_buffer(GTK_BUFFER_VIEW(view), bview, addr, code);

    g_signal_connect(G_OBJECT(bview), "need-redraw",
                     G_CALLBACK(gtk_block_view_need_redraw), view);

}