retdec
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
retdec::fileformat::DotnetTypeReconstructor Class Reference

#include <dotnet_type_reconstructor.h>

Collaboration diagram for retdec::fileformat::DotnetTypeReconstructor:
Collaboration graph
[legend]

Public Types

using ClassList = std::vector< std::shared_ptr< DotnetClass > >
 
using ClassTable = std::map< std::size_t, std::shared_ptr< DotnetClass > >
 
using ClassToMethodTable = std::unordered_map< const DotnetClass *, std::vector< std::unique_ptr< DotnetMethod > >>
 
using MethodTable = std::map< std::size_t, DotnetMethod * >
 
using SignatureTable = std::map< const DotnetMethod *, std::vector< std::uint8_t > >
 

Public Member Functions

 DotnetTypeReconstructor (const MetadataStream *metadata, const StringStream *strings, const BlobStream *blob)
 
bool reconstruct ()
 
ClassList getDefinedClasses () const
 
ClassList getReferencedClasses () const
 

Private Member Functions

bool reconstructClasses ()
 
bool reconstructMethods ()
 
bool reconstructGenericParameters ()
 
bool reconstructMethodParameters ()
 
bool reconstructFields ()
 
bool reconstructProperties ()
 
bool reconstructNestedClasses ()
 
bool reconstructBaseTypes ()
 
void linkReconstructedClasses ()
 
void linkReconstructedClassesDo (size_t i, std::vector< bool > &visited, std::vector< bool > &stack, ClassList &refClasses, const MetadataTable< TypeRef > *typeRefTable)
 
std::unique_ptr< DotnetClasscreateClassDefinition (const TypeDef *typeDef, std::size_t fieldsCount, std::size_t methodsCount, std::size_t typeDefIndex)
 
std::unique_ptr< DotnetClasscreateClassReference (const TypeRef *typeRef, std::size_t typeRefIndex)
 
std::unique_ptr< DotnetFieldcreateField (const Field *field, const DotnetClass *ownerClass)
 
std::unique_ptr< DotnetPropertycreateProperty (const Property *property, const DotnetClass *ownerClass)
 
std::unique_ptr< DotnetMethodcreateMethod (const MethodDef *methodDef, const DotnetClass *ownerClass)
 
std::unique_ptr< DotnetParametercreateMethodParameter (const Param *param, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod, std::vector< std::uint8_t > &signature)
 
template<typename T >
std::unique_ptr< T > createDataTypeFollowedByReference (std::vector< std::uint8_t > &data)
 
