00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <libheraia.h>
00025 #include "heraia_types.h"
00026
00027 static guint which_endianness(heraia_window_t *main_window);
00028 static void interpret_as_date(heraia_window_t *main_window, DecodeDateFunc decode_it, gchar *widget_name, guint length, guint endianness);
00029 static void interpret_as_number(heraia_window_t *main_window, DecodeFunc decode_it, gchar *widget_name, guint length, guint endianness);
00030 static void close_data_interpretor_window(GtkWidget *widget, gpointer data);
00031 static void connect_data_interpretor_signals(heraia_window_t *main_window);
00032
00037 static guint which_endianness(heraia_window_t *main_window)
00038 {
00039 GtkRadioButton *rb = GTK_RADIO_BUTTON(heraia_get_widget(main_window->xmls->main, "diw_rb_little_endian"));
00040 GtkWidget *activated = NULL;
00041 const gchar *widget_name = NULL;
00042
00043 activated = gtk_radio_button_get_active_from_widget(rb);
00044 widget_name = gtk_widget_get_name(activated);
00045
00046 if (g_ascii_strcasecmp(widget_name, "diw_rb_little_endian") == 0)
00047 {
00048 return H_DI_LITTLE_ENDIAN;
00049 }
00050 else if (g_ascii_strcasecmp(widget_name, "diw_rb_big_endian") == 0)
00051 {
00052 return H_DI_BIG_ENDIAN;
00053 }
00054 else if (g_ascii_strcasecmp(widget_name, "diw_rb_middle_endian") == 0)
00055 {
00056 return H_DI_MIDDLE_ENDIAN;
00057 }
00058 else
00059 return H_DI_LITTLE_ENDIAN;
00060 }
00061
00062
00072 static void interpret_as_date(heraia_window_t *main_window, DecodeDateFunc decode_it, gchar *widget_name, guint length, guint endianness)
00073 {
00074 gint result = 0;
00075 guchar *c = NULL;
00076 gchar *text = NULL;
00077 data_window_t *data_window = main_window->current_DW;
00078 GtkWidget *entry = heraia_get_widget(main_window->xmls->main, widget_name);
00079 date_and_time_t *mydate = NULL;
00080
00081 c = (guchar *) g_malloc0 (sizeof(guchar) * length);
00082 mydate = (date_and_time_t *) g_malloc0 (sizeof(date_and_time_t));
00083
00084 result = ghex_get_data(data_window, length, endianness, c);
00085
00086 if (result == TRUE)
00087 {
00088 text = decode_it(c, mydate);
00089
00090 if (text != NULL)
00091 {
00092 gtk_entry_set_text(GTK_ENTRY(entry), text);
00093 }
00094 else
00095 {
00096 text = g_strdup_printf("Something's wrong!");
00097 gtk_entry_set_text(GTK_ENTRY(entry), text);
00098 }
00099 }
00100 else
00101 {
00102 text = g_strdup_printf("Cannot interpret as a %d byte(s) date", length);
00103 gtk_entry_set_text(GTK_ENTRY(entry), text);
00104 }
00105
00106 g_free(c);
00107 g_free(text);
00108 }
00109
00110
00120 static void interpret_as_number(heraia_window_t *main_window, DecodeFunc decode_it, gchar *widget_name, guint length, guint endianness)
00121 {
00122 gint result = 0;
00123 guchar *c = NULL;
00124 gchar *text = NULL;
00125 data_window_t *data_window = main_window->current_DW;
00126 GtkWidget *entry = heraia_get_widget(main_window->xmls->main, widget_name);
00127
00128 c = (guchar *) g_malloc0(sizeof(guchar) * length);
00129
00130 result = ghex_get_data(data_window, length, endianness, c);
00131
00132 if (result == TRUE)
00133 {
00134 text = decode_it(c);
00135
00136 if (text != NULL)
00137 {
00138 gtk_entry_set_text(GTK_ENTRY(entry), text);
00139 }
00140 else
00141 {
00142 text = g_strdup_printf("Something's wrong!");
00143 gtk_entry_set_text(GTK_ENTRY(entry), text);
00144 }
00145 }
00146 else
00147 {
00148 text = g_strdup_printf("Cannot interpret as a %d byte(s) number", length);
00149 gtk_entry_set_text(GTK_ENTRY(entry), text);
00150 }
00151
00152 g_free(c);
00153 g_free(text);
00154 }
00155
00156
00161 static void close_data_interpretor_window(GtkWidget *widget, gpointer data)
00162 {
00163 heraia_window_t *main_window = (heraia_window_t *) data;
00164
00165 if (main_window != NULL && main_window->xmls != NULL && main_window->xmls->main)
00166 {
00167 g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "DIMenu"), "activate");
00168 }
00169 }
00170
00174 void refresh_data_interpretor_window(GtkWidget *widget, gpointer data)
00175 {
00176 heraia_window_t *main_window = (heraia_window_t *) data;
00177 guint endianness = 0;
00178
00179 if (main_window != NULL && main_window->current_DW != NULL && main_window->win_prop->main_dialog->displayed == TRUE)
00180 {
00181 endianness = which_endianness(main_window);
00182 interpret_as_number(main_window, decode_8bits_unsigned, "diw_8bits_us", 1, endianness);
00183 interpret_as_number(main_window, decode_8bits_signed, "diw_8bits_s", 1, endianness);
00184 interpret_as_number(main_window, decode_16bits_unsigned, "diw_16bits_us", 2, endianness);
00185 interpret_as_number(main_window, decode_16bits_signed, "diw_16bits_s", 2, endianness);
00186 interpret_as_number(main_window, decode_32bits_unsigned, "diw_32bits_us", 4, endianness);
00187 interpret_as_number(main_window, decode_32bits_signed, "diw_32bits_s", 4, endianness);
00188 interpret_as_number(main_window, decode_64bits_unsigned, "diw_64bits_us", 8, endianness);
00189 interpret_as_number(main_window, decode_64bits_signed, "diw_64bits_s", 8, endianness);
00190 interpret_as_number(main_window, decode_to_bits, "diw_base_bits", 1, endianness);
00191 interpret_as_number(main_window, decode_packed_BCD, "diw_base_bcd", 1, endianness);
00192
00193 interpret_as_date(main_window, decode_C_date, "diw_C_date", 4, endianness);
00194 interpret_as_date(main_window, decode_dos_date, "diw_msdos_date", 4, endianness);
00195 interpret_as_date(main_window, decode_filetime_date, "diw_filetime_date", 8, endianness);
00196 interpret_as_date(main_window, decode_HFS_date, "diw_HFS_date", 4, endianness);
00197
00198 refresh_all_ud_data_interpretor(main_window, endianness);
00199 }
00200 }
00201
00202
00207 static void connect_data_interpretor_signals(heraia_window_t *main_window)
00208 {
00209
00210 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "data_interpretor_window")), "delete_event",
00211 G_CALLBACK(delete_dt_window_event), main_window);
00212
00213 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "data_interpretor_window")), "destroy",
00214 G_CALLBACK(destroy_dt_window), main_window);
00215
00216
00217 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "diw_close_menu")), "activate",
00218 G_CALLBACK(close_data_interpretor_window), main_window);
00219
00220
00221 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "diw_rb_little_endian")), "toggled",
00222 G_CALLBACK(refresh_data_interpretor_window), main_window);
00223
00224
00225 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "diw_rb_big_endian")), "toggled",
00226 G_CALLBACK(refresh_data_interpretor_window), main_window);
00227
00228
00229 g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "diw_rb_middle_endian")), "toggled",
00230 G_CALLBACK(refresh_data_interpretor_window), main_window);
00231 }
00232
00238 void data_interpretor_init_interface(heraia_window_t *main_window)
00239 {
00240 data_window_t *dw = NULL;
00241
00242 if (main_window != NULL)
00243 {
00244
00245 connect_data_interpretor_signals(main_window);
00246
00247 dw = main_window->current_DW;
00248
00249 if (dw != NULL)
00250 {
00251
00252
00253 dw->diw = heraia_get_widget(main_window->xmls->main, "data_interpretor_window");
00254 dw->tab_displayed = 0;
00255 }
00256 }
00257 }