mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-01 00:51:19 +00:00
moar rarch
This commit is contained in:
parent
b626e08e29
commit
bfdd3da987
124
libr/arch/arch.c
124
libr/arch/arch.c
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2022 - pancake */
|
||||
/* radare - LGPL - Copyright 2022 - pancake, condret */
|
||||
|
||||
#include <r_arch.h>
|
||||
#include <config.h>
|
||||
@ -8,8 +8,16 @@ static const RArchPlugin * const arch_static_plugins[] = { R_ARCH_STATIC_PLUGINS
|
||||
static void plugin_free (void *p) {
|
||||
}
|
||||
|
||||
static void _decoder_free_cb (HtPPKv *kv) {
|
||||
free (kv->key);
|
||||
RArchDecoder *decoder = (RArchDecoder *)kv->value;
|
||||
if (decoder->p->fini) {
|
||||
decoder->p->fini (decoder->user);
|
||||
}
|
||||
free (decoder);
|
||||
}
|
||||
|
||||
R_API RArch *r_arch_new(void) {
|
||||
int i;
|
||||
RArch *a = R_NEW0 (RArch);
|
||||
if (!a) {
|
||||
return NULL;
|
||||
@ -19,53 +27,103 @@ R_API RArch *r_arch_new(void) {
|
||||
free (a);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; arch_static_plugins[i]; i++) {
|
||||
a->decoders = ht_pp_new (NULL, _decoder_free_cb, NULL);
|
||||
if (!a->decoders) {
|
||||
r_list_free (a->plugins);
|
||||
free (a);
|
||||
return NULL;
|
||||
}
|
||||
ut32 i = 0;
|
||||
while (arch_static_plugins[i++]) {
|
||||
r_arch_add (a, (RArchPlugin*)arch_static_plugins[i]);
|
||||
}
|
||||
return NULL;
|
||||
return a;
|
||||
}
|
||||
|
||||
R_API int r_arch_del(RArch *a, const char *name) {
|
||||
/* TODO: r_arch_del not implemented */
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API bool r_arch_add(RArch *a, RArchPlugin *foo) {
|
||||
if (!foo->name) {
|
||||
R_API bool r_arch_use(RArch *a, RArchConfig *config) {
|
||||
r_return_val_if_fail (a && config && config->arch, false);
|
||||
ut32 bits_bits;
|
||||
switch (config->bits) {
|
||||
case 64:
|
||||
bits_bits = R_SYS_BITS_64;
|
||||
break;
|
||||
case 32:
|
||||
bits_bits = R_SYS_BITS_32;
|
||||
break;
|
||||
case 27:
|
||||
bits_bits = R_SYS_BITS_27;
|
||||
break;
|
||||
case 16:
|
||||
bits_bits = R_SYS_BITS_16;
|
||||
break;
|
||||
case 8:
|
||||
bits_bits = R_SYS_BITS_8;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
// TODO: do more checks
|
||||
r_list_append (a->plugins, foo);
|
||||
char *dname = NULL;
|
||||
RArchPlugin *p = NULL;
|
||||
RListIter *iter;
|
||||
r_list_foreach (a->plugins, iter, p) {
|
||||
if (!strcmp (p->arch, config->arch)) {
|
||||
//TODO: add more checks here
|
||||
const int info_bits = p->info (R_ARCH_INFO_BITS);
|
||||
if (info_bits == -1) {
|
||||
continue;
|
||||
}
|
||||
if (info_bits & bits_bits) {
|
||||
dname = p->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!dname) {
|
||||
return false;
|
||||
}
|
||||
r_ref (config);
|
||||
if (a->cfg) {
|
||||
r_unref (a->cfg);
|
||||
}
|
||||
r_arch_use_decoder (a, dname); //use load here?
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API void r_arch_free(RArch *a) {
|
||||
free (a);
|
||||
R_API bool r_arch_add(RArch *a, RArchPlugin *ap) {
|
||||
r_return_val_if_fail (a && ap->name && ap->arch && ap->info, false);
|
||||
return !!r_list_append (a->plugins, ap);
|
||||
}
|
||||
|
||||
R_API RArchDecoder *r_arch_use(RArch *a, RArchConfig *ac, const char *name) {
|
||||
static bool _pick_any_decoder_as_current (void *user, const char *dname, const void *dec) {
|
||||
RArch *arch = (RArch *)user;
|
||||
arch->current = (RArchDecoder *)dec;
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API bool r_arch_del(RArch *a, const char *name) {
|
||||
r_return_val_if_fail (a && a->plugins && name, false);
|
||||
if (a->current && !strcmp (a->current->p->name, name)) {
|
||||
a->current = NULL;
|
||||
}
|
||||
if (a->decoders) {
|
||||
ht_pp_delete (a->decoders, name);
|
||||
}
|
||||
RListIter *iter;
|
||||
RArchPlugin *ap = NULL;
|
||||
RArchPlugin *p = NULL;
|
||||
RArchPlugin *p;
|
||||
r_list_foreach (a->plugins, iter, p) {
|
||||
if (!strcmp (name, p->name)) {
|
||||
ap = p;
|
||||
break;
|
||||
r_list_delete (a->plugins, iter);
|
||||
if (!a->current) {
|
||||
ht_pp_foreach (a->decoders, (HtPPForeachCallback)_pick_any_decoder_as_current, a);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (ap) {
|
||||
RArchDecoder *ad = R_NEW0 (RArchDecoder);
|
||||
ad->data = ap->init ((void *)a, ac);
|
||||
ad->p = ap;
|
||||
ad->ac = ac; // XXX copy instead of reference?
|
||||
return ad;
|
||||
}
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
R_API RArchOp *r_arch_decode(RArchDecoder *ad, const ut8 *buf, size_t len) {
|
||||
ad->p->decode (ad, buf, len);
|
||||
return NULL;
|
||||
R_API void r_arch_free(RArch *a) {
|
||||
r_return_if_fail (a);
|
||||
ht_pp_free (a->decoders);
|
||||
r_list_free (a->plugins);
|
||||
free (a);
|
||||
}
|
||||
#endif
|
||||
|
@ -3,8 +3,6 @@
|
||||
#include <r_arch.h>
|
||||
#include <r_util.h>
|
||||
|
||||
#if 1
|
||||
|
||||
R_API bool r_arch_load_decoder(RArch *arch, const char *dname) {
|
||||
r_return_val_if_fail (dname && arch && arch->plugins && arch->decoders, false);
|
||||
RArchDecoder *decoder = (RArchDecoder *)ht_pp_find (arch->decoders, dname, NULL);
|
||||
@ -88,11 +86,7 @@ R_API bool r_arch_unload_decoder(RArch *arch, const char *dname) {
|
||||
if (decoder->refctr) {
|
||||
return true;
|
||||
}
|
||||
if (decoder->p->fini) {
|
||||
decoder->p->fini (decoder->user);
|
||||
}
|
||||
ht_pp_delete (arch->decoders, decoder->p->name);
|
||||
free (decoder);
|
||||
if (arch->current == decoder) {
|
||||
arch->current = NULL;
|
||||
ht_pp_foreach (arch->decoders, (HtPPForeachCallback)_pick_any_decoder_as_current, arch);
|
||||
@ -127,5 +121,3 @@ R_API int r_arch_decode(RArch *arch, const char *dname, RArchOp *op, ut64 addr,
|
||||
}
|
||||
return decoder->p->decode (arch, op, addr, data, len, mask);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* radare - LGPL - Copyright 2022 - pancake */
|
||||
|
||||
#include <r_arch.h>
|
||||
#include <r_util.h>
|
||||
|
||||
#if 0
|
||||
static int null_arch(RArch *arch, RArchOp *op, ut64 addr, const ut8 *data, int len, RArchOpMask mask) {
|
||||
@ -12,12 +13,19 @@ static bool null_set_reg_profile(RArch* arch) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static int info (ut32 query) {
|
||||
if (query == R_ARCH_INFO_BITS) {
|
||||
return R_SYS_BITS_64 | R_SYS_BITS_32 | R_SYS_BITS_27 | R_SYS_BITS_16 | R_SYS_BITS_8;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
RArchPlugin r_arch_plugin_null = {
|
||||
.name = "null",
|
||||
.desc = "Fallback/Null archysis plugin",
|
||||
.arch = "none",
|
||||
.license = "LGPL3",
|
||||
// .bits = 8|16|32|64,
|
||||
.info = info,
|
||||
// .op = &null_arch,
|
||||
// .set_reg_profile = &null_set_reg_profile,
|
||||
};
|
||||
|
@ -376,10 +376,6 @@ R_API bool r_asm_use(RAsm *a, const char *name) {
|
||||
r_asm_set_cpu (a, NULL);
|
||||
}
|
||||
a->cur = h;
|
||||
#if 0
|
||||
r_arch_use (a->config, h->arch);
|
||||
r_arch_use (a->config, h->name);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
@ -391,7 +387,6 @@ R_API bool r_asm_use(RAsm *a, const char *name) {
|
||||
r_arch_config_set_cpu (a->config, arch);
|
||||
// r_asm_set_cpu (a, arch);
|
||||
// h->arch = name;
|
||||
// r_arch_use (a->config, arch);
|
||||
#else
|
||||
r_asm_set_cpu (a, arch);
|
||||
#endif
|
||||
|
@ -44,7 +44,6 @@ typedef struct r_arch_config_t {
|
||||
R_REF_TYPE;
|
||||
} RArchConfig;
|
||||
|
||||
#if 1
|
||||
// XXX: this definition is plain wrong. use enum or empower bits
|
||||
#define R_ARCH_OP_TYPE_MASK 0x8000ffff
|
||||
#define R_ARCH_OP_HINT_MASK 0xf0000000
|
||||
@ -352,8 +351,6 @@ typedef struct r_arch_plugin_t {
|
||||
// void (*esil_fini)(RAnalEsil *esil);
|
||||
} RArchPlugin;
|
||||
|
||||
//R_API RArch *r_arch_new(void);
|
||||
//R_API void r_arch_free(RArch *arch);
|
||||
//dname is name of decoder to use, NULL if current
|
||||
R_API bool r_arch_load_decoder(RArch *arch, const char *dname);
|
||||
R_API bool r_arch_use_decoder(RArch *arch, const char *dname);
|
||||
@ -364,16 +361,15 @@ R_API bool r_arch_set_reg_profile(RArch *arch, const char *dname, struct r_reg_t
|
||||
//R_API bool r_arch_esil_init(RArch *arch, const char *dname, RAnalEsil *esil);
|
||||
//R_API void r_arch_esil_fini(RArch *arch, const char *dname, RAnalEsil *esil);
|
||||
|
||||
#endif
|
||||
|
||||
// arch
|
||||
R_API RArchDecoder *r_arch_use(RArch *arch, RArchConfig *config, const char *name);
|
||||
R_API RArch *r_arch_new(void);
|
||||
R_API bool r_arch_use(RArch *arch, RArchConfig *config);
|
||||
R_API bool r_arch_add(RArch *arch, RArchPlugin *ap);
|
||||
R_API bool r_arch_del(RArch *arch, const char *name);
|
||||
R_API void r_arch_free(RArch *arch);
|
||||
|
||||
R_API void r_arch_config_use(RArchConfig *config, R_NULLABLE const char *arch);
|
||||
R_API bool r_arch_add(RArch *a, RArchPlugin *foo);
|
||||
R_API int r_arch_del(RArch *a, const char *name);
|
||||
R_API void r_arch_free(RArch *a);
|
||||
// aconfig
|
||||
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 void r_arch_config_set_bits(RArchConfig *config, int bits);
|
||||
R_API RArchConfig *r_arch_config_new(void);
|
||||
|
Loading…
Reference in New Issue
Block a user