@@ -29,69 +29,6 @@ static int cmpsize(const void *a, const void *b) {
2929 return (as > bs )? 1 : (as < bs )? -1 : 0 ;
3030}
3131
32- static int cmp_sec_range (const RCoreSecRange * a , const RCoreSecRange * b ) {
33- ut64 fa = a -> from ;
34- ut64 fb = b -> from ;
35- return (fa > fb )? 1 : (fa < fb )? -1 : 0 ;
36- }
37-
38- static RVecRCoreSecRange * r_core_get_sec_ranges (RCore * core ) {
39- RCorePriv * priv = core -> priv ;
40- // Check if we have a cached result
41- if (priv -> sec_ranges ) {
42- return priv -> sec_ranges ;
43- }
44- RVecRCoreSecRange * sr = RVecRCoreSecRange_new ();
45- RBin * bin = core -> bin ;
46- int va = core -> io -> va ;
47- RListIter * iter ;
48- RBinFile * bf ;
49- r_list_foreach (bin -> binfiles , iter , bf ) {
50- RBinObject * obj = bf -> bo ;
51- if (!obj ) {
52- continue ;
53- }
54- RBinSection * section ;
55- RListIter * sit ;
56- r_list_foreach (obj -> sections , sit , section ) {
57- if (section -> is_segment ) {
58- continue ;
59- }
60- ut64 from = va ? obj -> baddr_shift + section -> vaddr : section -> paddr ;
61- ut64 to = from + (va ? section -> vsize : section -> size );
62- if (to <= from ) {
63- continue ;
64- }
65- #if 0
66- // Skip writable sections unless they contain strings
67- if ((section -> perm & R_PERM_W ) && !section -> has_strings ) {
68- continue ;
69- }
70- #endif
71- RCoreSecRange r = {
72- .from = from ,
73- .to = to ,
74- };
75- RVecRCoreSecRange_push_back (sr , & r );
76- }
77- }
78- if (!RVecRCoreSecRange_empty (sr ) && RVecRCoreSecRange_length (sr ) > 1 ) {
79- RVecRCoreSecRange_sort (sr , cmp_sec_range );
80- }
81- // Cache the result
82- priv -> sec_ranges = sr ;
83- return sr ;
84- }
85-
86- R_IPI void r_core_sec_ranges_invalidate (RCore * core ) {
87- R_RETURN_IF_FAIL (core );
88- RCorePriv * priv = core -> priv ;
89- if (priv && priv -> sec_ranges ) {
90- RVecRCoreSecRange_free (priv -> sec_ranges );
91- priv -> sec_ranges = NULL ;
92- }
93- }
94-
9532static int cmpfcncc (const void * _a , const void * _b ) {
9633 RAnalFunction * a = (RAnalFunction * )_a ;
9734 RAnalFunction * b = (RAnalFunction * )_b ;
@@ -227,30 +164,6 @@ static int is_string(const ut8 *buf, int size, int *len) {
227164 return 1 ;
228165}
229166
230- static inline int find_sec_range_idx (const RVecRCoreSecRange * sr , ut64 addr ) {
231- if (!sr || RVecRCoreSecRange_empty (sr )) {
232- return -1 ;
233- }
234- size_t count = RVecRCoreSecRange_length (sr );
235- const RCoreSecRange * last = RVecRCoreSecRange_at (sr , count - 1 );
236- if (addr >= last -> to ) {
237- return -1 ;
238- }
239- int lo = 0 , hi = (int )count - 1 ;
240- while (lo <= hi ) {
241- const int mid = lo + (hi - lo ) / 2 ;
242- const RCoreSecRange * r = RVecRCoreSecRange_at (sr , mid );
243- if (addr >= r -> to ) {
244- lo = mid + 1 ;
245- } else if (addr < r -> from ) {
246- hi = mid - 1 ;
247- } else {
248- return mid ;
249- }
250- }
251- return -1 ;
252- }
253-
254167#define STRSZ 128
255168static bool is_cfstring_or_pstring (RCore * core , char * str , int size , int * len ) {
256169 ut64 v0 = r_read_at_le64 (str , 0 );
@@ -269,22 +182,13 @@ static bool is_cfstring_or_pstring(RCore *core, char *str, int size, int *len) {
269182 return false;
270183}
271184
272- static bool is_string_at (RCore * core , ut64 addr , char * str , int * olen , const RVecRCoreSecRange * sr ) {
185+ static bool is_string_at (RCore * core , ut64 addr , char * str , int * olen ) {
273186 if (olen ) {
274187 * olen = 0 ;
275188 }
276189 if (!r_io_is_valid_offset (core -> io , addr , 0 )) {
277190 return false;
278191 }
279- int idx = find_sec_range_idx (sr , addr );
280- if (idx < 0 ) {
281- return false;
282- }
283- const RCoreSecRange * r = RVecRCoreSecRange_at (sr , idx );
284- if (addr + 4 > r -> to ) {
285- return false;
286- }
287-
288192 int len = 0 ;
289193 const int size = STRSZ - 1 ;
290194
@@ -4602,7 +4506,7 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode
46024506 return count ;
46034507}
46044508
4605- static void add_string_ref (RCore * core , ut64 xref_from , ut64 xref_to , const RVecRCoreSecRange * sr ) {
4509+ static void add_string_ref (RCore * core , ut64 xref_from , ut64 xref_to ) {
46064510 const int reftype = R_ANAL_REF_TYPE_DATA | R_ANAL_REF_TYPE_READ ;
46074511 int len = 0 ;
46084512 char str [STRSZ ] = {0 };
@@ -4612,7 +4516,7 @@ static void add_string_ref(RCore *core, ut64 xref_from, ut64 xref_to, const RVec
46124516 if (!xref_from || xref_from == UT64_MAX ) {
46134517 xref_from = core -> anal -> esil -> addr ;
46144518 }
4615- if (is_string_at (core , xref_to , str , & len , sr ) && str [0 ] && len > 0 ) {
4519+ if (is_string_at (core , xref_to , str , & len ) && str [0 ] && len > 0 ) {
46164520 r_anal_xrefs_set (core -> anal , xref_from , xref_to , reftype );
46174521 r_name_filter (str , -1 );
46184522 if (* str ) {
@@ -4638,7 +4542,6 @@ typedef struct {
46384542 int rad ;
46394543 bool cfg_debug ;
46404544 bool cfg_anal_strings ;
4641- const RVecRCoreSecRange * sr ;
46424545} XrefSearchCtx ;
46434546
46444547// R2R db/anal/mach0
@@ -4663,11 +4566,11 @@ static bool found_xref(const XrefSearchCtx *ctx, ut64 at, ut64 xref_to, RAnalRef
46634566 }
46644567 if (!ctx -> rad ) {
46654568 if (ctx -> cfg_anal_strings && R_ANAL_REF_TYPE_MASK (type ) == R_ANAL_REF_TYPE_DATA ) {
4666- add_string_ref (core , at , xref_to , ctx -> sr );
4569+ add_string_ref (core , at , xref_to );
46674570 } else if (ctx -> cfg_anal_strings && R_ANAL_REF_TYPE_MASK (type ) == R_ANAL_REF_TYPE_ICOD ) {
4668- add_string_ref (core , at , xref_to , ctx -> sr );
4571+ add_string_ref (core , at , xref_to );
46694572 } else if (ctx -> cfg_anal_strings && R_ANAL_REF_TYPE_MASK (type ) == R_ANAL_REF_TYPE_STRN ) {
4670- add_string_ref (core , at , xref_to , ctx -> sr );
4573+ add_string_ref (core , at , xref_to );
46714574 } else if (xref_to ) {
46724575 r_anal_xrefs_set (core -> anal , at , xref_to , type );
46734576 }
@@ -4689,7 +4592,7 @@ static bool found_xref(const XrefSearchCtx *ctx, ut64 at, ut64 xref_to, RAnalRef
46894592 r_cons_printf (core -> cons , "%s 0x%08" PFMT64x " 0x%08" PFMT64x "\n" , cmd , xref_to , at );
46904593 if (ctx -> cfg_anal_strings && R_ANAL_REF_TYPE_MASK (type ) == R_ANAL_REF_TYPE_DATA ) {
46914594 char str_flagname [STRSZ ] = {0 };
4692- if (is_string_at (core , xref_to , str_flagname , & len , ctx -> sr )) {
4595+ if (is_string_at (core , xref_to , str_flagname , & len )) {
46934596 ut64 str_addr = xref_to ;
46944597 r_name_filter (str_flagname , -1 );
46954598 r_cons_printf (core -> cons , "'f str.%s=0x%" PFMT64x "\n" , str_flagname , str_addr );
@@ -4726,8 +4629,7 @@ R_API int r_core_anal_search_xrefs(RCore *core, ut64 from, ut64 to, PJ *pj, int
47264629 }
47274630
47284631 const bool search_badpages = r_config_get_b (core -> config , "search.badpages" );
4729- RVecRCoreSecRange * sr = r_core_get_sec_ranges (core );
4730- XrefSearchCtx ctx = { core , pj , rad , r_config_get_b (core -> config , "cfg.debug" ), cfg_anal_strings , sr };
4632+ XrefSearchCtx ctx = { core , pj , rad , r_config_get_b (core -> config , "cfg.debug" ), cfg_anal_strings };
47314633 if (core -> blocksize <= OPSZ ) {
47324634 R_LOG_ERROR ("block size too small" );
47334635 return -1 ;
@@ -5449,7 +5351,6 @@ typedef struct {
54495351 RAnalFunction * fcn ;
54505352 char * spname ;
54515353 ut64 initial_sp ;
5452- RVecRCoreSecRange * sr ;
54535354} EsilBreakCtx ;
54545355
54555356typedef int RPerm ;
@@ -5589,7 +5490,7 @@ static bool esilbreak_mem_read(REsil *esil, ut64 addr, ut8 *buf, int len) {
55895490 } else {
55905491 r_anal_xrefs_set (core -> anal , esil -> addr , refptr , R_ANAL_REF_TYPE_DATA | R_ANAL_REF_TYPE_READ );
55915492 str [sizeof (str ) - 1 ] = 0 ;
5592- add_string_ref (core , esil -> addr , refptr , ctx -> sr );
5493+ add_string_ref (core , esil -> addr , refptr );
55935494 esilbreak_last_data = UT64_MAX ;
55945495 }
55955496 }
@@ -5639,18 +5540,18 @@ static bool esilbreak_reg_write(REsil *esil, const char *name, ut64 *val) {
56395540 }
56405541 if (core -> rasm && core -> rasm -> config && core -> rasm -> config -> bits == 32 && strstr (core -> rasm -> config -> arch , "arm" )) {
56415542 if ((!(at & 1 )) && r_io_is_valid_offset (anal -> iob .io , at , 0 )) { // !core->anal->opt.noncode)) {
5642- add_string_ref (anal -> coreb .core , esil -> addr , at , ctx -> sr );
5543+ add_string_ref (anal -> coreb .core , esil -> addr , at );
56435544 }
56445545 } else if (core -> anal && core -> anal -> config && core -> anal -> config -> bits == 32 && strstr (core -> anal -> config -> arch , "arm" )) {
56455546 if ((!(at & 1 )) && r_io_is_valid_offset (anal -> iob .io , at , 0 )) { // !core->anal->opt.noncode)) {
5646- add_string_ref (anal -> coreb .core , esil -> addr , at , ctx -> sr );
5547+ add_string_ref (anal -> coreb .core , esil -> addr , at );
56475548 }
56485549 }
56495550 } else {
56505551 // intel, sparc and others
56515552 if (op -> type != R_ANAL_OP_TYPE_RMOV ) {
56525553 if (r_io_is_valid_offset (anal -> iob .io , at , 0 )) {
5653- add_string_ref (anal -> coreb .core , esil -> addr , at , ctx -> sr );
5554+ add_string_ref (anal -> coreb .core , esil -> addr , at );
56545555 }
56555556 }
56565557 }
@@ -5883,7 +5784,6 @@ static ut64 pulldata(RCore *core, ut8 *buf, size_t buf_size, ut64 start, ut64 en
58835784
58845785R_API void r_core_anal_esil (RCore * core , const char * str /* len */ , const char * target /* addr */ ) {
58855786 bool cfg_anal_strings = r_config_get_b (core -> config , "anal.strings" );
5886- RVecRCoreSecRange * sr = r_core_get_sec_ranges (core );
58875787 bool emu_lazy = r_config_get_b (core -> config , "emu.lazy" );
58885788 const bool gp_fixed = r_config_get_b (core -> config , "anal.fixed.gp" );
58895789 bool newstack = r_config_get_b (core -> config , "anal.var.newstack" );
@@ -6002,8 +5902,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
60025902 & op ,
60035903 fcn ,
60045904 spname ,
6005- r_reg_getv (core -> anal -> reg , spname ), // initial_sp
6006- sr
5905+ r_reg_getv (core -> anal -> reg , spname ) // initial_sp
60075906 };
60085907 ESIL -> cb .hook_reg_write = & esilbreak_reg_write ;
60095908 //this is necessary for the hook to read the id of analop
@@ -6258,7 +6157,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
62586157 if (myvalid (core , dst )) {
62596158 r_anal_xrefs_set (core -> anal , cur , dst , R_ANAL_REF_TYPE_DATA | R_ANAL_REF_TYPE_READ );
62606159 if (cfg_anal_strings ) {
6261- add_string_ref (core , op .addr , dst , sr );
6160+ add_string_ref (core , op .addr , dst );
62626161 }
62636162 }
62646163 }
@@ -6268,7 +6167,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
62686167 if (myvalid (core , dst )) {
62696168 r_anal_xrefs_set (core -> anal , cur , dst , R_ANAL_REF_TYPE_DATA | R_ANAL_REF_TYPE_READ );
62706169 if (cfg_anal_strings ) {
6271- add_string_ref (core , op .addr , dst , sr );
6170+ add_string_ref (core , op .addr , dst );
62726171 }
62736172 }
62746173 }
@@ -6278,7 +6177,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
62786177 if (myvalid (core , dst )) {
62796178 r_anal_xrefs_set (core -> anal , cur , dst , R_ANAL_REF_TYPE_DATA | R_ANAL_REF_TYPE_READ );
62806179 if (cfg_anal_strings ) {
6281- add_string_ref (core , op .addr , dst , sr );
6180+ add_string_ref (core , op .addr , dst );
62826181 }
62836182 }
62846183 }
@@ -6304,7 +6203,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
63046203 }
63056204 }
63066205 if (cfg_anal_strings ) {
6307- add_string_ref (core , op .addr , op .ptr , sr );
6206+ add_string_ref (core , op .addr , op .ptr );
63086207 }
63096208 break ;
63106209 case R_ANAL_OP_TYPE_SUB :
@@ -6328,7 +6227,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
63286227 }
63296228 }
63306229 if (cfg_anal_strings ) {
6331- add_string_ref (core , op .addr , dst , sr );
6230+ add_string_ref (core , op .addr , dst );
63326231 }
63336232 } else if (archIsMips32 ) {
63346233 if (!needOpVals ) {
@@ -6354,11 +6253,11 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
63546253 if (CHECKREF (dst ) || CHECKREF (cur )) {
63556254 r_anal_xrefs_set (core -> anal , cur , dst , R_ANAL_REF_TYPE_DATA );
63566255 if (cfg_anal_strings ) {
6357- add_string_ref (core , op .addr , dst , sr );
6256+ add_string_ref (core , op .addr , dst );
63586257 }
63596258 if ((f = r_core_flag_get_by_spaces (core -> flags , false, dst ))) {
63606259 r_meta_set_string (core -> anal , R_META_TYPE_COMMENT , cur , f -> name );
6361- } else if (is_string_at (core , dst , str , NULL , sr )) {
6260+ } else if (is_string_at (core , dst , str , NULL )) {
63626261 char * str2 = r_str_newf ("esilref: '%s'" , str );
63636262 // HACK avoid format string inside string used later as format
63646263 // string crashes disasm inside agf under some conditions.
@@ -6374,7 +6273,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
63746273 } else {
63756274 R_LOG_DEBUG ("add aae string refs for this arch here" );
63766275 if (cfg_anal_strings ) {
6377- add_string_ref (core , op .addr , dst , sr );
6276+ add_string_ref (core , op .addr , dst );
63786277 }
63796278#endif
63806279 }
@@ -6386,7 +6285,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
63866285 if (myvalid (core , dst )) {
63876286 r_anal_xrefs_set (core -> anal , cur , dst , R_ANAL_REF_TYPE_DATA | R_ANAL_REF_TYPE_READ );
63886287 if (cfg_anal_strings ) {
6389- add_string_ref (core , op .addr , dst , sr );
6288+ add_string_ref (core , op .addr , dst );
63906289 }
63916290 }
63926291 }
@@ -6395,7 +6294,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
63956294 if (myvalid (core , dst )) {
63966295 r_anal_xrefs_set (core -> anal , cur , dst , R_ANAL_REF_TYPE_DATA | R_ANAL_REF_TYPE_READ );
63976296 if (cfg_anal_strings ) {
6398- add_string_ref (core , op .addr , dst , sr );
6297+ add_string_ref (core , op .addr , dst );
63996298 }
64006299 }
64016300 }
@@ -6528,7 +6427,6 @@ R_IPI int r_core_search_value_in_range(RCore *core, bool relative, RInterval sea
65286427 bool vinfun = r_config_get_b (core -> config , "anal.vinfun" );
65296428 bool vinfunr = r_config_get_b (core -> config , "anal.vinfunrange" );
65306429 bool analStrings = r_config_get_b (core -> config , "anal.strings" );
6531- RVecRCoreSecRange * sr = r_core_get_sec_ranges (core );
65326430 // bool be = r_config_get_b (core->config, "cfg.bigendian");
65336431 const bool be = R_ARCH_CONFIG_IS_BIG_ENDIAN (core -> anal -> config );
65346432 if (relative ) {
@@ -6647,7 +6545,7 @@ R_IPI int r_core_search_value_in_range(RCore *core, bool relative, RInterval sea
66476545 if (isValidMatch ) {
66486546 cb (core , addr , value , vsize , cb_user );
66496547 if (analStrings && stringAt (core , addr )) {
6650- add_string_ref (core , addr , value , sr );
6548+ add_string_ref (core , addr , value );
66516549 }
66526550 hitctr ++ ;
66536551 }
0 commit comments