summaryrefslogtreecommitdiff
path: root/src/arch/dalvik/operand.h
blob: b9a01325e03abfd274b9ff350c5f58729edfde12 (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

/* Chrysalide - Outil d'analyse de fichiers binaires
 * operand.h - prototypes pour l'aide à la création d'opérandes Dalvik
 *
 * Copyright (C) 2010-2012 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/>.
 */


#ifndef _ARCH_DALVIK_OPERAND_H
#define _ARCH_DALVIK_OPERAND_H


#include "operands/args.h"
#include "operands/pool.h"
#include "operands/register.h"
#include "../instruction.h"
#include "../../format/dex/dex.h"



/**
 * Cf. les documentations suivantes :
 * - http://www.netmite.com/android/mydroid/dalvik/docs/instruction-formats.html
 * - http://www.netmite.com/android/mydroid/dalvik/docs/dalvik-bytecode.html
 * - http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html
 */


/* Construction d'identifiants typés */

#define DALVIK_OP_LEN_OFF   28
#define DALVIK_OP_LEN_MASK  0xf0000000

#define DALVIK_OP_REG_OFF   24
#define DALVIK_OP_REG_MASK  0x0f000000
#define DALVIK_OP_REG_RANGE 0xf

#define DALVIK_OP_POOL_OFF  20
#define DALVIK_OP_POOL_MASK 0x00f00000

#define DALVIK_OP_EXTRA_MASK (DALVIK_OP_POOL_MASK)

#define DALVIK_OP_LEN(l)        ((l) << DALVIK_OP_LEN_OFF)
#define DALVIK_OP_GET_LEN(v)    (((v) & DALVIK_OP_LEN_MASK) >> DALVIK_OP_LEN_OFF)

#define DALVIK_OP_REG(r)        ((r) << DALVIK_OP_REG_OFF)
#define DALVIK_OP_COUNT_REG(v)  (((v) & DALVIK_OP_REG_MASK) >> DALVIK_OP_REG_OFF)

#define DALVIK_OP_POOL(p)       ((p) << DALVIK_OP_POOL_OFF)
#define DALVIK_OP_GET_POOL(v)   (((v) & DALVIK_OP_POOL_MASK) >> DALVIK_OP_POOL_OFF)

#define DALVIK_OP_GET_MNEMONIC(v) ((v) & 0xff)


/* Types d'opérandes supportés */
typedef enum _DalvikOperandType
{
    DALVIK_OPT_10T      = DALVIK_OP_LEN(1) | DALVIK_OP_REG(0) | 'T',
    DALVIK_OPT_10X      = DALVIK_OP_LEN(1) | DALVIK_OP_REG(0) | 'X',

    DALVIK_OPT_11N      = DALVIK_OP_LEN(1) | DALVIK_OP_REG(1) | 'N',
    DALVIK_OPT_11X      = DALVIK_OP_LEN(1) | DALVIK_OP_REG(1) | 'X',

    DALVIK_OPT_12X      = DALVIK_OP_LEN(1) | DALVIK_OP_REG(2) | 'X',

    DALVIK_OPT_20T      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(0) | 'T',

    DALVIK_OPT_21C      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(1) | 'C',
    DALVIK_OPT_21H      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(1) | 'H',
    DALVIK_OPT_21S      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(1) | 'S',
    DALVIK_OPT_21T      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(1) | 'T',

    DALVIK_OPT_22B      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(2) | 'B',
    DALVIK_OPT_22C      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(2) | 'C',
    DALVIK_OPT_22S      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(2) | 'S',
    DALVIK_OPT_22T      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(2) | 'T',
    DALVIK_OPT_22X      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(2) | 'X',

    DALVIK_OPT_23X      = DALVIK_OP_LEN(2) | DALVIK_OP_REG(3) | 'X',

    DALVIK_OPT_30T      = DALVIK_OP_LEN(3) | DALVIK_OP_REG(0) | 'T',

    DALVIK_OPT_31C      = DALVIK_OP_LEN(3) | DALVIK_OP_REG(1) | 'C',
    DALVIK_OPT_31I      = DALVIK_OP_LEN(3) | DALVIK_OP_REG(1) | 'I',
    DALVIK_OPT_31T      = DALVIK_OP_LEN(3) | DALVIK_OP_REG(1) | 'T',

    DALVIK_OPT_32X      = DALVIK_OP_LEN(3) | DALVIK_OP_REG(2) | 'X',

    DALVIK_OPT_35C      = DALVIK_OP_LEN(3) | DALVIK_OP_REG(5) | 'C',

    DALVIK_OPT_3RC      = DALVIK_OP_LEN(3) | DALVIK_OP_REG(DALVIK_OP_REG_RANGE) | 'C',
    DALVIK_OPT_3RMS     = DALVIK_OP_LEN(3) | DALVIK_OP_REG(DALVIK_OP_REG_RANGE) | 'M',
    DALVIK_OPT_3RFS     = DALVIK_OP_LEN(3) | DALVIK_OP_REG(DALVIK_OP_REG_RANGE) | 'F',

    DALVIK_OPT_51L      = DALVIK_OP_LEN(5) | DALVIK_OP_REG(1) | 'L'

} DalvikOperandType;


/* Procède à la lecture d'opérandes pour une instruction. */
bool dalvik_read_operands(GArchInstruction *, GExeFormat *, const GBinContent *, vmpa2t *, SourceEndian, DalvikOperandType);

/* Procède à la lecture d'opérandes pour une instruction. */
void dalvik_mark_first_operand_as_written(GArchInstruction *);



#endif  /* _ARCH_DALVIK_OPERAND_H */