** A nasty hack to allow the dumping of the currently highlighted hex dump ** as a file. diff -u -u -r1.109 menu.c --- gtk/menu.c 19 Nov 2003 00:04:15 -0000 1.109 +++ gtk/menu.c 24 Nov 2003 00:00:36 -0000 @@ -342,12 +342,16 @@ ITEM_FACTORY_ENTRY("/Expand All", NULL, expand_all_cb, 0, NULL, NULL) }; +extern void savehex_cb(GtkWidget * w, gpointer data _U_); + static GtkItemFactoryEntry hexdump_menu_items[] = { ITEM_FACTORY_ENTRY("/Follow TCP Stream", NULL, follow_stream_cb, 0, NULL, NULL), ITEM_FACTORY_ENTRY("/Decode As...", NULL, decode_as_cb, 0, NULL, NULL), ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb, + 0, NULL, NULL), + ITEM_FACTORY_ENTRY("/Save highlighted hex as rawhex.dat", NULL, savehex_cb, 0, NULL, NULL) }; diff -u -u -r1.64 proto_draw.c --- gtk/proto_draw.c 3 Nov 2003 21:00:05 -0000 1.64 +++ gtk/proto_draw.c 24 Nov 2003 00:00:36 -0000 @@ -729,6 +729,49 @@ gtk_notebook_set_page(GTK_NOTEBOOK(byte_nb_ptr), 0); } + +static struct { + guint8 *data; + int len; +} saved_hex; + +static void save_hex_data(const guint8 *pd, int len, int bstart, int bend) +{ + if (saved_hex.data) { + free(saved_hex.data); + saved_hex.data = NULL; + saved_hex.len = 0; + } + if (bstart != -1 && bend > bstart) { + saved_hex.data = malloc(bend-bstart); + saved_hex.len = bend-bstart; + if (saved_hex.data) { + memcpy(saved_hex.data, pd+bstart, bend-bstart); + } + } +} + +#include + +/* save the current highlighted hex data as hex_raw.dat */ +void savehex_cb(GtkWidget * w, gpointer data _U_) +{ + int fd; + if (!saved_hex.data) { + printf("No data to save\n"); + return; + } + fd = open("rawhex.dat", O_WRONLY|O_CREAT|O_TRUNC, 0666); + if (fd == -1) { + perror("rawhex.dat"); + return; + } + write(fd, saved_hex.data, saved_hex.len); + close(fd); + printf("Saved %d bytes to rawhex.dat\n", saved_hex.len); +} + + #if GTK_MAJOR_VERSION < 2 static void packet_hex_print_common(GtkText *bv, const guint8 *pd, int len, int bstart, @@ -759,6 +802,8 @@ GtkTextMark *mark = NULL; #endif + save_hex_data(pd, len, bstart, bend); + #if GTK_MAJOR_VERSION < 2 /* Freeze the text for faster display */ gtk_text_freeze(bv); @@ -1539,3 +1584,4 @@ gtk_tree_store_clear(GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)))); #endif } +