Rizin
unix-like reverse engineering framework and cli tools
lua_arch.c File Reference
#include "lua_arch.h"

Go to the source code of this file.

Functions

LuaInstruction lua_build_instruction (const ut8 *buf)
 
void lua_set_instruction (LuaInstruction instruction, ut8 *data)
 
bool free_lua_opnames (LuaOpNameList list)
 
char * luaop_new_str_3arg (char *opname, int a, int b, int c)
 
char * luaop_new_str_2arg (char *opname, int a, int b)
 
char * luaop_new_str_1arg (char *opname, int a)
 
char * luaop_new_str_3arg_ex (char *opname, int a, int b, int c, int isk)
 
char * luaop_new_str_2arg_ex (char *opname, int a, int b, int isk)
 
char * luaop_new_str_1arg_ex (char *opname, int a, int isk)
 
int lua_load_next_arg_start (const char *raw_string, char *recv_buf)
 
bool lua_is_valid_num_value_string (const char *str)
 
int lua_convert_str_to_num (const char *str)
 

Function Documentation

◆ free_lua_opnames()

bool free_lua_opnames ( LuaOpNameList  list)

Definition at line 22 of file lua_arch.c.

22  {
23  if (list != NULL) {
24  RZ_FREE(list);
25  return true;
26  }
27  return false;
28 }
#define NULL
Definition: cris-opc.c:27
static void list(RzEgg *egg)
Definition: rz-gg.c:52
#define RZ_FREE(x)
Definition: rz_types.h:369

References list(), NULL, and RZ_FREE.

Referenced by rz_luac_disasm().

◆ lua_build_instruction()

LuaInstruction lua_build_instruction ( const ut8 buf)

Definition at line 6 of file lua_arch.c.

6  {
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 }
voidpf void * buf
Definition: ioapi.h:138
ut32 LuaInstruction
Definition: lua_arch.h:27

Referenced by lua53_anal_op(), lua53_disasm(), lua54_anal_op(), and lua54_disasm().

◆ lua_convert_str_to_num()

int lua_convert_str_to_num ( const char *  str)

Definition at line 137 of file lua_arch.c.

137  {
138  return strtoll(str, NULL, 0);
139 }

References NULL, and cmd_descs_generate::str.

Referenced by encode_instruction().

◆ lua_is_valid_num_value_string()

bool lua_is_valid_num_value_string ( const char *  str)

Definition at line 129 of file lua_arch.c.

129  {
131  RZ_LOG_ERROR("assembler: lua: %s is not a valid number argument\n", str);
132  return false;
133  }
134  return true;
135 }
#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

References NULL, rz_is_valid_input_num_value(), RZ_LOG_ERROR, and cmd_descs_generate::str.

Referenced by encode_instruction().

◆ lua_load_next_arg_start()

int lua_load_next_arg_start ( const char *  raw_string,
char *  recv_buf 
)

Definition at line 98 of file lua_arch.c.

98  {
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 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86

References memcpy(), NULL, and rz_str_trim_head_ro().

Referenced by encode_instruction().

◆ lua_set_instruction()

void lua_set_instruction ( LuaInstruction  instruction,
ut8 data 
)

Definition at line 15 of file lua_arch.c.

15  {
16  data[3] = instruction >> 24;
17  data[2] = instruction >> 16;
18  data[1] = instruction >> 8;
19  data[0] = instruction >> 0;
20 }

Referenced by rz_luac_asm().

◆ luaop_new_str_1arg()

char* luaop_new_str_1arg ( char *  opname,
int  a 
)

Definition at line 53 of file lua_arch.c.

53  {
54  char *asm_string;
55 
56  asm_string = rz_str_newf(
57  "%s %d",
58  opname,
59  a);
60 
61  return asm_string;
62 }
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define a(i)
Definition: sha256.c:41

References a, and rz_str_newf().

Referenced by lua53_disasm(), and lua54_disasm().

◆ luaop_new_str_1arg_ex()

char* luaop_new_str_1arg_ex ( char *  opname,
int  a,
int  isk 
)

Definition at line 87 of file lua_arch.c.

87  {
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 }

References a, and rz_str_newf().

Referenced by lua54_disasm().

◆ luaop_new_str_2arg()

char* luaop_new_str_2arg ( char *  opname,
int  a,
int  b 
)

Definition at line 42 of file lua_arch.c.

42  {
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 }
#define b(i)
Definition: sha256.c:42

References a, b, and rz_str_newf().

Referenced by lua53_disasm(), and lua54_disasm().

◆ luaop_new_str_2arg_ex()

char* luaop_new_str_2arg_ex ( char *  opname,
int  a,
int  b,
int  isk 
)

Definition at line 76 of file lua_arch.c.

76  {
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 }

References a, b, and rz_str_newf().

Referenced by lua54_disasm().

◆ luaop_new_str_3arg()

char* luaop_new_str_3arg ( char *  opname,
int  a,
int  b,
int  c 
)

Definition at line 31 of file lua_arch.c.

31  {
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 }
#define c(i)
Definition: sha256.c:43

References a, b, c, and rz_str_newf().

Referenced by lua53_disasm(), and lua54_disasm().

◆ luaop_new_str_3arg_ex()

char* luaop_new_str_3arg_ex ( char *  opname,
int  a,
int  b,
int  c,
int  isk 
)

Definition at line 65 of file lua_arch.c.

65  {
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 }

References a, b, c, and rz_str_newf().

Referenced by lua54_disasm().