summaryrefslogtreecommitdiff
path: root/plugins/mobicore/mclf-int.c
blob: cb4dbb3e09876d855c3ace76bd56cc5042b0a0af (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

/* Chrysalide - Outil d'analyse de fichiers binaires
 * mclf-int.c - structures internes du format MCLF
 *
 * Copyright (C) 2015 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/>.
 */


#include "mclf-int.h"



/******************************************************************************
*                                                                             *
*  Paramètres  : format = informations chargées à consulter.                  *
*                header = en-tête à déterminer. [OUT]                         *
*                endian = boutisme reconnu dans le format. [OUT]              *
*                                                                             *
*  Description : Procède à la lecture de l'en-tête d'un contenu binaire MCLF. *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool read_mclf_header(GMCLFFormat *format, mclf_header_t *header, SourceEndian endian)
{
    bool result;                            /* Bilan à retourner           */
    GBinContent *content;                   /* Contenu binaire à lire      */
    vmpa2t pos;                             /* Position de lecture         */

    content = G_BIN_FORMAT(format)->content;

    init_vmpa(&pos, 0, VMPA_NO_VIRTUAL);

    result = g_binary_content_read_u32(content, &pos, endian, &header->intro.magic);
    result &= g_binary_content_read_u32(content, &pos, endian, &header->intro.version);

    printf("Version :: %u (%x)\n", header->intro.version, header->intro.version);


    result &= g_binary_content_read_u32(content, &pos, endian, &header->v1.flags);
    result &= g_binary_content_read_u32(content, &pos, endian, &header->v1.mem_type);
    result &= g_binary_content_read_u32(content, &pos, endian, &header->v1.service_type);

    printf("Mem type : 0x%08x\n", header->v1.mem_type);

    result &= g_binary_content_read_u32(content, &pos, endian, &header->v1.num_instances);
    result &= g_binary_content_get_raw(content, &pos, 16, (bin_t *)&header->v1.uuid);
    result &= g_binary_content_read_u32(content, &pos, endian, &header->v1.driver_id);
    result &= g_binary_content_read_u32(content, &pos, endian, &header->v1.num_threads);

    printf("Num threads : 0x%08x\n", header->v1.num_threads);

    result &= read_mclf_segment_desc(format, &header->v1.text, &pos, endian);

    printf("TEXT :: 0x%08x + %u\n", header->v1.text.start, header->v1.text.len);

    result &= read_mclf_segment_desc(format, &header->v1.data, &pos, endian);

    printf("DATA :: 0x%08x + %u\n", header->v1.data.start, header->v1.data.len);


    result &= g_binary_content_read_u32(content, &pos, endian, &header->v1.bss_len);
    result &= g_binary_content_read_u32(content, &pos, endian, &header->v1.entry);

    printf("ENTRY :: 0x%08x\n", header->v1.entry);



    result &= g_binary_content_read_u32(content, &pos, endian, &header->v2.service_version);


    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : format  = informations chargées à consulter.                 *
*                segment = descripteur à déterminer. [OUT]                    *
*                pos     = position de début de lecture. [OUT]                *
*                endian  = boutisme reconnu dans le format. [OUT]             *
*                                                                             *
*  Description : Procède à la lecture d'un descripteur de segment MCLF.       *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool read_mclf_segment_desc(GMCLFFormat *format, segment_descriptor_t *segment, vmpa2t *pos, SourceEndian endian)
{
    bool result;                            /* Bilan à retourner           */
    GBinContent *content;                   /* Contenu binaire à lire      */

    content = G_BIN_FORMAT(format)->content;

    result = g_binary_content_read_u32(content, pos, endian, &segment->start);
    result &= g_binary_content_read_u32(content, pos, endian, &segment->len);

    return result;

}