diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2014-08-18 21:55:24 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2014-08-18 21:55:24 (GMT) |
commit | a0a7b6c1e05c78ae433f353d15e3366107b67d03 (patch) | |
tree | bca0b187778cf016c6131bfc982b08c67a38442b /src/core/collections.c | |
parent | 161c0f8ab227af5033b1b6456607b9b9c3bc60df (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/collections.c')
-rw-r--r-- | src/core/collections.c | 175 |
1 files changed, 175 insertions, 0 deletions
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; + +} |