forked from facebook/redex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDexAsm.cpp
108 lines (96 loc) · 2.68 KB
/
DexAsm.cpp
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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "DexAsm.h"
#include "IRInstruction.h"
#include "Show.h"
namespace dex_asm {
bool unsupported(IROpcode opcode) {
switch (opcode) {
case OPCODE_CONST_STRING:
case OPCODE_CONST_CLASS:
case OPCODE_CHECK_CAST:
case OPCODE_INSTANCE_OF:
case OPCODE_NEW_INSTANCE:
case OPCODE_NEW_ARRAY:
case OPCODE_FILLED_NEW_ARRAY:
case OPCODE_IGET:
case OPCODE_IGET_WIDE:
case OPCODE_IGET_OBJECT:
case OPCODE_IGET_BOOLEAN:
case OPCODE_IGET_BYTE:
case OPCODE_IGET_CHAR:
case OPCODE_IGET_SHORT:
case OPCODE_IPUT:
case OPCODE_IPUT_WIDE:
case OPCODE_IPUT_OBJECT:
case OPCODE_IPUT_BOOLEAN:
case OPCODE_IPUT_BYTE:
case OPCODE_IPUT_CHAR:
case OPCODE_IPUT_SHORT:
case OPCODE_SGET:
case OPCODE_SGET_WIDE:
case OPCODE_SGET_OBJECT:
case OPCODE_SGET_BOOLEAN:
case OPCODE_SGET_BYTE:
case OPCODE_SGET_CHAR:
case OPCODE_SGET_SHORT:
case OPCODE_SPUT:
case OPCODE_SPUT_WIDE:
case OPCODE_SPUT_OBJECT:
case OPCODE_SPUT_BOOLEAN:
case OPCODE_SPUT_BYTE:
case OPCODE_SPUT_CHAR:
case OPCODE_SPUT_SHORT:
case OPCODE_INVOKE_VIRTUAL:
case OPCODE_INVOKE_SUPER:
case OPCODE_INVOKE_DIRECT:
case OPCODE_INVOKE_STATIC:
case OPCODE_INVOKE_INTERFACE:
return true;
default:
return false;
}
}
void assemble(IRInstruction* insn, std::initializer_list<Operand> args) {
assemble(insn, args.begin(), args.end());
}
IRInstruction* dasm(IROpcode opcode, std::initializer_list<Operand> args) {
assert_log(!unsupported(opcode), "%s is unsupported", SHOW(opcode));
auto insn = new IRInstruction(opcode);
assemble(insn, args);
return insn;
}
IRInstruction* dasm(IROpcode opcode,
const DexString* string,
std::initializer_list<Operand> args) {
auto insn = new IRInstruction(opcode);
insn->set_string(string);
assemble(insn, args);
return insn;
}
IRInstruction* dasm(IROpcode opcode,
DexType* type,
std::initializer_list<Operand> args) {
auto insn = new IRInstruction(opcode);
insn->set_type(type);
assemble(insn, args);
return insn;
}
IRInstruction* dasm(IROpcode opcode,
DexFieldRef* field,
std::initializer_list<Operand> args) {
auto insn = new IRInstruction(opcode);
insn->set_field(field);
assemble(insn, args);
return insn;
}
IRInstruction* dasm(IROpcode opcode,
DexMethodRef* method,
std::initializer_list<Operand> args) {
return dasm(opcode, method, args.begin(), args.end());
}
} // namespace dex_asm