summaryrefslogtreecommitdiff
path: root/src/format/dwarf/form.c
blob: bbd030606b705784ab84dbee5c9d375706a0cb9e (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

/* Chrysalide - Outil d'analyse de fichiers binaires
 * form.h - prototypes pour la transmission des valeurs d'attributs
 *
 * Copyright (C) 2015 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/>.
 */


#include "form.h"



/******************************************************************************
*                                                                             *
*  Paramètres  : value = valeur au format Dwarf à consulter.                  *
*                form   = nature de la valeur à lire.                         *
*                addr   = valeur utilisable en interne récupérée. [OUT]       *
*                                                                             *
*  Description : Transcrit une valeur Dwarf brute en adresse virtuelle.       *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool translate_form_into_address(const dw_form_value *value, DwarfForm form, virt_t *addr)
{
    bool result;                            /* Bilan à retourner           */

    result = true;

    switch (form)
    {
        case DW_FORM_addr:
            *addr = value->v2.address;
            break;

        case DW_FORM_data1:
            *addr = value->v2.data1;
            break;

        case DW_FORM_data2:
            *addr = value->v2.data2;
            break;

        case DW_FORM_data4:
            *addr = value->v2.data4;
            break;

        case DW_FORM_data8:
            *addr = value->v2.data8;
            break;

        default:
            result = false;
            break;

    }

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : value = valeur au format Dwarf à consulter.                  *
*                form   = nature de la valeur à lire.                         *
*                                                                             *
*  Description : Transcrit une valeur Dwarf brute en chaîne de caractères.    *
*                                                                             *
*  Retour      : Bilan de l'opération : chaîne de caractères ou NULL si échec.*
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

const char *translate_form_into_string(const dw_form_value *value, DwarfForm form)
{
    const char *result;                     /* Valeur et bilan à retourner */

    switch (form)
    {
        case DW_FORM_string:
        case DW_FORM_strp:
            result = value->v2.string;
            break;

        default:
            result = NULL;
            break;

    }

    return result;

}