mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 13:19:54 +00:00
Migrate xcore plugin ##arch
This commit is contained in:
parent
96bc36135f
commit
6501345848
2
dist/plugins-cfg/plugins.def.cfg
vendored
2
dist/plugins-cfg/plugins.def.cfg
vendored
@ -57,7 +57,7 @@ arch.v850
|
||||
arch.vax
|
||||
arch.ws
|
||||
anal.x86_cs
|
||||
anal.xcore_cs
|
||||
arch.xcore_cs
|
||||
arch.xtensa
|
||||
arch.z80
|
||||
arch.amd29k
|
||||
|
2
dist/plugins-cfg/plugins.mingw.cfg
vendored
2
dist/plugins-cfg/plugins.mingw.cfg
vendored
@ -44,7 +44,7 @@ arch.ws
|
||||
arch.xap
|
||||
anal.x86_cs
|
||||
arch.m68k_gnu
|
||||
anal.xcore_cs
|
||||
arch.xcore_cs
|
||||
arch.z80
|
||||
arch.v810
|
||||
arch.vax
|
||||
|
2
dist/plugins-cfg/plugins.nogpl.cfg
vendored
2
dist/plugins-cfg/plugins.nogpl.cfg
vendored
@ -21,7 +21,7 @@ anal.tms320
|
||||
arch.v850
|
||||
arch.ws
|
||||
anal.x86_cs
|
||||
anal.xcore_cs
|
||||
arch.xcore_cs
|
||||
arch.null
|
||||
arch.i4004
|
||||
esil.dummy
|
||||
|
2
dist/plugins-cfg/plugins.static.cfg
vendored
2
dist/plugins-cfg/plugins.static.cfg
vendored
@ -32,7 +32,7 @@ arch.lanai
|
||||
arch.ws
|
||||
arch.xap
|
||||
anal.x86_cs
|
||||
anal.xcore_cs
|
||||
arch.xcore_cs
|
||||
arch.z80
|
||||
arch.vax
|
||||
arch.6502
|
||||
|
2
dist/plugins-cfg/plugins.static.nogpl.cfg
vendored
2
dist/plugins-cfg/plugins.static.nogpl.cfg
vendored
@ -19,7 +19,7 @@ arch.s390_cs
|
||||
arch.ws
|
||||
arch.xap
|
||||
anal.x86_cs
|
||||
anal.xcore_cs
|
||||
arch.xcore_cs
|
||||
arch.lh5801
|
||||
arch.6502
|
||||
arch.snes
|
||||
|
2
dist/plugins-cfg/plugins.termux.cfg
vendored
2
dist/plugins-cfg/plugins.termux.cfg
vendored
@ -20,7 +20,7 @@ anal.sparc_cs
|
||||
arch.sparc_gnu
|
||||
arch.v850
|
||||
anal.x86_cs
|
||||
anal.xcore_cs
|
||||
arch.xcore_cs
|
||||
arch.z80
|
||||
arch.mcore
|
||||
arch.vax
|
||||
|
@ -77,7 +77,7 @@ r_anal_sources = [
|
||||
'p/anal_tms320.c',
|
||||
# join_paths('arch/whitespace/wsdis.c'),
|
||||
'p/anal_x86_cs.c',
|
||||
'p/anal_xcore_cs.c',
|
||||
'../arch/p/xcore_cs/plugin.c',
|
||||
#join_paths('arch','gb','meta_gb_cmt.c'),
|
||||
'../arch/p/msp430/plugin.c',
|
||||
'../arch/p/msp430/msp430_disas.c',
|
||||
|
@ -1,12 +0,0 @@
|
||||
OBJ_XCORE_CS=anal_xcore_cs.o
|
||||
|
||||
include p/capstone.mk
|
||||
|
||||
STATIC_OBJ+=${OBJ_XCORE_CS}
|
||||
TARGET_XCORE_CS=anal_xcore_cs.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_XCORE_CS}
|
||||
|
||||
${TARGET_XCORE_CS}: ${OBJ_XCORE_CS}
|
||||
${CC} ${CFLAGS} $(call libname,anal_xcore_cs) $(CS_CFLAGS) \
|
||||
-o anal_xcore_cs.${EXT_SO} ${OBJ_XCORE_CS} $(CS_LDFLAGS)
|
@ -113,6 +113,7 @@ r_arch_sources = [
|
||||
'p/msp430/msp430_disas.c',
|
||||
'p/h8300/plugin.c',
|
||||
'p/h8300/h8300_disas.c',
|
||||
'p/xcore_cs/plugin.c',
|
||||
# python
|
||||
'p/pyc/plugin.c',
|
||||
'p/pyc/opcode_all.c',
|
||||
|
12
libr/arch/p/xcore_cs.mk
Normal file
12
libr/arch/p/xcore_cs.mk
Normal file
@ -0,0 +1,12 @@
|
||||
OBJ_XCORE_CS=p/xcore_cs/plugin.o
|
||||
|
||||
include p/capstone.mk
|
||||
|
||||
STATIC_OBJ+=${OBJ_XCORE_CS}
|
||||
TARGET_XCORE_CS=xcore_cs.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_XCORE_CS}
|
||||
|
||||
${TARGET_XCORE_CS}: ${OBJ_XCORE_CS}
|
||||
${CC} ${CFLAGS} $(call libname,xcore_cs) $(CS_CFLAGS) \
|
||||
-o xcore_cs.${EXT_SO} ${OBJ_XCORE_CS} $(CS_LDFLAGS)
|
@ -14,8 +14,8 @@
|
||||
#define CSINC XCORE
|
||||
#define CSINC_MODE \
|
||||
CS_MODE_BIG_ENDIAN \
|
||||
| (a->config->cpu != NULL && ((!strcmp (a->config->cpu, "v9"))) ? CS_MODE_V9 : 0)
|
||||
#include "capstone.inc"
|
||||
| (as->config->cpu != NULL && ((!strcmp (as->config->cpu, "v9"))) ? CS_MODE_V9 : 0)
|
||||
#include "../capstone.inc"
|
||||
|
||||
static void opex(RStrBuf *buf, csh handle, cs_insn *insn) {
|
||||
int i;
|
||||
@ -59,10 +59,20 @@ static void opex(RStrBuf *buf, csh handle, cs_insn *insn) {
|
||||
pj_free (pj);
|
||||
}
|
||||
|
||||
static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
|
||||
csh handle = init_capstone (a);
|
||||
static csh cs_handle_for_session(RArchSession *as) {
|
||||
r_return_val_if_fail (as && as->data, 0);
|
||||
CapstonePluginData *pd = as->data;
|
||||
return pd->cs_handle;
|
||||
}
|
||||
|
||||
static bool decode(RArchSession *as, RAnalOp *op, RAnalOpMask mask) {
|
||||
const ut64 addr = op->addr;
|
||||
const ut8 *buf = op->bytes;
|
||||
const int len = op->size;
|
||||
|
||||
csh handle = cs_handle_for_session (as);
|
||||
if (handle == 0) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
cs_insn *insn;
|
||||
@ -117,25 +127,60 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn
|
||||
}
|
||||
cs_free (insn, n);
|
||||
}
|
||||
return op->size;
|
||||
return op->size > 0;
|
||||
}
|
||||
|
||||
RAnalPlugin r_anal_plugin_xcore_cs = {
|
||||
static int archinfo(RArchSession *as, ut32 q) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *mnemonics(RArchSession *as, int id, bool json) {
|
||||
CapstonePluginData *cpd = as->data;
|
||||
return r_arch_cs_mnemonics (as, cpd->cs_handle, id, json);
|
||||
}
|
||||
|
||||
static bool init(RArchSession *as) {
|
||||
r_return_val_if_fail (as, false);
|
||||
if (as->data) {
|
||||
R_LOG_WARN ("Already initialized");
|
||||
return false;
|
||||
}
|
||||
as->data = R_NEW0 (CapstonePluginData);
|
||||
CapstonePluginData *cpd = (CapstonePluginData*)as->data;
|
||||
if (!r_arch_cs_init (as, &cpd->cs_handle)) {
|
||||
R_LOG_ERROR ("Cannot initialize capstone");
|
||||
R_FREE (as->data);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool fini(RArchSession *as) {
|
||||
r_return_val_if_fail (as, false);
|
||||
CapstonePluginData *cpd = as->data;
|
||||
cs_close (&cpd->cs_handle);
|
||||
R_FREE (as->data);
|
||||
return true;
|
||||
}
|
||||
|
||||
RArchPlugin r_arch_plugin_xcore_cs = {
|
||||
.name = "xcore",
|
||||
.desc = "Capstone XCORE analysis",
|
||||
.license = "BSD",
|
||||
.esil = false,
|
||||
.arch = "xcore",
|
||||
.bits = 32,
|
||||
.op = &analop,
|
||||
//.set_reg_profile = &set_reg_profile,
|
||||
.mnemonics = cs_mnemonics,
|
||||
.bits = R_SYS_BITS_PACK1 (32),
|
||||
.decode = decode,
|
||||
.info = archinfo,
|
||||
//.regs = regs,
|
||||
.mnemonics = mnemonics,
|
||||
.init = init,
|
||||
.fini = fini,
|
||||
};
|
||||
|
||||
#ifndef R2_PLUGIN_INCORE
|
||||
R_API RLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_ANAL,
|
||||
.data = &r_anal_plugin_xcore_cs,
|
||||
.type = R_LIB_TYPE_ARCH,
|
||||
.data = &r_arch_plugin_xcore_cs,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
@ -1584,7 +1584,6 @@ extern RAnalPlugin r_anal_plugin_x86_cs;
|
||||
extern RAnalPlugin r_anal_plugin_x86_im;
|
||||
extern RAnalPlugin r_anal_plugin_x86_simple;
|
||||
extern RAnalPlugin r_anal_plugin_x86_udis;
|
||||
extern RAnalPlugin r_anal_plugin_xcore_cs;
|
||||
extern RAnalPlugin r_anal_plugin_pickle;
|
||||
extern RAnalPlugin r_anal_plugin_evm_cs;
|
||||
|
||||
|
@ -340,6 +340,7 @@ extern RArchPlugin r_arch_plugin_ppc_gnu;
|
||||
extern RArchPlugin r_arch_plugin_loongarch_gnu;
|
||||
extern RArchPlugin r_arch_plugin_6502_cs;
|
||||
extern RArchPlugin r_arch_plugin_m680x_cs;
|
||||
extern RArchPlugin r_arch_plugin_xcore_cs;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -169,7 +169,6 @@ anal_plugins += [
|
||||
'sparc_cs',
|
||||
'tms320',
|
||||
'x86_cs',
|
||||
'xcore_cs'
|
||||
]
|
||||
|
||||
arch_plugins += [
|
||||
@ -178,6 +177,7 @@ arch_plugins += [
|
||||
's390_cs',
|
||||
'm68k_cs',
|
||||
'm680x_cs',
|
||||
'xcore_cs'
|
||||
]
|
||||
|
||||
if no_user_plugins
|
||||
|
Loading…
Reference in New Issue
Block a user