ghex_heraia_interface.c File Reference

An interface to the ghex library -> this adds an abstract layer. More...

#include <libheraia.h>
Include dependency graph for ghex_heraia_interface.c:

Go to the source code of this file.

Functions

doc_theraia_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'.
gchar * heraia_hex_document_get_filename (Heraia_Document *hex_doc)
 Retrieves the filename of a document which ever it is !
gchar * doc_t_document_get_filename (doc_t *doc)
 Retrieves from a doc_t * document it's filename, which ever it is.
HERAIA_ERROR heraia_hex_document_save (doc_t *current_doc)
HERAIA_ERROR heraia_hex_document_save_as (doc_t *current_doc, gchar *filename)
 Saves an opened and edited document to a new file.
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 have two or more of them if we have only one byte, we reverse its order if endianness is MIDDLE_ENDIAN we swap only four or more bytes Here we might have funny things with len corresponding to 24 or 56 bits for example.
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 variable.
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.
void ghex_set_data (doc_t *doc, guint64 position, guint rep_len, guint len, guchar *data)
 Wrapper to the hex_document_set_data function.
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.
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.
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.
guint64 ghex_file_size (Heraia_Hex *gh)
 Returns the file size of an opened Heraia_Hex document.
guint64 ghex_get_cursor_position (GtkWidget *hex_widget)
 Retrieves the cursor's position from the current hexwidget.
void ghex_set_cursor_position (GtkWidget *hex_widget, guint64 position)
 Sets the cursor at the defined position in the hexwidget.
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.
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_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).
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 doc at position position and with len buffer_size.
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.
selection_tghex_get_selection (GtkWidget *hex_widget)
 Retrieves the selection made (if any) in the hex widget.
doc_tnew_doc_t (Heraia_Document *hex_doc, GtkWidget *hex_widget)
 Inits a doc_t structure.
void close_doc_t (doc_t *current_doc)
 Closes a previously malloced doc_t structure.

Detailed Description

An interface to the ghex library -> this adds an abstract layer.

Definition in file ghex_heraia_interface.c.


Function Documentation

static void change_endianness ( guint  len,
guint  endianness,
guchar *  result 
) [static]

Deals with the endianness of 'len' bytes located in 'result' for BIG_ENDIAN we only swap bytes if we have two or more of them if we have only one byte, we reverse its order if endianness is MIDDLE_ENDIAN we swap only four or more bytes Here we might have funny things with len corresponding to 24 or 56 bits for example.

Warning:
Assumption is made that the default order is LITTLE_ENDIAN (which may not be true on some systems !)
We do assume that 'result' really contains 'len' bytes of data previously gmalloc'ed
Parameters:
len : len bytes to change endianness
endianness : H_DI_BIG_ENDIAN or H_DI_MIDDLE_ENDIAN we consider that there is nothing to do with H_DI_LITTLE_ENDIAN
[in,out] result : contains the bytes to be swaped and at the end, contains the result.

Definition at line 205 of file ghex_heraia_interface.c.

References H_DI_BIG_ENDIAN, H_DI_MIDDLE_ENDIAN, reverse_byte_order(), and swap_bytes().

Referenced by ghex_memcpy().

Here is the call graph for this function:

Here is the caller graph for this function:

void close_doc_t ( doc_t current_doc  ) 

Closes a previously malloced doc_t structure.

Parameters:
current_doc 

Definition at line 827 of file ghex_heraia_interface.c.

References doc_t::hex_widget.

Referenced by close_one_document().

Here is the caller graph for this function:

gchar* doc_t_document_get_filename ( doc_t doc  ) 

Retrieves from a doc_t * document it's filename, which ever it is.

Parameters:
doc : an existing doc_t
Returns:
returns the filename of that document.

Definition at line 97 of file ghex_heraia_interface.c.

References heraia_hex_document_get_filename(), and doc_t::hex_doc.

