Add support for small push in x86.nz assembler

Better Visual Assembler and help ('?' show help)
This commit is contained in:
pancake 2012-12-22 04:28:19 +01:00
parent 1f1b0f32e9
commit 0d04880367
6 changed files with 62 additions and 43 deletions

View File

@ -456,6 +456,14 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
data[l++] = ch;
return l;
}
{
int n = addr;
if (n>-127 && n<=127) {
data[l++] = 0x6a;
data[l++] = addr;
return 2;
}
}
data[l++] = 0x68;
data[l++] = ptr[0];
data[l++] = ptr[1];

View File

@ -306,7 +306,10 @@ R_API char *r_line_readline_cb(RLineReadCallback cb, void *user) {
}
#endif
I.buffer.data[I.buffer.length]='\0';
if (cb) cb (user, I.buffer.data);
if (cb && !cb (user, I.buffer.data)) {
I.buffer.data[0] = 0;
I.buffer.length = 0;
}
ch = r_line_readchar ();
if (ch == -1)

View File

@ -173,7 +173,7 @@ static int cmd_help(void *data, const char *input) {
return 0;
case '$':
r_cons_printf (
"$variables:\n"
"RNum $variables usable in math expressions:\n"
" $$ = here (current virtual seek)\n"
" $o = here (current disk io offset)\n"
" $s = file size\n"
@ -193,7 +193,8 @@ static int cmd_help(void *data, const char *input) {
" $l = opcode length\n"
" $e = 1 if end of block, else 0\n"
" ${eval} = get value of eval config variable # TODO: use ?k too\n"
" $? = last comparision value\n");
" $? = last comparision value\n"
);
return R_TRUE;
case 'V':
r_cons_printf ("%s\n", R2_VERSION);
@ -203,11 +204,9 @@ static int cmd_help(void *data, const char *input) {
core->num->value = strlen (input);
break;
case 'X':
{
for (input++; input[0]==' '; input++);
ut64 n = r_num_math (core->num, input);
r_cons_printf ("%"PFMT64x"\n", n);
}
for (input++; input[0]==' '; input++);
n = r_num_math (core->num, input);
r_cons_printf ("%"PFMT64x"\n", n);
break;
case 'x':
for (input++; input[0]==' '; input++);
@ -466,4 +465,3 @@ static int cmd_help(void *data, const char *input) {
}
return 0;
}

View File

@ -12,24 +12,35 @@ typedef struct {
int blocklen;
} RCoreVisualAsm;
static void readline_callback(RCoreVisualAsm *a, const char *str) {
static int readline_callback(RCoreVisualAsm *a, const char *str) {
int xlen;
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"));
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", a->acode->buf_hex);
else r_cons_newline ();
if (a->acode) {
int xlen = strlen (a->acode->buf_hex);
strcpy (a->codebuf, a->blockbuf);
memcpy (a->codebuf, a->acode->buf_hex, xlen);
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);
}
r_core_cmdf (a->core, "pd 7@b:%s", a->codebuf);
}
r_core_cmdf (a->core, "pd 7@b:%s", a->codebuf);
r_cons_flush ();
return 1;
}
R_API void r_core_visual_asm(RCore *core) {

View File

@ -757,38 +757,37 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
r_cons_clear00 ();
r_cons_printf (
"Visual mode help:\n"
" >||< seek aligned to block size\n"
" hjkl move around (or HJKL)\n"
" pP rotate print modes\n"
" _ enter the hud\n"
" . seek to program counter\n"
" / in cursor mode search in current block\n"
" :cmd run radare command\n"
" ;[-]cmt add/remove comment\n"
" /*+-[] change block size, [] = resize scr.cols\n"
" cC toggle cursor and colors\n"
" gG go seek to begin and end of file (0-$s)\n"
" >||< seek aligned to block size\n"
" iaA (i)nsert hex, (a)ssemble code, visual (A)ssembler\n"
" b/B toggle breakpoint / automatic block size\n"
" hjkl move around (or HJKL) (left-down-up-right)\n"
" pP rotate print modes (hex, disasm, debug, words, buf)\n"
" cC toggle (c)ursor and (C)olors\n"
" d[f?] define function, data, code, ..\n"
" D enter visual diff mode (set diff.from/to)\n"
" x show xrefs to seek between them\n"
" sS step / step over\n"
//" n/N seek next/previous block\n"
" i/a insert hex (i) or assemble code (a)\n"
" e edit eval configuration variables\n"
" f/F set/unset flag\n"
" gG go seek to begin and end of file (0-$s)\n"
" mK/'K mark/go to Key (any key)\n"
" M walk the mounted filesystems\n"
" n/N seek next/prev function/flag/hit (scr.nkey)\n"
" q back to radare shell\n"
" sS step / step over\n"
" t track flags (browse symbols, functions..)\n"
" T browse anal info and comments\n"
" v visual code analysis menu\n"
" V view graph using cmd.graph (agv?)\n"
" M walk the mounted filesystems\n"
" f/F set/unset flag\n"
" n/N seek next/prev function/flag/hit (scr.nkey)\n"
" b/B toggle breakpoint / automatic block size\n"
" uU undo/redo seek\n"
" x show xrefs to seek between them\n"
" yY copy and paste selection\n"
" mK/'K mark/go to Key (any key)\n"
" M show mount points\n"
" _ enter the hud\n"
" / in cursor mode search in current block\n"
" :cmd run radare command\n"
" ;[-]cmt add/remove comment\n"
" . seek to program counter\n"
" z toggle zoom mode\n"
" q back to radare shell\n");
);
r_cons_flush ();
r_cons_any_key ();
r_cons_clear00 ();

View File

@ -294,7 +294,7 @@ R_API void r_line_free();
R_API char *r_line_get_prompt ();
R_API void r_line_set_prompt(const char *prompt);
typedef void (RLineReadCallback) (void *user, const char *line);
typedef int (RLineReadCallback) (void *user, const char *line);
R_API char *r_line_readline();
R_API char *r_line_readline_cb(RLineReadCallback cb, void *user);