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