Rizin
unix-like reverse engineering framework and cli tools
opcode.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016-2020 c0riolis
2 // SPDX-FileCopyrightText: 2016-2020 x0urc3
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #ifndef OPCODE_H
6 #define OPCODE_H
7 
8 #include <rz_types.h>
9 #include <rz_list.h>
10 #include <rz_util.h>
11 #include <rz_analysis.h>
12 
13 #define OBJECT_SIZE_ON_STACK 1
14 
15 typedef enum {
16  HASCOMPARE = 0x1,
17  HASCONDITION = 0x2, // conditional operator; has jump offset
18  HASCONST = 0x4,
19  HASFREE = 0x8,
20  HASJABS = 0x10, // Will appear with HASCONDITION sometimes
21  HASJREL = 0x20, // Will appear with HASCONDITION sometimes
22  HASLOCAL = 0x40,
23  HASNAME = 0x80,
24  HASNARGS = 0x100, // For function-like calls
25  HASSTORE = 0x200, // Some sort of store operation
26  HASVARGS = 0x400, // Similar but for operators BUILD_xxx
27  NOFOLLOW = 0x800, // Instruction doesn't fall to the next opcode
29 
30 typedef enum {
31  NAME_OP = 0x1,
32  LOCAL_OP = 0x2,
33  FREE_OP = 0x4,
34  DEF_OP = 0x8,
36 
37 typedef struct {
38  char *op_name;
44 
45 typedef struct {
49  void *(*version_sig)();
52 } pyc_opcodes;
53 
54 typedef struct {
55  char *op_name;
56  const char *(*formatter)(ut32 oparg);
57 } pyc_arg_fmt;
58 
59 typedef struct {
60  char *version;
61  pyc_opcodes *(*opcode_func)();
63 
64 typedef struct {
65  char *op_name;
66  void (*func)(RzAnalysisOp *op, pyc_opcode_object *op_obj, ut32 oparg);
68 
70 
71 pyc_opcodes *opcode_2x(void);
72 pyc_opcodes *opcode_3x(void);
73 pyc_opcodes *opcode_10(void);
74 pyc_opcodes *opcode_11(void);
75 pyc_opcodes *opcode_12(void);
76 pyc_opcodes *opcode_13(void);
77 pyc_opcodes *opcode_14(void);
78 pyc_opcodes *opcode_15(void);
79 pyc_opcodes *opcode_16(void);
80 pyc_opcodes *opcode_20(void);
81 pyc_opcodes *opcode_21(void);
82 pyc_opcodes *opcode_22(void);
83 pyc_opcodes *opcode_23(void);
84 pyc_opcodes *opcode_24(void);
85 pyc_opcodes *opcode_25(void);
86 pyc_opcodes *opcode_26(void);
87 pyc_opcodes *opcode_27(void);
88 pyc_opcodes *opcode_30(void);
89 pyc_opcodes *opcode_31(void);
90 pyc_opcodes *opcode_32(void);
91 pyc_opcodes *opcode_33(void);
92 pyc_opcodes *opcode_34(void);
93 pyc_opcodes *opcode_35(void);
94 pyc_opcodes *opcode_36(void);
95 pyc_opcodes *opcode_37(void);
96 pyc_opcodes *opcode_38(void);
97 pyc_opcodes *opcode_39(void);
98 
100 
103 bool pyc_opcodes_equal(pyc_opcodes *op, const char *version);
104 
105 void add_arg_fmt(pyc_opcodes *ret, char *op_name, const char *(*formatter)(ut32 oparg));
106 
107 const char *format_MAKE_FUNCTION_arg_3x(ut32 oparg);
108 const char *format_extended_arg(ut32 oparg);
110 const char *format_CALL_FUNCTION_KW_36(ut32 oparg);
111 const char *format_CALL_FUNCTION_EX_36(ut32 oparg);
112 const char *format_MAKE_FUNCTION_arg_36(ut32 oparg);
113 const char *format_value_flags_36(ut32 oparg);
114 const char *format_extended_arg_36(ut32 oparg);
115 
116 struct op_parameter {
118  const char *op_name;
125 };
126 
127 #define def_op(...) def_opN((struct op_parameter){ .fallthrough = true, __VA_ARGS__ })
128 #define def_op0(...) def_opN((struct op_parameter){ .pop = -2, .push = -2, .fallthrough = true, __VA_ARGS__ })
129 #define def_op00(...) def_opN((struct op_parameter){ __VA_ARGS__ })
130 void(def_opN)(struct op_parameter par);
131 
132 #define name_op0(...) name_opN((struct op_parameter){ .pop = -2, .push = -2, __VA_ARGS__ })
133 #define name_op(...) name_opN((struct op_parameter){ __VA_ARGS__ })
134 void(name_opN)(struct op_parameter par);
135 
136 #define local_op0(...) local_opN((struct op_parameter){ .pop = 0, .push = 1, __VA_ARGS__ })
137 #define local_op(...) local_opN((struct op_parameter){ __VA_ARGS__ })
138 void(local_opN)(struct op_parameter par);
139 
140 #define free_op0(...) free_opN((struct op_parameter){ .pop = 0, .push = 1, __VA_ARGS__ })
141 #define free_op(...) free_opN((struct op_parameter){ __VA_ARGS__ })
142 void(free_opN)(struct op_parameter par);
143 
144 #define store_op00(...) store_opN((struct op_parameter){ __VA_ARGS__ })
145 #define store_op(...) store_opN((struct op_parameter){ .func = DEF_OP, __VA_ARGS__ })
146 #define store_op0(...) store_opN((struct op_parameter){ .pop = 0, .push = 1, .func = DEF_OP, __VA_ARGS__ })
147 void(store_opN)(struct op_parameter par);
148 
149 #define varargs_op(...) varargs_op((struct op_parameter){ __VA_ARGS__ })
150 #define varargs_op0(...) varargs_op((struct op_parameter){ .pop = -1, .push = 1, __VA_ARGS__ })
151 void(varargs_op)(struct op_parameter par);
152 
153 #define const_op(...) const_opN((struct op_parameter){ .pop = 0, .push = 1, __VA_ARGS__ })
154 #define const_op00(...) const_opN((struct op_parameter){ __VA_ARGS__ })
155 void(const_opN)(struct op_parameter par);
156 
157 #define compare_op0(...) compare_op((struct op_parameter){ .pop = 2, .push = 1, __VA_ARGS__ })
158 #define compare_op(...) compare_op((struct op_parameter){ __VA_ARGS__ })
159 void(compare_op)(struct op_parameter par);
160 
161 #define jabs_op00(...) jabs_opN((struct op_parameter){ __VA_ARGS__ })
162 #define jabs_op0(...) jabs_opN((struct op_parameter){ .pop = 0, .push = 0, .conditional = false, .fallthrough = true, __VA_ARGS__ })
163 #define jabs_op(...) jabs_opN((struct op_parameter){ .fallthrough = true, __VA_ARGS__ })
164 void(jabs_opN)(struct op_parameter par);
165 
166 #define jrel_op00(...) jrel_opN((struct op_parameter){ __VA_ARGS__ })
167 #define jrel_op0(...) jrel_opN((struct op_parameter){ .pop = 0, .push = 0, .conditional = false, .fallthrough = true, __VA_ARGS__ })
168 #define jrel_op(...) jrel_opN((struct op_parameter){ .fallthrough = true, __VA_ARGS__ })
169 void(jrel_opN)(struct op_parameter par);
170 
171 #define nargs_op(...) nargs_op((struct op_parameter){ __VA_ARGS__ })
172 #define nargs_op0(...) nargs_op((struct op_parameter){ .pop = -2, .push = -2, __VA_ARGS__ })
173 void(nargs_op)(struct op_parameter par);
174 
175 #define rm_op(...) rm_op((struct op_parameter){ __VA_ARGS__ })
176 void(rm_op)(struct op_parameter par);
177 
178 #endif
ut8 op
Definition: 6502dis.c:13
OPCODE_DESC opcodes[]
Definition: avr_esil.c:1270
uint16_t ut16
uint32_t ut32
uint8_t ut8
Definition: lh5801.h:11
pyc_opcodes * opcode_24(void)
Definition: opcode_24.c:6
pyc_opcodes * opcode_15(void)
Definition: opcode_15.c:6
pyc_opcodes * opcode_12(void)
Definition: opcode_12.c:6
#define nargs_op(...)
Definition: opcode.h:171
pyc_opcodes * opcode_37(void)
Definition: opcode_37.c:6
pyc_opcodes * opcode_32(void)
Definition: opcode_32.c:6
pyc_opcodes * opcode_3x(void)
Definition: opcode_3x.c:6
void free_opcode(pyc_opcodes *opcodes)
Definition: opcode.c:217
const char * format_extended_arg(ut32 oparg)
Definition: opcode_arg_fmt.c:6
pyc_opcodes * new_pyc_opcodes()
Definition: opcode.c:185
const char * format_MAKE_FUNCTION_arg_3x(ut32 oparg)
const char * format_MAKE_FUNCTION_arg_36(ut32 oparg)
pyc_opcodes * opcode_23(void)
Definition: opcode_23.c:6
pyc_opcodes * opcode_31(void)
Definition: opcode_31.c:6
pyc_opcodes * opcode_26(void)
Definition: opcode_26.c:6
pyc_opcodes * opcode_14(void)
Definition: opcode_14.c:6
const char * format_CALL_FUNCTION_KW_36(ut32 oparg)
pyc_opcodes * opcode_25(void)
Definition: opcode_25.c:6
pyc_opcodes * opcode_11(void)
Definition: opcode_11.c:6
void() free_opN(struct op_parameter par)
Definition: opcode.c:265
pyc_opcodes * opcode_38(void)
Definition: opcode_38.c:6
void() const_opN(struct op_parameter par)
Definition: opcode.c:296
pyc_opcodes * opcode_27(void)
Definition: opcode_27.c:6
pyc_opcodes * get_opcode_by_version(char *version)
Definition: opcode.c:169
void() local_opN(struct op_parameter par)
Definition: opcode.c:260
void() def_opN(struct op_parameter par)
Definition: opcode.c:244
pyc_opcodes * opcode_21(void)
Definition: opcode_21.c:6
pyc_opcodes * opcode_2x(void)
Definition: opcode_2x.c:6
pyc_opcodes * opcode_13(void)
Definition: opcode_13.c:6
pyc_opcodes * opcode_10(void)
Definition: opcode_10.c:6
void() store_opN(struct op_parameter par)
Definition: opcode.c:270
const char * format_extended_arg_36(ut32 oparg)
pyc_opcodes * opcode_16(void)
Definition: opcode_16.c:6
#define varargs_op(...)
Definition: opcode.h:149
pyc_opcodes * opcode_39(void)
Definition: opcode_39.c:6
void analysis_pyc_op(RzAnalysisOp *op, pyc_opcode_object *op_obj, ut32 oparg)
bool pyc_opcodes_equal(pyc_opcodes *op, const char *version)
Definition: opcode.c:151
#define compare_op(...)
Definition: opcode.h:158
pyc_opcodes * opcode_33(void)
Definition: opcode_33.c:6
void() jrel_opN(struct op_parameter par)
Definition: opcode.c:314
pyc_opcodes * opcode_34(void)
Definition: opcode_34.c:6
void add_arg_fmt(pyc_opcodes *ret, char *op_name, const char *(*formatter)(ut32 oparg))
Definition: opcode.c:234
pyc_opcodes * opcode_36(void)
Definition: opcode_36.c:6
pyc_opcodes * opcode_22(void)
Definition: opcode_22.c:6
#define rm_op(...)
Definition: opcode.h:175
pyc_opcodes * opcode_30(void)
Definition: opcode_30.c:6
pyc_opcodes * opcode_20(void)
Definition: opcode_20.c:6
pyc_store_op_func
Definition: opcode.h:30
@ LOCAL_OP
Definition: opcode.h:32
@ DEF_OP
Definition: opcode.h:34
@ FREE_OP
Definition: opcode.h:33
@ NAME_OP
Definition: opcode.h:31
pyc_opcode_type
Definition: opcode.h:15
@ HASNAME
Definition: opcode.h:23
@ HASCONDITION
Definition: opcode.h:17
@ HASCOMPARE
Definition: opcode.h:16
@ HASLOCAL
Definition: opcode.h:22
@ HASSTORE
Definition: opcode.h:25
@ HASJREL
Definition: opcode.h:21
@ HASCONST
Definition: opcode.h:18
@ NOFOLLOW
Definition: opcode.h:27
@ HASNARGS
Definition: opcode.h:24
@ HASVARGS
Definition: opcode.h:26
@ HASFREE
Definition: opcode.h:19
@ HASJABS
Definition: opcode.h:20
pyc_opcodes * opcode_35(void)
Definition: opcode_35.c:6
const char * format_CALL_FUNCTION_pos_name_encoded(ut32 oparg)
void() name_opN(struct op_parameter par)
Definition: opcode.c:255
const char * format_CALL_FUNCTION_EX_36(ut32 oparg)
void() jabs_opN(struct op_parameter par)
Definition: opcode.c:306
const char * format_value_flags_36(ut32 oparg)
#define st8
Definition: rz_types_base.h:16
char * op_name
Definition: opcode.h:65
pyc_store_op_func func
Definition: opcode.h:122
bool fallthrough
Definition: opcode.h:124
pyc_opcode_object * op_obj
Definition: opcode.h:117
ut8 op_code
Definition: opcode.h:119
bool conditional
Definition: opcode.h:123
const char * op_name
Definition: opcode.h:118
st8 push
Definition: opcode.h:121
char * op_name
Definition: opcode.h:55
char * op_name
Definition: opcode.h:38
ut8 have_argument
Definition: opcode.h:47
pyc_opcode_object * opcodes
Definition: opcode.h:51
ut8 extended_arg
Definition: opcode.h:46
ut8 bits
Definition: opcode.h:48
RzList * opcode_arg_fmt
Definition: opcode.h:50
char * version
Definition: opcode.h:60
Definition: dis.c:32