Rizin
unix-like reverse engineering framework and cli tools
asm_luac.c File Reference

Go to the source code of this file.

Functions

int rz_luac_disasm (RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len)
 
int rz_luac_asm (RzAsm *a, RzAsmOp *opstruct, const char *str)
 

Variables

RzAsmPlugin rz_asm_plugin_luac
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ rz_luac_asm()

int rz_luac_asm ( RzAsm a,
RzAsmOp opstruct,
const char *  str 
)

Definition at line 31 of file asm_luac.c.

31  {
32  int str_len = strlen(str);
33  ut32 instruction = 0;
34  ut8 buffer[4];
35 
36  if (!a->cpu) {
37  RZ_LOG_ERROR("assembler: lua: no version info, specify it with `asm.cpu` option\n");
38  return -1;
39  }
40 
41  if (strcmp(a->cpu, "5.3") == 0) {
42  if (!lua53_assembly(str, str_len, &instruction)) {
43  return -1;
44  }
45  } else if (strcmp(a->cpu, "5.4") == 0) {
46  if (!lua54_assembly(str, str_len, &instruction)) {
47  return -1;
48  }
49  } else {
50  RZ_LOG_ERROR("assembler: lua: version %s is not supported\n", a->cpu);
51  return -1;
52  }
53 
55  rz_strbuf_setbin(&opstruct->buf, (const ut8 *)&buffer, 4);
56  return 4;
57 }
uint32_t ut32
uint8_t ut8
Definition: lh5801.h:11
void lua_set_instruction(LuaInstruction instruction, ut8 *data)
Definition: lua_arch.c:15
bool lua54_assembly(const char *input, st32 input_size, LuaInstruction *instruction)
Definition: assembly_54.c:96
bool lua53_assembly(const char *input, st32 input_size, LuaInstruction *instruction)
Definition: assembly_53.c:60
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t len)
Definition: strbuf.c:85
#define a(i)
Definition: sha256.c:41
Definition: buffer.h:15
RzStrBuf buf
Definition: rz_asm.h:71

References a, rz_asm_op_t::buf, lua53_assembly(), lua54_assembly(), lua_set_instruction(), RZ_LOG_ERROR, rz_strbuf_setbin(), and cmd_descs_generate::str.

◆ rz_luac_disasm()

int rz_luac_disasm ( RzAsm a,
RzAsmOp opstruct,
const ut8 buf,
int  len 
)

Definition at line 6 of file asm_luac.c.

6  {
7  LuaOpNameList oplist = NULL;
8  int r = 0;
9 
10  if (!a->cpu) {
11  RZ_LOG_ERROR("disassembler: lua: no version info, specify it with `asm.cpu` option\n");
12  return -1;
13  }
14 
15  if (strcmp(a->cpu, "5.4") == 0) {
16  oplist = get_lua54_opnames();
17  r = lua54_disasm(opstruct, buf, len, oplist);
18  } else if (strcmp(a->cpu, "5.3") == 0) {
19  oplist = get_lua53_opnames();
20  r = lua53_disasm(opstruct, buf, len, oplist);
21  } else {
22  RZ_LOG_ERROR("disassembler: lua: version %s is not supported\n", a->cpu);
23  return -1;
24  }
25 
26  free_lua_opnames(oplist);
27  opstruct->size = r;
28  return r;
29 }
size_t len
Definition: 6502dis.c:15
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
voidpf void * buf
Definition: ioapi.h:138
bool free_lua_opnames(LuaOpNameList list)
Definition: lua_arch.c:22
char ** LuaOpNameList
Definition: lua_arch.h:30
LuaOpNameList get_lua54_opnames(void)
Definition: opcode_54.c:9
int lua54_disasm(RzAsmOp *op, const ut8 *buf, int len, LuaOpNameList oplist)
Definition: disassembly_54.c:6
LuaOpNameList get_lua53_opnames(void)
Definition: opcode_53.c:10
int lua53_disasm(RzAsmOp *op, const ut8 *buf, int len, LuaOpNameList oplist)
Definition: disassembly_53.c:7
int size
Definition: rz_asm.h:67

References a, free_lua_opnames(), get_lua53_opnames(), get_lua54_opnames(), len, lua53_disasm(), lua54_disasm(), NULL, r, RZ_LOG_ERROR, and rz_asm_op_t::size.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_luac
Definition: asm_luac.c:59
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_asm.h:133

Definition at line 70 of file asm_luac.c.

◆ rz_asm_plugin_luac

RzAsmPlugin rz_asm_plugin_luac
Initial value:
= {
.name = "luac",
.arch = "luac",
.license = "LGPL3",
.bits = 8,
.desc = "luac disassemble plugin",
.disassemble = &rz_luac_disasm,
.assemble = &rz_luac_asm,
}
int rz_luac_asm(RzAsm *a, RzAsmOp *opstruct, const char *str)
Definition: asm_luac.c:31
int rz_luac_disasm(RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len)
Definition: asm_luac.c:6

Definition at line 59 of file asm_luac.c.