Arion 1.0.2-alpha
A high-performance C++ framework for emulating executable binaries.
 
Loading...
Searching...
No Matches
arion_poly_struct::PolymorphicStructFactory< T > Class Template Reference

#include <struct_utils.hpp>

Public Member Functions

size_t get_struct_sz (arion::CPU_ARCH arch)
 
size_t get_host_struct_sz ()
 
STRUCT_ID feed (arion::CPU_ARCH arch, arion::BYTE *struct_inst)
 
STRUCT_ID feed_host (T *struct_inst)
 
arion::BYTEbuild (STRUCT_ID id, arion::CPU_ARCH arch, size_t &struct_len)
 
T * build_host (STRUCT_ID id)
 
std::string to_string (STRUCT_ID id, std::shared_ptr< arion::Arion > arion, arion::CPU_ARCH arch)
 
void release_struct (STRUCT_ID id)
 
void clear_structs ()
 

Protected Types

using ftype = arion_poly_struct::POLYMORPHIC_STRUCT_FIELD_TYPE
 Macro for easy access to POLYMORPHIC_STRUCT_FIELD_TYPE in subclass definitions.
 

Protected Member Functions

 PolymorphicStructFactory (std::vector< POLYMORPHIC_STRUCT_FIELD > fields)
 
 ~PolymorphicStructFactory ()
 

Private Member Functions

STRUCT_ID gen_next_id ()
 
STRUCT_ID add_struct_entry (std::unique_ptr< PolymorphicStruct > struct_inst)
 
uint8_t get_align (arion::CPU_ARCH arch)
 
uint8_t get_ptr_sz (arion::CPU_ARCH arch)
 
uint16_t get_arch_sz (arion::CPU_ARCH arch)
 

Private Attributes

STRUCT_ID curr_id = 1
 Counter for generating unique structure IDs.
 
std::stack< STRUCT_IDfree_ids
 Stack of released IDs for reuse.
 
std::map< STRUCT_ID, std::unique_ptr< PolymorphicStruct > > curr_structs
 Map of currently allocated polymorphic structure instances.
 
std::vector< POLYMORPHIC_STRUCT_FIELDfields
 Definition of all potential fields in the polymorphic structure.
 

Detailed Description

template<typename T>
class arion_poly_struct::PolymorphicStructFactory< T >

Manages the definition and instantiation of polymorphic structures (structs whose layout changes per architecture).

Template Parameters
TThe host-side C++ type corresponding to the structure being managed.

Member Typedef Documentation

◆ ftype

Macro for easy access to POLYMORPHIC_STRUCT_FIELD_TYPE in subclass definitions.

Constructor & Destructor Documentation

◆ PolymorphicStructFactory()

template<typename T >
arion_poly_struct::PolymorphicStructFactory< T >::PolymorphicStructFactory ( std::vector< POLYMORPHIC_STRUCT_FIELD fields)
inlineprotected

Builder for PolymorphicStructFactory instances.

Parameters
[in]fieldsThe vector of field definitions defining the structure layout.

◆ ~PolymorphicStructFactory()

template<typename T >
arion_poly_struct::PolymorphicStructFactory< T >::~PolymorphicStructFactory ( )
inlineprotected

Destructor: cleans up all currently managed structure instances.

Member Function Documentation

◆ add_struct_entry()

template<typename T >
STRUCT_ID arion_poly_struct::PolymorphicStructFactory< T >::add_struct_entry ( std::unique_ptr< PolymorphicStruct struct_inst)
inlineprivate

Allocates a new STRUCT_ID and stores the polymorphic instance.

Parameters
[in]struct_instUnique pointer to the PolymorphicStruct instance.
Returns
The assigned STRUCT_ID.

◆ build()

template<typename T >
arion::BYTE * arion_poly_struct::PolymorphicStructFactory< T >::build ( STRUCT_ID  id,
arion::CPU_ARCH  arch,
size_t &  struct_len 
)
inline

Builds the raw memory representation of a managed structure instance for a target architecture.

Parameters
[in]idThe ID of the managed structure instance.
[in]archThe target CPU architecture for layout.
[out]struct_lenThe size of the resulting raw data buffer.
Returns
A pointer to the dynamically allocated raw byte array representing the structure.

◆ build_host()

template<typename T >
T * arion_poly_struct::PolymorphicStructFactory< T >::build_host ( STRUCT_ID  id)
inline

Builds and returns a host-side C++ structure (T) instance from a managed instance.

Parameters
[in]idThe ID of the managed structure instance.
Returns
A pointer to the newly allocated host structure (T*).

◆ clear_structs()

