Rizin
unix-like reverse engineering framework and cli tools
asm_dcpu16.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2012-2018 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include <string.h>
7 #include <rz_types.h>
8 #include <rz_util.h>
9 #include <rz_lib.h>
10 #include <rz_asm.h>
11 #include "../arch/dcpu16/dcpu16.h"
12 #include "../arch/dcpu16/dis.c"
13 #include "../arch/dcpu16/asm.c"
14 
15 static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
16  char buf_asm[96];
17  if (len < 2) {
18  return -1; // at least 2 bytes!
19  }
20  op->size = dcpu16_disasm(buf_asm, sizeof(buf_asm), (const ut16 *)buf, len, NULL);
21  rz_strbuf_set(&op->buf_asm, (op->size > 0) ? buf_asm : "(data)");
22  return op->size;
23 }
24 
25 static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
26  int len = dcpu16_assemble((ut8 *)rz_strbuf_get(&op->buf), buf);
27  op->buf.len = len;
28  return len;
29 }
30 
32  .name = "dcpu16",
33  .arch = "dpcu",
34  .bits = 16,
35  .endian = RZ_SYS_ENDIAN_LITTLE,
36  .desc = "Mojang's DCPU-16",
37  .license = "PD",
38  .disassemble = &disassemble,
39  .assemble = &assemble
40 };
41 
42 #ifndef RZ_PLUGIN_INCORE
45  .data = &rz_asm_plugin_dcpu16,
47 };
48 #endif
size_t len
Definition: 6502dis.c:15
int dcpu16_assemble(ut8 *out, const char *unoline)
Definition: asm.c:216
RzAsmPlugin rz_asm_plugin_dcpu16
Definition: asm_dcpu16.c:31
RZ_API RzLibStruct rizin_plugin
Definition: asm_dcpu16.c:43
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_dcpu16.c:15
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf)
Definition: asm_dcpu16.c:25
#define RZ_API
#define NULL
Definition: cris-opc.c:27
int dcpu16_disasm(char *out, size_t size_out, const ut16 *inp, int len, int *cost)
Definition: dis.c:130
uint16_t ut16
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526
#define RZ_VERSION
Definition: rz_version.h:8
#define a(i)
Definition: sha256.c:41
const char * name
Definition: rz_asm.h:130
const char * version
Definition: rz_asm.h:133
Definition: dis.c:32