diff --git a/magisk-loader/src/main/jni/src/magisk_loader.cpp b/magisk-loader/src/main/jni/src/magisk_loader.cpp index 5d47a6d3..9c2d7e31 100644 --- a/magisk-loader/src/main/jni/src/magisk_loader.cpp +++ b/magisk-loader/src/main/jni/src/magisk_loader.cpp @@ -50,45 +50,6 @@ constexpr int PER_USER_RANGE = 100000; static constexpr uid_t kAidInjected = INJECTED_AID; static constexpr uid_t kAidInet = 3003; -std::vector MapInfo::Scan(std::string_view pid) { - constexpr static auto kPermLength = 5; - constexpr static auto kMapEntry = 7; - std::vector info; - auto path = "/proc/" + std::string{pid} + "/maps"; - auto maps = fopen(path.c_str(), "r"); - if (maps) { - char *line = nullptr; - size_t len = 0; - ssize_t read; - while ((read = getline(&line, &len, maps)) > 0) { - line[read - 1] = '\0'; - uintptr_t start = 0; - uintptr_t end = 0; - uintptr_t off = 0; - ino_t inode = 0; - unsigned int dev_major = 0; - unsigned int dev_minor = 0; - std::array perm{'\0'}; - int path_off; - if (sscanf(line, "%" PRIxPTR "-%" PRIxPTR " %4s %" PRIxPTR " %x:%x %lu %n%*s", &start, - &end, perm.data(), &off, &dev_major, &dev_minor, &inode, - &path_off) != kMapEntry) { - continue; - } - while (path_off < read && isspace(line[path_off])) path_off++; - 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.perms |= PROT_READ; - if (perm[1] == 'w') ref.perms |= PROT_WRITE; - if (perm[2] == 'x') ref.perms |= PROT_EXEC; - } - free(line); - } - fclose(maps); - return info; -} - void MagiskLoader::LoadDex(JNIEnv *env, PreloadedDex &&dex) { auto classloader = JNI_FindClass(env, "java/lang/ClassLoader"); auto getsyscl_mid = JNI_GetStaticMethodID(env, classloader, "getSystemClassLoader", diff --git a/magisk-loader/src/main/jni/src/magisk_loader.h b/magisk-loader/src/main/jni/src/magisk_loader.h index 765fd179..57da14ff 100644 --- a/magisk-loader/src/main/jni/src/magisk_loader.h +++ b/magisk-loader/src/main/jni/src/magisk_loader.h @@ -67,34 +67,4 @@ private: static void setAllowUnload(bool unload); }; - -struct MapInfo { - /// \brief The start address of the memory region. - uintptr_t start; - /// \brief The end address of the memory region. - uintptr_t end; - /// \brief The permissions of the memory region. This is a bit mask of the following values: - /// - PROT_READ - /// - PROT_WRITE - /// - PROT_EXEC - uint8_t perms; - /// \brief Whether the memory region is private. - bool is_private; - /// \brief The offset of the memory region. - uintptr_t offset; - /// \brief The device number of the memory region. - /// Major can be obtained by #major() - /// Minor can be obtained by #minor() - dev_t dev; - /// \brief The inode number of the memory region. - ino_t inode; - /// \brief The path of the memory region. - std::string path; - - /// \brief Scans /proc/self/maps and returns a list of \ref MapInfo entries. - /// This is useful to find out the inode of the library to hook. - /// \param[in] pid The process id to scan. This is "self" by default. - /// \return A list of \ref MapInfo entries. - static std::vector Scan(std::string_view pid = "self"); -}; } // namespace lspd