Skip to content

Commit

Permalink
Make /m create flags
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Apr 24, 2018
1 parent 455c9d7 commit 45588ed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
48 changes: 30 additions & 18 deletions libr/core/cmd_magic.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* radare - LGPL - Copyright 2009-2015 - pancake */
#include <stddef.h>
/* radare - LGPL - Copyright 2009-2018 - pancake */

#include "r_config.h"
#include "r_cons.h"
#include "r_core.h"
#include "r_magic.h"
#include "r_types.h"

/* ugly global vars */
static int magicdepth = 99; //XXX: do not use global var here
static RMagic *ck = NULL; // XXX: Use RCore->magic
static char *ofile = NULL;
static int kw_count = 0;

static void r_core_magic_reset(RCore *core) {
kw_count = 0;
}

static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, int v, bool json) {
const char *fmt;
Expand Down Expand Up @@ -55,7 +55,7 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
ck = NULL;
}
}
if (ck==NULL) {
if (!ck) {
// TODO: Move RMagic into RCore
r_magic_free (ck);
// allocate once
Expand All @@ -81,12 +81,12 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
}
//repeat:
//if (v) r_cons_printf (" %d # pm %s @ 0x%"PFMT64x"\n", depth, file? file: "", addr);
if (delta+2>core->blocksize) {
if (delta + 2 > core->blocksize) {
eprintf ("EOB\n");
ret = -1;
goto seek_exit;
}
str = r_magic_buffer (ck, core->block+delta, core->blocksize-delta);
str = r_magic_buffer (ck, core->block+delta, core->blocksize - delta);
if (str) {
const char *cmdhit;
#if USE_LIB_MAGIC
Expand All @@ -95,7 +95,9 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
if (!v && (!strcmp (str, "data"))) {
#endif
int mod = core->search->align;
if (mod<1) mod = 1;
if (mod < 1) {
mod = 1;
}
//r_magic_free (ck);
//ck = NULL;
//return -1;
Expand All @@ -108,13 +110,18 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
for (q=p; *q; q++) {
if (q[0]=='\\' && q[1]=='n') {
*q = '\n';
strcpy (q+1, q+((q[2]==' ')? 3: 2));
strcpy (q + 1, q + ((q[2] == ' ')? 3: 2));
}
}
cmdhit = r_config_get (core->config, "cmd.hit");
if (cmdhit && *cmdhit) {
r_core_cmd0 (core, cmdhit);
}
{
const char *searchprefix = r_config_get (core->config, "search.prefix");
const char *flag = sdb_fmt ("%s%d_%d", searchprefix, 0, kw_count++);
r_flag_set (core->flags, flag, addr + adelta, 1);
}
// TODO: This must be a callback .. move this into RSearch?
if (!json) {
r_cons_printf ("0x%08"PFMT64x" %d %s\n", addr + adelta, magicdepth-depth, p);
Expand All @@ -128,19 +135,23 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth,
r_cons_clear_line (1);
//eprintf ("0x%08"PFMT64x" 0x%08"PFMT64x" %d %s\n", addr+adelta, addr+adelta, magicdepth-depth, p);
// walking children
for (q=p; *q; q++) {
for (q = p; *q; q++) {
switch (*q) {
case ' ':
fmt = q+1;
fmt = q + 1;
break;
case '@':
{
ut64 addr = 0LL;
*q = 0;
if (!memcmp (q+1, "0x", 2))
sscanf (q+3, "%"PFMT64x, &addr);
else sscanf (q+1, "%"PFMT64d, &addr);
if (!fmt || !*fmt) fmt = file;
if (!strncmp (q + 1, "0x", 2)) {
sscanf (q + 3, "%"PFMT64x, &addr);
} else {
sscanf (q + 1, "%"PFMT64d, &addr);
}
if (!fmt || !*fmt) {
fmt = file;
}
r_core_magic_at (core, fmt, addr, depth, 1, json);
*q = '@';
}
Expand Down Expand Up @@ -182,6 +193,7 @@ static void r_core_magic(RCore *core, const char *file, int v) {
ut64 addr = core->offset;
magicdepth = r_config_get_i (core->config, "magic.depth"); // TODO: do not use global var here
r_core_magic_at (core, file, addr, magicdepth, v, false);
if (addr != core->offset)
if (addr != core->offset) {
r_core_seek (core, addr, true);
}
}
1 change: 1 addition & 0 deletions libr/core/cmd_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -2860,6 +2860,7 @@ static int cmd_search(void *data, const char *input) {
if (json) {
r_cons_printf ("[");
}
r_core_magic_reset (core);
r_list_foreach (param.boundaries, iter, map) {
if (!json) {
eprintf ("-- %llx %llx\n", map->itv.addr, r_itv_end (map->itv));
Expand Down

0 comments on commit 45588ed

Please sign in to comment.