3#include "KittyUtils.hpp"
4#include "KittyIOFile.hpp"
52 IKittyMemOp() : _pid(0)
55 virtual ~IKittyMemOp() =
default;
62 virtual bool init(pid_t pid) = 0;
82 virtual size_t Read(uintptr_t address,
void *buffer,
size_t len, MemMode mode = MemMode::Normal) = 0;
94 virtual size_t Write(uintptr_t address,
void *buffer,
size_t len, MemMode mode = MemMode::Normal) = 0;
115 std::string
ReadUTF8(uintptr_t address,
size_t maxLen);
127 std::u16string
ReadUTF16(uintptr_t address,
size_t maxLen);
139 std::u32string
ReadUTF32(uintptr_t address,
size_t maxLen);
151 std::wstring
ReadWStr(uintptr_t address,
size_t maxLen)
153 if constexpr (
sizeof(wchar_t) == 2)
155 auto str =
ReadUTF16(address, maxLen *
sizeof(
wchar_t));
156 return std::wstring(
reinterpret_cast<const wchar_t *
>(str.data()), str.size());
160 auto str =
ReadUTF32(address, maxLen *
sizeof(
wchar_t));
161 return std::wstring(
reinterpret_cast<const wchar_t *
>(str.data()), str.size());
175 inline std::string
ReadStr(uintptr_t address,
size_t maxLen)
190 inline bool WriteStr(uintptr_t address, std::string str)
192 const size_t len = str.size() + 1;
193 return Write(address, &str[0], len) == len;
206 inline bool WriteWStr(uintptr_t address, std::wstring str)
208 const size_t len = (str.size() + 1) *
sizeof(wchar_t);
209 return Write(address, &str[0], len) == len;
236 size_t Read(uintptr_t address,
void *buffer,
size_t len, MemMode mode = MemMode::Normal);
248 size_t Write(uintptr_t address,
void *buffer,
size_t len, MemMode mode = MemMode::Normal);
257 std::unique_ptr<KittyIOFile> _pMem;
277 size_t Read(uintptr_t address,
void *buffer,
size_t len, MemMode mode = MemMode::Normal);
290 size_t Write(uintptr_t address,
void *buffer,
size_t len, MemMode mode = MemMode::Normal);
std::string ReadUTF8(uintptr_t address, size_t maxLen)
Reads a UTF-8 encoded string from remote process memory.
std::u32string ReadUTF32(uintptr_t address, size_t maxLen)
Reads a UTF-32 encoded string from remote process memory.
std::wstring ReadWStr(uintptr_t address, size_t maxLen)
Reads a platform wchar_t string from remote process memory.
Definition KittyMemOp.hpp:151
virtual bool init(pid_t pid)=0
Initializes the memory operations for a given process.
int lastErrno() const
Returns the last error number.
Definition KittyMemOp.hpp:99
pid_t processID() const
Returns the process ID.
Definition KittyMemOp.hpp:67
bool WriteStr(uintptr_t address, std::string str)
Writes a UTF-8 string to remote process memory.
Definition KittyMemOp.hpp:190
virtual size_t Write(uintptr_t address, void *buffer, size_t len, MemMode mode=MemMode::Normal)=0
Writes data to process memory.
std::u16string ReadUTF16(uintptr_t address, size_t maxLen)
Reads a UTF-16 encoded string from remote process memory.
bool WriteWStr(uintptr_t address, std::wstring str)
Writes a platform wchar_t string to remote process memory.
Definition KittyMemOp.hpp:206
virtual size_t Read(uintptr_t address, void *buffer, size_t len, MemMode mode=MemMode::Normal)=0
Reads data from process memory.
std::string ReadStr(uintptr_t address, size_t maxLen)
Reads a UTF-8 string from remote process memory.
Definition KittyMemOp.hpp:175
Interface class for IO memory operations.
Definition KittyMemOp.hpp:255
size_t Write(uintptr_t address, void *buffer, size_t len, MemMode mode=MemMode::Normal)
Writes memory through /proc/<pid>/mem.
bool init(pid_t pid)
Initializes the memory operations for a given process.
size_t Read(uintptr_t address, void *buffer, size_t len, MemMode mode=MemMode::Normal)
Reads memory through /proc/<pid>/mem.
Interface class for syscall memory operations.
Definition KittyMemOp.hpp:217
size_t Read(uintptr_t address, void *buffer, size_t len, MemMode mode=MemMode::Normal)
Reads memory using process_vm_readv.
bool init(pid_t pid)
Initializes the memory operations for a given process.
size_t Write(uintptr_t address, void *buffer, size_t len, MemMode mode=MemMode::Normal)
Writes memory using process_vm_writev.