diff options
Diffstat (limited to 'src/project.c')
-rw-r--r-- | src/project.c | 190 |
1 files changed, 125 insertions, 65 deletions
diff --git a/src/project.c b/src/project.c index 9f880a2..9273b94 100644 --- a/src/project.c +++ b/src/project.c @@ -26,6 +26,7 @@ #include <dirent.h> #include <malloc.h> +#include <stdio.h> #include <string.h> #include <unistd.h> @@ -34,7 +35,9 @@ #include "xml.h" #include "gtkext/easygtk.h" #include "gtkext/gtkblockview.h" +#include "gtkext/gtkdockpanel.h" #include "gtkext/gtkgraphview.h" +#include "panel/panels.h" @@ -226,50 +229,108 @@ openida_project *create_empty_openida_project(void) * * ******************************************************************************/ -openida_project *load_openida_project_from_xml(const char *filename) +openida_project *g_openida_project_new_from_xml(const char *filename) { openida_project *result; /* Adresse à retourner */ - xmlDoc *xdoc; /* Structure XML chargée */ - xmlNode *xroot; /* Noeud premier de la def. */ - xmlXPathContextPtr xpathCtx; /* Contexte pour les XPath */ - xmlXPathObjectPtr xpathObj; /* Cible d'une recherche */ + xmlDocPtr xdoc; /* Structure XML chargée */ + xmlXPathContextPtr context; /* Contexte pour les XPath */ + xmlXPathObjectPtr xobject; /* Cible d'une recherche */ unsigned int i; /* Boucle de parcours */ + size_t access_len; /* Taille d'un chemin interne */ + char *access; /* Chemin pour une sous-config.*/ openida_binary *binary; /* Représentation à intégrer */ - if (!open_xml_file(filename, &xdoc, &xroot, &xpathCtx)) return NULL; + if (!open_xml_file(filename, &xdoc, &context)) return NULL; result = (openida_project *)calloc(1, sizeof(openida_project)); + /* Chargement des éléments binaires attachés */ + xobject = get_node_xpath_object(context, "/OpenIDAProject/Binaries/Binary"); - xpathObj = get_node_xpath_object(xpathCtx, "/OpenIDAProject/Binaries/*"); + for (i = 0; i < XPATH_OBJ_NODES_COUNT(xobject); i++) + { + access_len = strlen("/OpenIDAProject/Binaries/Binary[position()=") + + strlen("4294967295" /* UINT_MAX */) + strlen("]") + 1; - printf("nodes :: %d\n", XPATH_OBJ_NODES_COUNT(xpathObj)); + access = calloc(access_len, sizeof(char)); + snprintf(access, access_len, "/OpenIDAProject/Binaries/Binary[position()=%u]", i + 1); - for (i = 0; i < XPATH_OBJ_NODES_COUNT(xpathObj); i++) - { - binary = read_openida_binary_from_xml(xpathCtx, "/OpenIDAProject/Binaries", i + 1); + binary = g_binary_file_new_from_xml(context, access); + + free(access); if (binary != NULL) attach_binary_to_openida_project(result, binary); } - if(xpathObj != NULL) - xmlXPathFreeObject(xpathObj); + if(xobject != NULL) + xmlXPathFreeObject(xobject); + + /* Fin du chargement */ + + close_xml_file(xdoc, context); + + return result; + +} + +/****************************************************************************** +* * +* Paramètres : project = project à sauvegarder. * +* filename = nom de fichier à utiliser ou NULL pour l'existant.* +* * +* Description : Procède à l'enregistrement d'un projet donné. * +* * +* Retour : true si l'enregistrement s'est déroule sans encombre. * +* * +* Remarques : - * +* * +******************************************************************************/ +bool g_openida_project_save(openida_project *project, const char *filename) +{ + bool result; /* Bilan à retourner */ + xmlDocPtr xdoc; /* Document XML à créer */ + xmlXPathContextPtr context; /* Contexte pour les recherches*/ + size_t i; /* Boucle de parcours */ + size_t access_len; /* Taille d'un chemin interne */ + char *access; /* Chemin pour une sous-config.*/ + result = create_new_xml_file(&xdoc, &context); + result &= (ensure_node_exist(xdoc, context, "/OpenIDAProject") != NULL); + /* Enregistrement des éléments binaires attachés */ + for (i = 0; i < project->binaries_count && result; i++) + { + access_len = strlen("/OpenIDAProject/Binaries/Binary[position()=") + + strlen("4294967295" /* UINT_MAX */) + strlen("]") + 1; + access = calloc(access_len, sizeof(char)); + snprintf(access, access_len, "/OpenIDAProject/Binaries/Binary[position()=%u]", i + 1); - xmlXPathFreeContext(xpathCtx); - xmlFreeDoc(xdoc); - xmlCleanupParser(); + result = g_openida_binary_save(project->binaries[i]->binary, xdoc, context, access); + free(access); + } + + /* Sauvegarde finale */ + + result &= save_xml_file(xdoc, filename); + + if (result) + { + if (project->filename != NULL) free(project->filename); + project->filename = strdup(filename); + + } + + close_xml_file(xdoc, context); return result; @@ -318,55 +379,6 @@ bool has_storing_filename(const openida_project *project) } -/****************************************************************************** -* * -* Paramètres : project = project à sauvegarder. * -* filename = nom de fichier à utiliser ou NULL pour l'existant.* -* * -* Description : Procède à l'enregistrement d'un projet donné. * -* * -* Retour : true si l'enregistrement s'est déroule sans encombre. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool write_openida_project_to_xml(openida_project *project, const char *filename) -{ - bool result; /* Bilan à faire remonter */ - xmlTextWriterPtr writer; /* Rédacteur pour la sortie XML*/ - size_t i; /* Boucle de parcours */ - - writer = start_writing_xml_file(filename); - - result = open_xml_element(writer, "OpenIDAProject"); - - /* Enregistrement des éléments binaires attachés */ - - result &= open_xml_element(writer, "Binaries"); - - for (i = 0; i < project->binaries_count && result; i++) - write_openida_binary_to_xml(project->binaries[i], writer); - - result &= close_xml_element(writer); - - result &= close_xml_element(writer); - - result &= end_writing_xml_file(writer); - - if (result) - { - if (project->filename != NULL) free(project->filename); - project->filename = strdup(filename); - } - - return result; - -} - - - - @@ -568,3 +580,51 @@ void load_recent_openida_projects_list(GObject *ref, GCallback *func) gtk_widget_set_sensitive(menuitem, one_entry); } + + +/****************************************************************************** +* * +* Paramètres : project = projet dont le contenu est à afficher. * +* func = fonction à appeler lors d'un clic sur les menus. * +* * +* Description : Met en place un projet à l'écran. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void display_openida_project(const openida_project *project, GObject *ref) +{ + GtkDockPanel *dpanel; /* Support de panneaux */ + size_t i; /* Boucle de parcours */ + openida_binary *binary; + GtkWidget *view; /* Affichage du code binaire */ + GtkDockItem *ditem; /* Panneau avec ses infos. */ + + dpanel = GTK_DOCK_PANEL(g_object_get_data(ref, "binpanel")); + + for (i = 0; i < project->binaries_count; i++) + { + binary = project->binaries[i]->binary; + + view = get_loaded_binary_view(project->binaries[i], BVW_BLOCK); + + ditem = gtk_dock_item_new(openida_binary_to_string(binary), view); + gtk_dock_panel_add_item(dpanel, ditem); + + } + + + if (i > 0) + { + g_object_set_data(ref, "current_binary", binary); + + + reload_symbols_panel_content(get_panel(PNT_SYMBOLS), get_openida_binary_format(binary)); + + } + + +} |