BlackBone
Windows memory hacking library
 All Classes Functions
blackbone::MemBlock Class Reference

Public Member Functions

BLACKBONE_API MemBlock (class ProcessMemory *mem, ptr_t ptr, bool own=true)
 MemBlock ctor More...
 
BLACKBONE_API MemBlock (class ProcessMemory *mem, ptr_t ptr, size_t size, DWORD prot, bool own=true, bool physical=false)
 MemBlock ctor More...
 
BLACKBONE_API ptr_t Realloc (size_t size, ptr_t desired=0, DWORD protection=PAGE_EXECUTE_READWRITE)
 Reallocate existing block for new size More...
 
BLACKBONE_API NTSTATUS Protect (DWORD protection, size_t offset=0, size_t size=0, DWORD *pOld=nullptr)
 Change memory protection More...
 
BLACKBONE_API NTSTATUS Free (size_t size=0)
 Free memory More...
 
BLACKBONE_API NTSTATUS Read (size_t offset, size_t size, PVOID pResult, bool handleHoles=false)
 Read data More...
 
BLACKBONE_API NTSTATUS Write (size_t offset, size_t size, const void *pData)
 Write data More...
 
template<class T >
Read (size_t offset, const T &def_val)
 Read data More...
 
template<class T >
NTSTATUS Write (size_t offset, const T &data)
 Write data More...
 
BLACKBONE_API void Reset ()
 Try to free memory and reset pointers More...
 
BLACKBONE_API void Release ()
 Memory will not be deallocated upon object destruction More...
 
template<typename T = ptr_t>
ptr () const
 Get memory pointer More...
 
BLACKBONE_API size_t size () const
 Get block size More...
 
BLACKBONE_API DWORD protection () const
 Get block memory protection More...
 
BLACKBONE_API bool valid () const
 Validate memory block

Returns
true if memory pointer isn't 0

 
BLACKBONE_API operator ptr_t () const
 Get memory pointer More...
 
BLACKBONE_API MemBlockoperator= (const MemBlock &other)
 

Static Public Member Functions

static BLACKBONE_API MemBlock Allocate (class ProcessMemory &process, size_t size, ptr_t desired=0, DWORD protection=PAGE_EXECUTE_READWRITE)
 Allocate new memory block More...
 

Constructor & Destructor Documentation

blackbone::MemBlock::MemBlock ( class ProcessMemory mem,
ptr_t  ptr,
bool  own = true 
)

MemBlock ctor

Parameters
memProcess memory routines
ptrMemory address
owntrue if caller will be responsible for block deallocation
blackbone::MemBlock::MemBlock ( class ProcessMemory mem,
ptr_t  ptr,
size_t  size,
DWORD  prot,
bool  own = true,
bool  physical = false 
)

MemBlock ctor

Parameters
memProcess memory routines
ptrMemory address
sizeBlock size
protMemory protection
owntrue if caller will be responsible for block deallocation

Member Function Documentation

MemBlock blackbone::MemBlock::Allocate ( class ProcessMemory process,
size_t  size,
ptr_t  desired = 0,
DWORD  protection = PAGE_EXECUTE_READWRITE 
)
static

Allocate new memory block

Parameters
processProcess memory routines
sizeBlock size
desiredDesired base address of new block
protectionWin32 Memory protection flags
Returns
Memory block. If failed - returned block will be invalid
Parameters
processProcess memory routines
sizeBlock size
desiredDesired base address of new block
protectionMemory protection
Returns
Memory block. If failed - returned block will be invalid
NTSTATUS blackbone::MemBlock::Free ( size_t  size = 0)

Free memory

Parameters
sizeSize of memory chunk to free. If 0 - whole block is freed
BLACKBONE_API blackbone::MemBlock::operator ptr_t ( ) const
inline

Get memory pointer

Returns
Memory pointer
NTSTATUS blackbone::MemBlock::Protect ( DWORD  protection,
size_t  offset = 0,
size_t  size = 0,
DWORD *  pOld = nullptr 
)

Change memory protection

Parameters
protectionNew protection flags
offsetMemory offset in block
sizeBlock size
pOldOld protection flags
Returns
Status
BLACKBONE_API DWORD blackbone::MemBlock::protection ( ) const
inline

Get block memory protection

Returns
Memory protection flags
template<typename T = ptr_t>
T blackbone::MemBlock::ptr ( ) const
inline

Get memory pointer

Returns
Memory pointer
NTSTATUS blackbone::MemBlock::Read ( size_t  offset,
size_t  size,
PVOID  pResult,
bool  handleHoles = false 
)

Read data

Parameters
offsetData offset in block
sizeSize of data to read
pResultOutput buffer
handleHolesIf true, function will try to read all committed pages in range ignoring uncommitted. Otherwise function will fail if there is at least one non-committed page in region.
Returns
Status
template<class T >
T blackbone::MemBlock::Read ( size_t  offset,
const T &  def_val 
)
inline

Read data

Parameters
offsetData offset in block
def_valDefult return value if read has failed
Returns
Read data
ptr_t blackbone::MemBlock::Realloc ( size_t  size,
ptr_t  desired = 0,
DWORD  protection = PAGE_EXECUTE_READWRITE 
)

Reallocate existing block for new size

Parameters
sizeNew block size
desiredDesired base address of new block
protectionMemory protection
Returns
New block address
BLACKBONE_API void blackbone::MemBlock::Release ( )
inline

Memory will not be deallocated upon object destruction

void blackbone::MemBlock::Reset ( )

Try to free memory and reset pointers

BLACKBONE_API size_t blackbone::MemBlock::size ( ) const
inline

Get block size

Returns
Block size
NTSTATUS blackbone::MemBlock::Write ( size_t  offset,
size_t  size,
const void *  pData 
)

Write data

Parameters
offsetData offset in block
sizeSize of data to write
pDataBuffer to write
Returns
Status
template<class T >
NTSTATUS blackbone::MemBlock::Write ( size_t  offset,
const T &  data 
)
inline

Write data

Parameters
offsetOffset in block
dataData to write
Returns
Status

The documentation for this class was generated from the following files: