summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/binary.c286
-rw-r--r--src/analysis/binary.h14
-rw-r--r--src/analysis/project.c67
3 files changed, 48 insertions, 319 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;
diff --git a/src/analysis/binary.h b/src/analysis/binary.h
index 56f21a1..0241381 100644
--- a/src/analysis/binary.h
+++ b/src/analysis/binary.h
@@ -81,12 +81,6 @@ GLoadedContent *g_loaded_binary_new(GExeFormat *);
/* ------------------------- INFORMATIONS D'ENREGISTREMENTS ------------------------- */
-/* Identifie l'utilisateur analysant le binaire courant. */
-const char *g_loaded_binary_get_username(const GLoadedBinary *);
-
-/* Définit l'utilisateur analysant le binaire courant. */
-void g_loaded_binary_set_username(GLoadedBinary *, const char *);
-
/* Détermine si tous les enregistrements sont locaux ou non. */
bool g_loaded_binary_use_remote_storage(const GLoadedBinary *);
@@ -99,12 +93,6 @@ void g_loaded_binary_get_remote_server(const GLoadedBinary *, const char **, con
/* Définit le serveur distant associé au binaire courant. */
void g_loaded_binary_set_remote_server(GLoadedBinary *, const char *, const char *);
-/* Indique la forme d'enregistrement d'une fonctionnalité. */
-DBStorage g_loaded_binary_get_storage(const GLoadedBinary *, DBFeatures);
-
-/* Définit la forme d'enregistrement d'une fonctionnalité. */
-void g_loaded_binary_set_storage(GLoadedBinary *, DBFeatures, DBStorage);
-
/* Sauvegarde le cache des instructions désassemblées. */
bool g_loaded_binary_save_cache(const GLoadedBinary *);
@@ -114,7 +102,7 @@ bool g_loaded_binary_save_cache(const GLoadedBinary *);
/* Fournit un client assurant la liaison avec un serveur. */
-GAnalystClient *g_loaded_binary_get_client(const GLoadedBinary *, bool);
+GAnalystClient *g_loaded_binary_get_client(const GLoadedBinary *);
/* Fournit l'ensemble des collections utilisées par un binaire. */
GDbCollection **g_loaded_binary_get_collections(const GLoadedBinary *, size_t *);
diff --git a/src/analysis/project.c b/src/analysis/project.c
index 13985f3..b57afc7 100644
--- a/src/analysis/project.c
+++ b/src/analysis/project.c
@@ -381,14 +381,8 @@ bool g_study_project_save(GStudyProject *project, const char *filename)
xmlDocPtr xdoc; /* Document XML à créer */
xmlXPathContextPtr context; /* Contexte pour les recherches*/
const char *final; /* Lieu d'enregistrement final */
- size_t root_count; /* Quantité d'origines */
size_t i; /* Boucle de parcours */
- GBinContent *content; /* Contenu brut à manipuler */
- GBinContent *root; /* Contenu d'origine à traiter */
- const gchar *hash; /* Empreinte d'un contenu */
char *access; /* Chemin pour une sous-config.*/
- xmlXPathObjectPtr xobject; /* Cible d'une recherche */
- char *format; /* Format associé à un élément */
/* Forme générale */
@@ -401,85 +395,26 @@ bool g_study_project_save(GStudyProject *project, const char *filename)
result = add_string_attribute_to_node(xdoc, context, "/ChrysalideProject", "version", PROJECT_XML_VERSION);
if (result)
- result = (ensure_node_exist(xdoc, context, "/ChrysalideProject/RootContents") != NULL);
-
- if (result)
result = (ensure_node_exist(xdoc, context, "/ChrysalideProject/LoadedContents") != NULL);
final = filename != NULL ? filename : project->filename;
/* Inscriptions des contenus */
- root_count = 0;
-
g_study_project_lock_contents(project);
for (i = 0; i < project->count && result; i++)
{
- content = g_loaded_content_get_content(project->contents[i]);
-
- /* Racine */
-
- root = g_binary_content_get_root(content);
-
- hash = g_binary_content_get_checksum(root);
-
- asprintf(&access, "/ChrysalideProject/RootContents/Content[@hash='%s']", hash);
-
- xobject = get_node_xpath_object(context, access);
-
- free(access);
-
- if (XPATH_OBJ_NODES_COUNT(xobject) == 0)
- {
- asprintf(&access, "/ChrysalideProject/RootContents/Content[position()=%zu]", ++root_count);
-
- if (result)
- result = (ensure_node_exist(xdoc, context, access) != NULL);
-
- if (result)
- {
- hash = g_binary_content_get_checksum(content);
- result = add_string_attribute_to_node(xdoc, context, access, "hash", hash);
- }
-
- if (result)
- result = g_binary_content_save(root, xdoc, context, access, final);
-
- free(access);
-
- }
-
- if(xobject != NULL)
- xmlXPathFreeObject(xobject);
-
- /* Charge utile */
-
asprintf(&access, "/ChrysalideProject/LoadedContents/Content[position()=%zu]", i + 1);
if (result)
result = (ensure_node_exist(xdoc, context, access) != NULL);
if (result)
- {
- hash = g_binary_content_get_checksum(content);
- result = add_string_attribute_to_node(xdoc, context, access, "hash", hash);
- }
-
- if (result)
- {
- format = g_loaded_content_get_format_name(project->contents[i]);
- result = add_string_attribute_to_node(xdoc, context, access, "format", format);
- free(format);
- }
-
- if (result)
result = g_loaded_content_save(project->contents[i], xdoc, context, access);
free(access);
- g_object_unref(G_OBJECT(content));
-
}
g_study_project_unlock_contents(project);
@@ -1093,7 +1028,7 @@ static GLoadingHandler *g_loading_handler_new_recovering(GStudyProject *project,
{
asprintf(&access, "/ChrysalideProject/RootContents/Content[position()=%zu]", i + 1);
- content = g_binary_content_new_from_xml(context, access, project->filename);
+ content = NULL;//g_binary_content_new_from_xml(context, access, project->filename);
free(access);