Rizin
unix-like reverse engineering framework and cli tools
asm_avr.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include <string.h>
7 
8 #include <rz_types.h>
9 #include <rz_util.h>
10 #include <rz_lib.h>
11 #include <rz_asm.h>
12 
13 #include "../arch/avr/assembler.h"
14 #include "../arch/avr/disassembler.h"
15 
16 static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
17  AVROp aop = { 0 };
18  op->size = avr_disassembler(buf, len, a->pc, a->big_endian, &aop, &op->buf_asm);
19  if (!op->size) {
20  op->size = 2;
21  rz_strbuf_set(&op->buf_asm, "invalid");
22  }
23  return op->size;
24 }
25 
26 static int assemble(RzAsm *a, RzAsmOp *ao, const char *str) {
27  st32 slen = strlen(str);
28 
29  ut8 buffer[16];
30  ut32 written = avr_assembler(str, slen, buffer, sizeof(buffer), a->pc, a->big_endian);
31 
32  if (written < 1) {
33  return -1;
34  }
35 
36  rz_strbuf_setbin(&ao->buf, (const ut8 *)&buffer, written);
37  return (int)written;
38 }
39 
41  .name = "avr",
42  .arch = "avr",
43  .license = "LGPL3",
44  .bits = 8 | 16,
46  .desc = "AVR Atmel",
47  .disassemble = &disassemble,
48  .assemble = &assemble,
49  .cpus =
50  "ATmega8,"
51  "ATmega1280,"
52  "ATmega1281,"
53  "ATmega16,"
54  "ATmega168,"
55  "ATmega2560,"
56  "ATmega2561,"
57  "ATmega328p,"
58  "ATmega32u4,"
59  "ATmega48,"
60  "ATmega640,"
61  "ATmega88,"
62  "ATxmega128a4u,"
63  "ATTiny48,"
64  "ATTiny88,"
65 };
66 
67 #ifndef RZ_PLUGIN_INCORE
70  .data = &rz_asm_plugin_avr,
72 };
73 #endif
size_t len
Definition: 6502dis.c:15
static int assemble(RzAsm *a, RzAsmOp *ao, const char *str)
Definition: asm_avr.c:26
RZ_API RzLibStruct rizin_plugin
Definition: asm_avr.c:68
RzAsmPlugin rz_asm_plugin_avr
Definition: asm_avr.c:40
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_avr.c:16
ut32 avr_assembler(const char *input, st32 input_size, ut8 *output, st32 output_size, ut64 pc, bool be)
Definition: assembler.c:1084
ut32 avr_disassembler(const ut8 *buffer, const ut32 size, ut64 pc, bool be, AVROp *aop, RzStrBuf *sb)
Definition: disassembler.c:773
#define RZ_API
uint32_t ut32
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 bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t len)
Definition: strbuf.c:85
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526
#define st32
Definition: rz_types_base.h:12
#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
const char * name
Definition: rz_asm.h:130
const char * version
Definition: rz_asm.h:133
Definition: dis.c:32