diff options
Diffstat (limited to 'src/analysis/binary.c')
-rw-r--r-- | src/analysis/binary.c | 511 |
1 files changed, 193 insertions, 318 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c index d7cb29c..38cb503 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -120,19 +120,16 @@ static void g_loaded_binary_dispose(GLoadedBinary *); /* Procède à la libération totale de la mémoire. */ static void g_loaded_binary_finalize(GLoadedBinary *); -/* Acquitte la fin d'un désasemblage différé et complet. */ -static void ack_completed_disassembly(GDelayedDisassembly *, GLoadedBinary *); - /* ------------------------- INFORMATIONS D'ENREGISTREMENTS ------------------------- */ /* Charge en mémoire les formes d'enregistrement du XML. */ -static bool g_loaded_binary_load_storage(GLoadedBinary *, xmlXPathContextPtr, const char *); +static bool g_loaded_binary_load_storage(GLoadedBinary *, xmlXPathContext *, const char *); /* Ecrit les formes d'enregistrement du binaire dans du XML. */ -static bool g_loaded_binary_save_storage(const GLoadedBinary *, xmlDocPtr, xmlXPathContextPtr, const char *); +static bool g_loaded_binary_save_storage(const GLoadedBinary *, xmlDoc *, xmlXPathContext *, const char *); /* Etablit une connexion au serveur interne en tant que client. */ static bool g_loaded_binary_connect_internal(GLoadedBinary *); @@ -146,13 +143,26 @@ static bool g_loaded_binary_connect_remote(GLoadedBinary *); -/* Lance l'analyse d'un élément binaire chargé. */ -static void _g_loaded_binary_analyse(GLoadedBinary *, disassembly_ack_fc); /* ---------------------- GESTION SOUS FORME DE CONTENU CHARGE ---------------------- */ +/* Interprète un contenu binaire chargé avec un appui XML. */ +static bool g_loaded_binary_restore(GLoadedBinary *, xmlDoc *, xmlXPathContext *, const char *); + +/* Ecrit une sauvegarde du binaire dans un fichier XML. */ +static bool g_loaded_binary_save(const GLoadedBinary *, xmlDoc *, xmlXPathContext *, const char *); + +/* Fournit le contenu représenté de l'élément chargé. */ +static GBinContent *g_loaded_binary_get_content(const GLoadedBinary *); + +/* Fournit le contenu représenté de l'élément chargé. */ +static const char *g_loaded_binary_get_format_name(const GLoadedBinary *); + +/* Assure le désassemblage en différé. */ +static bool g_loaded_binary_analyze(GLoadedBinary *, wgroup_id_t, GtkStatusStack *); + /* Fournit le désignation associée à l'élément chargé. */ static const char *g_loaded_binary_describe(const GLoadedBinary *, bool); @@ -269,6 +279,14 @@ static void g_loaded_binary_init(GLoadedBinary *binary) static void g_loaded_binary_interface_init(GLoadedContentInterface *iface) { + iface->restore = (restore_content_fc)g_loaded_binary_restore; + iface->save = (save_content_fc)g_loaded_binary_save; + + iface->get_content = (get_content_fc)g_loaded_binary_get_content; + iface->get_format_name = (get_format_name_fc)g_loaded_binary_get_format_name; + + iface->analyze = (analyze_loaded_fc)g_loaded_binary_analyze; + iface->describe = (describe_loaded_fc)g_loaded_binary_describe; iface->count_views = (count_loaded_views_fc)g_loaded_binary_count_views; @@ -333,6 +351,32 @@ static void g_loaded_binary_finalize(GLoadedBinary *binary) /****************************************************************************** * * +* Paramètres : format = format d'exécutable établi. * +* * +* Description : Interprète un contenu binaire chargé. * +* * +* Retour : Adresse de la représentation ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GLoadedContent *g_loaded_binary_new(GExeFormat *format) +{ + GLoadedBinary *result; /* Adresse à retourner */ + + result = g_object_new(G_TYPE_LOADED_BINARY, NULL); + + result->format = format; + + return G_LOADED_CONTENT(result); + +} + + + +/****************************************************************************** +* * * Paramètres : content = contenu binaire chargé en mémoire. * * * * Description : Interprète un contenu binaire chargé. * @@ -343,7 +387,7 @@ static void g_loaded_binary_finalize(GLoadedBinary *binary) * * ******************************************************************************/ -GLoadedBinary *g_loaded_binary_new(GBinContent *content) +GLoadedBinary *g_loaded_binary_new_old(GBinContent *content) { GLoadedBinary *result; /* Adresse à retourner */ FormatMatchStatus status; /* Statut d'une reconnaissance */ @@ -420,198 +464,6 @@ GLoadedBinary *g_loaded_binary_new(GBinContent *content) /****************************************************************************** * * -* Paramètres : context = contexte pour les recherches XPath. * -* path = chemin d'accès au noeud XML à lire. * -* project = projet dans lequel venir rechercher les contenus. * -* * -* Description : Interprète un contenu binaire chargé avec un appui XML. * -* * -* Retour : Adresse de la représentation ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const char *path, GStudyProject *project) -{ - GLoadedBinary *result; /* Adresse à retourner */ - char *content_path; /* Partie "Contenus" */ - char *access; /* Chemin d'accès à un élément */ - char *hash; /* Empreinte à retrouver */ - GBinContent *content; /* Contenu à référencer */ - xmlXPathObjectPtr xobject; /* Cible d'une recherche */ - unsigned int i; /* Boucle de parcours */ - bool attached; /* Bilan d'un chargement */ - - /* Contenus binaires associés */ - - content_path = strdup(path); - content_path = stradd(content_path, "/Contents"); - - access = strdup(content_path); - access = stradd(access, "/Main"); - - hash = get_node_text_value(context, access); - - free(access); - - if (hash == NULL) - goto glbnfx_early_error; - - content = g_study_project_find_binary_content_by_hash(project, hash); - - free(hash); - - if (content == NULL) - goto glbnfx_early_error; - - result = g_loaded_binary_new(content); - - g_object_unref(G_OBJECT(content)); - - if (result == NULL) - goto glbnfx_early_error; - - asprintf(&access, "%s/DebugInfo", content_path); - - xobject = get_node_xpath_object(context, access); - - free(access); - - for (i = 0; i < XPATH_OBJ_NODES_COUNT(xobject); i++) - { - asprintf(&access, "%s/DebugInfo[position()=%u]", content_path, i + 1); - - hash = get_node_text_value(context, access); - - free(access); - - if (hash == NULL) - goto glbnfx_error; - - content = g_study_project_find_binary_content_by_hash(project, hash); - - free(hash); - - if (content == NULL) - goto glbnfx_error; - - attached = g_loaded_binary_attach_debug_info(result, content); - - g_object_unref(G_OBJECT(content)); - - if (!attached) - goto glbnfx_error; - - } - - if(xobject != NULL) - xmlXPathFreeObject(xobject); - - free(content_path); - - /* Elément divers associés au binaire */ - - if (!g_loaded_binary_load_storage(result, context, path)) - goto glbnfx_final_error; - - return result; - - glbnfx_error: - - free(content_path); - - glbnfx_final_error: - - g_object_unref(G_OBJECT(result)); - - return NULL; - - glbnfx_early_error: - - g_object_unref(G_OBJECT(result)); - - free(content_path); - - return NULL; - -} - - -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à traiter. * -* xdoc = structure XML en cours d'édition. * -* context = contexte à utiliser pour les recherches. * -* path = chemin d'accès réservé au binaire. * -* base = référence au lieu d'enregistrement du projet. * -* * -* Description : Ecrit une sauvegarde du binaire dans un fichier XML. * -* * -* Retour : true si l'opération a bien tourné, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_loaded_binary_save(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path, const char *base) -{ - bool result; /* Bilan à faire remonter */ - char *content_path; /* Partie "Contenus" */ - char *access; /* Chemin d'accès à un élément */ - GBinContent *content; /* Contenu à référencer */ - size_t debugs_count; /* Quantité de formats liés */ - size_t i; /* Boucle de parcours */ - GDbgFormat *debug; /* Informations de débogage */ - - /* Contenus binaires associés */ - - content_path = strdup(path); - content_path = stradd(content_path, "/Contents"); - - asprintf(&access, "%s/Main", content_path); - - content = g_binary_format_get_content(G_BIN_FORMAT(binary->format)); - result = g_binary_content_save(content, xdoc, context, access, base); - g_object_unref(G_OBJECT(content)); - - free(access); - - debugs_count = g_exe_format_count_debug_info(binary->format); - - for (i = 0; i < debugs_count && result; i++) - { - asprintf(&access, "%s/DebugInfo[position()=%zu]", content_path, i); - - debug = g_exe_format_get_debug_info(binary->format, i); - - content = g_binary_format_get_content(G_BIN_FORMAT(debug)); - result = g_binary_content_save(content, xdoc, context, access, base); - g_object_unref(G_OBJECT(content)); - - g_object_unref(G_OBJECT(debug)); - - free(access); - - } - - free(content_path); - - /* Elément divers associés au binaire */ - - result = g_loaded_binary_save_storage(binary, xdoc, context, path); - - /* Sauvegarde côté serveur */ - - g_db_client_save(binary->local); - - return result; - -} - - -/****************************************************************************** -* * * Paramètres : binary = élément binaire à consulter. * * full = précise s'il s'agit d'une version longue ou non. * * * @@ -659,7 +511,7 @@ const char *g_loaded_binary_get_name(const GLoadedBinary *binary, bool full) * * ******************************************************************************/ -static bool g_loaded_binary_load_storage(GLoadedBinary *binary, xmlXPathContextPtr context, const char *path) +static bool g_loaded_binary_load_storage(GLoadedBinary *binary, xmlXPathContext *context, const char *path) { bool result; /* Bilan à faire remonter */ char *storage_path; /* Partie "Enregistrement" */ @@ -783,7 +635,7 @@ static bool g_loaded_binary_load_storage(GLoadedBinary *binary, xmlXPathContextP * * ******************************************************************************/ -static bool g_loaded_binary_save_storage(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path) +static bool g_loaded_binary_save_storage(const GLoadedBinary *binary, xmlDoc *xdoc, xmlXPathContext *context, const char *path) { bool result; /* Bilan à faire remonter */ char *storage_path; /* Partie "Enregistrement" */ @@ -1414,86 +1266,6 @@ bool _g_loaded_binary_remove_from_collection(GLoadedBinary *binary, DBFeatures f -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à traiter. * -* ack = éventuelle fonction à appeler en conclusion. * -* * -* Description : Lance l'analyse d'un élément binaire chargé. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void _g_loaded_binary_analyse(GLoadedBinary *binary, disassembly_ack_fc ack) -{ - /* Détermination de l'identifiant */ - - - - /* Contacts avec les serveurs */ - - - // Déconnexion... - - g_loaded_binary_connect_internal(binary); - - - disassemble_binary(binary, &binary->disass_cache, ack); - - - - /* TODO : remme ! */ - //ack_completed_disassembly(NULL, binary); - -} - - -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à traiter. * -* * -* Description : Lance l'analyse d'un élément binaire chargé. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_loaded_binary_analyse(GLoadedBinary *binary) -{ - _g_loaded_binary_analyse(binary, ack_completed_disassembly); - -} - - -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à traiter. * -* * -* Description : Lance l'analyse d'un binaire chargé et attend sa conclusion. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_loaded_binary_analyse_and_wait(GLoadedBinary *binary) -{ - GWorkQueue *queue; /* Gestionnaire de différés */ - - _g_loaded_binary_analyse(binary, NULL); - - queue = get_work_queue(); - g_work_queue_wait_for_completion(queue, DEFAULT_WORK_GROUP); - - ack_completed_disassembly(NULL, binary); - -} /****************************************************************************** @@ -1682,80 +1454,183 @@ bool *g_loaded_binary_display_decomp_lines(GLoadedBinary *binary) } + +/* ---------------------------------------------------------------------------------- */ +/* GESTION SOUS FORME DE CONTENU CHARGE */ +/* ---------------------------------------------------------------------------------- */ + + /****************************************************************************** * * -* Paramètres : disass = travail de désassemblage mené à bien. * -* binary = représentation de binaire à l'origine de l'opérat°. * +* Paramètres : binary = élément binaire à traiter. * +* xdoc = structure XML en cours d'édition. * +* context = contexte à utiliser pour les recherches. * +* path = chemin d'accès réservé au binaire. * * * -* Description : Acquitte la fin d'un désasemblage différé et complet. * +* Description : Interprète un contenu binaire chargé avec un appui XML. * * * -* Retour : - * +* Retour : true si l'opération a bien tourné, false sinon. * * * * Remarques : - * * * ******************************************************************************/ -#include "../gui/core/global.h" -void ack_completed_disassembly(GDelayedDisassembly *disass, GLoadedBinary *binary) -{ - //GRenderingLine *line; /* "Première" ligne de rendu */ - size_t i; /* Boucle de parcours */ +static bool g_loaded_binary_restore(GLoadedBinary *binary, xmlDoc *xdoc, xmlXPathContext *context, const char *path) +{ + bool result; /* Bilan à faire remonter */ - const char * const *files; /* Liste de fichiers source */ + /* Elément divers associés au binaire */ + result = g_loaded_binary_load_storage(binary, context, path); + return result; +} - g_binary_format_complete_analysis(G_BIN_FORMAT(binary->format), get_global_status()); +/****************************************************************************** +* * +* Paramètres : binary = élément binaire à traiter. * +* xdoc = structure XML en cours d'édition. * +* context = contexte à utiliser pour les recherches. * +* path = chemin d'accès réservé au binaire. * +* * +* Description : Ecrit une sauvegarde du binaire dans un fichier XML. * +* * +* Retour : true si l'opération a bien tourné, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ +static bool g_loaded_binary_save(const GLoadedBinary *binary, xmlDoc *xdoc, xmlXPathContext *context, const char *path) +{ + bool result; /* Bilan à faire remonter */ - /* ... = *///g_loaded_binary_connect_internal(binary); + /* Elément divers associés au binaire */ + result = g_loaded_binary_save_storage(binary, xdoc, context, path); - /* Décompilation... */ + /* Sauvegarde côté serveur */ + if (result) + g_db_client_save(binary->local); + return result; - files = g_binary_format_get_source_files(G_BIN_FORMAT(binary->format), - &binary->decbuf_count, &binary->defsrc); +} -#if 0 - if (binary->decbuf_count > 0) - { - binary->dec_buffers = (GCodeBuffer **)calloc(binary->decbuf_count, sizeof(GCodeBuffer *)); - /* - for (i = 0; i < binary->decbuf_count; i++) - binary->dec_buffers[i] = decompile_all_from_file(binary, files[i]); - */ - } -#endif +/****************************************************************************** +* * +* Paramètres : binary = élément chargé à manipuler. * +* * +* Description : Fournit le contenu représenté de l'élément chargé. * +* * +* Retour : Contenu représenté. * +* * +* Remarques : - * +* * +******************************************************************************/ +static GBinContent *g_loaded_binary_get_content(const GLoadedBinary *binary) +{ + GBinContent *result; /* Contenu interne à renvoyer */ + result = g_binary_format_get_content(G_BIN_FORMAT(binary->format)); -#if 0 - g_rendering_line_merge(&binary->lines, &disass->lines); + return result; +} +/****************************************************************************** +* * +* Paramètres : binary = élément chargé à manipuler. * +* * +* Description : Fournit le contenu représenté de l'élément chargé. * +* * +* Retour : Contenu représenté. * +* * +* Remarques : - * +* * +******************************************************************************/ - line = g_rendering_line_find_by_address(disass->lines, NULL, - g_exe_format_get_entry_point(binary->format)); - if (line != NULL) g_rendering_line_add_flag(line, RLF_ENTRY_POINT); +static const char *g_loaded_binary_get_format_name(const GLoadedBinary *binary) +{ + const char *result; /* Désignation à retourner */ - /* On réintègre le flot premier */ -#endif + result = g_binary_format_get_name(G_BIN_FORMAT(binary->format)); - g_signal_emit_by_name(binary, "disassembly-done"); + return result; } +/****************************************************************************** +* * +* Paramètres : binary = élément chargé dont l'analyse est lancée. * +* gid = groupe de travail dédié. * +* status = barre de statut à tenir informée. * +* * +* Description : Assure le désassemblage en différé. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ -/* ---------------------------------------------------------------------------------- */ -/* GESTION SOUS FORME DE CONTENU CHARGE */ -/* ---------------------------------------------------------------------------------- */ +static bool g_loaded_binary_analyze(GLoadedBinary *binary, wgroup_id_t gid, GtkStatusStack *status) +{ + bool result; /* Bilan à retourner */ + GBinFormat *format; /* Format lié au binaire */ + const char *arch; /* Architecture d'exécution */ + const char *desc; /* Description humaine associée*/ + + /* Interprétation du format associé */ + + format = G_BIN_FORMAT(binary->format); + + result = g_binary_format_analyze(format, gid, status); + if (!result) goto glba_exit; + + /* Architecture visée */ + + arch = g_exe_format_get_target_machine(binary->format); + desc = get_arch_processor_name(arch); + + if (desc == NULL) + { + log_simple_message(LMT_INFO, _("Unknown architecture")); + goto glba_exit; + } + else + log_variadic_message(LMT_INFO, _("Detected architecture: %s"), desc); + + binary->proc = get_arch_processor_for_type(arch); + + if (binary->proc == NULL) + { + log_simple_message(LMT_ERROR, _("Unable to load the required processor")); + goto glba_exit; + } + + /* Phase de désassemblage pur */ + + g_loaded_binary_connect_internal(binary); + + disassemble_binary(binary, gid, status, &binary->disass_cache); + + g_binary_format_complete_analysis(format, status); + + result = true; + + glba_exit: + + return result; + +} /****************************************************************************** |