diff options
Diffstat (limited to 'src/analysis/db/items/bookmark.c')
-rw-r--r-- | src/analysis/db/items/bookmark.c | 416 |
1 files changed, 416 insertions, 0 deletions
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); + +} |