Rizin
unix-like reverse engineering framework and cli tools
lua_arch.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-only
2 // SPDX-FileCopyrightText: 2021 Heersin <teablearcher@gmail.com>
3 
4 #include "lua_arch.h"
5 
7  LuaInstruction ret = 0;
8  ret |= buf[3] << 24;
9  ret |= buf[2] << 16;
10  ret |= buf[1] << 8;
11  ret |= buf[0];
12  return ret;
13 }
14 
16  data[3] = instruction >> 24;
17  data[2] = instruction >> 16;
18  data[1] = instruction >> 8;
19  data[0] = instruction >> 0;
20 }
21 
23  if (list != NULL) {
24  RZ_FREE(list);
25  return true;
26  }
27  return false;
28 }
29 
30 /* formatted strings for asm_buf */
31 char *luaop_new_str_3arg(char *opname, int a, int b, int c) {
32  char *asm_string;
33 
34  asm_string = rz_str_newf(
35  "%s %d %d %d",
36  opname,
37  a, b, c);
38 
39  return asm_string;
40 }
41 
42 char *luaop_new_str_2arg(char *opname, int a, int b) {
43  char *asm_string;
44 
45  asm_string = rz_str_newf(
46  "%s %d %d",
47  opname,
48  a, b);
49 
50  return asm_string;
51 }
52 
53 char *luaop_new_str_1arg(char *opname, int a) {
54  char *asm_string;
55 
56  asm_string = rz_str_newf(
57  "%s %d",
58  opname,
59  a);
60 
61  return asm_string;
62 }
63 
64 /* For the k flag */
65 char *luaop_new_str_3arg_ex(char *opname, int a, int b, int c, int isk) {
66  char *asm_string;
67 
68  asm_string = rz_str_newf(
69  "%s %d %d %d %d",
70  opname,
71  a, b, c, isk);
72 
73  return asm_string;
74 }
75 
76 char *luaop_new_str_2arg_ex(char *opname, int a, int b, int isk) {
77  char *asm_string;
78 
79  asm_string = rz_str_newf(
80  "%s %d %d %d",
81  opname,
82  a, b, isk);
83 
84  return asm_string;
85 }
86 
87 char *luaop_new_str_1arg_ex(char *opname, int a, int isk) {
88  char *asm_string;
89 
90  asm_string = rz_str_newf(
91  "%s %d %d",
92  opname,
93  a, isk);
94 
95  return asm_string;
96 }
97 
98 int lua_load_next_arg_start(const char *raw_string, char *recv_buf) {
99  if (!raw_string) {
100  return 0;
101  }
102 
103  const char *arg_start = NULL;
104  const char *arg_end = NULL;
105  int arg_len = 0;
106 
107  /* locate the start point */
108  arg_start = rz_str_trim_head_ro(raw_string);
109  if (strlen(arg_start) == 0) {
110  return 0;
111  }
112 
113  arg_end = strchr(arg_start, ' ');
114  if (arg_end == NULL) {
115  /* is last arg */
116  arg_len = strlen(arg_start);
117  } else {
118  arg_len = arg_end - arg_start;
119  }
120 
121  /* Set NUL */
122  memcpy(recv_buf, arg_start, arg_len);
123  recv_buf[arg_len] = 0x00;
124 
125  /* Calculate offset */
126  return arg_start - raw_string + arg_len;
127 }
128 
131  RZ_LOG_ERROR("assembler: lua: %s is not a valid number argument\n", str);
132  return false;
133  }
134  return true;
135 }
136 
137 int lua_convert_str_to_num(const char *str) {
138  return strtoll(str, NULL, 0);
139 }
#define NULL
Definition: cris-opc.c:27
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void list(RzEgg *egg)
Definition: rz-gg.c:52
char * luaop_new_str_2arg(char *opname, int a, int b)
Definition: lua_arch.c:42
bool lua_is_valid_num_value_string(const char *str)
Definition: lua_arch.c:129
char * luaop_new_str_2arg_ex(char *opname, int a, int b, int isk)
Definition: lua_arch.c:76
char * luaop_new_str_3arg(char *opname, int a, int b, int c)
Definition: lua_arch.c:31
int lua_load_next_arg_start(const char *raw_string, char *recv_buf)
Definition: lua_arch.c:98
char * luaop_new_str_3arg_ex(char *opname, int a, int b, int c, int isk)
Definition: lua_arch.c:65
bool free_lua_opnames(LuaOpNameList list)
Definition: lua_arch.c:22
LuaInstruction lua_build_instruction(const ut8 *buf)
Definition: lua_arch.c:6
int lua_convert_str_to_num(const char *str)
Definition: lua_arch.c:137
char * luaop_new_str_1arg(char *opname, int a)
Definition: lua_arch.c:53
void lua_set_instruction(LuaInstruction instruction, ut8 *data)
Definition: lua_arch.c:15
char * luaop_new_str_1arg_ex(char *opname, int a, int isk)
Definition: lua_arch.c:87
ut32 LuaInstruction
Definition: lua_arch.h:27
char ** LuaOpNameList
Definition: lua_arch.h:30
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API bool rz_is_valid_input_num_value(RzNum *num, const char *input_value)
Definition: unum.c:735
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86
#define RZ_FREE(x)
Definition: rz_types.h:369
#define b(i)
Definition: sha256.c:42
#define c(i)
Definition: sha256.c:43
#define a(i)
Definition: sha256.c:41