summaryrefslogtreecommitdiff
path: root/plugins/dexresolver/context.c
blob: 19be9c0460b0d5d17200fd47419251dd22fd237a (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

/* OpenIDA - Outil d'analyse de fichiers binaires
 * context.h - prototypes pour les instances d'actions du présent greffon
 *
 * Copyright (C) 2010 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include "context.h"


#include <analysis/line_code.h>
#include <arch/dalvik/operand.h>
#include <glibext/delayed-int.h>
#include <plugins/context-int.h>


#include "operand.h"



/* ---------------------------- REMPLACEMENT D'OPERANDES ---------------------------- */


#define G_TYPE_DEX_RESOLVER_WORK               g_dex_resolver_work_get_type()
#define G_DEX_RESOLVER_WORK(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dex_resolver_work_get_type(), GDelayedDisassembly))
#define G_IS_DEX_RESOLVER_WORK(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dex_resolver_work_get_type()))
#define G_DEX_RESOLVER_WORK_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DEX_RESOLVER_WORK, GDelayedDisassemblyClass))
#define G_IS_DEX_RESOLVER_WORK_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DEX_RESOLVER_WORK))
#define G_DEX_RESOLVER_WORK_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DEX_RESOLVER_WORK, GDelayedDisassemblyClass))


/* Instance du greffon pour OpenIDA (instance) */
typedef struct _GDexResolverWork
{
    GDelayedWork parent;                    /* A laisser en premier        */

    GOpenidaBinary *binary;                 /* Destinataire final          */

} GDexResolverWork;


/* Instance du greffon pour OpenIDA (classe) */
typedef struct _GDexResolverWorkClass
{
    GDelayedWorkClass parent;               /* A laisser en premier        */

} GDexResolverWorkClass;


/* Indique le type défini pour les tâches de résolutions différées. */
static GType g_dex_resolver_work_get_type(void);

/* Initialise la classe des résolutions d'opérandes différées. */
static void g_dex_resolver_work_class_init(GDexResolverWorkClass *);

/* Initialise une tâche de résolution d'opérandes différée. */
static void g_dex_resolver_work_init(GDexResolverWork *);

/* Crée une tâche de résolution d'opérandes différée. */
static GDexResolverWork *g_dex_resolver_work_new(GOpenidaBinary *);

/* Assure la résolution d'opérandes en différé. */
static void g_dex_resolver_work_process(GDexResolverWork *, GtkExtStatusBar *);



/* -------------------------- TACHE DIFFEREE DANS LE TEMPS -------------------------- */
/* -------------------------- TACHE DIFFEREE DANS LE TEMPS -------------------------- */



/* Instance du greffon pour OpenIDA (instance) */
struct _GDexResolverContext
{
    GPluginContext parent;                  /* A laisser en premier        */

};


/* Instance du greffon pour OpenIDA (classe) */
struct _GDexResolverContextClass
{
    GPluginContextClass parent;             /* A laisser en premier        */

};



/* Initialise la classe des instances de greffon. */
static void g_dex_resolver_context_class_init(GDexResolverContextClass *);

/* Initialise une instance d'instance de greffon. */
static void g_dex_resolver_context_init(GDexResolverContext *);






/* ---------------------------------------------------------------------------------- */
/*                              REMPLACEMENT D'OPERANDES                              */
/* ---------------------------------------------------------------------------------- */


/* Indique le type défini pour les tâches de résolutions différées. */
G_DEFINE_TYPE(GDexResolverWork, g_dex_resolver_work, G_TYPE_DELAYED_WORK);


/******************************************************************************
*                                                                             *
*  Paramètres  : klass = classe à initialiser.                                *
*                                                                             *
*  Description : Initialise la classe des résolutions d'opérandes différées.  *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_dex_resolver_work_class_init(GDexResolverWorkClass *klass)
{

}


/******************************************************************************
*                                                                             *
*  Paramètres  : disass = instance à initialiser.                             *
*                                                                             *
*  Description : Initialise une tâche de résolution d'opérandes différée.     *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_dex_resolver_work_init(GDexResolverWork *disass)
{
    G_DELAYED_WORK(disass)->run = (run_task_fc)g_dex_resolver_work_process;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : binary = binaire chargé en attente des résultats.            *
*                                                                             *
*  Description : Crée une tâche de résolution d'opérandes différée.           *
*                                                                             *
*  Retour      : Tâche créée.                                                 *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static GDexResolverWork *g_dex_resolver_work_new(GOpenidaBinary *binary)
{
    GDexResolverWork *result;               /* Tâche à retourner           */

    result = g_object_new(G_TYPE_DEX_RESOLVER_WORK, NULL);

    result->binary = binary;

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : work      = analyse à mener.                                 *
*                statusbar = barre de statut à tenir informée.                *
*                                                                             *
*  Description : Assure la résolution d'opérandes en différé.                 *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_dex_resolver_work_process(GDexResolverWork *work, GtkExtStatusBar *statusbar)
{
    GDexFormat *format;                     /* Format du binaire utilisé   */
    GRenderingLine *lines;                  /* Lignes désassemblées        */
    GRenderingLine *iter;                   /* Boucle de parcours          */
    GArchInstruction *instr;                /* Instruction à ausculter     */
    size_t count;                           /* Quantité d'opérandes        */
    size_t i;                               /* Boucle de parcours          */
    const GArchOperand *op;                 /* Opérande à analyser         */
    GArchOperand *new;                      /* Nouvel opérande à afficher  */

    format = G_DEX_FORMAT(g_openida_binary_get_format(work->binary));

    lines = g_openida_binary_get_lines(work->binary);

    for (iter = lines;
         iter != NULL;
         iter = g_rendering_line_get_next_iter(lines, iter, NULL))
    {
        /* On ne traite que du code ici ! */
        if (!G_IS_CODE_LINE(iter)) continue;

        instr = g_code_line_get_instruction(G_CODE_LINE(iter));
        count = g_arch_instruction_count_operands(instr);

        /* FIXME : l'opérande recherchée est à position fixe ! */
        for (i = 0; i < count; i++)
        {
            op = g_arch_instruction_get_operand(instr, i);

            if (G_IS_DALVIK_POOL_OPERAND(op))
            {
                new = g_dalvik_hpool_operand_new(format, G_DALVIK_POOL_OPERAND(op));

                if (new != NULL)
                    g_arch_instruction_replace_operand(instr, new, op);

            }

        }

    }

}



/* ---------------------------------------------------------------------------------- */
/*                              REMPLACEMENT D'OPERANDES                              */
/*                              REMPLACEMENT D'OPERANDES                              */
/* ---------------------------------------------------------------------------------- */


/* Indique le type défini pour une instance de greffon. */
G_DEFINE_TYPE(GDexResolverContext, g_dex_resolver_context, G_TYPE_PLUGIN_CONTEXT);


/******************************************************************************
*                                                                             *
*  Paramètres  : klass = classe à initialiser.                                *
*                                                                             *
*  Description : Initialise la classe des instances de greffon.               *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_dex_resolver_context_class_init(GDexResolverContextClass *klass)
{

}


/******************************************************************************
*                                                                             *
*  Paramètres  : context = instance à initialiser.                            *
*                                                                             *
*  Description : Initialise une instance d'instance de greffon.               *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_dex_resolver_context_init(GDexResolverContext *context)
{

}


/******************************************************************************
*                                                                             *
*  Paramètres  : binary = contenu binaire chargé à traiter.                   *
*                                                                             *
*  Description : Lance l'exécution d'une action du greffon.                   *
*                                                                             *
*  Retour      : Instance d'exécution du greffon.                             *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GPluginContext *g_dex_resolver_context_new(GOpenidaBinary *binary)
{
    GPluginContext *result;                 /* Bilan d'exécution à renvoyer*/
    GDexResolverWork *work;                 /* Tâche de parcours de lignes */

    result = g_object_new(G_TYPE_DEX_RESOLVER_CONTEXT, NULL);

    work = g_dex_resolver_work_new(binary);

    g_signal_connect(work, "work-completed", G_CALLBACK(g_object_unref), NULL);

    g_work_queue_schedule_work(get_work_queue(), G_DELAYED_WORK(work));

    return result;

}