Rizin
unix-like reverse engineering framework and cli tools
asm_x86_nasm.c File Reference
#include <rz_lib.h>
#include <rz_asm.h>

Go to the source code of this file.

Functions

static int assemble (RzAsm *a, RzAsmOp *op, const char *buf)
 

Variables

RzAsmPlugin rz_asm_plugin_x86_nasm
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ assemble()

static int assemble ( RzAsm a,
RzAsmOp op,
const char *  buf 
)
static

Definition at line 7 of file asm_x86_nasm.c.

7  {
8  char *ipath, *opath;
9  if (a->syntax != RZ_ASM_SYNTAX_INTEL) {
10  RZ_LOG_ERROR("assembler: x86.nasm: the assembler does not support non-intel syntax\n");
11  return -1;
12  }
13 
14  int ifd = rz_file_mkstemp("rz_nasm", &ipath);
15  if (ifd == -1) {
16  return -1;
17  }
18 
19  int ofd = rz_file_mkstemp("rz_nasm", &opath);
20  if (ofd == -1) {
21  free(ipath);
22  return -1;
23  }
24 
25  char *asm_buf = rz_str_newf("[BITS %i]\nORG 0x%" PFMT64x "\n%s\n", a->bits, a->pc, buf);
26  if (asm_buf) {
27  rz_xwrite(ifd, asm_buf, strlen(asm_buf));
28  free(asm_buf);
29  }
30 
31  close(ifd);
32 
33  if (!rz_sys_cmdf("nasm %s -o %s", ipath, opath)) {
34  ut8 buf[512]; // TODO: remove limits
35  op->size = read(ofd, buf, sizeof(buf));
36  rz_asm_op_set_buf(op, buf, op->size);
37  } else {
38  RZ_LOG_ERROR("assembler: x86.nasm: failed to run command 'nasm %s -o %s'\n", ipath, opath);
39  }
40 
41  close(ofd);
42  unlink(ipath);
43  unlink(opath);
44  free(ipath);
45  free(opath);
46 
47  return op->size;
48 }
RZ_API void rz_asm_op_set_buf(RzAsmOp *op, const ut8 *buf, int len)
Definition: aop.c:83
static static fork const void static count close
Definition: sflib.h:33
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static static fork const void static count static fd const char static mode unlink
Definition: sflib.h:41
@ RZ_ASM_SYNTAX_INTEL
Definition: rz_asm.h:50
RZ_API int rz_file_mkstemp(RZ_NULLABLE const char *prefix, char **oname)
Definition: file.c:1058
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API int rz_sys_cmdf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define rz_xwrite(fd, buf, count)
Definition: rz_types.h:642
#define PFMT64x
Definition: rz_types.h:393
#define a(i)
Definition: sha256.c:41
Definition: dis.c:32
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References a, close, free(), PFMT64x, read(), rz_asm_op_set_buf(), RZ_ASM_SYNTAX_INTEL, rz_file_mkstemp(), RZ_LOG_ERROR, rz_str_newf(), rz_sys_cmdf(), rz_xwrite, and unlink.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_x86_nasm
Definition: asm_x86_nasm.c:50
@ 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 62 of file asm_x86_nasm.c.

◆ rz_asm_plugin_x86_nasm

RzAsmPlugin rz_asm_plugin_x86_nasm
Initial value:
= {
.name = "x86.nasm",
.desc = "X86 nasm assembler",
.license = "LGPL3",
.arch = "x86",
.bits = 16 | 32 | 64,
.assemble = &assemble
}
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf)
Definition: asm_x86_nasm.c:7
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526

Definition at line 50 of file asm_x86_nasm.c.