Add missing map offset

This commit is contained in:
LoveSy 2022-11-27 01:24:21 +08:00
parent c9e91f007e
commit bf8b87d7cb
No known key found for this signature in database
2 changed files with 8 additions and 7 deletions

View File

@ -11,8 +11,9 @@ inline namespace v1 {
struct MapInfo { struct MapInfo {
uintptr_t start; uintptr_t start;
uintptr_t end; uintptr_t end;
uint8_t perm; uint8_t perms;
bool is_private; bool is_private;
uintptr_t offset;
dev_t dev; dev_t dev;
ino_t inode; ino_t inode;
std::string path; std::string path;

View File

@ -38,7 +38,7 @@ public:
// and for offset != 0 it's what we hook // and for offset != 0 it's what we hook
// if (perm[0] != 'r') continue; // if (perm[0] != 'r') continue;
if (!map.is_private) continue; if (!map.is_private) continue;
if (map.perm & PROT_EXEC) continue; if (map.perms & PROT_EXEC) continue;
// if (off != 0) continue; // if (off != 0) continue;
if (map.path.empty()) continue; if (map.path.empty()) continue;
if (map.path[0] == '[') continue; if (map.path[0] == '[') continue;
@ -168,7 +168,7 @@ public:
for (auto &[addr, backup] : info.hooks) { for (auto &[addr, backup] : info.hooks) {
*reinterpret_cast<uintptr_t *>(addr) = backup; *reinterpret_cast<uintptr_t *>(addr) = backup;
} }
mprotect(reinterpret_cast<void *>(info.start), len, info.perm); mprotect(reinterpret_cast<void *>(info.start), len, info.perms);
} }
info.hooks.clear(); info.hooks.clear();
info.backup = 0; info.backup = 0;
@ -207,12 +207,12 @@ namespace lsplt {
continue; continue;
} }
while (path_off < read && isspace(line[path_off])) path_off++; while (path_off < read && isspace(line[path_off])) path_off++;
auto &ref = info.emplace_back(MapInfo{start, end, 0, perm[3] == 'p', auto &ref = info.emplace_back(MapInfo{start, end, 0, perm[3] == 'p', off,
static_cast<dev_t>(makedev(dev_major, dev_minor)), static_cast<dev_t>(makedev(dev_major, dev_minor)),
inode, line + path_off}); inode, line + path_off});
if (perm[0] == 'r') ref.perm |= PROT_READ; if (perm[0] == 'r') ref.perms |= PROT_READ;
if (perm[1] == 'w') ref.perm |= PROT_WRITE; if (perm[1] == 'w') ref.perms |= PROT_WRITE;
if (perm[2] == 'x') ref.perm |= PROT_EXEC; if (perm[2] == 'x') ref.perms |= PROT_EXEC;
} }
free(line); free(line);
} }