* Initial vapi for r_db
- Added vala example using r_db (db.vala) * Fix segmentation fault in db.c when adding nodes with no keys defined. (-1) * Added vala example * Added r_db to the default build list * Added r_th, r_bp and r_db in pkgconfig
This commit is contained in:
parent
e4f749b1b9
commit
25dceb21a8
|
@ -368,7 +368,7 @@ for A in ${ENVWORDS} ; do
|
||||||
SEDFLAGS="${SEDFLAGS}s,@${A}@,${VAR},g;"
|
SEDFLAGS="${SEDFLAGS}s,@${A}@,${VAR},g;"
|
||||||
done
|
done
|
||||||
SEDFLAGS="${SEDFLAGS}'"
|
SEDFLAGS="${SEDFLAGS}'"
|
||||||
for A in ./config-user.mk libr/include/r_userconf.h pkgcfg/libr.pc pkgcfg/r_io.pc pkgcfg/r_asm.pc pkgcfg/r_bin.pc pkgcfg/r_cons.pc pkgcfg/r_diff.pc pkgcfg/r_core.pc pkgcfg/r_socket.pc pkgcfg/r_line.pc pkgcfg/r_syscall.pc pkgcfg/r_macro.pc pkgcfg/r_util.pc pkgcfg/r_search.pc pkgcfg/r_vm.pc ; do # SUBDIRS
|
for A in ./config-user.mk libr/include/r_userconf.h pkgcfg/libr.pc pkgcfg/r_io.pc pkgcfg/r_asm.pc pkgcfg/r_bin.pc pkgcfg/r_cons.pc pkgcfg/r_diff.pc pkgcfg/r_core.pc pkgcfg/r_socket.pc pkgcfg/r_line.pc pkgcfg/r_syscall.pc pkgcfg/r_macro.pc pkgcfg/r_util.pc pkgcfg/r_search.pc pkgcfg/r_vm.pc pkgcfg/r_th.pc pkgcfg/r_bp.pc pkgcfg/r_db.pc ; do # SUBDIRS
|
||||||
if [ -f "${VPATH}/${A}.acr" ]; then
|
if [ -f "${VPATH}/${A}.acr" ]; then
|
||||||
SD_TARGET=${A}
|
SD_TARGET=${A}
|
||||||
else
|
else
|
||||||
|
|
|
@ -50,4 +50,7 @@ SUBDIRS ./config-user.mk libr/include/r_userconf.h
|
||||||
pkgcfg/r_util.pc
|
pkgcfg/r_util.pc
|
||||||
pkgcfg/r_search.pc
|
pkgcfg/r_search.pc
|
||||||
pkgcfg/r_vm.pc
|
pkgcfg/r_vm.pc
|
||||||
|
pkgcfg/r_th.pc
|
||||||
|
pkgcfg/r_bp.pc
|
||||||
|
pkgcfg/r_db.pc
|
||||||
;
|
;
|
||||||
|
|
|
@ -5,7 +5,7 @@ PFX=${DESTDIR}${PREFIX}
|
||||||
#PREFIX=${PFX}
|
#PREFIX=${PFX}
|
||||||
|
|
||||||
# Libraries
|
# Libraries
|
||||||
LIBLIST=io util lib meta lang flags bin bininfo macro hash line cons print config syscall range socket cmd asm anal parse search diff bp debug reg core var sign trace vm th
|
LIBLIST=io util lib meta lang flags bin bininfo macro hash line cons print config syscall range socket cmd asm anal parse search diff bp debug reg core var sign trace vm th db
|
||||||
|
|
||||||
# Under development
|
# Under development
|
||||||
#LIBLIST+=print
|
#LIBLIST+=print
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
NAME=r_db
|
NAME=r_db
|
||||||
|
DEPS=r_util
|
||||||
|
|
||||||
OBJ=db.o table.o
|
OBJ=db.o table.o
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
* Return FALSE when adding two elements with the same
|
||||||
|
attributes (get before add) if the db is unique
|
||||||
|
// not necessary, we can just do this by manually checkingc
|
||||||
|
|
||||||
* Benchmarking
|
* Benchmarking
|
||||||
- Compilation support for profiling memory usage
|
- Compilation support for profiling memory usage
|
||||||
- Compare performance against sqlite
|
- Compare performance against sqlite
|
||||||
|
|
14
libr/db/db.c
14
libr/db/db.c
|
@ -50,8 +50,12 @@ R_API int r_db_add_id(struct r_db_t *db, int key, int size)
|
||||||
|
|
||||||
static int _r_db_add_internal(struct r_db_t *db, int key, void *b)
|
static int _r_db_add_internal(struct r_db_t *db, int key, void *b)
|
||||||
{
|
{
|
||||||
int i, idx, len, size = db->blocks_sz[key];
|
int i, idx, len, size;
|
||||||
struct r_db_block_t *block = db->blocks[key];
|
struct r_db_block_t *block;
|
||||||
|
if (key<0 || key>255)
|
||||||
|
return R_FALSE;
|
||||||
|
size = db->blocks_sz[key];
|
||||||
|
block = db->blocks[key];
|
||||||
if (block == NULL) {
|
if (block == NULL) {
|
||||||
block = r_db_block_new();
|
block = r_db_block_new();
|
||||||
db->blocks[key] = block;
|
db->blocks[key] = block;
|
||||||
|
@ -63,7 +67,7 @@ static int _r_db_add_internal(struct r_db_t *db, int key, void *b)
|
||||||
block = block->childs[idx];
|
block = block->childs[idx];
|
||||||
}
|
}
|
||||||
if (block) {
|
if (block) {
|
||||||
if (block->data==NULL) {
|
if (block->data == NULL) {
|
||||||
block->data = malloc(sizeof(void *)*2);
|
block->data = malloc(sizeof(void *)*2);
|
||||||
block->data[0] = b;
|
block->data[0] = b;
|
||||||
block->data[1] = NULL;
|
block->data[1] = NULL;
|
||||||
|
@ -75,12 +79,12 @@ static int _r_db_add_internal(struct r_db_t *db, int key, void *b)
|
||||||
block->data[len+1] = NULL;
|
block->data[len+1] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (block!=NULL);;
|
return (block!=NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_API int r_db_add(struct r_db_t *db, void *b)
|
R_API int r_db_add(struct r_db_t *db, void *b)
|
||||||
{
|
{
|
||||||
int i, ret=0;
|
int i, ret = R_FALSE;
|
||||||
for(i=db->id_min;i<=db->id_max;i++) {
|
for(i=db->id_min;i<=db->id_max;i++) {
|
||||||
if (db->blocks[i])
|
if (db->blocks[i])
|
||||||
ret += _r_db_add_internal(db, i, b);
|
ret += _r_db_add_internal(db, i, b);
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
prefix=@PREFIX@
|
||||||
|
exec_prefix=${prefix}
|
||||||
|
libdir=${exec_prefix}/lib
|
||||||
|
includedir=${prefix}/include
|
||||||
|
|
||||||
|
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 -lr_util
|
||||||
|
Cflags: -I${includedir}/libr
|
|
@ -75,6 +75,7 @@ namespace Radare {
|
||||||
public uint64 mdisassemble(out Aop aop, uint8 *buf, uint64 length);
|
public uint64 mdisassemble(out Aop aop, uint8 *buf, uint64 length);
|
||||||
public int massemble(out Aop aop, string buf);
|
public int massemble(out Aop aop, string buf);
|
||||||
public int parse();
|
public int parse();
|
||||||
|
// This is the destructor
|
||||||
public void free();
|
public void free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* radare - LGPL - Copyright 2009 pancake<@nopcode.org> */
|
||||||
|
|
||||||
|
[CCode (cheader_filename="r_db.h", cprefix="r_db_", lower_case_cprefix="r_db_")]
|
||||||
|
namespace Radare {
|
||||||
|
[Compact]
|
||||||
|
[CCode (cname="struct r_db_t", free_function="r_db_free", cprefix="r_db_")]
|
||||||
|
public class Database {
|
||||||
|
/* lifecycle */
|
||||||
|
public Database();
|
||||||
|
public void init();
|
||||||
|
public void free();
|
||||||
|
|
||||||
|
/* storage */
|
||||||
|
public int add_id(int off, int size);
|
||||||
|
public bool @add(void *b);
|
||||||
|
public bool delete(void *b);
|
||||||
|
public void* get(int key, uint8* buf);
|
||||||
|
|
||||||
|
/* stacky! */
|
||||||
|
public int push(ref uint8* buf);
|
||||||
|
public uint8 *pop();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,13 @@
|
||||||
all: core hash sc socket asm search bin
|
all: core hash sc socket asm search bin db
|
||||||
@true
|
@true
|
||||||
|
|
||||||
genie:
|
genie:
|
||||||
valac --vapidir=.. --pkg r_asm --pkg libr asm.gs
|
valac --vapidir=.. --pkg r_asm --pkg libr asm.gs
|
||||||
valac --vapidir=.. --pkg r_search --pkg libr search.gs
|
valac --vapidir=.. --pkg r_search --pkg libr search.gs
|
||||||
|
|
||||||
|
db:
|
||||||
|
valac --vapidir=${PWD}/.. --pkg r_db db.vala
|
||||||
|
|
||||||
sc:
|
sc:
|
||||||
valac -C --vapidir=${PWD}/.. sc.vala --pkg r_syscall
|
valac -C --vapidir=${PWD}/.. sc.vala --pkg r_syscall
|
||||||
gcc sc.c `pkg-config gobject-2.0 --libs --cflags` -I../../include/ -lr_syscall -Wl,-R../../syscall -L../../syscall -o sc
|
gcc sc.c `pkg-config gobject-2.0 --libs --cflags` -I../../include/ -lr_syscall -Wl,-R../../syscall -L../../syscall -o sc
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
using Radare;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
var db = new Radare.Database();
|
||||||
|
db.add_id(0, 4);
|
||||||
|
|
||||||
|
db.add("food");
|
||||||
|
db.add("caca");
|
||||||
|
db.add("food");
|
||||||
|
|
||||||
|
stdout.printf("%p\n", db.get(0, "caca"));
|
||||||
|
stdout.printf("%p\n", db.get(0, "miau"));
|
||||||
|
stdout.printf("%p\n", db.get(0, "food"));
|
||||||
|
db = null;
|
||||||
|
}
|
|
@ -7,5 +7,5 @@ Name: libr
|
||||||
Description: radare foundation libraries
|
Description: radare foundation libraries
|
||||||
Version: 0.2
|
Version: 0.2
|
||||||
Requires:
|
Requires:
|
||||||
Libs: -L${libdir} -lr_io -lr_util -lr_lib -lr_meta -lr_lang -lr_flags -lr_bin -lr_bininfo -lr_macro -lr_hash -lr_line -lr_cons -lr_print -lr_config -lr_syscall -lr_range -lr_socket -lr_cmd -lr_asm -lr_anal -lr_parse -lr_search -lr_diff -lr_bp -lr_debug -lr_reg -lr_core -lr_var -lr_sign -lr_trace -lr_vm
|
Libs: -L${libdir} -lr_io -lr_util -lr_lib -lr_meta -lr_lang -lr_flags -lr_bin -lr_bininfo -lr_macro -lr_hash -lr_line -lr_cons -lr_print -lr_config -lr_syscall -lr_range -lr_socket -lr_cmd -lr_asm -lr_anal -lr_parse -lr_search -lr_diff -lr_bp -lr_debug -lr_reg -lr_core -lr_var -lr_sign -lr_trace -lr_vm -lr_th -lr_db
|
||||||
Cflags: -I${includedir}/libr
|
Cflags: -I${includedir}/libr
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
prefix=@PREFIX@
|
||||||
|
exec_prefix=${prefix}
|
||||||
|
libdir=${exec_prefix}/lib
|
||||||
|
includedir=${prefix}/include
|
||||||
|
|
||||||
|
Name: r_bp
|
||||||
|
Description: radare foundation libraries
|
||||||
|
Version: 0.2
|
||||||
|
Requires:
|
||||||
|
Libs: -L${libdir} -lr_bp
|
||||||
|
Cflags: -I${includedir}/libr
|
|
@ -0,0 +1,11 @@
|
||||||
|
prefix=@PREFIX@
|
||||||
|
exec_prefix=${prefix}
|
||||||
|
libdir=${exec_prefix}/lib
|
||||||
|
includedir=${prefix}/include
|
||||||
|
|
||||||
|
Name: r_db
|
||||||
|
Description: radare foundation libraries
|
||||||
|
Version:
|
||||||
|
Requires:
|
||||||
|
Libs: -L${libdir} -lr_db -lr_util
|
||||||
|
Cflags: -I${includedir}/libr
|
|
@ -0,0 +1,11 @@
|
||||||
|
prefix=@PREFIX@
|
||||||
|
exec_prefix=${prefix}
|
||||||
|
libdir=${exec_prefix}/lib
|
||||||
|
includedir=${prefix}/include
|
||||||
|
|
||||||
|
Name: r_th
|
||||||
|
Description: radare foundation libraries
|
||||||
|
Version:
|
||||||
|
Requires:
|
||||||
|
Libs: -L${libdir} -lr_th
|
||||||
|
Cflags: -I${includedir}/libr
|
Loading…
Reference in New Issue