* Fix macro definitions

* Handle asm.flags in core_disasm
This commit is contained in:
pancake 2011-06-26 21:24:22 +02:00
parent 868acc4059
commit ef375bf85d
4 changed files with 43 additions and 37 deletions

View File

@ -28,7 +28,7 @@ R_API void r_cmd_macro_init(RCmdMacro *mac) {
R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
struct list_head *pos;
struct r_cmd_macro_item_t *macro;
char buf[1024];
char buf[4096];
char *bufp;
char *pbody;
char *ptr;
@ -37,7 +37,7 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
char *name, *args = NULL;
if (oname[0]=='\0') {
r_cmd_macro_list(mac);
r_cmd_macro_list (mac);
return 0;
}
@ -49,12 +49,12 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
pbody = strchr (name, ',');
if (pbody) {
pbody[0] = '\0';
pbody = pbody + 1;
*pbody = '\0';
pbody++;
}
if (name[strlen (name)-1]==')') {
eprintf ("No body?\n");
eprintf ("r_cmd_macro_add: missing macro body?\n");
free (name);
return -1;
}
@ -78,7 +78,7 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
}
}
if (ptr)
*ptr=' ';
*ptr = ' ';
if (macro == NULL) {
macro = (struct r_cmd_macro_item_t *)malloc (sizeof(struct r_cmd_macro_item_t));
macro->name = strdup (name);
@ -105,7 +105,7 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
pbody[lidx]='\0';
}
strcpy (macro->code, pbody);
strcat (macro->code, ",");
//strcat (macro->code, ",");
} else {
for (;;) { // XXX input from mac->fd
#if 0
@ -115,7 +115,7 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
}
fgets(buf, 1023, r_cons_stdin_fd);
#endif
fgets (buf, 1023, stdin);
fgets (buf, sizeof (buf), stdin);
if (buf[0]==')')
break;
for (bufp=buf;*bufp==' '||*bufp=='\t';bufp=bufp+1);
@ -125,7 +125,7 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
strcat (macro->code, bufp);
break;
}
if (buf[0] != '\n')
if (*buf != '\n')
strcat (macro->code, bufp);
}
}

View File

@ -1608,21 +1608,17 @@ static int cmd_print(void *data, const char *input) {
break;
case 'i': {
RAsmOp asmop;
int j, ret;
int j, ret, err = 0;
const ut8 *buf = core->block;
if (l==0) l = len;
for (i=j=0; i<core->blocksize && i<len; i+=ret,j++ ) {
ret = r_asm_disassemble (core->assembler, &asmop, buf+i, len-i);
if (ret<1) {
ret = 1;
//eprintf ("** invalid opcode at 0x%08"PFMT64x" **\n",
// core->assembler->pc + ret);
printf ("???\n");
} else {
printf ("%s\n", asmop.buf_asm);
}
err = 1;
r_cons_printf ("???\n");
} else r_cons_printf ("%s\n", asmop.buf_asm);
}
return 0;
return err;
}
case 'D':
case 'd':
@ -3783,8 +3779,11 @@ static int cmd_macro(void *data, const char *input) {
break;
} while (ptr[strlen (ptr)-1] != ')');
ptr = buf;
} else {
buf = strdup (input);
buf[strlen (input)-1] = 0;
}
r_cmd_macro_add (&core->cmd->macro, ptr);
r_cmd_macro_add (&core->cmd->macro, buf);
free (buf);
break;
}
@ -3833,18 +3832,22 @@ static int r_core_cmd_subst(RCore *core, char *cmd) {
cmd = r_str_trim_head_tail (cmd);
/* quoted / raw command */
if (cmd[0] =='.' && cmd[1] == '"') { /* interpret */
ret = r_cmd_call (core->cmd, cmd);
return ret;
}
if (cmd[0] == '"') {
switch (*cmd) {
case '.':
if (cmd[1] == '"') { /* interpret */
ret = r_cmd_call (core->cmd, cmd);
return ret;
}
break;
case '"':
if (cmd[len-1] != '"') {
eprintf ("parse: Missing ending '\"'\n");
return -1;
}
cmd[len-1]='\0';
ret = r_cmd_call (core->cmd, cmd+1);
return ret;
return r_cmd_call (core->cmd, cmd+1);
case '(':
return r_cmd_call (core->cmd, cmd);
}
/* comments */

View File

@ -53,6 +53,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
int linesout = r_config_get_i (core->config, "asm.linesout");
int adistrick = r_config_get_i (core->config, "asm.middle"); // TODO: find better name
int show_offset = r_config_get_i (core->config, "asm.offset");
int show_flags = r_config_get_i (core->config, "asm.flags");
int show_bytes = r_config_get_i (core->config, "asm.bytes");
int show_comments = r_config_get_i (core->config, "asm.comments");
int show_stackptr = r_config_get_i (core->config, "asm.stackptr");
@ -237,16 +238,18 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
} else f = NULL;
} else r_cons_printf (" ");
}
flag = r_flag_get_i (core->flags, at);
//if (flag && !show_bytes) {
if (flag) {
if (show_lines && refline)
r_cons_strcat (refline);
if (show_offset)
printoffset (at, show_color);
if (show_functions)
r_cons_printf ("%s:\n%s", flag->name, f?"| ":" ");
else r_cons_printf ("%s:\n", flag->name);
if (show_flags) {
flag = r_flag_get_i (core->flags, at);
//if (flag && !show_bytes) {
if (flag) {
if (show_lines && refline)
r_cons_strcat (refline);
if (show_offset)
printoffset (at, show_color);
if (show_functions)
r_cons_printf ("%s:\n%s", flag->name, f?"| ":" ");
else r_cons_printf ("%s:\n", flag->name);
}
}
if (show_lines && line)
r_cons_strcat (line);

View File

@ -9,7 +9,7 @@ f cow
f-cow
f-bar
f-foo
pd 1
pi 1
'
EXPECT="nop
mov eax, 0x21"