summaryrefslogtreecommitdiff
path: root/src/analysis/binary.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/binary.c')
-rw-r--r--src/analysis/binary.c286
1 files changed, 46 insertions, 240 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 19b46a2..2b23eff 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -65,17 +65,11 @@ struct _GLoadedBinary
{
GObject parent; /* A laisser en premier */
- char *username; /* Identifiant de l'utilisateur*/
- bool username_changed; /* Mémorise les changements */
-
bool use_remote; /* Enregistrements distants ? */
char *remote_host; /* Nom du serveur distant */
char *remote_port; /* Port du serveur distant */
+ GAnalystClient *client; /* Enregistrements courants */
- GAnalystClient *local; /* Enregistrements locaux */
- GAnalystClient *remote; /* Enregistrements distants */
-
- DBStorage storages[DBF_COUNT]; /* Lieux d'enregistrement */
GList *collections; /* Ensemble de modifications */
GExeFormat *format; /* Format du binaire */
@@ -246,17 +240,10 @@ static void g_loaded_binary_class_init(GLoadedBinaryClass *klass)
static void g_loaded_binary_init(GLoadedBinary *binary)
{
- binary->username = strdup("default");
-
binary->use_remote = false;
binary->remote_host = strdup("localhost");
binary->remote_port = strdup("1337");
- binary->storages[DBF_BOOKMARKS] = DBS_ALL_LOCAL;
- binary->storages[DBF_COMMENTS] = DBS_ALL_LOCAL;
- binary->storages[DBF_MOVES] = DBS_ALL_LOCAL;
- binary->storages[DBF_DISPLAY_SWITCHERS] = DBS_ALL_LOCAL;
-
binary->collections = create_collections_list();
attach_binary_to_collections(binary->collections, binary);
@@ -332,8 +319,7 @@ static void g_loaded_binary_dispose(GLoadedBinary *binary)
{
BinaryView i; /* Boucle de parcours */
- g_clear_object(&binary->local);
- g_clear_object(&binary->remote);
+ g_clear_object(&binary->client);
delete_collections_list(&binary->collections);
@@ -366,9 +352,8 @@ static void g_loaded_binary_dispose(GLoadedBinary *binary)
static void g_loaded_binary_finalize(GLoadedBinary *binary)
{
- free(binary->username);
-
free(binary->remote_host);
+ free(binary->remote_port);
G_OBJECT_CLASS(g_loaded_binary_parent_class)->finalize(G_OBJECT(binary));
@@ -427,7 +412,6 @@ static bool g_loaded_binary_load_storage(GLoadedBinary *binary, xmlXPathContext
char *value; /* Valeur lue à partie du XML */
char *access; /* Chemin d'accès à un élément */
char *port; /* Port de communication */
- DBFeatures i; /* Boucle de parcours */
result = true;
@@ -441,21 +425,6 @@ static bool g_loaded_binary_load_storage(GLoadedBinary *binary, xmlXPathContext
free(value);
- /* 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);
@@ -483,46 +452,6 @@ static bool g_loaded_binary_load_storage(GLoadedBinary *binary, xmlXPathContext
free(access);
- /* Fonctionnalités */
-
- for (i = 0; i < DBF_COUNT; i++)
- {
- access = strdup(storage_path);
- access = stradd(access, "/Features/");
-
- switch (i)
- {
- case DBF_BOOKMARKS:
- access = stradd(access, "Bookmarks");
- break;
- case DBF_COMMENTS:
- access = stradd(access, "Comments");
- break;
- case DBF_MOVES:
- access = stradd(access, "Moves");
- break;
- case DBF_DISPLAY_SWITCHERS:
- access = stradd(access, "Segments");
- break;
- default:
- /* Pour GCC */
- assert(false);
- 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);
-
- }
-
if (binary->use_remote)
g_loaded_binary_set_remote_storage_usage(binary, true);
@@ -555,7 +484,6 @@ static bool g_loaded_binary_save_storage(const GLoadedBinary *binary, xmlDoc *xd
bool result; /* Bilan à faire remonter */
char *storage_path; /* Partie "Enregistrement" */
char *access; /* Chemin d'accès à un élément */
- DBFeatures i; /* Boucle de parcours */
result = true;
@@ -565,15 +493,6 @@ static bool g_loaded_binary_save_storage(const GLoadedBinary *binary, xmlDoc *xd
result &= add_string_attribute_to_node(xdoc, context, storage_path, "remote",
binary->use_remote ? "true" : "false");
- /* 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);
@@ -585,39 +504,6 @@ static bool g_loaded_binary_save_storage(const GLoadedBinary *binary, xmlDoc *xd
free(access);
- /* Fonctionnalités */
-
- for (i = 0; i < DBF_COUNT; i++)
- {
- access = strdup(storage_path);
- access = stradd(access, "/Features/");
-
- switch (i)
- {
- case DBF_BOOKMARKS:
- access = stradd(access, "Bookmarks");
- break;
- case DBF_COMMENTS:
- access = stradd(access, "Comments");
- break;
- case DBF_MOVES:
- access = stradd(access, "Moves");
- break;
- case DBF_DISPLAY_SWITCHERS:
- access = stradd(access, "Segments");
- break;
- default:
- /* Pour GCC */
- assert(false);
- break;
- }
-
- result &= add_uint_content_to_node(xdoc, context, access, binary->storages[i]);
-
- free(access);
-
- }
-
free(storage_path);
return result;
@@ -629,52 +515,6 @@ static bool g_loaded_binary_save_storage(const GLoadedBinary *binary, xmlDoc *xd
* *
* 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. *
-* *
* Description : Détermine si tous les enregistrements sont locaux ou non. *
* *
* Retour : Statut de l'utilisation du serveur local. *
@@ -707,7 +547,7 @@ void g_loaded_binary_set_remote_storage_usage(GLoadedBinary *binary, bool use)
{
binary->use_remote = use;
- g_clear_object(&binary->remote);
+ g_clear_object(&binary->client);
if (use)
g_loaded_binary_connect_remote(binary);
@@ -764,47 +604,6 @@ void g_loaded_binary_set_remote_server(GLoadedBinary *binary, const char *host,
/******************************************************************************
* *
-* 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 à manipuler. *
* *
* Description : Etablit une connexion au serveur interne en tant que client. *
@@ -829,9 +628,9 @@ static bool g_loaded_binary_connect_internal(GLoadedBinary *binary)
/* Tentative de connexion */
- binary->local = g_analyst_client_new(checksum, binary->collections);
+ binary->client = g_analyst_client_new(checksum, binary->collections);
- result = g_hub_client_start_internal(G_HUB_CLIENT(binary->local));
+ result = g_hub_client_start_internal(G_HUB_CLIENT(binary->client));
return result;
@@ -856,7 +655,7 @@ static bool g_loaded_binary_connect_remote(GLoadedBinary *binary)
GBinContent *content; /* Contenu bianire manipulé */
const gchar *checksum; /* Identifiant de binaire */
- assert(binary->remote == NULL);
+ assert(binary->client == NULL);
/* Détermination de l'identifiant */
@@ -866,9 +665,9 @@ static bool g_loaded_binary_connect_remote(GLoadedBinary *binary)
/* Tentative de connexion */
- binary->remote = g_analyst_client_new(checksum, binary->collections);
+ binary->client = g_analyst_client_new(checksum, binary->collections);
- result = g_hub_client_start_remote(G_HUB_CLIENT(binary->remote),
+ result = g_hub_client_start_remote(G_HUB_CLIENT(binary->client),
binary->remote_host, binary->remote_port, true);
if (!result)
@@ -876,7 +675,7 @@ static bool g_loaded_binary_connect_remote(GLoadedBinary *binary)
log_variadic_message(LMT_ERROR, _("Failed to connect to remote host '%s:%s'"),
binary->remote_host, binary->remote_port);
- g_clear_object(&binary->remote);
+ g_clear_object(&binary->client);
}
@@ -940,8 +739,7 @@ bool g_loaded_binary_save_cache(const GLoadedBinary *binary)
/******************************************************************************
* *
-* Paramètres : binary = élément binaire à consulter. *
-* internal = sélectionne le client à renvoyer selon sa nature. *
+* Paramètres : binary = élément binaire à consulter. *
* *
* Description : Fournit un client assurant la liaison avec un serveur. *
* *
@@ -951,14 +749,11 @@ bool g_loaded_binary_save_cache(const GLoadedBinary *binary)
* *
******************************************************************************/
-GAnalystClient *g_loaded_binary_get_client(const GLoadedBinary *binary, bool internal)
+GAnalystClient *g_loaded_binary_get_client(const GLoadedBinary *binary)
{
GAnalystClient *result; /* Instance à retourner */
- if (internal)
- result = binary->local;
- else
- result = binary->remote;
+ result = binary->client;
if (result != NULL)
g_object_ref(G_OBJECT(result));
@@ -1054,15 +849,9 @@ GDbCollection *g_loaded_binary_find_collection(const GLoadedBinary *binary, DBFe
bool g_loaded_binary_add_to_collection(GLoadedBinary *binary, GDbItem *item)
{
bool result; /* Bilan à faire remonter */
- DBFeatures feature; /* Domaine de fonctionnalité */
- DBStorage storage; /* Forme d'enregistrement */
GAnalystClient *client; /* Liaison à utiliser */
- feature = g_db_item_get_feature(item);
-
- storage = g_loaded_binary_get_storage(binary, feature);
-
- client = g_loaded_binary_get_client(binary, storage == DBS_ALL_LOCAL);
+ client = g_loaded_binary_get_client(binary);
if (client == NULL)
{
@@ -1099,24 +888,13 @@ bool g_loaded_binary_add_to_collection(GLoadedBinary *binary, GDbItem *item)
bool g_loaded_binary_set_last_active(GLoadedBinary *binary, timestamp_t timestamp)
{
bool result; /* Bilan à retourner */
- bool done; /* Suivi des actions menées */
result = true;
- done = false;
- if (binary->local != NULL)
- {
- result = g_analyst_client_set_last_active(binary->local, timestamp);
- done = true;
- }
-
- if (result && binary->remote != NULL)
- {
- result = g_analyst_client_set_last_active(binary->remote, timestamp);
- done = true;
- }
+ if (binary->client != NULL)
+ result = g_analyst_client_set_last_active(binary->client, timestamp);
- if (!done)
+ else
{
log_simple_message(LMT_ERROR, _("No connection to a server found in order to set timestamp"));
result = false;
@@ -1530,6 +1308,9 @@ static bool g_loaded_binary_restore(GLoadedBinary *binary, xmlDoc *xdoc, xmlXPat
static bool g_loaded_binary_save(GLoadedBinary *binary, xmlDoc *xdoc, xmlXPathContext *context, const char *path)
{
bool result; /* Bilan à faire remonter */
+ GBinContent *content; /* Contenu brut à manipuler */
+ const gchar *hash; /* Empreinte d'un contenu */
+ char *key; /* Support associé au contenu */
/* Mise en cache des instructions */
@@ -1538,6 +1319,31 @@ static bool g_loaded_binary_save(GLoadedBinary *binary, xmlDoc *xdoc, xmlXPathCo
/* Elément divers associés au binaire */
if (result)
+ {
+ content = g_loaded_content_get_content(G_LOADED_CONTENT(binary));
+
+ hash = g_binary_content_get_checksum(content);
+ result = add_string_attribute_to_node(xdoc, context, path, "hash", hash);
+
+ g_object_unref(G_OBJECT(content));
+
+ }
+
+ if (result)
+ {
+ key = g_loaded_content_get_format_name(G_LOADED_CONTENT(binary));
+ result = add_string_attribute_to_node(xdoc, context, path, "format", key);
+ free(key);
+ }
+
+ if (result)
+ {
+ key = g_arch_processor_get_key(binary->proc);
+ result = add_string_attribute_to_node(xdoc, context, path, "arch", key);
+ free(key);
+ }
+
+ if (result)
result = g_loaded_binary_save_storage(binary, xdoc, context, path);
if (result)
@@ -1546,7 +1352,7 @@ static bool g_loaded_binary_save(GLoadedBinary *binary, xmlDoc *xdoc, xmlXPathCo
/* Sauvegarde côté serveur */
if (result)
- g_analyst_client_save(binary->local);
+ g_analyst_client_save(binary->client);
return result;