Referenced by add_gtk_tree_view_to_result_notebook(), add_new_tab_in_main_window(), on_close_activate(), on_save_activate(), on_save_as_activate(), realize_some_numerical_stat(), save_mp_files_filenames(), select_a_file_to_save(), select_file_to_load(), set_notebook_tab_name(), and update_main_window_name().

Here is the call graph for this function:

Here is the caller graph for this function:

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 doc at position position and with len buffer_size.

Parameters:
doc : the document where we want to compare data
string : the string we want to compare
buffer_size : size of the buffer string
position the localisation in the document where we want to compare thing
Returns:
a gint 0 means that at the given position and for the len buffer_size the document doc contains exactly the string. -1 if an error occured.

Definition at line 715 of file ghex_heraia_interface.c.

References doc_t::hex_doc.

Referenced by fr_replace_data().

Here is the caller graph for this function:

guint64 ghex_file_size ( Heraia_Hex gh  ) 

Returns the file size of an opened Heraia_Hex document.

Parameters:
gh : the widget of a an opened Heraia_Hex document
Returns:
returns the file size of that document

Definition at line 459 of file ghex_heraia_interface.c.

Referenced by fr_get_search_string(), ghex_memcpy(), goto_dialog_ok(), populate_stats_histos(), refresh_file_labels(), and rw_add_one_tab_from_find_all_bt().

Here is the caller graph for this function:

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.

Parameters:
doc : the document searched
search_buffer : the string searched for
buffer_size : size of the buffer
[out] : position (if any) of the found string
Returns:
True if something has been found. False otherwise

Definition at line 738 of file ghex_heraia_interface.c.

References doc_t::hex_doc, and doc_t::hex_widget.

Referenced by find_prev_bt_clicked().

Here is the caller graph for this function:

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).

Tries to find search_buffer in doc, data being passed to a decoding function

