mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-03 20:22:38 +00:00
* r_core
- Add support to '/c' for "multiple instructions" search with search.asmstr=1 - Move r_core_asm_search functions to core/asm.c - Fix typo in r_core_anal_search()
This commit is contained in:
parent
a324e5579b
commit
8768a18a88
@ -4,7 +4,7 @@ DEPS=r_config r_cons r_line r_io r_cmd r_util r_print r_flags r_asm r_lib
|
||||
DEPS+=r_debug r_hash r_bin r_lang r_io r_anal r_parse r_print r_bp
|
||||
DEPS+=r_reg r_meta r_search r_syscall r_sign r_diff
|
||||
|
||||
OBJ=core.o cmd.o file.o config.o visual.o io.o yank.o libs.o anal.o project.o gdiff.o
|
||||
OBJ=core.o cmd.o file.o config.o visual.o io.o yank.o libs.o anal.o project.o gdiff.o asm.o
|
||||
|
||||
CFLAGS+=-DLIBDIR=\"${PREFIX}/lib\"
|
||||
CFLAGS+=-DPREFIX=\"${PREFIX}\"
|
||||
|
@ -442,7 +442,7 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref) {
|
||||
eprintf ("Null reference search is not supported\n");
|
||||
else
|
||||
if (core->blocksize<=OPSZ)
|
||||
eprintf ("erro: block size too small\n");
|
||||
eprintf ("error: block size too small\n");
|
||||
else
|
||||
for (at = from; at < to; at += core->blocksize) {
|
||||
if (r_cons_singleton ()->breaked)
|
||||
|
83
libr/core/asm.c
Normal file
83
libr/core/asm.c
Normal file
@ -0,0 +1,83 @@
|
||||
/* radare - LGPL - Copyright 2009-2010 */
|
||||
/* nibble<.ds@gmail.com> */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_core.h>
|
||||
#include <r_asm.h>
|
||||
|
||||
R_API char* r_core_asm_search(RCore *core, const char *input, ut64 from, ut64 to) {
|
||||
RAsmCode *acode;
|
||||
char *ret;
|
||||
|
||||
if (!(acode = r_asm_massemble (core->assembler, input)))
|
||||
return NULL;
|
||||
ret = strdup (acode->buf_hex);
|
||||
r_asm_code_free (acode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define OPSZ 32
|
||||
R_API int r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut64 to) {
|
||||
RAsmAop aop;
|
||||
ut64 at, toff = core->offset;
|
||||
ut8 *buf;
|
||||
char *tok, *tokens[1024];
|
||||
int idx, tidx, ret, len;
|
||||
int tokcount, matchcount, count;
|
||||
|
||||
for (tokcount=0;;tokcount++) {
|
||||
if (tokcount==0) tok = (char*)strtok ((char*)input, ";");
|
||||
else tok = (char*)strtok (NULL, ";");
|
||||
if (tok == NULL)
|
||||
break;
|
||||
tokens[tokcount] = tok;
|
||||
}
|
||||
if (core->blocksize<=OPSZ) {
|
||||
eprintf ("error: block size too small\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
buf = (ut8 *)malloc (core->blocksize);
|
||||
for (at = from, count = 0, matchcount = 0; at < to; at += core->blocksize-OPSZ) {
|
||||
if (r_cons_singleton ()->breaked)
|
||||
break;
|
||||
ret = r_io_read_at (core->io, at, buf, core->blocksize);
|
||||
if (ret != core->blocksize)
|
||||
break;
|
||||
idx = 0, matchcount = 0;
|
||||
while (idx<core->blocksize) {
|
||||
r_asm_set_pc (core->assembler, at+idx);
|
||||
if (!(len = r_asm_disassemble (core->assembler, &aop, buf+idx, core->blocksize-idx))) {
|
||||
if (matchcount != 0)
|
||||
idx = tidx+1;
|
||||
else idx++;
|
||||
matchcount = 0;
|
||||
continue;
|
||||
}
|
||||
if (strstr (aop.buf_asm, tokens[matchcount])) {
|
||||
if (matchcount == tokcount-1) {
|
||||
if (tokcount == 1)
|
||||
tidx = idx;
|
||||
r_cons_printf ("f hit0_%i @ 0x%08"PFMT64x"\n", count, at+tidx);
|
||||
count++;
|
||||
matchcount = 0;
|
||||
idx = tidx+1;
|
||||
} else if (matchcount == 0) {
|
||||
tidx = idx;
|
||||
matchcount++;
|
||||
idx += len;
|
||||
} else {
|
||||
matchcount++;
|
||||
idx += len;
|
||||
}
|
||||
} else {
|
||||
if (matchcount != 0)
|
||||
idx = tidx+1;
|
||||
else idx++;
|
||||
matchcount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
r_asm_set_pc (core->assembler, toff);
|
||||
free (buf);
|
||||
return R_TRUE;
|
||||
}
|
@ -2221,41 +2221,19 @@ static int cmd_search(void *data, const char *input) {
|
||||
/* TODO: Move to a separate function */
|
||||
int asmstr = r_config_get_i (core->config, "search.asmstr");
|
||||
if (asmstr) {
|
||||
RAsmAop aop;
|
||||
ut64 at, toff = core->offset;
|
||||
ut8 *buf;
|
||||
int i, count;
|
||||
buf = (ut8 *)malloc (core->blocksize);
|
||||
for (at = from, count = 0; at < to; at += core->blocksize) {
|
||||
if (r_cons_singleton ()->breaked)
|
||||
break;
|
||||
ret = r_io_read_at (core->io, at, buf, core->blocksize);
|
||||
if (ret != core->blocksize)
|
||||
break;
|
||||
for (i=0; i<core->blocksize; i++) {
|
||||
r_asm_set_pc (core->assembler, at+i);
|
||||
if (!(r_asm_disassemble (core->assembler, &aop, buf+i, core->blocksize-i)))
|
||||
continue;
|
||||
if (strstr (aop.buf_asm, input+2)) {
|
||||
r_cons_printf ("f hit0_%i 0x%08"PFMT64x"\n", count, (ut64)(at+i));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
r_asm_set_pc (core->assembler, toff);
|
||||
free (buf);
|
||||
r_core_asm_strsearch (core, input+2, from, to);
|
||||
dosearch = 0;
|
||||
} else {
|
||||
RAsmCode *acode;
|
||||
if (!(acode = r_asm_massemble (core->assembler, input+2)))
|
||||
char *kwd;
|
||||
if (!(kwd = r_core_asm_search (core, input+2, from, to)))
|
||||
return R_FALSE;
|
||||
r_search_reset (core->search, R_SEARCH_KEYWORD);
|
||||
r_search_set_distance (core->search, (int)
|
||||
r_config_get_i (core->config, "search.distance"));
|
||||
r_search_kw_add (core->search,
|
||||
r_search_keyword_new_hexmask (acode->buf_hex, NULL));
|
||||
r_search_keyword_new_hexmask (kwd, NULL));
|
||||
r_search_begin (core->search);
|
||||
r_asm_code_free (acode);
|
||||
free (kwd);
|
||||
dosearch = 1;
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,10 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad);
|
||||
R_API int r_core_anal_graph(struct r_core_t *core, ut64 addr, int opts);
|
||||
R_API int r_core_anal_graph_fcn(struct r_core_t *core, char *input, int opts);
|
||||
|
||||
/* asm.c */
|
||||
R_API char* r_core_asm_search(RCore *core, const char *input, ut64 from, ut64 to);
|
||||
R_API int r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut64 to);
|
||||
|
||||
/* gdiff.c */
|
||||
R_API int r_core_gdiff(struct r_core_t *core, char *file1, char *file2, int va);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user