Heraia  0.1.8
libheraia.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3  libheraia.h
4  Heraia's library header
5 
6  (C) Copyright 2008 - 2011 Sébastien Tricaud, Olivier Delhomme
7  e-mail : heraia@delhomme.org
8  URL : http://heraia.tuxfamily.org
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2, or (at your option)
13  any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 /**
24  * @file libheraia.h
25  *
26  * This file contains all the definitions and includes all other .h
27  * files. This is not very friendly, but ease compilation on exotic
28  * systems.
29  */
30 #ifndef _LIBHERAIA_H_
31 #define _LIBHERAIA_H_
32 
33 /* I have some problems under windows if #ifdef statement is activated */
34 
35 /* #ifdef HAVE_CONFIG_H */
36 #include "config.h"
37 /* #endif */ /* HAVE_CONFIG_H */
38 
39 
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <time.h>
44 #include <unistd.h>
45 #include <sys/types.h>
46 #include <sys/stat.h>
47 #include <getopt.h>
48 
49 #include <glib.h>
50 #include <glib/gstdio.h>
51 #include <glib/gi18n-lib.h>
52 #include <gmodule.h>
53 
54 
55 #ifdef GTKHEX3
56  #include <gtkhex-3/gtkhex.h>
57 #endif
58 #ifndef GTKHEX3
59  #include <gtkhex/gtkhex.h>
60 #endif
61 
62 
63 /**
64  * @typedef HexDocument Heraia_Document
65  * Abstract layer this may be usefull if we decide to leave Heraia_Hex
66  * and use something else !
67  *
68  * @typedef GtkHex Heraia_Hex
69  * Abstract layer this may be usefull if we decide to leave Heraia_Hex
70  * and use something else !
71  */
72 /**
73  * @typedef gint HERAIA_ERROR
74  * Defines heraia error type (this should be used !)
75  */
76 typedef HexDocument Heraia_Document;
77 typedef GtkHex Heraia_Hex;
78 typedef gint HERAIA_ERROR;
79 
80 /**
81  * @typedef gint RefreshType
82  * Refresh type (may be used to decide what to do
83  * in a particular case)
84  * @warning This is not thread safe !!
85  */
86 /**
87  * @def HERAIA_REFRESH_NOTHING
88  * When nothing is refreshed
89  *
90  * @def HERAIA_REFRESH_NEW_FILE
91  * When a new file has been loaded
92  *
93  * @def HERAIA_REFRESH_CURSOR_MOVE
94  * When the cursor is moving
95  *
96  * @def HERAIA_REFRESH_TAB_CHANGED
97  * When user selects another tab in main notebook
98  */
99 typedef gint RefreshType;
100 #define HERAIA_REFRESH_NOTHING 0
101 #define HERAIA_REFRESH_NEW_FILE 1
102 #define HERAIA_REFRESH_CURSOR_MOVE 2
103 #define HERAIA_REFRESH_TAB_CHANGED 3
104 
105 
106 /**
107  * @def HERAIA_FIND_FORWARD
108  * When one wants to do a search in the forward direction
109  *
110  * @def HERAIA_FIND_BACKWARD
111  * When one wants to do a search in the backward direction
112  *
113  * @def HERAIA_FIND_ALL
114  * When one wants to do a global search in th whole document
115  */
116 #define HERAIA_FIND_FORWARD 32
117 #define HERAIA_FIND_BACKWARD 64
118 #define HERAIA_FIND_ALL 128
119 
120 
121 /**
122  * @struct date_and_time_t
123  * A human struct to store a date with a time.
124  * @todo add an UTC info field
125  */
126 typedef struct
127 {
128  guint32 year;
129  guint32 month;
130  guint32 day;
131 
132  guint32 hour;
133  guint32 minutes;
134  guint32 seconds;
136 
137 
138 /** Templates for the decoding functions */
139 typedef gchar *(* DecodeFunc) (guchar *, gpointer); /**< Decode function template */
140 
141 
142 /**
143  * @struct decode_parameters_t
144  * Used to pass decoding options to the functions. Those options are evaluated
145  * from data_interpretor's window
146  */
147 typedef struct
148 {
149  guint endianness; /**< endianness */
150  guint stream_size; /**< stream_size */
152 
153 
154 /**
155  * @struct decode_t
156  * Basic way to associate a decode function and an entry that will receive the
157  * result
158  * @warning this structure is subject to changes
159  */
160  typedef struct
161  {
162  DecodeFunc func; /**< a function to decode into something */
163  GtkWidget *entry; /**< the widget that will receive the result */
164  gchar *err_msg; /**< error message if something went wrong when decoding
165  expects a %d somewhere in the message to represents
166  the stream lenght to be decoded */
167  } decode_t;
168 
169 
170 /**
171  * @struct decode_generic_t
172  * Basic way to have as many as we want decoding functions corresponding to one
173  * label. This structure is basicaly one row in the data intrepretor window
174  * @warning this structure is subject to changes
175  */
176  typedef struct
177  {
178  GPtrArray *decode_array; /**< Pointer Array of decode_t functions and corresponding entries */
179  GtkWidget *label; /**< label for these decoding functions */
180  guint data_size; /**< size of what we may decode */
181  gboolean fixed_size; /**< says whether we can modify data_size or not */
183 
184 
185 /**
186  * @struct tab_t
187  * Tabulation structure to be used in the GtkNoteBook of
188  * data_interpretor's window
189  */
190 typedef struct
191 {
192  guint index; /**< number for this tab */
193  guint nb_cols; /**< number of columns in this tab - this MUST NOT change in any way */
194  guint nb_rows; /**< number of rows in this tab - this is automatically updated */
195  GtkWidget *label; /**< label for this tab */
196  GPtrArray *col_labels; /**< array of GtkWidgets of columns labels */
197  GPtrArray *vboxes; /**< array of vboxes where we will pack label and entry widgets */
198  GPtrArray *rows; /**< array of pointers to decode_generic_t variables. */
199 } tab_t;
200 
201 
202 /**
203  * @struct data_window_t
204  * Data interpretor window structure
205  */
206 typedef struct
207 {
208  GtkWidget *diw; /**< data interpretor window */
209  gint tab_displayed; /**< keeps the last displayed tab's number before closing */
210  guint nb_tabs; /**< keeps Number of tabs in the GPtrArray */
211  GPtrArray *tabs; /**< an array of tabs displayed in data interpretor's notebook (tab_t) */
212 } data_window_t;
213 
214 
215 /**
216  * @struct xml_t
217  * Structure that contains all the xml definitions loaded at
218  * running time using GtkBuilder
219  */
220 typedef struct
221 {
222  GtkBuilder *main; /**< the main interface xml description */
223 } xml_t;
224 
225 
226 /**
227  * @def WPT_DEFAULT_HEIGHT
228  * Defines the default height for a window (set in window_prop_t)
229  *
230  * @def WPT_DEFAULT_WIDTH
231  * Defines the default width for a window (set in window_prop_t)
232  */
233 #define WPT_DEFAULT_HEIGHT 200
234 #define WPT_DEFAULT_WIDTH 200
235 
236 
237 /**
238  * @struct window_prop_t
239  * Window properties
240  * - position (x,y) record window's position
241  * - displayed (boolean) say whether the window is displayed or not
242  */
243 typedef struct
244 {
245  gint x; /**< x position (upper left corner) */
246  gint y; /**< y position (upper left corner) */
247  guint height; /**< y+height (bottom right corner) */
248  guint width; /**< x+width (bottom right corner) */
249  gboolean displayed; /**< TRUE if displayed, FALSE otherwise */
250 } window_prop_t;
251 
252 
253 /**
254  * @struct all_window_prop_t
255  * Structure to keep window properties for each window
256  * @todo Transform this to a list of properties and add values to distinguish
257  * between windows ?
258  */
259 typedef struct
260 {
262  window_prop_t *data_interpretor; /**< data interpretor window */
263  window_prop_t *log_box; /**< log window */
264  window_prop_t *main_dialog; /**< heraia's main window */
265  window_prop_t *plugin_list; /**< plugin description window */
266  window_prop_t *ldt; /**< list data types window */
267  window_prop_t *main_pref_window; /**< main preference window */
268  window_prop_t *goto_window; /**< goto dialog window */
269  window_prop_t *result_window; /**< result window properties */
270  window_prop_t *find_window; /**< find window */
271  window_prop_t *fr_window; /**< find and replace window */
272  window_prop_t *fdft_window; /**< find data from type window */
274 
275 
276 /**
277  * @struct prefs_t
278  * Data type related to preferences
279  */
280 typedef struct
281 {
282  gchar *filename; /**< user preference file file name */
283  gchar *pathname; /**< user preference file path name */
284  GKeyFile *file; /**< preference file contents */
285 } prefs_t;
286 
287 
288 /**
289  * @struct doc_t
290  * Proposal for a structure that will group all informations about
291  * a single document. This structure is managed in heraia_io.c
292  */
293 typedef struct
294 {
295  Heraia_Document *hex_doc; /**< Document definition related to Heraia_Hex (GtkHex) */
296  GtkWidget *hex_widget; /**< hexwidget corresponding to the document */
297  gboolean modified; /**< If hex_doc->changed <> modified then the
298  document has something changed that may need
299  an upate */
300 } doc_t;
301 
302 
303 /**
304  * @struct selection_t
305  * A structure to manage a single selection
306  */
307 typedef struct
308 {
309  guint64 start; /**< Starting position of the selection */
310  guint64 end; /**< Ending position of the selection */
311 } selection_t;
312 
313 
314 /**
315  * @struct
316  * A structure to manage the find data type window
317  */
318 typedef struct
319 {
320  GtkWidget *category_cb; /** ComboBox Widget for the category of the search */
321  GtkWidget *type_cb; /** ComboBox Widget for the type of the data in the category */
322  GtkWidget *feature_cb; /** ComboBox Widget for the feature related to the type of the data */
323 } fdft_t;
324 
325 
326 /**
327  * @struct heraia_struct_t
328  * This is the main structure. It contains all things that the program needs
329  * results GPtrArray stores the pointer of the corresponding document from
330  * which the search took place.
331  */
332 typedef struct
333 {
334  gboolean debug; /**< Used to tell the program wether we want to display debug messages or not */
335  doc_t *current_doc; /**< This is a pointer to the current edited document */
336  GPtrArray *documents; /**< An array of doc_t in order to be able to open more than one doc */
337  xml_t *xmls; /**< All the xmls used in the program, loaded at running time */
338  data_window_t *current_DW; /**< data_interpretor pointer */
339  GList *location_list; /**< this is the location list where we store some paths */
340  GList *plugins_list; /**< A list of plugins */
341  RefreshType event; /**< Tells what is happening */
342  all_window_prop_t *win_prop; /**< Keeps window properties */
343  prefs_t *prefs; /**< All datas related to main preferences */
344  doc_t *find_doc; /**< find document and hexwidget for find window */
345  doc_t *fr_find_doc; /**< find and replace window, find document and hexwidget */
346  doc_t *fr_replace_doc; /**< find and replace window, replace document and hexwidget */
347  fdft_t *fdft; /**< Keeps comboboxes created for the fdft window */
348  GPtrArray *results; /**< An array of pointers (doc_t *) for each tab in the result window. */
350 
351 
352 #include "data_interpretor.h"
353 #include "decode.h"
354 #include "ghex_heraia_interface.h"
355 #include "heraia_errors.h"
356 #include "heraia_io.h"
357 #include "heraia_ui.h"
358 #include "log.h"
359 #include "main_pref_window.h"
360 #include "plugin.h"
361 #include "plugin_list.h"
362 #include "user_prefs.h"
363 #include "tests.h"
364 #include "goto_dialog.h"
365 #include "result_window.h"
366 #include "find_replace_window.h"
367 
368 
369 extern int libheraia_test(void);
370 
371 /**
372  * Python specific
373  */
374 extern void libheraia_initialize(void);
375 extern void libheraia_finalize(void);
376 
377 #endif /* _LIBHERAIA_H_ */
Header file providing an interface to Heraia_Hex.
window_prop_t * find_window
find window
Definition: libheraia.h:270
GPtrArray * results
An array of pointers (doc_t *) for each tab in the result window.
Definition: libheraia.h:348
This is the main structure.
Definition: libheraia.h:332
Window properties.
Definition: libheraia.h:243
window_prop_t * data_interpretor
data interpretor window
Definition: libheraia.h:262
doc_t * fr_find_doc
find and replace window, find document and hexwidget
Definition: libheraia.h:345
gint x
x position (upper left corner)
Definition: libheraia.h:245
gboolean fixed_size
says whether we can modify data_size or not
Definition: libheraia.h:181
GtkWidget * feature_cb
ComboBox Widget for the type of the data in the category.
Definition: libheraia.h:322
gchar * err_msg
error message if something went wrong when decoding expects a d somewhere in the message to represent...
Definition: libheraia.h:164
Tabulation structure to be used in the GtkNoteBook of data_interpretor's window.
Definition: libheraia.h:190
window_prop_t * result_window
result window properties
Definition: libheraia.h:269
gint tab_displayed
keeps the last displayed tab's number before closing
Definition: libheraia.h:209
window_prop_t * fr_window
find and replace window
Definition: libheraia.h:271
GtkWidget * type_cb
ComboBox Widget for the category of the search.
Definition: libheraia.h:321
RefreshType event
Tells what is happening.
Definition: libheraia.h:341
Header file where plugin definitions are sat.
window_prop_t * main_dialog
heraia's main window
Definition: libheraia.h:264
gboolean displayed
TRUE if displayed, FALSE otherwise.
Definition: libheraia.h:249
gchar * filename
user preference file file name
Definition: libheraia.h:282
window_prop_t * plugin_list
plugin description window
Definition: libheraia.h:265
Header file for user preferences.
GtkWidget * category_cb
Definition: libheraia.h:320
guint data_size
size of what we may decode
Definition: libheraia.h:180
Header for decoding things (numbers, dates, binary, ...)
DecodeFunc func
a function to decode into something
Definition: libheraia.h:162
guint nb_rows
number of rows in this tab - this is automatically updated
Definition: libheraia.h:194
all_window_prop_t * win_prop
Keeps window properties.
Definition: libheraia.h:342
window_prop_t * main_pref_window
main preference window
Definition: libheraia.h:267
GtkWidget * label
label for this tab
Definition: libheraia.h:195
window_prop_t * fdft_window
find data from type window
Definition: libheraia.h:272
Data interpretor window structure.
Definition: libheraia.h:206
fdft_t * fdft
Keeps comboboxes created for the fdft window.
Definition: libheraia.h:347
Header file for handling errors.
Proposal for a structure that will group all informations about a single document.
Definition: libheraia.h:293
guint64 start
Starting position of the selection.
Definition: libheraia.h:309
GtkHex Heraia_Hex
Abstract layer this may be usefull if we decide to leave Heraia_Hex and use something else ! ...
Definition: libheraia.h:77
guint32 year
Definition: libheraia.h:128
Heraia_Document * hex_doc
Document definition related to Heraia_Hex (GtkHex)
Definition: libheraia.h:295
A structure to manage a single selection.
Definition: libheraia.h:307
guint64 end
Ending position of the selection.
Definition: libheraia.h:310
xml_t * xmls
All the xmls used in the program, loaded at running time.
Definition: libheraia.h:337
gchar * pathname
user preference file path name
Definition: libheraia.h:283
Data type related to preferences.
Definition: libheraia.h:280
GKeyFile * file
preference file contents
Definition: libheraia.h:284
Header file for the plugin list window.
guint32 month
Definition: libheraia.h:129
gboolean debug
Used to tell the program wether we want to display debug messages or not.
Definition: libheraia.h:334
A human struct to store a date with a time.
Definition: libheraia.h:126
window_prop_t * ldt
list data types window
Definition: libheraia.h:266
guint32 seconds
Definition: libheraia.h:134
int libheraia_test(void)
A simple test function.
Definition: libheraia.c:56
Header file for file operations.
GPtrArray * vboxes
array of vboxes where we will pack label and entry widgets
Definition: libheraia.h:197
window_prop_t * about_box
Definition: libheraia.h:261
prefs_t * prefs
All datas related to main preferences.
Definition: libheraia.h:343
Basic way to associate a decode function and an entry that will receive the result.
Definition: libheraia.h:160
void libheraia_finalize(void)
Definition: libheraia.c:67
GtkWidget * hex_widget
hexwidget corresponding to the document
Definition: libheraia.h:296
gint y
y position (upper left corner)
Definition: libheraia.h:246
guint32 hour
Definition: libheraia.h:132
void libheraia_initialize(void)
Python specific.
Definition: libheraia.c:62
GtkBuilder * main
the main interface xml description
Definition: libheraia.h:222
Structure to keep window properties for each window.
Definition: libheraia.h:259
gchar *(* DecodeFunc)(guchar *, gpointer)
Templates for the decoding functions.
Definition: libheraia.h:139
GPtrArray * decode_array
Pointer Array of decode_t functions and corresponding entries.
Definition: libheraia.h:178
gint HERAIA_ERROR
Defines heraia error type (this should be used !)
Definition: libheraia.h:78
GList * plugins_list
A list of plugins.
Definition: libheraia.h:340
data_window_t * current_DW
data_interpretor pointer
Definition: libheraia.h:338
HexDocument Heraia_Document
Abstract layer this may be usefull if we decide to leave Heraia_Hex and use something else ! ...
Definition: libheraia.h:76
GPtrArray * tabs
an array of tabs displayed in data interpretor's notebook (tab_t)
Definition: libheraia.h:211
window_prop_t * log_box
log window
Definition: libheraia.h:263
Header file for tests (code coverage and bug tracking)
Header file for the result window.
GPtrArray * col_labels
array of GtkWidgets of columns labels
Definition: libheraia.h:196
GtkWidget * label
label for these decoding functions
Definition: libheraia.h:179
Header file that handles preference window.
guint height
y+height (bottom right corner)
Definition: libheraia.h:247
Structure that contains all the xml definitions loaded at running time using GtkBuilder.
Definition: libheraia.h:220
Header file for the goto dialog window.
GtkWidget * diw
data interpretor window
Definition: libheraia.h:208
guint nb_tabs
keeps Number of tabs in the GPtrArray
Definition: libheraia.h:210
doc_t * current_doc
This is a pointer to the current edited document.
Definition: libheraia.h:335
window_prop_t * goto_window
goto dialog window
Definition: libheraia.h:268
guint32 minutes
Definition: libheraia.h:133
gint RefreshType
Refresh type (may be used to decide what to do in a particular case)
Definition: libheraia.h:99
GtkWidget * entry
the widget that will receive the result
Definition: libheraia.h:163
doc_t * find_doc
find document and hexwidget for find window
Definition: libheraia.h:344
guint index
number for this tab
Definition: libheraia.h:192
guint width
x+width (bottom right corner)
Definition: libheraia.h:248
Header file for the data interpretor.
GPtrArray * documents
An array of doc_t in order to be able to open more than one doc.
Definition: libheraia.h:336
gboolean modified
If hex_doc->changed <> modified then the document has something changed that may need an upate...
Definition: libheraia.h:297
guint stream_size
stream_size
Definition: libheraia.h:150
Header file for the logging subsystem.
Header file for menu, callbacks, utility functions and ui management.
guint endianness
endianness
Definition: libheraia.h:149
Basic way to have as many as we want decoding functions corresponding to one label.
Definition: libheraia.h:176
GList * location_list
this is the location list where we store some paths
Definition: libheraia.h:339
doc_t * fr_replace_doc
find and replace window, replace document and hexwidget
Definition: libheraia.h:346
Used to pass decoding options to the functions.
Definition: libheraia.h:147
GPtrArray * rows
array of pointers to decode_generic_t variables.
Definition: libheraia.h:198
guint nb_cols
number of columns in this tab - this MUST NOT change in any way
Definition: libheraia.h:193