Rizin
unix-like reverse engineering framework and cli tools
vasm.c File Reference
#include <rz_core.h>

Go to the source code of this file.

Classes

struct  RzCoreVisualAsm
 

Macros

#define RZ_VISUAL_ASM_BUFSIZE   1024
 

Functions

static int readline_callback (void *_a, const char *str)
 
RZ_API void rz_core_visual_asm (RzCore *core, ut64 off)
 

Macro Definition Documentation

◆ RZ_VISUAL_ASM_BUFSIZE

#define RZ_VISUAL_ASM_BUFSIZE   1024

Definition at line 6 of file vasm.c.

Function Documentation

◆ readline_callback()

static int readline_callback ( void *  _a,
const char *  str 
)
static

Definition at line 19 of file vasm.c.

19  {
20  RzCoreVisualAsm *a = _a;
21  RzCore *core = a->core;
23  rz_cons_printf("Write some %s-%" PFMT64d " assembly...\n\n",
24  rz_config_get(a->core->config, "asm.arch"),
25  rz_config_get_i(a->core->config, "asm.bits"));
26  if (*str == '?') {
27  rz_cons_printf("0> ?\n\n"
28  "Visual assembler help:\n\n"
29  " assemble input while typing using asm.arch, asm.bits and cfg.bigendian\n"
30  " press enter to quit (prompt if there are bytes to be written)\n"
31  " this assembler supports various directives like .hex ...\n");
32  } else {
33  rz_asm_code_free(a->acode);
34  rz_asm_set_pc(a->core->rasm, a->off);
35  a->acode = rz_asm_massemble(a->core->rasm, str);
36  if (a->acode) {
37  char *hex = rz_asm_code_get_hex(a->acode);
38  rz_cons_printf("[VA:%d]> %s\n", a->acode ? a->acode->len : 0, str);
39  if (a->acode && a->acode->len) {
40  rz_cons_printf("* %s\n\n", hex);
41  } else {
42  rz_cons_print("\n\n");
43  }
44  int xlen = RZ_MIN(strlen(hex), RZ_VISUAL_ASM_BUFSIZE - 2);
45  strcpy(a->codebuf, a->blockbuf);
46  memcpy(a->codebuf, hex, xlen);
47  if (xlen >= strlen(a->blockbuf)) {
48  a->codebuf[xlen] = '\0';
49  }
50  free(hex);
51  } else {
52  rz_cons_printf("[VA:0]> %s\n* ?\n\n", str);
53  }
54  {
55  int rows = 0;
56  int cols = rz_cons_get_size(&rows);
57  core->print->cur_enabled = 1;
58  core->print->ocur = 0;
59  core->print->cur = (a->acode && a->acode->len) ? a->acode->len - 1 : 0;
60  char *cmd = rz_str_newf("pd %d @x:%s @0x%" PFMT64x, rows - 11, a->codebuf, a->off);
61  char *res = rz_core_cmd_str(a->core, cmd);
62  char *msg = rz_str_ansi_crop(res, 0, 0, cols - 2, rows - 5);
63  rz_cons_printf("%s\n", msg);
64  free(msg);
65  free(res);
66  free(cmd);
67  }
68  }
69  rz_cons_flush();
70  return 1;
71 }
RZ_API void * rz_asm_code_free(RzAsmCode *acode)
Definition: acode.c:11
RZ_API char * rz_asm_code_get_hex(RzAsmCode *acode)
Definition: acode.c:68
RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc)
Definition: asm.c:533
RZ_API RzAsmCode * rz_asm_massemble(RzAsm *a, const char *assembly)
Definition: asm.c:814
RZ_API char * rz_core_cmd_str(RzCore *core, const char *cmd)
Executes a rizin command and returns the stdout as a string.
Definition: cmd.c:5513
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API void rz_cons_clear00(void)
Definition: cons.c:778
RZ_API int rz_cons_get_size(int *rows)
Definition: cons.c:1446
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
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 cmd
Definition: sflib.h:79
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static const char hex[16]
Definition: print.c:21
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_ansi_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2)
Definition: str.c:2174
#define PFMT64d
Definition: rz_types.h:394
#define PFMT64x
Definition: rz_types.h:393
#define RZ_MIN(x, y)
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119
#define a(i)
Definition: sha256.c:41
RzPrint * print
Definition: rz_core.h:327
int ocur
Definition: rz_print.h:135
bool cur_enabled
Definition: rz_print.h:130
#define RZ_VISUAL_ASM_BUFSIZE
Definition: vasm.c:6

