forked from Dees-Troy/android_external_libenc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dec_base.h
136 lines (125 loc) · 3.36 KB
/
dec_base.h
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
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author Alexander V. Astapchuk
*/
/**
* @file
* @brief Main decoding (disassembling) routines and structures.
*
* @note Quick and rough implementation, subject for a change.
*/
#ifndef __DEC_BASE_H_INCLUDED__
#define __DEC_BASE_H_INCLUDED__
#include "enc_base.h"
#include "enc_prvt.h"
#ifdef ENCODER_ISOLATE
using namespace enc_ia32;
#endif
#define IF_CONDITIONAL (0x00000000)
#define IF_SYMMETRIC (0x00000000)
#define IF_BRANCH (0x00000000)
struct Inst {
Inst() {
mn = Mnemonic_Null;
prefc = 0;
size = 0;
flags = 0;
//offset = 0;
//direct_addr = NULL;
argc = 0;
for(int i = 0; i < 4; ++i)
{
pref[i] = InstPrefix_Null;
}
}
/**
* Mnemonic of the instruction.s
*/
Mnemonic mn;
/**
* Enumerating of indexes in the pref array.
*/
enum PrefGroups
{
Group1 = 0,
Group2,
Group3,
Group4
};
/**
* Number of prefixes (1 byte each).
*/
unsigned int prefc;
/**
* Instruction prefixes. Prefix should be placed here according to its group.
*/
InstPrefix pref[4];
/**
* Size, in bytes, of the instruction.
*/
unsigned size;
/**
* Flags of the instruction.
* @see MF_
*/
unsigned flags;
/**
* An offset of target address, in case of 'CALL offset',
* 'JMP/Jcc offset'.
*/
//int offset;
/**
* Direct address of the target (on Intel64/IA-32 is 'instruction IP' +
* 'instruction length' + offset).
*/
//void * direct_addr;
/**
* Number of arguments of the instruction.
*/
unsigned argc;
//
EncoderBase::Operand operands[3];
//
const EncoderBase::OpcodeDesc * odesc;
};
inline bool is_jcc(Mnemonic mn)
{
return Mnemonic_JO <= mn && mn<=Mnemonic_JG;
}
class DecoderBase {
public:
static unsigned decode(const void * addr, Inst * pinst);
private:
static bool decodeModRM(const EncoderBase::OpcodeDesc& odesc,
const unsigned char ** pbuf, Inst * pinst
#ifdef _EM64T_
, const Rex *rex
#endif
);
static bool decode_aux(const EncoderBase::OpcodeDesc& odesc,
unsigned aux, const unsigned char ** pbuf,
Inst * pinst
#ifdef _EM64T_
, const Rex *rex
#endif
);
static bool try_mn(Mnemonic mn, const unsigned char ** pbuf, Inst * pinst);
static unsigned int fill_prefs( const unsigned char * bytes, Inst * pinst);
static bool is_prefix(const unsigned char * bytes);
};
#endif // ~ __DEC_BASE_H_INCLUDED__