diff options
Diffstat (limited to 'src/analysis/db/misc')
| -rw-r--r-- | src/analysis/db/misc/Makefile.am | 1 | ||||
| -rw-r--r-- | src/analysis/db/misc/snapshot.c | 217 | ||||
| -rw-r--r-- | src/analysis/db/misc/snapshot.h | 82 | ||||
| -rw-r--r-- | src/analysis/db/misc/timestamp.c | 4 | 
4 files changed, 302 insertions, 2 deletions
| diff --git a/src/analysis/db/misc/Makefile.am b/src/analysis/db/misc/Makefile.am index ebe92e1..c702145 100644 --- a/src/analysis/db/misc/Makefile.am +++ b/src/analysis/db/misc/Makefile.am @@ -3,6 +3,7 @@ noinst_LTLIBRARIES  = libanalysisdbmisc.la  libanalysisdbmisc_la_SOURCES =			\  	rlestr.h rlestr.c					\ +	snapshot.h snapshot.c				\  	timestamp.h timestamp.c  libanalysisdbmisc_la_LIBADD =  diff --git a/src/analysis/db/misc/snapshot.c b/src/analysis/db/misc/snapshot.c new file mode 100644 index 0000000..982553b --- /dev/null +++ b/src/analysis/db/misc/snapshot.c @@ -0,0 +1,217 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * snapshot.c - encodage des informations utiles aux instantanés + * + * Copyright (C) 2019 Cyrille Bagard + * + *  This file is part of Chrysalide. + * + *  Chrysalide 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. + * + *  Chrysalide 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 Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "snapshot.h" + + +#include <string.h> +#include <openssl/rand.h> + + +#include "../../../core/logs.h" + + + +/* ---------------------------------------------------------------------------------- */ +/*                            IDENTIFIANTS DES INSTANTANES                            */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : id = identifiant d'instantané à initialiser. [OUT]           * +*                                                                             * +*  Description : Construit un identifiant pour instantané de base de données. * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool init_snapshot_id(snapshot_id_t *id) +{ +    bool result;                            /* Bilan à retourner           */ +    int ret;                                /* Bilan d'une génération      */ +    unsigned char rand[SNAP_ID_RAND_SZ];    /* Tirage aléatoire            */ +    size_t i;                               /* Boucle de parcours          */ + +    static char *alphabet = "0123456789abcdef"; + +    ret = RAND_bytes(rand, SNAP_ID_RAND_SZ); + +    if (ret != 1) +    { +        LOG_ERROR_OPENSSL; +        result = false; +    } + +    else +    { +        for (i = 0; i < SNAP_ID_RAND_SZ; i++) +        { +            id->name[i * 2 + 0] = alphabet[rand[i] & 0xf]; +            id->name[i * 2 + 1] = alphabet[(rand[i] >> 4) & 0xf]; +        } + +        id->name[i * 2] = '\0'; + +        result = true; + +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : id   = identifiant d'instantané à initialiser. [OUT]         * +*                text = source de données pour la constitution.               * +*                                                                             * +*  Description : Construit un identifiant pour instantané de base de données. * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool init_snapshot_id_from_text(snapshot_id_t *id, const char *text) +{ +    bool result;                            /* Bilan à retourner           */ + +    result = (strlen(text) == (SNAP_ID_HEX_SZ - 1)); + +    if (result) +        strcpy(id->name, text); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : dest = destination de la copie d'indentifiant. [OUT]         * +*                src  = source de l'identifiant à copier.                     * +*                                                                             * +*  Description : Effectue une copie d'identifiant d'instantané.               * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void copy_snapshot_id(snapshot_id_t *dest, const snapshot_id_t *src) +{ +    memcpy(dest->name, src->name, SNAP_ID_HEX_SZ); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : id1 = premier identifiant à comparer.                        * +*                id2 = second identifiant à comparer.                         * +*                                                                             * +*  Description : Effectue la comparaison entre deux identifiants.             * +*                                                                             * +*  Retour      : Résultat de la comparaison : -1, 0 ou 1.                     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +int cmp_snapshot_id(const snapshot_id_t *id1, const snapshot_id_t *id2) +{ +    int result;                             /* Bilan à retourner           */ + +    result = memcmp(id1->name, id2->name, SNAP_ID_HEX_SZ); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : id   = informations à constituer. [OUT]                      * +*                pbuf = paquet de données où venir puiser les infos.          * +*                                                                             * +*  Description : Importe la définition d'un identifiant d'instantané.         * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool unpack_snapshot_id(snapshot_id_t *id, packed_buffer *pbuf) +{ +    bool result;                            /* Bilan à retourner           */ + +    result = extract_packed_buffer(pbuf, id->name, SNAP_ID_HEX_SZ, false); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : id   = informations à sauvegarer.                            * +*                pbuf = paquet de données où venir inscrire les infos.        * +*                                                                             * +*  Description : Exporte la définition d'un identifiant d'instantané.         * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool pack_snapshot_id(const snapshot_id_t *id, packed_buffer *pbuf) +{ +    bool result;                            /* Bilan à retourner           */ + +    result = extend_packed_buffer(pbuf, id->name, SNAP_ID_HEX_SZ, false); + +    return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/*                             PROPRIETES DES INSTANTANES                             */ +/* ---------------------------------------------------------------------------------- */ + + + + + + + diff --git a/src/analysis/db/misc/snapshot.h b/src/analysis/db/misc/snapshot.h new file mode 100644 index 0000000..4aaa6f9 --- /dev/null +++ b/src/analysis/db/misc/snapshot.h @@ -0,0 +1,82 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * snapshot.h - prototypes pour l'encodage des informations utiles aux instantanés + * + * Copyright (C) 2019 Cyrille Bagard + * + *  This file is part of Chrysalide. + * + *  Chrysalide 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. + * + *  Chrysalide 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 Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _ANALYSIS_DB_MISC_SNAPSHOT_H +#define _ANALYSIS_DB_MISC_SNAPSHOT_H + + +#include <stdbool.h> +#include <stdint.h> + + +#include "../../../common/packed.h" + + + +/* -------------------------- IDENTIFIANTS DES INSTANTANES -------------------------- */ + + +#define SNAP_ID_RAND_SZ 32 +#define SNAP_ID_HEX_SZ (SNAP_ID_RAND_SZ * 2 + 1) + +/* Représentation d'un instantané */ +typedef struct _snapshot_id_t +{ +    char name[SNAP_ID_HEX_SZ]; + +} snapshot_id_t; + + +/* Construit un identifiant pour instantané de base de données. */ +bool init_snapshot_id(snapshot_id_t *); + +/* Construit un identifiant pour instantané de base de données. */ +bool init_snapshot_id_from_text(snapshot_id_t *, const char *); + +#define snapshot_id_as_string(id) (id)->name + +/* Effectue une copie d'identifiant d'instantané. */ +void copy_snapshot_id(snapshot_id_t *, const snapshot_id_t *); + +/* Effectue la comparaison entre deux identifiants. */ +int cmp_snapshot_id(const snapshot_id_t *, const snapshot_id_t *); + +/* Importe la définition d'un identifiant d'instantané. */ +bool unpack_snapshot_id(snapshot_id_t *, packed_buffer *); + +/* Exporte la définition d'un identifiant d'instantané. */ +bool pack_snapshot_id(const snapshot_id_t *, packed_buffer *); + + + +/* --------------------------- PROPRIETES DES INSTANTANES --------------------------- */ + + + + + + + + + +#endif  /* _ANALYSIS_DB_MISC_SNAPSHOT_H */ diff --git a/src/analysis/db/misc/timestamp.c b/src/analysis/db/misc/timestamp.c index 6453953..12299eb 100644 --- a/src/analysis/db/misc/timestamp.c +++ b/src/analysis/db/misc/timestamp.c @@ -79,8 +79,8 @@ bool timestamp_is_younger(timestamp_t stamp, timestamp_t limit)  /******************************************************************************  *                                                                             * -*  Paramètres  : t1 = première chaîne à comparer.                             * -*                t2 = seconde chaîne à comparer.                              * +*  Paramètres  : t1 = premier horodatage à comparer.                          * +*                t2 = second horodatage à comparer.                           *  *                                                                             *  *  Description : Effectue la comparaison entre deux horodatages.              *  *                                                                             * | 
