* Remove deprecated r_meta.pc

* Use RMemoryPool and RList in RSearch
  - Store hits in RList if no callback defined
* Fix constructor of r_mem_pool if alloc fails in init
* Remove unused file from search/ binparse.c
This commit is contained in:
pancake 2010-03-15 10:46:41 +01:00
parent 8fcf6de02f
commit 76a22ef18e
14 changed files with 99 additions and 490 deletions

2
configure vendored
View File

@ -443,7 +443,7 @@ for A in ${ENVWORDS} ; do
SEDFLAGS="${SEDFLAGS}s,@${A}@,${VAR},g;"
done
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_anal.pc pkgcfg/r_hash.pc pkgcfg/r_cons.pc pkgcfg/r_diff.pc pkgcfg/r_core.pc pkgcfg/r_lang.pc pkgcfg/r_socket.pc pkgcfg/r_debug.pc pkgcfg/r_reg.pc pkgcfg/r_cmd.pc pkgcfg/r_config.pc pkgcfg/r_flags.pc pkgcfg/r_meta.pc pkgcfg/r_line.pc pkgcfg/r_syscall.pc pkgcfg/r_macro.pc pkgcfg/r_sign.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 pkgcfg/r_lib.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_anal.pc pkgcfg/r_hash.pc pkgcfg/r_cons.pc pkgcfg/r_diff.pc pkgcfg/r_core.pc pkgcfg/r_lang.pc pkgcfg/r_socket.pc pkgcfg/r_debug.pc pkgcfg/r_reg.pc pkgcfg/r_cmd.pc pkgcfg/r_config.pc pkgcfg/r_flags.pc pkgcfg/r_line.pc pkgcfg/r_syscall.pc pkgcfg/r_macro.pc pkgcfg/r_sign.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 pkgcfg/r_lib.pc ; do # SUBDIRS
if [ -f "${VPATH}/${A}.acr" ]; then
SD_TARGET=${A}
else

View File

@ -81,7 +81,6 @@ SUBDIRS ./config-user.mk libr/include/r_userconf.h
pkgcfg/r_cmd.pc
pkgcfg/r_config.pc
pkgcfg/r_flags.pc
pkgcfg/r_meta.pc
pkgcfg/r_line.pc
pkgcfg/r_syscall.pc
pkgcfg/r_macro.pc

View File

