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/analysis/db/items | |
| 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/analysis/db/items')
| -rw-r--r-- | src/analysis/db/items/Makefile.am | 17 | ||||
| -rw-r--r-- | src/analysis/db/items/bookmark.c | 416 | ||||
| -rw-r--r-- | src/analysis/db/items/bookmark.h | 79 | ||||
| -rw-r--r-- | src/analysis/db/items/comment.c | 398 | ||||
| -rw-r--r-- | src/analysis/db/items/comment.h | 77 | 
5 files changed, 987 insertions, 0 deletions
diff --git a/src/analysis/db/items/Makefile.am b/src/analysis/db/items/Makefile.am new file mode 100644 index 0000000..f026d44 --- /dev/null +++ b/src/analysis/db/items/Makefile.am @@ -0,0 +1,17 @@ + +noinst_LTLIBRARIES  = libanalysisdbitems.la + +libanalysisdbitems_la_SOURCES =			\ +	bookmark.h bookmark.c				\ +	comment.h comment.c + +libanalysisdbitems_la_LIBADD =	 + +libanalysisdbitems_la_LDFLAGS =  + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBARCHIVE_CFLAGS) $(LIBSQLITE_CFLAGS) + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS =  diff --git a/src/analysis/db/items/bookmark.c b/src/analysis/db/items/bookmark.c new file mode 100644 index 0000000..c28a837 --- /dev/null +++ b/src/analysis/db/items/bookmark.c @@ -0,0 +1,416 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * bookmark.h - prototypes pour la gestion des signets au sein d'un binaire + * + * 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 "bookmark.h" + + +#include <stdio.h> +#include <sys/socket.h> + + +#include "../item-int.h" +#include "../misc/rlestr.h" + + + +/* Signet à l'intérieur d'une zone de texte (instance) */ +struct _GDbBookmark +{ +    GDbItem parent;                         /* A laisser en premier        */ + +    vmpa2t addr;                            /* Adresse du signet           */ +    rle_string comment;                     /* Eventuel commentaire associé*/ + +}; + +/* Signet à l'intérieur d'une zone de texte (classe) */ +struct _GDbBookmarkClass +{ +    GDbItemClass parent;                    /* A laisser en premier        */ + +}; + + + +/* Initialise la classe des signets dans une zone de texte. */ +static void g_db_bookmark_class_init(GDbBookmarkClass *); + +/* Initialise un signet dans une zone de texte. */ +static void g_db_bookmark_init(GDbBookmark *); + +/* Supprime toutes les références externes. */ +static void g_db_bookmark_dispose(GDbBookmark *); + +/* Procède à la libération totale de la mémoire. */ +static void g_db_bookmark_finalize(GDbBookmark *); + + + +/* Effectue la comparaison entre deux signets de collection. */ +static gint g_db_bookmark_cmp(GDbBookmark *, GDbBookmark *); + +/* Importe la définition d'un signet dans un flux réseau. */ +static bool g_db_bookmark_recv_from_fd(GDbBookmark *, int, int); + +/* Exporte la définition d'un signet dans un flux réseau. */ +static bool g_db_bookmark_send_to_fd(const GDbBookmark *, int, int); + + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : db = accès à la base de données.                             * +*                                                                             * +*  Description : Crée la table des signets dans une base de données.          * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool create_bookmark_db_table(sqlite3 *db) +{ +    char *sql;                              /* Requête à exécuter          */ +    int ret;                                /* Bilan de la création        */ +    char *msg;                              /* Message d'erreur            */ + +    sql = "CREATE TABLE Bookmarks ("            \ +             "id INT PRIMARY KEY NOT NULL, "    \ +             "user TEXT NOT NULL, "             \ +             "created INT NOT NULL, "           \ +             "address INT NOT NULL, "           \ +             "comment TEXT"                     \ +          ");"; + +    ret = sqlite3_exec(db, sql, NULL, NULL, &msg); +    if (ret != SQLITE_OK) +    { +        fprintf(stderr, "sqlite3_exec(): %s\n", msg); +        sqlite3_free(msg); +    } + +    return (ret == SQLITE_OK); + +} + + + + + + + + + + +/* Indique le type défini pour un signet à l'intérieur d'une zone de texte. */ +G_DEFINE_TYPE(GDbBookmark, g_db_bookmark, G_TYPE_DB_ITEM); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des signets dans une zone de texte.     * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_db_bookmark_class_init(GDbBookmarkClass *klass) +{ +    GObjectClass *object;                   /* Autre version de la classe  */ +    GDbItemClass *item;                     /* Encore une autre vision...  */ + +    object = G_OBJECT_CLASS(klass); + +    object->dispose = (GObjectFinalizeFunc/* ! */)g_db_bookmark_dispose; +    object->finalize = (GObjectFinalizeFunc)g_db_bookmark_finalize; + +    item = G_DB_ITEM_CLASS(klass); + +    item->cmp = (GCompareFunc)g_db_bookmark_cmp; + +    item->recv = (recv_db_item_fc)g_db_bookmark_recv_from_fd; +    item->send = (send_db_item_fc)g_db_bookmark_send_to_fd; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : bookmark = instance à initialiser.                           * +*                                                                             * +*  Description : Initialise un signet dans une zone de texte.                 * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_db_bookmark_init(GDbBookmark *bookmark) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : bookmark = instance d'objet GLib à traiter.                  * +*                                                                             * +*  Description : Supprime toutes les références externes.                     * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_db_bookmark_dispose(GDbBookmark *bookmark) +{ +    G_OBJECT_CLASS(g_db_bookmark_parent_class)->dispose(G_OBJECT(bookmark)); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : bookmark = instance d'objet GLib à traiter.                  * +*                                                                             * +*  Description : Procède à la libération totale de la mémoire.                * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_db_bookmark_finalize(GDbBookmark *bookmark) +{ +    G_OBJECT_CLASS(g_db_bookmark_parent_class)->finalize(G_OBJECT(bookmark)); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : addr    = adresse inamovible localisant une position donnée. * +*                comment = commentaire construit ou NULL.                     * +*                                                                             * +*  Description : Crée une définition d'un signet dans une zone de texte.      * +*                                                                             * +*  Retour      : Signet mis en place ou NULL en cas d'erreur.                 * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDbBookmark *g_db_bookmark_new(const vmpa2t *addr, const char *comment) +{ +    GDbBookmark *result;                    /* Instance à retourner        */ + +    result = g_object_new(G_TYPE_DB_BOOKMARK, NULL); + + + + +    /* TODO */ + +    //dup addr; + + +    g_db_bookmark_set_comment(result, comment); + +    return result; + +} + + + + + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : a = premier élément à analyser.                              * +*                b = second élément à analyser.                               * +*                                                                             * +*  Description : Effectue la comparaison entre deux signets de collection.    * +*                                                                             * +*  Retour      : Bilan de la comparaison : -1, 0 ou 1.                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static gint g_db_bookmark_cmp(GDbBookmark *a, GDbBookmark *b) +{ +    gint result;                            /* Bilan de la comparaison     */ + +    result = cmp_vmpa_by_phy(&a->addr, &b->addr); + +    if (result == 0) +        result = cmp_rle_string(&a->comment, &b->comment); + +    return 0; + + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : bookmark = signet dont les informations sont à charger. [OUT]* +*                fd       = flux ouvert en lecture pour l'importation.        * +*                flags    = éventuelles options d'envoi supplémentaires.      * +*                                                                             * +*  Description : Importe la définition d'un signet dans un flux réseau.       * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_db_bookmark_recv_from_fd(GDbBookmark *bookmark, int fd, int flags) +{ +    bool status;                            /* Bilan d'opération initiale  */ + +    status = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->recv(G_DB_ITEM(bookmark), fd, flags); +    if (!status) return false; + +    if (!recv_vmpa(&bookmark->addr, fd, 0)) +        return false; + +    if (!recv_rle_string(&bookmark->comment, fd, 0)) +        return false; + +    return true; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : bookmark = informations à sauvegarder.                       * +*                fd       = flux ouvert en écriture pour l'exportation.       * +*                flags    = éventuelles options d'envoi supplémentaires.      * +*                                                                             * +*  Description : Exporte la définition d'un signet dans un flux réseau.       * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_db_bookmark_send_to_fd(const GDbBookmark *bookmark, int fd, int flags) +{ +    bool status;                            /* Bilan d'opération initiale  */ + +    status = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->send(G_DB_ITEM(bookmark), fd, MSG_MORE | flags); +    if (!status) return false; + + +    printf("<sending> FROM %s...\n", __FUNCTION__); + + +    if (!send_vmpa(&bookmark->addr, fd, MSG_MORE | flags)) +        return false; + +    if (!send_rle_string(&bookmark->comment, fd, flags)) +        return false; + +    return true; + +} + + + + + + + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : bookmark = informations à consulter.                         * +*                                                                             * +*  Description : Fournit l'adresse associée à un signet.                      * +*                                                                             * +*  Retour      : Adresse mémoire.                                             * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +vmpa2t *g_db_bookmark_get_address(GDbBookmark *bookmark) +{ +    return &bookmark->addr; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : bookmark = informations à consulter.                         * +*                                                                             * +*  Description : Fournit le commentaire associé à un signet.                  * +*                                                                             * +*  Retour      : Commentaire existant ou NULL.                                * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +const char *g_db_bookmark_get_comment(const GDbBookmark *bookmark) +{ +    return get_rle_string(&bookmark->comment); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : bookmark = informations à consulter.                         * +*                comment  = commentaire construit ou NULL.                    * +*                                                                             * +*  Description : Définit le commentaire associé à un signet.                  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void g_db_bookmark_set_comment(GDbBookmark *bookmark, const char *comment) +{ +    set_rle_string(&bookmark->comment, comment); + +} diff --git a/src/analysis/db/items/bookmark.h b/src/analysis/db/items/bookmark.h new file mode 100644 index 0000000..d1b073c --- /dev/null +++ b/src/analysis/db/items/bookmark.h @@ -0,0 +1,79 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * bookmark.h - prototypes pour la gestion des signets au sein d'un binaire + * + * 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 _ANALYSIS_DB_ITEMS_BOOKMARK_H +#define _ANALYSIS_DB_ITEMS_BOOKMARK_H + + + +#include <glib-object.h> +#include <sqlite3.h> +#include <stdbool.h> + + +#include "../../../arch/vmpa.h" + + + +/* Crée la table des signets dans une base de données. */ +bool create_bookmark_db_table(sqlite3 *); + + + + + + + +#define G_TYPE_DB_BOOKMARK               g_db_bookmark_get_type() +#define G_DB_BOOKMARK(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_db_bookmark_get_type(), GDbBookmark)) +#define G_IS_DB_BOOKMARK(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_db_bookmark_get_type())) +#define G_DB_BOOKMARK_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DB_BOOKMARK, GDbBookmarkClass)) +#define G_IS_DB_BOOKMARK_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DB_BOOKMARK)) +#define G_DB_BOOKMARK_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DB_BOOKMARK, GDbBookmarkClass)) + + +/* Signet à l'intérieur d'une zone de texte (instance) */ +typedef struct _GDbBookmark GDbBookmark; + +/* Signet à l'intérieur d'une zone de texte (classe) */ +typedef struct _GDbBookmarkClass GDbBookmarkClass; + + +/* Indique le type défini pour un signet à l'intérieur d'une zone de texte. */ +GType g_db_bookmark_get_type(void); + +/* Crée une définition d'un signet dans une zone de texte. */ +GDbBookmark *g_db_bookmark_new(const vmpa2t *, const char *); + +/* Fournit l'adresse associée à un signet. */ +vmpa2t *g_db_bookmark_get_address(GDbBookmark *); + +/* Fournit le commentaire associé à un signet. */ +const char *g_db_bookmark_get_comment(const GDbBookmark *); + +/* Définit le commentaire associé à un signet. */ +void g_db_bookmark_set_comment(GDbBookmark *, const char *); + + + +#endif  /* _ANALYSIS_DB_ITEMS_BOOKMARK_H */ diff --git a/src/analysis/db/items/comment.c b/src/analysis/db/items/comment.c new file mode 100644 index 0000000..73a18b0 --- /dev/null +++ b/src/analysis/db/items/comment.c @@ -0,0 +1,398 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * comment.c - gestion des commentaires dans du texte + * + * 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 "comment.h" + + +#include <stdio.h> +#include <sys/socket.h> + + +#include "../item-int.h" +#include "../misc/rlestr.h" + + + +/* Commentaire à placer dans du texte quelconque (instance) */ +struct _GDbComment +{ +    GDbItem parent;                         /* A laisser en premier        */ + +    vmpa2t *addr;                           /* Adresse du commentaire      */ +    rle_string text;                        /* Contenu du commentaire      */ + +}; + +/* Commentaire à placer dans du texte quelconque (classe) */ +struct _GDbCommentClass +{ +    GDbItemClass parent;                    /* A laisser en premier        */ + +}; + + + +/* Initialise la classe des commentaires dans une zone de texte. */ +static void g_db_comment_class_init(GDbCommentClass *); + +/* Initialise un commentaire dans une zone de texte. */ +static void g_db_comment_init(GDbComment *); + +/* Supprime toutes les références externes. */ +static void g_db_comment_dispose(GDbComment *); + +/* Procède à la libération totale de la mémoire. */ +static void g_db_comment_finalize(GDbComment *); + +/* Effectue la comparaison entre deux commentaires enregistrés. */ +static gint g_db_comment_cmp(GDbComment *, GDbComment *); + +/* Importe la définition d'un commentaire dans un flux réseau. */ +static bool g_db_comment_recv_from_fd(GDbComment *, int, int); + +/* Exporte la définition d'un commentaire dans un flux réseau. */ +static bool g_db_comment_send_to_fd(const GDbComment *, int, int); + + + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : db = accès à la base de données.                             * +*                                                                             * +*  Description : Crée la table des commentaires dans une base de données.     * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool create_comment_db_table(sqlite3 *db) +{ +    char *sql;                              /* Requête à exécuter          */ +    int ret;                                /* Bilan de la création        */ +    char *msg;                              /* Message d'erreur            */ + +    sql = "CREATE TABLE Comments ("            \ +             "id INT PRIMARY KEY NOT NULL, "    \ +             "user TEXT NOT NULL, "             \ +             "created INT NOT NULL, "           \ +             "address INT NOT NULL, "           \ +             "comment TEXT"                     \ +          ");"; + +    ret = sqlite3_exec(db, sql, NULL, NULL, &msg); +    if (ret != SQLITE_OK) +    { +        fprintf(stderr, "sqlite3_exec(): %s\n", msg); +        sqlite3_free(msg); +    } + +    return (ret == SQLITE_OK); + +} + + + + + + + + + + +/* Indique le type défini pour un commentaire à l'intérieur d'une zone de texte. */ +G_DEFINE_TYPE(GDbComment, g_db_comment, G_TYPE_DB_ITEM); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des commentaires dans une zone de texte.* +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_db_comment_class_init(GDbCommentClass *klass) +{ +    GObjectClass *object;                   /* Autre version de la classe  */ +    GDbItemClass *item;                     /* Encore une autre vision...  */ + +    object = G_OBJECT_CLASS(klass); + +    object->dispose = (GObjectFinalizeFunc/* ! */)g_db_comment_dispose; +    object->finalize = (GObjectFinalizeFunc)g_db_comment_finalize; + +    item = G_DB_ITEM_CLASS(klass); + +    item->cmp = (GCompareFunc)g_db_comment_cmp; + +    item->recv = (recv_db_item_fc)g_db_comment_recv_from_fd; +    item->send = (send_db_item_fc)g_db_comment_send_to_fd; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : comment = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise un commentaire dans une zone de texte.            * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_db_comment_init(GDbComment *comment) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : comment = instance d'objet GLib à traiter.                   * +*                                                                             * +*  Description : Supprime toutes les références externes.                     * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_db_comment_dispose(GDbComment *comment) +{ +    G_OBJECT_CLASS(g_db_comment_parent_class)->dispose(G_OBJECT(comment)); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : comment = instance d'objet GLib à traiter.                   * +*                                                                             * +*  Description : Procède à la libération totale de la mémoire.                * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_db_comment_finalize(GDbComment *comment) +{ +    delete_vmpa(comment->addr); + +    exit_rle_string(comment->text); + +    G_OBJECT_CLASS(g_db_comment_parent_class)->finalize(G_OBJECT(comment)); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : addr        = adresse inamovible localisant une position.    * +*                text        = commentaire construit ou NULL.                 * +*                is_volatile = état du besoin en sauvegarde.                  * +*                                                                             * +*  Description : Crée une définition de commentaire dans une zone de texte.   * +*                                                                             * +*  Retour      : Commentaire mis en place ou NULL en cas d'erreur.            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GDbComment *g_db_comment_new(const vmpa2t *addr, const char *text, bool is_volatile) +{ +    GDbComment *result;                    /* Instance à retourner        */ + +    result = g_object_new(G_TYPE_DB_COMMENT, NULL); + +    result->addr = dup_vmpa(addr); + +    g_db_comment_set_text(result, text); + +    g_db_item_set_volatile(G_DB_ITEM(result), is_volatile); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : a = premier élément à analyser.                              * +*                b = second élément à analyser.                               * +*                                                                             * +*  Description : Effectue la comparaison entre deux commentaires enregistrés. * +*                                                                             * +*  Retour      : Bilan de la comparaison : -1, 0 ou 1.                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static gint g_db_comment_cmp(GDbComment *a, GDbComment *b) +{ +    gint result;                            /* Bilan de la comparaison     */ + +    result = cmp_vmpa_by_phy(a->addr, b->addr); + +    if (result == 0) +        result = cmp_rle_string(&a->text, &b->text); + +    return 0; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : comment = commentaire avec informations sont à charger. [OUT]* +*                fd      = flux ouvert en lecture pour l'importation.         * +*                flags   = éventuelles options d'envoi supplémentaires.       * +*                                                                             * +*  Description : Importe la définition d'un commentaire dans un flux réseau.  * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_db_comment_recv_from_fd(GDbComment *comment, int fd, int flags) +{ +    bool status;                            /* Bilan d'opération initiale  */ + +    status = G_DB_ITEM_CLASS(g_db_comment_parent_class)->recv(G_DB_ITEM(comment), fd, flags); +    if (!status) return false; + +    if (!recv_vmpa(comment->addr, fd, 0)) +        return false; + +    if (!recv_rle_string(&comment->text, fd, 0)) +        return false; + +    return true; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : comment = informations à sauvegarder.                        * +*                fd      = flux ouvert en écriture pour l'exportation.        * +*                flags   = éventuelles options d'envoi supplémentaires.       * +*                                                                             * +*  Description : Exporte la définition d'un commentaire dans un flux réseau.  * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_db_comment_send_to_fd(const GDbComment *comment, int fd, int flags) +{ +    bool status;                            /* Bilan d'opération initiale  */ + +    status = G_DB_ITEM_CLASS(g_db_comment_parent_class)->send(G_DB_ITEM(comment), fd, MSG_MORE | flags); +    if (!status) return false; + +    if (!send_vmpa(comment->addr, fd, MSG_MORE | flags)) +        return false; + +    if (!send_rle_string(&comment->text, fd, flags)) +        return false; + +    return true; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : comment = informations à consulter.                          * +*                                                                             * +*  Description : Fournit l'adresse associée à un commentaire.                 * +*                                                                             * +*  Retour      : Adresse mémoire.                                             * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +const vmpa2t *g_db_comment_get_address(GDbComment *comment) +{ +    return comment->addr; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : comment = informations à consulter.                          * +*                                                                             * +*  Description : Fournit le commentaire associé à un commentaire.             * +*                                                                             * +*  Retour      : Commentaire existant ou NULL.                                * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +const char *g_db_comment_get_text(const GDbComment *comment) +{ +    return get_rle_string(&comment->text); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : comment = informations à consulter.                          * +*                text    = commentaire construit ou NULL.                     * +*                                                                             * +*  Description : Définit le commentaire associé à un commentaire.             * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void g_db_comment_set_text(GDbComment *comment, const char *text) +{ +    set_rle_string(&comment->text, text); + +} diff --git a/src/analysis/db/items/comment.h b/src/analysis/db/items/comment.h new file mode 100644 index 0000000..792fb92 --- /dev/null +++ b/src/analysis/db/items/comment.h @@ -0,0 +1,77 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * comment.h - prototypes pour la gestion des commentaires dans du texte + * + * 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 _ANALYSIS_DB_ITEMS_COMMENT_H +#define _ANALYSIS_DB_ITEMS_COMMENT_H + + + +#include <glib-object.h> +#include <sqlite3.h> +#include <stdbool.h> + + +#include "../../../arch/vmpa.h" + + + +/* Crée la table des commentaires dans une base de données. */ +bool create_comment_db_table(sqlite3 *); + + + + + +#define G_TYPE_DB_COMMENT               g_db_comment_get_type() +#define G_DB_COMMENT(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_db_comment_get_type(), GDbComment)) +#define G_IS_DB_COMMENT(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_db_comment_get_type())) +#define G_DB_COMMENT_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DB_COMMENT, GDbCommentClass)) +#define G_IS_DB_COMMENT_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DB_COMMENT)) +#define G_DB_COMMENT_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DB_COMMENT, GDbCommentClass)) + + +/* Commentaire à placer dans du texte quelconque (instance) */ +typedef struct _GDbComment GDbComment; + +/* Commentaire à placer dans du texte quelconque (classe) */ +typedef struct _GDbCommentClass GDbCommentClass; + + +/* Indique le type défini pour un commentaire à l'intérieur d'une zone de texte. */ +GType g_db_comment_get_type(void); + +/* Crée une définition de commentaire dans une zone de texte. */ +GDbComment *g_db_comment_new(const vmpa2t *, const char *, bool); + +/* Fournit l'adresse associée à un commentaire. */ +const vmpa2t *g_db_comment_get_address(GDbComment *); + +/* Fournit le commentaire associé à un commentaire. */ +const char *g_db_comment_get_text(const GDbComment *); + +/* Définit le commentaire associé à un commentaire. */ +void g_db_comment_set_text(GDbComment *, const char *); + + + +#endif  /* _ANALYSIS_DB_ITEMS_COMMENT_H */  | 