Parameters:
direction : the direction to look for (HERAIA_FIND_FORWARD or HERAIA_FIND_BACKWARD and only those directions)
doc : the document searched in
decode_it the function that will be used to decode the text
decode_parameters : this structure contains the selected endiannes and the selected stream size
data_size : size of the data to be read in order to use the decoding function
search_buffer : the string searched for (this is a simple guchar *null terminated entered by the user
[out] position (if any) of the found string
Returns:
True if something has been found. False otherwise

Definition at line 660 of file ghex_heraia_interface.c.

References HERAIA_FIND_ALL, HERAIA_FIND_BACKWARD, HERAIA_FIND_FORWARD, doc_t::hex_doc, hex_document_find_decode(), and doc_t::hex_widget.

Referenced by fdft_search_direction().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Todo:
a uniq function that will unify ghex_find_forward and ghex_find_backward
Parameters:
doc : the document searched
search_buffer : the string searched for
buffer_size : size of the buffer
[out] position (if any) of the found string
Returns:
True if something has been found. False otherwise

Definition at line 520 of file ghex_heraia_interface.c.

References doc_t::hex_doc, and doc_t::hex_widget.

Referenced by find_all_bt_clicked(), and fr_search_forward().

Here is the caller graph for this function:

guint64 ghex_get_cursor_position ( GtkWidget *  hex_widget  ) 

Retrieves the cursor's position from the current hexwidget.

Parameters:
hex_widget : the widget that displays the hex document
Returns:
returns the cursor's position

Definition at line 477 of file ghex_heraia_interface.c.

Referenced by fdft_search_direction(), find_prev_bt_clicked(), fr_replace_data(), fr_search_forward(), goto_dialog_ok(), refresh_file_labels(), and save_mp_files_filenames().

Here is the caller graph for this function:

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.

Warning:
guchar *c MUST have been pre allocated BEFORE the call.
Parameters:
hex_widget : MUST be a Heraia_Hex widget
length : can be anything but MUST be strictly less than the size allocated to *c
endianness : H_DI_BIG_ENDIAN, H_DI_MIDDLE_ENDIAN or H_DI_LITTLE_ENDIAN
c : a previously g_malloc'ed gchar * string that will contain copied bytes.

Definition at line 282 of file ghex_heraia_interface.c.

References ghex_get_data_position().

Referenced by interpret().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Warning:
guchar *c MUST have been pre allocated BEFORE the call.
Parameters:
hex_widget : MUST be a Heraia_Hex widget
pos : position in the file where we want to get the data
length : can be anything but MUST be strictly less than the size allocated to *c
endianness : H_DI_BIG_ENDIAN, H_DI_MIDDLE_ENDIAN or H_DI_LITTLE_ENDIAN
c : a previously g_malloc'ed gchar * string that will contain copied bytes.

Definition at line 327 of file ghex_heraia_interface.c.

References ghex_memcpy().

Referenced by fr_get_search_string(), ghex_get_data(), and hex_document_find_decode().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
hex_widget : MUST be a Heraia_Hex widget
pos : position in the file where we want to get the data
length : length of the data to get
endianness : H_DI_BIG_ENDIAN, H_DI_MIDDLE_ENDIAN or H_DI_LITTLE_ENDIAN
Returns:
the newly allocated string that contains the ascii translation from the data or NULL if something went wrong.

Definition at line 354 of file ghex_heraia_interface.c.

References ghex_memcpy(), and is_displayable.

Referenced by rw_add_one_tab_from_find_all_bt().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
hex_widget : MUST be a Heraia_Hex widget
pos : position in the file where we want to get the data
length : length of the data to get
endianness : H_DI_BIG_ENDIAN, H_DI_MIDDLE_ENDIAN or H_DI_LITTLE_ENDIAN
Returns:
the newly allocated string that contains the ascii translation from the data or NULL if something went wrong.

Definition at line 404 of file ghex_heraia_interface.c.

References ghex_memcpy().

Referenced by rw_add_one_tab_from_find_all_bt().

Here is the call graph for this function:

Here is the caller graph for this function:

selection_t* ghex_get_selection ( GtkWidget *  hex_widget  ) 

Retrieves the selection made (if any) in the hex widget.

Parameters:
hex_widget : the widget that displays the hex document
Returns:
returns a filed selection_t structure

Definition at line 773 of file ghex_heraia_interface.c.

References selection_t::end, and selection_t::start.

Referenced by refresh_file_labels().

Here is the caller graph for this function:

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 variable.

Warning:
We assume that a previous g_malloc has been done in order to use the function. Here we need the "swap_bytes" function defined in the decode.h header in order to take the endianness into account
Parameters:
gh : A Heraia_Hex document.
pos : position where we want to begin to copy bytes
len : number of bytes we want to copy
endianness : endianness we want to apply to the bytes we want to copy
[out] result : a previously g_malloc'ed gchar * string that will contain copied bytes.
Returns:
TRUE if everything went ok, FALSE otherwise

Definition at line 242 of file ghex_heraia_interface.c.

References change_endianness(), and ghex_file_size().

Referenced by ghex_get_data_position(), ghex_get_data_to_ascii(), and ghex_get_data_to_hex().

Here is the call graph for this function:

Here is the caller graph for this function:

void ghex_set_cursor_position ( GtkWidget *  hex_widget,
guint64  position 
)

Sets the cursor at the defined position in the hexwidget.

Parameters:
hex_widget : the widget that displays the hex document
position : the position where we want to go
Warning:
no checks are made here (limits and such ...). Checks are made in the gtk_hex_set_cursor function itself.

Definition at line 499 of file ghex_heraia_interface.c.

Referenced by fdft_search_direction(), find_prev_bt_clicked(), fr_search_forward(), goto_dialog_ok(), load_mp_files_filenames(), and tree_selection_changed().

Here is the caller graph for this function:

void ghex_set_data ( doc_t doc,
guint64  position,
guint  rep_len,
guint  len,
guchar *  data 
)

Wrapper to the hex_document_set_data function.

Parameters:
doc : the document searched
position : the position where to set the data
rep_len : the len of the data to be replaced in the document doc
len : the len of the data
data : the data that will replace the one in the document

Definition at line 305 of file ghex_heraia_interface.c.

References doc_t::hex_doc.

Referenced by fr_replace_data().

Here is the caller graph for this function:

gchar* heraia_hex_document_get_filename ( Heraia_Document hex_doc  ) 

Retrieves the filename of a document which ever it is !

Parameters:
doc : an Heraia_Document
Returns:
returns the filename of that document.

Definition at line 79 of file ghex_heraia_interface.c.

Referenced by doc_t_document_get_filename().

Here is the caller graph for this function:

HERAIA_ERROR 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'.

Parameters:
main_struct : main structure
filename : a char * representing an existing file named "filename"
Returns:
Always returns HERAIA_NOERR;
Todo:
: do something to take errors into account

Definition at line 39 of file ghex_heraia_interface.c.

References connect_cursor_moved_signal(), heraia_struct_t::documents, is_toggle_button_activated(), xml_t::main, new_doc_t(), and heraia_struct_t::xmls.

Referenced by load_file_to_analyse().

Here is the call graph for this function:

Here is the caller graph for this function:

HERAIA_ERROR heraia_hex_document_save ( doc_t current_doc  ) 

Definition at line 116 of file ghex_heraia_interface.c.

References HERAIA_FILE_ERROR, HERAIA_NOERR, and doc_t::hex_doc.

Referenced by on_save_activate().

Here is the caller graph for this function:

HERAIA_ERROR heraia_hex_document_save_as ( doc_t current_doc,
gchar *  filename 
)

Saves an opened and edited document to a new file.

Parameters:
current_doc : current edited document (doc_t * structure)
filename : the new filename where to save the file
Returns:
returns HERAIA_NOERR if everything went ok or HERAIA_FILE_ERROR in case of an error

< to make libghex happy !

Definition at line 145 of file ghex_heraia_interface.c.

References HERAIA_FILE_ERROR, HERAIA_NOERR, and doc_t::hex_doc.

Referenced by on_save_as_activate().

Here is the caller graph for this function:

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 
) [static]

