Data Structures | Functions | Variables
bfn Namespace Reference

Data Structures

class  corrupt_vmm_error
 
class  driver_inaccessible_error
 
class  general_exception
 
class  invalid_file_error
 
class  invalid_vmm_state_error
 
class  ioctl_failed_error
 
class  missing_argument_error
 
class  unique_map_ptr_x64
 
class  unknown_command_error
 
class  unknown_status_error
 
class  unknown_vmcall_data_type_error
 
class  unknown_vmcall_string_type_error
 
class  unknown_vmcall_type_error
 

Functions

template<class T >
auto make_unique_map_x64 (typename unique_map_ptr_x64< T >::pointer phys, x64::memory_attr::attr_type attr=x64::memory_attr::rw_wb)
 
template<class T >
auto make_unique_map_x64 (typename unique_map_ptr_x64< T >::integer_pointer phys, x64::memory_attr::attr_type attr=x64::memory_attr::rw_wb)
 
template<class T >
auto make_unique_map_x64 (const std::vector< std::pair< typename unique_map_ptr_x64< T >::integer_pointer, typename unique_map_ptr_x64< T >::size_type >> &list, x64::memory_attr::attr_type attr=x64::memory_attr::rw_wb)
 
template<class T >
auto make_unique_map_x64 (typename unique_map_ptr_x64< T >::integer_pointer virt, typename unique_map_ptr_x64< T >::integer_pointer cr3, typename unique_map_ptr_x64< T >::size_type size, x64::msrs::value_type pat)
 
uintptr_t virt_to_phys_with_cr3 (uintptr_t virt, uintptr_t cr3)
 
void map_with_cr3 (uintptr_t vmap, uintptr_t virt, uintptr_t cr3, size_t size, x64::msrs::value_type pat)
 
template<class T >
void swap (unique_map_ptr_x64< T > &x, unique_map_ptr_x64< T > &y) noexcept
 
template<class T1 , class T2 >
bool operator== (const unique_map_ptr_x64< T1 > &x, const unique_map_ptr_x64< T2 > &y)
 
template<class T1 , class T2 >
bool operator!= (const unique_map_ptr_x64< T1 > &x, const unique_map_ptr_x64< T2 > &y)
 
template<class T1 , class T2 >
bool operator< (const unique_map_ptr_x64< T1 > &x, const unique_map_ptr_x64< T2 > &y)
 
template<class T1 , class T2 >
bool operator<= (const unique_map_ptr_x64< T1 > &x, const unique_map_ptr_x64< T2 > &y)
 
template<class T1 , class T2 >
bool operator> (const unique_map_ptr_x64< T1 > &x, const unique_map_ptr_x64< T2 > &y)
 
template<class T1 , class T2 >
bool operator>= (const unique_map_ptr_x64< T1 > &x, const unique_map_ptr_x64< T2 > &y)
 
template<class T >
bool operator== (const unique_map_ptr_x64< T > &x, std::nullptr_t dontcare) noexcept
 
template<class T >
bool operator== (std::nullptr_t dontcare, const unique_map_ptr_x64< T > &y) noexcept
 
template<class T >
bool operator!= (const unique_map_ptr_x64< T > &x, std::nullptr_t dontcare) noexcept
 
template<class T >
bool operator!= (std::nullptr_t dontcare, const unique_map_ptr_x64< T > &y) noexcept
 
