Implement rasm2 -s? and refactor this a bit
This commit is contained in:
parent
516a095a04
commit
d7e0be5dad
5 changed files with 38 additions and 15 deletions
|
|
@ -476,9 +476,16 @@ int main (int argc, char *argv[]) {
|
|||
if (fd != -1) dup2 (fd, 1);
|
||||
break;
|
||||
case 's':
|
||||
if (!strcmp (optarg, "att"))
|
||||
r_asm_set_syntax (a, R_ASM_SYNTAX_ATT);
|
||||
else r_asm_set_syntax (a, R_ASM_SYNTAX_INTEL);
|
||||
if (*optarg == '?') {
|
||||
printf ("att\nintel\nmasm\njz\nregnum\n");
|
||||
return false;
|
||||
} else {
|
||||
int syntax = r_asm_syntax_from_string (optarg);
|
||||
if (syntax == -1) {
|
||||
return false;
|
||||
}
|
||||
r_asm_set_syntax (a, syntax);
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
if (quiet) {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ _rasm2 () {
|
|||
return 0
|
||||
;;
|
||||
-s)
|
||||
COMPREPLY=( $(compgen -W "$(r2 -qc 'e asm.syntax=?' --)" -- $cur ))
|
||||
COMPREPLY=( $(compgen -W "$(rasm2 -s?)" -- $cur ))
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
|
|
|||
|
|
@ -859,3 +859,22 @@ R_API ut8 *r_asm_from_string(RAsm *a, ut64 addr, const char *b, int *l) {
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API int r_asm_syntax_from_string(const char *name) {
|
||||
if (!strcmp (name, "regnum")) {
|
||||
return R_ASM_SYNTAX_REGNUM;
|
||||
}
|
||||
if (!strcmp (name, "jz")) {
|
||||
return R_ASM_SYNTAX_JZ;
|
||||
}
|
||||
if (!strcmp (name, "intel")) {
|
||||
return R_ASM_SYNTAX_INTEL;
|
||||
}
|
||||
if (!strcmp (name, "masm")) {
|
||||
return R_ASM_SYNTAX_MASM;
|
||||
}
|
||||
if (!strcmp (name, "att")) {
|
||||
return R_ASM_SYNTAX_ATT;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -587,17 +587,13 @@ static int cb_asmsyntax(void *user, void *data) {
|
|||
if (*node->value == '?') {
|
||||
r_cons_printf ("att\nintel\nmasm\njz\nregnum\n");
|
||||
return false;
|
||||
} else if (!strcmp (node->value, "regnum")) {
|
||||
r_asm_set_syntax (core->assembler, R_ASM_SYNTAX_REGNUM);
|
||||
} else if (!strcmp (node->value, "jz")) {
|
||||
r_asm_set_syntax (core->assembler, R_ASM_SYNTAX_JZ);
|
||||
} else if (!strcmp (node->value, "intel")) {
|
||||
r_asm_set_syntax (core->assembler, R_ASM_SYNTAX_INTEL);
|
||||
} else if (!strcmp (node->value, "masm")) {
|
||||
r_asm_set_syntax (core->assembler, R_ASM_SYNTAX_MASM);
|
||||
} else if (!strcmp (node->value, "att")) {
|
||||
r_asm_set_syntax (core->assembler, R_ASM_SYNTAX_ATT);
|
||||
} else return false;
|
||||
} else {
|
||||
int syntax = r_asm_syntax_from_string (node->value);
|
||||
if (syntax == -1) {
|
||||
return false;
|
||||
}
|
||||
r_asm_set_syntax (core->assembler, syntax);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,6 +150,7 @@ R_API int r_asm_set_bits(RAsm *a, int bits);
|
|||
R_API void r_asm_set_cpu(RAsm *a, const char *cpu);
|
||||
R_API bool r_asm_set_big_endian(RAsm *a, bool big_endian);
|
||||
R_API int r_asm_set_syntax(RAsm *a, int syntax);
|
||||
R_API int r_asm_syntax_from_string(const char *name);
|
||||
R_API int r_asm_set_pc(RAsm *a, ut64 pc);
|
||||
R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len);
|
||||
R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf);
|
||||
|
|
|
|||
Loading…
Reference in a new issue