Rizin
unix-like reverse engineering framework and cli tools
opcode_15.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2020 FXTi <zjxiang1998@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include "opcode.h"
5 
8  if (!ret) {
9  return NULL;
10  }
11 
12  ret->version_sig = (void *(*)())opcode_15;
13 
14  def_opN((struct op_parameter){ .op_obj = ret->opcodes, .op_name = "STOP_CODE", .op_code = 0, .pop = 0, .push = 0, .fallthrough = false });
15  def_op(.op_obj = ret->opcodes, .op_name = "POP_TOP", .op_code = 1);
16  def_op(.op_obj = ret->opcodes, .op_name = "ROT_TWO", .op_code = 2);
17  def_op(.op_obj = ret->opcodes, .op_name = "ROT_THREE", .op_code = 3);
18  def_op(.op_obj = ret->opcodes, .op_name = "DUP_TOP", .op_code = 4);
19 
20  def_op(.op_obj = ret->opcodes, .op_name = "UNARY_POSITIVE", .op_code = 10, .pop = 1, .push = 1);
21  def_op(.op_obj = ret->opcodes, .op_name = "UNARY_NEGATIVE", .op_code = 11, .pop = 1, .push = 1);
22  def_op(.op_obj = ret->opcodes, .op_name = "UNARY_NOT", .op_code = 12, .pop = 1, .push = 1);
23  def_op(.op_obj = ret->opcodes, .op_name = "UNARY_CONVERT", .op_code = 13, .pop = 1, .push = 1);
24 
25  def_op(.op_obj = ret->opcodes, .op_name = "UNARY_INVERT", .op_code = 15, .pop = 1, .push = 1);
26 
27  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_POWER", .op_code = 19, .pop = 1, .push = 1);
28  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_MULTIPLY", .op_code = 20, .pop = 2, .push = 1);
29  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_DIVIDE", .op_code = 21, .pop = 2, .push = 1);
30  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_MODULO", .op_code = 22, .pop = 2, .push = 1);
31  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_ADD", .op_code = 23, .pop = 2, .push = 1);
32  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_SUBTRACT", .op_code = 24, .pop = 2, .push = 1);
33  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_SUBSCR", .op_code = 25, .pop = 2, .push = 1);
34 
35  def_op(.op_obj = ret->opcodes, .op_name = "SLICE_0", .op_code = 30, .pop = 1, .push = 1);
36  def_op(.op_obj = ret->opcodes, .op_name = "SLICE_1", .op_code = 31, .pop = 2, .push = 1);
37  def_op(.op_obj = ret->opcodes, .op_name = "SLICE_2", .op_code = 32, .pop = 2, .push = 1);
38  def_op(.op_obj = ret->opcodes, .op_name = "SLICE_3", .op_code = 33, .pop = 3, .push = 1);
39 
40  store_op(.op_obj = ret->opcodes, .op_name = "STORE_SLICE_0", .op_code = 40, .pop = 2, .push = 0);
41  store_op(.op_obj = ret->opcodes, .op_name = "STORE_SLICE_1", .op_code = 41, .pop = 3, .push = 0);
42  store_op(.op_obj = ret->opcodes, .op_name = "STORE_SLICE_2", .op_code = 42, .pop = 3, .push = 0);
43  store_op(.op_obj = ret->opcodes, .op_name = "STORE_SLICE_3", .op_code = 43, .pop = 4, .push = 0);
44 
45  def_op(.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_0", .op_code = 50, .pop = 1, .push = 0);
46  def_op(.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_1", .op_code = 51, .pop = 2, .push = 0);
47  def_op(.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_2", .op_code = 52, .pop = 2, .push = 0);
48  def_op(.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_3", .op_code = 53, .pop = 3, .push = 0);
49 
50  store_op(.op_obj = ret->opcodes, .op_name = "STORE_SUBSCR", .op_code = 60, .pop = 3, .push = 0); // Implements TOS1[TOS] = TOS2.
51  def_op(.op_obj = ret->opcodes, .op_name = "DELETE_SUBSCR", .op_code = 61, .pop = 2, .push = 0); // Implements del TOS1[TOS].
52 
53  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_LSHIFT", .op_code = 62, .pop = 2, .push = 1);
54  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_RSHIFT", .op_code = 63, .pop = 2, .push = 1);
55  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_AND", .op_code = 64, .pop = 2, .push = 1);
56  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_XOR", .op_code = 65, .pop = 2, .push = 1);
57  def_op(.op_obj = ret->opcodes, .op_name = "BINARY_OR", .op_code = 66, .pop = 2, .push = 1);
58 
59  def_op(.op_obj = ret->opcodes, .op_name = "PRINT_EXPR", .op_code = 70, .pop = 1, .push = 0);
60  def_op(.op_obj = ret->opcodes, .op_name = "PRINT_ITEM", .op_code = 71, .pop = 1, .push = 0);
61  def_op(.op_obj = ret->opcodes, .op_name = "PRINT_NEWLINE", .op_code = 72, .pop = 1, .push = 0);
62 
63  def_op(.op_obj = ret->opcodes, .op_name = "BREAK_LOOP", .op_code = 80, .pop = 0, .push = 0);
64 
65  def_op(.op_obj = ret->opcodes, .op_name = "LOAD_LOCALS", .op_code = 82, .pop = 0, .push = 1);
66  def_op00(.op_obj = ret->opcodes, .op_name = "RETURN_VALUE", .op_code = 83, .pop = 1, .push = 0, .fallthrough = false);
67 
68  def_op(.op_obj = ret->opcodes, .op_name = "EXEC_STMT", .op_code = 85, .pop = 3, .push = 0);
69 
70  def_op(.op_obj = ret->opcodes, .op_name = "POP_BLOCK", .op_code = 87, .pop = 0, .push = 0);
71  def_op(.op_obj = ret->opcodes, .op_name = "END_FINALLY", .op_code = 88, .pop = 1, .push = 0);
72  def_op(.op_obj = ret->opcodes, .op_name = "BUILD_CLASS", .op_code = 89, .pop = 3, .push = 0);
73 
74  ret->have_argument = 90; // Opcodes from here have an argument:
75 
76  store_op00(.op_obj = ret->opcodes, .op_name = "STORE_NAME", .op_code = 90, .pop = 1, .push = 0, .func = NAME_OP); // Operand is in name list
77  name_op(.op_obj = ret->opcodes, .op_name = "DELETE_NAME", .op_code = 91, .pop = 0, .push = 0); // ""
78  varargs_op(.op_obj = ret->opcodes, .op_name = "UNPACK_TUPLE", .op_code = 92); // Number of tuple items
79  def_op(.op_obj = ret->opcodes, .op_name = "UNPACK_LIST", .op_code = 93); // Number of list items
80  store_op00(.op_obj = ret->opcodes, .op_name = "STORE_ATTR", .op_code = 95, .pop = 2, .push = 0, .func = NAME_OP); // Operand is in name list
81  name_op(.op_obj = ret->opcodes, .op_name = "DELETE_ATTR", .op_code = 96, .pop = 1, .push = 0); // ""
82  store_op00(.op_obj = ret->opcodes, .op_name = "STORE_GLOBAL", .op_code = 97, .pop = 1, .push = 0, .func = NAME_OP); // ""
83  name_op(.op_obj = ret->opcodes, .op_name = "DELETE_GLOBAL", .op_code = 98, .pop = 0, .push = 0); // ""
84 
85  const_op00(.op_obj = ret->opcodes, .op_name = "LOAD_CONST", .op_code = 100, .pop = 0, .push = 1); // Operand is in const list
86  name_op(.op_obj = ret->opcodes, .op_name = "LOAD_NAME", .op_code = 101, .pop = 0, .push = 1); // Operand is in name list
87  varargs_op(.op_obj = ret->opcodes, .op_name = "BUILD_TUPLE", .op_code = 102, .pop = -1, .push = 1); // Number of tuple items
88  varargs_op(.op_obj = ret->opcodes, .op_name = "BUILD_LIST", .op_code = 103, .pop = -1, .push = 1); // Number of list items
89  varargs_op(.op_obj = ret->opcodes, .op_name = "BUILD_MAP", .op_code = 104, .pop = -1, .push = 1); // Always zero for now
90  name_op(.op_obj = ret->opcodes, .op_name = "LOAD_ATTR", .op_code = 105, .pop = 1, .push = 1); // Operand is in name list
91  compare_op(.op_obj = ret->opcodes, .op_name = "COMPARE_OP", .op_code = 106, .pop = 2, .push = 1); // Comparison operator
92 
93  name_op(.op_obj = ret->opcodes, .op_name = "IMPORT_NAME", .op_code = 107, .pop = 2, .push = 1); // Operand is in name list
94  name_op(.op_obj = ret->opcodes, .op_name = "IMPORT_FROM", .op_code = 108, .pop = 0, .push = 1); // Operand is in name list
95 
96  jrel_op(.op_obj = ret->opcodes, .op_name = "JUMP_FORWARD", .op_code = 110, .pop = 0, .push = 0); // Number of bytes to skip
97  jrel_op(.op_obj = ret->opcodes, .op_name = "JUMP_IF_FALSE", .op_code = 111, .pop = 1, .push = 1, .conditional = true); // ""
98  jrel_op(.op_obj = ret->opcodes, .op_name = "JUMP_IF_TRUE", .op_code = 112, .pop = 1, .push = 1, .conditional = true); // ""
99  jabs_op(.op_obj = ret->opcodes, .op_name = "JUMP_ABSOLUTE", .op_code = 113, .pop = 0, .push = 0); // Target byte offset from beginning of code
100  def_op(.op_obj = ret->opcodes, .op_name = "FOR_LOOP", .op_code = 114); // Number of bytes to skip
101 
102  name_op(.op_obj = ret->opcodes, .op_name = "LOAD_GLOBAL", .op_code = 116, .pop = 0, .push = 1); // Operand is in name list
103 
104  jrel_op(.op_obj = ret->opcodes, .op_name = "SETUP_LOOP", .op_code = 120, .pop = 0, .push = 0, .conditional = true); // Distance to target address
105  jrel_op(.op_obj = ret->opcodes, .op_name = "SETUP_EXCEPT", .op_code = 121, .pop = 0, .push = 0, .conditional = true); // ""
106  jrel_op(.op_obj = ret->opcodes, .op_name = "SETUP_FINALLY", .op_code = 122, .pop = 0, .push = 0, .conditional = true); // ""
107 
108  local_op(.op_obj = ret->opcodes, .op_name = "LOAD_FAST", .op_code = 124, .pop = 0, .push = 1); // Local variable number
109  store_op00(.op_obj = ret->opcodes, .op_name = "STORE_FAST", .op_code = 125, .pop = 1, .push = 0, .func = LOCAL_OP); // Local variable number
110  local_op0(.op_obj = ret->opcodes, .op_name = "DELETE_FAST", .op_code = 126); // Local variable number
111 
112  def_op(.op_obj = ret->opcodes, .op_name = "SET_LINENO", .op_code = 127); // Current line number
113 
114  def_op00(.op_obj = ret->opcodes, .op_name = "RAISE_VARARGS", .op_code = 130, .pop = -1, .push = 0, .fallthrough = false);
115  // Number of raise arguments (1, 2, or 3)
116  nargs_op(.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION", .op_code = 131, .pop = -1, .push = 1); // //args + (//kwargs << 8)
117 
118  def_op(.op_obj = ret->opcodes, .op_name = "MAKE_FUNCTION", .op_code = 132, .pop = -1, .push = 1); // Number of args with default values
119  varargs_op(.op_obj = ret->opcodes, .op_name = "BUILD_SLICE", .op_code = 133, .pop = -1, .push = 1); // Number of items
120 
121  def_op(.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", .op_code = 143);
122  ret->extended_arg = 143;
123 
125  add_arg_fmt(ret, "EXTENDED_ARG", format_extended_arg);
126 
127  return ret;
128 }
#define NULL
Definition: cris-opc.c:27
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition: list.c:120
pyc_opcodes * new_pyc_opcodes()
Definition: opcode.c:185
void() def_opN(struct op_parameter par)
Definition: opcode.c:244
void add_arg_fmt(pyc_opcodes *ret, char *op_name, const char *(*formatter)(ut32 oparg))
Definition: opcode.c:234
pyc_opcodes * opcode_15(void)
Definition: opcode_15.c:6
#define nargs_op(...)
Definition: opcode.h:171
#define store_op(...)
Definition: opcode.h:145
const char * format_extended_arg(ut32 oparg)
Definition: opcode_arg_fmt.c:6
#define jabs_op(...)
Definition: opcode.h:163
#define local_op(...)
Definition: opcode.h:137
#define const_op00(...)
Definition: opcode.h:154
#define def_op00(...)
Definition: opcode.h:129
#define local_op0(...)
Definition: opcode.h:136
#define varargs_op(...)
Definition: opcode.h:149
#define compare_op(...)
Definition: opcode.h:158
#define store_op00(...)
Definition: opcode.h:144
#define jrel_op(...)
Definition: opcode.h:168
#define def_op(...)
Definition: opcode.h:127
@ LOCAL_OP
Definition: opcode.h:32
@ NAME_OP
Definition: opcode.h:31
#define name_op(...)
Definition: opcode.h:133
char * op_name
Definition: opcode.h:38
ut8 have_argument
Definition: opcode.h:47
void *(* version_sig)()
Definition: opcode.h:49
pyc_opcode_object * opcodes
Definition: opcode.h:51
ut8 extended_arg
Definition: opcode.h:46
RzList * opcode_arg_fmt
Definition: opcode.h:50