References a, cmd, rz_print_t::cur, rz_print_t::cur_enabled, free(), hex, memcpy(), msg, rz_print_t::ocur, PFMT64d, PFMT64x, rz_core_t::print, rz_asm_code_free(), rz_asm_code_get_hex(), rz_asm_massemble(), rz_asm_set_pc(), rz_config_get(), rz_config_get_i(), rz_cons_clear00(), rz_cons_flush(), rz_cons_get_size(), rz_cons_printf(), rz_core_cmd_str(), RZ_MIN, rz_str_ansi_crop(), rz_str_newf(), RZ_VISUAL_ASM_BUFSIZE, and cmd_descs_generate::str.

Referenced by rz_core_visual_asm().

◆ rz_core_visual_asm()

RZ_API void rz_core_visual_asm ( RzCore core,
ut64  off 
)

Definition at line 73 of file vasm.c.

73  {
74  RzCoreVisualAsm cva = {
75  .core = core,
76  .off = off
77  };
78  rz_io_read_at(core->io, off, cva.buf, sizeof(cva.buf));
79  cva.blocklen = rz_hex_bin2str(cva.buf, sizeof(cva.buf), cva.blockbuf);
80 
82 
83  if (cva.acode && cva.acode->len > 0) {
84  if (rz_cons_yesno('y', "Save changes? (Y/n)")) {
85  if (!rz_io_write_at(core->io, off, cva.acode->bytes, cva.acode->len)) {
86  eprintf("ERROR: Cannot write in here, check map permissions or reopen the file with oo+\n");
88  }
89  }
90  }
92 }
#define NULL
Definition: cris-opc.c:27
RZ_API const char * rz_line_readline_cb(RzLineReadCallback cb, void *user)
Definition: dietline.c:1331
RZ_API int rz_cons_any_key(const char *msg)
Definition: input.c:393
RZ_API bool rz_cons_yesno(int def, const char *fmt,...)
Definition: input.c:666
int off
Definition: pal.c:13
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
RZ_API bool rz_io_write_at(RzIO *io, ut64 addr, const ut8 *buf, int len)
Definition: io.c:358
RzAsmCode * acode
Definition: vasm.c:14
ut8 buf[128]
Definition: vasm.c:13
RzCore * core
Definition: vasm.c:9
char blockbuf[RZ_VISUAL_ASM_BUFSIZE]
Definition: vasm.c:10
int blocklen
Definition: vasm.c:15
ut8 * bytes
Definition: rz_asm.h:80
RzIO * io
Definition: rz_core.h:313
static int readline_callback(void *_a, const char *str)
Definition: vasm.c:19

References RzCoreVisualAsm::acode, RzCoreVisualAsm::blockbuf, RzCoreVisualAsm::blocklen, RzCoreVisualAsm::buf, rz_asm_code_t::bytes, RzCoreVisualAsm::core, eprintf, rz_core_t::io, rz_asm_code_t::len, NULL, off, readline_callback(), rz_asm_code_free(), rz_cons_any_key(), rz_cons_yesno(), rz_hex_bin2str(), rz_io_read_at(), rz_io_write_at(), and rz_line_readline_cb().

Referenced by __assemble_cb(), __panels_process(), rz_core_visual_cmd(), and rz_core_visual_define().