forked from radareorg/radare2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add regexp search method in r_search - Uses libc regcomp+regexec - Added regexp test example * Added libr.pc for pkg-config
- Loading branch information
Showing
8 changed files
with
113 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
prefix=/usr | ||
exec_prefix=${prefix} | ||
libdir=${exec_prefix}/lib | ||
includedir=${prefix}/include | ||
|
||
Name: libr | ||
Description: radare framework libraries | ||
Version: 0.1 | ||
Requires: gobject-2.0 gmodule-no-export-2.0 | ||
Libs: -L${libdir} -lr_core -lr_lang -lr_search -lr_cmd | ||
Cflags: -I${includedir}/libr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* radare - LGPL - Copyright 2008-2009 pancake<nopcode.org> */ | ||
|
||
#include "r_search.h" | ||
#include <regex.h> | ||
|
||
int r_search_regexp_update(struct r_search_t *s, u64 from, const u8 *buf, int len) | ||
{ | ||
struct list_head *pos; | ||
char *buffer = malloc(len+1); | ||
char *skipz, *end; | ||
int i, count = 0; | ||
|
||
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); | ||
int reflags = REG_EXTENDED; | ||
int delta = 0; | ||
regmatch_t matches[10]; | ||
regex_t compiled; | ||
|
||
if (strchr(kw->binmask, 'i')) | ||
reflags |= REG_ICASE; | ||
|
||
regcomp(&compiled, kw->keyword, reflags); | ||
foo: | ||
while (!regexec(&compiled, buffer+delta, 1, &matches, 0)) { | ||
if (s->callback) | ||
s->callback(kw, s->user, (u64)from+matches[0].rm_so+delta); | ||
else printf("hit%d_%d 0x%08llx ; %s\n", | ||
count, kw->count, (u64)from+matches[0].rm_so, | ||
buf+matches[0].rm_so+delta); | ||
delta += matches[0].rm_so+1; | ||
kw->count++; | ||
count++; | ||
} | ||
|
||
/* TODO: check if skip 0 works */ | ||
skipz = strchr(buffer, '\0'); | ||
end = buffer+len; | ||
if (skipz && skipz+1 < end) { | ||
for(;!*skipz&&end;skipz=skipz+1); | ||
delta = skipz-buffer; | ||
goto foo; | ||
} | ||
} | ||
return count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <r_search.h> | ||
|
||
u8 *buffer = "ELF,e,e,e,ELF--fooo"; | ||
|
||
int hit(struct r_search_kw_t *kw, void *user, u64 addr) | ||
{ | ||
const u8 *buf = (u8*)user; | ||
printf("HIT %d AT %lld (%s)\n", kw->count, addr, buffer+addr); | ||
return 1; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
struct r_search_t *rs; | ||
|
||
rs = r_search_new(R_SEARCH_REGEXP); | ||
r_search_set_callback(rs, &hit, buffer); | ||
r_search_kw_add(rs, "E.F", "i"); /* search for /E.F/i */ | ||
r_search_initialize(rs); | ||
printf("Searching strings in '%s'\n", buffer); | ||
r_search_update_i(rs, 0LL, buffer, strlen(buffer)); | ||
rs = r_search_free(rs); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters