LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
LIEF::runtime::Memory::Chunk Class Reference

Represents a contiguous chunk of memory allocated or inspected by the runtime. More...

#include <Memory.hpp>

Public Member Functions

 Chunk (void *addr, size_t size, uint32_t permissions)
 Chunk (void *addr, size_t size)
 Chunk (void *addr)
void * addr_ptr ()
 Returns the start address of the memory chunk as an opaque pointer.
const void * addr_ptr () const
uintptr_t addr () const
 Returns the start address of the memory chunk.
size_t size () const
 Returns the size of the memory chunk in bytes.
uint32_t permissions () const
 Returns the current permissions of the memory chunk.
uintptr_t page_start () const
 Returns the address of the start of the page containing this chunk.
uintptr_t page_end () const
 Returns the address of the end of the page containing this chunk.
Chunkchange_permissions (uint32_t p)
 Changes the permissions of the memory chunk.
Chunkmake_x ()
 Sets the permissions to Execute only.
Chunkmake_rw ()
 Sets the permissions to Read and Write.
Chunkmake_rx ()
 Sets the permissions to Read and Execute.
Chunkmake_rwx ()
 Sets the permissions to Read, Write, and Execute.
Chunkmake_ro ()
 Sets the permissions to Read Only.
Chunkcache_flush ()
 Flushes the instruction cache for this memory chunk. This should be used when modifying code in memory (e.g., hooking, JIT).
bool is_valid () const
 Check if this chunk is valid.
 operator bool () const
ok_error_t deallocate ()
std::string to_string () const

Detailed Description

Represents a contiguous chunk of memory allocated or inspected by the runtime.

Constructor & Destructor Documentation

◆ Chunk() [1/3]

LIEF::runtime::Memory::Chunk::Chunk ( void * addr,
size_t size,
uint32_t permissions )
inline

◆ Chunk() [2/3]

LIEF::runtime::Memory::Chunk::Chunk ( void * addr,
size_t size )
inline

◆ Chunk() [3/3]

LIEF::runtime::Memory::Chunk::Chunk ( void * addr)
inline

Member Function Documentation

◆ addr()

uintptr_t LIEF::runtime::Memory::Chunk::addr ( ) const
inline

Returns the start address of the memory chunk.

Referenced by Chunk(), Chunk(), and Chunk().

◆ addr_ptr() [1/2]

void * LIEF::runtime::Memory::Chunk::addr_ptr ( )
inline

Returns the start address of the memory chunk as an opaque pointer.

◆ addr_ptr() [2/2]

const void * LIEF::runtime::Memory::Chunk::addr_ptr ( ) const
inline

◆ cache_flush()

Chunk & LIEF::runtime::Memory::Chunk::cache_flush ( )

Flushes the instruction cache for this memory chunk. This should be used when modifying code in memory (e.g., hooking, JIT).

References Chunk(), and LIEF_LIFETIMEBOUND.

◆ change_permissions()

Chunk & LIEF::runtime::Memory::Chunk::change_permissions ( uint32_t p)
inline

Changes the permissions of the memory chunk.

References Chunk(), LIEF::logging::err(), LIEF_LIFETIMEBOUND, LIEF::runtime::Memory::mprotect(), and to_string().

Referenced by make_ro(), make_rw(), make_rwx(), make_rx(), and make_x().

◆ deallocate()

ok_error_t LIEF::runtime::Memory::Chunk::deallocate ( )
inline

◆ is_valid()

bool LIEF::runtime::Memory::Chunk::is_valid ( ) const
inline

Check if this chunk is valid.

References is_valid().

Referenced by is_valid(), and operator bool().

◆ make_ro()

Chunk & LIEF::runtime::Memory::Chunk::make_ro ( )
inline

Sets the permissions to Read Only.

References change_permissions(), Chunk(), LIEF_LIFETIMEBOUND, and LIEF::runtime::Memory::P_READ.

◆ make_rw()

Chunk & LIEF::runtime::Memory::Chunk::make_rw ( )
inline

◆ make_rwx()

Chunk & LIEF::runtime::Memory::Chunk::make_rwx ( )
inline

◆ make_rx()

Chunk & LIEF::runtime::Memory::Chunk::make_rx ( )
inline

◆ make_x()

Chunk & LIEF::runtime::Memory::Chunk::make_x ( )
inline

Sets the permissions to Execute only.

References change_permissions(), Chunk(), LIEF_LIFETIMEBOUND, and LIEF::runtime::Memory::P_EXEC.

◆ operator bool()

LIEF::runtime::Memory::Chunk::operator bool ( ) const
inline

References is_valid().

◆ page_end()

uintptr_t LIEF::runtime::Memory::Chunk::page_end ( ) const

Returns the address of the end of the page containing this chunk.

◆ page_start()

uintptr_t LIEF::runtime::Memory::Chunk::page_start ( ) const

Returns the address of the start of the page containing this chunk.

◆ permissions()

uint32_t LIEF::runtime::Memory::Chunk::permissions ( ) const
inline

Returns the current permissions of the memory chunk.

Referenced by Chunk().

◆ size()

size_t LIEF::runtime::Memory::Chunk::size ( ) const
inline

Returns the size of the memory chunk in bytes.

Referenced by Chunk(), and Chunk().

◆ to_string()

std::string LIEF::runtime::Memory::Chunk::to_string ( ) const

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