summaryrefslogtreecommitdiff
path: root/src/core
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/core
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/core')
-rwxr-xr-xsrc/core/Makefile.am1
-rw-r--r--src/core/collections.c175
-rw-r--r--src/core/collections.h54
-rw-r--r--src/core/core.c5
-rw-r--r--src/core/params.c90
-rw-r--r--src/core/params.h6
6 files changed, 331 insertions, 0 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 0724a3f..02b6877 100755
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -2,6 +2,7 @@
noinst_LTLIBRARIES = libcore.la
libcore_la_SOURCES = \
+ collections.h collections.c \
core.h core.c \
params.h params.c
diff --git a/src/core/collections.c b/src/core/collections.c
new file mode 100644
index 0000000..860b7f6
--- /dev/null
+++ b/src/core/collections.c
@@ -0,0 +1,175 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * collections.c - enregistrement et la diffusion des collections
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "collections.h"
+
+
+#include <assert.h>
+#include <malloc.h>
+#include <pthread.h>
+
+
+#include "../analysis/db/collection.h"
+#include "../analysis/db/protocol.h"
+#include "../analysis/db/items/bookmark.h"
+
+
+
+/* Caractéristiques d'une collection */
+typedef struct _collec_t
+{
+ GType items; /* Type d'éléments rassemblés */
+ create_db_table_fc create; /* Création de la BD associée */
+
+} collec_t;
+
+
+/* Mémorisation des types de collection enregistrés */
+static collec_t *_collection_definitions = NULL;
+static uint32_t _collection_definitions_count = 0;
+
+/* Verrou pour des accès atomiques */
+/* ... */
+
+
+
+/******************************************************************************
+* *
+* Paramètres : items = type GLib des éléments constituant une collection. *
+* create = création de la base de données correspondante. *
+* *
+* Description : Enregistre un type d'élément à gérer par collection. *
+* *
+* Retour : Identifiant unique attribué "dynamiquement". *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+uint32_t register_collection_type(GType items, create_db_table_fc create)
+{
+ uint32_t result; /* Identifiant à retourner */
+
+ /* TODO : lock */
+
+ result = _collection_definitions_count++;
+
+ _collection_definitions = (collec_t *)realloc(_collection_definitions,
+ _collection_definitions_count * sizeof(collec_t));
+
+ _collection_definitions[result].items = items;
+ _collection_definitions[result].create = create;
+
+ /* TODO : unlock */
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Charge les définitions de collections "natives". *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool load_hard_coded_collection_definitions(void)
+{
+ uint32_t id; /* Identifiant unique retourné */
+
+ /**
+ * La liste des chargements doit se faire dans le même ordre que
+ * la définition de l'énumération 'DBFeatures' dans le fichier 'protocol.h',
+ * afin de garder la correspondance entre les identifiants.
+ */
+
+ id = register_collection_type(G_TYPE_DB_BOOKMARK, create_bookmark_db_table);
+ assert(id == DBF_BOOKMARKS);
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Décharge toutes les définitions de collections. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void unload_collection_definitions(void)
+{
+ if (_collection_definitions != NULL)
+ free(_collection_definitions);
+
+ _collection_definitions = NULL;
+ _collection_definitions_count = 0;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit un nouvel ensemble de collections. *
+* *
+* Retour : Liste complète de collections vierges. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GList *create_collections_list(void)
+{
+ GList *result; /* Groupe à retourner */
+ uint32_t i; /* Boucle de parcours */
+ const collec_t *def; /* Définition brute à lire */
+ GDbCollection *collec; /* Nouveau groupe à intégrer */
+
+ result = NULL;
+
+ for (i = 0; i < _collection_definitions_count; i++)
+ {
+ def = &_collection_definitions[i];
+ collec = g_db_collection_new(i, def->items);
+
+ result = g_list_append(result, collec);
+
+ }
+
+ return result;
+
+}
diff --git a/src/core/collections.h b/src/core/collections.h
new file mode 100644
index 0000000..b84bdd9
--- /dev/null
+++ b/src/core/collections.h
@@ -0,0 +1,54 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * collections.h - prototypes pour l'enregistrement et la diffusion des collections
+ *
+ * Copyright (C) 2014 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _CORE_COLLECTIONS_H
+#define _CORE_COLLECTIONS_H
+
+
+#include <glib-object.h>
+#include <sqlite3.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+
+
+/* Crée la table dans une base de données. */
+typedef bool (* create_db_table_fc) (sqlite3 *);
+
+
+
+/* Enregistre un type d'élément à gérer par collection. */
+uint32_t register_collection_type(GType, create_db_table_fc);
+
+/* Charge les définitions de collections "natives". */
+bool load_hard_coded_collection_definitions(void);
+
+/* Décharge toutes les définitions de collections. */
+void unload_collection_definitions(void);
+
+/* Construit un nouvel ensemble de collections. */
+GList *create_collections_list(void);
+
+
+
+#endif /* _ANALYSIS_DB_COLLECTION_H */
diff --git a/src/core/core.c b/src/core/core.c
index d90dd5c..d7e7755 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -24,6 +24,7 @@
#include "core.h"
+#include "collections.h"
#include "params.h"
@@ -50,6 +51,8 @@ bool load_all_basic_components(void)
result &= g_generic_config_read(get_main_configuration());
+ result &= load_hard_coded_collection_definitions();
+
return result;
}
@@ -69,6 +72,8 @@ bool load_all_basic_components(void)
void unload_all_basic_components(void)
{
+ unload_collection_definitions();
+
g_generic_config_write(get_main_configuration());
unload_main_config_parameters();
diff --git a/src/core/params.c b/src/core/params.c
index c8263f0..7bc1162 100644
--- a/src/core/params.c
+++ b/src/core/params.c
@@ -24,6 +24,75 @@
#include "params.h"
+#include <limits.h>
+#include <malloc.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Détermine une fois pour toute la désignation de l'usager. *
+* *
+* Retour : Nom déterminé à libérer de la mémoire. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *get_author_name(void)
+{
+ char *result; /* Désignation à retourner */
+ char *chrysalide_user; /* Eventuel nom spécifique */
+ char *logname; /* Nom depuis l'environnement */
+ char hostname[HOST_NAME_MAX]; /* Nom de la machine courante */
+ int ret; /* Bilan d'un appel */
+ size_t length; /* Taille de la désignation */
+
+ chrysalide_user = getenv("CHRYSALIDE_USER");
+
+ if (chrysalide_user != NULL)
+ result = strdup(chrysalide_user);
+
+ else
+ {
+ logname = getenv("LOGNAME");
+
+ ret = gethostname(hostname, HOST_NAME_MAX);
+ if (ret != 0)
+ hostname[0] = '\0';
+
+ if (logname != NULL && hostname[0] != '\0')
+ {
+ length = strlen(logname) + 1 + strlen(hostname) + 1;
+ result = (char *)calloc(length, sizeof(char));
+ snprintf(result, length, "%s@%s", logname, hostname);
+ }
+ else if (logname != NULL && hostname[0] == '\0')
+ {
+ length = strlen(logname) + 1;
+ result = (char *)calloc(length, sizeof(char));
+ snprintf(result, length, "%s", logname);
+ }
+ else if (logname == NULL && hostname[0] != '\0')
+ {
+ length = 1 + strlen(hostname) + 1;
+ result = (char *)calloc(length, sizeof(char));
+ snprintf(result, length, "@%s", hostname);
+ }
+ else
+ result = strdup("anonymous");
+
+ }
+
+ return result;
+
+}
+
/******************************************************************************
* *
@@ -41,10 +110,31 @@ bool load_main_config_parameters(void)
{
GGenConfig *config; /* Configuration à charger */
GCfgParam *param; /* Paramètre chargé */
+ char *string; /* Valeur sous forme de texte */
config = g_generic_config_new("main");
set_main_configuration(config);
+ string = get_author_name();
+ param = g_generic_config_create_param(config, MPK_AUTHOR_NAME, CPT_STRING, string);
+ free(string);
+ if (param == NULL) return false;
+
+ param = g_generic_config_create_param(config, MPK_REMOTE_HOST, CPT_STRING, "localhost");
+ if (param == NULL) return false;
+
+ param = g_generic_config_create_param(config, MPK_REMOTE_PORT, CPT_INTEGER, 9999);
+ if (param == NULL) return false;
+
+ param = g_generic_config_create_param(config, MPK_LOCAL_HOST, CPT_STRING, "localhost");
+ if (param == NULL) return false;
+
+ param = g_generic_config_create_param(config, MPK_LOCAL_PORT, CPT_INTEGER, 1337);
+ if (param == NULL) return false;
+
+ param = g_generic_config_create_param(config, MPK_SERVER_BACKLOG, CPT_INTEGER, 20);
+ if (param == NULL) return false;
+
param = g_generic_config_create_param(config, MPK_LAST_PROJECT, CPT_STRING, NULL);
if (param == NULL) return false;
diff --git a/src/core/params.h b/src/core/params.h
index b79cc3a..db01d20 100644
--- a/src/core/params.h
+++ b/src/core/params.h
@@ -33,6 +33,12 @@
* Clefs de paramètres de configuration principale.
*/
+#define MPK_AUTHOR_NAME "cdb.default.author"
+#define MPK_REMOTE_HOST "cdb.default.network.remote.server"
+#define MPK_REMOTE_PORT "cdb.default.network.remote.port"
+#define MPK_LOCAL_HOST "cdb.network.local.server"
+#define MPK_LOCAL_PORT "cdb.network.local.port"
+#define MPK_SERVER_BACKLOG "cdb.network.server.backlog"
#define MPK_LAST_PROJECT "gui.editor.last_project"
#define MPK_ELLIPSIS_HEADER "gui.editor.panels.ellipsis_header"
#define MPK_ELLIPSIS_TAB "gui.editor.panels.ellipsis_tab"