summaryrefslogtreecommitdiff
path: root/src/arch/storage.h
blob: 35e3a7d6d89eab7152f0f77f3f9703da8273e969 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

/* Chrysalide - Outil d'analyse de fichiers binaires
 * storage.h - prototypes pour la conservation hors mémoire vive des instructions désassemblées
 *
 * Copyright (C) 2018 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef _ARCH_STORAGE_H
#define _ARCH_STORAGE_H


#include <glib-object.h>


#include <stdbool.h>


#include "processor.h"



/* ------------------- MECANISME DE SAUVEGARDE ET DE RESTAURATION ------------------- */


/* Définition générique d'une instruction d'architecture (instance) */
typedef struct _GArchInstruction GArchInstruction;


#define G_TYPE_ASM_STORAGE            g_asm_storage_get_type()
#define G_ASM_STORAGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_ASM_STORAGE, GAsmStorage))
#define G_IS_ASM_STORAGE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_ASM_STORAGE))
#define G_ASM_STORAGE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ASM_STORAGE, GAsmStorageClass))
#define G_IS_ASM_STORAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ASM_STORAGE))
#define G_ASM_STORAGE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ASM_STORAGE, GAsmStorageClass))


/* Définition d'une conservation d'instructions d'assemblage (instance) */
typedef struct _GAsmStorage GAsmStorage;

/* Définition d'une conservation d'instructions d'assemblage (classe) */
typedef struct _GAsmStorageClass GAsmStorageClass;


/* Indique le type défini pour une conservation d'instructions d'assemblage. */
GType g_asm_storage_get_type(void);

/* Crée le support d'une conservation d'instructions. */
GAsmStorage *g_asm_storage_new_compressed(GArchProcessor *, const gchar *);

/* Détermine si un cache d'instructions complet existe. */
bool g_asm_storage_has_cache(const GAsmStorage *);

/* Crée une nouvelle instance d'objet à partir de son type. */
GObject *g_asm_storage_create_object(GAsmStorage *, packed_buffer *);

/* Sauvegarde le type d'un objet instancié. */
bool g_asm_storage_store_object_gtype(GAsmStorage *, GObject *, packed_buffer *);

/* Type de fichier intermédiaire */
typedef enum _StorageFileType
{
    SFT_INSTRUCTION,                        /* Pour instructions           */
    SFT_OPERAND,                            /* Pour opérandes              */
    SFT_REGISTER                            /* Pour registres              */

} StorageFileType;

/* Charge des données rassemblées. */
bool _g_asm_storage_load_data(const GAsmStorage *, StorageFileType, packed_buffer *, off64_t);

#define g_asm_storage_load_instruction_data(s, b, p) \
    _g_asm_storage_load_data(s, SFT_INSTRUCTION, b, p)

#define g_asm_storage_load_operand_data(s, b, p) \
    _g_asm_storage_load_data(s, SFT_OPERAND, b, p)

#define g_asm_storage_load_register_data(s, b, p) \
    _g_asm_storage_load_data(s, SFT_REGISTER, b, p)

/* Sauvegarde des données rassemblées. */
bool _g_asm_storage_store_data(const GAsmStorage *, StorageFileType, packed_buffer *, off64_t *);

#define g_asm_storage_store_instruction_data(s, b, p) \
    _g_asm_storage_store_data(s, SFT_INSTRUCTION, b, p)

#define g_asm_storage_store_operand_data(s, b, p) \
    _g_asm_storage_store_data(s, SFT_OPERAND, b, p)

#define g_asm_storage_store_register_data(s, b, p) \
    _g_asm_storage_store_data(s, SFT_REGISTER, b, p)

/* Lance une restauration complète d'unsauvegarde compressée. */
bool g_asm_storage_open(GAsmStorage *, GBinFormat *, wgroup_id_t);

/* Fournit l'instruction correspondant à une position indicée. */
GArchInstruction *g_asm_storage_get_instruction_at(GAsmStorage *, GBinFormat *, off64_t, packed_buffer *);

/* Programme une sauvegarde complète et compressée. */
void g_asm_storage_save(GAsmStorage *);



#endif  /* _ARCH_STORAGE_H */