Rizin
unix-like reverse engineering framework and cli tools
asm_sparc_gnu.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "disas-asm.h"
#include <mybfd.h>

Go to the source code of this file.

Functions

static int sparc_buffer_read_memory (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info)
 
static int symbol_at_address (bfd_vma addr, struct disassemble_info *info)
 
static void memory_error_func (int status, bfd_vma memaddr, struct disassemble_info *info)
 
static int disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
 

Variables

static unsigned long Offset = 0
 
static RzStrBufbuf_global = NULL
 
static unsigned char bytes [4]
 
RzAsmPlugin rz_asm_plugin_sparc_gnu
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ disassemble()

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

Definition at line 41 of file asm_sparc_gnu.c.

41  {
42  static struct disassemble_info disasm_obj;
43  if (len < 4) {
44  return -1;
45  }
46  buf_global = &op->buf_asm;
47  Offset = a->pc;
48  // disasm inverted
49  rz_mem_swapendian(bytes, buf, 4); // TODO handle thumb
50 
51  rz_strbuf_set(&op->buf_asm, "");
52  /* prepare disassembler */
53  memset(&disasm_obj, '\0', sizeof(struct disassemble_info));
54  disasm_obj.buffer = bytes;
55  disasm_obj.read_memory_func = &sparc_buffer_read_memory;
56  disasm_obj.symbol_at_address_func = &symbol_at_address;
57  disasm_obj.memory_error_func = &memory_error_func;
58  disasm_obj.print_address_func = &generic_print_address_func;
59  disasm_obj.endian = a->big_endian;
60  disasm_obj.fprintf_func = &generic_fprintf_func;
61  disasm_obj.stream = stdout;
62  disasm_obj.mach = ((a->bits == 64)
64  : 0);
65 
66  op->size = print_insn_sparc((bfd_vma)Offset, &disasm_obj);
67 
68  if (!strncmp(rz_strbuf_get(&op->buf_asm), "unknown", 7)) {
69  rz_asm_op_set_asm(op, "invalid");
70  }
71  if (op->size == -1) {
72  rz_asm_op_set_asm(op, "(data)");
73  }
74  return op->size;
75 }
size_t len
Definition: 6502dis.c:15
RZ_API void rz_asm_op_set_asm(RzAsmOp *op, const char *str)
Definition: aop.c:53
static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_info *info)
Definition: asm_sparc_gnu.c:34
static int sparc_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info)
Definition: asm_sparc_gnu.c:18
static unsigned long Offset
Definition: asm_sparc_gnu.c:14
static int symbol_at_address(bfd_vma addr, struct disassemble_info *info)
Definition: asm_sparc_gnu.c:30
static RzStrBuf * buf_global
Definition: asm_sparc_gnu.c:15
static unsigned char bytes[4]
Definition: asm_sparc_gnu.c:16
int print_insn_sparc(bfd_vma, disassemble_info *)
Definition: sparc-dis.c:480
voidpf void * buf
Definition: ioapi.h:138
return memset(p, 0, total)
#define bfd_mach_sparc_v9b
Definition: mybfd.h:1623
BFD_HOST_U_64_BIT bfd_vma
Definition: mybfd.h:111
RZ_API void rz_mem_swapendian(ut8 *dest, const ut8 *orig, int size)
Definition: mem.c:202
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 a(i)
Definition: sha256.c:41
Definition: dis.c:32

References a, bfd_mach_sparc_v9b, buf_global, disassemble_info::buffer, bytes, disassemble_info::endian, disassemble_info::fprintf_func, len, disassemble_info::mach, memory_error_func(), disassemble_info::memory_error_func, memset(), Offset, disassemble_info::print_address_func, print_insn_sparc(), disassemble_info::read_memory_func, rz_asm_op_set_asm(), rz_mem_swapendian(), rz_strbuf_get(), rz_strbuf_set(), sparc_buffer_read_memory(), disassemble_info::stream, symbol_at_address(), and disassemble_info::symbol_at_address_func.

◆ memory_error_func()

static void memory_error_func ( int  status,
bfd_vma  memaddr,
struct disassemble_info info 
)
static

Definition at line 34 of file asm_sparc_gnu.c.

34  {
35  //--
36 }

Referenced by disassemble().

◆ sparc_buffer_read_memory()

static int sparc_buffer_read_memory ( bfd_vma  memaddr,
bfd_byte myaddr,
unsigned int  length,
struct disassemble_info info 
)
static

Definition at line 18 of file asm_sparc_gnu.c.

18  {
19  int delta = (memaddr - Offset);
20  if (delta < 0) {
21  return -1; // disable backward reads
22  }
23  if ((delta + length) > 4) {
24  return -1;
25  }
26  memcpy(myaddr, bytes, length);
27  return 0;
28 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static st64 delta
Definition: vmenus.c:2425

References bytes, delta, length, memcpy(), and Offset.

Referenced by disassemble().

◆ symbol_at_address()

static int symbol_at_address ( bfd_vma  addr,
struct disassemble_info info 
)
static

Definition at line 30 of file asm_sparc_gnu.c.

30  {
31  return 0;
32 }

Referenced by disassemble().

Variable Documentation

◆ buf_global

RzStrBuf* buf_global = NULL
static

Definition at line 15 of file asm_sparc_gnu.c.

Referenced by disassemble().

◆ bytes

unsigned char bytes[4]
static

Definition at line 16 of file asm_sparc_gnu.c.

Referenced by disassemble(), and sparc_buffer_read_memory().

◆ Offset

unsigned long Offset = 0
static

Definition at line 14 of file asm_sparc_gnu.c.

Referenced by disassemble(), and sparc_buffer_read_memory().

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_sparc_gnu
Definition: asm_sparc_gnu.c:77
@ 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 88 of file asm_sparc_gnu.c.

◆ rz_asm_plugin_sparc_gnu

RzAsmPlugin rz_asm_plugin_sparc_gnu
Initial value:
= {
.name = "sparc.gnu",
.arch = "sparc",
.bits = 32 | 64,
.license = "GPL3",
.desc = "Scalable Processor Architecture",
.disassemble = &disassemble,
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_sparc_gnu.c:41
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526

Definition at line 77 of file asm_sparc_gnu.c.