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 - 2009 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 * file. This is not very friendly, but ease compilation on exotic 00028 * systems. 00029 */ 00030 #ifndef _LIBHERAIA_H_ 00031 #define _LIBHERAIA_H_ 00032 00033 #include <stdio.h> 00034 #include <stdlib.h> 00035 #include <string.h> 00036 #include <time.h> 00037 #include <unistd.h> 00038 #include <sys/types.h> 00039 #include <sys/stat.h> 00040 #include <getopt.h> 00041 00042 #include <glib.h> 00043 #include <glib/gstdio.h> 00044 #include <glade/glade.h> 00045 #include <gmodule.h> 00046 00047 #include <gtkhex/gtkhex.h> 00048 00049 /** 00050 * @typedef HexDocument Heraia_Document 00051 * Abstract layer this may be usefull if we decide to leave GtkHex 00052 * and use something else ! 00053 * 00054 * @typedef GtkHex Heraia_Hex 00055 * Abstract layer this may be usefull if we decide to leave GtkHex 00056 * and use something else ! 00057 */ 00058 /** 00059 * @typedef gint HERAIA_ERROR 00060 * Defines heraia error type (this should be used !) 00061 */ 00062 typedef HexDocument Heraia_Document; 00063 typedef GtkHex Heraia_Hex; 00064 typedef gint HERAIA_ERROR; 00065 00066 /** 00067 * @typedef gint RefreshType 00068 * Refresh type (may be used to decide what to do 00069 * in a particular case) 00070 * @warning This is not thread safe !! 00071 */ 00072 /** 00073 * @def HERAIA_REFRESH_NOTHING 00074 * When nothing is refreshed 00075 * 00076 * @def HERAIA_REFRESH_NEW_FILE 00077 * When a new file has been loaded 00078 * 00079 * @def HERAIA_REFRESH_CURSOR_MOVE 00080 * When the cursor is moving 00081 * 00082 * @def HERAIA_REFRESH_TAB_CHANGED 00083 * When user selects another tab in main notebook 00084 */ 00085 typedef gint RefreshType; 00086 #define HERAIA_REFRESH_NOTHING 0 00087 #define HERAIA_REFRESH_NEW_FILE 1 00088 #define HERAIA_REFRESH_CURSOR_MOVE 2 00089 #define HERAIA_REFRESH_TAB_CHANGED 3 00090 00091 /** 00092 * @struct date_and_time_t 00093 * A human struct to store a date with a time. 00094 * @todo add an UTC info field 00095 */ 00096 typedef struct 00097 { 00098 guint32 year; 00099 guint32 month; 00100 guint32 day; 00101 00102 guint32 hour; 00103 guint32 minutes; 00104 guint32 seconds; 00105 } date_and_time_t; 00106 00107 00108 /** Templates for the decoding functions */ 00109 typedef gchar *(* DecodeFunc) (guchar *, gpointer); /**< Decode function template */ 00110 00111 /** 00112 * @struct decode_parameters_t 00113 * Used to pass decoding options to the functions. Those options are evaluated 00114 * from data_interpretor's window 00115 */ 00116 typedef struct 00117 { 00118 guint endianness; /**< endianness */ 00119 guint stream_size; /**< stream_size */ 00120 } decode_parameters_t; 00121 00122 /** 00123 * @struct decode_t 00124 * Basic way to associate a decode function and an entry that will receive the 00125 * result 00126 * @warning this structure is subject to changes 00127 */ 00128 typedef struct 00129 { 00130 DecodeFunc func; /**< a function to decode into something */ 00131 GtkWidget *entry; /**< the widget that will receive the result */ 00132 } decode_t; 00133 00134 00135 /** 00136 * @struct decode_generic_t 00137 * Basic way to have as many as we want decoding functions corresponding to one 00138 * label. This Structure is basicaly one row in the data intrepretor window 00139 * @warning this structure is subject to changes 00140 */ 00141 typedef struct 00142 { 00143 GPtrArray *decode_array; /**< Pointer Array of decode_t functions and corresponding entries */ 00144 GtkWidget *label; /**< label for these decoding functions */ 00145 guint data_size; /**< size of what we may decode */ 00146 gboolean fixed_size; /**< says whether we can modify data_size or not */ 00147 } decode_generic_t; 00148 00149 00150 /** 00151 * @struct tab_t 00152 * Tabulation structure to be used in the GtkNoteBook of 00153 * data_interpretor's window 00154 */ 00155 typedef struct 00156 { 00157 guint index; /**< number for this tab */ 00158 guint nb_cols; /**< number of columns in this tab - this MUST NOT change in any way */ 00159 guint nb_rows; /**< number of rows in this tab - this is automatically updated */ 00160 GtkWidget *label; /**< label for this tab */ 00161 GPtrArray *col_labels; /**< array of GtkWidgets of columns labels */ 00162 GPtrArray *vboxes; /**< array of vboxes where we will pack label and entry widgets */ 00163 GPtrArray *rows; /**< array of pointers to decode_generic_t variables. */ 00164 } tab_t; 00165 00166 /** 00167 * @struct data_window_t 00168 * Data interpretor window structure 00169 */ 00170 typedef struct 00171 { 00172 /** Current Hexwidget that we want data to be interpreted */ 00173 GtkWidget *current_hexwidget; /** @todo we may want to move this from here to heraia_window_t structure. This should not be used anymore */ 00174 GtkWidget *diw; /**< data interpretor window */ 00175 gint tab_displayed; /**< keeps the last displayed tab's number before closing */ 00176 guint nb_tabs; /**< keeps Number of tabs in the GPtrArray */ 00177 GPtrArray *tabs; /**< an array of tabs displayed in data interpretor's notebook */ 00178 } data_window_t; 00179 00180 /* Treatment Stuff (if one wants to add new data types) */ 00181 typedef GList *(* TreatmentDoFunc) (GList *); /**< Treatment function called while operating the treatment */ 00182 typedef void (* TreatmentInitFunc) (gpointer); /**< Treatment init function */ 00183 typedef void (* TreatmentDelFunc) (gpointer); /**< Treatment delete function */ 00184 typedef gpointer (*TreatmentCopyFunc) (gpointer); /**< Treatment copy function that have to copy internal 00185 structures (widgets and all stuff in it) */ 00186 /** 00187 * @struct treatment_t 00188 * Treatment structure 00189 * @warning I'm not happy with this struct and all data_type.c file. I plan 00190 * to replace thoses ugly things with an embedded scripting language 00191 * such as python. 00192 */ 00193 typedef struct 00194 { 00195 gchar *name; /**< Treatment name */ 00196 TreatmentDoFunc do_it; /**< Treatment function that manages the whole treatment (interface + treatment itself) */ 00197 TreatmentInitFunc init; /**< inits the interface */ 00198 TreatmentDelFunc kill; /**< kills the treatment itself */ 00199 TreatmentCopyFunc copy; /**< Copy the gpointer data sub structure of the treatment itself */ 00200 gpointer data; /**< Generic treatment data. Each instantiated treatment may have it's own */ 00201 } treatment_t; 00202 00203 /** 00204 * @struct treatment_container_t 00205 * Structure in order to contain one treatment 00206 * @warning I'm not happy with this struct and all data_type.c file. I plan 00207 * to replace thoses ugly things with an embedded scripting language 00208 * such as python. 00209 */ 00210 typedef struct 00211 { 00212 GtkWidget *container_box; /**< Upper box containing the whole stuff */ 00213 GtkWidget *button_box; /**< Right part of the hbox. Contains "-", GtkEntry, "+" */ 00214 GtkWidget *combo_box; /**< Left box where we have the combobox */ 00215 GtkWidget *tment_list; /**< Combobox containning the treatment list */ 00216 GtkWidget *result; /**< The GtkEntry in the vbox */ 00217 GtkWidget *moins; /**< "-" button */ 00218 GtkWidget *plus; /**< "+" button */ 00219 treatment_t *treatment; /**< Selected treatment */ 00220 } treatment_container_t; 00221 00222 /** 00223 * @struct data_type_t 00224 * Data type structure entry that contains user defined data types 00225 * This is integrated within a GList. 00226 * !! Do not forget to update the functions related to this such as 00227 * - new_data_type 00228 * - free_data_type 00229 * - copy_data_type 00230 * See data_type.c for thoses functions 00231 * @warning I'm not happy with this struct and all data_type.c file. I plan 00232 * to replace thoses ugly things with an embedded scripting language 00233 * such as python. 00234 */ 00235 typedef struct 00236 { 00237 gchar *name; /**< Name of the data type */ 00238 guint size; /**< size of the data type (here we may limit size entry, eg <= 16 for example) */ 00239 GList *treatment_c_list; /**< Treatments containers to be applied (in the list order) to the data 00240 (treatment_container_t *) */ 00241 GtkWidget *di_label; /**< label for the data_interpretor window */ 00242 GtkWidget *di_entry; /**< entry for the data interpretor window */ 00243 } data_type_t; 00244 00245 00246 /** 00247 * @struct xml_t 00248 * Structure that contains all the xml definitions loaded at 00249 * running time using libglade 00250 */ 00251 typedef struct 00252 { 00253 GladeXML *main; /**< the main interface xml description */ 00254 } xml_t; 00255 00256 00257 /** 00258 * @def WPT_DEFAULT_HEIGHT 00259 * Defines the default height for a window (set in window_prop_t) 00260 * 00261 * @def WPT_DEFAULT_WIDTH 00262 * Defines the default width for a window (set in window_prop_t) 00263 */ 00264 #define WPT_DEFAULT_HEIGHT 200 00265 #define WPT_DEFAULT_WIDTH 200 00266 00267 /** 00268 * @struct window_prop_t 00269 * Window properties 00270 * - position (x,y) record window's position 00271 * - displayed (boolean) say whether the window is displayed or not 00272 */ 00273 typedef struct 00274 { 00275 gint x; /**< x position (upper left corner) */ 00276 gint y; /**< y position (upper left corner) */ 00277 guint height; /**< y+height (bottom right corner) */ 00278 guint width; /**< x+width (bottom right corner) */ 00279 gboolean displayed; /**< TRUE if displayed, FALSE otherwise */ 00280 } window_prop_t; 00281 00282 /** 00283 * @struct all_window_prop_t 00284 * Structure to keep window properties for each window 00285 */ 00286 typedef struct 00287 { 00288 window_prop_t *about_box; 00289 window_prop_t *data_interpretor; /**< data interpretor window */ 00290 window_prop_t *log_box; /**< log window */ 00291 window_prop_t *main_dialog; /**< heraia's main window */ 00292 window_prop_t *plugin_list; /**< plugin description window */ 00293 window_prop_t *ldt; /**< list data types window */ 00294 window_prop_t *main_pref_window; /**< main preference window */ 00295 } all_window_prop_t; 00296 00297 /** 00298 * @struct prefs_t 00299 * Data type related to preferences 00300 */ 00301 typedef struct 00302 { 00303 gchar *filename; /**< user preference file file name */ 00304 gchar *pathname; /**< user preference file path name */ 00305 GKeyFile *file; /**< preference file contents */ 00306 } prefs_t; 00307 00308 00309 /** 00310 * @struct doc_t 00311 * Proposal for a structure that will group all informations about 00312 * a single document. This structure is managed in heraia_io.c 00313 */ 00314 typedef struct 00315 { 00316 Heraia_Document *hex_doc; /**< Document definition related to libgtkhex */ 00317 GtkWidget *hex_widget; /**< hexwidget corresponding to the document */ 00318 } doc_t; 00319 00320 00321 /** 00322 * @struct heraia_window_t 00323 * This is the main structure (mainly named main_window due to historycal reasons) 00324 * It contains all things that the program needs 00325 */ 00326 typedef struct 00327 { 00328 gboolean debug; /**< Used to tell the program wether we want to display debug messages or not */ 00329 doc_t *current_doc; /**< This is a pointer to the current edited document */ 00330 GPtrArray *documents; /**< An array of doc_t in order to be able to open more than one doc */ 00331 xml_t *xmls; /**< All the xmls used in the program, loaded at running time */ 00332 data_window_t *current_DW; /**< data_interpretor pointer */ 00333 GList *location_list; /**< this is the location list where we store some paths */ 00334 GList *plugins_list; /**< A list of plugins */ 00335 GList *data_type_list; /**< A list of data types */ 00336 data_type_t *current_data_type; /**< data type that is being edited */ 00337 GList *available_treatment_list;/**< Available treatments that can be used by the user in the data type window */ 00338 RefreshType event; /**< Tells what is happening */ 00339 all_window_prop_t *win_prop; /**< Keeps window properties */ 00340 prefs_t *prefs; /**< All datas related to main preferences */ 00341 } heraia_window_t; 00342 00343 #include "config.h" 00344 #include "data_interpretor.h" 00345 #include "data_type.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 "list_data_types.h" 00352 #include "log.h" 00353 #include "main_pref_window.h" 00354 #include "plugin.h" 00355 #include "plugin_list.h" 00356 #include "treatments.h" 00357 #include "user_prefs.h" 00358 00359 extern int libheraia_test(void); 00360 00361 /** 00362 * Python specific 00363 */ 00364 extern void libheraia_initialize(void); 00365 extern void libheraia_finalize(void); 00366 00367 #endif /* _LIBHERAIA_H_ */