mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-11 15:04:23 +00:00
Fix #8514 - Implement /c/a and make /c/ work properly
This commit is contained in:
parent
c971176e41
commit
140e26143d
@ -14,8 +14,12 @@ static void add_hit_to_sorted_hits(RList* hits, ut64 addr, int len, ut8 is_valid
|
||||
static int prune_hits_in_addr_range(RList *hits, ut64 addr, ut64 len, ut8 is_valid);
|
||||
|
||||
static int rcoreasm_address_comparator(RCoreAsmHit *a, RCoreAsmHit *b){
|
||||
if (a->addr == b->addr) return 0;
|
||||
if (a->addr < b->addr) return -1;
|
||||
if (a->addr == b->addr) {
|
||||
return 0;
|
||||
}
|
||||
if (a->addr < b->addr) {
|
||||
return -1;
|
||||
}
|
||||
return 1; /* a->addr > b->addr */
|
||||
}
|
||||
|
||||
@ -29,16 +33,18 @@ R_API RCoreAsmHit *r_core_asm_hit_new() {
|
||||
|
||||
R_API RList *r_core_asm_hit_list_new() {
|
||||
RList *list = r_list_new ();
|
||||
if (!list) return NULL;
|
||||
list->free = &r_core_asm_hit_free;
|
||||
if (list) {
|
||||
list->free = &r_core_asm_hit_free;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
R_API void r_core_asm_hit_free(void *_hit) {
|
||||
RCoreAsmHit *hit = _hit;
|
||||
if (hit) {
|
||||
if (hit->code)
|
||||
if (hit->code) {
|
||||
free (hit->code);
|
||||
}
|
||||
free (hit);
|
||||
}
|
||||
}
|
||||
@ -56,7 +62,7 @@ R_API char* r_core_asm_search(RCore *core, const char *input) {
|
||||
|
||||
#define OPSZ 8
|
||||
// TODO: add support for byte-per-byte opcode search
|
||||
R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut64 to, int maxhits, int regexp) {
|
||||
R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut64 to, int maxhits, int regexp, int everyByte) {
|
||||
RCoreAsmHit *hit;
|
||||
RAsmOp op;
|
||||
RList *hits;
|
||||
@ -173,7 +179,11 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6
|
||||
idx += len;
|
||||
}
|
||||
} else {
|
||||
idx = matchcount? tidx + 1: idx + 1;
|
||||
if (everyByte) {
|
||||
idx = matchcount? tidx + 1: idx + 1;
|
||||
} else {
|
||||
idx += len;
|
||||
}
|
||||
R_FREE (code);
|
||||
matchcount = 0;
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ static const char *help_msg_slash_c[] = {
|
||||
"Usage:", "/c [inst]", " Search for asm",
|
||||
"/c ", "instr", "search for instruction 'instr'",
|
||||
"/c/ ", "instr", "search for instruction that matches regexp 'instr'",
|
||||
"/c/a ", "instr", "search for every byte instruction that matches regexp 'instr'",
|
||||
"/c ", "instr1;instr2", "search for instruction 'instr1' followed by 'instr2'",
|
||||
"/c/ ", "instr1;instr2", "search for regex instruction 'instr1' followed by regex 'instr2'",
|
||||
"/cj ", "instr", "json output",
|
||||
@ -75,7 +76,6 @@ static const char *help_msg_slash_C[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static const char *help_msg_slash_r[] = {
|
||||
"Usage:", "/r[acerwx] [address]", " search references to this specific address",
|
||||
"/r", " [addr]", "search references to this specific address",
|
||||
@ -1700,7 +1700,8 @@ static void do_asm_search(RCore *core, struct search_parameters *param, const ch
|
||||
int kwidx = core->search->n_kws; // (int)r_config_get_i (core->config, "search.kwidx")-1;
|
||||
RList *hits;
|
||||
RIOMap *map;
|
||||
int regexp = input[1] == '/';
|
||||
bool regexp = input[1] == '/'; // "/c/"
|
||||
bool everyByte = regexp && input[2] == 'a';
|
||||
char *end_cmd = strstr (input, " ");
|
||||
int outmode;
|
||||
if (!end_cmd) {
|
||||
@ -1730,6 +1731,9 @@ static void do_asm_search(RCore *core, struct search_parameters *param, const ch
|
||||
r_cons_print ("[");
|
||||
}
|
||||
r_cons_break_push (NULL, NULL);
|
||||
if (everyByte) {
|
||||
input ++;
|
||||
}
|
||||
r_list_foreach (param->boundaries, itermap, map) {
|
||||
ut64 from = map->itv.addr;
|
||||
ut64 to = r_itv_end (map->itv);
|
||||
@ -1743,7 +1747,7 @@ static void do_asm_search(RCore *core, struct search_parameters *param, const ch
|
||||
hits = NULL;
|
||||
} else {
|
||||
hits = r_core_asm_strsearch (core, input + 2,
|
||||
from, to, maxhits, regexp);
|
||||
from, to, maxhits, regexp, everyByte);
|
||||
}
|
||||
if (hits) {
|
||||
const char *cmdhit = r_config_get (core->config, "cmd.hit");
|
||||
|
@ -414,7 +414,7 @@ R_API RList *r_core_asm_hit_list_new(void);
|
||||
R_API void r_core_asm_hit_free(void *_hit);
|
||||
R_API void r_core_set_asm_configs(RCore *core, char *arch, ut32 bits, int segoff);
|
||||
R_API char* r_core_asm_search(RCore *core, const char *input);
|
||||
R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut64 to, int maxhits, int regexp);
|
||||
R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut64 to, int maxhits, int regexp, int everyByte);
|
||||
R_API RList *r_core_asm_bwdisassemble (RCore *core, ut64 addr, int n, int len);
|
||||
R_API RList *r_core_asm_back_disassemble_instr (RCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding);
|
||||
R_API RList *r_core_asm_back_disassemble_byte (RCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding);
|
||||
|
Loading…
Reference in New Issue
Block a user