summaryrefslogtreecommitdiff
path: root/src/analysis/binary.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2014-08-18 21:55:24 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2014-08-18 21:55:24 (GMT)
commita0a7b6c1e05c78ae433f353d15e3366107b67d03 (patch)
treebca0b187778cf016c6131bfc982b08c67a38442b /src/analysis/binary.c
parent161c0f8ab227af5033b1b6456607b9b9c3bc60df (diff)
Inserted storages and collections into loaded binaries (first steps).
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@389 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/binary.c')
-rw-r--r--src/analysis/binary.c194
1 files changed, 191 insertions, 3 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 83e81d8..5577bb8 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -40,6 +40,7 @@
#include "disass/disassembler.h"
#include "../common/extstr.h"
#include "../common/cpp.h"
+#include "../core/params.h"
@@ -222,11 +223,20 @@ static void g_loaded_binary_finalize(GLoadedBinary *binary)
* Remarques : - *
* *
******************************************************************************/
-
+#include "db/items/bookmark.h"
GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const char *path)
{
GLoadedBinary *result; /* Adresse à retourner */
char *type; /* Type de binaire à charger */
+
+
+
+ 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;
@@ -241,16 +251,101 @@ GLoadedBinary *g_loaded_binary_new_from_xml(xmlXPathContextPtr context, const ch
if (result == NULL)
return NULL;
+ /* --------- %< --------- TODO : à bouger pur + de générique --------- %< --------- */
+
+
+ result->collections = create_collections_list();
+
+
if (!g_loaded_binary_load_storage(result, context, path))
goto glbnfx_error;
+
+ /* --------- %< --------- TODO : à bouger pur + de générique --------- %< --------- */
+
+
+
/*
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("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_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);
+
+
+
+
+
+ /* --------- %< --------- %< --------- %< --------- %< --------- */
+
+ do
+ {
+ vmpa2t addr;
+ GDbBookmark *bm;
+ bool status;
+
+
+ init_vmpa(&addr, 123, 0x200);
+
+ bm = g_db_bookmark_new(&addr, "Premier commentaire");
+
+
+
+ status = g_loaded_binary_add_to_collection(result, DBF_BOOKMARKS, G_DB_ITEM(bm));
+
+ if (status)
+ printf("send OK\n");
+ else
+ printf("send nok\n");
+
+
+ /*
+ safe_send(client->fd, (uint32_t []) { htobe32(DBC_COLLECTION) }, sizeof(uint32_t), MSG_MORE);
+ safe_send(client->fd, (uint32_t []) { htobe32(DBF_BOOKMARKS) }, sizeof(uint32_t), MSG_MORE);
+ safe_send(client->fd, (uint32_t []) { htobe32(DBA_ADD_ITEM) }, sizeof(uint32_t), MSG_MORE);
+
+ if (g_db_item_send(G_DB_ITEM(bm), client->fd, 0))
+ printf("send OK\n");
+ else
+ printf("send nok\n");
+
+ */
+
+
+ }
+ while (0);
+
+ /* --------- %< --------- %< --------- %< --------- %< --------- */
+
+
+
+
+
+
printf("DB status :: %d\n", status);
@@ -872,6 +967,97 @@ void g_loaded_binary_set_storage(GLoadedBinary *binary, DBFeatures feature, DBSt
+/* ---------------------------------------------------------------------------------- */
+/* MANIPULATION DES COLLECTIONS */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* feature = fonctionnalité assurée par la collection visée. *
+* *
+* Description : Trouve une collection assurant une fonctionnalité donnée. *
+* *
+* Retour : Collection trouvée ou NULL. *
+* *
+* Remarques : Le résultat est à déréfrencer après usage. *
+* *
+******************************************************************************/
+
+GDbCollection *g_loaded_binary_find_collection(GLoadedBinary *binary, DBFeatures feature)
+{
+ GDbCollection *result; /* Collection à retourner */
+
+ /* TODO : lock */
+
+ result = find_collection_in_list(binary->collections, feature);
+
+ if (result != NULL)
+ g_object_ref(G_OBJECT(result));
+
+ /* TODO : unlock */
+
+ return result;
+
+}
+
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = élément binaire à consulter. *
+* feature = fonctionnalité visée par la requête. *
+* item = élémnent à pousser vers un serveur de collection. *
+* *
+* Description : Demande l'intégration d'une modification dans une collection.*
+* *
+* Retour : Bilan partiel de l'opération demandée. *
+* *
+* Remarques : L'appelant perd la propriété de l'élément à ajouté. *
+* *
+******************************************************************************/
+
+bool g_loaded_binary_add_to_collection(GLoadedBinary *binary, DBFeatures feature, GDbItem *item)
+{
+ bool result; /* Bilan à faire remonter */
+ GDbCollection *collec; /* Collection visée au final */
+ DBStorage storage; /* Forme d'enregistrement */
+ GDbClient *client; /* Liaison à utiliser */
+ int fd; /* Identifiant du canal de com.*/
+
+ collec = g_loaded_binary_find_collection(binary, feature);
+ if (collec == NULL) return false;
+
+ /* S'il n'y a pas besoin de sauvegarde... */
+ if (g_db_item_is_volatile(item))
+ g_db_collection_add_item(collec, item);
+
+ /* Sinon on envoie par le réseau ! */
+ else
+ {
+ storage = g_loaded_binary_get_storage(binary, feature);
+
+
+ /* TODO : sélection du bon client... */
+ client = binary->local;
+
+
+ fd = g_db_client_get_fd(client);
+
+ result = g_db_collection_send(collec, fd, DBA_ADD_ITEM, item);
+
+ g_db_client_put_fd(client);
+
+ }
+
+ g_object_unref(G_OBJECT(collec));
+ g_object_unref(G_OBJECT(item));
+
+ return result;
+
+}
+
@@ -946,8 +1132,10 @@ 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 */