void __attribute__ ((weak)) map_with_cr3(uintptr_t vmap
 
 expects (lower(vmap)==0)
 
 expects (virt !=0)
 
 expects (cr3 !=0)
 
 expects (lower(cr3)==0)
 
 expects (size !=0)
 
 for (auto offset=0UL;offset< size;offset+=x64::page_size)
 
template<class T , class = typename std::enable_if<std::is_integral<T>::value>::type>
std::string to_string (const T val, const int base)
 
template<class T >
auto mock_no_delete (MockRepository &mocks)
 
template<class T >
auto mock_shared (MockRepository &mocks)
 
template<class T >
auto mock_unique (MockRepository &mocks)
 
template<class T >
auto lower (T ptr) noexcept
 
template<class T >
auto lower (T ptr, uintptr_t from) noexcept
 
template<class T >
auto upper (T ptr) noexcept
 
template<class T >
auto upper (T ptr, uintptr_t from) noexcept
 

Variables

void uintptr_t virt
 
void uintptr_t uintptr_t cr3
 
void uintptr_t uintptr_t size_t size
 
void uintptr_t uintptr_t size_t x64::msrs::value_type pat
 

Function Documentation

◆ make_unique_map_x64() [1/4]

template<class T >
auto bfn::make_unique_map_x64 ( typename unique_map_ptr_x64< T >::pointer  phys,
x64::memory_attr::attr_type  attr = x64::memory_attr::rw_wb 
)

Make Unique Map (Single Page)

This function can be used to map a single virtual memory page to a single physical memory page.

Example:

std::cout << bfn::make_unique_map_x64<char>(phys) << '\n';
Precondition
expects: phys != nullptr
expects: attr != map_none
Postcondition
ensures: ret.get() != nullptr
Parameters
physthe physical address to map
attrdefines how to map the memory. Defaults to map_read_write
Returns
resulting unique_map_ptr_x64

Definition at line 75 of file map_ptr_x64.h.

◆ make_unique_map_x64() [2/4]

template<class T >
auto bfn::make_unique_map_x64 ( typename unique_map_ptr_x64< T >::integer_pointer  phys,
x64::memory_attr::attr_type  attr = x64::memory_attr::rw_wb 
)

Make Unique Map (Single Page)

This function can be used to map a single virtual memory page to a single physical memory page.

Example:

std::cout << bfn::make_unique_map_x64<char>(phys) << '\n';
Precondition
expects: phys != 0
expects: attr != map_none
Postcondition
ensures: ret.get() != nullptr
Parameters
physthe physical address to map
attrdefines how to map the memory. Defaults to map_read_write
Returns
resulting unique_map_ptr_x64

Definition at line 112 of file map_ptr_x64.h.

◆ make_unique_map_x64() [3/4]

template<class T >
auto bfn::make_unique_map_x64 ( const std::vector< std::pair< typename unique_map_ptr_x64< T >::integer_pointer, typename unique_map_ptr_x64< T >::size_type >> &  list,
x64::memory_attr::attr_type  attr = x64::memory_attr::rw_wb 
)

Make Unique Map (Physically Contiguous / Non-Contiguous Range)

This function can be used to map both physically contiguous, and physically non-contiguous memory by providing a list of physical pages to map. The list consists of std::pairs, each containing a physical address, and a size. A physically contiguous memory range would consist of a list of one std::pair contains the physical address and it's size. A physically non-contiguous range would consist of a list of each page range that makes up the memory to be mapped (similar to a Windows MDL). In either case the total number of bytes mapped is equal to the total of each size field in each std::pair in the list provided.

Example:

auto phys_range_1 = std::make_pair(phys1, size1);
auto phys_range_2 = std::make_pair(phys2, size2);
auto phys_range_3 = std::make_pair(phys3, size3);
auto list = {phys_range_1, phys_range_2, phys_range_3};
std::cout << bfn::make_unique_map_x64<char>(list) << '\n';
Precondition
expects: list.empty() == false
expects: list.at(i).first != 0
expects: list.at(i).second != 0
expects: list.at(i).second & (x64::page_size - 1) == 0
expects: attr != map_none
Postcondition
ensures: ret.get() != nullptr
Parameters
listlist of std::pairs, each containing a physical address and a size, defining a physical address range to add to the virtual address mapping
attrdefines how to map the memory. Defaults to map_read_write
Returns
resulting unique_map_ptr_x64

Definition at line 168 of file map_ptr_x64.h.

◆ make_unique_map_x64() [4/4]

template<class T >
auto bfn::make_unique_map_x64 ( typename unique_map_ptr_x64< T >::integer_pointer  virt,
typename unique_map_ptr_x64< T >::integer_pointer  cr3,
typename unique_map_ptr_x64< T >::size_type  size,
x64::msrs::value_type  pat 
)

Make Unique Map (Physically Contiguous / Non-Contiguous Range With CR3)

This function can be used to map both physically contiguous, and physically non-contiguous memory by providing an existing virtually contiguous memory range address and size, as well as the CR3 value that defines the existing virtual to physical memory mappings. This is useful when mapping guest memory into VMM, and caution should be taken if mapping executable memory.

Note
since this function must map in the guest's page tables to locate each physical address for each page being mapped, this function is very expensive, and should not be used in time critical operations.

Example:

std::cout << bfn::make_unique_map_x64<char>(virt, vmcs::guest_cr3::get(), size) << '\n';
Precondition
expects: virt != 0
expects: cr3 != 0
expects: size != 0
Postcondition
ensures: get() != nullptr
Parameters
virtthe virtual address containing the existing mapping
cr3the root page table containing the existing virtual to physical memory mappings
sizethe number of bytes to map
patthe pat msr associated with the provided cr3
Returns
resulting unique_map_ptr_x64

Definition at line 222 of file map_ptr_x64.h.

◆ virt_to_phys_with_cr3()

uintptr_t bfn::virt_to_phys_with_cr3 ( uintptr_t  virt,
uintptr_t  cr3 
)
inline

Virt to Phys with CR3

Converts a virtual address to a physical address given the CR3 to locate the physical address from. Note that this function has to map / unmap the page table tree as it traverses the tree to locate the physical address. As a result, this is an expensive operation and should not be used in time sensitive operations.

Note
the provided virtual address should be present prior to running this function.
Precondition
expects: virt != 0
expects: cr3 != 0
Postcondition
ensures: none
Parameters
virtvirtual address to convert
cr3the CR3 to lookup the physical address from. The virtual address should originate from this CR3, otherwise the resulting physical address could be incorrect, or an exception could be thrown.
Returns
returns the physical address mapped to the provided virtual address located in the provided CR3

Definition at line 919 of file map_ptr_x64.h.

◆ map_with_cr3()

void bfn::map_with_cr3 ( uintptr_t  vmap,
uintptr_t  virt,
uintptr_t  cr3,
size_t  size,
x64::msrs::value_type  pat 
)

Map Physically Contiguous / Non-Contiguous Range With CR3

This function can be used to map both physically contiguous, and physically non-contiguous memory by providing an existing virtually contiguous memory range address and size, as well as the CR3 value that defines the existing virtual to physical memory mappings. This is useful when mapping guest memory into VMM, and caution should be taken if mapping executable memory.

Note
since this function must map in the guest's page tables to locate each physical address for each page being mapped, this function is very expensive, and should not be used in time critical operations.
this function should not be used directly, but instead the unique_map_ptr_x64 version should be used instead. This function can however be overloaded to provide custom functionality for mapping guest memory into the VMM.
Precondition
expects: vmap != 0
expects: vmap & (x64::page_size - 1) == 0
expects: virt != 0
expects: cr3 != 0
expects: cr3 & (x64::page_size - 1) == 0
expects: size != 0
expects: attr != 0
Postcondition
ensures: get() != nullptr
Parameters
vmapthe virtual address to map the range to
virtthe virtual address containing the existing mapping
cr3the root page table containing the existing virtual to physical memory mappings
sizethe number of bytes to map
patthe pat msr associated with the provided cr3

◆ swap()

template<class T >
void bfn::swap ( unique_map_ptr_x64< T > &  x,
unique_map_ptr_x64< T > &  y 
)
noexcept

Definition at line 876 of file map_ptr_x64.h.

◆ operator==() [1/3]

template<class T1 , class T2 >
bool bfn::operator== ( const unique_map_ptr_x64< T1 > &  x,
const unique_map_ptr_x64< T2 > &  y 
)

Definition at line 880 of file map_ptr_x64.h.

◆ operator!=() [1/3]

template<class T1 , class T2 >
bool bfn::operator!= ( const unique_map_ptr_x64< T1 > &  x,
const unique_map_ptr_x64< T2 > &  y 
)

Definition at line 884 of file map_ptr_x64.h.

◆ operator<()

template<class T1 , class T2 >
bool bfn::operator< ( const unique_map_ptr_x64< T1 > &  x,
const unique_map_ptr_x64< T2 > &  y 
)

Definition at line 888 of file map_ptr_x64.h.

◆ operator<=()

template<class T1 , class T2 >
bool bfn::operator<= ( const unique_map_ptr_x64< T1 > &  x,
const unique_map_ptr_x64< T2 > &  y 
)

Definition at line 892 of file map_ptr_x64.h.

◆ operator>()

template<class T1 , class T2 >
bool bfn::operator> ( const unique_map_ptr_x64< T1 > &  x,
const unique_map_ptr_x64< T2 > &  y 
)

Definition at line 896 of file map_ptr_x64.h.

◆ operator>=()

template<class T1 , class T2 >
bool bfn::operator>= ( const unique_map_ptr_x64< T1 > &  x,
const unique_map_ptr_x64< T2 > &  y 
)

Definition at line 900 of file map_ptr_x64.h.

◆ operator==() [2/3]

template<class T >
bool bfn::operator== ( const unique_map_ptr_x64< T > &  x,
std::nullptr_t  dontcare 
)
noexcept

Definition at line 904 of file map_ptr_x64.h.

◆ operator==() [3/3]

template<class T >
bool bfn::operator== ( std::nullptr_t  dontcare,
const unique_map_ptr_x64< T > &  y 
)
noexcept

Definition at line 908 of file map_ptr_x64.h.

◆ operator!=() [2/3]

template<class T >
bool bfn::operator!= ( const unique_map_ptr_x64< T > &  x,
std::nullptr_t  dontcare 
)
noexcept

Definition at line 912 of file map_ptr_x64.h.

◆ operator!=() [3/3]

template<class T >
bool bfn::operator!= ( std::nullptr_t  dontcare,
const unique_map_ptr_x64< T > &  y 
)
noexcept

Definition at line 916 of file map_ptr_x64.h.

◆ __attribute__()

void bfn::__attribute__ ( (weak)  )

◆ expects() [1/5]

bfn::expects ( lower(vmap)  = =0)

◆ expects() [2/5]

bfn::expects ( virt = 0)

◆ expects() [3/5]

bfn::expects ( cr3 = 0)

◆ expects() [4/5]

bfn::expects ( lower(cr3 = =0)

◆ expects() [5/5]

bfn::expects ( size = 0)

◆ for()

bfn::for ( )

Definition at line 45 of file map_ptr_x64.cpp.

◆ to_string()

template<class T , class = typename std::enable_if<std::is_integral<T>::value>::type>
std::string bfn::to_string ( const T  val,
const int  base 
)

Get a std::string representation of an interger

Parameters
valInteger to get a std::string representation of
baseThe base to format the std::string representation
Note
Only bases 8, 16 and 10 are supported

Definition at line 42 of file to_string.h.

◆ mock_no_delete()

template<class T >
auto bfn::mock_no_delete ( MockRepository &  mocks)

Mock No Delete

If the destructor of the class is called, this function prevents a crash by registering a call to the destructor to do nothing.

MockRepository mocks;
auto f = bfn::mock_no_delete<foo>(mocks);

Definition at line 272 of file unittest.h.

◆ mock_shared()

template<class T >
auto bfn::mock_shared ( MockRepository &  mocks)

Mock Shared

Use this function to create a mocked version of a shared pointer.

MockRepository mocks;
auto f = bfn::mock_shared<foo>(mocks);

Definition at line 290 of file unittest.h.

◆ mock_unique()

template<class T >
auto bfn::mock_unique ( MockRepository &  mocks)

Mock Unique

Use this function to create a mocked version of a unique pointer.

MockRepository mocks;
auto f = bfn::mock_unique<foo>(mocks);

Definition at line 303 of file unittest.h.

◆ lower() [1/2]

template<class T >
auto bfn::lower ( ptr)
noexcept

Lower

Parameters
ptrthe pointer to mask
Returns
the lower 12 bits of ptr

Definition at line 36 of file upper_lower.h.

◆ lower() [2/2]

template<class T >
auto bfn::lower ( ptr,
uintptr_t  from 
)
noexcept

Lower

Parameters
ptrthe pointer to mask
fromthe number of bits to mask
Returns
the lower "from" bits of ptr

Definition at line 46 of file upper_lower.h.

◆ upper() [1/2]

template<class T >
auto bfn::upper ( ptr)
noexcept

Upper

Parameters
ptrthe pointer to mask
Returns
the upper 12 bits of ptr

Definition at line 55 of file upper_lower.h.

◆ upper() [2/2]

template<class T >
auto bfn::upper ( ptr,
uintptr_t  from 
)
noexcept

Upper

Parameters
ptrthe pointer to mask
fromthe number of bits to mask
Returns
the upper "from" bits of ptr

Definition at line 65 of file upper_lower.h.

Variable Documentation

◆ virt

void uintptr_t bfn::virt

Definition at line 33 of file map_ptr_x64.cpp.

◆ cr3

void uintptr_t uintptr_t bfn::cr3

Definition at line 33 of file map_ptr_x64.cpp.

◆ size

void uintptr_t uintptr_t size_t bfn::size

Definition at line 33 of file map_ptr_x64.cpp.

◆ pat

void uintptr_t uintptr_t size_t x64::msrs::value_type bfn::pat
Initial value:
{
expects(vmap != 0)
expects(size !=0)

Definition at line 37 of file map_ptr_x64.cpp.