Finds, in all directions the desired searched string.

Parameters:
direction : the direction to look for (HERAIA_FIND_FORWARD or HERAIA_FIND_BACKWARD)
doc : the document searched in
decode_it the function that will be used to decode the text
data_size : size of the data to be read in order to use the decoding function
decode_parameters : this structure contains the selected endiannes and the selected stream size
start : the start position where to begin the search
search_buffer : the string searched for (this is a simple guchar *null terminated entered by the user
[out] found : the position of the found string (or start +1 if not found)
Returns:
True if something has been found. False otherwise

used to test different results of function calls

the character under the cursor

decoded text

to stop the search when something is found or something is wrong

TRUE if something has been found, FALSE otherwise

Definition at line 566 of file ghex_heraia_interface.c.

References decode_parameters_t::endianness, ghex_get_data_position(), HERAIA_FIND_ALL, HERAIA_FIND_BACKWARD, HERAIA_FIND_FORWARD, and doc_t::hex_widget.

Referenced by ghex_find_decode().

Here is the call graph for this function:

Here is the caller graph for this function:

doc_t* new_doc_t ( Heraia_Document hex_doc,
GtkWidget *  hex_widget 
)

Inits a doc_t structure.

Parameters:
hex_doc : hex_document but encapsulated in Heraia_Document structure
hex_widget : Widget to display an hexadecimal view of the file
Returns:
returns a newly allocated doc_t structure

Todo:
do a function to access this value

Definition at line 809 of file ghex_heraia_interface.c.

References doc_t::hex_doc, doc_t::hex_widget, and doc_t::modified.

Referenced by create_find_or_replace_doc_t(), heraia_hex_document_new(), and on_new_activate().

Here is the caller graph for this function:

Generated on Mon May 2 21:05:09 2011 for Heraia by  doxygen 1.6.3