* Add random documentation for dynamic language plugins
* Properly installation of vapi files - Lot of fixtures to build a external hello world in gtk+vala+r_asm - default staticplugins for r_asm are: mips, java and x86_olly by default - Add r_util.vapi and make .pc file point to -lr_util - Use .deps to generate dependencies between vapi files - Fix r_asm.vapi (Added Asm.Aop struct) - add set(string) method - asm/disasm -> assemble/disassemble * Fix warning + build in sign.c - Included in default build * Fix segfault in r_lib with NULL in opendir() * More fixtures for r_asm_plugin_* - use #ifndef CORELIB - drop 'static' * Update README
This commit is contained in:
parent
655d437e70
commit
19fa55ba33
|
@ -0,0 +1,34 @@
|
|||
There is a way to implement dynamic language plugins for radare...
|
||||
|
||||
A stub generator will be appreciated to create all the necessary
|
||||
boilerplate to write a single .c file calling the perl/python/ruby
|
||||
interface from each method hook.
|
||||
|
||||
We should define a common and simple way to design those inter-
|
||||
language communications.
|
||||
|
||||
With this interface properly defined we can get some more fun and
|
||||
write the language bindings using the same lang-C api.
|
||||
|
||||
A simple perl script can be used to parse function signatures and
|
||||
enums to fill the structures in the proper way (SWIG replacement)
|
||||
|
||||
help is welcome!
|
||||
|
||||
------------------8<------------------------------
|
||||
|
||||
some random food:
|
||||
|
||||
#include <r_lang_lib.h>
|
||||
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len)
|
||||
{
|
||||
LANG_PERL_SET_U8P("$buf", buf);
|
||||
LANG_PERL_SET_U64("$len", len);
|
||||
LANG_PERL(
|
||||
"print \"Hello World $len\";
|
||||
$ret = 1;")
|
||||
return LANG_PERL_GET($ret);
|
||||
}
|
||||
|
||||
PLUGIN_ASM("asm_ppc", "PPC disassembly plugin", NULL, NULL, &disasm, NULL);
|
|
@ -4,7 +4,7 @@ PFX=${DESTDIR}${PREFIX}
|
|||
#PREFIX=${PFX}
|
||||
|
||||
# Libraries
|
||||
LIBLIST=io util lib meta lang flags bin macro hash line cons line print config syscall range socket cmd asm anal parse search diff debug reg core var
|
||||
LIBLIST=io util lib meta lang flags bin macro hash line cons line print config syscall range socket cmd asm anal parse search diff debug reg core var sign
|
||||
|
||||
# Under development
|
||||
#LIBLIST+=print
|
||||
|
@ -39,6 +39,8 @@ install:
|
|||
@mkdir -p ${PREFIX}/lib/pkgconfig
|
||||
@cat libr.pc.acr | sed -e 's,@PREFIX@,${PREFIX},g' > libr.pc
|
||||
cp libr.pc ${PREFIX}/lib/pkgconfig
|
||||
@mkdir -p ${PREFIX}/share/vala/vapi
|
||||
cp vapi/*.vapi vapi/*.deps ${PREFIX}/share/vala/vapi
|
||||
@mkdir -p ${PREFIX}/lib/radare2
|
||||
@for a in `find */p -perm /u+x -type f`; \
|
||||
do echo " $$a"; cp $$a ${PREFIX}/lib/radare2 ; done
|
||||
|
@ -59,6 +61,7 @@ uninstall:
|
|||
echo ${PREFIX}/lib/$$a ; rm -f ${PREFIX}/lib/$$a ; done
|
||||
### includes
|
||||
-(cd include && for a in * ; do rm -f ${PREFIX}/libr/$$a ; done)
|
||||
cd vapi/ ; for a in *.vapi *.deps ; do rm ${PREFIX}/share/vala/vapi/$$a ; done
|
||||
### programs
|
||||
-@for a in `find */t -perm /u+x -type f | grep 2`; do \
|
||||
a=`echo $$a|awk -F / '{ print $$NF; }'`; \
|
||||
|
|
10
libr/README
10
libr/README
|
@ -14,6 +14,16 @@ The 'R' is for refactoring, reversing, radare, ...
|
|||
Each module has its own test directory (t/) which contains simple applications
|
||||
using the upper directory code and linking against the direct dependencies.
|
||||
|
||||
Each mode can own a plugin directory (p/) that contains extensions for the
|
||||
parent library module (libr/asm/p/asm_x86).
|
||||
|
||||
There's also the possibility to define a list of static plugins to be built
|
||||
inside the parent module. This way you can avoid some flexibility to ease
|
||||
portability and build single binaries with some embedded features.
|
||||
|
||||
The library can be used from 'pkg-config', this way you can easy build an
|
||||
application or plugin that links against libr or just few elements of it.
|
||||
|
||||
This enables a fine-grained test level for checking all functionalities in
|
||||
one shot and give us the opportunity to write radare2 as test programs.
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ int r_asm_init(struct r_asm_t *a)
|
|||
{
|
||||
int i;
|
||||
a->user = NULL;
|
||||
a->cur = NULL;
|
||||
INIT_LIST_HEAD(&a->asms);
|
||||
r_asm_set_bits(a, 32);
|
||||
r_asm_set_big_endian(a, 0);
|
||||
|
|
|
@ -91,7 +91,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
return aop->inst_len;
|
||||
}
|
||||
|
||||
static struct r_asm_handle_t r_asm_plugin_arm = {
|
||||
struct r_asm_handle_t r_asm_plugin_arm = {
|
||||
.name = "asm_arm",
|
||||
.desc = "ARM disassembly plugin",
|
||||
.init = NULL,
|
||||
|
@ -100,7 +100,9 @@ static struct r_asm_handle_t r_asm_plugin_arm = {
|
|||
.assemble = NULL
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
.data = &r_asm_plugin_arm
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -21,7 +21,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
return aop->inst_len;
|
||||
}
|
||||
|
||||
static struct r_asm_handle_t r_asm_plugin_csr = {
|
||||
struct r_asm_handle_t r_asm_plugin_csr = {
|
||||
.name = "asm_csr",
|
||||
.desc = "CSR disassembly plugin",
|
||||
.init = NULL,
|
||||
|
@ -30,7 +30,9 @@ static struct r_asm_handle_t r_asm_plugin_csr = {
|
|||
.assemble = NULL
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
.data = &r_asm_plugin_csr
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -35,7 +35,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
return aop->inst_len;
|
||||
}
|
||||
|
||||
static struct r_asm_handle_t r_asm_plugin_m68k = {
|
||||
struct r_asm_handle_t r_asm_plugin_m68k = {
|
||||
.name = "asm_m68k",
|
||||
.desc = "M68K disassembly plugin",
|
||||
.init = NULL,
|
||||
|
@ -44,7 +44,9 @@ static struct r_asm_handle_t r_asm_plugin_m68k = {
|
|||
.assemble = NULL
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
.data = &r_asm_plugin_m68k
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -35,7 +35,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
return aop->inst_len;
|
||||
}
|
||||
|
||||
static struct r_asm_handle_t r_asm_plugin_ppc = {
|
||||
struct r_asm_handle_t r_asm_plugin_ppc = {
|
||||
.name = "asm_ppc",
|
||||
.desc = "PPC disassembly plugin",
|
||||
.init = NULL,
|
||||
|
|
|
@ -90,7 +90,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
return aop->inst_len;
|
||||
}
|
||||
|
||||
static struct r_asm_handle_t r_asm_plugin_sparc = {
|
||||
struct r_asm_handle_t r_asm_plugin_sparc = {
|
||||
.name = "asm_sparc",
|
||||
.desc = "SPARC disassembly plugin",
|
||||
.init = NULL,
|
||||
|
|
|
@ -35,7 +35,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
return aop->inst_len;
|
||||
}
|
||||
|
||||
static struct r_asm_handle_t r_asm_plugin_x86 = {
|
||||
struct r_asm_handle_t r_asm_plugin_x86 = {
|
||||
.name = "asm_x86",
|
||||
.desc = "X86 disassembly plugin",
|
||||
.init = NULL,
|
||||
|
@ -44,7 +44,9 @@ static struct r_asm_handle_t r_asm_plugin_x86 = {
|
|||
.assemble = NULL
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
.data = &r_asm_plugin_x86
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -38,7 +38,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
return aop->inst_len;
|
||||
}
|
||||
|
||||
static struct r_asm_handle_t r_asm_plugin_x86_bea = {
|
||||
struct r_asm_handle_t r_asm_plugin_x86_bea = {
|
||||
.name = "asm_x86_bea",
|
||||
.desc = "X86 disassembly plugin (bea engine)",
|
||||
.init = NULL,
|
||||
|
@ -47,7 +47,9 @@ static struct r_asm_handle_t r_asm_plugin_x86_bea = {
|
|||
.assemble = NULL
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
.data = &r_asm_plugin_x86_bea
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -49,7 +49,7 @@ static int assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
|||
return aop->inst_len;
|
||||
}
|
||||
|
||||
static struct r_asm_handle_t r_asm_plugin_x86_olly = {
|
||||
struct r_asm_handle_t r_asm_plugin_x86_olly = {
|
||||
.name = "asm_x86_olly",
|
||||
.desc = "X86 disassembly plugin (olly engine)",
|
||||
.init = NULL,
|
||||
|
@ -58,8 +58,9 @@ static struct r_asm_handle_t r_asm_plugin_x86_olly = {
|
|||
.assemble = &assemble
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
.data = &r_asm_plugin_x86_olly
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
#define _INCLUDE_CONFIG_H_
|
||||
|
||||
#define R_ASM_STATIC_PLUGINS \
|
||||
&r_asm_plugin_java, &r_asm_plugin_mips, 0
|
||||
&r_asm_plugin_java, \
|
||||
&r_asm_plugin_x86_olly, \
|
||||
&r_asm_plugin_mips, 0
|
||||
|
||||
#define R_BIN_STATIC_PLUGINS \
|
||||
0
|
||||
|
||||
|
|
|
@ -6,5 +6,5 @@ WINDOWS=0
|
|||
USE_RIO=1
|
||||
|
||||
# static plugins
|
||||
STATIC_ASM_PLUGINS=p/java.mk p/mips.mk
|
||||
STATIC_ASM_PLUGINS=p/x86olly.mk p/mips.mk p/java.mk
|
||||
STATIC_BIN_PLUGINS=
|
||||
|
|
|
@ -61,4 +61,11 @@ int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf);
|
|||
extern struct r_asm_handle_t r_asm_plugin_bf;
|
||||
extern struct r_asm_handle_t r_asm_plugin_java;
|
||||
extern struct r_asm_handle_t r_asm_plugin_mips;
|
||||
extern struct r_asm_handle_t r_asm_plugin_x86;
|
||||
extern struct r_asm_handle_t r_asm_plugin_arm;
|
||||
extern struct r_asm_handle_t r_asm_plugin_csr;
|
||||
extern struct r_asm_handle_t r_asm_plugin_m68k;
|
||||
extern struct r_asm_handle_t r_asm_plugin_x86_bea;
|
||||
extern struct r_asm_handle_t r_asm_plugin_x86_olly;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -169,17 +169,21 @@ int r_lib_opendir(struct r_lib_t *lib, const char *path)
|
|||
{
|
||||
char file[1024];
|
||||
struct dirent *de;
|
||||
DIR *dh = opendir(path);
|
||||
DIR *dh;
|
||||
|
||||
if (path == NULL)
|
||||
return R_FALSE;
|
||||
dh = opendir(path);
|
||||
if (dh == NULL) {
|
||||
IFDBG fprintf(stderr, "Cannot open directory '%s'\n", path);
|
||||
return -1;
|
||||
return R_FALSE;
|
||||
}
|
||||
while((de = (struct dirent *)readdir(dh))) {
|
||||
snprintf(file, 1023, "%s/%s", path, de->d_name);
|
||||
r_lib_open(lib, file);
|
||||
}
|
||||
closedir(dh);
|
||||
return 0;
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
int r_lib_list(struct r_lib_t *lib)
|
||||
|
|
|
@ -7,5 +7,5 @@ Name: libr
|
|||
Description: radare framework libraries
|
||||
Version: 0.1
|
||||
Requires:
|
||||
Libs: -L${libdir} -lr_core -lr_lang -lr_search -lr_cmd -lr_meta -lr_asm
|
||||
Libs: -L${libdir} -lr_core -lr_lang -lr_search -lr_cmd -lr_meta -lr_asm -lr_util
|
||||
Cflags: -I${includedir}/libr
|
||||
|
|
|
@ -18,7 +18,7 @@ int r_sign_set(struct r_sign_item_t *sig, const char *key, const char *value)
|
|||
sig->size = atoi(value);
|
||||
} else
|
||||
if (!strcmp(key, "cksum")) {
|
||||
sscanf(value, "%x", &sig->csum);
|
||||
sscanf(value, "%lx", &sig->csum);
|
||||
}
|
||||
return R_TRUE;
|
||||
// fprintf(stderr, "%s:%s\n", key, value);
|
||||
|
@ -84,8 +84,8 @@ int r_sign_info(struct r_sign_t *sig)
|
|||
struct r_sign_t *r_sign_free(struct r_sign_t *sig)
|
||||
{
|
||||
free (sig);
|
||||
struct list_head *pos;
|
||||
list_for_each_safe(pos, n, head) {
|
||||
struct list_head *pos, *n;
|
||||
list_for_each_safe(pos, n, &sig->items) {
|
||||
struct r_sign_item_t *i = list_entry(pos, struct r_sign_item_t, list);
|
||||
free(i->bytes);
|
||||
free(i);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
* Pluggify!
|
||||
* Add w32 0x2e syscall support
|
||||
* include syscalls from file
|
||||
* Added documentation string per-syscall in r_syscall_list_t
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
r_asm
|
||||
r_util
|
|
@ -0,0 +1 @@
|
|||
/* empty */
|
|
@ -27,6 +27,7 @@ namespace Radare {
|
|||
ATT = 2,
|
||||
OLLY = 3
|
||||
}
|
||||
|
||||
|
||||
[CCode (cprefix="R_ASM_PAR_")]
|
||||
public enum Parser {
|
||||
|
@ -35,6 +36,16 @@ namespace Radare {
|
|||
REALLOC = 2
|
||||
}
|
||||
|
||||
[CCode (cname="struct r_asm_aop_t")]
|
||||
public struct Aop {
|
||||
public int inst_len;
|
||||
public uint8 *buf;
|
||||
public string buf_asm;
|
||||
public string buf_hex;
|
||||
public string buf_err;
|
||||
//pointer
|
||||
}
|
||||
|
||||
public int arch;
|
||||
public int bits;
|
||||
public bool big_endian;
|
||||
|
@ -49,14 +60,16 @@ namespace Radare {
|
|||
public Asm();
|
||||
|
||||
public int init();
|
||||
public bool set_arch(Arch arch);
|
||||
public int list();
|
||||
public bool set(string name);
|
||||
public bool set_arch(Asm.Arch arch);
|
||||
public bool set_bits(int bits);
|
||||
public bool set_syntax(Syntax syntax);
|
||||
public bool set_syntax(Asm.Syntax syntax);
|
||||
public bool set_pc(uint64 addr);
|
||||
public bool set_big_endian(bool big);
|
||||
public bool set_parser(Parser parser, parse_cb cb, void *aux);
|
||||
public int disasm(uint8 *buf, uint64 length);
|
||||
public int asm(string buf);
|
||||
public bool set_parser(Asm.Parser parser, parse_cb cb, void *aux);
|
||||
public int disassemble(Aop aop, uint8 *buf, uint64 length);
|
||||
public int assemble(Aop aop, string buf);
|
||||
public int parse();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/* radare - LGPL - Copyright 2009 nibble<.ds@gmail.com> */
|
||||
|
||||
[CCode (cheader_filename="r_util.h", cprefix="r_util_", lower_case_cprefix="r_util_")]
|
||||
namespace Radare {
|
||||
[Compact]
|
||||
[CCode (cprefix="r_")]
|
||||
public static class Util {
|
||||
public static int hex_str2bin(string in, uint8 *buf);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue