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