Skip to content

Commit

Permalink
Honor iomaps in search ranges and add basic awk bindings
Browse files Browse the repository at this point in the history
Honor iomaps on search.to
Initial import of the 'awk bindings'
Honor search.{from|to}
  • Loading branch information
radare committed Oct 31, 2012
1 parent 8270c60 commit a0d099b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
1 change: 0 additions & 1 deletion binr/rafind2/rafind2.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
if (rad) {
printf ("f hit%d_%d 0x%08"PFMT64x" ; %s\n", 0, kw->count, addr, curfile);
} else {
if (!kw->count) printf ("; %s\n", kw->keyword);
printf ("%s: %03d @ 0x%"PFMT64x"\n", curfile, kw->count, addr);
if (pr) {
r_print_hexdump (pr, addr, (ut8*)buffer+delta, 78, 16, R_TRUE);
Expand Down
15 changes: 13 additions & 2 deletions libr/core/cmd_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,14 @@ static int cmd_search(void *data, const char *input) {
ut64 at, from, to;
const char *mode;
char *inp;
ut64 n64;
ut64 n64, __from, __to;
ut32 n32;
ut16 n16;
ut8 *buf;

__from = r_config_get_i (core->config, "search.from");
__to = r_config_get_i (core->config, "search.to");

searchshow = r_config_get_i (core->config, "search.show");
mode = r_config_get (core->config, "search.in");
if (!strcmp (mode, "block")) {
Expand All @@ -177,8 +180,9 @@ static int cmd_search(void *data, const char *input) {
if (to == 0LL || to == UT64_MAX || to == UT32_MAX)
to = r_io_size (core->io);
} else {
RIOMap *map = r_io_map_get (core->io, core->offset);
from = core->offset;
to = r_io_size (core->io);
to = r_io_size (core->io) + (map? map->to:0);
}
} else
if (!strcmp (mode, "section")) {
Expand Down Expand Up @@ -219,6 +223,13 @@ static int cmd_search(void *data, const char *input) {
}
}

if (__from != UT64_MAX) from = __from;
if (__to != UT64_MAX) to = __to;
if (__to < __from) {
eprintf ("Invalid search range. Check 'e search.{from|to}'\n");
return R_FALSE;
}

core->search->align = r_config_get_i (core->config, "search.align");
searchflags = r_config_get_i (core->config, "search.flags");
//TODO: handle section ranges if from&&to==0
Expand Down
4 changes: 2 additions & 2 deletions libr/core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,9 @@ R_API int r_core_config_init(RCore *core) {
r_config_desc (cfg, "search.count", "Start index number at search hits");
r_config_set (cfg, "search.prefix", "hit");
r_config_desc (cfg, "search.prefix", "Prefix name in search hits label");
r_config_set_i (cfg, "search.from", UT64_MAX);
r_config_set_i (cfg, "search.from", -1);
r_config_desc (cfg, "search.from", "Search start address");
r_config_set_i (cfg, "search.to", UT64_MAX);
r_config_set_i (cfg, "search.to", -1);
r_config_desc (cfg, "search.to", "Search end address");
r_config_set_i (cfg, "search.distance", 0); // TODO: use i_cb here and remove code in cmd.c
r_config_desc (cfg, "search.distance", "Search string distance");
Expand Down
38 changes: 38 additions & 0 deletions r2-bindings/awk/r2.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/awk -f

# Configuration
BEGIN {
cpu="arm";
bits=32
offset=0
}
# API
function sys(cmd) {
res = ""
while((cmd|getline line)>0) {
res=res""line"\n"
}
close(x)
return res
}

function dis(x) { return sys("rasm2 -o "offset" -b "bits" -a "cpu" -d '"x"'"); }
function asm(x) { return sys("rasm2 -o "offset" -b "bits" -a "cpu" '"x"'"); }
function symbols(x) { return sys("rabin2 -vs '"x"'"); }
function entry(x) { return sys("rabin2 -ve '"x"'"); }
#TODO: function write(data,off) { return sys("rabin2 -ve '"x"'"); }

function hexfind(file, x) {
return sys("rafind2 -x '"x"' '"file"'|cut -d @ -f 2")
}

# Your program here
BEGIN {
cpu="x86"
op=dis("90903939");
print("Commandline disassembler")
split (hexfind("/bin/ls", "90"), results, / /)
for (a in results) {
print("--- "a)
}
}

0 comments on commit a0d099b

Please sign in to comment.