MCPcopy Create free account
hub / github.com/ALEX5402/NewBlackbox / findModuleBase

Method findModuleBase

Bcore/src/main/cpp/Utils/elf_util.cpp:238–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236}
237
238bool ElfImg::findModuleBase() {
239 char buff[256];
240 off_t load_addr;
241 bool found = false;
242 FILE *maps = fopen("/proc/self/maps", "r");
243
244
245 while (fgets(buff, sizeof(buff), maps)) {
246 if ((strstr(buff, "r-xp") || strstr(buff, "r--p")) && strstr(buff, elf.data())) {
247 ALOGD("found: %s", buff);
248 std::string_view b = buff;
249 if (auto begin = b.find_last_of(' '); begin != std::string_view::npos && b[++begin] == '/') {
250 found = true;
251 elf = b.substr(begin);
252 if (elf.back() == '\n') elf.pop_back();
253 ALOGD("update path: %s", elf.data());
254 break;
255 }
256 }
257 }
258
259 if (!found) {
260 ALOGE("failed to read load address for %s", elf.data());
261 fclose(maps);
262 return false;
263 }
264
265 if (char *next = buff; load_addr = strtoul(buff, &next, 16), next == buff) {
266 ALOGE("failed to read load address for %s", elf.data());
267 }
268
269 fclose(maps);
270
271 ALOGD("get module base %s: %lx", elf.data(), load_addr);
272
273 base = reinterpret_cast<void *>(load_addr);
274 return true;
275}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected