53 static void plot_in_pixbuf(GdkPixbuf *pixbuf, gint64 x, gint64 y, guchar red, guchar green, guchar blue, guchar alpha);
105 plugin->
extra = extra;
131 log_message(main_struct, G_LOG_LEVEL_INFO, Q_(
"%s xml interface loaded."), plugin->
info->
name);
135 log_message(main_struct, G_LOG_LEVEL_WARNING, Q_(
"Unable to load %s xml interface."), plugin->
info->
name);
148 gtk_check_menu_item_set_active(plugin->
cmi_entry, TRUE);
173 void run(GtkWidget *widget, gpointer data)
177 gboolean menu_state = FALSE;
184 menu_state = gtk_check_menu_item_get_active(plugin->
cmi_entry);
188 if (menu_state == TRUE)
211 gtk_widget_set_sensitive(
heraia_get_widget(xml,
"statw_export_to_csv"), sensitive);
212 gtk_widget_set_sensitive(
heraia_get_widget(xml,
"statw_export_to_gnuplot"), sensitive);
213 gtk_widget_set_sensitive(
heraia_get_widget(xml,
"statw_export_to_pcv"), sensitive);
230 if (main_struct != NULL && plugin != NULL)
235 plugin->
run_proc(NULL, (gpointer) main_struct);
287 gtk_check_menu_item_set_active(plugin->
cmi_entry, FALSE);
301 GtkImage *image = NULL;
302 GdkPixbuf *pixbuf = NULL;
303 gchar *filename = NULL;
304 GError **error = NULL;
311 pixbuf = gtk_image_get_pixbuf(image);
314 if (filename != NULL)
316 gdk_pixbuf_save(pixbuf, filename,
"png", error,
"compression",
"9", NULL);
330 GtkFileChooser *file_chooser = NULL;
331 gint response_id = 0;
334 file_chooser = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new(window_text, NULL,
335 GTK_FILE_CHOOSER_ACTION_SAVE,
336 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
337 GTK_STOCK_OPEN, GTK_RESPONSE_OK,
341 gtk_window_set_modal(GTK_WINDOW(file_chooser), TRUE);
342 gtk_file_chooser_set_select_multiple(file_chooser, FALSE);
343 gtk_file_chooser_set_do_overwrite_confirmation(file_chooser, TRUE);
346 if (extra != NULL && extra->
dirname != NULL)
348 gtk_file_chooser_set_current_folder(file_chooser, extra->
dirname);
351 response_id = gtk_dialog_run(GTK_DIALOG(file_chooser));
355 case GTK_RESPONSE_OK:
356 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser));
359 if (filename != NULL)
365 extra->
dirname = g_path_get_dirname(filename);
369 case GTK_RESPONSE_CANCEL:
375 gtk_widget_destroy(GTK_WIDGET(file_chooser));
389 gchar *filename = NULL;
400 if (filename != NULL)
402 fp = g_fopen(filename,
"w+");
405 if (fp != NULL && extra != NULL)
407 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
heraia_get_widget(plugin->
xml,
"rb_1D"))) == TRUE)
410 fprintf(fp, Q_(
"\"Byte\";\"Count\"\n"));
412 for (i=0; i<=255; i++)
414 fprintf(fp,
"%d;%llu\n", i, (
long long unsigned int) extra->
histo1D[i]);
421 fprintf(fp, Q_(
"\"Byte/Byte\";"));
422 for (j=0; j<255; j++)
424 fprintf(fp,
"\"%d\";", j);
426 fprintf(fp,
"\"%d\"\n", 255);
428 for (i=0; i<=255; i++)
430 fprintf(fp,
"\"%d\";", i);
431 for (j=0 ; j<255; j++)
433 fprintf(fp,
"\"%llu\";", (
long long unsigned int) extra->
histo2D[i][j]);
435 fprintf(fp,
"\"%llu\"\n", (
long long unsigned int) extra->
histo2D[i][255]);
441 if (filename != NULL)
458 gchar *filename = NULL;
469 if (filename != NULL)
471 fp = g_fopen(filename,
"w+");
474 if (fp != NULL && extra != NULL)
477 fprintf(fp,
"set terminal png transparent nocrop enhanced small size 1280,960\n");
478 fprintf(fp,
"set output '%s.png'\n", g_path_get_basename(filename));
479 fprintf(fp,
"set xrange [-10:265]\n");
480 fprintf(fp,
"set xlabel 'Bytes'\n");
482 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
heraia_get_widget(plugin->
xml,
"rb_1D"))) == TRUE)
485 fprintf(fp, Q_(
"set title 'Classical histogram'\n"));
486 fprintf(fp,
"set ylabel 'Count'\n");
487 fprintf(fp, Q_(
"plot '-' title 'Byte count' with impulses\n"));
489 for (i=0; i<=255; i++)
491 fprintf(fp,
"%llu\n", (
long long unsigned int) extra->
histo1D[i]);
498 fprintf(fp, Q_(
"set title 'Heatmap histogram'\n"));
499 fprintf(fp,
"set bar 1.000000\n");
500 fprintf(fp,
"set style rectangle back fc lt -3 fillstyle solid 1.00 border -1\n");
501 fprintf(fp,
"unset key\n");
502 fprintf(fp,
"set view map\n");
503 fprintf(fp,
"set yrange [-10:265]\n");
504 fprintf(fp,
"set ylabel 'Bytes'\n");
505 fprintf(fp,
"set palette rgbformulae 36, 13, 15\n");
506 fprintf(fp,
"splot '-' matrix with image\n");
508 for (i=0; i<=255; i++)
510 for (j=0; j<=255; j++)
512 fprintf(fp,
"%llu ", (
long long unsigned int) extra->
histo2D[i][j]);
523 if (filename != NULL)
540 gchar *filename = NULL;
551 if (filename != NULL)
553 fp = g_fopen(filename,
"w+");
556 if (fp != NULL && extra != NULL)
558 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
heraia_get_widget(plugin->
xml,
"rb_1D"))) == TRUE)
561 fprintf(fp,
"header {\n");
562 fprintf(fp,
"\theight = \"960\";\n");
563 fprintf(fp,
"\twidth = \"1280\";\n");
564 fprintf(fp, Q_(
"\ttitle = \"Classical histogram\";\n"));
566 fprintf(fp,
"axes {\n");
567 fprintf(fp, Q_(
"\tinteger b [label=\"Bytes\"];\n"));
568 fprintf(fp, Q_(
"\tinteger c [label=\"Byte count\"];\n"));
570 fprintf(fp,
"data {\n");
572 for (i=0; i<=255; i++)
574 fprintf(fp,
"\tb=\"%d\", c=\"%llu\";\n", i, (
long long unsigned int) extra->
histo1D[i]);
581 fprintf(fp,
"header {\n");
582 fprintf(fp,
"\theight = \"960\";\n");
583 fprintf(fp,
"\twidth = \"1280\";\n");
584 fprintf(fp, Q_(
"\ttitle = \"Classical histogram\";\n"));
586 fprintf(fp,
"axes {\n");
587 fprintf(fp, Q_(
"\tchar a [label=\"Bytes\"];\n"));
588 fprintf(fp, Q_(
"\tport c [label=\"Byte count\"];\n"));
589 fprintf(fp, Q_(
"\tchar b [label=\"Bytes\"];\n"));
591 fprintf(fp,
"data {\n");
593 for (i=0; i<=255; i++)
595 for (j=0; j<=255; j++)
599 fprintf(fp,
"\ta=\"%d\", c=\"%llu\", b=\"%d\" [color=\"red\"];\n", i, (
long long unsigned int) extra->
histo2D[i][j], j);
605 fprintf(fp,
"\ta=\"%d\", c=\"%llu\", b=\"%d\" [color=\"green\"];\n", i, (
long long unsigned int) extra->
histo2D[i][j], j);
609 fprintf(fp,
"\ta=\"%d\", c=\"%llu\", b=\"%d\";\n", i, (
long long unsigned int) extra->
histo2D[i][j], j);
619 if (filename != NULL)
641 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
heraia_get_widget(plugin->
xml,
"rb_1D"))) == TRUE)
643 gtk_image_set_from_pixbuf(image, extra->
pixbuf_1D);
647 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
heraia_get_widget(plugin->
xml,
"rb_2D"))) == TRUE)
649 gtk_image_set_from_pixbuf(image, extra->
pixbuf_2D);
689 g_signal_connect(G_OBJECT(
heraia_get_widget(plugin->
xml,
"statw_export_to_gnuplot")),
"clicked",
708 struct tm *tm = NULL;
709 size_t char_size = 0;
711 buf = (gchar *) g_malloc0(22*
sizeof(gchar));
715 char_size = strftime(buf, 22,
"%x %X", tm);
735 struct stat *stat_buf;
737 gchar *filename = NULL;
741 if (main_struct != NULL && main_struct->
current_doc != NULL)
746 if (filename != NULL)
748 log_message(main_struct, G_LOG_LEVEL_INFO, Q_(
"Calculating stats on %s"), filename);
750 stat_buf = (
struct stat *) g_malloc0 (
sizeof(
struct stat));
751 g_lstat(filename, stat_buf);
752 if (S_ISREG(stat_buf->st_mode))
793 log_message(main_struct, G_LOG_LEVEL_INFO, Q_(
"Histos calculated !"));
820 for (i=0; i<=255; i++)
823 for (j=0; j<=255; j++)
847 c1 = gtk_hex_get_byte(gh, i);
852 c2 = gtk_hex_get_byte(gh, i);
861 if (gtk_toggle_button_get_active(rb_1D) == TRUE)
863 gtk_image_set_from_pixbuf(image, extra->
pixbuf_1D);
867 if (gtk_toggle_button_get_active(rb_2D) == TRUE)
869 gtk_image_set_from_pixbuf(image, extra->
pixbuf_2D);
883 guint64 min = G_MAXUINT64;
884 gint64 mean = extra->
histo1D[0];
889 for (i=0; i<=255; i++)
904 diff = extra->
histo1D[i] - mean;
905 mean = mean + diff/n;
924 guint64 min = G_MAXUINT;
925 gint64 mean = extra->
histo2D[0][0];
930 for (i=0; i<=255; i++)
932 for (j=0; j<=255; j++)
935 if (extra->
histo2D[i][j] > max)
939 if (extra->
histo2D[i][j] < min)
947 diff = extra->
histo2D[i][j] - mean;
948 mean = mean + diff/n;
965 extra->
pixbuf_1D = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 255, 255);
966 gdk_pixbuf_fill(extra->
pixbuf_1D, 0xFFFFFF00);
967 gdk_pixbuf_add_alpha(extra->
pixbuf_1D, TRUE, (guchar) 255, (guchar) 255, (guchar) 255);
969 extra->
pixbuf_2D = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 255, 255);
970 gdk_pixbuf_fill(extra->
pixbuf_2D, 0xFFFFFF00);
971 gdk_pixbuf_add_alpha(extra->
pixbuf_2D, TRUE, (guchar) 255, (guchar) 255, (guchar) 255);
1000 static void plot_in_pixbuf(GdkPixbuf *pixbuf, gint64 x, gint64 y, guchar red, guchar green, guchar blue, guchar alpha)
1002 guchar *pixels = NULL;
1005 pixels = gdk_pixbuf_get_pixels(pixbuf);
1007 p = pixels + y * gdk_pixbuf_get_rowstride(pixbuf) + x * gdk_pixbuf_get_n_channels(pixbuf);
1022 guchar *pixels = NULL;
1028 gint rowstride = gdk_pixbuf_get_rowstride(pixbuf);
1029 gint n_channels = gdk_pixbuf_get_n_channels(pixbuf);
1031 pixels = gdk_pixbuf_get_pixels(pixbuf);
1035 p = pixels + y * rowstride + x * n_channels;
1036 p[0] = (guchar) 255-(y/2);
1038 p[2] = (guchar) y/2;
1039 p[3] = (guchar) 255;
1057 for (i=0; i<=255; i++)
1061 inter = (gdouble) (y_norm*255) / (gdouble)(extra->
infos_1D->
max);
1086 gdouble threshold1 = 0;
1087 gdouble threshold2 = 0;
1095 threshold1 = min + (mean - min) / 2;
1096 threshold2 = mean + (max - mean) / 2;
1098 floor = (guchar) 50;
1099 ceill = (guchar) 200;
1101 for (i=0; i<=255; i++)
1103 for (j=0; j<=255; j++)
1105 height = extra->
histo2D[i][j];
1110 if (height >= min && height <= threshold1)
1114 blue = (guchar) (height - min)*(ceill-floor) / threshold1;
1123 else if (height > threshold1 && height <= threshold2)
1125 red = (guchar) floor;
1126 green = (guchar) (height - threshold1)*(ceill-floor) / (threshold2 - threshold1);
1127 blue = (guchar) floor;
1130 else if (height > threshold2 && height <= max)
1132 red = (guchar) (height - threshold2)*(ceill-floor) / (max - threshold2);
void kill_text_from_textview(GtkTextView *textview)
Kills the text from a textview.
This is the main structure.
static void statw_export_to_pcv_clicked(GtkWidget *widget, gpointer data)
What to do when "export to pcv" button is clicked.
static void calc_infos_histo_1D(stat_t *extra)
Seeks the histo1D struct to find the maximum value.
gint x
x position (upper left corner)
gchar * dirname
last openned directory where files were saved
void add_text_to_textview(GtkTextView *textview, const char *format,...)
adds a text to a textview
guint nb_val
number of different values
static void histo_radiobutton_toggled(GtkWidget *widget, gpointer data)
What to do when the user chooses a 1D or 2D histo.
static void stat_window_connect_signals(heraia_plugin_t *plugin)
Connects all the signals to the correct functions.
RefreshProc refresh_proc
Called when the cursor changes it's position.
heraia_plugin_t * find_plugin_by_name(GList *plugins_list, gchar *name)
Finds the desired plugin by its name and return the plugin structure or NULL.
gchar * doc_t_document_get_filename(doc_t *doc)
Retrieves from a doc_t * document it's filename, which ever it is.
void log_message(heraia_struct_t *main_struct, GLogLevelFlags log_level, const char *format,...)
A function that helps logging a message a the specified level.
RefreshType event
Tells what is happening.
guint64 histo2D[256][256]
The values for the 2D histogram.
static void statw_export_to_gnuplot_clicked(GtkWidget *widget, gpointer data)
What to do when "export to gnuplot" button is clicked.
gboolean displayed
TRUE if displayed, FALSE otherwise.
GtkBuilder * xml
Eventually the plugin's GtkBuilder XML interface.
static void destroy_stat_window(GtkWidget *widget, GdkEvent *event, gpointer data)
Closes stat window.
guint64 histo1D[256]
The values for the 1D histogram.
InitProc init_proc
Called when the application initialy starts up.
void show_hide_widget(GtkWidget *widget, gboolean show, window_prop_t *win_prop)
To help plugins to deal with widgets, shows or hide a specific widget.
guint64 ghex_file_size(Heraia_Hex *gh)
Returns the file size of an opened Heraia_Hex document.
static void calc_infos_histo_2D(stat_t *extra)
Seeks the histo2D struct to find the maximum value.
Contains everything needed from stat.c : structures and defines.
histo_infos_t * infos_1D
stores mathematical datas on the histogram (1D)
#define HERAIA_PRIORITY_DEFAULT
Priorities ...
static void make_pixbufs_from_histos(stat_t *extra)
Makes the pixbufs from the histograms values.
static void do_pixbuf_2D_from_histo2D(stat_t *extra, guint max_2D)
Fills the pixbuf with the corresponding data from the histo2D struct It is really hard to make someth...
#define HERAIA_REFRESH_NEW_FILE
When a new file has been loaded.
plugin_info_t * info
The plugin information.
GtkHex Heraia_Hex
Abstract layer this may be usefull if we decide to leave Heraia_Hex and use something else ! ...
GdkPixbuf * pixbuf_1D
Pixbuf to be displayed (1D)
RunProc run_proc
Called to run an interface everytime the plugin is called.
static void init_stats_pixbufs(stat_t *extra)
Inits the image buffers.
window_prop_t * win_prop
Stores the window's properties.
This is the stat structure.
#define PLUGIN_DESCRIPTION
static void set_statw_button_state(GtkBuilder *xml, gboolean sensitive)
Sets stat window's button's sensitive property.
void * extra
Plugin-specific data.
static void populate_stats_histos(heraia_struct_t *main_struct, heraia_plugin_t *plugin)
Populates the histograms.
static void line_in_pixbuf(GdkPixbuf *pixbuf, gint64 x, gint64 y)
Prints a line of pixels in the corresponding pixbuf (1D histo)
static void do_pixbuf_1D_from_histo1D(stat_t *extra)
Fills the pixbuf with the corresponding data from the histo1D struct.
static void init_stats_histos(heraia_plugin_t *plugin)
Inits the histograms.
static void statw_save_as_clicked(GtkWidget *widget, gpointer data)
What to do when the save as button is clicked.
heraia_plugin_t * heraia_plugin_init(heraia_plugin_t *plugin)
Initialisation plugin function called when the plugin is loaded (some sort of pre-init) ...
static void realize_some_numerical_stat(heraia_struct_t *main_struct, heraia_plugin_t *plugin)
Do some stats on the selected file (entire file is used)
GtkWidget * hex_widget
hexwidget corresponding to the document
gint y
y position (upper left corner)
gboolean load_plugin_xml(heraia_struct_t *main_struct, heraia_plugin_t *plugin)
Loads the xml's definition file that describes the plugin (.gtkbuilder suffix) tries the paths found ...
static void plot_in_pixbuf(GdkPixbuf *pixbuf, gint64 x, gint64 y, guchar red, guchar green, guchar blue, guchar alpha)
Prints a pixel in the corresponding pixbuf.
PluginState state
The state of the plugin.
void quit(void)
Normaly this is called when the plugin is unloaded One may wait it's entire life for this to be calle...
Complete plugin structure.
static void statw_close_clicked(GtkWidget *widget, gpointer data)
What to do when the window is closed.
void refresh(heraia_struct_t *main_struct, void *data)
The refresh function is called when a new file is loaded or when the cursor is moved Here we want to ...
GList * plugins_list
A list of plugins.
void init(heraia_struct_t *main_struct)
The real init function of the plugin (called at init time)
static gchar * transform_time_t_to_gchar(time_t *a_time)
Do format a date form a time_t value.
GdkPixbuf * pixbuf_2D
Pixbuf to be displayed (2D)
static gchar * stat_select_file_to_save(const gchar *window_text, stat_t *extra)
Selecting the file filename where to save the file.
void run(GtkWidget *widget, gpointer data)
This function is called via a signal handler when the menu entry is toggled.
doc_t * current_doc
This is a pointer to the current edited document.
GtkWidget * heraia_get_widget(GtkBuilder *xml, gchar *widget_name)
This is a wrapper to the GtkBuilder xml get widget.
static void statw_export_to_csv_clicked(GtkWidget *widget, gpointer data)
What to do when "export to csv" button is clicked.
QuitProc quit_proc
Called when the application exits.
#define HERAIA_REFRESH_TAB_CHANGED
When user selects another tab in main notebook.
plugin_filter_t * filter
The plugin filter.
histo_infos_t * infos_2D
stores mathematical datas on the histogram (2D)
GtkCheckMenuItem * cmi_entry
The CheckMenuItem that may be created in the heraia interface.
static gboolean delete_stat_window_event(GtkWidget *widget, GdkEvent *event, gpointer data)
Usefull functions for the stat plugin those may be included in an another .c source file ...