25#ifndef MEMORYACCESSOR_SRC_MEMORYACCESSOR_H_
26#define MEMORYACCESSOR_SRC_MEMORYACCESSOR_H_
35#include <unordered_set>
64 virtual const char *what()
const noexcept override {
65 return "Base exception";
81 virtual const char *what()
const noexcept override {
82 return "PID exception";
99 virtual const char *what()
const noexcept override {
100 return "An error occurred while checking if PID exists";
117 virtual const char *what()
const noexcept override {
118 return "PID not exist";
135 virtual const char *what()
const noexcept override {
return "PID not set"; }
150 virtual const char *what()
const noexcept override {
151 return "Error in opening file";
168 virtual const char *what()
const noexcept override {
169 return "Error in opening current /proc/PID/mem";
185 virtual const char *what()
const noexcept override {
186 return "Error in opening current /proc/PID/maps";
202 virtual const char *what()
const noexcept override {
203 return "Error in parsing /proc/PID/maps";
220 virtual const char *what()
const noexcept override {
221 return "Segment exception";
238 virtual const char *what()
const noexcept override {
239 return "The segment of memory does not exist";
256 virtual const char *what()
const noexcept override {
257 return "Access to the segment of memory denied";
274 virtual const char *what()
const noexcept override {
275 return "Address does not belong to any segment";
315 pid_t
GetPid() const noexcept(false);
316 void SetPid(const pid_t &pid) noexcept(false);
317 void CheckPid() const noexcept(false);
321 void CheckSegNum(const
size_t &num) const noexcept(false);
323 void Reset() noexcept;
324 size_t ReadSegment(
char *dst, const
size_t &num,
size_t start = 0,
325 size_t amount = SIZE_MAX) noexcept(false);
326 size_t WriteSegment(const
char *src, const
size_t &num,
size_t start = 0,
327 size_t amount = SIZE_MAX) noexcept(false);
328 void Read(
char *dst,
size_t address,
size_t amount,
329 size_t &done_amount) noexcept(false);
330 void Write(const
char *src,
size_t address,
size_t amount,
331 size_t &done_amount) noexcept(false);
344 void OpenMem() noexcept(false);
345 void CheckMem() noexcept(false);
346 void CheckSegBoundaries(const
size_t &num, const
size_t &start,
347 size_t &amount) const noexcept(false);
348 void PrepareMemSegment(const
size_t &num, const
size_t &start,
349 size_t &amount) noexcept(false);
351 static
bool one_instance_created_;
Ex: Address does not belong to any segment.
Definition memoryaccessor.h:267
Ex: Parsing /proc/PID/maps failed.
Definition memoryaccessor.h:195
Ex: Base exception.
Definition memoryaccessor.h:57
Ex: Could not check if PID exists.
Definition memoryaccessor.h:92
Ex: Exception related to files.
Definition memoryaccessor.h:143
Ex: Opening /proc/PID/maps failed.
Definition memoryaccessor.h:178
Ex: Operation with /proc/PID/mem failed.
Definition memoryaccessor.h:161
Ex: Exception related to PID.
Definition memoryaccessor.h:74
Ex: PID does not exist.
Definition memoryaccessor.h:110
Ex: PID is not set.
Definition memoryaccessor.h:128
Ex: Access to the segment of memory denied.
Definition memoryaccessor.h:249
Ex: Exception related to memory segments.
Definition memoryaccessor.h:213
Ex: Segment of memory does not exist.
Definition memoryaccessor.h:231
A class to perform the main operations with memory.
Definition memoryaccessor.h:50
void CheckPid() const noexcept(false)
Check if PID is set.
Definition memoryaccessor.cc:107
pid_t GetPid() const noexcept(false)
Get PID.
Definition memoryaccessor.cc:72
MemoryAccessor & operator=(const MemoryAccessor &origin)=delete
Copy-assignment operator (deleted).
std::vector< SegmentInfo > segment_infos_
Definition memoryaccessor.h:341
size_t AddressInSegment(const size_t &address) const noexcept(false)
Find out which segment an address belongs to.
Definition memoryaccessor.cc:200
size_t WriteSegment(const char *src, const size_t &num, size_t start=0, size_t amount=SIZE_MAX) noexcept(false)
Write data to memory segment.
Definition memoryaccessor.cc:294
MemoryAccessor(const MemoryAccessor &origin)=delete
Copy constructor (deleted).
MemoryAccessor(MemoryAccessor &&origin)=delete
Move constructor (deleted).
void ParseMaps() noexcept(false)
Parse maps file.
Definition memoryaccessor.cc:121
size_t ReadSegment(char *dst, const size_t &num, size_t start=0, size_t amount=SIZE_MAX) noexcept(false)
Read full memory segment or a part of it.
Definition memoryaccessor.cc:267
void Read(char *dst, size_t address, size_t amount, size_t &done_amount) noexcept(false)
Read data from /proc/PID/mem.
Definition memoryaccessor.cc:322
std::unordered_set< std::string > GetAllSegmentNames() const noexcept
Get all segment names.
Definition memoryaccessor.cc:179
void SetPid(const pid_t &pid) noexcept(false)
Set PID.
Definition memoryaccessor.cc:85
std::map< std::string, SegmentInfo * > special_segment_found_
Definition memoryaccessor.h:336
MemoryAccessor(Tools &tools) noexcept(false)
Constructor.
Definition memoryaccessor.cc:51
void ResetSegments() noexcept
Delete all data related to found segments.
Definition memoryaccessor.cc:232
Tools & tools_
A reference to a Tools class instance.
Definition memoryaccessor.h:333
void Reset() noexcept
Reset all data related to PID.
Definition memoryaccessor.cc:243
~MemoryAccessor() noexcept
Destructor.
Definition memoryaccessor.cc:63
void Write(const char *src, size_t address, size_t amount, size_t &done_amount) noexcept(false)
Write data to /proc/PID/mem.
Definition memoryaccessor.cc:365
void CheckSegNum(const size_t &num) const noexcept(false)
Check if a segment with the given number exists.
Definition memoryaccessor.cc:220
MemoryAccessor & operator=(MemoryAccessor &&origin)=delete
Move-assignment operator (deleted).
A struct to store the information of a memory segment.
Definition segmentinfo.h:37