Rizin
unix-like reverse engineering framework and cli tools
asm_sh.c File Reference
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "../arch/sh/disassembler.h"
#include "../arch/sh/assembler.h"

Go to the source code of this file.

Functions

static int disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
 
static int assemble (RzAsm *a, RzAsmOp *ao, const char *str)
 

Variables

RzAsmPlugin rz_asm_plugin_sh
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ assemble()

static int assemble ( RzAsm a,
RzAsmOp ao,
const char *  str 
)
static

Definition at line 25 of file asm_sh.c.

25  {
26  bool success;
27  ut16 opcode = sh_assembler(str, a->pc, &success);
28  if (!success) {
29  return -1;
30  }
31 
32  ut8 buffer[2];
33  rz_write_ble16(buffer, opcode, a->big_endian);
34  rz_strbuf_setbin(&ao->buf, buffer, 2);
35  return 2;
36 }
uint16_t ut16
uint8_t ut8
Definition: lh5801.h:11
static void rz_write_ble16(void *dest, ut16 val, bool big_endian)
Definition: rz_endian.h:532
RZ_API bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t len)
Definition: strbuf.c:85
RZ_IPI ut16 sh_assembler(RZ_NONNULL const char *buffer, ut64 pc, RZ_NULLABLE bool *success)
Assemble instruction from SuperH-4 ISA FPU instructions not implemented yet.
Definition: assembler.c:402
#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, rz_strbuf_setbin(), rz_write_ble16(), sh_assembler(), and cmd_descs_generate::str.

◆ disassemble()

static int disassemble ( RzAsm a,
RzAsmOp op,
const ut8 buf,
int  len 
)
static

Definition at line 11 of file asm_sh.c.

11  {
12  SHOp *dis_op = sh_disassembler(rz_read_ble16(buf, a->big_endian));
13  op->size = 2;
14  if (!dis_op) {
15  rz_strbuf_set(&op->buf_asm, "invalid");
16  } else {
17  char *disasm = sh_op_to_str(dis_op, a->pc);
18  rz_strbuf_set(&op->buf_asm, disasm);
19  free(disasm);
20  }
21  RZ_FREE(dis_op);
22  return op->size;
23 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
static ut16 rz_read_ble16(const void *src, bool big_endian)
Definition: rz_endian.h:493
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
#define RZ_FREE(x)
Definition: rz_types.h:369
RZ_IPI RZ_OWN SHOp * sh_disassembler(ut16 opcode)
Disassemble opcode and return a SHOp.
Definition: disassembler.c:130
RZ_IPI RZ_OWN char * sh_op_to_str(RZ_NONNULL const SHOp *op, ut64 pc)
Return string representation of disassembled op.
Definition: disassembler.c:224
Definition: dis.c:32

References a, free(), RZ_FREE, rz_read_ble16(), rz_strbuf_set(), sh_disassembler(), and sh_op_to_str().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
.data = &rz_asm_plugin_sh,
}
RzAsmPlugin rz_asm_plugin_sh
Definition: asm_sh.c:38
@ 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 51 of file asm_sh.c.

◆ rz_asm_plugin_sh

RzAsmPlugin rz_asm_plugin_sh
Initial value:
= {
.name = "sh",
.arch = "sh",
.author = "DMaroo",
.license = "LGPL3",
.bits = 32,
.desc = "SuperH-4 CPU",
.disassemble = &disassemble,
.assemble = &assemble
}
static int assemble(RzAsm *a, RzAsmOp *ao, const char *str)
Definition: asm_sh.c:25
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_sh.c:11
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526

Definition at line 38 of file asm_sh.c.