Rizin
unix-like reverse engineering framework and cli tools
asm_luac.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 
5 
6 int rz_luac_disasm(RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len) {
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 }
30 
31 int rz_luac_asm(RzAsm *a, RzAsmOp *opstruct, const char *str) {
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 }
58 
60  .name = "luac",
61  .arch = "luac",
62  .license = "LGPL3",
63  .bits = 8,
64  .desc = "luac disassemble plugin",
65  .disassemble = &rz_luac_disasm,
66  .assemble = &rz_luac_asm,
67 };
68 
69 #ifndef RZ_PLUGIN_INCORE
72  .data = rz_asm_plugin_luac,
74 };
75 #endif
size_t len
Definition: 6502dis.c:15
RzAsmPlugin rz_asm_plugin_luac
Definition: asm_luac.c:59
int rz_luac_asm(RzAsm *a, RzAsmOp *opstruct, const char *str)
Definition: asm_luac.c:31
RZ_API RzLibStruct rizin_plugin
Definition: asm_luac.c:70
int rz_luac_disasm(RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len)
Definition: asm_luac.c:6
#define RZ_API
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
bool free_lua_opnames(LuaOpNameList list)
Definition: lua_arch.c:22
void lua_set_instruction(LuaInstruction instruction, ut8 *data)
Definition: lua_arch.c:15
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
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
int lua53_disasm(RzAsmOp *op, const ut8 *buf, int len, LuaOpNameList oplist)
Definition: disassembly_53.c:7
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#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 RZ_VERSION
Definition: rz_version.h:8
#define a(i)
Definition: sha256.c:41
Definition: buffer.h:15
RzStrBuf buf
Definition: rz_asm.h:71
int size
Definition: rz_asm.h:67
const char * name
Definition: rz_asm.h:130
const char * version
Definition: rz_asm.h:133