22
33#include " platform_types.h"
44#include " utils.h"
5+ #include " protect.h"
56#include < cstdint>
67#include < expected>
78#include < filesystem>
@@ -18,38 +19,10 @@ class Pointer;
1819class Module ;
1920struct Thread ;
2021class Process ;
21-
22- using Allocator = struct ProcessAllocator {
23- explicit ProcessAllocator (std::shared_ptr<Process> proc);
24-
25- std::optional<Pointer> allocate (size_t size, void *nearAddr = nullptr );
26-
27- void deallocate (Pointer addr);
28-
29- private:
30- struct AllocatedPageData {
31- size_t size;
32- std::map<void *, size_t > allocated;
33- };
34- std::map<void *, AllocatedPageData> allocatedPages;
35- std::shared_ptr<Process> proc;
36- };
22+ class ProcessAllocator ;
3723
3824class Process : public std ::enable_shared_from_this<Process> {
3925public:
40- enum class MemoryProtection {
41- None = 0 ,
42- Read = 0x0001 ,
43- Write = 0x0010 ,
44- Execute = 0x0100 ,
45- ReadWrite = Read | Write,
46- ReadWriteExecute = Read | Write | Execute,
47- ReadExecute = Read | Execute,
48- rw = ReadWrite,
49- rwx = ReadWriteExecute,
50- rx = ReadExecute
51- };
52-
5326#ifdef _WIN32
5427
5528 explicit Process (HANDLE h);
@@ -64,9 +37,10 @@ class Process : public std::enable_shared_from_this<Process> {
6437 WIN_ONLY (HANDLE h = nullptr );
6538 friend Module;
6639 friend Pointer;
40+ friend ProcessAllocator;
6741
6842 std::shared_ptr<Pointer> _memo_ptr;
69- std::shared_ptr<struct ProcessAllocator > _allocator_ptr;
43+ std::shared_ptr<ProcessAllocator> _allocator_ptr;
7044
7145public:
7246 CLASS_MOVE_ONLY (Process)
@@ -91,23 +65,23 @@ class Process : public std::enable_shared_from_this<Process> {
9165 size_t size) const ;
9266 bool check_writable (void *addr, size_t size) const ;
9367
94- std::expected<MemoryProtection , std::string>
68+ std::expected<Protect , std::string>
9569 try_set_memory_protect (void *addr, size_t size,
96- MemoryProtection protect) const ;
97- MemoryProtection set_memory_protect (void *addr, size_t size,
98- MemoryProtection protect) const ;
70+ Protect protect) const ;
71+ Protect set_memory_protect (void *addr, size_t size,
72+ Protect protect) const ;
9973
10074 std::expected<bool , std::string> try_check_valid (void *addr) const ;
10175 bool check_valid (void *addr) const ;
10276
103- std::expected<void * , std::string>
104- try_malloc (size_t size, MemoryProtection protect = MemoryProtection ::rw,
105- void *nearAddr = nullptr ) const ;
106- void * malloc (size_t size, MemoryProtection protect = MemoryProtection ::rw,
107- void *nearAddr = nullptr ) const ;
77+ std::expected<Pointer , std::string>
78+ try_malloc (size_t size, Protect protect = Protect ::rw,
79+ void *nearAddr = nullptr );
80+ Pointer malloc (size_t size, Protect protect = Protect ::rw,
81+ void *nearAddr = nullptr );
10882
109- std::expected<void , std::string> try_free (void *addr, size_t size = 0 ) const ;
110- void free (void *addr, size_t size = 0 ) const ;
83+ std::expected<void , std::string> try_free (void *addr, size_t size = 0 );
84+ void free (void *addr, size_t size = 0 );
11185
11286 [[nodiscard]] std::optional<std::shared_ptr<Module>>
11387 module (const std::string &name);
@@ -126,7 +100,7 @@ class Process : public std::enable_shared_from_this<Process> {
126100
127101 Pointer memo ();
128102
129- struct ProcessAllocator & allocator ();
103+ ProcessAllocator& allocator ();
130104
131105 std::vector<Thread> threads ();
132106
0 commit comments