2012-12-22 01:37:01 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2012 - pancake */
|
|
|
|
|
|
|
|
#include <r_core.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
RCore *core;
|
|
|
|
char blockbuf[1024];
|
|
|
|
char codebuf[1024];
|
|
|
|
int oplen;
|
|
|
|
ut8 buf[128];
|
|
|
|
RAsmCode *acode;
|
|
|
|
int blocklen;
|
2013-03-07 12:08:05 +00:00
|
|
|
ut64 off;
|
2012-12-22 01:37:01 +00:00
|
|
|
} RCoreVisualAsm;
|
|
|
|
|
2013-01-04 13:51:21 +00:00
|
|
|
static int readline_callback(void *_a, const char *str) {
|
|
|
|
RCoreVisualAsm *a = _a;
|
2012-12-22 03:28:19 +00:00
|
|
|
int xlen;
|
2012-12-22 01:37:01 +00:00
|
|
|
r_cons_clear00 ();
|
|
|
|
r_cons_printf ("Write your favourite %s-%d opcode...\n\n",
|
|
|
|
r_config_get (a->core->config, "asm.arch"),
|
|
|
|
r_config_get_i (a->core->config, "asm.bits"));
|
2012-12-22 03:28:19 +00:00
|
|
|
if (*str == '?') {
|
|
|
|
r_cons_printf ("0> ?\n\n"
|
|
|
|
"Visual assembler help:\n\n"
|
|
|
|
" assemble input while typing using asm.arch, asm.bits and cfg.bigendian\n"
|
|
|
|
" press enter to quit (prompt if there are bytes to be written)\n"
|
|
|
|
" this assembler supports various directives like .hex ...\n"
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
r_asm_code_free (a->acode);
|
|
|
|
a->acode = r_asm_massemble (a->core->assembler, str);
|
|
|
|
r_cons_printf ("%d> %s\n", a->acode? a->acode->len: 0, str);
|
|
|
|
if (a->acode && a->acode->len)
|
|
|
|
r_cons_printf ("* %s\n\n", a->acode->buf_hex);
|
|
|
|
else r_cons_printf ("\n\n");
|
|
|
|
if (a->acode) {
|
|
|
|
xlen = strlen (a->acode->buf_hex);
|
|
|
|
strcpy (a->codebuf, a->blockbuf);
|
|
|
|
memcpy (a->codebuf, a->acode->buf_hex, xlen);
|
|
|
|
}
|
2013-03-07 12:08:05 +00:00
|
|
|
r_core_cmdf (a->core, "pd 7@b:%s @0x%"PFMT64x, a->codebuf, a->off);
|
2012-12-22 01:37:01 +00:00
|
|
|
}
|
|
|
|
r_cons_flush ();
|
2012-12-22 03:28:19 +00:00
|
|
|
return 1;
|
2012-12-22 01:37:01 +00:00
|
|
|
}
|
|
|
|
|
2013-03-07 12:08:05 +00:00
|
|
|
R_API void r_core_visual_asm(RCore *core, ut64 off) {
|
2012-12-22 01:37:01 +00:00
|
|
|
RCoreVisualAsm cva = {0};
|
|
|
|
cva.core = core;
|
2013-03-07 12:08:05 +00:00
|
|
|
cva.off = off;
|
2012-12-22 01:37:01 +00:00
|
|
|
|
2013-03-07 12:08:05 +00:00
|
|
|
r_io_read_at (core->io, off, cva.buf, sizeof (cva.buf));
|
2012-12-22 01:37:01 +00:00
|
|
|
cva.blocklen = r_hex_bin2str (cva.buf, sizeof (cva.buf), cva.blockbuf);
|
|
|
|
|
|
|
|
r_line_readline_cb (readline_callback, &cva);
|
|
|
|
|
|
|
|
if (cva.acode && cva.acode->len>0)
|
|
|
|
if (r_cons_yesno ('y', "Save changes? (Y/n)"))
|
2013-03-07 12:08:05 +00:00
|
|
|
r_core_cmdf (core, "wx %s @ 0x%"PFMT64x,
|
|
|
|
cva.acode->buf_hex, off);
|
2012-12-22 01:37:01 +00:00
|
|
|
r_asm_code_free (cva.acode);
|
|
|
|
}
|