3#include "KittyUtils.hpp"
4#include <unordered_map>
18 uintptr_t startAddress;
22 bool readable, writeable, executable;
23 bool is_private, is_shared;
24 bool is_ro, is_rw, is_rx;
31 : pid(0), startAddress(0), endAddress(0), length(0), protection(0), readable(
false), writeable(
false),
32 executable(
false), is_private(
false), is_shared(
false), is_ro(
false), is_rw(
false), is_rx(
false),
37 inline bool operator==(
const ProcMap &other)
const
39 return (pid == other.pid && startAddress == other.startAddress && endAddress == other.endAddress &&
40 protection == other.protection && is_private == other.is_private && is_shared == other.is_shared &&
41 offset == other.offset && dev == other.dev && inode == other.inode && pathname == other.pathname);
44 inline bool operator!=(
const ProcMap &other)
const
46 return (pid != other.pid || startAddress != other.startAddress || endAddress != other.endAddress ||
47 protection != other.protection || is_private != other.is_private || is_shared != other.is_shared ||
48 offset != other.offset || dev != other.dev || inode != other.inode || pathname != other.pathname);
56 return (startAddress && endAddress && length);
64 return pathname.empty();
75 return address >= startAddress && address < endAddress;
87 writeable ?
'w' :
'-',
88 executable ?
'x' :
'-',
89 is_private ?
'p' :
's',
147 std::unordered_map<std::string, std::string> data;
148 static bool parse(
const std::string &path, ProcStatus *out);
151 ProcStatus() : _pid(-1), _tid(-1)
166 inline static bool parse(pid_t pid, ProcStatus *out)
168 if (pid <= 0 || !out)
172 return parse(
"/proc/" + std::to_string(pid) +
"/status", out);
183 inline static bool parse(pid_t pid, pid_t tid, ProcStatus *out)
185 if (pid <= 0 || tid <= 0 || !out)
190 return parse(
"/proc/" + std::to_string(pid) +
"/task/" + std::to_string(tid) +
"/status", out);
203 return _tid <= 0 ? parse(_pid,
this) : parse(_pid, _tid,
this);
214 return data.find(key) != data.end();
223 inline std::string
getString(
const std::string &key)
const
225 auto it = data.find(key);
226 return (it != data.end()) ? it->second :
"";
235 inline long long getInt(
const std::string &key)
const
237 auto it = data.find(key);
238 if (it == data.end())
241 return std::strtoll(it->second.c_str(),
nullptr, 10);
250 inline bool getBool(
const std::string &key)
const
287 const std::string &name,
288 const std::vector<ProcMap> &maps = std::vector<ProcMap>());
298 ProcMap getAddressMap(pid_t pid, uintptr_t address,
const std::vector<ProcMap> &maps = std::vector<ProcMap>());
316 const std::vector<ProcMap> &maps = std::vector<ProcMap>());
325 std::string getAppDirectory(
const std::string &pkg);
Represents a mapping of a memory region.
Definition KittyMemoryEx.hpp:15
bool isUnknown() const
Checks if the map is unknown (i.e., no pathname).
Definition KittyMemoryEx.hpp:62
bool contains(uintptr_t address) const
Checks if the map contains a specific address.
Definition KittyMemoryEx.hpp:73
std::string toString() const
Converts the map to a string representation..
Definition KittyMemoryEx.hpp:81
bool isValid() const
Checks if the map is valid.
Definition KittyMemoryEx.hpp:54
std::string getString(const std::string &key) const
Retrieves the string value associated with a key.
Definition KittyMemoryEx.hpp:223
bool getBool(const std::string &key) const
Retrieves the boolean value associated with a key.
Definition KittyMemoryEx.hpp:250
static bool parse(pid_t pid, pid_t tid, ProcStatus *out)
Parses the status of a process given its PID and thread ID.
Definition KittyMemoryEx.hpp:183
bool contains(const std::string &key) const
Checks if the process status data contains a specific key.
Definition KittyMemoryEx.hpp:212
bool refresh()
Refreshes the process status.
Definition KittyMemoryEx.hpp:201
long long getInt(const std::string &key) const
Retrieves the integer value associated with a key.
Definition KittyMemoryEx.hpp:235
static bool parse(pid_t pid, ProcStatus *out)
Parses the status of a process given its PID.
Definition KittyMemoryEx.hpp:166
Provides utility functions for process memory.
Definition KittyMemoryEx.hpp:10
std::vector< pid_t > getAllThreads(pid_t pid)
Retrieves a list of thread IDs for a given process ID.
std::vector< ProcMap > getMaps(pid_t pid, EProcMapFilter filter, const std::string &name, const std::vector< ProcMap > &maps=std::vector< ProcMap >())
Retrieves information about all memory maps in a remote process.
pid_t getProcessID(const std::string &processName)
Retrieves the process ID that matches a given process name.
std::vector< pid_t > getProcessIDs(const std::string &processName)
Retrieves a list of process IDs that match a given process name.
std::vector< std::vector< ProcMap > > getFileMappings(pid_t pid, const std::string &path, const std::vector< ProcMap > &maps=std::vector< ProcMap >())
Returns all contiguous mappings of a file in a remote process.
EProcMapFilter
Enumerates the filter types for finding memory maps.
Definition KittyMemoryEx.hpp:260
std::string getProcessName(pid_t pid)
Retrieves the name of the process by its process ID.
ProcMap getAddressMap(pid_t pid, uintptr_t address, const std::vector< ProcMap > &maps=std::vector< ProcMap >())
Retrieves the map information for a specific address in a remote process.
std::vector< ProcMap > getAllMaps(pid_t pid)
Retrieves information about all memory maps in a remote process.
std::string fmt(const char *fmt,...)
Formats a string using a printf-style format.