template<typename T >
std::unique_ptr< T > createDataTypeFollowedByType (std::vector< std::uint8_t > &data, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
 
template<typename T , typename U >
std::unique_ptr< T > createGenericReference (std::vector< std::uint8_t > &data, const U *owner)
 
std::unique_ptr< DotnetDataTypeGenericInstcreateGenericInstantiation (std::vector< std::uint8_t > &data, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
 
std::unique_ptr< DotnetDataTypeArraycreateArray (std::vector< std::uint8_t > &data, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
 
template<typename T >
std::unique_ptr< T > createModifier (std::vector< std::uint8_t > &data, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
 
std::unique_ptr< DotnetDataTypeFnPtrcreateFnPtr (std::vector< std::uint8_t > &data, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
 
std::unique_ptr< DotnetDataTypeBasedataTypeFromSignature (std::vector< std::uint8_t > &signature, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
 
const DotnetClassselectClass (const TypeDefOrRef &typeDefOrRef) const
 

Private Attributes

const MetadataStreammetadataStream
 
const StringStreamstringStream
 
const BlobStreamblobStream
 
ClassTable defClassTable
 
ClassTable refClassTable
 
MethodTable methodTable
 
ClassToMethodTable classToMethodTable
 
SignatureTable methodReturnTypeAndParamTypeTable
 

Member Typedef Documentation

◆ ClassList

◆ ClassTable

using retdec::fileformat::DotnetTypeReconstructor::ClassTable = std::map<std::size_t, std::shared_ptr<DotnetClass> >

◆ ClassToMethodTable

using retdec::fileformat::DotnetTypeReconstructor::ClassToMethodTable = std::unordered_map<const DotnetClass*, std::vector<std::unique_ptr<DotnetMethod> >>

◆ MethodTable

◆ SignatureTable

using retdec::fileformat::DotnetTypeReconstructor::SignatureTable = std::map<const DotnetMethod*, std::vector<std::uint8_t> >

Constructor & Destructor Documentation

◆ DotnetTypeReconstructor()

retdec::fileformat::DotnetTypeReconstructor::DotnetTypeReconstructor ( const MetadataStream metadata,
const StringStream strings,
const BlobStream blob 
)

Constructor.

Parameters
metadataMetadata stream.
stringsString stream.
blobBlob stream.

Member Function Documentation

◆ createArray()

std::unique_ptr< DotnetDataTypeArray > retdec::fileformat::DotnetTypeReconstructor::createArray ( std::vector< std::uint8_t > &  data,
const DotnetClass ownerClass,
const DotnetMethod ownerMethod 
)
private

Creates data type from signature that represent array.

Parameters
dataSignature data.
ownerClassOwning class.
ownerMethodOwning method.
Returns
New data type or nullptr in case of failure.

◆ createClassDefinition()

std::unique_ptr< DotnetClass > retdec::fileformat::DotnetTypeReconstructor::createClassDefinition ( const TypeDef typeDef,
std::size_t  fieldsCount,
std::size_t  methodsCount,
std::size_t  typeDefIndex 
)
private

Creates new class definition from TypeDef table record.

Parameters
typeDefTypeDef table record.
fieldsCountDeclared number of fields.
methodsCountDeclared number of methods.
typeDefIndexIndex of TypeDef record.
Returns
New class definition or nullptr in case of failure.

◆ createClassReference()

std::unique_ptr< DotnetClass > retdec::fileformat::DotnetTypeReconstructor::createClassReference ( const TypeRef typeRef,
std::size_t  typeRefIndex 
)
private

Creates new class reference from TypeRef table record.

Parameters
typeRefTypeRef table record.
typeRefIndexIndex of typeRef table record.
Returns
New class reference or nullptr in case of failure.

◆ createDataTypeFollowedByReference()

template<typename T >
std::unique_ptr< T > retdec::fileformat::DotnetTypeReconstructor::createDataTypeFollowedByReference ( std::vector< std::uint8_t > &  data)
private

Creates data type from signature that references defined or imported class.

Parameters
dataSignature data.
Returns
New data type or nullptr in case of failure.

◆ createDataTypeFollowedByType()

template<typename T >
std::unique_ptr< T > retdec::fileformat::DotnetTypeReconstructor::createDataTypeFollowedByType ( std::vector< std::uint8_t > &  data,
const DotnetClass ownerClass,
const DotnetMethod ownerMethod 
)
private

Creates data type from signature that refers to another data type.

Parameters
dataSignature data.
ownerClassOwning class.
ownerMethodOwning method.
Returns
New data type or nullptr in case of failure.

◆ createField()

std::unique_ptr< DotnetField > retdec::fileformat::DotnetTypeReconstructor::createField ( const Field field,
const DotnetClass ownerClass 
)
private

Creates new field from Field table record.

Parameters
fieldField table record.
ownerClassOwning class.
Returns
New field or nullptr in case of failure.

◆ createFnPtr()

std::unique_ptr< DotnetDataTypeFnPtr > retdec::fileformat::DotnetTypeReconstructor::createFnPtr ( std::vector< std::uint8_t > &  data,
const DotnetClass ownerClass,
const DotnetMethod ownerMethod 
)
private

Creates data type from signature that represents function pointer.

Parameters
dataSignature data.
ownerClassOwning class.
ownerMethodOwning method.
Returns
New data type or nullptr in case of failure.

◆ createGenericInstantiation()

std::unique_ptr< DotnetDataTypeGenericInst > retdec::fileformat::DotnetTypeReconstructor::createGenericInstantiation ( std::vector< std::uint8_t > &  data,
const DotnetClass ownerClass,
const DotnetMethod ownerMethod 
)
private

Creates data type from signature that instantiates generic data type.

Parameters
dataSignature data.
ownerClassOwning class.
ownerMethodOwning method.
Returns
New data type or nullptr in case of failure.

◆ createGenericReference()

template<typename T , typename U >
std::unique_ptr< T > retdec::fileformat::DotnetTypeReconstructor::createGenericReference ( std::vector< std::uint8_t > &  data,
const U *  owner 
)
private

Creates data type from signature that references generic parameter.

Parameters
dataSignature data.
ownerOwning class or method.
Returns
New data type or nullptr in case of failure.

◆ createMethod()

std::unique_ptr< DotnetMethod > retdec::fileformat::DotnetTypeReconstructor::createMethod ( const MethodDef methodDef,
const DotnetClass ownerClass 
)
private

Creates new method from MethodDef table record.

Parameters
methodDefMethodDef table record.
ownerClassOwning class.
Returns
New method or nullptr in case of failure.

◆ createMethodParameter()

std::unique_ptr< DotnetParameter > retdec::fileformat::DotnetTypeReconstructor::createMethodParameter ( const Param param,
const DotnetClass ownerClass,
const DotnetMethod ownerMethod,
std::vector< std::uint8_t > &  signature 
)
private

Creates new method parameter from Param table record.

Parameters
paramParam table record.
ownerClassOwning class.
ownerMethodOwning method.
signatureSignature with data types. Is destroyed in the meantime.
Returns
New method parameter or nullptr in case of failure.

◆ createModifier()

template<typename T >
std::unique_ptr< T > retdec::fileformat::DotnetTypeReconstructor::createModifier ( std::vector< std::uint8_t > &  data,
const DotnetClass ownerClass,
const DotnetMethod ownerMethod 
)
private

Creates data type from signature that represent type modifier.

Parameters
dataSignature data.
ownerClassOwning class.
ownerMethodOwning method.
Returns
New data type or nullptr in case of failure.

◆ createProperty()

std::unique_ptr< DotnetProperty > retdec::fileformat::DotnetTypeReconstructor::createProperty ( const Property property,
const DotnetClass ownerClass 
)
private

Creates new property from Property table record.

Parameters
propertyProperty table record.
ownerClassOwning class.
Returns
New property or nullptr in case of failure.

◆ dataTypeFromSignature()

std::unique_ptr< DotnetDataTypeBase > retdec::fileformat::DotnetTypeReconstructor::dataTypeFromSignature ( std::vector< std::uint8_t > &  signature,
const DotnetClass ownerClass,
const DotnetMethod ownerMethod 
)
private

Creates data type from signature. Signature is destroyed in the meantime.

Parameters
signatureSignature data.
ownerClassOwning class.
ownerMethodOwning method.
Returns
New data type or nullptr in case of failure.

◆ getDefinedClasses()

DotnetTypeReconstructor::ClassList retdec::fileformat::DotnetTypeReconstructor::getDefinedClasses ( ) const

Returns the defined classes.

Returns
Defined classes.

◆ getReferencedClasses()

DotnetTypeReconstructor::ClassList retdec::fileformat::DotnetTypeReconstructor::getReferencedClasses ( ) const

Returns the referenced (imported) classes.

Returns
Referenced (imported) classes.

◆ linkReconstructedClasses()

void retdec::fileformat::DotnetTypeReconstructor::linkReconstructedClasses ( )
private

Links referenced (imported) classes.

◆ linkReconstructedClassesDo()

void retdec::fileformat::DotnetTypeReconstructor::linkReconstructedClassesDo ( size_t  i,
std::vector< bool > &  visited,
std::vector< bool > &  stack,
ClassList refClasses,
const MetadataTable< TypeRef > *  typeRefTable 
)
private

Helper function for linkReconstructedClasses()

Parameters
iIndex of a class to be linked.
visitedVisited flags for cyclic linkage detection.
stackRecent traversal stack for cyclic linkage detection.
refClassesList of imported classes.
typeRefTableTyperef table.

◆ reconstruct()

bool retdec::fileformat::DotnetTypeReconstructor::reconstruct ( )

Reconstructs classes, methods, fields, properties and class hierarchy.

Returns
true if reconstruction was successful, otherwise false.

◆ reconstructBaseTypes()

bool retdec::fileformat::DotnetTypeReconstructor::reconstructBaseTypes ( )
private

Reconstructs base types of classes.

Returns
true if reconstruction successful, otherwise false.

◆ reconstructClasses()

bool retdec::fileformat::DotnetTypeReconstructor::reconstructClasses ( )
private

Reconstructs defined and referenced (imported) classes and interfaces.

Returns
true if reconstruction successful, otherwise false.

◆ reconstructFields()

bool retdec::fileformat::DotnetTypeReconstructor::reconstructFields ( )
private

Reconstructs fields of classes.

Returns
true if reconstruction successful, otherwise false.

◆ reconstructGenericParameters()

bool retdec::fileformat::DotnetTypeReconstructor::reconstructGenericParameters ( )
private

Reconstructs generic parameters of classes and methods.

Returns
true if reconstruction successful, otherwise false.

◆ reconstructMethodParameters()

bool retdec::fileformat::DotnetTypeReconstructor::reconstructMethodParameters ( )
private

Reconstructs parameters of methods.

Returns
true if reconstruction successful, otherwise false.

◆ reconstructMethods()

bool retdec::fileformat::DotnetTypeReconstructor::reconstructMethods ( )
private

Reconstructs methods in the classes and interfaces. Method parameters are not reconstructed here.

Returns
true if reconstruction successful, otherwise false.

◆ reconstructNestedClasses()

bool retdec::fileformat::DotnetTypeReconstructor::reconstructNestedClasses ( )
private

Reconstructs namespaces of nested classes.

Returns
true if reconstruction successful, otherwise false.

◆ reconstructProperties()

bool retdec::fileformat::DotnetTypeReconstructor::reconstructProperties ( )
private

Reconstructs fields of classes.

Returns
true if reconstruction successful, otherwise false.

◆ selectClass()

const DotnetClass * retdec::fileformat::DotnetTypeReconstructor::selectClass ( const TypeDefOrRef typeDefOrRef) const
private

Selects a class from defined or referenced class table based on provided TypeDefOrRef index.

Parameters
typeDefOrRefIndex.
Returns
Class if any exists, otherwise nullptr.

Member Data Documentation

◆ blobStream

const BlobStream* retdec::fileformat::DotnetTypeReconstructor::blobStream
private

◆ classToMethodTable

ClassToMethodTable retdec::fileformat::DotnetTypeReconstructor::classToMethodTable
private

◆ defClassTable

ClassTable retdec::fileformat::DotnetTypeReconstructor::defClassTable
private

◆ metadataStream

const MetadataStream* retdec::fileformat::DotnetTypeReconstructor::metadataStream
private

◆ methodReturnTypeAndParamTypeTable

SignatureTable retdec::fileformat::DotnetTypeReconstructor::methodReturnTypeAndParamTypeTable
private

◆ methodTable

MethodTable retdec::fileformat::DotnetTypeReconstructor::methodTable
private

◆ refClassTable

ClassTable retdec::fileformat::DotnetTypeReconstructor::refClassTable
private

◆ stringStream

const StringStream* retdec::fileformat::DotnetTypeReconstructor::stringStream
private

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