LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
instructions.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_DEX_INSTRUCTIONS_H
17#define LIEF_DEX_INSTRUCTIONS_H
18#include "LIEF/visibility.h"
19#include "LIEF/types.hpp"
20#include <cstddef>
21
22namespace LIEF {
23namespace DEX {
24
25enum SWITCH_ARRAY_IDENT : uint16_t {
29};
30enum OPCODES : uint8_t {
33 OP_NOP = 0x00,
34 OP_MOVE = 0x01,
36 OP_MOVE_16 = 0x03,
48 OP_RETURN = 0x0f,
51 OP_CONST_4 = 0x12,
53 OP_CONST = 0x14,
72 OP_THROW = 0x27,
73 OP_GOTO = 0x28,
74 OP_GOTO_16 = 0x29,
75 OP_GOTO_32 = 0x2a,
83 OP_IF_EQ = 0x32,
84 OP_IF_NE = 0x33,
85 OP_IF_LT = 0x34,
86 OP_IF_GE = 0x35,
87 OP_IF_GT = 0x36,
88 OP_IF_LE = 0x37,
89 OP_IF_EQZ = 0x38,
90 OP_IF_NEZ = 0x39,
91 OP_IF_LTZ = 0x3a,
92 OP_IF_GEZ = 0x3b,
93 OP_IF_GTZ = 0x3c,
94 OP_IF_LEZ = 0x3d,
95 OP_AGET = 0x44,
102 OP_APUT = 0x4b,
109 OP_IGET = 0x52,
116 OP_IPUT = 0x59,
123 OP_SGET = 0x60,
130 OP_SPUT = 0x67,
175 OP_OR_INT = 0x96,
252
253 // ODEX
270
271 // From DEX 38
276
277 // From DEX 39
280};
281
319
321 uint16_t ident; // 0x0100
322 uint16_t size;
323 uint32_t first_key;
324 // uint32_t targets[size]
325};
326
327
329 uint16_t ident; // 0x0200
330 uint16_t size;
331 // uint32_t targets[size]
332};
333
335 uint16_t ident;
337 uint32_t size;
338 //uint8_t data[size];
339};
340
344
347
348LIEF_API bool is_switch_array(const uint8_t* ptr, const uint8_t* end);
349
350LIEF_API size_t switch_array_size(const uint8_t* ptr, const uint8_t* end);
351
352} // Namespace LIEF
353} // Namespace DEX
354
355#endif
356
Definition DEX/Class.hpp:30
SWITCH_ARRAY_IDENT
Definition instructions.hpp:25
@ IDENT_SPARSE_SWITCH
Definition instructions.hpp:27
@ IDENT_PACKED_SWITCH
Definition instructions.hpp:26
@ IDENT_FILL_ARRAY
Definition instructions.hpp:28
OPCODES
The Dalvik Opcodes.
Definition instructions.hpp:32
@ OP_MONITOR_EXIT
Definition instructions.hpp:63
@ OP_APUT_BOOLEAN
Definition instructions.hpp:105
@ OP_DIV_INT_2_ADDR
Definition instructions.hpp:204
@ OP_OR_LONG
Definition instructions.hpp:186
@ OP_MOVE_OBJECT_FROM_16
Definition instructions.hpp:41
@ OP_PACKED_SWITCH
Definition instructions.hpp:76
@ OP_XOR_INT
Definition instructions.hpp:176
@ OP_IPUT_SHORT_QUICK
Definition instructions.hpp:265
@ OP_AGET_BOOLEAN
Definition instructions.hpp:98
@ OP_IPUT_WIDE
Definition instructions.hpp:117
@ OP_IGET_CHAR
Definition instructions.hpp:114
@ OP_IGET_SHORT
Definition instructions.hpp:115
@ OP_IPUT_CHAR_QUICK
Definition instructions.hpp:264
@ OP_SPUT_OBJECT
Definition instructions.hpp:132
@ OP_IGET_BYTE
Definition instructions.hpp:113
@ OP_APUT
Definition instructions.hpp:102
@ OP_DIV_LONG_2_ADDR
Definition instructions.hpp:215
@ OP_INVOKE_VIRTUAL_QUICK
Definition instructions.hpp:260
@ OP_IGET_WIDE
Definition instructions.hpp:110
@ OP_DIV_DOUBLE
Definition instructions.hpp:199
@ OP_REM_FLOAT_2_ADDR
Definition instructions.hpp:227
@ OP_AND_INT_2_ADDR
Definition instructions.hpp:206
@ OP_AGET_SHORT
Definition instructions.hpp:101
@ OP_CONST_WIDE_16
Definition instructions.hpp:55
@ OP_INVOKE_DIRECT
Definition instructions.hpp:139
@ OP_IPUT_SHORT
Definition instructions.hpp:122
@ OP_IF_LE
Definition instructions.hpp:88
@ OP_MOVE_OBJECT_16
Definition instructions.hpp:42
@ OP_CONST_METHOD_TYPE
Definition instructions.hpp:279
@ OP_LONG_TO_FLOAT
Definition instructions.hpp:158
@ OP_SGET
Definition instructions.hpp:123
@ OP_MUL_FLOAT_2_ADDR
Definition instructions.hpp:225
@ OP_DOUBLE_TO_INT
Definition instructions.hpp:163
@ OP_IGET
Definition instructions.hpp:109
@ OP_MOVE_WIDE_FROM_16
Definition instructions.hpp:38
@ OP_SGET_BYTE
Definition instructions.hpp:127
@ OP_ADD_INT_LIT_16
Definition instructions.hpp:233
@ OP_FLOAT_TO_DOUBLE
Definition instructions.hpp:162
@ OP_ADD_INT
Definition instructions.hpp:169
@ OP_INVOKE_VIRTUAL_RANGE_QUICK
Definition instructions.hpp:261
@ OP_OR_LONG_2_ADDR
Definition instructions.hpp:218
@ OP_AGET_WIDE
Definition instructions.hpp:96
@ OP_ADD_LONG
Definition instructions.hpp:180
@ OP_INT_TO_CHAR
Definition instructions.hpp:167
@ OP_INVOKE_CUSTOM_RANGE
Definition instructions.hpp:275
@ OP_IGET_QUICK
Definition instructions.hpp:254
@ OP_RETURN_VOID
Definition instructions.hpp:47
@ OP_CONST_HIGH_16
Definition instructions.hpp:54
@ OP_DIV_FLOAT
Definition instructions.hpp:194
@ OP_MOVE_WIDE
Definition instructions.hpp:37
@ OP_ADD_INT_2_ADDR
Definition instructions.hpp:201
@ OP_AGET
Definition instructions.hpp:95
@ OP_AGET_CHAR
Definition instructions.hpp:100
@ OP_GOTO
Definition instructions.hpp:73
@ OP_XOR_INT_LIT_8
Definition instructions.hpp:248
@ OP_IF_GE
Definition instructions.hpp:86
@ OP_RETURN_OBJECT
Definition instructions.hpp:50
@ OP_IPUT_WIDE_QUICK
Definition instructions.hpp:258
@ OP_IGET_BYTE_QUICK
Definition instructions.hpp:267
@ OP_USHR_INT
Definition instructions.hpp:179
@ OP_RETURN_WIDE
Definition instructions.hpp:49
@ OP_RETURN
Definition instructions.hpp:48
@ OP_SUB_INT_2_ADDR
Definition instructions.hpp:202
@ OP_INVOKE_STATIC
Definition instructions.hpp:140
@ OP_CONST_WIDE
Definition instructions.hpp:57
@ OP_IPUT_BYTE
Definition instructions.hpp:120
@ OP_OR_INT_2_ADDR
Definition instructions.hpp:207
@ OP_INVOKE_DIRECT_RANGE
Definition instructions.hpp:145
@ OP_MOVE_WIDE_16
Definition instructions.hpp:39
@ OP_CONST
Definition instructions.hpp:53
@ OP_NOT_LONG
Definition instructions.hpp:151
@ OP_ADD_DOUBLE_2_ADDR
Definition instructions.hpp:228
@ OP_INVOKE_INTERFACE_RANGE
Definition instructions.hpp:147
@ OP_IGET_OBJECT_QUICK
Definition instructions.hpp:256
@ OP_SHR_LONG_2_ADDR
Definition instructions.hpp:221
@ OP_DOUBLE_TO_FLOAT
Definition instructions.hpp:165
@ OP_INT_TO_BYTE
Definition instructions.hpp:166
@ OP_XOR_LONG_2_ADDR
Definition instructions.hpp:219
@ OP_SHR_INT_2_ADDR
Definition instructions.hpp:210
@ OP_IGET_CHAR_QUICK
Definition instructions.hpp:268
@ OP_IF_LT
Definition instructions.hpp:85
@ OP_REM_DOUBLE_2_ADDR
Definition instructions.hpp:232
@ OP_LONG_TO_INT
Definition instructions.hpp:157
@ OP_INVOKE_VIRTUAL_RANGE
Definition instructions.hpp:143
@ OP_APUT_SHORT
Definition instructions.hpp:108
@ OP_NEG_FLOAT
Definition instructions.hpp:152
@ OP_CONST_WIDE_HIGH_16
Definition instructions.hpp:58
@ OP_INT_TO_SHORT
Definition instructions.hpp:168
@ OP_AGET_OBJECT
Definition instructions.hpp:97
@ OP_IF_LTZ
Definition instructions.hpp:91
@ OP_XOR_LONG
Definition instructions.hpp:187
@ OP_MOVE_RESULT_OBJECT
Definition instructions.hpp:45
@ OP_SHL_LONG_2_ADDR
Definition instructions.hpp:220
@ OP_REM_INT_2_ADDR
Definition instructions.hpp:205
@ OP_APUT_CHAR
Definition instructions.hpp:107
@ OP_REM_DOUBLE
Definition instructions.hpp:200
@ OP_RSUB_INT_LIT_8
Definition instructions.hpp:242
@ OP_SGET_WIDE
Definition instructions.hpp:124
@ OP_INVOKE_SUPER_RANGE
Definition instructions.hpp:144
@ OP_IGET_OBJECT
Definition instructions.hpp:111
@ OP_SUB_DOUBLE_2_ADDR
Definition instructions.hpp:229
@ OP_SUB_FLOAT
Definition instructions.hpp:192
@ OP_CONST_STRING
Definition instructions.hpp:59
@ OP_SPUT_SHORT
Definition instructions.hpp:136
@ OP_INVOKE_VIRTUAL
Definition instructions.hpp:137
@ OP_ADD_FLOAT_2_ADDR
Definition instructions.hpp:223
@ OP_MOVE_RESULT
Definition instructions.hpp:43
@ OP_CMPL_FLOAT
Definition instructions.hpp:78
@ OP_MUL_LONG
Definition instructions.hpp:182
@ OP_AND_INT_LIT_8
Definition instructions.hpp:246
@ OP_NOT_INT
Definition instructions.hpp:149
@ OP_USHR_INT_LIT_8
Definition instructions.hpp:251
@ OP_REM_LONG
Definition instructions.hpp:184
@ OP_MOVE_EXCEPTION
Definition instructions.hpp:46
@ OP_CONST_METHOD_HANDLE
Definition instructions.hpp:278
@ OP_MUL_DOUBLE_2_ADDR
Definition instructions.hpp:230
@ OP_CMPL_DOUBLE
Definition instructions.hpp:80
@ OP_IF_GEZ
Definition instructions.hpp:92
@ OP_OR_INT_LIT_8
Definition instructions.hpp:247
@ OP_IF_NEZ
Definition instructions.hpp:90
@ OP_REM_LONG_2_ADDR
Definition instructions.hpp:216
@ OP_REM_INT
Definition instructions.hpp:173
@ OP_USHR_LONG
Definition instructions.hpp:190
@ OP_CONST_16
Definition instructions.hpp:52
@ OP_CONST_4
Definition instructions.hpp:51
@ OP_IF_EQ
Definition instructions.hpp:83
@ OP_NEG_LONG
Definition instructions.hpp:150
@ OP_CMPG_DOUBLE
Definition instructions.hpp:81
@ OP_IF_LEZ
Definition instructions.hpp:94
@ OP_IGET_SHORT_QUICK
Definition instructions.hpp:269
@ OP_NEW_ARRAY
Definition instructions.hpp:68
@ OP_SPUT_WIDE
Definition instructions.hpp:131
@ OP_SPUT
Definition instructions.hpp:130
@ OP_IGET_BOOLEAN
Definition instructions.hpp:112
@ OP_RSUB_INT
Definition instructions.hpp:234
@ OP_ADD_FLOAT
Definition instructions.hpp:191
@ OP_DIV_INT_LIT_16
Definition instructions.hpp:236
@ OP_INVOKE_POLYMORPHIC_RANGE
Definition instructions.hpp:273
@ OP_IPUT_BOOLEAN
Definition instructions.hpp:119
@ OP_INT_TO_FLOAT
Definition instructions.hpp:155
@ OP_IF_NE
Definition instructions.hpp:84
@ OP_DIV_LONG
Definition instructions.hpp:183
@ OP_FILL_ARRAY_DATA
Definition instructions.hpp:71
@ OP_MUL_DOUBLE
Definition instructions.hpp:198
@ OP_AGET_BYTE
Definition instructions.hpp:99
@ OP_DIV_INT
Definition instructions.hpp:172
@ OP_XOR_INT_LIT_16
Definition instructions.hpp:240
@ OP_INVOKE_INTERFACE
Definition instructions.hpp:141
@ OP_INVOKE_SUPER
Definition instructions.hpp:138
@ OP_SHL_INT
Definition instructions.hpp:177
@ OP_LONG_TO_DOUBLE
Definition instructions.hpp:159
@ OP_ADD_LONG_2_ADDR
Definition instructions.hpp:212
@ OP_FILLED_NEW_ARRAY
Definition instructions.hpp:69
@ OP_AND_LONG_2_ADDR
Definition instructions.hpp:217
@ OP_INT_TO_DOUBLE
Definition instructions.hpp:156
@ OP_IPUT_OBJECT_QUICK
Definition instructions.hpp:259
@ OP_DIV_INT_LIT_8
Definition instructions.hpp:244
@ OP_AND_LONG
Definition instructions.hpp:185
@ OP_CONST_WIDE_32
Definition instructions.hpp:56
@ OP_IF_EQZ
Definition instructions.hpp:89
@ OP_SUB_FLOAT_2_ADDR
Definition instructions.hpp:224
@ OP_CHECK_CAST
Definition instructions.hpp:64
@ OP_INVOKE_CUSTOM
Definition instructions.hpp:274
@ OP_ARRAY_LENGTH
Definition instructions.hpp:66
@ OP_MOVE_OBJECT
Definition instructions.hpp:40
@ OP_IPUT_CHAR
Definition instructions.hpp:121
@ OP_IPUT
Definition instructions.hpp:116
@ OP_ADD_DOUBLE
Definition instructions.hpp:196
@ OP_GOTO_32
Definition instructions.hpp:75
@ OP_MOVE_FROM_16
Definition instructions.hpp:35
@ OP_NEW_INSTANCE
Definition instructions.hpp:67
@ OP_NEG_DOUBLE
Definition instructions.hpp:153
@ OP_SPUT_CHAR
Definition instructions.hpp:135
@ OP_APUT_BYTE
Definition instructions.hpp:106
@ OP_SPUT_BOOLEAN
Definition instructions.hpp:133
@ OP_RETURN_VOID_NO_BARRIER
Definition instructions.hpp:142
@ OP_IGET_WIDE_QUICK
Definition instructions.hpp:255
@ OP_FILLED_NEW_ARRAY_RANGE
Definition instructions.hpp:70
@ OP_SHL_LONG
Definition instructions.hpp:188
@ OP_SHR_LONG
Definition instructions.hpp:189
@ OP_INT_TO_LONG
Definition instructions.hpp:154
@ OP_SGET_BOOLEAN
Definition instructions.hpp:126
@ OP_SUB_LONG_2_ADDR
Definition instructions.hpp:213
@ OP_SUB_DOUBLE
Definition instructions.hpp:197
@ OP_MUL_FLOAT
Definition instructions.hpp:193
@ OP_USHR_LONG_2_ADDR
Definition instructions.hpp:222
@ OP_NOP
Definition instructions.hpp:33
@ OP_MUL_INT_LIT_8
Definition instructions.hpp:243
@ OP_MUL_INT_2_ADDR
Definition instructions.hpp:203
@ OP_SUB_INT
Definition instructions.hpp:170
@ OP_USHR_INT_2_ADDR
Definition instructions.hpp:211
@ OP_MOVE
Definition instructions.hpp:34
@ OP_DIV_DOUBLE_2_ADDR
Definition instructions.hpp:231
@ OP_SGET_OBJECT
Definition instructions.hpp:125
@ OP_AND_INT
Definition instructions.hpp:174
@ OP_MUL_INT_LIT_16
Definition instructions.hpp:235
@ OP_MOVE_RESULT_WIDE
Definition instructions.hpp:44
@ OP_IPUT_QUICK
Definition instructions.hpp:257
@ OP_FLOAT_TO_INT
Definition instructions.hpp:160
@ OP_IPUT_BYTE_QUICK
Definition instructions.hpp:263
@ OP_IF_GTZ
Definition instructions.hpp:93
@ OP_MUL_LONG_2_ADDR
Definition instructions.hpp:214
@ OP_INVOKE_POLYMORPHIC
Definition instructions.hpp:272
@ OP_INVOKE_STATIC_RANGE
Definition instructions.hpp:146
@ OP_SUB_LONG
Definition instructions.hpp:181
@ OP_SPARSE_SWITCH
Definition instructions.hpp:77
@ OP_MOVE_16
Definition instructions.hpp:36
@ OP_OR_INT
Definition instructions.hpp:175
@ OP_CMP_LONG
Definition instructions.hpp:82
@ OP_REM_INT_LIT_16
Definition instructions.hpp:237
@ OP_IPUT_OBJECT
Definition instructions.hpp:118
@ OP_CONST_CLASS
Definition instructions.hpp:61
@ OP_OR_INT_LIT_16
Definition instructions.hpp:239
@ OP_DOUBLE_TO_LONG
Definition instructions.hpp:164
@ OP_APUT_OBJECT
Definition instructions.hpp:104
@ OP_SHR_INT
Definition instructions.hpp:178
@ OP_NEG_INT
Definition instructions.hpp:148
@ OP_IGET_BOOLEAN_QUICK
Definition instructions.hpp:266
@ OP_SGET_CHAR
Definition instructions.hpp:128
@ OP_REM_INT_LIT_8
Definition instructions.hpp:245
@ OP_THROW
Definition instructions.hpp:72
@ OP_AND_INT_LIT_16
Definition instructions.hpp:238
@ OP_SPUT_BYTE
Definition instructions.hpp:134
@ OP_CONST_STRING_JUMBO
Definition instructions.hpp:60
@ OP_SHL_INT_2_ADDR
Definition instructions.hpp:209
@ OP_MONITOR_ENTER
Definition instructions.hpp:62
@ OP_GOTO_16
Definition instructions.hpp:74
@ OP_APUT_WIDE
Definition instructions.hpp:103
@ OP_IPUT_BOOLEAN_QUICK
Definition instructions.hpp:262
@ OP_INSTANCE_OF
Definition instructions.hpp:65
@ OP_SHR_INT_LIT_8
Definition instructions.hpp:250
@ OP_CMPG_FLOAT
Definition instructions.hpp:79
@ OP_DIV_FLOAT_2_ADDR
Definition instructions.hpp:226
@ OP_ADD_INT_LIT_8
Definition instructions.hpp:241
@ OP_MUL_INT
Definition instructions.hpp:171
@ OP_FLOAT_TO_LONG
Definition instructions.hpp:161
@ OP_SHL_INT_LIT_8
Definition instructions.hpp:249
@ OP_SGET_SHORT
Definition instructions.hpp:129
@ OP_REM_FLOAT
Definition instructions.hpp:195
@ OP_XOR_INT_2_ADDR
Definition instructions.hpp:208
@ OP_IF_GT
Definition instructions.hpp:87
size_t inst_size_from_format(INST_FORMATS fmt)
bool is_switch_array(const uint8_t *ptr, const uint8_t *end)
size_t inst_size_from_opcode(OPCODES op)
INST_FORMATS
Definition instructions.hpp:282
@ F_3rmi
Definition instructions.hpp:312
@ F_3rms
Definition instructions.hpp:311
@ F_21t
Definition instructions.hpp:292
@ F_12x
Definition instructions.hpp:285
@ F_30t
Definition instructions.hpp:302
@ F_45cc
Definition instructions.hpp:316
@ F_11x
Definition instructions.hpp:287
@ F_22c
Definition instructions.hpp:300
@ F_35c
Definition instructions.hpp:307
@ F_00x
Definition instructions.hpp:283
@ F_22x
Definition instructions.hpp:291
@ F_20t
Definition instructions.hpp:289
@ F_23x
Definition instructions.hpp:296
@ F_10x
Definition instructions.hpp:284
@ F_35ms
Definition instructions.hpp:308
@ F_21c
Definition instructions.hpp:295
@ F_21s
Definition instructions.hpp:293
@ F_22t
Definition instructions.hpp:298
@ F_51l
Definition instructions.hpp:313
@ F_22s
Definition instructions.hpp:299
@ F_31i
Definition instructions.hpp:304
@ F_3rc
Definition instructions.hpp:310
@ F_22cs
Definition instructions.hpp:301
@ F_20bc
Definition instructions.hpp:290
@ F_21h
Definition instructions.hpp:294
@ F_11n
Definition instructions.hpp:286
@ F_31t
Definition instructions.hpp:305
@ F_32x
Definition instructions.hpp:303
@ F_35mi
Definition instructions.hpp:309
@ F_10t
Definition instructions.hpp:288
@ F_4rcc
Definition instructions.hpp:317
@ F_22b
Definition instructions.hpp:297
@ F_31c
Definition instructions.hpp:306
size_t switch_array_size(const uint8_t *ptr, const uint8_t *end)
INST_FORMATS inst_format_from_opcode(OPCODES op)
Return the INST_FORMATS format associated with the given opcode.
LIEF namespace.
Definition Abstract/Binary.hpp:36
Definition instructions.hpp:334
uint16_t ident
Definition instructions.hpp:335
uint32_t size
Definition instructions.hpp:337
uint16_t element_width
Definition instructions.hpp:336
Definition instructions.hpp:320
uint16_t ident
Definition instructions.hpp:321
uint32_t first_key
Definition instructions.hpp:323
uint16_t size
Definition instructions.hpp:322
Definition instructions.hpp:328
uint16_t ident
Definition instructions.hpp:329
uint16_t size
Definition instructions.hpp:330
#define LIEF_API
Definition visibility.h:41