Fix #5158 - Merge r_db into r_util
This commit is contained in:
parent
bec3566eef
commit
f96f00d62d
|
@ -29,7 +29,6 @@ CFLAGS=-I../../libr/include/
|
|||
ifeq ($(WITHNONPIC),1)
|
||||
LDFLAGS+=../../libr/io/libr_io.a
|
||||
LDFLAGS+=../../libr/asm/libr_asm.a
|
||||
LDFLAGS+=../../libr/db/libr_db.a
|
||||
LDFLAGS+=../../libr/egg/libr_egg.a
|
||||
LDFLAGS+=../../libr/core/libr_core.a
|
||||
LDFLAGS+=../../libr/crypto/libr_crypto.a
|
||||
|
@ -66,7 +65,6 @@ LDFLAGS+=-L../../libr/bin -lr_bin
|
|||
LDFLAGS+=-L../../libr/reg -lr_reg
|
||||
LDFLAGS+=-L../../libr/asm -lr_asm
|
||||
LDFLAGS+=-L../../libr/egg -lr_egg
|
||||
LDFLAGS+=-L../../libr/db -lr_db
|
||||
LDFLAGS+=-L../../libr/core -lr_core
|
||||
LDFLAGS+=-L../../libr/anal -lr_anal
|
||||
LDFLAGS+=-L../../libr/crypto -lr_crypto
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* copyright 2015 radare2 by pancake */
|
||||
/* copyright 2015-2016 radare2 by pancake */
|
||||
|
||||
#include <r_userconf.h>
|
||||
|
||||
#ifndef R2_GITTAP
|
||||
|
@ -18,8 +19,8 @@ static int blob_version(const char *program) {
|
|||
R_SYS_OS"-"
|
||||
R_SYS_ARCH"-%d git.%s\n",
|
||||
program, R2_VERSION_COMMIT,
|
||||
R_SYS_BITS&8?64:32,
|
||||
*R2_GITTAP? R2_GITTAP: "");
|
||||
(R_SYS_BITS & 8)? 64: 32,
|
||||
*R2_GITTAP ? R2_GITTAP: "");
|
||||
if (*R2_GITTIP) {
|
||||
printf ("commit: "R2_GITTIP" build: "R2_BIRTH"\n");
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ BIN=libr2
|
|||
ISLIB=1
|
||||
BINDEPS=r_core r_parse r_search r_cons r_config
|
||||
BINDEPS+=r_bin r_debug r_anal r_reg r_bp r_io
|
||||
BINDEPS+=r_lang r_asm r_syscall r_db r_hash r_crypto
|
||||
BINDEPS+=r_lang r_asm r_syscall r_hash r_crypto
|
||||
BINDEPS+=r_magic r_socket r_flags r_util r_egg r_fs
|
||||
|
||||
include ../rules.mk
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
BIN=rabin2
|
||||
BINDEPS=r_magic r_core r_db r_bin r_egg r_cons
|
||||
BINDEPS=r_magic r_core r_bin r_egg r_cons
|
||||
BINDEPS+=r_config r_io r_flags r_asm
|
||||
BINDEPS+=r_debug r_hash r_lang r_anal r_parse r_bp r_reg
|
||||
BINDEPS+=r_search r_syscall r_socket r_fs r_magic r_crypto r_util
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
BIN=radare2
|
||||
BINDEPS=r_core r_parse r_search r_cons r_config
|
||||
BINDEPS+=r_bin r_debug r_anal r_reg r_bp r_io r_fs
|
||||
BINDEPS+=r_lang r_asm r_syscall r_db r_hash
|
||||
BINDEPS+=r_lang r_asm r_syscall r_hash
|
||||
BINDEPS+=r_magic r_socket r_flags r_egg r_crypto r_util
|
||||
|
||||
# Apple Sign #
|
||||
|
|
|
@ -33,7 +33,6 @@ static int verify_version(int show) {
|
|||
{ "r_flags", &r_flag_version }, // XXX inconsistency
|
||||
{ "r_core", &r_core_version },
|
||||
{ "r_crypto", &r_crypto_version },
|
||||
{ "r_db", &r_db_version },
|
||||
{ "r_bp", &r_bp_version },
|
||||
{ "r_debug", &r_debug_version },
|
||||
{ "r_hash", &r_hash_version },
|
||||
|
|
|
@ -3,7 +3,7 @@ BIN=radiff2
|
|||
BINDEPS=r_core r_config r_cons r_search r_anal
|
||||
BINDEPS+=r_bin r_debug r_io r_asm r_hash r_fs r_crypto
|
||||
BINDEPS+=r_socket r_flags r_lang r_reg r_bp r_parse
|
||||
BINDEPS+=r_syscall r_db r_magic r_util r_parse r_egg
|
||||
BINDEPS+=r_syscall r_magic r_util r_parse r_egg
|
||||
|
||||
include ../rules.mk
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
BIN=rafind2
|
||||
|
||||
BINDEPS=r_search r_io r_asm r_anal r_reg r_cons r_lang
|
||||
BINDEPS+=r_socket r_db r_parse r_util r_syscall r_flags
|
||||
BINDEPS+=r_socket r_parse r_util r_syscall r_flags
|
||||
|
||||
include ../rules.mk
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
BIN=ragg2
|
||||
BINDEPS=r_egg r_bin r_syscall r_asm r_db
|
||||
BINDEPS=r_egg r_bin r_syscall r_asm
|
||||
BINDEPS+=r_io r_socket
|
||||
BINDEPS+=r_lang r_parse r_anal r_reg r_flags
|
||||
BINDEPS+=r_magic r_cons r_util
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
BIN=rahash2
|
||||
|
||||
BINDEPS=r_io r_hash r_socket r_asm r_cons
|
||||
BINDEPS+=r_anal r_syscall r_reg r_db r_parse
|
||||
BINDEPS+=r_anal r_syscall r_reg r_parse
|
||||
BINDEPS+=r_flags r_lang r_crypto r_util
|
||||
|
||||
include ../rules.mk
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
BIN=rasm2
|
||||
BINDEPS=r_asm r_parse r_syscall r_anal r_reg
|
||||
BINDEPS+=r_db r_flags r_cons r_util r_lang
|
||||
BINDEPS+=r_flags r_cons r_util r_lang
|
||||
|
||||
include ../rules.mk
|
||||
|
|
|
@ -5,7 +5,6 @@ build-project hash ;
|
|||
|
||||
build-project reg ;
|
||||
build-project cons ;
|
||||
build-project db ;
|
||||
build-project magic ;
|
||||
build-project diff ;
|
||||
build-project bp ;
|
||||
|
|
|
@ -12,7 +12,7 @@ PREFIX?=${PWD}/../prefix
|
|||
PWD=$(shell pwd)
|
||||
|
||||
LIBS0=util hash
|
||||
LIBS1=socket reg cons db magic bp search config
|
||||
LIBS1=socket reg cons magic bp search config
|
||||
LIBS2=syscall lang io crypto flags
|
||||
LIBS3=fs anal bin
|
||||
LIBS4=parse
|
||||
|
|
|
@ -4,7 +4,7 @@ EXTRA_TARGETS+=do
|
|||
EXTRA_CLEAN=doclean
|
||||
|
||||
NAME=r_anal
|
||||
DEPS=r_util r_db r_reg r_syscall
|
||||
DEPS=r_util r_reg r_syscall
|
||||
CFLAGS+=-DCORELIB -Iarch -I$(TOP)/shlr
|
||||
|
||||
LDFLAGS+=${BN_LIBS}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
include ../../global.mk
|
||||
|
||||
NAME=r_asm
|
||||
DEPS=r_db r_syscall r_lang r_util r_parse
|
||||
DEPS=r_syscall r_lang r_util r_parse
|
||||
DEPS+=r_flags r_cons r_reg r_anal
|
||||
CFLAGS+=-DCORELIB -Iarch/include -Iarch -I../../shlr
|
||||
CURDIR=p/
|
||||
|
|
|
@ -2,7 +2,7 @@ include ../config.mk
|
|||
include ../../global.mk
|
||||
|
||||
NAME=r_bin
|
||||
DEPS=r_util r_db r_io r_socket r_magic
|
||||
DEPS=r_util r_io r_socket r_magic
|
||||
|
||||
.PHONY: pre
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ OBJ_CGC=bin_cgc.o
|
|||
|
||||
STATIC_OBJ+=${OBJ_CGC}
|
||||
TARGET_CGC=bin_cgc.${EXT_SO}
|
||||
LINK+=-L../../db -lr_db
|
||||
#LINK+=-L../../util -lr_util $(SHLR)/sdb/src/libsdb.a
|
||||
|
||||
ifeq ($(WITHPIC),1)
|
||||
ALL_TARGETS+=${TARGET_CGC}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
OBJ_ELF=bin_elf.o bin_dbginfo_elf.o bin_write_elf.o
|
||||
OBJ_ELF+=../format/elf/elf.o ../format/elf/elf_write.o
|
||||
#LINK+=-L../../util -lr_util $(SHLR)/sdb/src/libsdb.a
|
||||
|
||||
STATIC_OBJ+=${OBJ_ELF}
|
||||
TARGET_ELF=bin_elf.${EXT_SO}
|
||||
LINK+=-L../../db -lr_db
|
||||
|
||||
ifeq ($(WITHPIC),1)
|
||||
ALL_TARGETS+=${TARGET_ELF}
|
||||
|
|
|
@ -2,7 +2,7 @@ OBJ_MBN=bin_mbn.o
|
|||
|
||||
STATIC_OBJ+=${OBJ_MBN}
|
||||
TARGET_MBN=bin_mbn.${EXT_SO}
|
||||
LINK+=-L../../db -lr_db
|
||||
#LINK+=-L../../util -lr_util $(SHLR)/sdb/src/libsdb.a
|
||||
|
||||
ifeq ($(WITHPIC),1)
|
||||
ALL_TARGETS+=${TARGET_MBN}
|
||||
|
|
|
@ -2,7 +2,7 @@ OBJ_TE=bin_te.o ../format/te/te.o
|
|||
|
||||
STATIC_OBJ+=${OBJ_TE}
|
||||
TARGET_TE=bin_te.${EXT_SO}
|
||||
LINK+=-L../../db -lr_db $(SHLR)/sdb/src/libsdb.a
|
||||
#LINK+=-L../../util -lr_util $(SHLR)/sdb/src/libsdb.a
|
||||
|
||||
ALL_TARGETS+=${TARGET_TE}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ include ../config.mk
|
|||
|
||||
NAME=r_core
|
||||
|
||||
DEPS=r_config r_cons r_io r_util r_flags r_asm r_db
|
||||
DEPS=r_config r_cons r_io r_util r_flags r_asm
|
||||
DEPS+=r_debug r_hash r_bin r_lang r_io r_anal r_parse r_bp r_egg
|
||||
DEPS+=r_reg r_search r_syscall r_socket r_fs r_magic r_crypto
|
||||
|
||||
|
|
|
@ -796,7 +796,7 @@ static RList* construct_rop_gadget(RCore *core, ut64 addr, ut8 *buf, int idx,
|
|||
if (regex) {
|
||||
// get the first regexp.
|
||||
if (r_list_length (rx_list) > 0) {
|
||||
rx = r_list_get_n(rx_list, count++);
|
||||
rx = r_list_get_n (rx_list, count++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ include ../../../shlr/zip/deps.mk
|
|||
|
||||
CFLAGS+=-I../../include -Wall -shared ${PIC_CFLAGS} ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
|
||||
CFLAGS+=-L../../util -lr_util -L../../reg -lr_reg -L.. -lr_core
|
||||
CFLAGS+=-L../../db -lr_db -L../../cons -lr_cons -L../../bin -lr_bin
|
||||
#CFLAGS+=-L../../db -lr_db
|
||||
CFLAGS+=-L../../cons -lr_cons -L../../bin -lr_bin
|
||||
CFLAGS+=-L../../parse -lr_parse -L../../io -lr_io -L../../fs -lr_fs
|
||||
CFLAGS+=-L../../magic -lr_magic -L../../hash -lr_hash -L../../config -lr_config
|
||||
CFLAGS+=-L../../anal -lr_anal -L../../egg -lr_egg -L../../flags -lr_flags
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
OBJS = db.c table.c ;
|
||||
|
||||
lib r_db : $(OBJS) : <include>../include <library>../util <library>../../shlr/sdb ;
|
|
@ -1,44 +0,0 @@
|
|||
+------+
|
||||
| r.db | Simple and performance-friendly relational database
|
||||
+------+
|
||||
|
||||
The database of r.db is based on index tables of key-size depth.
|
||||
The key is the index of the key-bucket array which opens the search
|
||||
space to a single key.
|
||||
|
||||
Items are directly sorted
|
||||
|
||||
[255] key buckets
|
||||
|
|
||||
`-> [0..255] -----.
|
||||
| \ |
|
||||
| \ |
|
||||
[0..255] [0..255] |
|
||||
| | |-- size of key (depth)
|
||||
[0..255] ... |
|
||||
| |
|
||||
[0..255] -----'
|
||||
|
||||
OPERATIONS
|
||||
==========
|
||||
|
||||
ADD
|
||||
|
||||
DELETE
|
||||
|
||||
r_db_delete_by_key(db, K_ID, &tmp) # specify more than one key?
|
||||
|
||||
ITERATE
|
||||
|
||||
|
||||
+----------+
|
||||
| r.db.sql | The SQL frontend for r.db
|
||||
+----------+
|
||||
|
||||
- Compiles simple SQL-like sentences into a set of r.db queries
|
||||
|
||||
void **iter = r_db_sql_query("select * from flags");
|
||||
while(r_db_ptr(iter)) {
|
||||
struct foo_t *foo = r_db_ptr(iter);
|
||||
iter = r_db_ptr_next(iter);
|
||||
}
|
31
libr/db/TODO
31
libr/db/TODO
|
@ -1,31 +0,0 @@
|
|||
* Use r_mem_pool
|
||||
* Add support for one level RDB.. to 8x speed up
|
||||
* Serialize/Deserialize from disk
|
||||
* 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
|
||||
- Compilation support for profiling memory usage
|
||||
- Compare performance against sqlite
|
||||
* Import/export from/to SQL
|
||||
* SQL support
|
||||
|
||||
CREATE TABLE flags (
|
||||
name char(25) PRIMARY KEY,
|
||||
offset ut64,
|
||||
);
|
||||
|
||||
SELECT * FROM flags WHERE offset == 0x8048000;
|
||||
|
||||
CREATE VIEW flagwindow AS SELECT * FROM flags WHERE offset>0 and offset<100
|
||||
|
||||
DROP TABLE flags
|
||||
INSERT INTO flags (name, offset) VALUES ("patata", 33)
|
||||
|
||||
UPDATE flags SET offset=33 WHERE offset==20
|
||||
|
||||
STORE
|
||||
- ut32
|
||||
- ut64
|
||||
- Endianness matterz
|
||||
- RList *get_range (0, 4096)
|
275
libr/db/db.c
275
libr/db/db.c
|
@ -1,275 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2009-2013 - pancake */
|
||||
|
||||
#include "r_db.h"
|
||||
|
||||
R_LIB_VERSION (r_db);
|
||||
#if 0
|
||||
Configurable options:
|
||||
- allow dupped nodes? (two times the same pointer?)
|
||||
#endif
|
||||
|
||||
R_API RDatabase *r_db_new() {
|
||||
RDatabase *db = R_NEW (RDatabase);
|
||||
if (db) {
|
||||
memset (&db->blocks, '\0', sizeof (db->blocks));
|
||||
db->id_min = -1;
|
||||
db->id_max = -1;
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
R_API RDatabaseBlock *r_db_block_new() {
|
||||
RDatabaseBlock *ptr = R_NEW0 (RDatabaseBlock);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
R_API int r_db_add_id(struct r_db_t *db, int key, int size) {
|
||||
key &= 0xff;
|
||||
if (db->blocks[key])
|
||||
return false;
|
||||
if (db->id_min==-1) {
|
||||
db->id_min = key;
|
||||
db->id_max = key;
|
||||
} else if (db->id_max < key)
|
||||
db->id_max = key;
|
||||
if (key < db->id_min)
|
||||
db->id_min = key;
|
||||
db->blocks[key] = r_db_block_new ();
|
||||
db->blocks_sz[key] = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int _r_db_add_internal(struct r_db_t *db, int key, void *b) {
|
||||
int i, idx, len, size;
|
||||
struct r_db_block_t *block;
|
||||
if (key<0 || key>255)
|
||||
return false;
|
||||
size = db->blocks_sz[key];
|
||||
block = db->blocks[key];
|
||||
if (block == NULL) {
|
||||
block = r_db_block_new ();
|
||||
if (!block) return false;
|
||||
db->blocks[key] = block;
|
||||
}
|
||||
for (i=0;i<size;i++) {
|
||||
idx = (((ut8 *)b)[key+i]) & 0xff;
|
||||
if (block->childs[idx] == NULL)
|
||||
block->childs[idx] = r_db_block_new();
|
||||
block = block->childs[idx];
|
||||
}
|
||||
if (block) {
|
||||
if (block->data == NULL) {
|
||||
// TODO: use slices.. much faster alloc+free
|
||||
block->data = malloc(sizeof(void *)*2);
|
||||
block->data[0] = b;
|
||||
block->data[1] = NULL;
|
||||
} else {
|
||||
for (len=0; block->data[len]; len++);
|
||||
block->data = realloc (block->data, sizeof (void *)*(len+2));
|
||||
block->data[len] = b;
|
||||
block->data[len+1] = NULL;
|
||||
}
|
||||
}
|
||||
return (block != NULL);
|
||||
}
|
||||
|
||||
R_API int r_db_add(struct r_db_t *db, void *b) {
|
||||
int i, ret = false;
|
||||
for (i=db->id_min;i<=db->id_max;i++)
|
||||
if (db->blocks[i])
|
||||
ret += _r_db_add_internal (db, i, b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_db_add_unique(struct r_db_t *db, void *b) {
|
||||
int i, ret = true;
|
||||
for(i=db->id_min;i<=db->id_max;i++) {
|
||||
if (db->blocks[i] && r_db_get (db, i, b) != NULL) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret) ret = r_db_add (db, b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API void **r_db_get(struct r_db_t *db, int key, const ut8 *b) {
|
||||
RDatabaseBlock *block;
|
||||
int i, size;
|
||||
if (key == -1) {
|
||||
key = db->id_min;
|
||||
#if 0
|
||||
UNNECESSARY LOOPZ
|
||||
for (i=0;i<R_DB_KEYS;i++) {
|
||||
if (db->blocks[i]) {
|
||||
key = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (key == -1)
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
size = db->blocks_sz[key];
|
||||
block = db->blocks[key];
|
||||
for (i=0; block && i<size; i++)
|
||||
block = block->childs[b[key+i]];
|
||||
if (block)
|
||||
return block->data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO: MOVE AS DEFINE IN r_db.h */
|
||||
R_API void **r_db_get_next(void **ptr) {
|
||||
return ptr+1;
|
||||
}
|
||||
|
||||
/* TODO: MOVE AS DEFINE IN r_db.h */
|
||||
R_API void *r_db_get_cur(void **ptr) {
|
||||
return ptr[0];
|
||||
}
|
||||
|
||||
static int _r_db_delete_internal(struct r_db_t *db, int key, const ut8 *b) {
|
||||
RDatabaseBlock *block;
|
||||
int i, j, size = db->blocks_sz[key];
|
||||
block = db->blocks[key];
|
||||
|
||||
for (i=0;block&&i<size;i++)
|
||||
block = block->childs[b[key+i]];
|
||||
|
||||
if (block && block->data) {
|
||||
for (i=0;block->data[i]; i++) {
|
||||
if (block->data[i] == b)
|
||||
for (j=i;block->data[j]; j++)
|
||||
block->data[j] = block->data[j+1];
|
||||
}
|
||||
if (block->data[0] == NULL) {
|
||||
free (block->data);
|
||||
block->data = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_db_delete(struct r_db_t *db, const void *ptr) {
|
||||
int i;
|
||||
for (i=db->id_min; i<=db->id_max; i++)
|
||||
if (db->blocks[i])
|
||||
if (!_r_db_delete_internal (db, i, ptr))
|
||||
eprintf ("failed to delete internal pointer\n");
|
||||
/* TODO */
|
||||
if (db->cb_free && ptr)
|
||||
return db->cb_free (db, ptr, db->cb_user);
|
||||
return (ptr != NULL);
|
||||
}
|
||||
|
||||
static int r_db_iter_find_next(RDatabaseIter *it) {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API RDatabaseIter *r_db_iter_new(RDatabase *db, int key) {
|
||||
RDatabaseIter *iter = R_NEW0 (RDatabaseIter);
|
||||
if (!iter) return NULL;
|
||||
/* TODO: detect when keys are not valid and return NULL */
|
||||
iter->db = db;
|
||||
iter->key = key;
|
||||
iter->size = db->blocks_sz[key];
|
||||
memset (&iter->path, 0, sizeof (iter->path));
|
||||
/* TODO: detect when no keys are found and return NULL */
|
||||
iter->ptr = 0;
|
||||
iter->cur = NULL;
|
||||
r_db_iter_find_next (iter);
|
||||
/* TODO: first iteration must be done here */
|
||||
return iter;
|
||||
}
|
||||
|
||||
R_API void *r_db_iter_cur(struct r_db_iter_t *iter) {
|
||||
return iter->cur;
|
||||
#if 0
|
||||
void *cur = NULL;
|
||||
int i, depth = 0;
|
||||
struct r_db_t *db = iter->db;
|
||||
struct r_db_block_t *b = db->blocks[iter->key];
|
||||
if (iter->ptr == 0) {
|
||||
/* first iteration */
|
||||
} else {
|
||||
for(i=0;i<iter->size;i++) {
|
||||
b = &b[iter->path[i]];
|
||||
if (b == NULL) {
|
||||
fprintf(stderr, "r_db: Internal data corruption\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
/* TODO: check if null to find next node */
|
||||
return b->data[iter->ptr];
|
||||
}
|
||||
|
||||
for(i=0;i<255;i++) {
|
||||
if (b->childs[i]) {
|
||||
/* walk childs until reaching the leafs */
|
||||
b = b->childs[i];
|
||||
i=0;
|
||||
depth++;
|
||||
if (depth == iter->size) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//iter->db
|
||||
return cur;
|
||||
#endif
|
||||
}
|
||||
|
||||
// NOTE: required for vala/swig
|
||||
R_API void *r_db_iterator(RDatabase *db) {
|
||||
return r_db_iter_new (db, db->id_min);
|
||||
}
|
||||
|
||||
/* returns 1 if there is a next element */
|
||||
R_API int r_db_iter_next(RDatabaseIter *iter) {
|
||||
//RDatabaseBlock *b, *block;
|
||||
int i;//, j;
|
||||
// TODO: must be implemented for Vala/Swig
|
||||
// if (something) return 1;
|
||||
// depth = iter->size
|
||||
//
|
||||
for (i=iter->ptr; i<iter->size; i++) {
|
||||
//block = block->childs[b[key+i]];
|
||||
}
|
||||
iter->ptr = i; // update pointer
|
||||
iter->cur = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return current iter data and go to next iterable element */
|
||||
R_API void *r_db_iter_get(RDatabaseIter *iter) {
|
||||
void *data = iter->cur;
|
||||
|
||||
// TODO: must be implemented for Vala/Swig
|
||||
return data;
|
||||
}
|
||||
|
||||
R_API void *r_db_iter_prev(struct r_db_iter_t *iter) {
|
||||
/* TODO */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API struct r_db_iter_t *r_db_iter_free(struct r_db_iter_t *iter) {
|
||||
free (iter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API int r_db_free(struct r_db_t *db) {
|
||||
/* TODO : using the iterator logic */
|
||||
// TODO: use r_pool_mem here!
|
||||
#if 0
|
||||
r_db_iter_t *iter = r_db_iter(db, -1);
|
||||
if (db->cb_free) {
|
||||
r_db_delete(db); // XXX
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
ifeq ($(WITHNONPIC),1)
|
||||
LDFLAGS+=$(LIBR)/db/sdb/src/libsdb.a
|
||||
else
|
||||
LDFLAGS+=-L$(LIBR)/db -lr_db
|
||||
endif
|
|
@ -1,6 +0,0 @@
|
|||
BINDEPS=r_db r_util
|
||||
BIN=test
|
||||
OBJ=test.o
|
||||
|
||||
include ../../rules.mk
|
||||
include ../r.mk
|
109
libr/db/t/test.c
109
libr/db/t/test.c
|
@ -1,109 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
||||
|
||||
|
||||
#include "r_db.h"
|
||||
void test_pair ();
|
||||
void test_db();
|
||||
|
||||
struct item_t {
|
||||
char city[10];
|
||||
int people;
|
||||
int id;
|
||||
};
|
||||
|
||||
#define K_ID R_DB_INDEXOF(struct item_t, id)
|
||||
#define K_CITY R_DB_INDEXOF(struct item_t, city)
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_pair ();
|
||||
test_db ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_pair () {
|
||||
char *s;
|
||||
RPair *p = r_pair_new ();
|
||||
r_pair_set_sync_dir (p, "sdb-db-test");
|
||||
|
||||
r_pair_set (p, "root", "clown");
|
||||
r_pair_set (p, ".branch", "clown");
|
||||
r_pair_set (p, "user.name", "pancake");
|
||||
r_pair_set (p, "user.pass", "password");
|
||||
|
||||
s = r_pair_get (p, "user.name");
|
||||
printf ("user.name=%s\n", s);
|
||||
|
||||
{
|
||||
RPairItem *o;
|
||||
RListIter *iter;
|
||||
RList *list = r_pair_list (p, "user");
|
||||
printf ("DUMP:\n");
|
||||
r_list_foreach (list, iter, o) {
|
||||
printf (" %s = %s\n", o->k, o->v);
|
||||
}
|
||||
r_list_purge (list);
|
||||
}
|
||||
r_pair_sync (p);
|
||||
}
|
||||
|
||||
void test_db() {
|
||||
RDatabase *db = r_db_new ();
|
||||
void **siter;
|
||||
struct item_t *it, tmp;
|
||||
|
||||
r_db_add_id (db, K_CITY, 10);
|
||||
r_db_add_id (db, (int)(K_ID), sizeof (int));
|
||||
|
||||
it = (struct item_t *)malloc(sizeof(struct item_t));
|
||||
strcpy(it->city, "bcn");
|
||||
it->people = 1024;
|
||||
it->id = 33;
|
||||
r_db_add (db, it);
|
||||
r_db_add (db, it);
|
||||
//printf("(ORIG) %p\n", it);
|
||||
|
||||
tmp.id = 33;
|
||||
siter = r_db_get (db, K_ID, (void *)&tmp);
|
||||
for(; siter && *siter; siter=r_db_get_next (siter)) {
|
||||
struct item_t *foo = (struct item_t *)r_db_get_cur (siter);
|
||||
// printf("(GET) %p\n", foo);
|
||||
printf ("city: %s, people: %d, id: %d\n",
|
||||
foo->city, foo->people, foo->id);
|
||||
}
|
||||
|
||||
/* delete */
|
||||
r_db_delete(db, it);
|
||||
printf("--> delete 1 item\n");
|
||||
|
||||
/* list */
|
||||
tmp.id = 33;
|
||||
siter = r_db_get(db, K_ID, (void *)&tmp);
|
||||
for(; siter && siter[0]; siter=r_db_get_next(siter)) {
|
||||
struct item_t *foo = (struct item_t *)r_db_get_cur(siter);
|
||||
// printf("(GET) %p\n", foo);
|
||||
printf("city: %s, people: %d, id: %d\n",
|
||||
foo->city, foo->people, foo->id);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|---| key
|
||||
|--.--.--.--.--|
|
||||
|--.--.--.--.--|
|
||||
#endif
|
||||
printf("--> iterate over full list\n");
|
||||
{
|
||||
struct r_db_iter_t *iter;
|
||||
|
||||
iter = r_db_iter_new(db, K_ID); // iter = db.iterator(K_ID);
|
||||
//while (r_db_iter_cur(iter)) { // while(iter.exists()) {
|
||||
while (iter->cur) { // while(iter.exists()) {
|
||||
struct item_t *foo = (struct item_t *)iter->cur; //r_db_iter_cur(siter);
|
||||
printf("city: %s, people: %d, id: %d\n",
|
||||
foo->city, foo->people, foo->id);
|
||||
r_db_iter_next(iter);
|
||||
}
|
||||
}
|
||||
|
||||
printf("--> free db\n");
|
||||
r_db_free(db);
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2009-2016 - pancake */
|
||||
|
||||
#include "r_db.h"
|
||||
#include "r_util.h"
|
||||
|
||||
struct r_db_table_t *r_db_table_new(const char *name, const char *fmt, const char *fields) {
|
||||
int i;
|
||||
int offset = 0;
|
||||
struct r_db_table_t *table = R_NEW0 (RDatabaseTable);
|
||||
if (!table) return NULL;
|
||||
table->args = strdup (fields);
|
||||
if (!table->args) goto beach;
|
||||
|
||||
table->nelems = r_str_word_set0 (table->args);
|
||||
if (table->nelems != strlen (fmt)) {
|
||||
eprintf ("r_db_table_new: Invalid arguments\n");
|
||||
goto beach;
|
||||
} else {
|
||||
table->fmt = strdup (fmt);
|
||||
if (!table->fmt) goto beach;
|
||||
table->name = strdup (name);
|
||||
if (!table->name) goto beach;
|
||||
table->offset = (int*)calloc (1, sizeof (int)*table->nelems);
|
||||
if (!table->offset) goto beach;
|
||||
for (i=0; i<table->nelems; i++) {
|
||||
table->offset[i] = offset;
|
||||
offset += 4;
|
||||
}
|
||||
}
|
||||
return table;
|
||||
|
||||
beach:
|
||||
r_db_table_free (table);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get offset of given named field inside the table */
|
||||
int r_db_table_key(struct r_db_table_t *table, const char *name) {
|
||||
const char *word;
|
||||
int i;
|
||||
for (i = 0; i < table->nelems; i++) {
|
||||
word = r_str_word_get0 (table->args, i);
|
||||
if (!strcmp (name, word))
|
||||
break;
|
||||
}
|
||||
return table->offset[i];
|
||||
}
|
||||
|
||||
/* Get offset of the N field in the table */
|
||||
int r_db_table_key_i(struct r_db_table_t *table, int elem) {
|
||||
return (elem>=0 && table->nelems<elem)
|
||||
? table->offset[elem]
|
||||
: -1;
|
||||
}
|
||||
|
||||
/* Get name of the N field in the table */
|
||||
const char *r_db_table_field_i(struct r_db_table_t *table, int elem) {
|
||||
return (elem >= 0 && table->nelems < elem)
|
||||
? r_str_word_get0 (table->args, elem)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
void *r_db_table_free(struct r_db_table_t *table) {
|
||||
free (table->name);
|
||||
free (table->fmt);
|
||||
free (table->args);
|
||||
free (table->offset);
|
||||
free (table);
|
||||
return NULL;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
include ../config.mk
|
||||
|
||||
NAME=r_debug
|
||||
DEPS=r_reg r_db r_anal r_bp r_io r_parse r_cons r_syscall r_hash r_flags r_util
|
||||
DEPS=r_reg r_anal r_bp r_io r_parse r_cons r_syscall r_hash r_flags r_util
|
||||
DEPS+=r_socket
|
||||
CFLAGS+=-DCORELIB
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ ${TARGET_PTRACE}: ${OBJ_PTRACE}
|
|||
${LDFLAGS_LINKPATH}.. -L.. -lr_debug \
|
||||
${LDFLAGS_LINKPATH}../../io -L../../io -lr_io \
|
||||
${LDFLAGS_LINKPATH}../../bp -L../../bp -lr_bp \
|
||||
${LDFLAGS_LINKPATH}../../db -L../../db -lr_db \
|
||||
${LDFLAGS_LINKPATH}../../anal -L../../anal -lr_anal \
|
||||
${LDFLAGS_LINKPATH}../../reg -L../../reg -lr_reg \
|
||||
${LDFLAGS_LINKPATH}../../util -L../../util -lr_util \
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
include ../config.mk
|
||||
|
||||
NAME=r_egg
|
||||
DEPS=r_asm r_syscall r_db r_util r_parse r_reg r_anal
|
||||
DEPS=r_asm r_syscall r_util r_parse r_reg r_anal
|
||||
DEPS+=r_flags r_cons
|
||||
LINK+=$(SHLR)/java/libr_java.a
|
||||
|
||||
|
|
|
@ -3,6 +3,5 @@ include ../config.mk
|
|||
NAME=r_flags
|
||||
DEPS=r_util r_cons
|
||||
OBJS=flags.o sort.o spaces.o
|
||||
#DEPS+=r_db
|
||||
|
||||
include ../rules.mk
|
||||
|
|
|
@ -3,7 +3,7 @@ include ../config.mk
|
|||
NAME=r_parse
|
||||
DEPS=r_flags r_util r_anal r_syscall r_reg
|
||||
# indirect dependencies
|
||||
DEPS+=r_db r_cons
|
||||
DEPS+=r_cons
|
||||
|
||||
LINK+=$(STOP)/tcc/libr_tcc.a
|
||||
CFLAGS+=-I$(STOP)/tcc/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
include ../config.mk
|
||||
|
||||
NAME=r_syscall
|
||||
DEPS=r_util r_db
|
||||
DEPS=r_util
|
||||
|
||||
OBJS=syscall.o ioports.o
|
||||
CFLAGS+=-D__UNIX__ -Wall
|
||||
|
|
|
@ -40,7 +40,11 @@ ifneq ($(shell expr "`uname -r`" : '[0-6]\.'), 2)
|
|||
endif
|
||||
endif
|
||||
|
||||
pre: ${SDBLIB}
|
||||
${MAKE} all
|
||||
|
||||
include ../rules.mk
|
||||
include sdb.mk
|
||||
|
||||
sync-regex regex-sync:
|
||||
-rm -rf src/
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
include ../config.mk
|
||||
|
||||
NAME=r_db
|
||||
DEPS=r_util
|
||||
|
||||
OBJS=db.o table.o
|
||||
|
||||
SDBPATH=../../shlr/sdb/src/
|
||||
SDBLIB=${SDBPATH}/libsdb.a
|
||||
EXTRA_TARGETS+=${SDBLIB}
|
||||
|
||||
${SDBLIB}:
|
||||
${MAKE} -C ${SDBPATH}
|
||||
SDB_OBJS=
|
||||
SDB_OBJS+=buffer.o
|
||||
SDB_OBJS+=cdb.o
|
||||
|
@ -32,14 +27,8 @@ SDB_OBJS+=journal.o
|
|||
SDBOBJS=$(addprefix ${SDBPATH},${SDB_OBJS})
|
||||
|
||||
OBJS+=${SDBOBJS}
|
||||
#LINK+=${SDBPATH}/*.o
|
||||
|
||||
CFLAGS+=-I${SDBPATH}/src
|
||||
|
||||
pre: ${SDBLIB}
|
||||
${MAKE} all
|
||||
|
||||
include ../rules.mk
|
||||
|
||||
${SDBLIB}:
|
||||
${MAKE} -C ${SDBPATH}
|
||||
|
Loading…
Reference in New Issue