plugify  1.0.0.0
mem_protector.hpp
1 #pragma once
2 
3 #include <plugify/mem_addr.hpp>
4 #include <plugify/prot_flag.hpp>
5 #include <plugify_export.h>
6 
7 namespace plugify {
8  class MemAccessor;
17  class PLUGIFY_API MemProtector {
18  public:
19  MemProtector() = delete;
29  MemProtector(MemAddr address, size_t length, ProtFlag prot, bool unsetOnDestroy = true);
30 
35 
41  ProtFlag OriginalProt() const noexcept { return _origProtection; }
42 
48  bool IsValid() const noexcept { return _status; }
49 
50  private:
51  void* _address;
52  size_t _length;
53  bool _status;
54  bool _unsetLater;
56  ProtFlag _origProtection{ ProtFlag::UNSET };
57  };
58 
65  int TranslateProtection(ProtFlag flags) noexcept;
66 
73  ProtFlag TranslateProtection(int prot) noexcept;
74 
75 } // namespace plugify
A wrapper class for memory addresses, providing utility functions for pointer manipulation.
Definition: mem_addr.hpp:11
A class to manage memory protection settings.
~MemProtector()
Destructor to restore the original protection settings if required.
ProtFlag OriginalProt() const noexcept
Gets the original protection settings.
bool IsValid() const noexcept
Checks if the memory protection was successfully set.
MemProtector(MemAddr address, size_t length, ProtFlag prot, bool unsetOnDestroy=true)
Constructs a MemProtector object to set memory protection.