[core] Fix elf name match (#1083)

This commit is contained in:
残页 2021-09-09 00:24:38 +08:00 committed by GitHub
parent 6a2e53134f
commit bb86467918
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 9 deletions

View File

@ -223,25 +223,23 @@ ElfImg::getSymbOffset(std::string_view name, uint32_t gnu_hash, uint32_t elf_has
bool ElfImg::findModuleBase() { bool ElfImg::findModuleBase() {
char buff[256]; char buff[256];
off_t load_addr; off_t load_addr;
int found = 0; bool found = false;
FILE *maps = fopen("/proc/self/maps", "r"); FILE *maps = fopen("/proc/self/maps", "r");
while (fgets(buff, sizeof(buff), maps)) { while (fgets(buff, sizeof(buff), maps)) {
if ((buff[0] == '/' && (strstr(buff, "r-xp") || strstr(buff, "r--p"))) && strstr(buff, elf.data())) { if ((strstr(buff, "r-xp") || strstr(buff, "r--p")) && strstr(buff, elf.data())) {
found = 1;
LOGD("found: %s", buff); LOGD("found: %s", buff);
std::string_view b = buff; std::string_view b = buff;
if (auto begin = b.find_last_of(' '); begin != std::string_view::npos) { if (auto begin = b.find_last_of(' '); begin != std::string_view::npos && b[++begin] == '/') {
elf = b.substr(begin + 1); found = true;
elf = b.substr(begin);
if (elf.back() == '\n') elf.pop_back(); if (elf.back() == '\n') elf.pop_back();
} else {
return false;
}
LOGD("update path: %s", elf.data()); LOGD("update path: %s", elf.data());
break; break;
} }
} }
}
if (!found) { if (!found) {
LOGE("failed to read load address for %s", elf.data()); LOGE("failed to read load address for %s", elf.data());