mirror of
https://github.com/LSPosed/LSPlt.git
synced 2025-05-06 21:48:48 +08:00
Fix perm
This commit is contained in:
parent
eaff1e850b
commit
1155891414
@ -2,10 +2,24 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
namespace lsplt {
|
namespace lsplt {
|
||||||
inline namespace v1 {
|
inline namespace v1 {
|
||||||
|
|
||||||
|
struct MapInfo {
|
||||||
|
uintptr_t start;
|
||||||
|
uintptr_t end;
|
||||||
|
uint8_t perm;
|
||||||
|
bool is_private;
|
||||||
|
dev_t dev;
|
||||||
|
ino_t inode;
|
||||||
|
std::string path;
|
||||||
|
|
||||||
|
static std::vector<MapInfo> Scan();
|
||||||
|
};
|
||||||
|
|
||||||
[[maybe_unused, gnu::visibility("default")]] bool RegisterHook(ino_t ino, std::string_view symbol,
|
[[maybe_unused, gnu::visibility("default")]] bool RegisterHook(ino_t ino, std::string_view symbol,
|
||||||
void *callback, void **backup);
|
void *callback, void **backup);
|
||||||
|
|
||||||
|
@ -20,18 +20,14 @@ struct RegisterInfo {
|
|||||||
void **backup;
|
void **backup;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MapInfo {
|
struct HookMapInfo : public lsplt::MapInfo {
|
||||||
std::string path;
|
|
||||||
ino_t inode;
|
|
||||||
uintptr_t start;
|
|
||||||
uintptr_t end;
|
|
||||||
std::map<uintptr_t, uintptr_t> hooks;
|
std::map<uintptr_t, uintptr_t> hooks;
|
||||||
uintptr_t backup;
|
uintptr_t backup;
|
||||||
std::unique_ptr<Elf> elf;
|
std::unique_ptr<Elf> elf;
|
||||||
[[nodiscard]] bool Match(const RegisterInfo &info) const { return info.inode == inode; }
|
[[nodiscard]] bool Match(const RegisterInfo &info) const { return info.inode == inode; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class MapInfos : public std::map<uintptr_t, MapInfo, std::greater<>> {
|
class HookMapInfos : public std::map<uintptr_t, MapInfo, std::greater<>> {
|
||||||
public:
|
public:
|
||||||
static MapInfos ScanMapInfo() {
|
static MapInfos ScanMapInfo() {
|
||||||
constexpr static auto kPermLength = 5;
|
constexpr static auto kPermLength = 5;
|
||||||
@ -206,6 +202,46 @@ MapInfos map_info;
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace lsplt {
|
namespace lsplt {
|
||||||
|
|
||||||
|
std::vector<MapInfo> MapInfo::Scan() {
|
||||||
|
constexpr static auto kPermLength = 5;
|
||||||
|
constexpr static auto kMapEntry = 5;
|
||||||
|
std::vector<MapInfo> info;
|
||||||
|
auto maps = std::unique_ptr<FILE, decltype(&fclose)>{fopen("/proc/self/maps", "r"), &fclose};
|
||||||
|
if (maps) {
|
||||||
|
char *line = nullptr;
|
||||||
|
size_t len = 0;
|
||||||
|
ssize_t read;
|
||||||
|
while ((read = getline(&line, &len, maps.get())) != -1) {
|
||||||
|
uintptr_t start = 0;
|
||||||
|
uintptr_t end = 0;
|
||||||
|
uintptr_t off = 0;
|
||||||
|
ino_t inode = 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, &inode, &path_off) != kMapEntry) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// we basically only care about r--p entry
|
||||||
|
// and for offset == 0 it's an ELF header
|
||||||
|
// and for offset != 0 it's what we hook
|
||||||
|
// if (perm[0] != 'r') continue;
|
||||||
|
if (perm[3] != 'p') continue;
|
||||||
|
if (perm[2] == 'x') continue;
|
||||||
|
// if (off != 0) continue;
|
||||||
|
while (path_off < read && isspace(line[path_off])) path_off++;
|
||||||
|
if (path_off >= read) continue;
|
||||||
|
std::string path{line + path_off};
|
||||||
|
if (path.empty()) continue;
|
||||||
|
if (path[0] == '[') continue;
|
||||||
|
|
||||||
|
info.emplace(start, MapInfo{std::move(path), inode, start, end, {}, 0, nullptr});
|
||||||
|
}
|
||||||
|
free(line);
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
}
|
||||||
[[maybe_unused]] bool RegisterHook(ino_t ino, std::string_view symbol, void *callback,
|
[[maybe_unused]] bool RegisterHook(ino_t ino, std::string_view symbol, void *callback,
|
||||||
void **backup) {
|
void **backup) {
|
||||||
if (symbol.empty() || !callback) return false;
|
if (symbol.empty() || !callback) return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user