42 GtkWidget *hex_widget = NULL;
46 hex_doc = hex_document_new_from_file(filename);
51 hex_widget = hex_document_add_view(hex_doc);
60 g_ptr_array_add(main_struct->
documents, doc);
83 return hex_doc->file_name;
118 gint return_value = FALSE;
120 if (current_doc != NULL)
122 if (current_doc->
hex_doc != NULL)
124 return_value = hex_document_write(current_doc->
hex_doc);
128 if (return_value != FALSE)
147 gint return_value = FALSE;
150 gchar *path_end = NULL;
152 if (current_doc != NULL && current_doc->
hex_doc != NULL && filename != NULL)
154 fp = fopen(filename,
"w");
157 return_value = hex_document_write_to_file(current_doc->
hex_doc, fp);
161 for(i = strlen(current_doc->
hex_doc->file_name);
162 (i >= 0) && (current_doc->
hex_doc->file_name[i] !=
'/');
164 if (current_doc->
hex_doc->file_name[i] ==
'/')
166 path_end = ¤t_doc->
hex_doc->file_name[i+1];
170 path_end = current_doc->
hex_doc->file_name;
173 current_doc->
hex_doc->path_end = g_filename_to_utf8(path_end, -1, NULL, NULL, NULL);
177 if (return_value != FALSE)
246 if (result == NULL || gh == NULL)
257 for (i=0; i<len ; i++)
259 result[i] = gtk_hex_get_byte(gh, pos+i);
282 gboolean
ghex_get_data(GtkWidget *hex_widget, guint length, guint endianness, guchar *c)
307 if (doc != NULL && doc->
hex_doc != NULL && data != NULL)
309 hex_document_set_data(doc->
hex_doc, position, len, rep_len, data, TRUE);
329 gboolean result = FALSE;
334 result =
ghex_memcpy(gh, pos, length, endianness, c);
358 guchar *result = NULL;
361 c = (guchar *) g_malloc0 (
sizeof(guchar)*(length + 1));
363 if (
ghex_memcpy(gh, pos, length, endianness, c) == TRUE)
366 result = (guchar *) g_malloc0 (
sizeof(guchar)*(length + 2));
368 for(i = 0; i < length; i++)
381 result[i] = (guchar) 0;
407 static guchar hex[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'};
409 guchar *result = NULL;
415 c = (guchar *) g_malloc0 (
sizeof(guchar)*(length + 1));
417 if (
ghex_memcpy(gh, pos, length, endianness, c) == TRUE)
420 result = (guchar *) g_malloc0 (
sizeof(guchar)*( 3 * length + 2));
423 for(i = 0; i < length; i++)
426 high = (c[i] & 0xF0) >> 4;
428 result[j] = hex[high];
430 result[j] = hex[low];
433 if (i % gh->group_type == 0)
441 result[j] = (guchar) 0;
461 if (gh != NULL && gh->document != NULL)
463 return gh->document->file_size;
483 return gtk_hex_get_cursor(gh);
506 gtk_hex_set_cursor(gh, position);
522 guint64 current_position = 0;
524 gboolean result = FALSE;
528 current_position = *position;
529 result = hex_document_find_forward(doc->
hex_doc, current_position + 1, search_buffer, buffer_size, &offset);
533 *position = (guint64) offset;
569 gboolean result = FALSE;
572 gboolean end = FALSE;
573 gboolean yes = FALSE;
576 len = g_utf8_strlen(search_buffer, -1);
578 c = (guchar *) g_malloc0(
sizeof(guchar) * data_size);
588 text = decode_it(c, (gpointer) decode_parameters);
590 if (g_ascii_strncasecmp(text, search_buffer, len) == 0)
600 if (pos < doc->hex_doc->file_size)
662 guint64 current_position = 0;
663 gboolean result = FALSE;
666 if (doc != NULL && doc->
hex_widget != NULL && doc->
hex_doc != NULL && decode_it != NULL)
670 current_position = *position + 1;
674 current_position = *position - 1;
678 current_position = 0;
681 result =
hex_document_find_decode(direction, doc, decode_it, data_size, decode_parameters, current_position, search_buffer, &offset);
685 *position = (guint64) offset;
718 if (doc != NULL && doc->
hex_doc != NULL &&
string != NULL)
720 return hex_document_compare_data(doc->
hex_doc,
string, (gint) position, buffer_size);
740 guint64 current_position = 0;
742 gboolean result = FALSE;
746 current_position = *position;
747 result = hex_document_find_backward(doc->
hex_doc, current_position - 1, search_buffer, buffer_size, &offset);
751 *position = (guint64) offset;
782 if (gh->selection.start < gh->selection.end)
784 sel->
start = gh->selection.start;
785 sel->
end = gh->selection.end;
789 sel->
end = gh->selection.start;
790 sel->
start = gh->selection.end;
817 new_doc->
modified = hex_doc->changed;
830 if (current_doc != NULL)
This is the main structure.
static gboolean hex_document_find_decode(gint direction, doc_t *doc, DecodeFunc decode_it, guint data_size, decode_parameters_t *decode_parameters, guint64 start, gchar *search_buffer, guint64 *found)
Finds, in all directions the desired searched string.
gboolean ghex_find_backward(doc_t *doc, guchar *search_buffer, guint buffer_size, guint64 *position)
Wrapper to the hex_document_find_backward function Tries to find search_buffer in doc...
#define HERAIA_FIND_ALL
When one wants to do a global search in th whole document.
#define H_DI_MIDDLE_ENDIAN
Stands for middle endian representation (http://en.wikipedia.org/wiki/Endianness#Middle-endian) ...
gchar * doc_t_document_get_filename(doc_t *doc)
Retrieves from a doc_t * document it's filename, which ever it is.
gint ghex_compare_data(doc_t *doc, guchar *string, guint buffer_size, guint64 position)
Wrapper to the hex_document_compare_data function Compares data from string to the one contained in d...
gboolean ghex_get_data_position(GtkWidget *hex_widget, guint64 pos, guint length, guint endianness, guchar *c)
Gets the data from the hexwidget, a wrapper to the ghex_memcpy function.
gchar * heraia_hex_document_get_filename(Heraia_Document *hex_doc)
Retrieves the filename of a document which ever it is !
void reverse_byte_order(guchar *to_reverse)
Reverse the byte order LSB -> MSB in MSB -> LSB 12345678 in 87654321.
guint64 ghex_file_size(Heraia_Hex *gh)
Returns the file size of an opened Heraia_Hex document.
guchar * ghex_get_data_to_ascii(GtkWidget *hex_widget, guint64 pos, guint length, guint endianness)
Gets data from a defined position and formats it in an ascii displayable form.
#define H_DI_BIG_ENDIAN
Stands for big endian representation.
Proposal for a structure that will group all informations about a single document.
guint64 start
Starting position of the selection.
GtkHex Heraia_Hex
Abstract layer this may be usefull if we decide to leave Heraia_Hex and use something else ! ...
Heraia_Document * hex_doc
Document definition related to Heraia_Hex (GtkHex)
A structure to manage a single selection.
guint64 end
Ending position of the selection.
xml_t * xmls
All the xmls used in the program, loaded at running time.
void ghex_set_data(doc_t *doc, guint64 position, guint rep_len, guint len, guchar *data)
Wrapper to the hex_document_set_data function.
doc_t * heraia_hex_document_new(heraia_struct_t *main_struct, char *filename)
Removes the old document if it exists and adds a new one from the filename 'filename'.
GtkWidget * hex_widget
hexwidget corresponding to the document
static void change_endianness(guint len, guint endianness, guchar *result)
Deals with the endianness of 'len' bytes located in 'result' for BIG_ENDIAN we only swap bytes if we ...
GtkBuilder * main
the main interface xml description
gchar *(* DecodeFunc)(guchar *, gpointer)
Templates for the decoding functions.
#define HERAIA_NOERR
No error occured, everything is fine.
gint HERAIA_ERROR
Defines heraia error type (this should be used !)
gboolean ghex_find_decode(gint direction, doc_t *doc, DecodeFunc decode_it, decode_parameters_t *decode_parameters, guint data_size, gchar *search_buffer, guint64 *position)
Wrappers to the functions that will do the search (here it has nothing to do with ghex in fact)...
guint64 ghex_get_cursor_position(GtkWidget *hex_widget)
Retrieves the cursor's position from the current hexwidget.
HexDocument Heraia_Document
Abstract layer this may be usefull if we decide to leave Heraia_Hex and use something else ! ...
#define is_displayable(c)
gboolean swap_bytes(guchar *to_swap, guint first, guint last)
Swap bytes from the buffer to_swap.
This file contains all the definitions and includes all other .h files.
void ghex_set_cursor_position(GtkWidget *hex_widget, guint64 position)
Sets the cursor at the defined position in the hexwidget.
HERAIA_ERROR heraia_hex_document_save(doc_t *current_doc)
guchar * ghex_get_data_to_hex(GtkWidget *hex_widget, guint64 pos, guint length, guint endianness)
Gets data from a defined position and formats it in an hex displayable form.
gboolean ghex_get_data(GtkWidget *hex_widget, guint length, guint endianness, guchar *c)
Gets the data from the hexwidget under the cursor, a wrapper to the ghex_memcpy function.
gboolean is_toggle_button_activated(GtkBuilder *main_xml, gchar *check_button)
returns the state of a named check button contained in the GtkBuilder XML description ...
void close_doc_t(doc_t *current_doc)
Closes a previously malloced doc_t structure.
GPtrArray * documents
An array of doc_t in order to be able to open more than one doc.
gboolean modified
If hex_doc->changed <> modified then the document has something changed that may need an upate...
gboolean ghex_find_forward(doc_t *doc, guchar *search_buffer, guint buffer_size, guint64 *position)
Wrapper to the hex_document_find_forward function Tries to find search_buffer in doc.
guint endianness
endianness
gboolean ghex_memcpy(Heraia_Hex *gh, guint64 pos, guint len, guint endianness, guchar *result)
Returns 'len' number of bytes located at 'pos' in the Heraia_Hex document and puts it in the result v...
selection_t * ghex_get_selection(GtkWidget *hex_widget)
Retrieves the selection made (if any) in the hex widget.
HERAIA_ERROR heraia_hex_document_save_as(doc_t *current_doc, gchar *filename)
Saves an opened and edited document to a new file.
#define HERAIA_FIND_FORWARD
When one wants to do a search in the forward direction.
doc_t * new_doc_t(Heraia_Document *hex_doc, GtkWidget *hex_widget)
Inits a doc_t structure.
#define HERAIA_FILE_ERROR
When an error on a file occurs.
Used to pass decoding options to the functions.
#define HERAIA_FIND_BACKWARD
When one wants to do a search in the backward direction.
void connect_cursor_moved_signal(heraia_struct_t *main_struct, GtkWidget *hex_widget)
Connects the signal that the cursor has moved to the refreshing function.