00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ 00002 /* 00003 libheraia.h 00004 Heraia's library header 00005 00006 (C) Copyright 2008 - 2011 Sébastien Tricaud, Olivier Delhomme 00007 e-mail : heraia@delhomme.org 00008 URL : http://heraia.tuxfamily.org 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 2, or (at your option) 00013 any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 00023 /** 00024 * @file libheraia.h 00025 * 00026 * This file contains all the definitions and includes all other .h 00027 * files. This is not very friendly, but ease compilation on exotic 00028 * systems. 00029 */ 00030 #ifndef _LIBHERAIA_H_ 00031 #define _LIBHERAIA_H_ 00032 00033 /* I have some problems under windows if #ifdef statement is activated */ 00034 00035 /* #ifdef HAVE_CONFIG_H */ 00036 #include "config.h" 00037 /* #endif */ /* HAVE_CONFIG_H */ 00038 00039 00040 #include <stdio.h> 00041 #include <stdlib.h> 00042 #include <string.h> 00043 #include <time.h> 00044 #include <unistd.h> 00045 #include <sys/types.h> 00046 #include <sys/stat.h> 00047 #include <getopt.h> 00048 00049 #include <glib.h> 00050 #include <glib/gstdio.h> 00051 #include <glib/gi18n-lib.h> 00052 #include <gmodule.h> 00053 00054 #include <gtkhex/gtkhex.h> 00055 00056 /** 00057 * @typedef HexDocument Heraia_Document 00058 * Abstract layer this may be usefull if we decide to leave Heraia_Hex 00059 * and use something else ! 00060 * 00061 * @typedef GtkHex Heraia_Hex 00062 * Abstract layer this may be usefull if we decide to leave Heraia_Hex 00063 * and use something else ! 00064 */ 00065 /** 00066 * @typedef gint HERAIA_ERROR 00067 * Defines heraia error type (this should be used !) 00068 */ 00069 typedef HexDocument Heraia_Document; 00070 typedef GtkHex Heraia_Hex; 00071 typedef gint HERAIA_ERROR; 00072 00073 /** 00074 * @typedef gint RefreshType 00075 * Refresh type (may be used to decide what to do 00076 * in a particular case) 00077 * @warning This is not thread safe !! 00078 */ 00079 /** 00080 * @def HERAIA_REFRESH_NOTHING 00081 * When nothing is refreshed 00082 * 00083 * @def HERAIA_REFRESH_NEW_FILE 00084 * When a new file has been loaded 00085 * 00086 * @def HERAIA_REFRESH_CURSOR_MOVE 00087 * When the cursor is moving 00088 * 00089 * @def HERAIA_REFRESH_TAB_CHANGED 00090 * When user selects another tab in main notebook 00091 */ 00092 typedef gint RefreshType; 00093 #define HERAIA_REFRESH_NOTHING 0 00094 #define HERAIA_REFRESH_NEW_FILE 1 00095 #define HERAIA_REFRESH_CURSOR_MOVE 2 00096 #define HERAIA_REFRESH_TAB_CHANGED 3 00097 00098 00099 /** 00100 * @def HERAIA_FIND_FORWARD 00101 * When one wants to do a search in the forward direction 00102 * 00103 * @def HERAIA_FIND_BACKWARD 00104 * When one wants to do a search in the backward direction 00105 * 00106 * @def HERAIA_FIND_ALL 00107 * When one wants to do a global search in th whole document 00108 */ 00109 #define HERAIA_FIND_FORWARD 32 00110 #define HERAIA_FIND_BACKWARD 64 00111 #define HERAIA_FIND_ALL 128 00112 00113 00114 /** 00115 * @struct date_and_time_t 00116 * A human struct to store a date with a time. 00117 * @todo add an UTC info field 00118 */ 00119 typedef struct 00120 { 00121 guint32 year; 00122 guint32 month; 00123 guint32 day; 00124 00125 guint32 hour; 00126 guint32 minutes; 00127 guint32 seconds; 00128 } date_and_time_t; 00129 00130 00131 /** Templates for the decoding functions */ 00132 typedef gchar *(* DecodeFunc) (guchar *, gpointer); /**< Decode function template */ 00133 00134 00135 /** 00136 * @struct decode_parameters_t 00137 * Used to pass decoding options to the functions. Those options are evaluated 00138 * from data_interpretor's window 00139 */ 00140 typedef struct 00141 { 00142 guint endianness; /**< endianness */ 00143 guint stream_size; /**< stream_size */ 00144 } decode_parameters_t; 00145 00146 00147 /** 00148 * @struct decode_t 00149 * Basic way to associate a decode function and an entry that will receive the 00150 * result 00151 * @warning this structure is subject to changes 00152 */ 00153 typedef struct 00154 { 00155 DecodeFunc func; /**< a function to decode into something */ 00156 GtkWidget *entry; /**< the widget that will receive the result */ 00157 gchar *err_msg; /**< error message if something went wrong when decoding 00158 expects a %d somewhere in the message to represents 00159 the stream lenght to be decoded */ 00160 } decode_t; 00161 00162 00163 /** 00164 * @struct decode_generic_t 00165 * Basic way to have as many as we want decoding functions corresponding to one 00166 * label. This structure is basicaly one row in the data intrepretor window 00167 * @warning this structure is subject to changes 00168 */ 00169 typedef struct 00170 { 00171 GPtrArray *decode_array; /**< Pointer Array of decode_t functions and corresponding entries */ 00172 GtkWidget *label; /**< label for these decoding functions */ 00173 guint data_size; /**< size of what we may decode */ 00174 gboolean fixed_size; /**< says whether we can modify data_size or not */ 00175 } decode_generic_t; 00176 00177 00178 /** 00179 * @struct tab_t 00180 * Tabulation structure to be used in the GtkNoteBook of 00181 * data_interpretor's window 00182 */ 00183 typedef struct 00184 { 00185 guint index; /**< number for this tab */ 00186 guint nb_cols; /**< number of columns in this tab - this MUST NOT change in any way */ 00187 guint nb_rows; /**< number of rows in this tab - this is automatically updated */ 00188 GtkWidget *label; /**< label for this tab */ 00189 GPtrArray *col_labels; /**< array of GtkWidgets of columns labels */ 00190 GPtrArray *vboxes; /**< array of vboxes where we will pack label and entry widgets */ 00191 GPtrArray *rows; /**< array of pointers to decode_generic_t variables. */ 00192 } tab_t; 00193 00194 00195 /** 00196 * @struct data_window_t 00197 * Data interpretor window structure 00198 */ 00199 typedef struct 00200 { 00201 GtkWidget *diw; /**< data interpretor window */ 00202 gint tab_displayed; /**< keeps the last displayed tab's number before closing */ 00203 guint nb_tabs; /**< keeps Number of tabs in the GPtrArray */ 00204 GPtrArray *tabs; /**< an array of tabs displayed in data interpretor's notebook (tab_t) */ 00205 } data_window_t; 00206 00207 00208 /** 00209 * @struct xml_t 00210 * Structure that contains all the xml definitions loaded at 00211 * running time using GtkBuilder 00212 */ 00213 typedef struct 00214 { 00215 GtkBuilder *main; /**< the main interface xml description */ 00216 } xml_t; 00217 00218 00219 /** 00220 * @def WPT_DEFAULT_HEIGHT 00221 * Defines the default height for a window (set in window_prop_t) 00222 * 00223 * @def WPT_DEFAULT_WIDTH 00224 * Defines the default width for a window (set in window_prop_t) 00225 */ 00226 #define WPT_DEFAULT_HEIGHT 200 00227 #define WPT_DEFAULT_WIDTH 200 00228 00229 00230 /** 00231 * @struct window_prop_t 00232 * Window properties 00233 * - position (x,y) record window's position 00234 * - displayed (boolean) say whether the window is displayed or not 00235 */ 00236 typedef struct 00237 { 00238 gint x; /**< x position (upper left corner) */ 00239 gint y; /**< y position (upper left corner) */ 00240 guint height; /**< y+height (bottom right corner) */ 00241 guint width; /**< x+width (bottom right corner) */ 00242 gboolean displayed; /**< TRUE if displayed, FALSE otherwise */ 00243 } window_prop_t; 00244 00245 00246 /** 00247 * @struct all_window_prop_t 00248 * Structure to keep window properties for each window 00249 * @todo Transform this to a list of properties and add values to distinguish 00250 * between windows ? 00251 */ 00252 typedef struct 00253 { 00254 window_prop_t *about_box; 00255 window_prop_t *data_interpretor; /**< data interpretor window */ 00256 window_prop_t *log_box; /**< log window */ 00257 window_prop_t *main_dialog; /**< heraia's main window */ 00258 window_prop_t *plugin_list; /**< plugin description window */ 00259 window_prop_t *ldt; /**< list data types window */ 00260 window_prop_t *main_pref_window; /**< main preference window */ 00261 window_prop_t *goto_window; /**< goto dialog window */ 00262 window_prop_t *result_window; /**< result window properties */ 00263 window_prop_t *find_window; /**< find window */ 00264 window_prop_t *fr_window; /**< find and replace window */ 00265 window_prop_t *fdft_window; /**< find data from type window */ 00266 } all_window_prop_t; 00267 00268 00269 /** 00270 * @struct prefs_t 00271 * Data type related to preferences 00272 */ 00273 typedef struct 00274 { 00275 gchar *filename; /**< user preference file file name */ 00276 gchar *pathname; /**< user preference file path name */ 00277 GKeyFile *file; /**< preference file contents */ 00278 } prefs_t; 00279 00280 00281 /** 00282 * @struct doc_t 00283 * Proposal for a structure that will group all informations about 00284 * a single document. This structure is managed in heraia_io.c 00285 */ 00286 typedef struct 00287 { 00288 Heraia_Document *hex_doc; /**< Document definition related to Heraia_Hex (GtkHex) */ 00289 GtkWidget *hex_widget; /**< hexwidget corresponding to the document */ 00290 gboolean modified; /**< If hex_doc->changed <> modified then the 00291 document has something changed that may need 00292 an upate */ 00293 } doc_t; 00294 00295 00296 /** 00297 * @struct selection_t 00298 * A structure to manage a single selection 00299 */ 00300 typedef struct 00301 { 00302 guint64 start; /**< Starting position of the selection */ 00303 guint64 end; /**< Ending position of the selection */ 00304 } selection_t; 00305 00306 00307 /** 00308 * @struct 00309 * A structure to manage the find data type window 00310 */ 00311 typedef struct 00312 { 00313 GtkWidget *category_cb; /** ComboBox Widget for the category of the search */ 00314 GtkWidget *type_cb; /** ComboBox Widget for the type of the data in the category */ 00315 GtkWidget *feature_cb; /** ComboBox Widget for the feature related to the type of the data */ 00316 } fdft_t; 00317 00318 00319 /** 00320 * @struct heraia_struct_t 00321 * This is the main structure. It contains all things that the program needs 00322 * results GPtrArray stores the pointer of the corresponding document from 00323 * which the search took place. 00324 */ 00325 typedef struct 00326 { 00327 gboolean debug; /**< Used to tell the program wether we want to display debug messages or not */ 00328 doc_t *current_doc; /**< This is a pointer to the current edited document */ 00329 GPtrArray *documents; /**< An array of doc_t in order to be able to open more than one doc */ 00330 xml_t *xmls; /**< All the xmls used in the program, loaded at running time */ 00331 data_window_t *current_DW; /**< data_interpretor pointer */ 00332 GList *location_list; /**< this is the location list where we store some paths */ 00333 GList *plugins_list; /**< A list of plugins */ 00334 RefreshType event; /**< Tells what is happening */ 00335 all_window_prop_t *win_prop; /**< Keeps window properties */ 00336 prefs_t *prefs; /**< All datas related to main preferences */ 00337 doc_t *find_doc; /**< find document and hexwidget for find window */ 00338 doc_t *fr_find_doc; /**< find and replace window, find document and hexwidget */ 00339 doc_t *fr_replace_doc; /**< find and replace window, replace document and hexwidget */ 00340 fdft_t *fdft; /**< Keeps comboboxes created for the fdft window */ 00341 GPtrArray *results; /**< An array of pointers (doc_t *) for each tab in the result window. */ 00342 } heraia_struct_t; 00343 00344 00345 #include "data_interpretor.h" 00346 #include "decode.h" 00347 #include "ghex_heraia_interface.h" 00348 #include "heraia_errors.h" 00349 #include "heraia_io.h" 00350 #include "heraia_ui.h" 00351 #include "log.h" 00352 #include "main_pref_window.h" 00353 #include "plugin.h" 00354 #include "plugin_list.h" 00355 #include "user_prefs.h" 00356 #include "tests.h" 00357 #include "goto_dialog.h" 00358 #include "result_window.h" 00359 #include "find_replace_window.h" 00360 00361 00362 extern int libheraia_test(void); 00363 00364 /** 00365 * Python specific 00366 */ 00367 extern void libheraia_initialize(void); 00368 extern void libheraia_finalize(void); 00369 00370 #endif /* _LIBHERAIA_H_ */