summaryrefslogtreecommitdiff
path: root/src/glibext/gbinportion.h
blob: b91af05284bb77eadae373a58770ce9d2b658e9b (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

/* Chrysalide - Outil d'analyse de fichiers binaires
 * binportion.h - prototypes pour la représentation graphique de portions de binaire
 *
 * Copyright (C) 2013 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef _GLIBEXT_BINPORTION_H
#define _GLIBEXT_BINPORTION_H


#include <glib-object.h>
#include <stdbool.h>
#include <gtk/gtk.h>


#include "gcodebuffer.h"
#include "../arch/vmpa.h"
#include "../common/fnv1a.h"



/* ------------------------------- PORTION DE BINAIRE ------------------------------- */


/**
 * Couleurs de représentation.
 */

#define BPC_RAW             "binportion-raw"
#define BPC_CODE            "binportion-code"
#define BPC_DATA            "binportion-data"
#define BPC_DATA_RO         "binportion-data-ro"
#define BPC_DISASS_ERROR    "binportion-disassembly-error"


#define G_TYPE_BIN_PORTION                (g_binary_portion_get_type())
#define G_BIN_PORTION(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BIN_PORTION, GBinPortion))
#define G_IS_BIN_PORTION(obj)             (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BIN_PORTION))
#define G_BIN_PORTION_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BIN_PORTION, GBinPortionClass))
#define G_IS_BIN_PORTION_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BIN_PORTION))
#define G_BIN_PORTION_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BIN_PORTION, GBinPortionClass))


/* Portion de données binaires quelconques (instance) */
typedef struct _GBinPortion GBinPortion;

/* Portion de données binaires quelconques (classe) */
typedef struct _GBinPortionClass GBinPortionClass;


/* Droits d'accès à une portion */
typedef enum _PortionAccessRights
{
    PAC_NONE    = (0 << 0),                 /* Aucun                       */
    PAC_READ    = (1 << 0),                 /* Lecture                     */
    PAC_WRITE   = (1 << 1),                 /* Ecriture                    */
    PAC_EXEC    = (1 << 2)                  /* Exécution                   */

} PortionAccessRights;


/* Indique le type défini par la GLib pour les portions de données binaires. */
GType g_binary_portion_get_type(void);

/* Crée une description de partie de code vierge. */
GBinPortion *g_binary_portion_new(const char *);

/* Etablit la comparaison ascendante entre deux portions. */
int g_binary_portion_compare(const GBinPortion **, const GBinPortion **);

/* Attribue une description humaine à une partie de code. */
void g_binary_portion_set_desc(GBinPortion *, const char *);

/* Fournit la description attribuée à une partie de code. */
const char *g_binary_portion_get_desc(const GBinPortion *);

/* Définit les valeurs utiles d'une partie de code. */
void g_binary_portion_set_values(GBinPortion *, const vmpa2t *, phys_t);

/* Fournit l'emplacement d'une partie de code binaire. */
const mrange_t *g_binary_portion_get_range(const GBinPortion *);

/* Définit les droits associés à une partie de code. */
void g_binary_portion_set_rights(GBinPortion *, PortionAccessRights);

/* Fournit les droits associés à une partie de code. */
PortionAccessRights g_binary_portion_get_rights(const GBinPortion *);

/* Insère dans un tampon une description de portion. */
void g_binary_portion_print(const GBinPortion *, GCodeBuffer *, MemoryDataSize);

/* Prépare une astuce concernant une portion pour son affichage. */
void g_binary_portion_query_tooltip(GBinPortion *, GtkTooltip *);

/* Représente la portion sur une bande dédiée. */
void g_binary_portion_draw(const GBinPortion *, GtkStyleContext *, cairo_t *, const GdkRectangle *);



/* -------------------------- COUCHES DE PORTIONS BINAIRES -------------------------- */


#define G_TYPE_PORTION_LAYER                (g_portion_layer_get_type())
#define G_PORTION_LAYER(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PORTION_LAYER, GPortionLayer))
#define G_IS_PORTION_LAYER(obj)             (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PORTION_LAYER))
#define G_PORTION_LAYER_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PORTION_LAYER, GPortionLayerClass))
#define G_IS_PORTION_LAYER_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PORTION_LAYER))
#define G_PORTION_LAYER_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PORTION_LAYER, GPortionLayerClass))


/* Couche de portions binaires quelconques (instance) */
typedef struct _GPortionLayer GPortionLayer;

/* Couche de portions binaires quelconques (classe) */
typedef struct _GPortionLayerClass GPortionLayerClass;


/* Taille à définir lors d'un rattachement */
#define NO_LENGTH_YET VMPA_NO_PHYSICAL


/* Indique le type défini par la GLib pour les couches de portions binaires. */
GType g_portion_layer_get_type(void);

/* Crée une nouvelle couche de portions binaires. */
GPortionLayer *g_portion_layer_new(phys_t, const char *);

/* Attache une couche à une autre en tant que couche inférieure. */
void g_portion_layer_attach_sub(GPortionLayer *, GPortionLayer *);

/* Procède à l'inclusion d'une portion dans une couche. */
void g_portion_layer_include(GPortionLayer *, GBinPortion *);

/* Fournit une liste triée de portions d'un binaire. */
GBinPortion **g_portion_layer_collect_all_portions(const GPortionLayer *, size_t *);

/* Recherche la portion présente à un point donné. */
GBinPortion *g_portion_layer_find_portion_at_pos(const GPortionLayer *, gint, GdkRectangle *);

/* Recherche la portion présente à une adresse donnée. */
GBinPortion *g_portion_layer_find_portion_at_addr(const GPortionLayer *, const vmpa2t *, GdkRectangle *);

/* Fournit la position correspondant à une adresse donnée. */
bool g_portion_layer_get_addr_from_pos(GPortionLayer *, gint, const GdkRectangle *, vmpa2t *);

/* Fournit l'adresse correspondant à une position donnée. */
bool g_portion_layer_get_pos_from_addr(GPortionLayer *, const vmpa2t *, const GdkRectangle *, gint *);

/* Fonction appelée à chaque visite de portion.*/
typedef bool (* visit_portion_fc) (GBinPortion *, void *);

/* Parcours un ensemble de portions binaires. */
bool g_portion_layer_visit(const GPortionLayer *, visit_portion_fc, void *);

/* Prépare une astuce concernant une portion pour son affichage. */
gboolean g_portion_layer_query_tooltip(const GPortionLayer *, gint, gint, const GdkRectangle *, GtkTooltip *);

/* Représente une couche de portions sur une bande dédiée. */
void g_portion_layer_draw(const GPortionLayer *, GtkStyleContext *, cairo_t *, const GdkRectangle *);



#endif  /* _GLIBEXT_BINPORTION_H */