@@ -11,7 +11,7 @@ std::unique_ptr<MemoryRange> FindFileMemoryRange(const char *name) {
11
11
std::unique_ptr<MemoryRange> range (new MemoryRange);
12
12
range->base_ = UINTPTR_MAX;
13
13
ForeachMemoryRange (
14
- [&](uintptr_t begin, uintptr_t end, char *perm, char *mapname) -> bool {
14
+ [&](uintptr_t begin, uintptr_t end, uintptr_t offset, char *perm, char *mapname) -> bool {
15
15
if (strstr (mapname, name)) {
16
16
if (range->path_ == nullptr ) {
17
17
range->path_ = strdup (mapname);
@@ -31,23 +31,27 @@ std::unique_ptr<MemoryRange> FindFileMemoryRange(const char *name) {
31
31
std::unique_ptr<MemoryRange> FindExecuteMemoryRange (const char *name) {
32
32
std::unique_ptr<MemoryRange> range (new MemoryRange);
33
33
ForeachMemoryRange (
34
- [&](uintptr_t begin, uintptr_t end, char *perm, char *mapname) -> bool {
34
+ [&](uintptr_t begin, uintptr_t end, uintptr_t offset, char *perm, char *mapname) -> bool {
35
35
if (strncmp (mapname, " /system/fake-libs/" , 18 ) == 0 ) {
36
36
return true ;
37
37
}
38
- if (strstr (mapname, name) && strstr (perm, " x" ) && strstr (perm, " r" )) {
39
- range->path_ = strdup (mapname);
40
- range->base_ = begin;
41
- range->end_ = end;
42
- return false ;
38
+ if (strstr (mapname, name)) {
39
+ // find the correct base address
40
+ if (offset == 0 ) {
41
+ range->path_ = strdup (mapname);
42
+ range->base_ = begin;
43
+ range->end_ = end;
44
+ }
45
+ if (strstr (perm, " x" ))
46
+ return false ;
43
47
}
44
48
return true ;
45
49
});
46
50
return range;
47
51
}
48
52
49
53
void
50
- ForeachMemoryRange (std::function<bool (uintptr_t , uintptr_t , char *, char *)> callback) {
54
+ ForeachMemoryRange (std::function<bool (uintptr_t , uintptr_t , uintptr_t offset, char *, char *)> callback) {
51
55
FILE *f;
52
56
if ((f = fopen (" /proc/self/maps" , " r" ))) {
53
57
char buf[PATH_MAX], perm[12 ] = {' \0 ' }, dev[12 ] = {' \0 ' }, mapname[PATH_MAX] = {' \0 ' };
@@ -58,7 +62,7 @@ ForeachMemoryRange(std::function<bool(uintptr_t, uintptr_t, char *, char *)> cal
58
62
break ;
59
63
sscanf (buf, " %lx-%lx %s %lx %s %ld %s" , &begin, &end, perm,
60
64
&foo, dev, &inode, mapname);
61
- if (!callback (begin, end, perm, mapname)) {
65
+ if (!callback (begin, end, foo, perm, mapname)) {
62
66
break ;
63
67
}
64
68
}
@@ -69,7 +73,7 @@ ForeachMemoryRange(std::function<bool(uintptr_t, uintptr_t, char *, char *)> cal
69
73
bool IsFileInMemory (const char *name) {
70
74
bool found = false ;
71
75
ForeachMemoryRange (
72
- [&](uintptr_t begin, uintptr_t end, char *perm, char *mapname) -> bool {
76
+ [&](uintptr_t begin, uintptr_t end, uintptr_t offset, char *perm, char *mapname) -> bool {
73
77
if (strstr (mapname, name)) {
74
78
found = true ;
75
79
return false ;
0 commit comments