summaryrefslogtreecommitdiff
path: root/plugins/mobicore/symbols.c
blob: dc0a9500fe4120cd429a293d3eca0507196760c6 (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

/* Chrysalide - Outil d'analyse de fichiers binaires
 * symbols.c - gestion des symboles d'un MCLF
 *
 * Copyright (C) 2015-2017 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 "symbols.h"


#include <malloc.h>


#include <format/mangling/demangler.h>


#include "mclf-int.h"



/* Enregistre un point d'entrée au sein d'un binaire MCLF. */
static void register_mclf_entry_point(GMCLFFormat *, virt_t, phys_t, GBinRoutine *);

/* Enumère les points d'entrée principaux d'un binaire MCLF. */
static bool load_all_mclf_basic_entry_points(GMCLFFormat *format);



/******************************************************************************
*                                                                             *
*  Paramètres  : format  = description de l'exécutable à compléter.           *
*                vaddr   = adresse virtuelle du symbole à insérer.            *
*                len     = taille de la routine à ajouter.                    *
*                routine = représentation de la fonction repérée.             *
*                                                                             *
*  Description : Enregistre un point d'entrée au sein d'un binaire MCLF.      *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void register_mclf_entry_point(GMCLFFormat *format, virt_t vaddr, phys_t len, GBinRoutine *routine)
{
    GBinFormat *base;                   /* Version basique de l'instance   */
    vmpa2t addr;                        /* Localisation d'une routine  */
    mrange_t range;                     /* Couverture mémoire associée */
    GBinSymbol *symbol;                 /* Nouveau symbole construit   */

    base = G_BIN_FORMAT(format);

    /* Comptabilisation pour le désassemblage brut */

    base->entry_points = (virt_t *)realloc(base->entry_points, ++base->ep_count * sizeof(virt_t));

    base->entry_points[base->ep_count - 1] = vaddr;

    /* Comptabilisation en tant que symbole */

    vaddr &= ~0x1;

	init_vmpa(&addr, vaddr - format->header.v1.text.start, vaddr);
	init_vmpa(&addr, VMPA_NO_PHYSICAL, vaddr);

	init_mrange(&range, &addr, len);

	g_binary_routine_set_range(routine, &range);

	symbol = g_binary_symbol_new(STP_ENTRY_POINT);
	g_binary_symbol_attach_routine(symbol, routine);
	g_binary_format_add_symbol(base, symbol);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : format = description de l'exécutable à consulter.            *
*                                                                             *
*  Description : Enumère les points d'entrée principaux d'un binaire MCLF.    *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool load_all_mclf_basic_entry_points(GMCLFFormat *format)
{
    virt_t ep;                              /* Point d'entrée détecté      */
    GBinRoutine *routine;                   /* Routine à associer à un pt. */

    /* Point d'entrée principal éventuel */

    ep = format->header.v1.entry;

    if (ep != 0x0)
    {
        routine = try_to_demangle_routine("entry_point");
        register_mclf_entry_point(format, ep, 0, routine);
    }

    return true;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : format = description de l'exécutable à compléter.            *
*                                                                             *
*  Description : Charge en mémoire la liste humaine des symboles.             *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool load_mclf_symbols(GMCLFFormat *format)
{
    bool result;                            /* Bilan à retourner           */

    result = load_all_mclf_basic_entry_points(format);

    return result;

}