@@ -9,23 +9,20 @@ static LuaInstruction encode_instruction(ut8 opcode, const char *arg_start, ut16
99 int args [4 ];
1010 char buffer [64 ]; // buffer for digits
1111 int cur_cnt = 0 ;
12- int delta_offset ;
13-
14- if (arg_num > sizeof (args )) {
15- return -1 ;
16- }
1712
1813 for (int i = 0 ; i < arg_num ; ++ i ) {
19- delta_offset = lua_load_next_arg_start (arg_start , buffer );
20- if (delta_offset == 0 ) {
21- return -1 ;
22- }
23- if (lua_is_valid_num_value_string (buffer )) {
14+ const int delta_offset = lua_load_next_arg_start (arg_start , buffer );
15+ char * ptr = strchr (buffer , 'k' );
16+ if (ptr != NULL ) {
17+ * ptr = '\0' ;
2418 args [i ] = lua_convert_str_to_num (buffer );
25- arg_start += delta_offset ;
26- } else {
27- return -1 ;
19+ args [arg_num ] = 1 ;
20+ arg_num ++ ;
21+ flag |= PARAM_k ;
22+ break ;
2823 }
24+ args [i ] = lua_convert_str_to_num (buffer );
25+ arg_start += delta_offset ;
2926 }
3027
3128 LUA_SET_OPCODE (instruction , opcode );
@@ -95,27 +92,20 @@ static LuaInstruction encode_instruction(ut8 opcode, const char *arg_start, ut16
9592}
9693
9794bool lua55_assembly (const char * input , st32 input_size , LuaInstruction * instruction_p ) {
98- const char * opcode_start ; // point to the header
99- const char * opcode_end ; // point to the first white space
100- int opcode_len ;
101-
102- const char * arg_start ;
103-
104- ut8 opcode ;
105- LuaInstruction instruction = 0x00 ;
106-
10795 /* Find the opcode */
108- opcode_start = input ;
109- opcode_end = strchr (input , ' ' );
96+ const char * opcode_start = input ; ///< point to the header
97+ const char * opcode_end = strchr (input , ' ' ); ///< point to the first white space
11098 if (opcode_end == NULL ) {
11199 opcode_end = input + input_size ;
112100 }
113101
114- opcode_len = opcode_end - opcode_start ;
115- opcode = get_lua54_opcode_by_name (opcode_start , opcode_len );
102+ const int opcode_len = opcode_end - opcode_start ;
103+ const ut8 opcode = get_lua55_opcode_by_name (opcode_start , opcode_len );
116104
117105 /* Find the arguments */
118- arg_start = rz_str_trim_head_ro (opcode_end );
106+ const char * arg_start = rz_str_trim_head_ro (opcode_end );
107+
108+ LuaInstruction instruction = 0x00 ;
119109
120110 /* Encode opcode and args */
121111 switch (opcode ) {
@@ -152,14 +142,18 @@ bool lua55_assembly(const char *input, st32 input_size, LuaInstruction *instruct
152142 // iABC k instruction
153143 case OP_TAILCALL :
154144 case OP_RETURN :
155- case OP_NEWTABLE :
156- case OP_SETLIST :
157- case OP_MMBINK :
158145 case OP_SETTABUP :
159146 case OP_SETTABLE :
160147 case OP_SETI :
161148 case OP_SETFIELD :
162149 case OP_SELF :
150+ instruction = encode_instruction (opcode , arg_start ,
151+ PARAM_A | PARAM_B | PARAM_C ,
152+ 3 );
153+ break ;
154+ case OP_NEWTABLE :
155+ case OP_SETLIST :
156+ case OP_MMBINK :
163157 instruction = encode_instruction (opcode , arg_start ,
164158 PARAM_A | PARAM_B | PARAM_C | PARAM_k ,
165159 4 );
@@ -235,8 +229,8 @@ bool lua55_assembly(const char *input, st32 input_size, LuaInstruction *instruct
235229 // A with k
236230 case OP_TEST :
237231 instruction = encode_instruction (opcode , arg_start ,
238- PARAM_A | PARAM_k ,
239- 2 );
232+ PARAM_A ,
233+ 1 );
240234 break ;
241235 // no arg
242236 case OP_RETURN0 :
0 commit comments