summaryrefslogtreecommitdiff
path: root/src/format/format.h
blob: fec03ea439ae86e6743cc15095d2f40da41335ec (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

/* OpenIDA - Outil d'analyse de fichiers binaires
 * format.h - prototypes pour le support des différents formats binaires
 *
 * Copyright (C) 2009-2011 Cyrille Bagard
 *
 *  This file is part of OpenIDA.
 *
 *  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 _FORMAT_FORMAT_H
#define _FORMAT_FORMAT_H


#include <glib-object.h>
#include <stdbool.h>
#include <sys/types.h>


#include "symbol.h"
#include "../analysis/routine.h"
#include "../decomp/context.h"
#include "../decomp/instruction.h"



/* ------------------------ TRAITEMENT INDIVIDUEL DE FORMATS ------------------------ */


#define G_TYPE_BIN_FORMAT               g_binary_format_get_type()
#define G_BIN_FORMAT(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_binary_format_get_type(), GBinFormat))
#define G_IS_BIN_FORMAT(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_binary_format_get_type()))
#define G_BIN_FORMAT_GET_IFACE(inst)    (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_binary_format_get_type(), GBinFormatIface))
#define G_BIN_FORMAT_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BIN_FORMAT, GBinFormatClass))


/* Format binaire générique (instance) */
typedef struct _GBinFormat GBinFormat;

/* Format binaire générique (classe) */
typedef struct _GBinFormatClass GBinFormatClass;


/* Indique le type défini pour un format binaire générique. */
GType g_binary_format_get_type(void);

/* Fournit une référence vers le contenu binaire analysé. */
const bin_t *g_binary_format_get_content(const GBinFormat *, off_t *);

/* Ajoute un symbole à la collection du format binaire. */
void g_binary_format_add_symbol(GBinFormat *, GBinSymbol *);

/* Fournit la liste de tous les symboles détectés. */
GBinSymbol **g_binary_format_get_symbols(const GBinFormat *, size_t *);

/* Ajoute une routine à la collection du format binaire. */
void g_binary_format_add_routine(GBinFormat *, GBinRoutine *);

/* Fournit le prototype de toutes les routines détectées. */
GBinRoutine **g_binary_format_get_routines(const GBinFormat *, size_t *);

/* Procède à la décompilation basique d'une routine donnée. */
GDecInstruction *g_binary_format_decompile_routine(const GBinFormat *, GBinRoutine *, GDecContext *);

/* Fournit la liste des fichiers source détectés. */
const char * const *g_binary_format_get_source_files(const GBinFormat *, size_t *, size_t *);

/* Procède à la décompilation complète du format. */
void g_binary_format_decompile(const GBinFormat *, GCodeBuffer *, const char *filename);

/* Recherche le symbole correspondant à une adresse. */
bool g_binary_format_resolve_symbol(const GBinFormat *, const char **, SymbolType *, vmpa_t *);

/* Recherche une position dans une routine selon une adresse. */
bool g_binary_format_resolve_relative_routine(const GBinFormat *, const char **, vmpa_t *);



/* ----------------------- MANIPULATION D'ENSEMBLE DE FORMATS ----------------------- */


/* Identifiants pour les différents formats */
typedef enum _FormatIdentifier
{
    FID_DEX,                                /* Format DEX                  */
    //FID_DWARF,                              /* Format Dwarf                */
    FID_ELF,                                /* Format ELF                  */
    FID_JAVA,                               /* Format Java                 */
    FID_PE,                                 /* Format PE                   */

    FID_COUNT

} FormatIdentifier;

/* Spécialité des formats */
typedef enum _FormatType
{
    FMT_EXEC    = (1 << 0),                 /* Format d'exécutable         */
    FMT_DEBUG   = (1 << 1)                  /* Format de débogage          */

} FormatType;


/* Indication à propos du support d'un format */
typedef bool (* format_match_fc) (FormatType, const bin_t *, off_t);

/* Méthode de chargement d'un format */
typedef GBinFormat * (* format_load_fc) (const bin_t *, off_t);


/* Procède au chargement des formats binaires reconnus. */
bool init_all_formats(void);

/* Charge si possible un nouveau format binaire. */
GBinFormat *load_new_format(FormatType, char *filename, bin_t **, off_t *);



#endif  /* _FORMAT_FORMAT_H */