@ -355,6 +355,7 @@ int Elf_(r_bin_elf_get_bits)(struct Elf_(r_bin_elf_obj_t) *bin)
}
}
// TODO: must return const char * all those strings must be const char os[LINUX] or so
char* Elf_(r_bin_elf_get_osabi_name)(struct Elf_(r_bin_elf_obj_t) *bin)
{
switch (bin->ehdr.e_ident[EI_OSABI]) {

View File

@ -1,6 +1,7 @@
OBJ=hello.o
BINDEPS=r_line r_cons r_util
BIN=hello
LDFLAGS=-L..
#LIBS=../*.o ../../line/*.a ../../util/*.a
include ../../rules.mk

View File

@ -14,8 +14,6 @@ enum {
R_SEARCH_AES
};
/* search api */
typedef struct r_search_kw_t {
char keyword[128];
char binmask[128];
@ -30,10 +28,8 @@ typedef struct r_search_kw_t {
} RSearchKeyword;
typedef struct r_search_hit_t {
RSearchKeyword *kw;
ut64 addr;
struct r_search_kw_t *kw;
int len;
struct list_head list;
} RSearchHit;
typedef int (*RSearchCallback)(struct r_search_kw_t *kw, void *user, ut64 where);
@ -45,11 +41,12 @@ typedef struct r_search_t {
ut32 string_min; /* min number of matches */
ut32 string_max; /* max number of matches */
void *user; /* user data */
//int (*callback)(struct r_search_kw_t *kw, void *user, ut64 where);
RSearchCallback callback;
RList *hits;
RMemoryPool *pool;
//struct r_search_binparse_t *bp;
//TODO RList *kws; // TODO: Use r_search_kw_new ()
struct list_head kws; //r_search_hw_t kws;
struct list_head hits; //r_search_hit_t hits;
} RSearch;
#ifdef R_API
@ -71,8 +68,8 @@ R_API int r_search_kw_add_hex(RSearch *s, const char *kw, const char *bm);
R_API int r_search_kw_add_bin(RSearch *s, const ut8 *kw, int kw_len, const ut8 *bm, int bm_len);
// TODO: Must be RList
R_API struct r_search_kw_t *r_search_kw_list(RSearch *s);
R_API int r_search_reset(RSearch *s);
R_API int r_search_kw_reset(RSearch *s);
R_API void r_search_reset(RSearch *s);
R_API void r_search_kw_reset(RSearch *s);
R_API int r_search_range_add(RSearch *s, ut64 from, ut64 to);
R_API int r_search_range_set(RSearch *s, ut64 from, ut64 to);
@ -85,6 +82,7 @@ R_API int r_search_aes_update(RSearch *s, ut64 from, const ut8 *buf, int len);
R_API int r_search_strings_update(RSearch *s, ut64 from, const char *buf, int len, int enc);
R_API int r_search_regexp_update(RSearch *s, ut64 from, const ut8 *buf, int len);
R_API int r_search_xrefs_update(RSearch *s, ut64 from, const ut8 *buf, int len);
R_API int r_search_hit_new(RSearch *s, RSearchKeyword *kw, ut64 addr);
/* pattern search */
R_API int r_search_pattern(RSearch *s, ut32 size);

View File

@ -14,7 +14,6 @@ typedef struct { } RSystem;
typedef struct { } RStr;
typedef struct { } RLog;
/* pool */
typedef struct r_mem_pool_t {
void **nodes;
int ncount;
@ -25,7 +24,6 @@ typedef struct r_mem_pool_t {
int poolcount;
} RMemoryPool;
/* buf */
typedef struct r_buf_t {
ut8 *buf;
int length;
@ -161,7 +159,6 @@ R_API int r_cache_invalidate(struct r_cache_t *c, ut64 from, ut64 to);
R_API void r_prof_start(struct r_prof_t *p);
R_API double r_prof_end(struct r_prof_t *p);
/* memory */
R_API void r_mem_copybits(ut8 *dst, const ut8 *src, int bits);
R_API void r_mem_copyloop (ut8 *dest, const ut8 *orig, int dsize, int osize);
R_API void r_mem_copyendian (ut8 *dest, const ut8 *orig, int size, int endian);
@ -229,14 +226,12 @@ R_API char *r_str_concatf(char *ptr, const char *fmt, ...);
R_API void r_str_concatch(char *x, char y);
R_API void r_str_case(char *str, int up);
/* hex */
R_API int r_hex_pair2bin(const char *arg);
R_API int r_hex_str2bin(const char *in, ut8 *out);
R_API int r_hex_bin2str(const ut8 *in, int len, char *out);
R_API char *r_hex_bin2strdup(const ut8 *in, int len);
R_API int r_hex_to_byte(ut8 *val, ut8 c);
/* file */
R_API char *r_file_path(const char *bin);
R_API const char *r_file_basename (const char *path);
R_API const char *r_file_abspath(const char *file);
@ -274,7 +269,6 @@ R_API int r_range_init(struct r_range_t *r);
R_API RRange *r_range_new();
R_API RRange *r_range_new_from_string(const char *string);
R_API RRange *r_range_free(RRange *r);
R_API
R_API struct r_range_item_t *r_range_item_get(RRange *r, ut64 addr);
R_API ut64 r_range_size(RRange *r);
R_API int r_range_add_from_string(RRange *rgs, const char *string);

View File

@ -1,369 +0,0 @@
/* radare - LGPL - Copyright 2007-2009 esteve<eslack.org> */
/* contribs: pancake <nopcode.org> */
#include "r_search.h"
#if 0
#include "main.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "binparse.h"
#include "utils.h"
#endif
#if 0
token file example:
------------------------------
token: Library token
string: lib
mask: ff 00 ff
token: Fruit for the loom
string: rt
mask: ff ff
------------------------------
#endif
R_API void r_search_binparse_apply_mask (char * maskout, int masklen , token* tlist , int ntok)
{
int i;
for(i=0; i < ntok ; i ++ )
tlist[i].mask = maskout[masklen?i%masklen:0];
}
static ut8 get_byte(char *str, int len)
{
int value;
char* strp = alloca(sizeof(char)*len);
memcpy(strp, str, len);
if (strp[0] == '\\') {
strp[0] = '0';
sscanf (strp,"%x",&value );
} else sscanf (strp,"%c",(char *)&value );
return (ut8)(value & 0xFF);
}
#if 0
static unsigned char get_num(const char * str, int len)
{
ut8 * strp;
int value;
strp = alloca(len+1);
memset(strp, 0, len);
memcpy(strp, str, len );
if (strp[0] == '\\') {
strp[0] = '0';
sscanf (strp,"%x",&value );
} else value = strp[0]; //sscanf (strp,"%c",(char *)&value );
value = value & 0xFF ;
return (unsigned char)value ;
}
#endif
static int get_range(char *str, int len, unsigned char *cbase)
{
int g;
ut8 min, max;
for ( g= 0; (g < len ) && ( str[g] != '-' ) ; g++ );
min = get_byte ( str, g );
max = get_byte ( str+g+1, len-g-1 );
*cbase = min;
return (max-min);
}
static int tok_parse (char* str, int len, token * tlist )
{
int i;
int stat;
unsigned char tokaux;
int tokact=0;
char straux[5];
int rangemin = 0; // XXX BUGGY ???
int rangemax;
unsigned char cmin;
stat = 0;
for (i=0 ; i < len ; i ++ ) {
switch (str[i]) {
case '\\':
if (stat!=1&&( (stat < 10) || ( stat > 22 ) )) stat = 1;
else stat++;
break;
case '[':
if ( (stat!=1) && (stat!=10)) {
stat = 10;
rangemin = i+1 ;
}
else stat++;
break;
default:
if (stat != 0 ) stat ++;
break;
}
if ( stat == 0 ) {
tlist[tokact].mintok = str[i];
tlist[tokact].range = 0;
tokact++;
} else
if (stat == 2 ) { // parse \xAA
if (str[i]=='x' ) {
//stat = 3;
} else {
//Caracter escapat
tlist[tokact].mintok = str[i];
tlist[tokact].range = 0;
tokact++;
stat = 0;
}
} else
if (stat == 3 ) {
//primer despres de \x <--
straux[0]='0';
straux[1]='x';
straux[2]=str[i];
} else
if (stat == 4 ) {
//Ja tinc tot el byte
straux[3]=str[i];
straux[4]=0;
sscanf ( straux ,"%hhx",&tokaux);
//tokaux = 0xFF&((straux[0]-'0')*16 + (straux[1]-'0'));
tlist[tokact].mintok = tokaux;
tlist[tokact].range = 0;
tokact++;
stat = 0;
} else
if ( (stat >= 11) && (stat <= 22 ) ) {
if ( str[i] == ']' ) {
int irange;
rangemax = i-1;
irange = get_range( str+rangemin, rangemax-rangemin+1 , &cmin);
tlist[tokact].mintok = cmin;
tlist[tokact].range = irange;
tokact++;
stat = 0;
}
}
}
return tokact;
}
static int r_search_binparse_get_mask_list(char* mask, char* maskout)
{
int i,j,k;
char num[3];
num[2] = 0;
j = k = 0;
for(i=0; mask[i] ; i++) {
if (mask[i] != ' ') {
num[j] = mask[i];
j++;
}
if (j == 2) {
sscanf(num, "%hhx", (unsigned char*)&maskout[k]);
k++;
j = 0;
}
}
return k;
}
static tokenlist *r_search_binparse_token_mask(char *name, char *token, char *mask)
{
tokenlist *tls;
void *tlist = 0;
int ntok = 0;
int len;
int masklen;
char maskout[300];
tls = malloc( sizeof(tokenlist) );
// TODO mask not yet done
len = strlen(token);
tlist = malloc( (sizeof (token) * len) + 1 );
ntok = tok_parse(token, len, tlist);
tls->tl = tlist;
tls->numtok = ntok;
/* tls->lastpos = 0; */
tls->stat = 0;
strcpy ( tls->name , name ); // XXX bof here!
if ( mask == NULL )
mask = "ff";
masklen = r_search_binparse_get_mask_list(mask , maskout);
r_search_binparse_apply_mask(maskout, masklen, tlist, ntok);
//print_tok_list ( tls ) ;
return tls;
}
#if 0
// line , IN rep linia tokens, surt llista token
static tokenlist* get_tok_list(char* line, int maxlen)
{
int i ,p;
token * tlist;
tokenlist *tls;
int ntok;
tls = malloc ( sizeof ( tokenlist ) ) ;
for ( i = 0 ; i < maxlen ; i ++ ) if ( line[i] == '$' ) break;
for ( p = i+1 ; p < maxlen ; p ++ )
if ( line[p] == '$' && line[p-1] != '\\' ) break;
//Prova, cada caracter un token
if ( i == (p-1) ) {
tlist = malloc ( sizeof (token) ) ;
tlist[0].mintok = 0;
tlist[0].range = 0xFF;
ntok = 1;
} else {
ntok = p - i;
tlist = malloc( sizeof (token) * ( ntok ) );
ntok = tok_parse( line+1, ntok-1, tlist );
}
tls->tl = tlist;
tls->numtok = ntok;
/* tls->lastpos = 0; */
tls->stat = 0;
strncpy(tls->name, line+p+1, 256);
tls->name[strlen(tls->name)-1] = '\0';
return tls;
}
static const char *str_get_arg(const char *buf)
{
const char *str;
str = strchr(buf, ':');
if (str != NULL)
str = strchr(str+1, '\t');
if (str == NULL)
return NULL;
str = strdup(str+1);
return str;
}
#endif
/* public api */
//tokenizer* binparse_new(int kws)
R_API struct r_search_binparse_t *binparse_new(int kws)
{
struct r_search_binparse_t *tll = R_NEW(struct r_search_binparse_t);
if (tll == NULL)
return NULL;
tll->tls = (tokenlist**)malloc(sizeof (tokenlist*) * kws);
if (tll->tls == NULL) {
free(tll);
return NULL;
}
tll->nlists = 0;
tll->interrupted = 0;
return tll;
}
//int binparser_free(tokenizer* ptokenizer)
R_API int r_search_binparse_free(struct r_search_binparse_t *ptokenizer)
{
int i;
if (ptokenizer == NULL)
return 0;
for (i=0; i<ptokenizer->nlists; i++) {
free(ptokenizer->tls[i]->tl);
free(ptokenizer->tls[i]);
}
free(ptokenizer->tls);
free(ptokenizer);
return 0;
}
//int binparse_add(tokenizer *t, char *string, char *mask)
R_API int r_search_binparse_add(struct r_search_binparse_t *t, const char *string, const char *mask)
{
int n = t->nlists;
char name[32];
if (string == NULL)
return -1;
t->nlists++;
//snprintf(name, 31, "SEARCH[%d]", n);
snprintf(name, 31, "kw[%d]", n);
t->tls = (tokenlist **) realloc(t->tls, t->nlists*sizeof(tokenlist*));
t->tls[n] = r_search_binparse_token_mask(name, string, mask);
return n;
}
// XXX name needs to be changed in runtime?
R_API int r_search_binparse_add_named(struct r_search_binparse_t *t, const char *name, const char *string, const char *mask)
{
int ret = r_search_binparse_add(t, string, mask);
if (ret != -1)
strncpy(t->tls[ret]->name, name, 200);
return ret;
}
/* -1 = error, 0 = skip, 1 = hit found */
R_API int r_search_binparse_update(struct r_search_binparse_t *t, ut8 inchar, ut64 where)
//int update_tlist(tokenizer* t, ut8 inchar, ut64 where )
{
ut8 cmin, cmax, cmask;
int i;
if (t->nlists == 0) {
fprintf(stderr, "No tokens defined\n");
//config.interrupted = 1;
t->interrupted = 1;
return -1;
}
for (i=0; i<t->nlists; i++ ) {
cmin = (t->tls[i]->tl[t->tls[i]->stat]).mintok;
if ((t->tls[i]->tl[t->tls[i]->stat]).range > 0) {
// RANGE
cmax = cmin + (t->tls[i]->tl[t->tls[i]->stat]).range;
if ((inchar >= cmin) && (inchar <= cmax))
t->tls[i]->actp[t->tls[i]->stat++] = inchar;
else t->tls[i]->stat = 0;
} else {
// 1 char
cmask = (t->tls[i]->tl[t->tls[i]->stat]).mask;
if ((inchar&cmask) == (cmin&cmask))
t->tls[i]->actp[t->tls[i]->stat++] = inchar;
else t->tls[i]->stat = 0;
}
if (t->tls[i]->stat == (t->tls[i]->numtok)) {
t->tls[i]->actp[t->tls[i]->stat+1] = 0 ;
t->tls[i]->actp[0] = 0 ; //rststr
if (t->callback != NULL) // t->tls[i] is the hit
if (!t->callback(t, i, (ut64)(where-(t->tls[i]->numtok-1))))
return 1;
t->tls[i]->stat = 0 ;
}
}
return 0;
}

View File

@ -29,8 +29,7 @@ static fnditem* init_fi()
}
#endif
static void add_fi (fnditem* n, unsigned char* blk, int patlen)
{
static void add_fi (fnditem* n, unsigned char* blk, int patlen) {
fnditem* p;
for(p=n;p->next!=NULL;p=p->next);
@ -42,19 +41,17 @@ static void add_fi (fnditem* n, unsigned char* blk, int patlen)
p->next = NULL;
}
static int is_fi_present(fnditem* n, unsigned char* blk , int patlen)
{
static int is_fi_present(fnditem* n, unsigned char* blk , int patlen) {
fnditem* p;
for(p=n;p->next!=NULL; p=p->next) {
if (!memcmp(blk, p->str, patlen))
for (p=n;p->next!=NULL; p=p->next) {
if (!memcmp (blk, p->str, patlen))
return 1;
}
return 0;
}
// XXX needs to be refactored
int do_byte_pat(int patlen)
{
int do_byte_pat(int patlen) {
unsigned char block[BSIZE+MAX_PATLEN];
unsigned char sblk[MAX_PATLEN+1];
static fnditem* root;
@ -153,8 +150,7 @@ int do_byte_pat(int patlen)
/* -- */
R_API int r_search_pattern_update(int patlen)
{
R_API int r_search_pattern_update(int patlen) {
unsigned char block[BSIZE+MAX_PATLEN];
unsigned char sblk[MAX_PATLEN+1];
static fnditem* root;

View File

@ -1,56 +1,49 @@
/* radare - LGPL - Copyright 2008-2009 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2008-2010 pancake<nopcode.org> */
#include "r_search.h"
#if __UNIX__
#include <regex.h>
R_API int r_search_regexp_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len)
{
R_API int r_search_regexp_update(RSearch *s, ut64 from, const ut8 *buf, int len) {
struct list_head *pos;
char *buffer = malloc(len+1);
char *buffer = malloc (len+1);
char *skipz, *end;
int count = 0;
memcpy(buffer, buf, len);
memcpy (buffer, buf, len);
buffer[len]='\0';
list_for_each_prev(pos, &s->kws) {
struct r_search_kw_t *kw = list_entry(pos, struct r_search_kw_t, list);
list_for_each_prev (pos, &s->kws) {
RSearchKeyword *kw = list_entry (pos, RSearchKeyword, list);
int reflags = REG_EXTENDED;
int ret, delta = 0;
regmatch_t matches[10];
regex_t compiled;
if (strchr(kw->binmask, 'i'))
if (strchr (kw->binmask, 'i'))
reflags |= REG_ICASE;
if (regcomp(&compiled, kw->keyword, reflags)) {
fprintf(stderr, "Cannot compile '%s' regexp\n",kw->keyword);
if (regcomp (&compiled, kw->keyword, reflags)) {
eprintf ("Cannot compile '%s' regexp\n",kw->keyword);
return -1;
}
foo:
ret = regexec(&compiled, buffer+delta, 1, matches, 0);
if (ret) {
return 0;
} else
ret = regexec (&compiled, buffer+delta, 1, matches, 0);
if (ret) return 0;
do {
if (s->callback)
s->callback(kw, s->user, (ut64)from+matches[0].rm_so+delta);
else printf("hit%d_%d 0x%08llx ; %s\n",
count, kw->count, (ut64)(from+matches[0].rm_so),
buf+matches[0].rm_so+delta);
r_search_hit_new (s, kw, (ut64)(from+matches[0].rm_so+delta));
delta += matches[0].rm_so+1;
kw->count++;
count++;
} while(!regexec(&compiled, buffer+delta, 1, matches, 0));
} while (!regexec (&compiled, buffer+delta, 1, matches, 0));
if (delta == 0)
return 0;
/* TODO: check if skip 0 works */
skipz = strchr(buffer, '\0');
skipz = strchr (buffer, '\0');
end = buffer+len;
if (skipz && skipz+1 < end) {
for(;!*skipz&&end;skipz=skipz+1);
for (;!*skipz&&end;skipz=skipz+1);
delta = skipz-buffer;
if (kw->count>0)
goto foo;
@ -60,8 +53,7 @@ R_API int r_search_regexp_update(struct r_search_t *s, ut64 from, const ut8 *buf
}
#else
R_API int r_search_regexp_update(struct r_search_t *s, ut64 from, const ut8 *buf, int len)
{
R_API int r_search_regexp_update(RSearch *s, ut64 from, const ut8 *buf, int len) {
eprintf ("r_search_regexp_update: unimplemented for this platform\n");
return -1;
}

View File

@ -12,16 +12,17 @@ R_API int r_search_init(RSearch *s, int mode) {
s->pattern_size = 0;
s->string_max = 255;
s->string_min = 3;
s->hits = r_list_new ();
// TODO: review those mempool sizes. ensure never gets NULL
s->pool = r_mem_pool_new (sizeof (RSearchHit), 1024, 10);
INIT_LIST_HEAD (&(s->kws));
INIT_LIST_HEAD (&(s->hits));
INIT_LIST_HEAD (&(s->hits));
return R_TRUE;
}
R_API RSearch *r_search_new(int mode) {
RSearch *s = R_NEW (RSearch);
if (r_search_init (s, mode) == -1) {
free (s);
if (!r_search_init (s, mode)) {
r_search_free (s);
s = NULL;
}
return s;
@ -29,6 +30,8 @@ R_API RSearch *r_search_new(int mode) {
R_API RSearch *r_search_free(RSearch *s) {
// TODO: it leaks
r_mem_pool_free (s->pool);
r_list_destroy (s->hits);
free (s);
return NULL;
}
@ -74,6 +77,19 @@ R_API int r_search_begin(RSearch *s) {
return 1;
}
R_API int r_search_hit_new(RSearch *s, RSearchKeyword *kw, ut64 addr) {
RSearchHit* hit;
if (s->callback)
return s->callback (kw, s->user, addr);
hit = r_mem_pool_alloc (s->pool);
if (!hit)
return R_FALSE;
hit->kw = kw;
hit->addr = addr;
r_list_append (s->hits, hit);
return R_TRUE;
}
// TODO: move into a plugin */
R_API int r_search_mybinparse_update(RSearch *s, ut64 from, const ut8 *buf, int len) {
struct list_head *pos;
@ -91,10 +107,8 @@ R_API int r_search_mybinparse_update(RSearch *s, ut64 from, const ut8 *buf, int
if (ch == ch2) {
kw->idx++;
if (kw->idx == kw->keyword_length) {
if (s->callback)
s->callback(kw, s->user, (ut64)from+i-kw->keyword_length+1);
else printf ("hit%d_%d 0x%08llx ; %s\n",
count, kw->count, (ut64)from+i+1, buf+i-kw->keyword_length+1);
r_search_hit_new (s, kw, (ut64)
from+i-kw->keyword_length+1);
kw->idx = 0;
kw->count++;
}
@ -148,7 +162,6 @@ R_API int r_search_update_i(RSearch *s, ut64 from, const ut8 *buf, long len) {
}
/* --- keywords --- */
/* string */
R_API int r_search_kw_add(RSearch *s, const char *kw, const char *bm) {
RSearchKeyword *k = R_NEW (RSearchKeyword);
@ -202,22 +215,22 @@ R_API int r_search_kw_add_bin(RSearch *s, const ut8 *kw, int kw_len, const ut8 *
return R_TRUE;
}
/* show keywords */
/* // MUST DEPRECATE // show keywords */
R_API RSearchKeyword *r_search_kw_list(RSearch *s) {
struct list_head *pos;
list_for_each_prev (pos, &s->kws) {
RSearchKeyword *kw = list_entry(pos, RSearchKeyword, list);
RSearchKeyword *kw = list_entry (pos, RSearchKeyword, list);
printf ("%s %s\n", kw->keyword, kw->binmask);
}
return NULL;
}
R_API int r_search_reset(RSearch *s) {
// TODO
return R_TRUE;
R_API void r_search_reset(RSearch *s) {
r_list_destroy (s->hits);
s->hits = r_list_new ();
s->hits->free = free;
r_search_kw_reset (s);
}
R_API int r_search_kw_reset(RSearch *s) {
// TODO
return R_TRUE;
R_API void r_search_kw_reset(RSearch *s) {
}

View File

@ -69,8 +69,7 @@ static int show_help(char *argv0, int line) {
return 0;
}
int rafind_open(char *file)
{
static int rafind_open(char *file) {
int ret, last = 0;
struct list_head *pos;
r_io_init(&io);
@ -120,8 +119,7 @@ int rafind_open(char *file)
return 0;
}
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
int c;
while ((c = getopt(argc, argv, "b:m:s:x:Xzf:t:rnhV")) != -1) {

View File

@ -2,32 +2,30 @@
char *buffer = "helloworldlibisniceandcoolib2loblubljb";
int hit(struct r_search_kw_t *kw, void *user, ut64 addr)
{
static int hit(struct r_search_kw_t *kw, void *user, ut64 addr) {
//const ut8 *buf = (ut8*)user;
printf("HIT %d AT %lld (%s)\n", kw->count, addr, buffer+addr);
printf ("HIT %d AT %lld (%s)\n", kw->count, addr, buffer+addr);
return 1;
}
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
struct r_search_t *rs;
rs = r_search_new(R_SEARCH_KEYWORD);
r_search_kw_add(rs, "lib", "");
r_search_set_callback(rs, &hit, buffer);
r_search_begin(rs);
rs = r_search_new (R_SEARCH_KEYWORD);
r_search_kw_add (rs, "lib", "");
r_search_set_callback (rs, &hit, buffer);
r_search_begin (rs);
printf("Searching for '%s' in '%s'\n", "lib", buffer);
r_search_update_i(rs, 0LL, (ut8*)buffer, strlen(buffer));
rs = r_search_free(rs);
r_search_update_i (rs, 0LL, (ut8*)buffer, strlen(buffer));
rs = r_search_free (rs);
/* test binmask */
rs = r_search_new(R_SEARCH_KEYWORD);
r_search_kw_add(rs, "lib", "ff00ff");
r_search_set_callback(rs, &hit, buffer);
r_search_begin(rs);
printf("Searching for '%s' with binmask 'ff00ff' in '%s'\n", "lib", buffer);
r_search_update_i(rs, 0LL, (ut8*)buffer, strlen(buffer));
rs = r_search_free(rs);
rs = r_search_new (R_SEARCH_KEYWORD);
r_search_kw_add (rs, "lib", "ff00ff");
r_search_set_callback (rs, &hit, buffer);
r_search_begin (rs);
printf ("Searching for '%s' with binmask 'ff00ff' in '%s'\n", "lib", buffer);
r_search_update_i (rs, 0LL, (ut8*)buffer, strlen(buffer));
rs = r_search_free (rs);
return 0;
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2010 pancake<nopcode.org> */
#include <r_util.h>
#include <stdlib.h>
@ -10,22 +10,20 @@
// This can be useful when the application is swapping (userland swapping?)
// Do user-swapping takes sense?
R_API struct r_mem_pool_t* r_mem_pool_deinit(struct r_mem_pool_t *pool)
{
R_API RMemoryPool* r_mem_pool_deinit(RMemoryPool *pool) {
int i;
for(i=0;i<pool->npool;i++)
free(pool->nodes[i]);
free(pool->nodes);
for (i=0; i<pool->npool; i++)
free (pool->nodes[i]);
free (pool->nodes);
pool->nodes = NULL;
return pool;
}
R_API struct r_mem_pool_t* r_mem_pool_init(struct r_mem_pool_t *pool, int nsize, int psize, int pcount)
{
R_API RMemoryPool* r_mem_pool_init(RMemoryPool *pool, int nsize, int psize, int pcount) {
if (pool) {
if (psize < 1)
if (psize<1)
psize = ALLOC_POOL_SIZE;
if (pcount < 1)
if (pcount<1)
pcount = ALLOC_POOL_COUNT;
// TODO: assert nodesize?;
pool->poolsize = psize;
@ -34,26 +32,27 @@ R_API struct r_mem_pool_t* r_mem_pool_init(struct r_mem_pool_t *pool, int nsize,
pool->npool = -1;
pool->ncount = pool->poolsize; // force init
pool->nodes = (void**) malloc (sizeof (void*) * pool->poolcount);
if (pool->nodes == NULL)
return NULL;
}
return pool;
}
R_API struct r_mem_pool_t *r_mem_pool_new(int nodesize, int poolsize, int poolcount)
{
return r_mem_pool_init (R_NEW (struct r_mem_pool_t),
nodesize, poolsize, poolcount);
R_API RMemoryPool *r_mem_pool_new(int nodesize, int poolsize, int poolcount) {
RMemoryPool *mp = R_NEW (struct r_mem_pool_t);
if (!r_mem_pool_init (mp, nodesize, poolsize, poolcount))
r_mem_pool_free (mp);
return mp;
}
R_API struct r_mem_pool_t *r_mem_pool_free(struct r_mem_pool_t *pool)
{
return (r_mem_pool_deinit(pool),free(pool),NULL);
R_API RMemoryPool *r_mem_pool_free(RMemoryPool *pool) {
return (r_mem_pool_deinit (pool), free (pool), NULL);
}
R_API void* r_mem_pool_alloc(struct r_mem_pool_t *pool)
{
R_API void* r_mem_pool_alloc(RMemoryPool *pool) {
if (pool->ncount >= pool->poolsize) {
if (++pool->npool >= pool->poolcount) {
fprintf (stderr, "FAIL: Cannot allocate more memory in the pool\n");
eprintf ("FAIL: Cannot allocate more memory in the pool\n");
return NULL;
}
pool->nodes[pool->npool] = malloc (pool->nodesize*pool->poolsize);

View File

@ -1,11 +0,0 @@
prefix=@PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: r_meta
Description: radare foundation libraries
Version:
Requires:
Libs: -L${libdir} -lr_meta
Cflags: -I${includedir}/libr