3 #include "../Include/Winheaders.h"
4 #include "../Include/Macro.h"
5 #include "../Include/Types.h"
20 inline DWORD CastProtection( DWORD prot,
bool bDEP )
28 if (prot == PAGE_EXECUTE_READ)
30 else if (prot == PAGE_EXECUTE_READWRITE)
31 return PAGE_READWRITE;
32 else if (prot == PAGE_EXECUTE_WRITECOPY)
33 return PAGE_WRITECOPY;
51 BLACKBONE_API MemBlock(
class ProcessMemory* mem, ptr_t
ptr,
bool own =
true );
62 size_t size, DWORD prot,
bool own =
true,
63 bool physical =
false );
65 BLACKBONE_API ~MemBlock();
84 BLACKBONE_API ptr_t
Realloc(
size_t size, ptr_t desired = 0, DWORD
protection = PAGE_EXECUTE_READWRITE );
94 BLACKBONE_API NTSTATUS
Protect( DWORD
protection,
size_t offset = 0,
size_t size = 0, DWORD* pOld =
nullptr );
100 BLACKBONE_API NTSTATUS
Free(
size_t size = 0 );
113 BLACKBONE_API NTSTATUS
Read(
size_t offset,
size_t size, PVOID pResult,
bool handleHoles =
false );
122 BLACKBONE_API NTSTATUS
Write(
size_t offset,
size_t size,
const void* pData );
131 T
Read(
size_t offset,
const T& def_val )
134 Read( offset,
sizeof(T), &res );
145 NTSTATUS
Write(
size_t offset,
const T& data )
147 return Write( offset,
sizeof(T), &data );
153 BLACKBONE_API
void Reset();
158 BLACKBONE_API
inline void Release() { _own =
false; }
164 template<
typename T = ptr_t >
165 inline T
ptr()
const {
return (T)_ptr; }
171 BLACKBONE_API
inline size_t size()
const {
return _size; }
177 BLACKBONE_API
inline DWORD
protection()
const {
return _protection; }
182 BLACKBONE_API
inline bool valid()
const {
return (_memory !=
nullptr && _ptr != 0); }
188 BLACKBONE_API
inline operator ptr_t()
const {
return _ptr; }
190 BLACKBONE_API MemBlock& operator =(
const MemBlock& other)
192 _memory = other._memory;
195 _protection = other._protection;
199 const_cast<MemBlock&
>(other).
Release();
207 DWORD _protection = 0;
209 bool _physical =
false;
210 class ProcessMemory* _memory;
BLACKBONE_API NTSTATUS Free(size_t size=0)
Free memory
Definition: MemBlock.cpp:140
T ptr() const
Get memory pointer
Definition: MemBlock.h:165
Definition: ProcessMemory.h:13
BLACKBONE_API NTSTATUS Read(size_t offset, size_t size, PVOID pResult, bool handleHoles=false)
Read data
Definition: MemBlock.cpp:178
BLACKBONE_API NTSTATUS Protect(DWORD protection, size_t offset=0, size_t size=0, DWORD *pOld=nullptr)
Change memory protection
Definition: MemBlock.cpp:125
BLACKBONE_API NTSTATUS Write(size_t offset, size_t size, const void *pData)
Write data
Definition: MemBlock.cpp:191
T Read(size_t offset, const T &def_val)
Read data
Definition: MemBlock.h:131
NTSTATUS Write(size_t offset, const T &data)
Write data
Definition: MemBlock.h:145
static BLACKBONE_API MemBlock Allocate(class ProcessMemory &process, size_t size, ptr_t desired=0, DWORD protection=PAGE_EXECUTE_READWRITE)
Allocate new memory block
Definition: MemBlock.cpp:66
BLACKBONE_API void Release()
Memory will not be deallocated upon object destruction
Definition: MemBlock.h:158
BLACKBONE_API DWORD protection() const
Get block memory protection
Definition: MemBlock.h:177
Definition: MemBlock.h:39
BLACKBONE_API ptr_t Realloc(size_t size, ptr_t desired=0, DWORD protection=PAGE_EXECUTE_READWRITE)
Reallocate existing block for new size
Definition: MemBlock.cpp:90
Definition: AsmHelper32.cpp:6
BLACKBONE_API bool valid() const
Validate memory block true if memory pointer isn't 0
Definition: MemBlock.h:182
BLACKBONE_API size_t size() const
Get block size
Definition: MemBlock.h:171
BLACKBONE_API void Reset()
Try to free memory and reset pointers
Definition: MemBlock.cpp:199