Remove RAsmPlugin struct and add the 'aia' command to show archinfo ##arch

This commit is contained in:
pancake 2022-12-06 12:16:45 +01:00 committed by GitHub
parent 3a16336491
commit 4b769417e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 276 additions and 640 deletions

View File

@ -488,21 +488,23 @@ R_API void r_anal_purge(RAnal *anal) {
// XXX deprecate. use r_arch_info() when all anal plugs get moved
R_API R_DEPRECATE int r_anal_archinfo(RAnal *anal, int query) {
r_return_val_if_fail (anal, -1);
switch (query) {
case R_ANAL_ARCHINFO_MIN_OP_SIZE:
case R_ANAL_ARCHINFO_MAX_OP_SIZE:
case R_ANAL_ARCHINFO_INV_OP_SIZE:
case R_ANAL_ARCHINFO_ALIGN:
{
// this check wont be needed when all the anal plugs move to archland
// const char *const b = anal->cur->name;
// eprintf ("%s %s\n", a,b);
if (anal->uses == 2 && anal->arch->session) {
const char *const a = anal->arch->session? anal->arch->session->config->arch: "";
const char *const b = anal->config->arch;
if (!strcmp (a, b)) {
int res = r_arch_info (anal->arch, query);
if (res != -1) {
return res;
}
return res;
}
if (anal->cur && anal->cur->archinfo) {
return anal->cur->archinfo (anal, query);
}
break;
}
// this is the anal archinfo fallback
if (anal->cur && anal->cur->archinfo) {
return anal->cur->archinfo (anal, query);
}
return -1;
}

View File

@ -197,7 +197,6 @@ R_API bool r_arch_del(RArch *arch, const char *name) {
R_API void r_arch_free(RArch *arch) {
if (arch) {
// ht_pp_free (arch->decoders);
r_list_free (arch->plugins);
r_unref (arch->cfg);
free (arch);

View File

@ -57,6 +57,20 @@ R_API bool r_arch_config_set_bits(RArchConfig *config, int bits) {
return is_valid;
}
R_API bool r_arch_config_set_syntax(RArchConfig *config, int syntax) {
switch (syntax) {
case R_ARCH_SYNTAX_REGNUM:
case R_ARCH_SYNTAX_INTEL:
case R_ARCH_SYNTAX_MASM:
case R_ARCH_SYNTAX_ATT:
case R_ARCH_SYNTAX_JZ:
config->syntax = syntax;
return true;
default:
return false;
}
}
R_API RArchConfig *r_arch_config_clone(RArchConfig *c) {
r_return_val_if_fail (c, NULL);
RArchConfig *ac = R_NEW0 (RArchConfig);

View File

@ -45,7 +45,7 @@ $(EXTRA_CLEAN):
include ${STATIC_PARSE_PLUGINS}
STATIC_OBJS=$(subst ..,p/..,$(subst parse_,p/parse_,$(STATIC_OBJ)))
OBJS=${STATIC_OBJS} asm.o acode.o aop.o aplugs.o filter.o parse.o
OBJS=${STATIC_OBJS} asm.o acode.o aop.o agperf.o filter.o parse.o
OBJS+=${SHARED2_OBJ}

View File

@ -18,8 +18,6 @@ static const char *directives[] = {
".else", ".set", ".get", NULL
};
static const RAsmPlugin * const asm_static_plugins[] = { NULL }; // asm plugins are deprecated
/* pseudo.c - private api */
static int r_asm_pseudo_align(RAsmCode *acode, RAsmOp *op, const char *input) {
acode->code_align = r_num_math (NULL, input);
@ -185,7 +183,6 @@ static inline int r_asm_pseudo_incbin(RAsmOp *op, char *input) {
}
R_API RAsm *r_asm_new(void) {
int i;
RAsm *a = R_NEW0 (RAsm);
if (!a) {
return NULL;
@ -197,9 +194,7 @@ R_API RAsm *r_asm_new(void) {
return NULL;
}
a->config = r_arch_config_new ();
for (i = 0; asm_static_plugins[i]; i++) {
r_asm_add (a, (RAsmPlugin*)asm_static_plugins[i]);
}
a->parse = r_parse_new ();
return a;
}
@ -252,66 +247,20 @@ R_API void r_asm_set_user_ptr(RAsm *a, void *user) {
a->user = user;
}
R_API bool r_asm_add(RAsm *a, RAsmPlugin *foo) {
if (!foo->name) {
return false;
}
if (r_asm_is_valid (a, foo->name)) {
return false;
}
r_list_append (a->plugins, foo);
return true;
}
R_API int r_asm_del(RAsm *a, const char *name) {
/* TODO: Implement r_asm_del */
return false;
}
R_API bool r_asm_is_valid(RAsm *a, const char *name) {
// r_return_val_if_fail (a && name, false);
if (a && R_STR_ISNOTEMPTY (name)) {
RAsmPlugin *h;
RListIter *iter;
r_list_foreach (a->plugins, iter, h) {
if (!strcmp (h->name, name)) {
return true;
}
}
}
return false;
}
R_API bool r_asm_use_assembler(RAsm *a, const char *name) {
r_return_val_if_fail (a && name, false);
RAsmPlugin *h;
RListIter *iter;
if (R_STR_ISNOTEMPTY (name)) {
r_list_foreach (a->plugins, iter, h) {
if (h->assemble && !strcmp (h->name, name)) {
a->acur = h;
// r_unref (a->ecur);
// a->ecur = a->ecur = r_arch_use (a->arch); // create a new instance for `ecur`
return true;
}
}
}
a->acur = NULL;
// TODO not implemented
return false;
}
static void load_asm_descriptions(RAsm *a, RAsmPlugin *p) {
const char *arch;
if (a->config->arch && (!p || !strcmp (p->name, "null"))) {
arch = a->config->arch;
} else if (p && !strcmp (p->name, "r2ghidra")) {
arch = p->name;
} else if (p) {
arch = p->arch;
} else {
static void load_asm_descriptions(RAsm *a) {
const char *arch = a->config->arch;
if (!arch || !strcmp (arch, "any")) {
arch = a->config->cpu;
}
if (!arch) {
return;
}
#if HAVE_GPERF
SdbGperf *gp = r_asm_get_gperf (arch);
if (gp) {
@ -343,8 +292,6 @@ R_API bool r_asm_use(RAsm *a, const char *name) {
}
r_arch_config_use (a->config, name);
r_asm_use_assembler (a, name);
RAsmPlugin *h;
RListIter *iter;
char *dotname = strdup (name);
char *vv = strchr (dotname, '.');
if (vv) {
@ -352,10 +299,14 @@ R_API bool r_asm_use(RAsm *a, const char *name) {
} else {
R_FREE (dotname);
}
#if 0
RListIter *iter;
RAsmPlugin *h;
r_list_foreach (a->plugins, iter, h) {
if (!strcmp (h->name, name)) {
if (!a->cur || (a->cur && h->arch && strcmp (a->cur->arch, h->arch))) {
load_asm_descriptions (a, h);
a->cur = h;
load_asm_descriptions (a);
r_asm_set_cpu (a, NULL);
}
a->cur = h;
@ -369,32 +320,20 @@ R_API bool r_asm_use(RAsm *a, const char *name) {
r_asm_set_cpu (a, arch);
#endif
a->cur = h;
load_asm_descriptions (a, h);
load_asm_descriptions (a);
free (arch);
return true;
}
#if 0
} else if (!strcmp (name, h->name)) {
#if 0
r_arch_config_set_cpu (a->config, NULL);
#else
h->arch = name; // leaks wtf is this shit
r_asm_set_cpu (a, NULL);
#endif
a->cur = h;
load_asm_descriptions (a, h);
return true;
}
#endif
}
#endif
if (a->analb.anal) {
if (a->analb.use (a->analb.anal, name)) {
load_asm_descriptions (a, NULL);
a->cur = NULL;
a->acur = NULL;
load_asm_descriptions (a);
//a->cur = NULL;
// a->acur = NULL;
return true;
}
R_LOG_ERROR ("Cannot find '%s' asm/arch/anal plugin. See rasm2 -L, -LL or -LLL", name);
R_LOG_ERROR ("Cannot find '%s' asm/arch/anal plugin. See rasm2 -L or -LL", name);
}
#if 0
// check if its a valid analysis plugin
@ -413,27 +352,15 @@ R_DEPRECATE R_API void r_asm_set_cpu(RAsm *a, const char *cpu) {
r_arch_config_set_cpu (a->config, cpu);
}
#if 0
static bool has_bits(RAsmPlugin *h, int bits) {
return (h && h->bits && (bits & h->bits));
}
#endif
R_DEPRECATE R_API int r_asm_set_bits(RAsm *a, int bits) {
a->config->bits = bits;
return true;
#if 0
if (has_bits (a->cur, bits)) {
a->config->bits = bits; // TODO : use OR? :)
return true;
}
return false;
#endif
}
R_API bool r_asm_set_big_endian(RAsm *a, bool b) {
r_return_val_if_fail (a, false);
a->config->endian = R_SYS_ENDIAN ? R_SYS_ENDIAN_BIG: R_SYS_ENDIAN_LITTLE; // default is host endian
#if 0
if (a->cur) {
switch (a->cur->endian) {
case R_SYS_ENDIAN_NONE:
@ -450,30 +377,16 @@ R_API bool r_asm_set_big_endian(RAsm *a, bool b) {
a->config->endian = R_SYS_ENDIAN_BIG;
break;
default:
R_LOG_WARN ("RAsmPlugin doesn't specify endianness");
R_LOG_WARN ("no endianness specified");
break;
}
} else {
a->config->endian = b ? R_SYS_ENDIAN_BIG: R_SYS_ENDIAN_LITTLE;
}
#endif
a->config->endian = b ? R_SYS_ENDIAN_BIG: R_SYS_ENDIAN_LITTLE;
return R_ARCH_CONFIG_IS_BIG_ENDIAN (a->config);
}
R_API bool r_asm_set_syntax(RAsm *a, int syntax) {
// TODO: move into r_arch ?
switch (syntax) {
case R_ARCH_SYNTAX_REGNUM:
case R_ARCH_SYNTAX_INTEL:
case R_ARCH_SYNTAX_MASM:
case R_ARCH_SYNTAX_ATT:
case R_ARCH_SYNTAX_JZ:
a->config->syntax = syntax;
return true;
default:
return false;
}
}
R_API int r_asm_set_pc(RAsm *a, ut64 pc) {
a->pc = pc;
return true;
@ -554,59 +467,6 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
typedef int (*Ase)(RAsm *a, RAsmOp *op, const char *buf);
#if 0
static bool assemblerMatches(RAsm *a, RAsmPlugin *h, const char *ends_with) {
const char *arch = R_UNWRAP3 (a, config, arch);
if (!a || !h->arch || !h->assemble || !has_bits (h, a->config->bits)) {
return false;
}
const char *cur_arch = R_UNWRAP3 (a, cur, arch);
if (!strcmp (h->arch, arch)) {
if (ends_with) {
return r_str_endswith (h->name, ends_with);
}
if ((cur_arch && r_str_startswith (cur_arch, h->arch))) {
return true;
}
}
return false;
}
#endif
static Ase find_assembler(RAsm *a, const char *kw) {
RAsmPlugin *ap = R_UNWRAP2 (a, acur);
if (ap && ap->assemble && !strcmp (ap->arch, a->config->arch)) {
return ap->assemble;
}
return NULL;
#if 0
RAsmAssembleCallback aac = R_UNWRAP3 (a, acur, assemble);
if (!aac) {
aac = R_UNWRAP3 (a, cur, assemble);
if (aac) {
eprintf ("\n");
return aac;
}
RAsmPlugin *h;
RListIter *iter;
r_list_foreach (a->plugins, iter, h) {
if (assemblerMatches (a, h, kw)) {
a->acur = h;
if (kw) {
if (r_str_endswith (h->name, kw)) {
eprintf ("AAC FOUND\n");
aac = h->assemble;
break;
}
}
break;
}
}
}
return aac;
#endif
}
static char *replace_directives_for(char *str, const char *token) {
RStrBuf *sb = r_strbuf_new ("");
char *p = NULL;
@ -675,7 +535,7 @@ R_API RAnalOp *r_asm_assemble2(RAsm *a, const char *str) {
}
// returns instruction size
R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf) {
static int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf) {
r_return_val_if_fail (a && op && buf, 0);
int ret = 0;
char *b = strdup (buf);
@ -685,7 +545,9 @@ R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf) {
if (a->ifilter) {
r_parse_parse (a->ifilter, buf, b);
}
r_str_case (b, false); // to-lower
#if 0
r_asm_op_init (op);
Ase ase = find_assembler (a, NULL);
if (!ase) {
@ -700,28 +562,26 @@ R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf) {
}
}
if (!ase && a->analb.anal) {
// disassemble using the analysis plugin if found
ase = NULL;
RAnalOp aop;
a->analb.opinit (&aop);
#else
if (a->analb.anal) {
#endif
// disassemble using the analysis plugin if found
//RAnalOp aop;
//a->analb.opinit (&aop);
ut8 buf[256] = {0};
// XXX we shuold use just RArch and ecur/dcur
ret = a->analb.encode (a->analb.anal, a->pc, b, buf, sizeof (buf));
if (ret > 0) {
// r_anal_op_set_bytes (op, op->addr, buf, R_MIN (ret, sizeof (buf)));
r_strbuf_setbin (&op->buf, buf, R_MIN (ret, sizeof (buf)));
} // else fail to assemble
a->analb.opfini (&aop);
// a->analb.opfini (&aop);
#if 0
} else if (ase) {
/* find callback if no assembler support in current plugin */
ret = ase (a, op, b);
}
// XXX delete this block, the ase thing should be setting asm, buf and hex
if (op && ret > 0) {
op->size = ret; // XXX shouldn't be necessary
r_asm_op_set_asm (op, b); // XXX ase should be updating this already, isn't?
ut8 *opbuf = (ut8*)r_strbuf_get (&op->buf);
if (opbuf) {
r_asm_op_set_buf (op, opbuf, ret);
}
#endif
}
free (b);
return ret;
@ -851,11 +711,11 @@ static int parse_asm_directive(RAsm *a, RAsmOp *op, RAsmCode *acode, char *ptr_s
} else if (r_str_startswith (ptr, ".fill ")) {
ret = r_asm_pseudo_fill (op, ptr + 6);
} else if (r_str_startswith (ptr, ".kernel ")) {
r_syscall_setup (a->syscall, a->cur->arch, a->config->bits, asmcpu, ptr + 8);
r_syscall_setup (a->syscall, a->config->arch, a->config->bits, asmcpu, ptr + 8);
} else if (r_str_startswith (ptr, ".cpu ")) {
r_asm_set_cpu (a, ptr + 5);
} else if (r_str_startswith (ptr, ".os ")) {
r_syscall_setup (a->syscall, a->cur->arch, a->config->bits, asmcpu, ptr + 4);
r_syscall_setup (a->syscall, a->config->arch, a->config->bits, asmcpu, ptr + 4);
} else if (r_str_startswith (ptr, ".hex ")) {
ret = r_asm_op_set_hex (op, ptr + 5);
} else if ((r_str_startswith (ptr, ".int16 ")) || r_str_startswith (ptr, ".short ")) {
@ -1046,7 +906,7 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) {
continue;
}
// XXX TODO remove arch-specific hacks
const char *cur_arch = R_UNWRAP3 (a, cur, arch);
const char *cur_arch = R_UNWRAP3 (a, config, arch);
if (cur_arch && r_str_startswith (cur_arch, "avr")) {
for (ptr_start = buf_token; *ptr_start && isavrseparator (*ptr_start); ptr_start++);
} else {
@ -1268,7 +1128,7 @@ R_API char *r_asm_mnemonics(RAsm *a, int id, bool json) {
}
R_API int r_asm_mnemonics_byname(RAsm *a, const char *name) {
r_return_val_if_fail (a && a->cur && name, 0);
r_return_val_if_fail (a && name, 0);
int i;
for (i = 0; i < 9000; i++) {
char *n = r_asm_mnemonics (a, i, false);
@ -1308,8 +1168,8 @@ R_API RList *r_asm_cpus(RAsm *a) {
RListIter *iter;
char *item;
// get asm plugin
RList *list = (a->cur && a->cur->cpus)
? r_str_split_duplist (a->cur->cpus, ",", 0)
RList *list = (a->config && a->config->cpu)
? r_str_split_duplist (a->config->cpu, ",", 0)
: r_list_newf (free);
// get anal plugin
if (a->analb.anal && a->analb.anal->cur && a->analb.anal->cur->cpus) {

View File

@ -6,7 +6,7 @@ r_asm_sources = [
'acode.c',
'parse.c',
'filter.c',
'aplugs.c',
'agperf.c',
'../arch/p/pseudo/z80_pseudo.c',
'../arch/p/pseudo/wasm_pseudo.c',
'../arch/p/pseudo/v850_pseudo.c',

View File

@ -3899,11 +3899,7 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode
int arch = -1;
if (core->rasm->config->bits == 64) {
// speedup search
if (core->rasm->cur) {
if (r_str_startswith (core->rasm->cur->name, "arm")) {
arch = R2_ARCH_ARM64;
}
} else if (core->rasm->config) {
if (core->rasm->config) {
if (r_str_startswith (core->rasm->config->arch, "arm")) {
arch = R2_ARCH_ARM64;
}
@ -5020,11 +5016,11 @@ static bool esilbreak_reg_write(REsil *esil, const char *name, ut64 *val) {
}
}
}
if (core->rasm && core->rasm->cur && core->rasm->config && core->rasm->config->bits == 32 && strstr (core->rasm->cur->name, "arm")) {
if (core->rasm && core->rasm->config && core->rasm->config->bits == 32 && strstr (core->rasm->config->arch, "arm")) {
if ((!(at & 1)) && r_io_is_valid_offset (anal->iob.io, at, 0)) { // !core->anal->opt.noncode)) {
add_string_ref (anal->coreb.core, esil->address, at);
}
} else if (core->anal && core->anal->config && core->anal->config->bits == 32 && strstr (core->anal->cur->name, "arm")) {
} else if (core->anal && core->anal->config && core->anal->config->bits == 32 && strstr (core->anal->config->arch, "arm")) {
if ((!(at & 1)) && r_io_is_valid_offset (anal->iob.io, at, 0)) { // !core->anal->opt.noncode)) {
add_string_ref (anal->coreb.core, esil->address, at);
}

View File

@ -4486,25 +4486,23 @@ R_API bool r_core_bin_set_arch_bits(RCore *r, const char *name, const char *_arc
}
}
/* Check if the arch name is a valid name */
if (!r_asm_is_valid (r->rasm, arch)) {
bool found_anal_plugin = false;
if (arch && r->anal && r->anal->plugins) {
RAnalPlugin *anal_plugin;
RListIter *iter;
r_list_foreach (r->anal->plugins, iter, anal_plugin) { //XXX: fix this properly after 5.8
if (!anal_plugin->arch) {
continue;
}
if (!strcmp (anal_plugin->arch, arch)) {
found_anal_plugin = true;
break;
}
bool found_anal_plugin = false;
if (arch && r->anal && r->anal->plugins) {
RAnalPlugin *anal_plugin;
RListIter *iter;
r_list_foreach (r->anal->plugins, iter, anal_plugin) { //XXX: fix this properly after 5.8
if (!anal_plugin->arch) {
continue;
}
if (!strcmp (anal_plugin->arch, arch)) {
found_anal_plugin = true;
break;
}
}
if (!found_anal_plugin) {
free (arch);
return false;
}
}
if (!found_anal_plugin) {
free (arch);
return false;
}
if (!strcmp (arch, "null")) {
free (arch);
@ -4544,24 +4542,17 @@ R_API bool r_core_bin_set_arch_bits(RCore *r, const char *name, const char *_arc
}
R_API bool r_core_bin_update_arch_bits(RCore *r) {
RBinFile *binfile = NULL;
const char *name = NULL, *arch = NULL;
ut16 bits = 0;
int bits = 0;
if (!r) {
return 0;
}
if (r->rasm) { //XXX: refactor when RArch is done
bits = r->rasm->config->bits;
if (r->rasm->cur) {
arch = r->rasm->cur->arch;
}
}
const char *arch = NULL;
if (!arch && r->anal && r->anal->cur) {
bits = r->anal->config->bits;
arch = r->anal->cur->arch;
}
binfile = r_bin_cur (r->bin);
name = binfile ? binfile->file : NULL;
RBinFile *binfile = r_bin_cur (r->bin);
const char *name = binfile ? binfile->file : NULL;
if (r->anal && binfile && binfile->curxtr) {
r_anal_hint_clear (r->anal);
}

View File

@ -130,100 +130,6 @@ static const char *has_esil(RCore *core, const char *name) {
return "__";
}
// copypasta from binr/rasm2/rasm2.c
bool rasm2_list(RCore *core, const char *arch, int fmt) {
int i;
const char *feat2, *feat;
RAsm *a = core->rasm;
char *bits = NULL;
RAsmPlugin *h;
RListIter *iter;
bool any = false;
PJ *pj = NULL;
if (fmt == 'j') {
pj = pj_new ();
if (!pj) {
return false;
}
pj_o (pj);
}
r_list_foreach (a->plugins, iter, h) {
if (arch && *arch) {
if (h->cpus && !strcmp (arch, h->name)) {
char *c = strdup (h->cpus);
int n = r_str_split (c, ',');
for (i = 0; i < n; i++) {
r_cons_println (r_str_word_get0 (c, i));
any = true;
}
free (c);
break;
}
} else {
RStrBuf *sb = r_strbuf_new ("");
if (h->bits & 8) {
r_strbuf_append (sb, "8");
}
if (h->bits & 16) {
r_strbuf_appendf (sb, "%s16", sb->len? ",": "");
}
if (h->bits & 32) {
r_strbuf_appendf (sb, "%s32", sb->len? ",": "");
}
if (h->bits & 64) {
r_strbuf_appendf (sb, "%s64", sb->len? ",": "");
}
if (!h->bits) {
r_strbuf_appendf (sb, "%s0", sb->len? ",": "");
}
bits = r_strbuf_drain (sb);
feat = "__";
if (h->assemble) {
feat = "a_";
}
feat2 = has_esil (core, h->name);
if (fmt == 'q') {
r_cons_println (h->name);
} else if (fmt == 'j') {
const char *license = "GPL";
pj_k (pj, h->name);
pj_o (pj);
pj_k (pj, "bits");
pj_a (pj);
if (h->bits & 8) {
pj_i (pj, 8);
}
if (h->bits & 16) {
pj_i (pj, 16);
}
if (h->bits & 32) {
pj_i (pj, 32);
}
if (h->bits & 64) {
pj_i (pj, 64);
}
pj_end (pj);
pj_ks (pj, "license", license);
pj_ks (pj, "description", h->desc);
pj_ks (pj, "features", feat);
pj_end (pj);
} else {
r_cons_printf ("%s%s %-11s %-11s %-7s %s\n",
feat, feat2, bits, h->name,
r_str_get_fail (h->license, "unknown"), h->desc);
}
any = true;
free (bits);
}
}
if (fmt == 'j') {
pj_end (pj);
r_cons_println (pj_string (pj));
pj_free (pj);
}
return any;
}
// more copypasta
bool ranal2_list(RCore *core, const char *arch, int fmt) {
int i;
@ -727,7 +633,7 @@ static bool cb_asmassembler(void *user, void *data) {
if (*node->value == '?') {
if (strlen (node->value) > 1 && node->value[1] == '?') {
/* print more verbose help instead of plain option values */
rasm2_list (core, NULL, node->value[1]);
ranal2_list (core, NULL, node->value[1]);
return false;
}
RConfigNode* asm_arch_node = r_config_node_get (core->config, "asm.arch");
@ -755,7 +661,6 @@ static void update_cmdpdc_options(RCore *core, RConfigNode *node) {
}
static void update_asmcpu_options(RCore *core, RConfigNode *node) {
RAsmPlugin *h;
RListIter *iter;
r_return_if_fail (core && core->rasm);
const char *arch = r_config_get (core->config, "asm.arch");
@ -763,7 +668,8 @@ static void update_asmcpu_options(RCore *core, RConfigNode *node) {
return;
}
r_config_node_purge_options (node);
r_list_foreach (core->rasm->plugins, iter, h) {
RArchPlugin *h;
r_list_foreach (core->anal->arch->plugins, iter, h) {
if (h->cpus && !strcmp (arch, h->name)) {
char *c = strdup (h->cpus);
int i, n = r_str_split (c, ',');
@ -788,7 +694,6 @@ static bool cb_asmcpu(void *user, void *data) {
// XXX not working const char *asm_arch = core->anal->config->arch;
const char *asm_arch = r_config_get (core->config, "asm.arch");
/* print verbose help instead of plain option listing */
rasm2_list (core, asm_arch, node->value[1]);
ranal2_list (core, asm_arch, node->value[1]);
return 0;
}
@ -803,11 +708,11 @@ static bool cb_asmcpu(void *user, void *data) {
}
static void update_asmarch_options(RCore *core, RConfigNode *node) {
RAsmPlugin *h;
RArchPlugin *h;
RListIter *iter;
if (core && node && core->rasm) {
r_config_node_purge_options (node);
r_list_foreach (core->rasm->plugins, iter, h) {
r_list_foreach (core->anal->arch->plugins, iter, h) {
if (h->name) {
SETOPTIONS (node, h->name, NULL);
}
@ -816,8 +721,8 @@ static void update_asmarch_options(RCore *core, RConfigNode *node) {
}
static void update_asmbits_options(RCore *core, RConfigNode *node) {
if (core && core->rasm && core->rasm->cur && node) {
int bits = core->rasm->cur->bits;
if (core && core->rasm && node) {
int bits = core->rasm->config->bits;
int i;
r_config_node_purge_options (node);
for (i = 1; i <= bits; i <<= 1) {
@ -833,19 +738,22 @@ static void update_asmbits_options(RCore *core, RConfigNode *node) {
static bool cb_asmarch(void *user, void *data) {
char asmparser[32];
RCore *core = (RCore *) user;
r_return_val_if_fail (core && core->anal, false);
RConfigNode *node = (RConfigNode *) data;
int bits = R_SYS_BITS;
if (!*node->value || !core || !core->rasm) {
if (R_STR_ISEMPTY (node->value)) {
return false;
}
if (core && core->anal && core->anal->config->bits) {
int bits = R_SYS_BITS;
if (core->anal->config && core->anal->config->bits) {
bits = core->anal->config->bits;
}
if (*node->value == '?') {
update_asmarch_options (core, node);
if (strlen (node->value) > 1 && node->value[1] == '?') {
/* print more verbose help instead of plain option values */
rasm2_list (core, NULL, node->value[1]);
ranal2_list (core, NULL, node->value[1]);
return false;
} else {
print_node_options (node);
@ -861,8 +769,9 @@ static bool cb_asmarch(void *user, void *data) {
//we should strdup here otherwise will crash if any r_config_set
//free the old value
char *asm_cpu = strdup (r_config_get (core->config, "asm.cpu"));
#if 0
if (core->rasm->cur) {
const char *new_asm_cpu = core->rasm->cur->cpus;
const char *new_asm_cpu = core->rasm->config->cpu;
if (R_STR_ISNOTEMPTY (new_asm_cpu)) {
char *nac = strdup (new_asm_cpu);
char *comma = strchr (nac, ',');
@ -878,7 +787,7 @@ static bool cb_asmarch(void *user, void *data) {
// the given asm.cpu setup, but we can ignore for now
// r_config_set (core->config, "asm.cpu", "");
}
bits = core->rasm->cur->bits;
bits = core->rasm->config->bits;
if (8 & bits) {
bits = 8;
} else if (16 & bits) {
@ -890,12 +799,13 @@ static bool cb_asmarch(void *user, void *data) {
}
update_asmbits_options (core, r_config_node_get (core->config, "asm.bits"));
}
#endif
snprintf (asmparser, sizeof (asmparser), "%s.pseudo", node->value);
r_config_set (core->config, "asm.parser", asmparser);
if (core->rasm->cur && core->anal && core->anal->cur && !(core->anal->cur->bits & core->anal->config->bits)) {
if (core->anal->cur && !(core->anal->config->bits & core->anal->config->bits)) {
r_config_set_i (core->config, "asm.bits", bits);
} else if (core->rasm->cur && core->anal && core->anal->cur && !(core->rasm->cur->bits & core->anal->config->bits)) {
} else if (core->anal->cur && !(core->rasm->config->bits & core->anal->config->bits)) {
r_config_set_i (core->config, "asm.bits", bits);
}
@ -996,6 +906,7 @@ static bool cb_asmbits(void *user, void *data) {
}
if (bits > 0) {
ret = r_asm_set_bits (core->rasm, bits);
#if 0
if (!ret) {
RAsmPlugin *h = core->rasm->cur;
if (!h) {
@ -1005,13 +916,14 @@ static bool cb_asmbits(void *user, void *data) {
}
// else { R_LOG_ERROR ("Cannot set bits %d to '%s'", bits, h->name); }
}
#endif
if (!r_anal_set_bits (core->anal, bits)) {
R_LOG_ERROR ("asm.arch: Cannot setup '%d' bits analysis engine", bits);
ret = false;
}
}
if (core->dbg && core->anal && core->anal->cur) {
r_debug_set_arch (core->dbg, core->anal->cur->arch, bits);
r_debug_set_arch (core->dbg, core->anal->config->arch, bits);
const bool load_from_debug = r_config_get_b (core->config, "cfg.debug");
if (load_from_debug) {
if (core->dbg->h && core->dbg->h->reg_profile) {
@ -1387,7 +1299,7 @@ static bool cb_asmsyntax(void *user, void *data) {
if (syntax == -1) {
return false;
}
r_asm_set_syntax (core->rasm, syntax);
r_arch_config_set_syntax (core->rasm->config, syntax);
}
return true;
}

View File

@ -5940,19 +5940,21 @@ R_API char *r_core_cmd_str(RCore *core, const char *cmd) {
return strdup ("");
}
r_cons_push ();
core->cons->context->noflush = true;
core->cons->context->cmd_str_depth++;
if (cmd && r_core_cmd (core, cmd, 0) == -1) {
//eprintf ("Invalid command: %s\n", cmd);
if (core->cons) {
core->cons->context->noflush = true;
core->cons->context->cmd_str_depth++;
if (cmd && r_core_cmd (core, cmd, 0) == -1) {
//eprintf ("Invalid command: %s\n", cmd);
if (--core->cons->context->cmd_str_depth == 0) {
core->cons->context->noflush = false;
r_cons_flush ();
}
r_cons_pop ();
return NULL;
}
if (--core->cons->context->cmd_str_depth == 0) {
core->cons->context->noflush = false;
r_cons_flush ();
}
r_cons_pop ();
return NULL;
}
if (--core->cons->context->cmd_str_depth == 0) {
core->cons->context->noflush = false;
}
r_cons_filter ();
const char *static_str = r_cons_get_buffer ();

View File

@ -207,6 +207,7 @@ static const RCoreHelpMessage help_msg_aflx = {
static const char *help_msg_ai[] = {
"Usage:", "ai", "[j*] [sz] # analysis/address information/imports",
"ai", " @addr", "show address information",
"aia", "", "show architecture specific information instruction size and alignment details",
"aii", " [namespace]", "global import (like afii, but global)",
"aii", "-", "delete all global imports",
"aij", " @addr", "show address information in JSON format",
@ -2071,9 +2072,7 @@ R_API char *cmd_syscall_dostr(RCore *core, st64 n, ut64 addr) {
// XXX this is a hack to make syscall args work on x86-32 and x86-64
// we need to shift sn first.. which is bad, but needs to be redesigned
int regidx = i;
if (core->rasm->config->bits == 32 &&
((core->rasm->cur && !strcmp (core->rasm->cur->arch, "x86")) ||
(core->anal->cur && !strcmp (core->anal->cur->arch , "x86")))) {
if (core->rasm->config->bits == 32 && !strcmp (core->rasm->config->arch, "x86")) {
regidx++;
}
ut64 arg = r_debug_arg_get (core->dbg, cc, regidx);
@ -6120,6 +6119,57 @@ static void cmd_anal_info(RCore *core, const char *input) {
case ' ':
cmd_address_info (core, input, 0);
break;
case 'a': // "aia"
if (input[1] == 'j') { // "aiaj"
PJ *pj = pj_new ();
pj_o (pj);
int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE);
if (v > 0) {
pj_ki (pj, "minopsz", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE);
if (v > 0) {
pj_ki (pj, "maxopsz", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_INV_OP_SIZE);
if (v > 0) {
pj_ki (pj, "invopsz", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_DATA_ALIGN);
if (v > 0) {
pj_ki (pj, "dtalign", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN);
if (v > 0) {
pj_ki (pj, "pcalign", v);
}
pj_end (pj);
char *s = pj_drain (pj);
r_cons_printf ("%s\n", s);
free (s);
} else {
int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE);
if (v > 0) {
r_cons_printf ("minopsz %d\n", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE);
if (v > 0) {
r_cons_printf ("maxopsz %d\n", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_INV_OP_SIZE);
if (v > 0) {
r_cons_printf ("invopsz %d\n", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_DATA_ALIGN);
if (v > 0) {
r_cons_printf ("dtalign %d\n", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN);
if (v > 0) {
r_cons_printf ("pcalign %d\n", v);
}
}
break;
case 'i': // "aii"
// global imports
if (input[1]) {
@ -8082,7 +8132,7 @@ static void cmd_anal_opcode(RCore *core, const char *input) {
r_cons_println (d);
free (d);
} else {
eprintf ("Unknown mnemonic\n");
R_LOG_ERROR ("Unknown mnemonic");
}
} else {
eprintf ("Use: aod[?a] ([opcode]) describe current, [given] or all mnemonics\n");
@ -12829,7 +12879,7 @@ static int cmd_anal(void *data, const char *input) {
case 'j':
case 'q':
case 0:
rasm2_list (core, NULL, input[1]);
ranal2_list (core, NULL, input[1]);
break;
default:
// help

View File

@ -246,22 +246,6 @@ static void r_core_file_info(RCore *core, PJ *pj, int mode) {
pj_ks (pj, "referer", desc->referer);
}
}
int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE);
if (v > 0) {
pj_ki (pj, "minopsz", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE);
if (v > 0) {
pj_ki (pj, "maxopsz", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_INV_OP_SIZE);
if (v > 0) {
pj_ki (pj, "invopsz", v);
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN);
if (v > 0) {
pj_ki (pj, "pcalign", v);
}
pj_ki (pj, "block", core->blocksize);
if (binfile) {
if (binfile->curxtr) {
@ -293,22 +277,6 @@ static void r_core_file_info(RCore *core, PJ *pj, int mode) {
pair ("humansz", humansz);
}
}
int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE);
if (v > 0) {
pair ("minopsz", r_strf ("%d", v));
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE);
if (v > 0) {
pair ("maxopsz", r_strf ("%d", v));
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_INV_OP_SIZE);
if (v > 0) {
pair ("invopsz", r_strf ("%d", v));
}
v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN);
if (v > 0) {
pair ("pcalign", r_strf ("%d", v));
}
if (desc) {
pair ("mode", r_str_rwx_i (desc->perm & R_PERM_RWX));
}

View File

@ -4,7 +4,6 @@
#include "r_cons.h"
#include "r_core.h"
bool rasm2_list(RCore *core, const char *arch, int fmt);
bool ranal2_list(RCore *core, const char *arch, int fmt);
static const char *help_msg_La[] = {
@ -433,20 +432,19 @@ static int cmd_plugins(void *data, const char *input) {
if (input[1] == '?') { // "Ls?"
r_core_cmd_help_match (core, help_msg_L, "Ls", true);
} else { // asm plugins
// r_core_cmd0 (core, "e asm.arch=??");
rasm2_list (core, NULL, input[1]);
// rasm2_list (core, NULL, input[1]);
ranal2_list (core, NULL, input[1]);
}
break;
case 'A': // "LA"
case 'A': // "LA" // list arch plugins
if (input[1] == '?') {
// r_core_cmd_help (core, help_msg_LA);
r_core_cmd_help_match (core, help_msg_L, "LA", true);
} else {
RListIter *iter;
RArchPlugin *item;
r_list_foreach (core->anal->arch->plugins, iter, item) {
eprintf ("%s\n", item->name);
}
// r_core_cmd0 (core, "e asm.arch=??");
}
break;
case 'p': // "Lp"

View File

@ -3017,12 +3017,10 @@ static void printraw(RCore *core, int len, int mode) {
static void _handle_call(RCore *core, char *line, char **str) {
// XXX: rewrite this function
r_return_if_fail (core && line && str && ((core->rasm && core->rasm->cur) || (core->anal && core->anal->cur)));
if ((core->rasm && core->rasm->cur && strstr (core->rasm->cur->arch, "x86")) ||
(core->anal && core->anal->cur && strstr (core->anal->cur->arch, "x86"))) {
r_return_if_fail (core && line && str && (core->anal && core->anal->cur));
if (core->rasm && core->rasm->config && !strcmp (core->rasm->config->arch, "x86")) {
*str = strstr (line, "call ");
} else if ((core->rasm && core->rasm->cur && strstr (core->rasm->cur->arch, "arm")) ||
(core->anal && core->anal->cur && strstr (core->anal->cur->arch, "arm"))) {
} else if (core->rasm && core->rasm->config && !strcmp (core->rasm->config->arch, "arm")) {
*str = strstr (line, " b ");
if (*str && strstr (*str, " 0x")) {
/*

View File

@ -3194,9 +3194,9 @@ static void search_similar_pattern(RCore *core, int count, struct search_paramet
static bool isArm(RCore *core) {
RAsm *as = core ? core->rasm : NULL;
if (as && as->cur && as->cur->arch) {
if (r_str_startswith (as->cur->arch, "arm")) {
if (as->cur->bits < 64) {
if (as && as->config && as->config->arch) {
if (r_str_startswith (as->config->arch, "arm")) {
if (as->config->bits < 64) {
return true;
}
}

View File

@ -5913,9 +5913,11 @@ toro:
if (core->rasm->config->syntax != R_ARCH_SYNTAX_INTEL) {
RAsmOp ao; /* disassemble for the vm .. */
int os = core->rasm->config->syntax;
r_asm_set_syntax (core->rasm, R_ARCH_SYNTAX_INTEL);
// r_asm_set_syntax (core->rasm, R_ARCH_SYNTAX_INTEL);
r_arch_config_set_syntax (core->rasm->config, R_ARCH_SYNTAX_INTEL);
r_asm_disassemble (core->rasm, &ao, ds_bufat (ds), ds_left (ds) + 5);
r_asm_set_syntax (core->rasm, os);
// r_asm_set_syntax (core->rasm, os);
r_arch_config_set_syntax (core->anal->config, os);
r_asm_op_fini (&ao);
}
if (mi_type == R_META_TYPE_FORMAT) {
@ -5953,9 +5955,11 @@ toro:
if (core->rasm->config->syntax != R_ARCH_SYNTAX_INTEL) {
RAsmOp ao; /* disassemble for the vm .. */
int os = core->rasm->config->syntax;
r_asm_set_syntax (core->rasm, R_ARCH_SYNTAX_INTEL);
// r_asm_set_syntax (core->rasm, R_ARCH_SYNTAX_INTEL);
r_arch_config_set_syntax (core->anal->config, R_ARCH_SYNTAX_INTEL);
r_asm_disassemble (core->rasm, &ao, ds_bufat (ds), ds_left (ds) + 5);
r_asm_set_syntax (core->rasm, os);
// r_asm_set_syntax (core->rasm, os);
r_arch_config_set_syntax (core->anal->config, os);
r_asm_op_fini (&ao);
}
if (ds->show_bytes_right && ds->show_bytes) {

View File

@ -39,7 +39,7 @@ CB (lang, lang)
CB (anal, anal)
#define r_esil_add r_esil_plugin_add
CB (esil, anal->esil)
CB (asm, rasm)
// CB (asm, rasm)
CB (parse, parser)
CB (bin, bin)
CB (egg, egg)
@ -105,7 +105,7 @@ R_API void r_core_loadlibs_init(RCore *core) {
DF (LANG, "language plugins", lang);
DF (ANAL, "analysis plugins", anal);
DF (ESIL, "esil emulation plugins", esil);
DF (ASM, "(dis)assembler plugins", asm);
// DF (ASM, "(dis)assembler plugins", asm);
DF (PARSE, "parsing plugins", parse);
DF (BIN, "bin plugins", bin);
DF (EGG, "egg plugins", egg);

View File

@ -419,7 +419,7 @@ static void rotateAsmBits(RCore *core) {
bits == 32 ? 64:
bits == 16 ? 32:
bits == 8 ? 16: bits;
if ((core->rasm->cur->bits & nb) == nb) {
if ((core->rasm->config->bits & nb) == nb) {
r_core_cmdf (core, "ahb %d", nb);
break;
}

View File

@ -84,11 +84,11 @@ beach:
R_API bool r_egg_add(REgg *a, REggPlugin *foo) {
r_return_val_if_fail (a && foo, false);
RListIter *iter;
RAsmPlugin *h;
// TODO: cache foo->name length and use memcmp instead of strcmp
if (!foo->name) {
return false;
}
REggPlugin *h;
r_list_foreach (a->plugins, iter, h) {
if (!strcmp (h->name, foo->name)) {
return false;
@ -345,7 +345,8 @@ R_API bool r_egg_assemble_asm(REgg *egg, char **asm_list) {
r_asm_use_assembler (egg->rasm, asm_name);
r_asm_set_bits (egg->rasm, egg->bits);
r_asm_set_big_endian (egg->rasm, egg->endian);
r_asm_set_syntax (egg->rasm, R_ARCH_SYNTAX_INTEL);
// r_asm_set_syntax (egg->rasm, R_ARCH_SYNTAX_INTEL);
r_arch_config_set_syntax (egg->rasm->config, R_ARCH_SYNTAX_INTEL);
code = r_buf_tostring (egg->buf);
asmcode = r_asm_massemble (egg->rasm, code);
if (asmcode) {

View File

@ -552,7 +552,7 @@ R_API R_DEPRECATE RAnalVar *r_anal_get_used_function_var(RAnal *anal, ut64 addr)
typedef RAnalFunction *(* RAnalGetFcnIn)(RAnal *anal, ut64 addr, int type);
typedef RAnalHint *(* RAnalGetHint)(RAnal *anal, ut64 addr);
typedef char *(* RAnalMnemonics)(RAnal *anal, int id, bool json);
typedef int (* RAnalEncode)(RAnal *anal, ut64 addr, const char *s, const ut8 *data, int len);
typedef int (* RAnalEncode)(RAnal *anal, ut64 addr, const char *s, ut8 *data, int len);
typedef int (* RAnalDecode)(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask);
typedef void (* RAnalOpInit)(RAnalOp *op);
typedef void (* RAnalOpFini)(RAnalOp *op);

View File

@ -182,6 +182,7 @@ R_API bool r_arch_set_arch(RArch *arch, char *archname);
// aconfig.c
R_API void r_arch_config_use(RArchConfig *config, R_NULLABLE const char *arch);
R_API void r_arch_config_set_cpu(RArchConfig *config, R_NULLABLE const char *cpu);
R_API bool r_arch_config_set_syntax(RArchConfig *config, int syntax);
R_API bool r_arch_config_set_bits(RArchConfig *c, int bits);
R_API RArchConfig *r_arch_config_new(void);
R_API RArchConfig *r_arch_config_clone(RArchConfig *c);

View File

@ -16,14 +16,6 @@ extern "C" {
R_LIB_VERSION_HEADER(r_asm);
enum {
R_ASM_MOD_RAWVALUE = 'r',
R_ASM_MOD_VALUE = 'v',
R_ASM_MOD_DSTREG = 'd',
R_ASM_MOD_SRCREG0 = '0',
R_ASM_MOD_SRCREG1 = '1',
R_ASM_MOD_SRCREG2 = '2'
};
// XXX should be using RArchOp !!!
typedef struct r_asm_op_t {
int size; // instruction size (must be deprecated. just use buf.len
@ -55,7 +47,6 @@ typedef struct {
char *value;
} RAsmEqu;
#define _RAsmPlugin struct r_asm_plugin_t
typedef struct r_asm_t {
RArch *arch;
RArchConfig *config;
@ -63,8 +54,12 @@ typedef struct r_asm_t {
void *user;
RArchSession *ecur; // encode current
RArchSession *dcur; // decode current
_RAsmPlugin *cur; // disassemble .. should be RArchPlugin DEPRECATE
_RAsmPlugin *acur; // assemble DEPRECATE
#if 0
void *cur; // deprecate
void *acur; // deprecate
#endif
// _RAsmPlugin *cur; // disassemble .. should be RArchPlugin DEPRECATE
// _RAsmPlugin *acur; // assemble DEPRECATE
// RArchSession *cur;
// RArchSession *acur;
RList *plugins;
@ -76,29 +71,12 @@ typedef struct r_asm_t {
RNum *num;
int dataalign;
HtPP *flags;
bool pseudo;
bool pseudo; // should be implicit by RParse
RParse *parse;
} RAsm;
typedef bool (*RAsmModifyCallback)(RAsm *a, ut8 *buf, int field, ut64 val);
typedef int (*RAsmAssembleCallback)(RAsm *a, RAsmOp *op, const char *buf);
typedef struct r_asm_plugin_t {
const char *name;
const char *arch;
const char *author;
const char *version;
const char *cpus;
const char *desc;
const char *license;
void *user; // user data pointer
int bits;
int endian;
RAsmAssembleCallback assemble;
RArchPluginEncodeCallback encode;
} RAsmPlugin;
#ifdef R_API
/* asm.c */
R_API RAsm *r_asm_new(void);
R_API void r_asm_free(RAsm *a);
@ -106,11 +84,12 @@ R_API bool r_asm_modify(RAsm *a, ut8 *buf, int field, ut64 val);
R_API char *r_asm_mnemonics(RAsm *a, int id, bool json);
R_API int r_asm_mnemonics_byname(RAsm *a, const char *name);
R_API void r_asm_set_user_ptr(RAsm *a, void *user);
R_API bool r_asm_add(RAsm *a, RAsmPlugin *foo);
R_API bool r_asm_is_valid(RAsm *a, const char *name);
R_API bool r_asm_use(RAsm *a, const char *name);
R_API bool r_asm_use_assembler(RAsm *a, const char *name);
// this is in archconfig
R_API bool r_asm_set_arch(RAsm *a, const char *name, int bits);
R_API int r_asm_set_bits(RAsm *a, int bits);
R_API void r_asm_set_cpu(RAsm *a, const char *cpu);
@ -120,7 +99,7 @@ R_API bool r_asm_set_syntax(RAsm *a, int syntax); // This is in RArchConfig
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);
// R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf);
R_API RAsmCode* r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len);
R_API RAsmCode* r_asm_mdisassemble_hexstr(RAsm *a, RParse *p, const char *hexstr);
R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf);
@ -158,14 +137,6 @@ R_API int r_asm_op_set_hexbuf(RAsmOp *op, const ut8 *buf, int len);
R_API void r_asm_op_set_buf(RAsmOp *op, const ut8 *str, int len);
R_API ut8 *r_asm_op_get_buf(RAsmOp *op);
/* plugin pointers */
extern RAsmPlugin r_asm_plugin_null;
extern RAsmPlugin r_asm_plugin_arm_as;
extern RAsmPlugin r_asm_plugin_ppc_as;
extern RAsmPlugin r_asm_plugin_sparc_gnu;
extern RAsmPlugin r_asm_plugin_x86_as;
extern RAsmPlugin r_asm_plugin_x86_nasm;
#endif
#ifdef __cplusplus

View File

@ -25,7 +25,7 @@ typedef struct r_lang_t {
struct r_lang_session_t *session;
} RLang;
typedef struct r_lang_session_t RLangSession;
typedef struct r_lang_session_t _RLangSession;
typedef struct r_lang_plugin_t {
const char *name;
@ -36,13 +36,13 @@ typedef struct r_lang_plugin_t {
const char *license;
const char **help;
const char *ext;
void *(*init)(RLangSession *s);
bool (*setup)(RLangSession *s);
bool (*fini)(RLangSession *s);
bool (*prompt)(RLangSession *s);
bool (*run)(RLangSession *s, const char *code, int len);
bool (*run_file)(RLangSession *s, const char *file);
int (*set_argv)(RLangSession *s, int argc, char **argv);
void *(*init)(_RLangSession *s);
bool (*setup)(_RLangSession *s);
bool (*fini)(_RLangSession *s);
bool (*prompt)(_RLangSession *s);
bool (*run)(_RLangSession *s, const char *code, int len);
bool (*run_file)(_RLangSession *s, const char *file);
int (*set_argv)(_RLangSession *s, int argc, char **argv);
} RLangPlugin;
typedef struct r_lang_def_t {

View File

@ -318,93 +318,6 @@ static void ranal2_list(RAsmState *as, const char *arch) {
pj_free (pj);
}
static void rasm2_list(RAsmState *as, const char *arch) {
int i;
char bits[32];
const char *feat2, *feat;
RAsmPlugin *h;
RListIter *iter;
PJ *pj = pj_new ();
if (!pj) {
return;
}
if (as->json) {
pj_a (pj);
}
r_list_foreach (as->a->plugins, iter, h) {
if (arch) {
if (h->cpus && !strcmp (arch, h->name)) {
char *c = strdup (h->cpus);
int n = r_str_split (c, ',');
for (i = 0; i < n; i++) {
printf ("%s\n", r_str_word_get0 (c, i));
}
free (c);
break;
}
} else {
bits[0] = 0;
if (h->bits == 27) {
strcat (bits, "27");
} else if (h->bits == 0) {
strcat (bits, "any");
} else {
if (h->bits & 4) {
strcat (bits, "4 ");
}
if (h->bits & 8) {
strcat (bits, "8 ");
}
if (h->bits & 16) {
strcat (bits, "16 ");
}
if (h->bits & 32) {
strcat (bits, "32 ");
}
if (h->bits & 64) {
strcat (bits, "64 ");
}
}
feat = "__";
if (h->assemble) {
feat = "a_";
}
feat2 = has_esil (as, h->name);
if (as->quiet) {
printf ("%s\n", h->name);
} else if (as->json) {
pj_o (pj);
pj_ks (pj, "name", h->name);
pj_k (pj, "bits");
pj_a (pj);
pj_i (pj, 32);
pj_i (pj, 64);
pj_end (pj);
pj_ks (pj, "license", r_str_get_fail (h->license, "unknown"));
pj_ks (pj, "description", h->desc);
pj_ks (pj, "features", feat);
pj_end (pj);
} else {
printf ("%s%s %-11s %-11s %-7s %s",
feat, feat2, bits, h->name,
r_str_get_fail (h->license, "unknown"), h->desc);
if (h->author) {
printf (" (by %s)", h->author);
}
if (h->version) {
printf (" v%s", h->version);
}
printf ("\n");
}
}
}
if (as->json) {
pj_end (pj);
printf ("%s\n", pj_string (pj));
pj_free (pj);
}
}
static int rasm_show_help(int v) {
if (v < 2) {
printf ("Usage: rasm2 [-ACdDehLBvw] [-a arch] [-b bits] [-o addr] [-s syntax]\n"
@ -707,14 +620,6 @@ static bool rasm_asm(RAsmState *as, const char *buf, ut64 offset, ut64 len, int
return (ret > 0);
}
/* asm callback */
static int __lib_asm_cb(RLibPlugin *pl, void *user, void *data) {
RAsmPlugin *hand = (RAsmPlugin *)data;
RAsmState *as = (RAsmState *)user;
r_asm_add (as->a, hand);
return true;
}
/* anal callback */
static int __lib_anal_cb(RLibPlugin *pl, void *user, void *data) {
RAnalPlugin *hand = (RAnalPlugin *)data;
@ -723,6 +628,14 @@ static int __lib_anal_cb(RLibPlugin *pl, void *user, void *data) {
return true;
}
/* arch callback */
static int __lib_arch_cb(RLibPlugin *pl, void *user, void *data) {
RArchPlugin *hand = (RArchPlugin *)data;
RAsmState *as = (RAsmState *)user;
r_arch_add (as->anal->arch, hand);
return true;
}
static int print_assembly_output(RAsmState *as, const char *buf, ut64 offset, ut64 len, int bits, int bin, bool use_spp, bool rad, bool hexwords, const char *arch) {
if (rad) {
printf ("e asm.arch=%s\n", arch? arch: R_SYS_ARCH);
@ -749,11 +662,12 @@ static void __load_plugins(RAsmState *as) {
free (tmp);
return;
}
r_lib_add_handler (as->l, R_LIB_TYPE_ASM, "(dis)assembly plugins", &__lib_asm_cb, NULL, as);
// r_lib_add_handler (as->l, R_LIB_TYPE_ASM, "(dis)assembly plugins", &__lib_asm_cb, NULL, as);
r_lib_add_handler (as->l, R_LIB_TYPE_ANAL, "analysis/emulation plugins", &__lib_anal_cb, NULL, as);
r_lib_add_handler (as->l, R_LIB_TYPE_ARCH, "architecture plugins", &__lib_arch_cb, NULL, as);
char *path = r_sys_getenv (R_LIB_ENV);
if (path && *path) {
if (R_STR_ISNOTEMPTY (path)) {
r_lib_opendir (as->l, path);
}
@ -809,7 +723,6 @@ R_API int r_main_rasm2(int argc, const char *argv[]) {
const char *file = NULL;
bool list_plugins = false;
bool list_anal_plugins = false;
bool list_arch_plugins = false;
bool isbig = false;
bool rad = false;
bool use_spp = false;
@ -900,7 +813,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) {
break;
case 'L':
if (list_anal_plugins) {
list_arch_plugins = true;
// ignored
} else if (list_plugins) {
list_anal_plugins = true;
} else {
@ -939,7 +852,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) {
__as_free (as);
return 1;
}
r_asm_set_syntax (as->a, syntax);
r_arch_config_set_syntax (as->a->config, syntax);
}
break;
case 'v':
@ -965,18 +878,13 @@ R_API int r_main_rasm2(int argc, const char *argv[]) {
ret = rasm_show_help (help > 1? 2: 0);
goto beach;
}
if (list_arch_plugins) {
rarch2_list (as, opt.argv[opt.ind]);
ret = 1;
goto beach;
}
if (list_anal_plugins) {
ranal2_list (as, opt.argv[opt.ind]);
ret = 1;
goto beach;
}
if (list_plugins) {
rasm2_list (as, opt.argv[opt.ind]);
rarch2_list (as, opt.argv[opt.ind]);
ret = 1;
goto beach;
}

View File

@ -1,17 +1,23 @@
NAME=offs390 bininfo
FILE=bins/s390/zos/prueba/prueba
CMDS=<<EOF
-a
aia
?e --
i
EOF
EXPECT=<<EOF
s390
minopsz 2
maxopsz 6
invopsz 2
dtalign 1
pcalign 1
--
fd 3
file bins/s390/zos/prueba/prueba
size 0x11000
humansz 68K
minopsz 2
maxopsz 6
invopsz 2
pcalign 1
mode r-x
format off
iorw false

View File

@ -31,8 +31,8 @@ e io.cache=true
EOF
EXPECT=<<EOF
file A\x1b¢€€𝄞󠁁\.bin
{"core":{"type":"","file":"A\u001b¢\u0080€𝄞\udb40\udc41\\.bin","fd":3,"size":256,"humansz":"256","iorw":true,"mode":"r-x","minopsz":1,"maxopsz":16,"invopsz":1,"block":256,"format":"any"}}
{"core":{"type":"","file":"A\u001b¢\u0080€𝄞\udb40\udc41\\.bin","fd":3,"size":256,"humansz":"256","iorw":true,"mode":"r-x","block":256,"format":"any"}}
file B\x1b¢€€𝄞󠁁\.bin
{"core":{"type":"","file":"B\u001b¢\u0080€𝄞\udb40\udc41\\.bin","fd":4,"size":256,"humansz":"256","iorw":true,"mode":"r-x","minopsz":1,"maxopsz":16,"invopsz":1,"block":256,"format":"any"}}
{"core":{"type":"","file":"B\u001b¢\u0080€𝄞\udb40\udc41\\.bin","fd":4,"size":256,"humansz":"256","iorw":true,"mode":"r-x","block":256,"format":"any"}}
EOF
RUN

View File

@ -11,8 +11,8 @@ e io.cache=true
EOF
EXPECT=<<EOF
file A\x1b¢€€𝄞󠁁\.bin
{"core":{"type":"","file":"A\u001b¢\u0080€𝄞\udb40\udc41\\.bin","fd":4,"size":256,"humansz":"256","iorw":true,"mode":"r-x","minopsz":1,"maxopsz":16,"invopsz":1,"block":256,"format":"any"}}
{"core":{"type":"","file":"A\u001b¢\u0080€𝄞\udb40\udc41\\.bin","fd":4,"size":256,"humansz":"256","iorw":true,"mode":"r-x","block":256,"format":"any"}}
file B\x1b¢€€𝄞󠁁\.bin
{"core":{"type":"","file":"B\u001b¢\u0080€𝄞\udb40\udc41\\.bin","fd":5,"size":256,"humansz":"256","iorw":true,"mode":"r-x","minopsz":1,"maxopsz":16,"invopsz":1,"block":256,"format":"any"}}
{"core":{"type":"","file":"B\u001b¢\u0080€𝄞\udb40\udc41\\.bin","fd":5,"size":256,"humansz":"256","iorw":true,"mode":"r-x","block":256,"format":"any"}}
EOF
RUN

View File

@ -213,9 +213,6 @@ fd 3
file malloc://1025
size 0x401
humansz 1.0K
minopsz 1
maxopsz 16
invopsz 1
mode rwx
format any
iorw true
@ -289,9 +286,6 @@ fd 3
file malloc://1024
size 0x400
humansz 1K
minopsz 1
maxopsz 16
invopsz 1
mode rwx
format any
iorw true
@ -331,9 +325,6 @@ EXPECT=<<EOF
fd 3
size 0x1323
humansz 4.8K
minopsz 1
maxopsz 16
invopsz 1
mode r-x
format elf
iorw false
@ -3189,9 +3180,6 @@ EXPECT=<<EOF
fd 3
size 0x1a36
humansz 6.6K
minopsz 1
maxopsz 16
invopsz 1
mode r-x
format elf64
iorw false
@ -3515,9 +3503,6 @@ EXPECT=<<EOF
fd 3
size 0x1a36
humansz 6.6K
minopsz 1
maxopsz 16
invopsz 1
mode r-x
iorw false
block 0x100

View File

@ -514,9 +514,6 @@ fd 3
file bins/elf/true32
size 0x560c
humansz 21.5K
minopsz 1
maxopsz 16
invopsz 1
mode r-x
format elf
iorw false
@ -554,9 +551,6 @@ fd 3
file malloc://512
size 0x200
humansz 512
minopsz 1
maxopsz 16
invopsz 1
mode rwx
format any
iorw true

View File

@ -199,9 +199,6 @@ EXPECT=<<EOF
fd 3
file malloc://1024
humansz 1K
minopsz 1
maxopsz 16
invopsz 1
mode rwx
format any
iorw true
@ -217,9 +214,6 @@ EXPECT=<<EOF
fd 3
file malloc://1024
humansz 1K
minopsz 1
maxopsz 16
invopsz 1
mode rwx
format any
iorw true
@ -235,9 +229,6 @@ EXPECT=<<EOF
file malloc://1024
size 0x400
humansz 1K
minopsz 1
maxopsz 16
invopsz 1
mode rwx
format any
iorw true
@ -559,9 +550,6 @@ json.core.size = 7441;
json.core.humansz = "7.3K";
json.core.iorw = false;
json.core.mode = "r-x";
json.core.minopsz = 1;
json.core.maxopsz = 16;
json.core.invopsz = 1;
json.core.block = 256;
json.core.format = "elf64";
json.bin = {};
@ -604,23 +592,23 @@ RUN
NAME=ij.gron.grep
FILE=bins/elf/crackme
CMDS=<<EOF
ij~{=}opsz
aiaj~{=}opsz
EOF
EXPECT=<<EOF
json.core.minopsz = 1;
json.core.maxopsz = 16;
json.core.invopsz = 1;
json.minopsz = 1;
json.maxopsz = 16;
json.invopsz = 1;
EOF
RUN
NAME=ij.gron.grep.two
FILE=bins/elf/crackme
CMDS=<<EOF
ij~{=}~opsz
aiaj~{=}~opsz
EOF
EXPECT=<<EOF
json.core.minopsz = 1;
json.core.maxopsz = 16;
json.core.invopsz = 1;
json.minopsz = 1;
json.maxopsz = 16;
json.invopsz = 1;
EOF
RUN

View File

@ -438,9 +438,6 @@ fd 3
file bins/elf/analysis/guess-number-riscv64
size 0x9d5a8
humansz 629.4K
minopsz 2
maxopsz 4
invopsz 2
mode r-x
format elf64
iorw false

View File

@ -1,18 +1,22 @@
NAME=ELF: ired v800
FILE=bins/v850/ired_v850
CMDS=<<EOF
aia
?e --
i
s+4
pd 3
EOF
EXPECT=<<EOF
minopsz 2
maxopsz 8
dtalign 2
pcalign 2
--
fd 3
file bins/v850/ired_v850
size 0xedeb8
humansz 951.7K
minopsz 2
maxopsz 8
pcalign 2
mode r-x
format elf
iorw false

View File

@ -10,10 +10,6 @@ fd 3
file bins/other/amiga-hunk-mc0201
size 0xcc
humansz 204
minopsz 2
maxopsz 6
invopsz 2
pcalign 2
mode r-x
format hunk
iorw false

View File

@ -9,9 +9,6 @@ fd 3
file bins/msx/testmsx.rom
size 0x2000
humansz 8K
minopsz 1
maxopsz 3
invopsz 1
mode r-x
format msx
iorw false

View File

@ -5,10 +5,6 @@ EXPECT=<<EOF
file bins/smd/LiquidSpaceDodgerV3.bin
size 0x272f8
humansz 156.7K
minopsz 2
maxopsz 6
invopsz 2
pcalign 2
mode r-x
format smd
iorw false

View File

@ -15,10 +15,6 @@ fd 3
file bins/wasm/dotnet.wasm
size 0x2ae89a
humansz 2.7M
minopsz 1
maxopsz 1
invopsz 1
pcalign 1
mode r-x
format wasm
iorw false

View File

@ -31,7 +31,9 @@ FILE=-
CMDS=<<EOF
!!rasm2 -L~4004
EOF
EXPECT=
EXPECT=<<EOF
ade 4 i4004 LGPL3 i4004 decoder plugin (by pancake, condret)
EOF
RUN
NAME=rasm2 arm asm/dis endian