From bf8b87d7cbc6ac5a4b8a5a6969af90e02d527042 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 27 Nov 2022 01:24:21 +0800 Subject: [PATCH] Add missing map offset --- lsplt/src/main/jni/include/lsplt.hpp | 3 ++- lsplt/src/main/jni/lsplt.cc | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lsplt/src/main/jni/include/lsplt.hpp b/lsplt/src/main/jni/include/lsplt.hpp index 4853520..c42f3f9 100644 --- a/lsplt/src/main/jni/include/lsplt.hpp +++ b/lsplt/src/main/jni/include/lsplt.hpp @@ -11,8 +11,9 @@ inline namespace v1 { struct MapInfo { uintptr_t start; uintptr_t end; - uint8_t perm; + uint8_t perms; bool is_private; + uintptr_t offset; dev_t dev; ino_t inode; std::string path; diff --git a/lsplt/src/main/jni/lsplt.cc b/lsplt/src/main/jni/lsplt.cc index 446157d..b26431c 100644 --- a/lsplt/src/main/jni/lsplt.cc +++ b/lsplt/src/main/jni/lsplt.cc @@ -38,7 +38,7 @@ public: // and for offset != 0 it's what we hook // if (perm[0] != 'r') continue; if (!map.is_private) continue; - if (map.perm & PROT_EXEC) continue; + if (map.perms & PROT_EXEC) continue; // if (off != 0) continue; if (map.path.empty()) continue; if (map.path[0] == '[') continue; @@ -168,7 +168,7 @@ public: for (auto &[addr, backup] : info.hooks) { *reinterpret_cast(addr) = backup; } - mprotect(reinterpret_cast(info.start), len, info.perm); + mprotect(reinterpret_cast(info.start), len, info.perms); } info.hooks.clear(); info.backup = 0; @@ -207,12 +207,12 @@ namespace lsplt { continue; } 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(makedev(dev_major, dev_minor)), inode, line + path_off}); - if (perm[0] == 'r') ref.perm |= PROT_READ; - if (perm[1] == 'w') ref.perm |= PROT_WRITE; - if (perm[2] == 'x') ref.perm |= PROT_EXEC; + if (perm[0] == 'r') ref.perms |= PROT_READ; + if (perm[1] == 'w') ref.perms |= PROT_WRITE; + if (perm[2] == 'x') ref.perms |= PROT_EXEC; } free(line); }