mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-25 06:09:50 +00:00
2x speedup in objc mach0 parsing with memoication
This commit is contained in:
parent
d779aa3352
commit
e0e15baa6c
@ -997,10 +997,11 @@ struct section_t* MACH0_(get_sections)(struct MACH0_(obj_t)* bin) {
|
||||
char segname[32], sectname[32];
|
||||
int i, j, to;
|
||||
|
||||
if (!bin)
|
||||
if (!bin) {
|
||||
return NULL;
|
||||
}
|
||||
/* for core files */
|
||||
if (bin->nsects <1 && bin->nsegs > 0) {
|
||||
if (bin->nsects < 1 && bin->nsegs > 0) {
|
||||
struct MACH0_(segment_command) *seg;
|
||||
if (!(sections = calloc ((bin->nsegs + 1), sizeof (struct section_t)))) {
|
||||
return NULL;
|
||||
@ -1021,13 +1022,16 @@ struct section_t* MACH0_(get_sections)(struct MACH0_(obj_t)* bin) {
|
||||
return sections;
|
||||
}
|
||||
|
||||
if (!bin->sects)
|
||||
if (!bin->sects) {
|
||||
return NULL;
|
||||
}
|
||||
to = R_MIN (bin->nsects, 128); // limit number of sections here to avoid fuzzed bins
|
||||
if (to < 1)
|
||||
if (to < 1) {
|
||||
return NULL;
|
||||
if (!(sections = malloc ((bin->nsects + 1) * sizeof (struct section_t))))
|
||||
}
|
||||
if (!(sections = malloc ((bin->nsects + 1) * sizeof (struct section_t)))) {
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < to; i++) {
|
||||
sections[i].offset = (ut64)bin->sects[i].offset;
|
||||
sections[i].addr = (ut64)bin->sects[i].addr;
|
||||
@ -1037,7 +1041,7 @@ struct section_t* MACH0_(get_sections)(struct MACH0_(obj_t)* bin) {
|
||||
r_str_ncpy (sectname, bin->sects[i].sectname, sizeof (sectname)-1);
|
||||
// hack to support multiple sections with same name
|
||||
snprintf (segname, sizeof (segname), "%d", i); // wtf
|
||||
for (j=0; j<bin->nsegs; j++) {
|
||||
for (j = 0; j < bin->nsegs; j++) {
|
||||
if (sections[i].addr >= bin->segs[j].vmaddr &&
|
||||
sections[i].addr < (bin->segs[j].vmaddr + bin->segs[j].vmsize)) {
|
||||
sections[i].srwx = prot2perm (bin->segs[j].initprot);
|
||||
|
@ -114,15 +114,17 @@ static mach0_ut get_pointer(mach0_ut p, ut32 *offset, ut32 *left, RBinFile *arch
|
||||
mach0_ut r;
|
||||
mach0_ut addr;
|
||||
|
||||
RList *sctns = NULL;
|
||||
static RList *sctns = NULL;
|
||||
RListIter *iter = NULL;
|
||||
RBinSection *s = NULL;
|
||||
|
||||
sctns = r_bin_plugin_mach.sections (arch);
|
||||
if (sctns == NULL) {
|
||||
// retain just for debug
|
||||
// eprintf ("there is no sections\n");
|
||||
return 0;
|
||||
sctns = r_bin_plugin_mach.sections (arch);
|
||||
if (sctns == NULL) {
|
||||
// retain just for debug
|
||||
// eprintf ("there is no sections\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
addr = p;
|
||||
@ -131,7 +133,10 @@ static mach0_ut get_pointer(mach0_ut p, ut32 *offset, ut32 *left, RBinFile *arch
|
||||
if (offset) *offset = addr - s->vaddr;
|
||||
if (left) *left = s->vsize - (addr - s->vaddr);
|
||||
r = (s->paddr + (addr - s->vaddr));
|
||||
#if 0
|
||||
r_list_free (sctns);
|
||||
sctns = NULL;
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@ -139,7 +144,10 @@ static mach0_ut get_pointer(mach0_ut p, ut32 *offset, ut32 *left, RBinFile *arch
|
||||
if (offset) *offset = 0;
|
||||
if (left) *left = 0;
|
||||
|
||||
#if 0
|
||||
r_list_free (sctns);
|
||||
sctns = NULL;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -746,8 +754,9 @@ static void get_class_t(mach0_ut p, RBinFile *arch, RBinClass *klass) {
|
||||
ut32 is_meta_class = 0;
|
||||
int len;
|
||||
|
||||
if (!(r = get_pointer (p, &offset, &left, arch)))
|
||||
if (!(r = get_pointer (p, &offset, &left, arch))) {
|
||||
return;
|
||||
}
|
||||
if ((r + left) < r || (r + size) < r) return;
|
||||
if (r > arch->size || r + left > arch->size) return;
|
||||
if (r + size > arch->size) return;
|
||||
|
Loading…
Reference in New Issue
Block a user