summaryrefslogtreecommitdiff
path: root/tools/d2c/conv.h
blob: acf007b0d90e90a09ed891bd5012dc00c13933f3 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

/* Chrysalide - Outil d'analyse de fichiers binaires
 * conv.h - prototypes pour les substitutions de valeurs depuis un contenu 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/>.
 */


#ifndef _TOOLS_CONV_H
#define _TOOLS_CONV_H


#include "bits.h"
#include "pproc.h"




/* Liste des fonctions de conversions présentes */
typedef struct _conv_list conv_list;







/* Types d'opérations unaires */
typedef enum _ConvUnaryOperation
{
    CUO_NOT,                                /* NOT (booléen)               */

    CUO_COUNT

} ConvUnaryOperation;



/* Types d'opérations binaires */
typedef enum _ConvBinaryOperation
{
    CBO_EOR,                                /* Ou exclusif (booléen)       */

    CBO_COUNT

} ConvBinaryOperation;


/* Représentation d'une expression de conversion */
typedef struct _conv_expr_t conv_expr_t;



/* Référence une variable en tant qu'expression de conversion. */
conv_expr_t *build_conv_expr_from_name(char *);

/* Conserve une valeur en tant qu'expression de conversion. */
conv_expr_t *build_conv_expr_from_number(unsigned long );

/* Construit une base d'expression de conversion composée. */
conv_expr_t *build_composed_conv_expr(char *, char *);

/* Etend une base d'expression de conversion composée. */
conv_expr_t *extend_composed_conv_expr(conv_expr_t *, char *);

/* Traduit une opération unaire sur expression de conversion. */
conv_expr_t *build_unary_conv_expr(conv_expr_t *, ConvUnaryOperation);

/* Traduit une opération binaire sur expression de conversion. */
conv_expr_t *build_binary_conv_expr(conv_expr_t *, conv_expr_t *, ConvBinaryOperation);








/* ------------------------ LISTES D'ARGUMENTS DE CONVERSION ------------------------ */


/* Liste d'expressions utilisées en arguments de conversion */
typedef struct _conv_arg_list_t conv_arg_list_t;


/* Crée une liste d'arguments de conversion. */
conv_arg_list_t *build_conv_arg_list(conv_expr_t *);

/* Libère la mémoire occupée par une liste d'expressions. */
void delete_conv_arg_list(conv_arg_list_t *);

/* Ajoute un élément à une liste d'arguments de conversion. */
conv_arg_list_t *extend_conv_arg_list(conv_arg_list_t *, conv_expr_t *);




/* ---------------------------- CONVERSION DES ARGUMENTS ---------------------------- */


/* Fonction de conversion */
typedef struct _conv_func conv_func;


/* Définit une conversion à partir d'une simple expression. */
conv_func *make_conv_from_expr(char *, conv_expr_t *);

/* Définit une conversion à partir d'une function à appeler. */
conv_func *make_conv_from_func(char *, char *, conv_arg_list_t *);

/* Libère de la mémoire une conversion enregistrée. */
void delete_conv_func(conv_func *);

/* Indique la variable de destination d'une conversion. */
const char *get_conv_dest_name(const conv_func *);

/* Marque les champs utilisés par une fonction de conversion. */
bool mark_conv_func(conv_func *, const coding_bits *, const conv_list *);

/* Déclare les variables associées à une fonction de conversion. */
bool declare_conv_func(conv_func *, int, const coding_bits *, const conv_list *, unsigned int);

/* Définit les variables associées à une fonction de conversion. */
bool define_conv_func(conv_func *, bool, bool, int, const char *, const coding_bits *, const conv_list *, const pre_processor *);



/* ---------------------------- ENSEMBLES DE CONVERSIONS ---------------------------- */


/* Crée un nouvelle liste vierge de fonctions de conversion. */
conv_list *create_conv_list(void);

/* Supprime de la mémoire une de fonctions de conversion. */
void delete_conv_list(conv_list *);

/* Enregistre une function de conversion du brut à l'utile. */
void register_conversion(conv_list *, conv_func *);

/* Recherche un résultat précis dans une liste de fonctions. */
conv_func *find_named_conv_in_list(const conv_list *, const char *);



#endif  /* _TOOLS_CONV_H */