diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-02-17 21:27:52 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-02-17 21:27:52 (GMT) |
commit | 3ba750662837541a5df510046c0a3fc521cca785 (patch) | |
tree | 711f412439e4b0d154207bbcbceeafce5f1b0864 /src/analysis | |
parent | 5c6680287b4b6ba38cc04e6d7cb80c87cb9e256d (diff) |
Defined, computed and stored the checksum in the binary content manager.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@474 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis')
-rw-r--r-- | src/analysis/binary-int.h | 1 | ||||
-rw-r--r-- | src/analysis/binary.c | 76 | ||||
-rw-r--r-- | src/analysis/binary.h | 3 | ||||
-rw-r--r-- | src/analysis/disass/disassembler.c | 31 |
4 files changed, 20 insertions, 91 deletions
diff --git a/src/analysis/binary-int.h b/src/analysis/binary-int.h index ec98bf9..c2657ae 100644 --- a/src/analysis/binary-int.h +++ b/src/analysis/binary-int.h @@ -62,7 +62,6 @@ struct _GLoadedBinary off_t bin_length; /* Taille des données brutes */ bin_t *bin_data; /* Données binaires brutes */ - GChecksum *checksum; /* Calcul de l'empreinte */ GExeFormat *format; /* Format du binaire */ GArchProcessor *proc; /* Architecture du binaire */ diff --git a/src/analysis/binary.c b/src/analysis/binary.c index 911e239..b94071c 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -179,9 +179,6 @@ static void g_loaded_binary_init(GLoadedBinary *binary) static void g_loaded_binary_dispose(GLoadedBinary *binary) { - if (binary->checksum != NULL) - g_checksum_free(binary->checksum); - if (binary->format != NULL) g_object_unref(G_OBJECT(binary->format)); if (binary->proc != NULL) @@ -237,14 +234,6 @@ GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const ch - char *host; /* Nom du serveur à contacter */ - int port; /* Numéro du port associé */ - char *author; /* Identification à diffuser */ - - - - bool status; /* Etat de la connexion à la BD*/ - result = NULL; type = get_node_prop_value(context, path, "type"); @@ -272,36 +261,6 @@ GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const ch - - printf("data :: %p length :: %d\n", result->bin_data, result->bin_length); - - - - /* Détermination de l'identifiant */ - - result->checksum = g_checksum_new(G_CHECKSUM_SHA256); - g_checksum_update(result->checksum, result->bin_data, result->bin_length); - - - result->local = g_db_client_new(g_loaded_binary_get_name(result, false), - g_loaded_binary_get_cheksum(result), - result->collections); - - - if (!g_generic_config_get_value(get_main_configuration(), MPK_LOCAL_HOST, &host)) - /* ... */; - - if (!g_generic_config_get_value(get_main_configuration(), MPK_LOCAL_PORT, &port)) - /* ... */; - - if (!g_generic_config_get_value(get_main_configuration(), MPK_AUTHOR_NAME, &author)) - /* ... */; - - - status = g_db_client_start(result->local, host, port, author); - - printf("DB status :: %d\n", status); - return result; glbnfx_error: @@ -716,6 +675,9 @@ bool g_loaded_binary_connect(GLoadedBinary *binary) { bool result; /* Bilan à retourner */ + GBinContent *content; /* Contenu bianire manipulé */ + const gchar *checksum; /* Identifiant de binaire */ + char *host; /* Nom du serveur à contacter */ int port; /* Numéro du port associé */ char *author; /* Identification à diffuser */ @@ -724,13 +686,11 @@ bool g_loaded_binary_connect(GLoadedBinary *binary) /* Détermination de l'identifiant */ - - binary->checksum = g_checksum_new(G_CHECKSUM_SHA256); - g_checksum_update(binary->checksum, binary->bin_data, binary->bin_length); - + content = g_binary_format_get_conten_(G_BIN_FORMAT(binary->format)); + checksum = g_binary_content_get_cheksum(content); binary->local = g_db_client_new(g_loaded_binary_get_name(binary, false), - g_loaded_binary_get_cheksum(binary), + checksum, binary->collections); @@ -867,10 +827,7 @@ void g_loaded_binary_analyse(GLoadedBinary *binary) { /* Détermination de l'identifiant */ - /* déplacé - binary->checksum = g_checksum_new(G_CHECKSUM_SHA256); - g_checksum_update(binary->checksum, binary->bin_data, binary->bin_length); - */ + /* Contacts avec les serveurs */ @@ -909,25 +866,6 @@ const char *g_loaded_binary_get_name(const GLoadedBinary *binary, bool full) /****************************************************************************** * * * Paramètres : binary = élément binaire à consulter. * -* * -* Description : Fournit une empreinte unique (SHA256) pour le binaire. * -* * -* Retour : Chaîne représentant l'empreinte du binaire. * -* * -* Remarques : - * -* * -******************************************************************************/ - -const gchar *g_loaded_binary_get_cheksum(const GLoadedBinary *binary) -{ - return g_checksum_get_string(binary->checksum); - -} - - -/****************************************************************************** -* * -* Paramètres : binary = élément binaire à consulter. * * length = taille en octets des données chargées. [OUT] * * * * Description : Fournit les détails du contenu binaire chargé en mémoire. * diff --git a/src/analysis/binary.h b/src/analysis/binary.h index fe6185f..b0fb369 100644 --- a/src/analysis/binary.h +++ b/src/analysis/binary.h @@ -152,9 +152,6 @@ void g_loaded_binary_analyse(GLoadedBinary *); /* Fournit le nom associé à l'élément binaire. */ const char *g_loaded_binary_get_name(const GLoadedBinary *, bool); -/* Fournit une empreinte unique (SHA256) pour le binaire. */ -const gchar *g_loaded_binary_get_cheksum(const GLoadedBinary *); - /* Fournit les détails du contenu binaire chargé en mémoire. */ bin_t *g_loaded_binary_get_data(const GLoadedBinary *, off_t *); diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c index c39073c..de9830c 100644 --- a/src/analysis/disass/disassembler.c +++ b/src/analysis/disass/disassembler.c @@ -89,7 +89,7 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *, GtkExtStatusBar /* Construit la description d'introduction du désassemblage. */ -static void build_disass_prologue(GCodeBuffer *, const char *, const uint8_t *, off_t); +static void build_disass_prologue(GCodeBuffer *, const char *, const char *); @@ -443,14 +443,12 @@ static void g_delayed_disassembly_process_old(GDelayedDisassembly *disass, GtkEx * * ******************************************************************************/ -static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, const uint8_t *data, off_t length) +static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, const char *checksum) { GLangOutput *output; /* Modèle de sortie adéquat */ GBufferLine *line; /* Ligne de destination */ size_t len; /* Taille du texte */ char *content; /* Contenu textuel d'une ligne */ - GChecksum *checksum; /* Calcul de l'empreinte */ - const gchar *hex; /* Valeur hexadécimale du SHA */ output = g_asm_output_new(); @@ -464,7 +462,7 @@ static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, con g_buffer_line_start_merge_at(line, BLC_PHYSICAL); line = g_lang_output_continue_comments(output, buffer, - SL(_("Chrysalide is free software - © 2008-2014 Cyrille Bagard"))); + SL(_("Chrysalide is free software - © 2008-2015 Cyrille Bagard"))); g_buffer_line_start_merge_at(line, BLC_PHYSICAL); line = g_lang_output_continue_comments(output, buffer, NULL, 0); @@ -484,17 +482,10 @@ static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, con /* Checksum SHA256 */ - checksum = g_checksum_new(G_CHECKSUM_SHA256); - - g_checksum_update(checksum, data, length); - hex = g_checksum_get_string(checksum); - - len = strlen(_("Sha256: ")) + strlen(hex); + len = strlen(_("Sha256: ")) + strlen(checksum); content = (char *)calloc(len + 1, sizeof(char)); - snprintf(content, len + 1, "%s%s", _("Sha256: "), hex); - - g_checksum_free(checksum); + snprintf(content, len + 1, "%s%s", _("Sha256: "), checksum); line = g_lang_output_continue_comments(output, buffer, content, len - 1); g_buffer_line_start_merge_at(line, BLC_PHYSICAL); @@ -535,15 +526,19 @@ static void build_disass_prologue(GCodeBuffer *buffer, const char *filename, con void disassemble_binary(GLoadedBinary *binary, GArchInstruction **instrs, GCodeBuffer **buffer, disassembly_ack_fc ack) { - const uint8_t *data; /* Données binaires brutes */ - off_t length; /* Quantité de ces données */ + GBinFormat *format; /* Format associé au binaire */ + GBinContent *content; /* Contenu bianire manipulé */ + const gchar *checksum; /* Identifiant de binaire */ GDelayedDisassembly *disass; /* Désassemblage à mener */ GWorkQueue *queue; /* Gestionnaire de différés */ *buffer = g_code_buffer_new(BLC_ASSEMBLY); - data = g_loaded_binary_get_data(binary, &length); - build_disass_prologue(*buffer, g_loaded_binary_get_name(binary, true), data, length); + format = G_BIN_FORMAT(g_loaded_binary_get_format(binary)); + content = g_binary_format_get_conten_(format); + checksum = g_binary_content_get_cheksum(content); + + build_disass_prologue(*buffer, g_loaded_binary_get_name(binary, true), checksum); disass = g_delayed_disassembly_new(binary, instrs, *buffer); g_signal_connect(disass, "work-completed", G_CALLBACK(ack), binary); |