template<typename T >
void arion_poly_struct::PolymorphicStructFactory< T >::clear_structs ( )
inline

Releases all currently managed structure instances.

◆ feed()

template<typename T >
STRUCT_ID arion_poly_struct::PolymorphicStructFactory< T >::feed ( arion::CPU_ARCH  arch,
arion::BYTE struct_inst 
)
inline

Parses raw memory data representing a structure instance and creates a corresponding PolymorphicStruct object.

Parameters
[in]archThe architecture used to interpret the structure layout (size, alignment).
[in]struct_instPointer to the raw byte data of the structure.
Returns
The unique ID of the newly created PolymorphicStruct instance.

◆ feed_host()

template<typename T >
STRUCT_ID arion_poly_struct::PolymorphicStructFactory< T >::feed_host ( T *  struct_inst)
inline

Feeds an existing host-side structure instance to the factory and gets its STRUCT_ID.

Parameters
[in]struct_instPointer to the host structure instance.
Returns
The unique ID of the newly created PolymorphicStruct instance.

◆ gen_next_id()

template<typename T >
STRUCT_ID arion_poly_struct::PolymorphicStructFactory< T >::gen_next_id ( )
inlineprivate

Generates a new unique STRUCT_ID.

Returns
The next available STRUCT_ID.

◆ get_align()

template<typename T >
uint8_t arion_poly_struct::PolymorphicStructFactory< T >::get_align ( arion::CPU_ARCH  arch)
inlineprivate

Retrieves the required memory alignment for the given architecture.

Parameters
[in]archThe CPU architecture.
Returns
The alignment size in bytes.

◆ get_arch_sz()

template<typename T >
uint16_t arion_poly_struct::PolymorphicStructFactory< T >::get_arch_sz ( arion::CPU_ARCH  arch)
inlineprivate

Retrieves the bit size (32 or 64) for the given architecture.

Parameters
[in]archThe CPU architecture.
Returns
The architecture size in bits.

◆ get_host_struct_sz()

template<typename T >
size_t arion_poly_struct::PolymorphicStructFactory< T >::get_host_struct_sz ( )
inline

Calculates the memory size of the structure instance for the host architecture.

Returns
The calculated size of the structure in bytes.

◆ get_ptr_sz()

template<typename T >
uint8_t arion_poly_struct::PolymorphicStructFactory< T >::get_ptr_sz ( arion::CPU_ARCH  arch)
inlineprivate

Retrieves the pointer size for the given architecture.

Parameters
[in]archThe CPU architecture.
Returns
The pointer size in bytes.

◆ get_struct_sz()

template<typename T >
size_t arion_poly_struct::PolymorphicStructFactory< T >::get_struct_sz ( arion::CPU_ARCH  arch)
inline

Calculates the memory size of the structure instance for a given target architecture, accounting for padding and alignment.

Parameters
[in]archThe target CPU architecture.
Returns
The calculated size of the structure in bytes.

◆ release_struct()

template<typename T >
void arion_poly_struct::PolymorphicStructFactory< T >::release_struct ( STRUCT_ID  id)
inline

Releases a managed structure instance, freeing its allocated resources and making its ID available for reuse.

Parameters
[in]idThe ID of the structure instance to release.

◆ to_string()

template<typename T >
std::string arion_poly_struct::PolymorphicStructFactory< T >::to_string ( STRUCT_ID  id,
std::shared_ptr< arion::Arion arion,
arion::CPU_ARCH  arch 
)
inline

Generates a string representation of the managed structure instance, formatting values using their KernelType.

Parameters
[in]idThe ID of the managed structure instance.
[in]arionShared pointer to the Arion instance (needed for memory access in some KernelType::str calls).
[in]archThe architecture to assume for pointer sizes and field interpretation.
Returns
A formatted string representation of the structure (e.g., "{field1=value, field2=value}").

Member Data Documentation

◆ curr_id

template<typename T >
STRUCT_ID arion_poly_struct::PolymorphicStructFactory< T >::curr_id = 1
private

Counter for generating unique structure IDs.

◆ curr_structs

template<typename T >
std::map<STRUCT_ID, std::unique_ptr<PolymorphicStruct> > arion_poly_struct::PolymorphicStructFactory< T >::curr_structs
private

Map of currently allocated polymorphic structure instances.

◆ fields

template<typename T >
std::vector<POLYMORPHIC_STRUCT_FIELD> arion_poly_struct::PolymorphicStructFactory< T >::fields
private

Definition of all potential fields in the polymorphic structure.

◆ free_ids

template<typename T >
std::stack<STRUCT_ID> arion_poly_struct::PolymorphicStructFactory< T >::free_ids
private

Stack of released IDs for reuse.


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