summaryrefslogtreecommitdiff
path: root/src/analysis/binary.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2014-03-20 22:52:48 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2014-03-20 22:52:48 (GMT)
commit18d6b808db6e31e867525d68f92d6f928a7ab5a7 (patch)
treed534c8e374004866696322a4c3f58ae2a7a545d9 /src/analysis/binary.c
parent84790a5b420d0a9ce658013573b180ce059db325 (diff)
Created the first steps for a distributed storage.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@368 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/binary.c')
-rw-r--r--src/analysis/binary.c444
1 files changed, 438 insertions, 6 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 05c4e99..31bd18b 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -39,6 +39,7 @@
#include "decomp/decompiler.h"
#include "disass/disassembler.h"
#include "../common/extstr.h"
+#include "../common/cpp.h"
@@ -69,6 +70,16 @@ 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 *);
+
+/* Ecrit les formes d'enregistrement du binaire dans du XML. */
+static bool g_loaded_binary_save_storage(const GLoadedBinary *, xmlDocPtr, xmlXPathContextPtr, const char *);
+
+
@@ -122,6 +133,16 @@ static void g_loaded_binary_class_init(GLoadedBinaryClass *klass)
static void g_loaded_binary_init(GLoadedBinary *binary)
{
+ binary->username = strdup("default");
+
+ binary->remote_host = strdup("localhost");
+ binary->remote_port = 9999;
+ binary->use_remote_server = false;
+
+ binary->storages[DBF_COMMENTS] = DBS_ALL_LOCAL;
+ binary->storages[DBF_SEGMENTS_DISPLAY] = DBS_ALL_LOCAL;
+ binary->storages[DBF_BOOKMARKS] = DBS_ALL_LOCAL;
+
binary->text_display[BDT_ASM][0] = true;
binary->text_display[BDT_ASM][1] = true;
binary->text_display[BDT_GRAPH][0] = false;
@@ -146,14 +167,14 @@ 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)
g_object_unref(G_OBJECT(binary->proc));
- if (binary->bin_data != NULL)
- free(binary->bin_data);
-
/* TODO... */
G_OBJECT_CLASS(g_loaded_binary_parent_class)->dispose(G_OBJECT(binary));
@@ -175,7 +196,12 @@ static void g_loaded_binary_dispose(GLoadedBinary *binary)
static void g_loaded_binary_finalize(GLoadedBinary *binary)
{
- /* TODO */
+ free(binary->username);
+
+ if (binary->bin_data != NULL)
+ free(binary->bin_data);
+
+ /* TODO... */
G_OBJECT_CLASS(g_loaded_binary_parent_class)->finalize(G_OBJECT(binary));
@@ -198,22 +224,33 @@ static void g_loaded_binary_finalize(GLoadedBinary *binary)
GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const char *path)
{
GLoadedBinary *result; /* Adresse à retourner */
- char *type; /* Tupe de binaire à charger */
+ char *type; /* Type de binaire à charger */
+ bool status; /* Etat de la connexion à la BD*/
result = NULL;
type = get_node_prop_value(context, path, "type");
if (strcmp(type, "file") == 0)
- result = g_loaded_binary_new_from_xml(context, path);
+ result = g_file_binary_new_from_xml(context, path);
free(type);
if (result == NULL)
return NULL;
+ if (!g_loaded_binary_load_storage(result, context, path))
+ goto glbnfx_error;
+
+ /*
if (!g_loaded_binary_load_parts_from_xml(result, context, path))
goto glbnfx_error;
+ */
+
+ result->local = g_db_client_new("localhost", 1337);
+ status = g_db_client_start(result->local);
+
+ printf("DB status :: %d\n", status);
return result;
@@ -247,6 +284,8 @@ bool g_loaded_binary_save(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathC
result = binary->save(binary, xdoc, context, path);
+ result = g_loaded_binary_save_storage(binary, xdoc, context, path);
+
/* Parties à désassembler */
result = g_loaded_binary_save_parts(binary, xdoc, context, path);
@@ -475,6 +514,368 @@ static bool g_loaded_binary_save_parts(const GLoadedBinary *binary, xmlDocPtr xd
}
+
+/* ---------------------------------------------------------------------------------- */
+/* INFORMATIONS D'ENREGISTREMENTS */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à traiter. *
+* context = contexte pour les recherches XPath. *
+* path = chemin d'accès au noeud XML à lire. *
+* *
+* Description : Charge en mémoire les formes d'enregistrement du XML. *
+* *
+* Retour : true si l'opération a bien tourné, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_loaded_binary_load_storage(GLoadedBinary *binary, xmlXPathContextPtr context, const char *path)
+{
+ bool result; /* Bilan à faire remonter */
+ char *storage_path; /* Partie "Enregistrement" */
+ char *access; /* Chemin d'accès à un élément */
+ char *value; /* Valeur lue à partie du XML */
+ unsigned short port; /* Port de communication */
+ bool use; /* Usage d'un serveur distant */
+ DBFeatures i; /* Boucle de parcours */
+
+ result = true;
+
+ storage_path = strdup(path);
+ storage_path = stradd(storage_path, "/Storage");
+
+ /* Nom d'utilisateur */
+
+ access = strdup(storage_path);
+ access = stradd(access, "/Username");
+
+ value = get_node_text_value(context, access);
+
+ if (value != NULL)
+ {
+ g_loaded_binary_set_username(binary, value);
+ free(value);
+ }
+
+ free(access);
+
+ /* Serveur distant */
+
+ access = strdup(storage_path);
+ access = stradd(access, "/RemoteServer");
+
+ value = get_node_prop_value(context, access, "port");
+ if (value == NULL) goto glbls_features;
+
+ port = atoi(value);
+
+ free(value);
+
+ value = get_node_prop_value(context, access, "use");
+ if (value == NULL) goto glbls_features;
+
+ use = (strcmp(value, "true") == 0);
+
+ free(value);
+
+ value = get_node_prop_value(context, access, "host");
+ if (value == NULL) goto glbls_features;
+
+ g_loaded_binary_set_remote_server(binary, value, port, use);
+
+ free(value);
+
+ glbls_features:
+
+ free(access);
+
+ /* Fonctionnalités */
+
+ for (i = 0; i < DBF_COUNT; i++)
+ {
+ access = strdup(storage_path);
+ access = stradd(access, "/Features/");
+
+ switch (i)
+ {
+ case DBF_COMMENTS:
+ access = stradd(access, "Comments");
+ break;
+ case DBF_SEGMENTS_DISPLAY:
+ access = stradd(access, "Segments");
+ break;
+ case DBF_BOOKMARKS:
+ access = stradd(access, "Bookmarks");
+ break;
+ case DBF_COUNT:
+ /* Pour GCC */
+ break;
+ }
+
+ value = get_node_text_value(context, access);
+
+ if (value != NULL)
+ {
+ if (atoi(value) <= DBS_MAX)
+ g_loaded_binary_set_storage(binary, i, atoi(value));
+
+ }
+
+ free(access);
+
+ }
+
+ free(storage_path);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* 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 les formes d'enregistrement du binaire dans du XML. *
+* *
+* Retour : true si l'opération a bien tourné, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_loaded_binary_save_storage(const GLoadedBinary *binary, xmlDocPtr xdoc, xmlXPathContextPtr context, const char *path)
+{
+ bool result; /* Bilan à faire remonter */
+ char *storage_path; /* Partie "Enregistrement" */
+ char *access; /* Chemin d'accès à un élément */
+ char port_str[sizeof(STR(USHRT_MAX)) + 1]; /* Version chaînée */
+ DBFeatures i; /* Boucle de parcours */
+
+ result = true;
+
+ storage_path = strdup(path);
+ storage_path = stradd(storage_path, "/Storage");
+
+ /* Nom d'utilisateur */
+
+ access = strdup(storage_path);
+ access = stradd(access, "/Username");
+
+ result &= add_content_to_node(xdoc, context, access, binary->username);
+
+ free(access);
+
+ /* Serveur distant */
+
+ access = strdup(storage_path);
+ access = stradd(access, "/RemoteServer");
+
+ result &= add_string_attribute_to_node(xdoc, context, access, "host", binary->remote_host);
+
+ sprintf(port_str, "%hu", binary->remote_port);
+ result &= add_string_attribute_to_node(xdoc, context, access, "port", port_str);
+
+ result &= add_string_attribute_to_node(xdoc, context, access, "use",
+ binary->use_remote_server ? "true" : "false");
+
+ free(access);
+
+ /* Fonctionnalités */
+
+ for (i = 0; i < DBF_COUNT; i++)
+ {
+ access = strdup(storage_path);
+ access = stradd(access, "/Features/");
+
+ switch (i)
+ {
+ case DBF_COMMENTS:
+ access = stradd(access, "Comments");
+ break;
+ case DBF_SEGMENTS_DISPLAY:
+ access = stradd(access, "Segments");
+ break;
+ case DBF_BOOKMARKS:
+ access = stradd(access, "Bookmarks");
+ break;
+ case DBF_COUNT:
+ /* Pour GCC */
+ break;
+ }
+
+ result &= add_uint_content_to_node(xdoc, context, access, binary->storages[i]);
+
+ free(access);
+
+ }
+
+ free(storage_path);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* *
+* Description : Identifie l'utilisateur analysant le binaire courant. *
+* *
+* Retour : Nom de l'utilisateur manipulant le binaire. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const char *g_loaded_binary_get_username(const GLoadedBinary *binary)
+{
+ return binary->username;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* username = nom de l'utilisateur manipulant le binaire. *
+* *
+* Description : Définit l'utilisateur analysant le binaire courant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_loaded_binary_set_username(GLoadedBinary *binary, const char *username)
+{
+ bool changed; /* Note les changements */
+
+ changed = (strcmp(binary->username, username) != 0);
+
+ free(binary->username);
+ binary->username = strdup(username);
+
+ binary->username_changed = changed;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* host = nom du serveur distant à contacter. [OUT] *
+* port = port de communication avec le serveur distant. [OUT]*
+* *
+* Description : Identifie le serveur distant associé au binaire courant. *
+* *
+* Retour : Statut de l'utilisation du serveur distant. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_loaded_binary_get_remote_server(const GLoadedBinary *binary, const char **host, unsigned short *port)
+{
+ *host = binary->remote_host;
+ *port = binary->remote_port;
+
+ return binary->use_remote_server;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* host = nom du serveur distant à contacter. *
+* port = port de communication avec le serveur distant. *
+* use = statut de l'utilisation du serveur distant. *
+* *
+* Description : Définit le serveur distant associé au binaire courant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_loaded_binary_set_remote_server(GLoadedBinary *binary, const char *host, unsigned short port, bool use)
+{
+ free(binary->remote_host);
+ binary->remote_host = strdup(host);
+
+ binary->remote_port = port;
+
+ binary->use_remote_server = use;
+
+ if (use)
+ /* TODO : reload conn ! */;
+ else
+ /* TODO : stop conn ! */;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* feature = fonctionnalité visée par la requête. *
+* *
+* Description : Indique la forme d'enregistrement d'une fonctionnalité. *
+* *
+* Retour : Type d'enregistrement sélectionné. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+DBStorage g_loaded_binary_get_storage(const GLoadedBinary *binary, DBFeatures feature)
+{
+ return binary->storages[feature];
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* feature = fonctionnalité visée par la requête. *
+* storage = type d'enregistrement sélectionné. *
+* *
+* Description : Définit la forme d'enregistrement d'une fonctionnalité. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_loaded_binary_set_storage(GLoadedBinary *binary, DBFeatures feature, DBStorage storage)
+{
+ binary->storages[feature] = storage;
+
+}
+
+
+
+
+
+
+
+
+
+
/******************************************************************************
* *
* Paramètres : binary = élément binaire à consulter. *
@@ -541,6 +942,18 @@ void g_loaded_binary_analyse(GLoadedBinary *binary)
GBinPart **parts; /* Parties d'élément binaire */
size_t parts_count; /* Nombre de ces parties */
+ /* Détermination de l'identifiant */
+
+ binary->checksum = g_checksum_new(G_CHECKSUM_SHA256);
+ g_checksum_update(binary->checksum, binary->bin_data, binary->bin_length);
+
+ /* Contacts avec les serveurs */
+
+
+
+
+
+
if (binary->parts_count[BPM_ROUTINES] > 0)
binary->model = BPM_ROUTINES;
@@ -597,6 +1010,25 @@ const char *g_loaded_binary_get_filename(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. *