Remove redundant MapInfo::Scan function
With inline hook, we no longer need to scan process virtual maps. Moreover, I can no longer justify the point 3 stated in commit156c6ae855by experiments, which is mysterious given my previous experiments done for the commit3c020a9cd7. Currently, only one thing is sure: reading `/proc/self/map` can be detected by Holmes. Hence, it is always a good practice to not inject unnecessary codes during the preAppSpecialize API.
This commit is contained in:
parent
583aa30393
commit
1d09934523
|
|
@ -50,45 +50,6 @@ constexpr int PER_USER_RANGE = 100000;
|
||||||
static constexpr uid_t kAidInjected = INJECTED_AID;
|
static constexpr uid_t kAidInjected = INJECTED_AID;
|
||||||
static constexpr uid_t kAidInet = 3003;
|
static constexpr uid_t kAidInet = 3003;
|
||||||
|
|
||||||
std::vector<MapInfo> MapInfo::Scan(std::string_view pid) {
|
|
||||||
constexpr static auto kPermLength = 5;
|
|
||||||
constexpr static auto kMapEntry = 7;
|
|
||||||
std::vector<MapInfo> 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<char, kPermLength> 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<dev_t>(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) {
|
void MagiskLoader::LoadDex(JNIEnv *env, PreloadedDex &&dex) {
|
||||||
auto classloader = JNI_FindClass(env, "java/lang/ClassLoader");
|
auto classloader = JNI_FindClass(env, "java/lang/ClassLoader");
|
||||||
auto getsyscl_mid = JNI_GetStaticMethodID(env, classloader, "getSystemClassLoader",
|
auto getsyscl_mid = JNI_GetStaticMethodID(env, classloader, "getSystemClassLoader",
|
||||||
|
|
|
||||||
|
|
@ -67,34 +67,4 @@ private:
|
||||||
|
|
||||||
static void setAllowUnload(bool unload);
|
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<MapInfo> Scan(std::string_view pid = "self");
|
|
||||||
};
|
|
||||||
} // namespace lspd
|
} // namespace lspd
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue