mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-15 11:48:12 +00:00
More refactorings and api redesigns in r_arch ##api
This commit is contained in:
parent
6e93407f29
commit
c9b90b8926
@ -257,9 +257,16 @@ R_API bool r_anal_use(RAnal *anal, const char *name) {
|
||||
}
|
||||
|
||||
R_API char *r_anal_get_reg_profile(RAnal *anal) {
|
||||
RArchSession *session = R_UNWRAP3 (anal, arch, session);
|
||||
RArchPluginRegistersCallback regs = R_UNWRAP3 (session, plugin, regs);
|
||||
if (regs) {
|
||||
return regs (session);
|
||||
}
|
||||
#if 0
|
||||
if (anal->arch && anal->arch->current && anal->arch->current->p && anal->arch->current->p->set_reg_profile) {
|
||||
eprintf ("WINRAR must get wat awat at\n");
|
||||
}
|
||||
#endif
|
||||
return (anal && anal->cur && anal->cur->get_reg_profile)
|
||||
? anal->cur->get_reg_profile (anal) : NULL;
|
||||
}
|
||||
@ -273,14 +280,23 @@ R_DEPRECATE R_API bool r_anal_set_reg_profile(RAnal *anal, const char *p) {
|
||||
bool ret = false;
|
||||
if (anal && anal->cur && anal->cur->set_reg_profile) {
|
||||
ret = anal->cur->set_reg_profile (anal);
|
||||
} else if (anal->arch && anal->arch->session && anal->arch->session->plugin && anal->arch->session->plugin->regs) {
|
||||
char *rp = anal->arch->session->plugin->regs (anal->arch->session);
|
||||
if (R_STR_ISNOTEMPTY (rp)) {
|
||||
r_reg_set_profile_string (anal->reg, rp);
|
||||
ret = true;
|
||||
}
|
||||
free (rp);
|
||||
#if 0
|
||||
} else if (anal->arch && anal->arch->current && anal->arch->current->p && anal->arch->current->p->set_reg_profile) {
|
||||
// RArchPluginRegistersCallback set_reg_profile = R_UNWRAP5 (anal, arch, current, p, regs);
|
||||
ret = anal->arch->current->p->set_reg_profile (anal->arch->cfg, anal->reg);
|
||||
} else if (anal->arch && anal->arch->current && anal->arch->current->p && anal->arch->current->p->set_reg_profile) {
|
||||
ret = anal->arch->current->p->set_reg_profile (anal->arch->cfg, anal->reg);
|
||||
#endif
|
||||
} else {
|
||||
char *p = r_anal_get_reg_profile (anal);
|
||||
if (p && *p) {
|
||||
if (R_STR_ISNOTEMPTY (p)) {
|
||||
r_reg_set_profile_string (anal->reg, p);
|
||||
ret = true;
|
||||
}
|
||||
@ -472,7 +488,7 @@ R_API R_DEPRECATE int r_anal_archinfo(RAnal *anal, int query) {
|
||||
case R_ANAL_ARCHINFO_INV_OP_SIZE:
|
||||
case R_ANAL_ARCHINFO_ALIGN:
|
||||
{
|
||||
int res = r_arch_info (anal->arch, NULL, query);
|
||||
int res = r_arch_info (anal->arch, query);
|
||||
if (res != -1) {
|
||||
return res;
|
||||
}
|
||||
|
@ -10,6 +10,12 @@ R_API RAnalOp *r_anal_op_new(void) {
|
||||
return op;
|
||||
}
|
||||
|
||||
R_API RAnalOp *r_anal_op_clone(RAnalOp *op) {
|
||||
RAnalOp *nop = R_NEW0 (RAnalOp);
|
||||
memcpy (nop, op, sizeof (RAnalOp));
|
||||
return nop;
|
||||
}
|
||||
|
||||
R_API RList *r_anal_op_list_new(void) {
|
||||
RList *list = r_list_new ();
|
||||
if (list) {
|
||||
@ -47,6 +53,7 @@ R_API void r_anal_op_fini(RAnalOp *op) {
|
||||
r_vector_fini (&op->dsts);
|
||||
r_list_free (op->access);
|
||||
op->access = NULL;
|
||||
R_FREE (op->bytes);
|
||||
r_strbuf_fini (&op->opex);
|
||||
r_strbuf_fini (&op->esil);
|
||||
r_anal_switch_op_free (op->switch_op);
|
||||
@ -89,28 +96,32 @@ static int defaultCycles(RAnalOp *op) {
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
// XXX deprecate!! or at least call r_arch_bath tradition
|
||||
R_API int r_anal_opasm(RAnal *anal, ut64 addr, const char *s, ut8 *outbuf, int outlen) {
|
||||
int ret = 0;
|
||||
if (outlen > 0 && anal->arch->current) {
|
||||
ret = r_arch_encode (anal->arch, addr, s, outbuf, outlen);
|
||||
// r_arch_op_to_analop (op, &archop);
|
||||
// ret = anal->arch->op (anal, op, addr, data, len, mask);
|
||||
if (ret < 1) {
|
||||
ret = r_arch_info (anal->arch, NULL, R_ANAL_ARCHINFO_INV_OP_SIZE);
|
||||
if (ret < 0) {
|
||||
ret = r_arch_info (anal->arch, NULL, R_ANAL_ARCHINFO_ALIGN);
|
||||
if (ret < 0) {
|
||||
if (outlen > 0 && anal->arch->session) {
|
||||
RAnalOp *op = r_anal_op_new ();
|
||||
r_anal_op_set_mnemonic (op, addr, s);
|
||||
if (!r_arch_encode (anal->arch, op, 0)) {
|
||||
int ret = r_arch_info (anal->arch, R_ANAL_ARCHINFO_INV_OP_SIZE);
|
||||
if (ret < 1) {
|
||||
ret = r_arch_info (anal->arch, R_ANAL_ARCHINFO_ALIGN);
|
||||
if (ret < 1) {
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// op->addr = addr;
|
||||
/* consider at least 1 byte to be part of the opcode */
|
||||
#if 0
|
||||
if (op->nopcode < 1) {
|
||||
op->nopcode = 1;
|
||||
int finlen = R_MIN (outlen, op->size);
|
||||
ret = op->size;
|
||||
if (op->bytes && finlen > 0) {
|
||||
memcpy (outbuf, op->bytes, finlen);
|
||||
} else {
|
||||
r_anal_op_free (op);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
r_anal_op_free (op);
|
||||
/* consider at least 1 byte to be part of the opcode */
|
||||
} else if (anal && outbuf && outlen > 0 && anal->cur && anal->cur->opasm) {
|
||||
// use core binding to set asm.bits correctly based on the addr
|
||||
// this is because of the hassle of arm/thumb
|
||||
@ -119,6 +130,7 @@ R_API int r_anal_opasm(RAnal *anal, ut64 addr, const char *s, ut8 *outbuf, int o
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) {
|
||||
r_anal_op_init (op);
|
||||
@ -138,8 +150,17 @@ R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
|
||||
return -1;
|
||||
}
|
||||
int ret = R_MIN (2, len);
|
||||
if (len > 0 && anal->arch->current) {
|
||||
ret = r_arch_decode (anal->arch, NULL, op, addr, data, len, mask);
|
||||
if (len > 0 && anal->arch->session) {
|
||||
r_anal_op_set_bytes (op, addr, data, len);
|
||||
bool bret = r_arch_decode (anal->arch, op, mask);
|
||||
if (!bret) {
|
||||
op->type = R_ANAL_OP_TYPE_ILL;
|
||||
op->size = r_anal_archinfo (anal, R_ANAL_ARCHINFO_INV_OP_SIZE);
|
||||
if (op->size < 0) {
|
||||
op->size = 1;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
// r_arch_op_to_analop (op, &archop);
|
||||
// ret = anal->arch->op (anal, op, addr, data, len, mask);
|
||||
if (ret < 1) {
|
||||
@ -149,6 +170,7 @@ R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le
|
||||
op->size = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
op->addr = addr;
|
||||
/* consider at least 1 byte to be part of the opcode */
|
||||
if (op->nopcode < 1) {
|
||||
@ -762,3 +784,25 @@ R_API const char *r_anal_op_direction_tostring(RAnalOp *op) {
|
||||
: d == 4 ? "exec"
|
||||
: d == 8 ? "ref": "none";
|
||||
}
|
||||
|
||||
R_API bool r_anal_op_set_mnemonic(RAnalOp *op, ut64 addr, const char *s) {
|
||||
char *news = strdup (s);
|
||||
if (news) {
|
||||
free (op->mnemonic);
|
||||
op->mnemonic = news;
|
||||
op->addr = addr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API bool r_anal_op_set_bytes(RAnalOp *op, ut64 addr, const ut8* data, int size) {
|
||||
if (op) {
|
||||
op->addr = addr;
|
||||
free (op->bytes);
|
||||
op->bytes = r_mem_dup (data, size);
|
||||
op->size = size;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -12,8 +12,7 @@ pre: libr_arch.$(EXT_SO) libr_arch.$(EXT_AR)
|
||||
|
||||
include $(STATIC_ARCH_PLUGINS)
|
||||
STATIC_OBJS=$(subst ..,p/..,$(subst arch_,p/arch_,$(STATIC_OBJ)))
|
||||
OBJS=arch.o aconfig.o switchop.o archop.o archvalue.o archcond.o
|
||||
OBJS=arch.o aconfig.o switchop.o archop.o archvalue.o archcond.o session.o
|
||||
OBJS+=${STATIC_OBJS}
|
||||
OBJS+=encoder.o decoder.o
|
||||
|
||||
include ../rules.mk
|
||||
|
@ -13,6 +13,12 @@ static void _ac_free(RArchConfig *cfg) {
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_arch_config_free(RArchConfig *r) {
|
||||
if (r) {
|
||||
r_unref (r);
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_arch_config_use(RArchConfig *config, R_NULLABLE const char *arch) {
|
||||
r_return_if_fail (config);
|
||||
// R_LOG_DEBUG ("RArch.USE (%s)", arch);
|
||||
@ -23,6 +29,11 @@ R_API void r_arch_config_use(RArchConfig *config, R_NULLABLE const char *arch) {
|
||||
config->arch = R_STR_ISNOTEMPTY (arch) ? strdup (arch) : NULL;
|
||||
}
|
||||
|
||||
R_API bool r_arch_config_iseq(RArchConfig *a, RArchConfig *b) {
|
||||
r_return_val_if_fail (a && b, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API void r_arch_config_set_cpu(RArchConfig *config, R_NULLABLE const char *cpu) {
|
||||
r_return_if_fail (config);
|
||||
// R_LOG_DEBUG ("RArch.CPU (%s)", cpu);
|
||||
@ -30,12 +41,33 @@ R_API void r_arch_config_set_cpu(RArchConfig *config, R_NULLABLE const char *cpu
|
||||
config->cpu = R_STR_ISNOTEMPTY (cpu) ? strdup (cpu) : NULL;
|
||||
}
|
||||
|
||||
R_API void r_arch_config_set_bits(RArchConfig *config, int bits) {
|
||||
r_return_if_fail (config);
|
||||
config->bits = bits;
|
||||
// callback
|
||||
// r_signal_now (config->events, "bits"
|
||||
// r_signal_on (config->events, "bits", &cb_bitschange);
|
||||
R_API bool r_arch_config_set_bits(RArchConfig *config, int bits) {
|
||||
r_return_val_if_fail (config, false);
|
||||
// if the config is tied to a session, there must be a callback to notify the plugin
|
||||
// that the config has chnaged and act accordingly. this is,
|
||||
bool is_valid = true;
|
||||
#if 0
|
||||
if (config->setbits) {
|
||||
is_valid = config->setbits (config, bits);
|
||||
}
|
||||
#endif
|
||||
if (is_valid) {
|
||||
config->bits = bits;
|
||||
}
|
||||
return is_valid;
|
||||
}
|
||||
|
||||
R_API RArchConfig *r_arch_config_clone(RArchConfig *c) {
|
||||
r_return_val_if_fail (c, NULL);
|
||||
RArchConfig *ac = R_NEW0 (RArchConfig);
|
||||
if (!ac) {
|
||||
return NULL;
|
||||
}
|
||||
ac->arch = R_STR_DUP (c->arch);
|
||||
ac->abi = R_STR_DUP (c->abi);
|
||||
ac->cpu = R_STR_DUP (c->cpu);
|
||||
ac->os = R_STR_DUP (c->os);
|
||||
return ac;
|
||||
}
|
||||
|
||||
R_API RArchConfig *r_arch_config_new(void) {
|
||||
|
@ -34,6 +34,7 @@ R_API RArch *r_arch_new(void) {
|
||||
free (a);
|
||||
return NULL;
|
||||
}
|
||||
a->cfg = r_arch_config_new ();
|
||||
ut32 i = 0;
|
||||
while (arch_static_plugins[i]) {
|
||||
r_arch_add (a, (RArchPlugin*)arch_static_plugins[i++]);
|
||||
@ -85,22 +86,22 @@ static ut32 _rate_compat(RArchPlugin *p, RArchConfig *cfg, const char *name) {
|
||||
return score;
|
||||
}
|
||||
|
||||
static char *_find_bestmatch(RList *plugins, RArchConfig *cfg, const char *name) {
|
||||
static RArchPlugin *find_bestmatch(RArch *arch, RArchConfig *cfg, const char *name) {
|
||||
ut8 best_score = 0;
|
||||
char *rname = NULL;
|
||||
RArchPlugin *ap = NULL;
|
||||
RListIter *iter;
|
||||
RArchPlugin *p;
|
||||
r_list_foreach (plugins, iter, p) {
|
||||
r_list_foreach (arch->plugins, iter, p) {
|
||||
const ut32 score = _rate_compat (p, cfg, name);
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
rname = p->name;
|
||||
ap = p;
|
||||
}
|
||||
if (score == 100) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rname;
|
||||
return ap;
|
||||
}
|
||||
|
||||
// use config as new arch config and use matching decoder as current
|
||||
@ -110,13 +111,29 @@ R_API bool r_arch_use(RArch *arch, RArchConfig *config, const char *name) {
|
||||
if (!config) {
|
||||
config = arch->cfg;
|
||||
}
|
||||
#if 0
|
||||
if (config && arch->cfg == config) {
|
||||
eprintf ("retur\n");
|
||||
return true;
|
||||
}
|
||||
if (!config) {
|
||||
// arch->decoder = NULL;
|
||||
#endif
|
||||
RArchPlugin *ap = find_bestmatch (arch, config, name);
|
||||
if (!ap) {
|
||||
r_unref (arch->session);
|
||||
arch->session = NULL;
|
||||
return false;
|
||||
}
|
||||
arch->session = r_arch_session (arch, config, ap);
|
||||
#if 0
|
||||
RArchConfig *oconfig = arch->cfg;
|
||||
r_unref (arch->cfg);
|
||||
arch->cfg = config;
|
||||
r_ref (arch->cfg);
|
||||
r_unref (oconfig);
|
||||
#endif
|
||||
#if 0
|
||||
// the res is boilerplate imho
|
||||
|
||||
const char *dname = config->decoder ? config->decoder: _find_bestmatch (arch->plugins, config, name);
|
||||
if (!dname) {
|
||||
return false;
|
||||
@ -134,9 +151,24 @@ R_API bool r_arch_use(RArch *arch, RArchConfig *config, const char *name) {
|
||||
return false;
|
||||
}
|
||||
r_unref (oconfig);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API bool r_arch_use_decoder(RArch *arch, const char *dname) {
|
||||
RArchConfig *cfg = r_arch_config_clone (arch->cfg);
|
||||
bool r = r_arch_use (arch, cfg, dname);
|
||||
if (!r) {
|
||||
r_unref (cfg);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
R_API bool r_arch_use_encoder(RArch *arch, const char *dname) {
|
||||
/// XXX this should be storing the plugin in a separate pointer
|
||||
return r_arch_use (arch, arch->cfg, dname);
|
||||
}
|
||||
|
||||
// set bits and update config
|
||||
// This api conflicts with r_arch_config_set_bits
|
||||
R_API bool r_arch_set_bits(RArch *arch, ut32 bits) {
|
||||
@ -207,6 +239,7 @@ R_API bool r_arch_set_endian(RArch *arch, ut32 endian) {
|
||||
}
|
||||
|
||||
R_API bool r_arch_set_arch(RArch *arch, char *archname) {
|
||||
// Rename to _use_arch instead ?
|
||||
r_return_val_if_fail (arch && archname, false);
|
||||
char *_arch = strdup (archname);
|
||||
if (!_arch) {
|
||||
@ -252,7 +285,7 @@ R_API bool r_arch_add(RArch *a, RArchPlugin *ap) {
|
||||
return !!r_list_append (a->plugins, ap);
|
||||
}
|
||||
|
||||
static bool _pick_any_decoder_as_current (void *user, const char *dname, const void *dec) {
|
||||
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;
|
||||
@ -298,19 +331,18 @@ R_API void r_arch_free(RArch *arch) {
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
R_API int r_arch_info(RArch *a, int query) {
|
||||
r_return_val_if_fail (a, -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:
|
||||
if (arch->current && anal->arch->current->archinfo) {
|
||||
return arch->current->archinfo (arch, query);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
RArchSession *session = R_UNWRAP2 (a, session);
|
||||
RArchPluginInfoCallback info = R_UNWRAP4 (a, session, plugin, info);
|
||||
return info? info (session, query): -1;
|
||||
}
|
||||
|
||||
R_API bool r_arch_encode(RArch *a, RAnalOp *op, RArchEncodeMask mask) {
|
||||
RArchPluginEncodeCallback encode = R_UNWRAP4 (a, session, plugin, encode);
|
||||
return encode? encode (a->session, op, mask): false;
|
||||
}
|
||||
|
||||
R_API bool r_arch_decode(RArch *a, RAnalOp *op, RArchDecodeMask mask) {
|
||||
RArchPluginEncodeCallback decode = R_UNWRAP4 (a, session, plugin, decode);
|
||||
return decode? decode (a->session, op, mask): false;
|
||||
}
|
||||
#endif
|
||||
|
@ -1,139 +0,0 @@
|
||||
/* radare2 - LGPL - Copyright 2022 - condret */
|
||||
|
||||
#include <r_arch.h>
|
||||
#include <r_util.h>
|
||||
|
||||
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);
|
||||
if (decoder) {
|
||||
decoder->refctr++;
|
||||
return true;
|
||||
}
|
||||
decoder = R_NEW (RArchDecoder);
|
||||
if (!decoder) {
|
||||
return false;
|
||||
}
|
||||
RListIter *iter;
|
||||
r_list_foreach (arch->plugins, iter, decoder->p) {
|
||||
if (!strcmp (decoder->p->name, dname)) {
|
||||
// plugins with init also MUST have fini
|
||||
if (decoder->p->init && decoder->p->fini) {
|
||||
if (!decoder->p->init (&decoder->user)) {
|
||||
free (decoder);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
decoder->user = NULL;
|
||||
}
|
||||
if (ht_pp_insert (arch->decoders, dname, decoder)) {
|
||||
decoder->refctr = 1;
|
||||
if (!arch->current) {
|
||||
arch->current = decoder;
|
||||
if (arch->cfg) {
|
||||
R_FREE (arch->cfg->decoder);
|
||||
arch->cfg->decoder = strdup (dname);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (decoder->p->fini) {
|
||||
decoder->p->fini (decoder->user);
|
||||
}
|
||||
free (decoder);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
free (decoder);
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API bool r_arch_use_decoder(RArch *arch, const char *dname) {
|
||||
r_return_val_if_fail (dname && arch && arch->decoders, false);
|
||||
if (!arch->current) {
|
||||
return r_arch_load_decoder (arch, dname);
|
||||
}
|
||||
if (!strcmp (arch->current->p->name, dname)) {
|
||||
return true;
|
||||
}
|
||||
RArchDecoder *decoder = (RArchDecoder *)ht_pp_find (arch->decoders, dname, NULL);
|
||||
if (!decoder) {
|
||||
decoder = arch->current;
|
||||
arch->current = NULL;
|
||||
if (!r_arch_load_decoder (arch, dname)) {
|
||||
arch->current = decoder;
|
||||
return false;
|
||||
}
|
||||
if (arch->cfg) {
|
||||
R_FREE (arch->cfg->decoder);
|
||||
arch->cfg->decoder = strdup (dname);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
arch->current = decoder;
|
||||
if (arch->cfg) {
|
||||
R_FREE (arch->cfg->decoder);
|
||||
arch->cfg->decoder = strdup (dname);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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_unload_decoder(RArch *arch, const char *dname) {
|
||||
r_return_val_if_fail (arch && arch->decoders, false);
|
||||
RArchDecoder *decoder = NULL;
|
||||
if (dname) {
|
||||
decoder = (RArchDecoder *)ht_pp_find (arch->decoders, dname, NULL);
|
||||
} else {
|
||||
decoder = arch->current;
|
||||
}
|
||||
if (!decoder) {
|
||||
return false;
|
||||
}
|
||||
decoder->refctr--;
|
||||
if (decoder->refctr) {
|
||||
return true;
|
||||
}
|
||||
ht_pp_delete (arch->decoders, decoder->p->name);
|
||||
if (arch->current == decoder) {
|
||||
arch->current = NULL;
|
||||
ht_pp_foreach (arch->decoders, (HtPPForeachCallback)_pick_any_decoder_as_current, arch);
|
||||
if (arch->cfg && arch->cfg->decoder) {
|
||||
R_FREE (arch->cfg->decoder);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API int r_arch_info(RArch *arch, const char *dname, ut32 query) {
|
||||
r_return_val_if_fail (arch, -1);
|
||||
RArchDecoder *decoder = NULL;
|
||||
if (dname) {
|
||||
decoder = (RArchDecoder *)ht_pp_find (arch->decoders, dname, NULL);
|
||||
} else {
|
||||
decoder = arch->current;
|
||||
}
|
||||
if (!decoder || !decoder->p->info) {
|
||||
return -1;
|
||||
}
|
||||
return decoder->p->info (arch->cfg, query);
|
||||
}
|
||||
|
||||
R_API int r_arch_decode(RArch *arch, const char *dname, RAnalOp *op, ut64 addr, const ut8 *data, int len, ut32 mask) {
|
||||
r_return_val_if_fail (arch && op && data && (len > 0), -1);
|
||||
RArchDecoder *decoder = NULL;
|
||||
if (dname) {
|
||||
decoder = (RArchDecoder *)ht_pp_find (arch->decoders, dname, NULL);
|
||||
} else {
|
||||
decoder = arch->current;
|
||||
}
|
||||
if (!decoder || !decoder->p->decode) {
|
||||
return -1;
|
||||
}
|
||||
return decoder->p->decode (arch, op, addr, data, len, mask, decoder->user);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
/* radare2 - LGPL - Copyright 2022 - condret */
|
||||
|
||||
#include <r_arch.h>
|
||||
#include <r_util.h>
|
||||
|
||||
// plaintext to opcdes bytes, returns length
|
||||
// why not returning an RBuffer?
|
||||
// R_API RBuffer *r_arch_encode(RArch *a, ut64 addr, const char *s) { }
|
||||
|
||||
R_API int r_arch_encode(RArch *a, ut64 addr, const char *s, ut8 *outbuf, int outlen) {
|
||||
int res = 0;
|
||||
RArchOpAsmCallback encode = R_UNWRAP4 (a, current, p, encode);
|
||||
if (encode) {
|
||||
res = encode (a, addr, s, outbuf, outlen);
|
||||
}
|
||||
return res;
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
r_arch_sources = [
|
||||
'arch.c',
|
||||
'aconfig.c',
|
||||
'decoder.c',
|
||||
'encoder.c',
|
||||
'switchop.c',
|
||||
'archop.c',
|
||||
'session.c',
|
||||
'archcond.c',
|
||||
'archvalue.c',
|
||||
'p/arch_null.c',
|
||||
|
268
libr/arch/p/amd29k/regs.h
Normal file
268
libr/arch/p/amd29k/regs.h
Normal file
@ -0,0 +1,268 @@
|
||||
"=PC pc\n"
|
||||
"=SP gp1\n"
|
||||
"=BP gp2\n"
|
||||
"=SR gp3\n" // status register ??
|
||||
"=SN gp4\n" // also for ret
|
||||
"=A0 lr1\n" // also for ret
|
||||
"=A1 lr2\n"
|
||||
"=A2 lr3\n"
|
||||
"=A3 lr4\n"
|
||||
"=A4 lr5\n"
|
||||
"=A5 lr6\n"
|
||||
"=A6 lr7\n"
|
||||
"gpr gp0 .32 0 0\n"
|
||||
"gpr gp1 .32 8 0\n"
|
||||
"gpr gp2 .32 16 0\n"
|
||||
"gpr gp3 .32 24 0\n"
|
||||
"gpr gp4 .32 32 0\n"
|
||||
"gpr gp5 .32 40 0\n"
|
||||
"gpr gp6 .32 48 0\n"
|
||||
"gpr gp7 .32 56 0\n"
|
||||
"gpr gp8 .32 64 0\n"
|
||||
"gpr gp9 .32 72 0\n"
|
||||
"gpr gp10 .32 80 0\n"
|
||||
"gpr gp11 .32 88 0\n"
|
||||
"gpr gp12 .32 96 0\n"
|
||||
"gpr gp13 .32 104 0\n"
|
||||
"gpr gp14 .32 112 0\n"
|
||||
"gpr gp15 .32 120 0\n"
|
||||
"gpr gp16 .32 128 0\n"
|
||||
"gpr gp17 .32 136 0\n"
|
||||
"gpr gp18 .32 144 0\n"
|
||||
"gpr gp19 .32 152 0\n"
|
||||
"gpr gp20 .32 160 0\n"
|
||||
"gpr gp21 .32 168 0\n"
|
||||
"gpr gp22 .32 176 0\n"
|
||||
"gpr gp23 .32 184 0\n"
|
||||
"gpr gp24 .32 192 0\n"
|
||||
"gpr gp25 .32 200 0\n"
|
||||
"gpr gp26 .32 208 0\n"
|
||||
"gpr gp27 .32 216 0\n"
|
||||
"gpr gp28 .32 224 0\n"
|
||||
"gpr gp29 .32 232 0\n"
|
||||
"gpr gp30 .32 240 0\n"
|
||||
"gpr gp31 .32 248 0\n"
|
||||
"gpr gp32 .32 256 0\n"
|
||||
"gpr gp33 .32 264 0\n"
|
||||
"gpr gp34 .32 272 0\n"
|
||||
"gpr gp35 .32 280 0\n"
|
||||
"gpr gp36 .32 288 0\n"
|
||||
"gpr gp37 .32 296 0\n"
|
||||
"gpr gp38 .32 304 0\n"
|
||||
"gpr gp39 .32 312 0\n"
|
||||
"gpr gp40 .32 320 0\n"
|
||||
"gpr gp41 .32 328 0\n"
|
||||
"gpr gp42 .32 336 0\n"
|
||||
"gpr gp43 .32 344 0\n"
|
||||
"gpr gp44 .32 352 0\n"
|
||||
"gpr gp45 .32 360 0\n"
|
||||
"gpr gp46 .32 368 0\n"
|
||||
"gpr gp47 .32 376 0\n"
|
||||
"gpr gp48 .32 384 0\n"
|
||||
"gpr gp49 .32 392 0\n"
|
||||
"gpr gp50 .32 400 0\n"
|
||||
"gpr gp51 .32 408 0\n"
|
||||
"gpr gp52 .32 416 0\n"
|
||||
"gpr gp53 .32 424 0\n"
|
||||
"gpr gp54 .32 432 0\n"
|
||||
"gpr gp55 .32 440 0\n"
|
||||
"gpr gp56 .32 448 0\n"
|
||||
"gpr gp57 .32 456 0\n"
|
||||
"gpr gp58 .32 464 0\n"
|
||||
"gpr gp59 .32 472 0\n"
|
||||
"gpr gp60 .32 480 0\n"
|
||||
"gpr gp61 .32 488 0\n"
|
||||
"gpr gp62 .32 496 0\n"
|
||||
"gpr gp63 .32 504 0\n"
|
||||
"gpr gp64 .32 512 0\n"
|
||||
"gpr gp65 .32 520 0\n"
|
||||
"gpr gp66 .32 528 0\n"
|
||||
"gpr gp67 .32 536 0\n"
|
||||
"gpr gp68 .32 544 0\n"
|
||||
"gpr gp69 .32 552 0\n"
|
||||
"gpr gp70 .32 560 0\n"
|
||||
"gpr gp71 .32 568 0\n"
|
||||
"gpr gp72 .32 576 0\n"
|
||||
"gpr gp73 .32 584 0\n"
|
||||
"gpr gp74 .32 592 0\n"
|
||||
"gpr gp75 .32 600 0\n"
|
||||
"gpr gp76 .32 608 0\n"
|
||||
"gpr gp77 .32 616 0\n"
|
||||
"gpr gp78 .32 624 0\n"
|
||||
"gpr gp79 .32 632 0\n"
|
||||
"gpr gp80 .32 640 0\n"
|
||||
"gpr gp81 .32 648 0\n"
|
||||
"gpr gp82 .32 656 0\n"
|
||||
"gpr gp83 .32 664 0\n"
|
||||
"gpr gp84 .32 672 0\n"
|
||||
"gpr gp85 .32 680 0\n"
|
||||
"gpr gp86 .32 688 0\n"
|
||||
"gpr gp87 .32 696 0\n"
|
||||
"gpr gp88 .32 704 0\n"
|
||||
"gpr gp89 .32 712 0\n"
|
||||
"gpr gp90 .32 720 0\n"
|
||||
"gpr gp91 .32 728 0\n"
|
||||
"gpr gp92 .32 736 0\n"
|
||||
"gpr gp93 .32 744 0\n"
|
||||
"gpr gp94 .32 752 0\n"
|
||||
"gpr gp95 .32 760 0\n"
|
||||
"gpr gp96 .32 768 0\n"
|
||||
"gpr gp97 .32 776 0\n"
|
||||
"gpr gp98 .32 784 0\n"
|
||||
"gpr gp99 .32 792 0\n"
|
||||
"gpr gp100 .32 800 0\n"
|
||||
"gpr gp101 .32 808 0\n"
|
||||
"gpr gp102 .32 816 0\n"
|
||||
"gpr gp103 .32 824 0\n"
|
||||
"gpr gp104 .32 832 0\n"
|
||||
"gpr gp105 .32 840 0\n"
|
||||
"gpr gp106 .32 848 0\n"
|
||||
"gpr gp107 .32 856 0\n"
|
||||
"gpr gp108 .32 864 0\n"
|
||||
"gpr gp109 .32 872 0\n"
|
||||
"gpr gp110 .32 880 0\n"
|
||||
"gpr gp111 .32 888 0\n"
|
||||
"gpr gp112 .32 896 0\n"
|
||||
"gpr gp113 .32 904 0\n"
|
||||
"gpr gp114 .32 912 0\n"
|
||||
"gpr gp115 .32 920 0\n"
|
||||
"gpr gp116 .32 928 0\n"
|
||||
"gpr gp117 .32 936 0\n"
|
||||
"gpr gp118 .32 944 0\n"
|
||||
"gpr gp119 .32 952 0\n"
|
||||
"gpr gp120 .32 960 0\n"
|
||||
"gpr gp121 .32 968 0\n"
|
||||
"gpr gp122 .32 976 0\n"
|
||||
"gpr gp123 .32 984 0\n"
|
||||
"gpr gp124 .32 992 0\n"
|
||||
"gpr gp125 .32 1000 0\n"
|
||||
"gpr gp126 .32 1008 0\n"
|
||||
"gpr gp127 .32 1016 0\n"
|
||||
"gpr lr1 .32 1024 0\n"
|
||||
"gpr lr2 .32 1032 0\n"
|
||||
"gpr lr3 .32 1040 0\n"
|
||||
"gpr lr4 .32 1048 0\n"
|
||||
"gpr lr5 .32 1056 0\n"
|
||||
"gpr lr6 .32 1064 0\n"
|
||||
"gpr lr7 .32 1072 0\n"
|
||||
"gpr lr8 .32 1080 0\n"
|
||||
"gpr lr9 .32 1088 0\n"
|
||||
"gpr lr10 .32 1096 0\n"
|
||||
"gpr lr11 .32 1104 0\n"
|
||||
"gpr lr12 .32 1112 0\n"
|
||||
"gpr lr13 .32 1120 0\n"
|
||||
"gpr lr14 .32 1128 0\n"
|
||||
"gpr lr15 .32 1136 0\n"
|
||||
"gpr lr16 .32 1144 0\n"
|
||||
"gpr lr17 .32 1152 0\n"
|
||||
"gpr lr18 .32 1160 0\n"
|
||||
"gpr lr19 .32 1168 0\n"
|
||||
"gpr lr20 .32 1176 0\n"
|
||||
"gpr lr21 .32 1184 0\n"
|
||||
"gpr lr22 .32 1192 0\n"
|
||||
"gpr lr23 .32 1200 0\n"
|
||||
"gpr lr24 .32 1208 0\n"
|
||||
"gpr lr25 .32 1216 0\n"
|
||||
"gpr lr26 .32 1224 0\n"
|
||||
"gpr lr27 .32 1232 0\n"
|
||||
"gpr lr28 .32 1240 0\n"
|
||||
"gpr lr29 .32 1248 0\n"
|
||||
"gpr lr30 .32 1256 0\n"
|
||||
"gpr lr31 .32 1264 0\n"
|
||||
"gpr lr32 .32 1272 0\n"
|
||||
"gpr lr33 .32 1280 0\n"
|
||||
"gpr lr34 .32 1288 0\n"
|
||||
"gpr lr35 .32 1296 0\n"
|
||||
"gpr lr36 .32 1304 0\n"
|
||||
"gpr lr37 .32 1312 0\n"
|
||||
"gpr lr38 .32 1320 0\n"
|
||||
"gpr lr39 .32 1328 0\n"
|
||||
"gpr lr40 .32 1336 0\n"
|
||||
"gpr lr41 .32 1344 0\n"
|
||||
"gpr lr42 .32 1352 0\n"
|
||||
"gpr lr43 .32 1360 0\n"
|
||||
"gpr lr44 .32 1368 0\n"
|
||||
"gpr lr45 .32 1376 0\n"
|
||||
"gpr lr46 .32 1384 0\n"
|
||||
"gpr lr47 .32 1392 0\n"
|
||||
"gpr lr48 .32 1400 0\n"
|
||||
"gpr lr49 .32 1408 0\n"
|
||||
"gpr lr50 .32 1416 0\n"
|
||||
"gpr lr51 .32 1424 0\n"
|
||||
"gpr lr52 .32 1432 0\n"
|
||||
"gpr lr53 .32 1440 0\n"
|
||||
"gpr lr54 .32 1448 0\n"
|
||||
"gpr lr55 .32 1456 0\n"
|
||||
"gpr lr56 .32 1464 0\n"
|
||||
"gpr lr57 .32 1472 0\n"
|
||||
"gpr lr58 .32 1480 0\n"
|
||||
"gpr lr59 .32 1488 0\n"
|
||||
"gpr lr60 .32 1496 0\n"
|
||||
"gpr lr61 .32 1504 0\n"
|
||||
"gpr lr62 .32 1512 0\n"
|
||||
"gpr lr63 .32 1520 0\n"
|
||||
"gpr lr64 .32 1528 0\n"
|
||||
"gpr lr65 .32 1536 0\n"
|
||||
"gpr lr66 .32 1544 0\n"
|
||||
"gpr lr67 .32 1552 0\n"
|
||||
"gpr lr68 .32 1560 0\n"
|
||||
"gpr lr69 .32 1568 0\n"
|
||||
"gpr lr70 .32 1576 0\n"
|
||||
"gpr lr71 .32 1584 0\n"
|
||||
"gpr lr72 .32 1592 0\n"
|
||||
"gpr lr73 .32 1600 0\n"
|
||||
"gpr lr74 .32 1608 0\n"
|
||||
"gpr lr75 .32 1616 0\n"
|
||||
"gpr lr76 .32 1624 0\n"
|
||||
"gpr lr77 .32 1632 0\n"
|
||||
"gpr lr78 .32 1640 0\n"
|
||||
"gpr lr79 .32 1648 0\n"
|
||||
"gpr lr80 .32 1656 0\n"
|
||||
"gpr lr81 .32 1664 0\n"
|
||||
"gpr lr82 .32 1672 0\n"
|
||||
"gpr lr83 .32 1680 0\n"
|
||||
"gpr lr84 .32 1688 0\n"
|
||||
"gpr lr85 .32 1696 0\n"
|
||||
"gpr lr86 .32 1704 0\n"
|
||||
"gpr lr87 .32 1712 0\n"
|
||||
"gpr lr88 .32 1720 0\n"
|
||||
"gpr lr89 .32 1728 0\n"
|
||||
"gpr lr90 .32 1736 0\n"
|
||||
"gpr lr91 .32 1744 0\n"
|
||||
"gpr lr92 .32 1752 0\n"
|
||||
"gpr lr93 .32 1760 0\n"
|
||||
"gpr lr94 .32 1768 0\n"
|
||||
"gpr lr95 .32 1776 0\n"
|
||||
"gpr lr96 .32 1784 0\n"
|
||||
"gpr lr97 .32 1792 0\n"
|
||||
"gpr lr98 .32 1800 0\n"
|
||||
"gpr lr99 .32 1808 0\n"
|
||||
"gpr lr100 .32 1816 0\n"
|
||||
"gpr lr101 .32 1824 0\n"
|
||||
"gpr lr102 .32 1832 0\n"
|
||||
"gpr lr103 .32 1840 0\n"
|
||||
"gpr lr104 .32 1848 0\n"
|
||||
"gpr lr105 .32 1856 0\n"
|
||||
"gpr lr106 .32 1864 0\n"
|
||||
"gpr lr107 .32 1872 0\n"
|
||||
"gpr lr108 .32 1880 0\n"
|
||||
"gpr lr109 .32 1888 0\n"
|
||||
"gpr lr110 .32 1896 0\n"
|
||||
"gpr lr111 .32 1904 0\n"
|
||||
"gpr lr112 .32 1912 0\n"
|
||||
"gpr lr113 .32 1920 0\n"
|
||||
"gpr lr114 .32 1928 0\n"
|
||||
"gpr lr115 .32 1936 0\n"
|
||||
"gpr lr116 .32 1944 0\n"
|
||||
"gpr lr117 .32 1952 0\n"
|
||||
"gpr lr118 .32 1960 0\n"
|
||||
"gpr lr119 .32 1968 0\n"
|
||||
"gpr lr120 .32 1976 0\n"
|
||||
"gpr lr121 .32 1984 0\n"
|
||||
"gpr lr122 .32 1992 0\n"
|
||||
"gpr lr123 .32 2000 0\n"
|
||||
"gpr lr124 .32 2008 0\n"
|
||||
"gpr lr125 .32 2016 0\n"
|
||||
"gpr lr126 .32 2024 0\n"
|
||||
"gpr lr127 .32 2032 0\n"
|
||||
"gpr lr128 .32 2040 0\n"
|
@ -623,288 +623,27 @@ void amd29k_instr_print(char *string, int string_size, ut64 address, amd29k_inst
|
||||
#undef AMD29K_IS_3
|
||||
#undef AMD29K_IS_4
|
||||
#undef AMD29K_IS_5
|
||||
static bool set_reg_profile(RArchConfig *cfg, RReg *reg) {
|
||||
|
||||
static char *regs(RArchSession *s) {
|
||||
const char * const p =
|
||||
"=PC pc\n"
|
||||
"=SP gp1\n"
|
||||
"=BP gp2\n"
|
||||
"=SR gp3\n" // status register ??
|
||||
"=SN gp4\n" // also for ret
|
||||
"=A0 lr1\n" // also for ret
|
||||
"=A1 lr2\n"
|
||||
"=A2 lr3\n"
|
||||
"=A3 lr4\n"
|
||||
"=A4 lr5\n"
|
||||
"=A5 lr6\n"
|
||||
"=A6 lr7\n"
|
||||
"gpr gp0 .32 0 0\n"
|
||||
"gpr gp1 .32 8 0\n"
|
||||
"gpr gp2 .32 16 0\n"
|
||||
"gpr gp3 .32 24 0\n"
|
||||
"gpr gp4 .32 32 0\n"
|
||||
"gpr gp5 .32 40 0\n"
|
||||
"gpr gp6 .32 48 0\n"
|
||||
"gpr gp7 .32 56 0\n"
|
||||
"gpr gp8 .32 64 0\n"
|
||||
"gpr gp9 .32 72 0\n"
|
||||
"gpr gp10 .32 80 0\n"
|
||||
"gpr gp11 .32 88 0\n"
|
||||
"gpr gp12 .32 96 0\n"
|
||||
"gpr gp13 .32 104 0\n"
|
||||
"gpr gp14 .32 112 0\n"
|
||||
"gpr gp15 .32 120 0\n"
|
||||
"gpr gp16 .32 128 0\n"
|
||||
"gpr gp17 .32 136 0\n"
|
||||
"gpr gp18 .32 144 0\n"
|
||||
"gpr gp19 .32 152 0\n"
|
||||
"gpr gp20 .32 160 0\n"
|
||||
"gpr gp21 .32 168 0\n"
|
||||
"gpr gp22 .32 176 0\n"
|
||||
"gpr gp23 .32 184 0\n"
|
||||
"gpr gp24 .32 192 0\n"
|
||||
"gpr gp25 .32 200 0\n"
|
||||
"gpr gp26 .32 208 0\n"
|
||||
"gpr gp27 .32 216 0\n"
|
||||
"gpr gp28 .32 224 0\n"
|
||||
"gpr gp29 .32 232 0\n"
|
||||
"gpr gp30 .32 240 0\n"
|
||||
"gpr gp31 .32 248 0\n"
|
||||
"gpr gp32 .32 256 0\n"
|
||||
"gpr gp33 .32 264 0\n"
|
||||
"gpr gp34 .32 272 0\n"
|
||||
"gpr gp35 .32 280 0\n"
|
||||
"gpr gp36 .32 288 0\n"
|
||||
"gpr gp37 .32 296 0\n"
|
||||
"gpr gp38 .32 304 0\n"
|
||||
"gpr gp39 .32 312 0\n"
|
||||
"gpr gp40 .32 320 0\n"
|
||||
"gpr gp41 .32 328 0\n"
|
||||
"gpr gp42 .32 336 0\n"
|
||||
"gpr gp43 .32 344 0\n"
|
||||
"gpr gp44 .32 352 0\n"
|
||||
"gpr gp45 .32 360 0\n"
|
||||
"gpr gp46 .32 368 0\n"
|
||||
"gpr gp47 .32 376 0\n"
|
||||
"gpr gp48 .32 384 0\n"
|
||||
"gpr gp49 .32 392 0\n"
|
||||
"gpr gp50 .32 400 0\n"
|
||||
"gpr gp51 .32 408 0\n"
|
||||
"gpr gp52 .32 416 0\n"
|
||||
"gpr gp53 .32 424 0\n"
|
||||
"gpr gp54 .32 432 0\n"
|
||||
"gpr gp55 .32 440 0\n"
|
||||
"gpr gp56 .32 448 0\n"
|
||||
"gpr gp57 .32 456 0\n"
|
||||
"gpr gp58 .32 464 0\n"
|
||||
"gpr gp59 .32 472 0\n"
|
||||
"gpr gp60 .32 480 0\n"
|
||||
"gpr gp61 .32 488 0\n"
|
||||
"gpr gp62 .32 496 0\n"
|
||||
"gpr gp63 .32 504 0\n"
|
||||
"gpr gp64 .32 512 0\n"
|
||||
"gpr gp65 .32 520 0\n"
|
||||
"gpr gp66 .32 528 0\n"
|
||||
"gpr gp67 .32 536 0\n"
|
||||
"gpr gp68 .32 544 0\n"
|
||||
"gpr gp69 .32 552 0\n"
|
||||
"gpr gp70 .32 560 0\n"
|
||||
"gpr gp71 .32 568 0\n"
|
||||
"gpr gp72 .32 576 0\n"
|
||||
"gpr gp73 .32 584 0\n"
|
||||
"gpr gp74 .32 592 0\n"
|
||||
"gpr gp75 .32 600 0\n"
|
||||
"gpr gp76 .32 608 0\n"
|
||||
"gpr gp77 .32 616 0\n"
|
||||
"gpr gp78 .32 624 0\n"
|
||||
"gpr gp79 .32 632 0\n"
|
||||
"gpr gp80 .32 640 0\n"
|
||||
"gpr gp81 .32 648 0\n"
|
||||
"gpr gp82 .32 656 0\n"
|
||||
"gpr gp83 .32 664 0\n"
|
||||
"gpr gp84 .32 672 0\n"
|
||||
"gpr gp85 .32 680 0\n"
|
||||
"gpr gp86 .32 688 0\n"
|
||||
"gpr gp87 .32 696 0\n"
|
||||
"gpr gp88 .32 704 0\n"
|
||||
"gpr gp89 .32 712 0\n"
|
||||
"gpr gp90 .32 720 0\n"
|
||||
"gpr gp91 .32 728 0\n"
|
||||
"gpr gp92 .32 736 0\n"
|
||||
"gpr gp93 .32 744 0\n"
|
||||
"gpr gp94 .32 752 0\n"
|
||||
"gpr gp95 .32 760 0\n"
|
||||
"gpr gp96 .32 768 0\n"
|
||||
"gpr gp97 .32 776 0\n"
|
||||
"gpr gp98 .32 784 0\n"
|
||||
"gpr gp99 .32 792 0\n"
|
||||
"gpr gp100 .32 800 0\n"
|
||||
"gpr gp101 .32 808 0\n"
|
||||
"gpr gp102 .32 816 0\n"
|
||||
"gpr gp103 .32 824 0\n"
|
||||
"gpr gp104 .32 832 0\n"
|
||||
"gpr gp105 .32 840 0\n"
|
||||
"gpr gp106 .32 848 0\n"
|
||||
"gpr gp107 .32 856 0\n"
|
||||
"gpr gp108 .32 864 0\n"
|
||||
"gpr gp109 .32 872 0\n"
|
||||
"gpr gp110 .32 880 0\n"
|
||||
"gpr gp111 .32 888 0\n"
|
||||
"gpr gp112 .32 896 0\n"
|
||||
"gpr gp113 .32 904 0\n"
|
||||
"gpr gp114 .32 912 0\n"
|
||||
"gpr gp115 .32 920 0\n"
|
||||
"gpr gp116 .32 928 0\n"
|
||||
"gpr gp117 .32 936 0\n"
|
||||
"gpr gp118 .32 944 0\n"
|
||||
"gpr gp119 .32 952 0\n"
|
||||
"gpr gp120 .32 960 0\n"
|
||||
"gpr gp121 .32 968 0\n"
|
||||
"gpr gp122 .32 976 0\n"
|
||||
"gpr gp123 .32 984 0\n"
|
||||
"gpr gp124 .32 992 0\n"
|
||||
"gpr gp125 .32 1000 0\n"
|
||||
"gpr gp126 .32 1008 0\n"
|
||||
"gpr gp127 .32 1016 0\n"
|
||||
"gpr lr1 .32 1024 0\n"
|
||||
"gpr lr2 .32 1032 0\n"
|
||||
"gpr lr3 .32 1040 0\n"
|
||||
"gpr lr4 .32 1048 0\n"
|
||||
"gpr lr5 .32 1056 0\n"
|
||||
"gpr lr6 .32 1064 0\n"
|
||||
"gpr lr7 .32 1072 0\n"
|
||||
"gpr lr8 .32 1080 0\n"
|
||||
"gpr lr9 .32 1088 0\n"
|
||||
"gpr lr10 .32 1096 0\n"
|
||||
"gpr lr11 .32 1104 0\n"
|
||||
"gpr lr12 .32 1112 0\n"
|
||||
"gpr lr13 .32 1120 0\n"
|
||||
"gpr lr14 .32 1128 0\n"
|
||||
"gpr lr15 .32 1136 0\n"
|
||||
"gpr lr16 .32 1144 0\n"
|
||||
"gpr lr17 .32 1152 0\n"
|
||||
"gpr lr18 .32 1160 0\n"
|
||||
"gpr lr19 .32 1168 0\n"
|
||||
"gpr lr20 .32 1176 0\n"
|
||||
"gpr lr21 .32 1184 0\n"
|
||||
"gpr lr22 .32 1192 0\n"
|
||||
"gpr lr23 .32 1200 0\n"
|
||||
"gpr lr24 .32 1208 0\n"
|
||||
"gpr lr25 .32 1216 0\n"
|
||||
"gpr lr26 .32 1224 0\n"
|
||||
"gpr lr27 .32 1232 0\n"
|
||||
"gpr lr28 .32 1240 0\n"
|
||||
"gpr lr29 .32 1248 0\n"
|
||||
"gpr lr30 .32 1256 0\n"
|
||||
"gpr lr31 .32 1264 0\n"
|
||||
"gpr lr32 .32 1272 0\n"
|
||||
"gpr lr33 .32 1280 0\n"
|
||||
"gpr lr34 .32 1288 0\n"
|
||||
"gpr lr35 .32 1296 0\n"
|
||||
"gpr lr36 .32 1304 0\n"
|
||||
"gpr lr37 .32 1312 0\n"
|
||||
"gpr lr38 .32 1320 0\n"
|
||||
"gpr lr39 .32 1328 0\n"
|
||||
"gpr lr40 .32 1336 0\n"
|
||||
"gpr lr41 .32 1344 0\n"
|
||||
"gpr lr42 .32 1352 0\n"
|
||||
"gpr lr43 .32 1360 0\n"
|
||||
"gpr lr44 .32 1368 0\n"
|
||||
"gpr lr45 .32 1376 0\n"
|
||||
"gpr lr46 .32 1384 0\n"
|
||||
"gpr lr47 .32 1392 0\n"
|
||||
"gpr lr48 .32 1400 0\n"
|
||||
"gpr lr49 .32 1408 0\n"
|
||||
"gpr lr50 .32 1416 0\n"
|
||||
"gpr lr51 .32 1424 0\n"
|
||||
"gpr lr52 .32 1432 0\n"
|
||||
"gpr lr53 .32 1440 0\n"
|
||||
"gpr lr54 .32 1448 0\n"
|
||||
"gpr lr55 .32 1456 0\n"
|
||||
"gpr lr56 .32 1464 0\n"
|
||||
"gpr lr57 .32 1472 0\n"
|
||||
"gpr lr58 .32 1480 0\n"
|
||||
"gpr lr59 .32 1488 0\n"
|
||||
"gpr lr60 .32 1496 0\n"
|
||||
"gpr lr61 .32 1504 0\n"
|
||||
"gpr lr62 .32 1512 0\n"
|
||||
"gpr lr63 .32 1520 0\n"
|
||||
"gpr lr64 .32 1528 0\n"
|
||||
"gpr lr65 .32 1536 0\n"
|
||||
"gpr lr66 .32 1544 0\n"
|
||||
"gpr lr67 .32 1552 0\n"
|
||||
"gpr lr68 .32 1560 0\n"
|
||||
"gpr lr69 .32 1568 0\n"
|
||||
"gpr lr70 .32 1576 0\n"
|
||||
"gpr lr71 .32 1584 0\n"
|
||||
"gpr lr72 .32 1592 0\n"
|
||||
"gpr lr73 .32 1600 0\n"
|
||||
"gpr lr74 .32 1608 0\n"
|
||||
"gpr lr75 .32 1616 0\n"
|
||||
"gpr lr76 .32 1624 0\n"
|
||||
"gpr lr77 .32 1632 0\n"
|
||||
"gpr lr78 .32 1640 0\n"
|
||||
"gpr lr79 .32 1648 0\n"
|
||||
"gpr lr80 .32 1656 0\n"
|
||||
"gpr lr81 .32 1664 0\n"
|
||||
"gpr lr82 .32 1672 0\n"
|
||||
"gpr lr83 .32 1680 0\n"
|
||||
"gpr lr84 .32 1688 0\n"
|
||||
"gpr lr85 .32 1696 0\n"
|
||||
"gpr lr86 .32 1704 0\n"
|
||||
"gpr lr87 .32 1712 0\n"
|
||||
"gpr lr88 .32 1720 0\n"
|
||||
"gpr lr89 .32 1728 0\n"
|
||||
"gpr lr90 .32 1736 0\n"
|
||||
"gpr lr91 .32 1744 0\n"
|
||||
"gpr lr92 .32 1752 0\n"
|
||||
"gpr lr93 .32 1760 0\n"
|
||||
"gpr lr94 .32 1768 0\n"
|
||||
"gpr lr95 .32 1776 0\n"
|
||||
"gpr lr96 .32 1784 0\n"
|
||||
"gpr lr97 .32 1792 0\n"
|
||||
"gpr lr98 .32 1800 0\n"
|
||||
"gpr lr99 .32 1808 0\n"
|
||||
"gpr lr100 .32 1816 0\n"
|
||||
"gpr lr101 .32 1824 0\n"
|
||||
"gpr lr102 .32 1832 0\n"
|
||||
"gpr lr103 .32 1840 0\n"
|
||||
"gpr lr104 .32 1848 0\n"
|
||||
"gpr lr105 .32 1856 0\n"
|
||||
"gpr lr106 .32 1864 0\n"
|
||||
"gpr lr107 .32 1872 0\n"
|
||||
"gpr lr108 .32 1880 0\n"
|
||||
"gpr lr109 .32 1888 0\n"
|
||||
"gpr lr110 .32 1896 0\n"
|
||||
"gpr lr111 .32 1904 0\n"
|
||||
"gpr lr112 .32 1912 0\n"
|
||||
"gpr lr113 .32 1920 0\n"
|
||||
"gpr lr114 .32 1928 0\n"
|
||||
"gpr lr115 .32 1936 0\n"
|
||||
"gpr lr116 .32 1944 0\n"
|
||||
"gpr lr117 .32 1952 0\n"
|
||||
"gpr lr118 .32 1960 0\n"
|
||||
"gpr lr119 .32 1968 0\n"
|
||||
"gpr lr120 .32 1976 0\n"
|
||||
"gpr lr121 .32 1984 0\n"
|
||||
"gpr lr122 .32 1992 0\n"
|
||||
"gpr lr123 .32 2000 0\n"
|
||||
"gpr lr124 .32 2008 0\n"
|
||||
"gpr lr125 .32 2016 0\n"
|
||||
"gpr lr126 .32 2024 0\n"
|
||||
"gpr lr127 .32 2032 0\n"
|
||||
"gpr lr128 .32 2040 0\n";
|
||||
return r_reg_set_profile_string (reg, p);
|
||||
#include "amd29k/regs.h"
|
||||
;
|
||||
return strdup (p);
|
||||
}
|
||||
|
||||
static int archinfo(RArchConfig *cfg, ut32 q) {
|
||||
static int archinfo(RArchSession *cfg, ut32 q) {
|
||||
if (q == R_ARCH_INFO_JMPMID) {
|
||||
return -1;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
static int decode(RArch *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, ut32 mask, void *user) {
|
||||
RArchConfig *cfg = a->cfg;
|
||||
static bool decode(RArchSession *a, RAnalOp *op, RArchDecodeMask mask) {
|
||||
const ut8 *buf = op->bytes;
|
||||
int len = op->size;
|
||||
ut64 addr = op->addr;
|
||||
|
||||
RArchConfig *cfg = a->config;
|
||||
op->size = 4;
|
||||
op->eob = false;
|
||||
|
||||
@ -964,7 +703,7 @@ RArchPlugin r_arch_plugin_amd29k = {
|
||||
.esil = false,
|
||||
.info = archinfo,
|
||||
.decode = &decode,
|
||||
.set_reg_profile = &set_reg_profile,
|
||||
.regs = regs,
|
||||
.cpus = CPU_29000 ","CPU_29050,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
};
|
||||
|
@ -3,45 +3,9 @@
|
||||
#include <r_arch.h>
|
||||
#include "./i4004/gperfdb.c"
|
||||
|
||||
static char *i4004_regs(RArchInstance *a) {
|
||||
static char *i4004_regs(RArchSession *a) {
|
||||
const char *p =
|
||||
"=PC PC\n"
|
||||
/* syntax not yet supported */
|
||||
// "=SP &PC1\n"
|
||||
"=A0 r0\n"
|
||||
"=A1 r1\n"
|
||||
"=A2 r2\n"
|
||||
"=A3 r3\n"
|
||||
"=R0 r0\n"
|
||||
"gpr r0 .4 0 0\n"
|
||||
"gpr r1 .4 .4 0\n"
|
||||
"gpr r0r1 1 0 0\n"
|
||||
"gpr r2 .4 .8 0\n"
|
||||
"gpr r3 .4 .12 0\n"
|
||||
"gpr r2r3 1 1 0\n"
|
||||
"gpr r4 .4 .16 0\n"
|
||||
"gpr r5 .4 .20 0\n"
|
||||
"gpr r4r5 1 2 0\n"
|
||||
"gpr r6 .4 .24 0\n"
|
||||
"gpr r7 .4 .28 0\n"
|
||||
"gpr r6r7 1 3 0\n"
|
||||
"gpr r8 .4 .32 0\n"
|
||||
"gpr r9 .4 .36 0\n"
|
||||
"gpr r8r9 1 4 0\n"
|
||||
"gpr r10 .4 .40 0\n"
|
||||
"gpr r11 .4 .44 0\n"
|
||||
"gpr r10r11 1 5 0\n"
|
||||
"gpr r12 .4 .52 0\n"
|
||||
"gpr r13 .4 .56 0\n"
|
||||
"gpr r12r13 1 6 0\n"
|
||||
"gpr r14 .4 .60 0\n"
|
||||
"gpr r15 .4 .64 0\n"
|
||||
"gpr r14r15 1 7 0\n"
|
||||
"gpr PC .12 .72 0\n"
|
||||
/* stack */
|
||||
"gpr PC1 .12 .88 0\n"
|
||||
"gpr PC2 .12 .104 0\n"
|
||||
"gpr PC3 .12 .120 0\n"
|
||||
#include "i4004/regs.h"
|
||||
;
|
||||
return strdup (p);
|
||||
}
|
||||
@ -90,7 +54,7 @@ static const char *i4004_f[16] = {
|
||||
};
|
||||
|
||||
static int i4004_get_ins_len(ut8 hex) {
|
||||
ut8 high = (hex & 0xf0)>>4;
|
||||
ut8 high = (hex & 0xf0) >> 4;
|
||||
int ret = i4004_ins_len[high];
|
||||
if (ret == 3) {
|
||||
ret = (hex & 1) ? 1 : 2;
|
||||
@ -98,7 +62,10 @@ static int i4004_get_ins_len(ut8 hex) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int i4004_decode(RArch *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, ut32 mask, void *user) {
|
||||
static bool i4004_decode(RArchSession *s, RAnalOp *op, RArchDecodeMask mask) {
|
||||
ut64 addr = op->addr;
|
||||
const ut8 *buf = op->bytes;
|
||||
int len = op->size;
|
||||
char basm[64];
|
||||
const size_t basz = sizeof (basm);
|
||||
int rlen = i4004_get_ins_len (*buf);
|
||||
@ -110,7 +77,9 @@ static int i4004_decode(RArch *a, RAnalOp *op, ut64 addr, const ut8 *buf, int le
|
||||
basm[0] = 0;
|
||||
|
||||
if (rlen > len) {
|
||||
return op->size = 0;
|
||||
op->size = 0;
|
||||
op->type = R_ANAL_OP_TYPE_ILL;
|
||||
return false;
|
||||
}
|
||||
switch (high) {
|
||||
case 0:
|
||||
@ -163,14 +132,14 @@ static int i4004_decode(RArch *a, RAnalOp *op, ut64 addr, const ut8 *buf, int le
|
||||
break;
|
||||
case 4:
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->jump = (ut16) (low<<8) | buf[1];
|
||||
op->jump = (ut16) (low << 8) | buf[1];
|
||||
if (mask & R_ARCH_OP_MASK_DISASM) {
|
||||
snprintf (basm, basz, "jun 0x%x", (ut16)op->jump);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
op->type = R_ANAL_OP_TYPE_CALL;
|
||||
op->jump = (ut16) (low<<8) | buf[1];
|
||||
op->jump = (ut16) (low << 8) | buf[1];
|
||||
op->fail = addr + rlen;
|
||||
if (mask & R_ARCH_OP_MASK_DISASM) {
|
||||
snprintf (basm, basz, "jms 0x%x", (ut16)op->jump);
|
||||
@ -248,11 +217,14 @@ static int i4004_decode(RArch *a, RAnalOp *op, ut64 addr, const ut8 *buf, int le
|
||||
if (mask & R_ARCH_OP_MASK_DISASM) {
|
||||
op->mnemonic = strdup (basm);
|
||||
}
|
||||
return op->size = rlen;
|
||||
op->size = rlen;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int i4004_encode(RArch *a, ut64 addr, const char *str, ut8 *outbuf, int outsize) {
|
||||
char *s = strdup (str);
|
||||
static bool i4004_encode(RArchSession *se, RAnalOp *op, RArchEncodeMask mask) {
|
||||
ut8 outbuf[32];
|
||||
// r_anal_op_set_bytes (op, addr, outbuf, outsize);
|
||||
char *s = strdup (op->mnemonic);
|
||||
r_str_case (s, false);
|
||||
s = r_str_replace (s, "_", "?", false); // mitigate a bug in sdb -C
|
||||
s = r_str_replace (s, ",", " _ ", false);
|
||||
@ -276,14 +248,16 @@ static int i4004_encode(RArch *a, ut64 addr, const char *str, ut8 *outbuf, int o
|
||||
if (hex_output) {
|
||||
r_str_argv_free (elems);
|
||||
free (s);
|
||||
r_hex_str2bin (hex_output, outbuf);
|
||||
int hexlen = r_hex_str2bin (hex_output, outbuf);
|
||||
op->size = hexlen;
|
||||
free (op->bytes);
|
||||
op->bytes = r_mem_dup (outbuf, hexlen);
|
||||
free (hex_output);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
if (strlen (elems[0]) != 3) {
|
||||
r_str_argv_free (elems);
|
||||
free (s);
|
||||
return 0;
|
||||
}
|
||||
int ret = 0;
|
||||
@ -374,10 +348,11 @@ static int i4004_encode(RArch *a, ut64 addr, const char *str, ut8 *outbuf, int o
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
free (op->bytes);
|
||||
op->bytes = r_mem_dup (outbuf, ret);
|
||||
op->size = ret;
|
||||
r_str_argv_free (elems);
|
||||
free (s);
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
RArchPlugin r_arch_plugin_i4004 = {
|
||||
|
@ -4,7 +4,9 @@
|
||||
#include <r_lib.h>
|
||||
#include "./jdh8/jdh8dis.c"
|
||||
|
||||
static int decode(RArch *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, ut32 mask, void *user) {
|
||||
static bool decode(RArchSession *s, RAnalOp *op, RArchDecodeMask mask) {
|
||||
const ut8 *buf = op->bytes;
|
||||
int len = op->size;
|
||||
int dlen = 0;
|
||||
char *o = jdh8Disass (buf, len, &dlen);
|
||||
op->mnemonic = strdup (o);
|
||||
|
@ -3,16 +3,6 @@
|
||||
#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) {
|
||||
return op->size = 1;
|
||||
}
|
||||
|
||||
static bool null_set_reg_profile(RArch* arch) {
|
||||
return r_reg_set_profile_string(arch->reg, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
RArchPlugin r_arch_plugin_null = {
|
||||
.name = "null",
|
||||
.desc = "Fallback/Null archysis plugin",
|
||||
|
@ -1,8 +1,7 @@
|
||||
/* radare - LGPL - Copyright 2010-2022 eloi <limited-entropy.com> */
|
||||
|
||||
#include <r_lib.h>
|
||||
#include <r_asm.h>
|
||||
#include <r_anal.h>
|
||||
#include <r_arch.h>
|
||||
#include "disas-asm.h"
|
||||
|
||||
#define BUFSZ 16
|
||||
@ -1166,50 +1165,18 @@ static int (*first_nibble_decode[])(RArch*,RAnalOp*,ut16) = {
|
||||
fpu_insn
|
||||
};
|
||||
|
||||
/* Set the profile register */
|
||||
static bool sh_set_reg_profile(RArchConfig* arch, struct r_reg_t *reg) {
|
||||
eprintf ("reg profile lol\n");
|
||||
//TODO Add system ( ssr, spc ) + fpu regs
|
||||
static char *regs(RArchSession *s) {
|
||||
const char * const p =
|
||||
"=PC pc\n"
|
||||
"=SN r0\n"
|
||||
"=SP r15\n"
|
||||
"=BP r14\n"
|
||||
"=A0 r4\n"
|
||||
"=A1 r5\n"
|
||||
"=A2 r6\n"
|
||||
"=A3 r7\n"
|
||||
"=R0 r0\n"
|
||||
"gpr r0 .32 0 0\n"
|
||||
"gpr r1 .32 4 0\n"
|
||||
"gpr r2 .32 8 0\n"
|
||||
"gpr r3 .32 12 0\n"
|
||||
"gpr r4 .32 16 0\n"
|
||||
"gpr r5 .32 20 0\n"
|
||||
"gpr r6 .32 24 0\n"
|
||||
"gpr r7 .32 28 0\n"
|
||||
"gpr r8 .32 32 0\n"
|
||||
"gpr r9 .32 36 0\n"
|
||||
"gpr r10 .32 40 0\n"
|
||||
"gpr r11 .32 44 0\n"
|
||||
"gpr r12 .32 48 0\n"
|
||||
"gpr r13 .32 52 0\n"
|
||||
"gpr r14 .32 56 0\n"
|
||||
"gpr r15 .32 60 0\n"
|
||||
"gpr pc .32 64 0\n"
|
||||
"gpr pr .32 68 0\n"
|
||||
"gpr sr .32 72 0\n"
|
||||
"gpr gbr .32 76 0\n"
|
||||
"gpr vbr .32 80 0\n"
|
||||
"gpr mach .32 84 0\n"
|
||||
"gpr macl .32 88 0\n";
|
||||
return r_reg_set_profile_string (reg, p);
|
||||
#include "sh/regs.h"
|
||||
;
|
||||
return strdup (p);
|
||||
}
|
||||
|
||||
static int archinfo(RArchConfig *a, ut32 q) {
|
||||
static int archinfo(RArchSession *s, ut32 q) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
// XXX this function should be generalized under the gnu-dis-asm utils
|
||||
static int sh_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info) {
|
||||
int delta = (memaddr - info->buffer_vma);
|
||||
if (delta < 0) {
|
||||
@ -1262,9 +1229,9 @@ static int disassemble(RArch *a, RAnalOp *op, const ut8 *buf, int len) {
|
||||
disasm_obj.stream = sb;
|
||||
|
||||
if (disasm_obj.endian == BFD_ENDIAN_BIG) {
|
||||
op->size = print_insn_shb ((bfd_vma)addr, &disasm_obj);
|
||||
} else {
|
||||
op->size = print_insn_shl ((bfd_vma)addr, &disasm_obj);
|
||||
} else {
|
||||
op->size = print_insn_shb ((bfd_vma)addr, &disasm_obj);
|
||||
}
|
||||
if (op->size == -1) {
|
||||
op->mnemonic = strdup ("(data)");
|
||||
@ -1277,12 +1244,17 @@ static int disassemble(RArch *a, RAnalOp *op, const ut8 *buf, int len) {
|
||||
|
||||
/* This is the basic operation analysis. Just initialize and jump to
|
||||
* routines defined in first_nibble_decode table */
|
||||
static int sh_op(RArch *a, RAnalOp *op, ut64 addr, const ut8 *data, int len, ut32 mask, void *user) {
|
||||
// static int sh_op(RArch *a, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) {
|
||||
if (!op || !a || !data || len < 2) {
|
||||
return 0;
|
||||
static bool decode(RArchSession *s, RAnalOp *op, RArchDecodeMask mask) {
|
||||
r_return_val_if_fail (s && op, false);
|
||||
if (!op || !s) {
|
||||
return false;
|
||||
}
|
||||
op->addr = addr;
|
||||
RArch *a = s->arch;
|
||||
if (op->size < 2) {
|
||||
return false;
|
||||
}
|
||||
int len = op->size;
|
||||
const ut8 *data = op->bytes;
|
||||
op->type = R_ANAL_OP_TYPE_UNK;
|
||||
op->size = 2;
|
||||
if (mask & R_ARCH_OP_MASK_DISASM) {
|
||||
@ -1290,9 +1262,10 @@ static int sh_op(RArch *a, RAnalOp *op, ut64 addr, const ut8 *data, int len, ut3
|
||||
// should be always 2?
|
||||
}
|
||||
bool be = R_ARCH_CONFIG_IS_BIG_ENDIAN (a->cfg);
|
||||
ut8 msb = be? data[0]: data[1];
|
||||
ut8 lsb = be? data[1]: data[0];
|
||||
return first_nibble_decode[(msb >> 4) & 0x0F](a, op, (ut16)(((ut16)msb << 8) | lsb));
|
||||
ut8 lsb = be? data[0]: data[1];
|
||||
ut8 msb = be? data[1]: data[0];
|
||||
op->size = first_nibble_decode[(msb >> 4) & 0x0F](a, op, (ut16)(((ut16)msb << 8) | lsb));
|
||||
return true;
|
||||
}
|
||||
|
||||
RArchPlugin r_arch_plugin_sh = {
|
||||
@ -1303,8 +1276,8 @@ RArchPlugin r_arch_plugin_sh = {
|
||||
.arch = "sh",
|
||||
.info = archinfo,
|
||||
.bits = 32,
|
||||
.decode = &sh_op,
|
||||
.set_reg_profile = &sh_set_reg_profile,
|
||||
.decode = &decode,
|
||||
.regs = regs,
|
||||
.esil = true
|
||||
};
|
||||
|
||||
|
37
libr/arch/p/i4004/regs.h
Normal file
37
libr/arch/p/i4004/regs.h
Normal file
@ -0,0 +1,37 @@
|
||||
"=PC PC\n"
|
||||
/* syntax not yet supported */
|
||||
// "=SP &PC1\n"
|
||||
"=A0 r0\n"
|
||||
"=A1 r1\n"
|
||||
"=A2 r2\n"
|
||||
"=A3 r3\n"
|
||||
"=R0 r0\n"
|
||||
"gpr r0 .4 0 0\n"
|
||||
"gpr r1 .4 .4 0\n"
|
||||
"gpr r0r1 1 0 0\n"
|
||||
"gpr r2 .4 .8 0\n"
|
||||
"gpr r3 .4 .12 0\n"
|
||||
"gpr r2r3 1 1 0\n"
|
||||
"gpr r4 .4 .16 0\n"
|
||||
"gpr r5 .4 .20 0\n"
|
||||
"gpr r4r5 1 2 0\n"
|
||||
"gpr r6 .4 .24 0\n"
|
||||
"gpr r7 .4 .28 0\n"
|
||||
"gpr r6r7 1 3 0\n"
|
||||
"gpr r8 .4 .32 0\n"
|
||||
"gpr r9 .4 .36 0\n"
|
||||
"gpr r8r9 1 4 0\n"
|
||||
"gpr r10 .4 .40 0\n"
|
||||
"gpr r11 .4 .44 0\n"
|
||||
"gpr r10r11 1 5 0\n"
|
||||
"gpr r12 .4 .52 0\n"
|
||||
"gpr r13 .4 .56 0\n"
|
||||
"gpr r12r13 1 6 0\n"
|
||||
"gpr r14 .4 .60 0\n"
|
||||
"gpr r15 .4 .64 0\n"
|
||||
"gpr r14r15 1 7 0\n"
|
||||
"gpr PC .12 .72 0\n"
|
||||
/* stack */
|
||||
"gpr PC1 .12 .88 0\n"
|
||||
"gpr PC2 .12 .104 0\n"
|
||||
"gpr PC3 .12 .120 0\n"
|
32
libr/arch/p/sh/regs.h
Normal file
32
libr/arch/p/sh/regs.h
Normal file
@ -0,0 +1,32 @@
|
||||
"=PC pc\n"
|
||||
"=SN r0\n"
|
||||
"=SP r15\n"
|
||||
"=BP r14\n"
|
||||
"=A0 r4\n"
|
||||
"=A1 r5\n"
|
||||
"=A2 r6\n"
|
||||
"=A3 r7\n"
|
||||
"=R0 r0\n"
|
||||
"gpr r0 .32 0 0\n"
|
||||
"gpr r1 .32 4 0\n"
|
||||
"gpr r2 .32 8 0\n"
|
||||
"gpr r3 .32 12 0\n"
|
||||
"gpr r4 .32 16 0\n"
|
||||
"gpr r5 .32 20 0\n"
|
||||
"gpr r6 .32 24 0\n"
|
||||
"gpr r7 .32 28 0\n"
|
||||
"gpr r8 .32 32 0\n"
|
||||
"gpr r9 .32 36 0\n"
|
||||
"gpr r10 .32 40 0\n"
|
||||
"gpr r11 .32 44 0\n"
|
||||
"gpr r12 .32 48 0\n"
|
||||
"gpr r13 .32 52 0\n"
|
||||
"gpr r14 .32 56 0\n"
|
||||
"gpr r15 .32 60 0\n"
|
||||
"gpr pc .32 64 0\n"
|
||||
"gpr pr .32 68 0\n"
|
||||
"gpr sr .32 72 0\n"
|
||||
"gpr gbr .32 76 0\n"
|
||||
"gpr vbr .32 80 0\n"
|
||||
"gpr mach .32 84 0\n"
|
||||
"gpr macl .32 88 0\n"
|
64
libr/arch/session.c
Normal file
64
libr/arch/session.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* radare2 - LGPL - Copyright 2022 - pancake */
|
||||
|
||||
#include <r_arch.h>
|
||||
#include <r_util.h>
|
||||
|
||||
#if 0
|
||||
// pseudocode
|
||||
var a = arch.session("x86", {bits: 64});
|
||||
var op = new RArchOp ();
|
||||
op.setBytes("\x90");
|
||||
if (!a.decode(op)) {
|
||||
println("cannot decode");
|
||||
}
|
||||
printfln (a.mnemonic);
|
||||
#endif
|
||||
|
||||
R_API RArchSession *r_arch_session(RArch *arch, RArchConfig *cfg, RArchPlugin *ap) {
|
||||
RArchSession *ai = R_NEW0 (RArchSession);
|
||||
if (!ai) {
|
||||
return NULL;
|
||||
}
|
||||
if (ai) {
|
||||
ai->arch = arch;
|
||||
ai->config = cfg;
|
||||
ai->plugin = ap;
|
||||
ai->user = NULL;
|
||||
RArchPluginInitCallback init = R_UNWRAP3 (ai, plugin, init);
|
||||
if (init) {
|
||||
bool res = init (ai); // must fill ai->data
|
||||
if (!res) {
|
||||
R_FREE (ai);
|
||||
}
|
||||
}
|
||||
}
|
||||
// resolve and instantiate plugin by name (
|
||||
return ai;
|
||||
}
|
||||
|
||||
R_API bool r_arch_session_decode(RArchSession *ai, RAnalOp *op, RArchDecodeMask mask) {
|
||||
RArchPluginDecodeCallback decode = R_UNWRAP3 (ai, plugin, decode);
|
||||
if (decode != NULL) {
|
||||
return decode (ai, op, mask);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API bool r_arch_session_encode(RArchSession *ai, RAnalOp *op, RArchEncodeMask mask) {
|
||||
RArchPluginEncodeCallback encode = R_UNWRAP3 (ai, plugin, encode);
|
||||
if (encode != NULL) {
|
||||
return encode (ai, op, mask);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_arch_session_info(RArchSession *s, int query) {
|
||||
if (!s) {
|
||||
return -1;
|
||||
}
|
||||
RArchPluginInfoCallback info = R_UNWRAP3 (s, plugin, info);
|
||||
if (info != NULL) {
|
||||
return info (s, query);
|
||||
}
|
||||
return -1;
|
||||
}
|
@ -1047,6 +1047,8 @@ R_API void r_anal_type_list(RAnal *a, short category, short enabled);
|
||||
R_API const char *r_anal_datatype_tostring(RAnalDataType t);
|
||||
R_API RAnalType *r_anal_str_to_type(RAnal *a, const char* s);
|
||||
R_API bool r_anal_op_nonlinear(int t);
|
||||
R_API bool r_anal_op_set_bytes(RAnalOp *op, ut64 addr, const ut8* data, int size);
|
||||
R_API bool r_anal_op_set_mnemonic(RAnalOp *op, ut64 addr, const char *s);
|
||||
R_API const char *r_anal_op_direction_tostring(RAnalOp *op);
|
||||
R_API bool r_anal_op_ismemref(int t);
|
||||
R_API const char *r_anal_optype_tostring(int t);
|
||||
|
@ -225,6 +225,7 @@ typedef struct r_anal_op_t {
|
||||
ut32 type2; /* used by java */
|
||||
RAnalStackOp stackop; /* operation on stack? */
|
||||
_RAnalCond cond; /* condition type */
|
||||
ut8 *bytes; /* can be null, but is used for encoding and decoding, malloc of `size` */
|
||||
int size; /* size in bytes of opcode */
|
||||
int nopcode; /* number of bytes representing the opcode (not the arguments) TODO: find better name */
|
||||
int cycles; /* cpu-cycles taken by instruction */
|
||||
@ -248,8 +249,8 @@ typedef struct r_anal_op_t {
|
||||
RList *access; /* RAnalValue access information */
|
||||
RStrBuf esil;
|
||||
RStrBuf opex;
|
||||
const char *reg; /* destination register */
|
||||
const char *ireg; /* register used for indirect memory computation*/
|
||||
const char *reg; /* destination register rename to dreg or dst_reg */
|
||||
const char *ireg; /* register used for indirect memory computation . TODO rename to ind_reg */
|
||||
int scale;
|
||||
ut64 disp;
|
||||
RAnalSwitchOp *switch_op;
|
||||
|
@ -87,49 +87,36 @@ typedef struct r_arch_decoder_t {
|
||||
|
||||
typedef struct r_arch_t {
|
||||
RList *plugins; // all plugins
|
||||
struct r_arch_session_t *session;
|
||||
// HtPP *ht_plugins; faster resolution by name
|
||||
#if 1
|
||||
struct r_arch_instance_t *cur; // this var must deprecate current!
|
||||
RArchDecoder *current; // currently used decoder
|
||||
HtPP *decoders; // as decoders instantiated plugins
|
||||
RArchConfig *cfg; // config
|
||||
RArchConfig *cfg; // global / default config
|
||||
bool autoselect;
|
||||
#endif
|
||||
} RArch;
|
||||
|
||||
typedef struct r_arch_instance_t {
|
||||
typedef struct r_arch_session_t {
|
||||
struct r_arch_t *arch;
|
||||
struct r_arch_plugin_t *plugin;
|
||||
RArchConfig *config; // TODO remove arch->config!
|
||||
void *data;
|
||||
void *user;
|
||||
} RArchInstance;
|
||||
R_REF_TYPE;
|
||||
} RArchSession;
|
||||
|
||||
typedef int (*RArchOpAsmCallback)(RArch *a, ut64 addr, const char *str, ut8 *outbuf, int outlen);
|
||||
// typedef int (*RArchPluginInfoCallback)(RArchInstance *i, ut32 query);
|
||||
typedef int (*RArchPluginInfoCallback)(RArchConfig *cfg, ut32 query);
|
||||
// typedef int (*RArchPluginDecodeCallback)(RArchConfig *cfg, struct r_anal_op_t *op, ut64 addr, const ut8 *data, int len, ut32 mask, void *user);
|
||||
typedef int (*RArchPluginDecodeCallback)(RArch *cfg, struct r_anal_op_t *op, ut64 addr, const ut8 *data, int len, ut32 mask, void *user);
|
||||
typedef char *(*RArchPluginRegistersCallback)(RArchInstance *ai);
|
||||
#if 0
|
||||
// addr, data/len and *user can be taken from RAnalOp, so the user must fill those fields before calling this functions
|
||||
R_API int r_arch_op_setbytes(op, ut64 addr, const ut8* data, int len);
|
||||
typedef bool (*RArchPluginDecodeCallback)(RArchInstance *cfg, struct r_anal_op_t *op, RArchDecodeMask mask);
|
||||
typedef bool (*RArchPluginEncodeCallback)(RArchInstance *cfg, struct r_anal_op_t *op);
|
||||
/*
|
||||
RArchOp op;
|
||||
RArch *a = r_arch_new ();
|
||||
RArchConfig *cfg = r_arch_config_new ();
|
||||
RArchInstance *ai = r_arch_use (a, cfg, "x86");
|
||||
RArchOp *op = r_arch_new ();
|
||||
r_arch_op_setbytes (op, 0x10080840, "\x90", 1);
|
||||
if (r_arch_instance_decode (ai, op)) {
|
||||
r_cons_printf ("Disasm of 0x90 is %s\n", r_arch_op_tostring (op));
|
||||
} else {
|
||||
R_LOG_ERROR ("Cannot disassemble");
|
||||
}
|
||||
r_arch_op_free (op);
|
||||
r_arch_instance_free (ai);
|
||||
r_arch_free (a);
|
||||
*/
|
||||
#endif
|
||||
typedef int (*RArchPluginInfoCallback)(RArchSession *cfg, ut32 query);
|
||||
typedef char *(*RArchPluginRegistersCallback)(RArchSession *ai);
|
||||
|
||||
typedef ut32 RArchDecodeMask;
|
||||
typedef ut32 RArchEncodeMask; // syntax ?
|
||||
|
||||
typedef bool (*RArchPluginDecodeCallback)(RArchSession *cfg, struct r_anal_op_t *op, RArchDecodeMask mask);
|
||||
typedef bool (*RArchPluginEncodeCallback)(RArchSession *cfg, struct r_anal_op_t *op, RArchEncodeMask mask);
|
||||
typedef bool (*RArchPluginInitCallback)(RArchSession *s);
|
||||
typedef bool (*RArchPluginFiniCallback)(RArchSession *s);
|
||||
|
||||
typedef struct r_arch_plugin_t {
|
||||
char *name;
|
||||
@ -143,13 +130,12 @@ typedef struct r_arch_plugin_t {
|
||||
ut32 bits;
|
||||
ut32 addr_bits;
|
||||
bool esil;
|
||||
bool (*init)(void **user); // Should return an RArchSession, this struct contains all the info we need
|
||||
void (*fini)(void *user);
|
||||
RArchPluginInitCallback init;
|
||||
RArchPluginInitCallback fini;
|
||||
RArchPluginInfoCallback info;
|
||||
RArchPluginDecodeCallback decode;
|
||||
RArchPluginRegistersCallback regs;
|
||||
bool (*set_reg_profile)(RArchConfig *cfg, struct r_reg_t *reg);
|
||||
RArchOpAsmCallback encode;
|
||||
RArchPluginEncodeCallback encode;
|
||||
RArchPluginDecodeCallback decode;
|
||||
//TODO: reenable this later
|
||||
// bool (*esil_init)(RAnalEsil *esil);
|
||||
// void (*esil_fini)(RAnalEsil *esil);
|
||||
@ -161,20 +147,28 @@ R_API bool r_arch_load_decoder(RArch *arch, const char *dname);
|
||||
R_API bool r_arch_use_decoder(RArch *arch, const char *dname);
|
||||
R_API bool r_arch_unload_decoder(RArch *arch, const char *dname);
|
||||
|
||||
R_API int r_arch_info(RArch *arch, const char *dname, ut32 query);
|
||||
R_API int r_arch_decode(RArch *arch, const char *dname, struct r_anal_op_t *op, ut64 addr, const ut8 *data, int len, ut32 mask);
|
||||
R_API int r_arch_encode(RArch *a, ut64 addr, const char *s, ut8 *outbuf, int outlen);
|
||||
R_API bool r_arch_set_reg_profile(RArch *arch, const char *dname, struct r_reg_t *reg);
|
||||
R_API int r_arch_info(RArch *arch, int query);
|
||||
|
||||
// deprecate
|
||||
R_API bool r_arch_decode(RArch *a, RAnalOp *op, RArchDecodeMask mask);
|
||||
// deprecate
|
||||
R_API bool r_arch_encode(RArch *a, RAnalOp *op, RArchEncodeMask mask);
|
||||
//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);
|
||||
|
||||
// instance.c
|
||||
// R_API RArchInstance r_arch_use(RArch *arch, RArchConfig *config, const char *name);
|
||||
R_API RArchSession *r_arch_session(RArch *arch, RArchConfig *cfg, RArchPlugin *ap);
|
||||
R_API bool r_arch_session_decode(RArchSession *ai, RAnalOp *op, RArchDecodeMask mask);
|
||||
R_API bool r_arch_session_encode(RArchSession *ai, RAnalOp *op, RArchEncodeMask mask);
|
||||
|
||||
// arch.c
|
||||
R_API RArch *r_arch_new(void);
|
||||
R_API bool r_arch_use(RArch *arch, RArchConfig *config, const char *name);
|
||||
// instance.c
|
||||
// R_API RArchSession r_arch_use(RArch *arch, RArchConfig *config, const char *name);
|
||||
|
||||
R_API bool r_arch_set_bits(RArch *arch, ut32 bits);
|
||||
|
||||
|
||||
R_API bool r_arch_set_endian(RArch *arch, ut32 endian);
|
||||
R_API bool r_arch_set_arch(RArch *arch, char *archname);
|
||||
R_API bool r_arch_add(RArch *arch, RArchPlugin *ap);
|
||||
@ -184,8 +178,13 @@ R_API void r_arch_free(RArch *arch);
|
||||
// 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 void r_arch_config_set_bits(RArchConfig *config, int bits);
|
||||
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);
|
||||
R_API void r_arch_config_free(RArchConfig *);
|
||||
|
||||
|
||||
// the archconfig inside an arch session
|
||||
|
||||
// XXX deprecate those names are uglyies and we can reuse R_PERM
|
||||
typedef enum {
|
||||
|
@ -22,13 +22,11 @@ EOF
|
||||
EXPECT=<<EOF
|
||||
mov.l r14, @-r15
|
||||
mov r15, r14
|
||||
(data)
|
||||
unaligned
|
||||
invalid
|
||||
mov.l @r1, r1
|
||||
mov r1, r2
|
||||
add 0x01, r2
|
||||
(data)
|
||||
unaligned
|
||||
invalid
|
||||
mov.l r2, @r1
|
||||
nop
|
||||
mov r14, r15
|
||||
|
@ -1,11 +1,11 @@
|
||||
dE "bt 0x00000004" 0x8900
|
||||
dE "bt 0x00000000" 0x89fe
|
||||
dE "bra 0x00000004" 0xa000
|
||||
dE "bra 0x00000006" 0xa001
|
||||
dE "bsr 0x00000004" 0xb000
|
||||
dE "bsr 0x00000002" 0xbfff
|
||||
dE "bt 0x00000004" 8900
|
||||
dE "bt 0x00000000" 89fe
|
||||
dE "bra 0x00000004" a000
|
||||
dE "bra 0x00000006" a001
|
||||
dE "bsr 0x00000004" b000
|
||||
dE "bsr 0x00000002" bfff
|
||||
dE "bsr 0x0000000e" 0xbffd 0x10
|
||||
dE "tst 0xFF, r0" 0xc8ff
|
||||
dE "tst 0xFF, r0" c8ff
|
||||
dE "mov.w @(0x0,pc), r0" 9000
|
||||
dEB "mov.w @(0x1fe,pc), r0" 90ff
|
||||
dE "mov.l @(0x0,pc), r0" d000
|
||||
|
@ -572,7 +572,7 @@ RUN
|
||||
|
||||
NAME=rasm -a sh -d
|
||||
FILE=-
|
||||
CMDS=!rasm2 -a sh -d "008d 0b00 2920 fb8f 0900 0b42 e031"
|
||||
CMDS=!rasm2 -a sh -d "8d00 000b 2029 8ffb 0009 420b 31e0"
|
||||
EXPECT=<<EOF
|
||||
bt.s 0x00000004
|
||||
rts
|
||||
@ -586,15 +586,15 @@ RUN
|
||||
|
||||
NAME=rasm -a sh -D
|
||||
FILE=-
|
||||
CMDS=!rasm2 -a sh -D "008d 0b00 2920 fb8f 0900 0b42 e031"
|
||||
CMDS=!rasm2 -a sh -D "8d00 000b 2029 8ffb 0009 420b 31e0"
|
||||
EXPECT=<<EOF
|
||||
0x00000000 2 008d bt.s 0x00000004
|
||||
0x00000002 2 0b00 rts
|
||||
0x00000004 2 2920 and r2, r0
|
||||
0x00000006 2 fb8f bf.s 0x00000000
|
||||
0x00000008 2 0900 nop
|
||||
0x0000000a 2 0b42 jsr @r2
|
||||
0x0000000c 2 e031 cmp/eq r14, r1
|
||||
0x00000000 2 8d00 bt.s 0x00000004
|
||||
0x00000002 2 000b rts
|
||||
0x00000004 2 2029 and r2, r0
|
||||
0x00000006 2 8ffb bf.s 0x00000000
|
||||
0x00000008 2 0009 nop
|
||||
0x0000000a 2 420b jsr @r2
|
||||
0x0000000c 2 31e0 cmp/eq r14, r1
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user