summaryrefslogtreecommitdiff
path: root/src/analysis/db/misc/snapshot.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-10-12 16:21:03 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-10-12 16:25:05 (GMT)
commit986125d4c2d8b049017b6d0770f16b9058076165 (patch)
treec89e6b7967a731e68d72f6d5a2150b0347db4ef3 /src/analysis/db/misc/snapshot.c
parent96afc0325e1c85bf1a76d63c6441cf8f044708fe (diff)
Defined a new type dedicated to snapshot identifiers.
Diffstat (limited to 'src/analysis/db/misc/snapshot.c')
-rw-r--r--src/analysis/db/misc/snapshot.c217
1 files changed, 217 insertions, 0 deletions
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 */
+/* ---------------------------------------------------------------------------------- */
+
+
+
+
+
+
+