summaryrefslogtreecommitdiff
path: root/src/analysis/db/item-int.h
blob: 12c69f3856aef19b6c07ebc6dd3cef598f29cb75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

/* Chrysalide - Outil d'analyse de fichiers binaires
 * item-int.h - prototypes et définitions internes pour les bases d'éléments de collection
 *
 * 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_ITEM_INT_H
#define _ANALYSIS_DB_ITEM_INT_H


#include "item.h"


#include <stdint.h>


#include "misc/rlestr.h"
#include "../binary.h"



/* Importe la définition d'une base d'éléments pour collection. */
typedef bool (* recv_db_item_fc) (GDbItem *, int, int);

/* Exporte la définition d'une base d'éléments pour collection. */
typedef bool (* send_db_item_fc) (const GDbItem *, int, int);

/* Exécute un élément de collection sur un binaire. */
typedef bool (* run_item_fc) (GDbItem *, GLoadedBinary *);

/* Constitue les champs destinés à une insertion / modification. */
typedef bool (* prepare_db_statement) (const GDbItem *, bound_value **, size_t *);

/* Charge les valeurs utiles pour une localisation. */
typedef bool (* load_db_item_fc) (GDbItem *, const bound_value *, size_t);


/* Base d'un élément pour collection générique (instance) */
struct _GDbItem
{
    GObject parent;                         /* A laisser en premier        */

    uint64_t created;                       /* Date de création            */
    uint64_t modified;                      /* Date de modification        */

    rle_string author;                      /* Utilisateur d'origine       */
    rle_string tool;                        /* Eventuel outil automatique ?*/

    rle_string label;                       /* Représentation humaine      */

    bool is_volatile;                       /* Pas besoin de sauvegarde ?  */

#ifdef DEBUG
    bool applied;                           /* L'élément a été appliqué    */
#endif

};

/* Base d'un élément pour collection générique (classe) */
struct _GDbItemClass
{
    GObjectClass parent;                    /* A laisser en premier        */

    GCompareFunc cmp;                       /* Comparaison entre éléments  */

    recv_db_item_fc recv;                   /* Réception depuis le réseau  */
    send_db_item_fc send;                   /* Emission depuis le réseau   */
    run_item_fc apply;                      /* Application de l'élément    */
    run_item_fc cancel;                     /* Retrait de l'élément        */

    prepare_db_statement prepare_stmt;      /* Préparation d'une requête   */
    load_db_item_fc load;                   /* Chargement à partir d'une BD*/

};


/* Définition du tronc commun pour les créations SQLite */
#define SQLITE_DB_ITEM_CREATE                   \
    "created INTEGER, "                         \
    "modified INTEGER, "                        \
    SQLITE_RLESTR_CREATE("author") ", "         \
    SQLITE_RLESTR_CREATE("tool") ", "           \
    SQLITE_RLESTR_CREATE("label")



#endif  /* _ANALYSIS_DB_ITEM_INT_H */