retdec
dotnet_type_reconstructor.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_FILEFORMAT_TYPES_DOTNET_TYPES_DOTNET_TYPE_RECONSTRUCTOR_H
8 #define RETDEC_FILEFORMAT_TYPES_DOTNET_TYPES_DOTNET_TYPE_RECONSTRUCTOR_H
9 
14 
15 namespace retdec {
16 namespace fileformat {
17 
19 {
20  public:
21  using ClassList = std::vector<std::shared_ptr<DotnetClass>>;
22  using ClassTable = std::map<std::size_t, std::shared_ptr<DotnetClass>>;
23  using ClassToMethodTable = std::unordered_map<const DotnetClass*, std::vector<std::unique_ptr<DotnetMethod>>>;
24  using MethodTable = std::map<std::size_t, DotnetMethod*>;
25  using SignatureTable = std::map<const DotnetMethod*, std::vector<std::uint8_t>>;
26 
27  DotnetTypeReconstructor(const MetadataStream* metadata, const StringStream* strings, const BlobStream* blob);
28 
29  bool reconstruct();
30 
33 
34  private:
35  bool reconstructClasses();
36  bool reconstructMethods();
39  bool reconstructFields();
40  bool reconstructProperties();
42  bool reconstructBaseTypes();
43 
45  void linkReconstructedClassesDo(size_t i, std::vector<bool> &visited, std::vector<bool> &stack, ClassList &refClasses, const MetadataTable<TypeRef>* typeRefTable);
46 
47  std::unique_ptr<DotnetClass> createClassDefinition(const TypeDef* typeDef, std::size_t fieldsCount,
48  std::size_t methodsCount, std::size_t typeDefIndex);
49  std::unique_ptr<DotnetClass> createClassReference(const TypeRef* typeRef, std::size_t typeRefIndex);
50  std::unique_ptr<DotnetField> createField(const Field* field, const DotnetClass* ownerClass);
51  std::unique_ptr<DotnetProperty> createProperty(const Property* property, const DotnetClass* ownerClass);
52  std::unique_ptr<DotnetMethod> createMethod(const MethodDef* methodDef, const DotnetClass* ownerClass);
53  std::unique_ptr<DotnetParameter> createMethodParameter(const Param* param, const DotnetClass* ownerClass, const DotnetMethod* ownerMethod, std::vector<std::uint8_t>& signature);
54 
55  template <typename T> std::unique_ptr<T> createDataTypeFollowedByReference(std::vector<std::uint8_t>& data);
56  template <typename T> std::unique_ptr<T> createDataTypeFollowedByType(std::vector<std::uint8_t>& data, const DotnetClass* ownerClass, const DotnetMethod* ownerMethod);
57  template <typename T, typename U> std::unique_ptr<T> createGenericReference(std::vector<std::uint8_t>& data, const U* owner);
58  std::unique_ptr<DotnetDataTypeGenericInst> createGenericInstantiation(std::vector<std::uint8_t>& data, const DotnetClass* ownerClass, const DotnetMethod* ownerMethod);
59  std::unique_ptr<DotnetDataTypeArray> createArray(std::vector<std::uint8_t>& data, const DotnetClass* ownerClass, const DotnetMethod* ownerMethod);
60  template <typename T> std::unique_ptr<T> createModifier(std::vector<std::uint8_t>& data, const DotnetClass* ownerClass, const DotnetMethod* ownerMethod);
61  std::unique_ptr<DotnetDataTypeFnPtr> createFnPtr(std::vector<std::uint8_t>& data, const DotnetClass* ownerClass, const DotnetMethod* ownerMethod);
62 
63  std::unique_ptr<DotnetDataTypeBase> dataTypeFromSignature(std::vector<std::uint8_t>& signature, const DotnetClass* ownerClass, const DotnetMethod* ownerMethod);
64 
65  const DotnetClass* selectClass(const TypeDefOrRef& typeDefOrRef) const;
66 
75 };
76 
77 } // namespace fileformat
78 } // namespace retdec
79 
80 #endif
Class for #Blob Stream.
Definition: blob_stream.h:18
Definition: dotnet_class.h:27
Definition: dotnet_method.h:23
Definition: dotnet_type_reconstructor.h:19
std::unique_ptr< T > createDataTypeFollowedByType(std::vector< std::uint8_t > &data, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
Definition: dotnet_type_reconstructor.cpp:1063
std::unique_ptr< T > createGenericReference(std::vector< std::uint8_t > &data, const U *owner)
Definition: dotnet_type_reconstructor.cpp:1079
std::unique_ptr< DotnetDataTypeArray > createArray(std::vector< std::uint8_t > &data, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
Definition: dotnet_type_reconstructor.cpp:1143
const StringStream * stringStream
Definition: dotnet_type_reconstructor.h:68
std::unordered_map< const DotnetClass *, std::vector< std::unique_ptr< DotnetMethod > >> ClassToMethodTable
Definition: dotnet_type_reconstructor.h:23
ClassTable refClassTable
Definition: dotnet_type_reconstructor.h:71
bool reconstructClasses()
Definition: dotnet_type_reconstructor.cpp:350
void linkReconstructedClassesDo(size_t i, std::vector< bool > &visited, std::vector< bool > &stack, ClassList &refClasses, const MetadataTable< TypeRef > *typeRefTable)
Definition: dotnet_type_reconstructor.cpp:289
ClassTable defClassTable
Definition: dotnet_type_reconstructor.h:70
SignatureTable methodReturnTypeAndParamTypeTable
Definition: dotnet_type_reconstructor.h:74
ClassList getDefinedClasses() const
Definition: dotnet_type_reconstructor.cpp:239
std::unique_ptr< DotnetDataTypeBase > dataTypeFromSignature(std::vector< std::uint8_t > &signature, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
Definition: dotnet_type_reconstructor.cpp:1279
DotnetTypeReconstructor(const MetadataStream *metadata, const StringStream *strings, const BlobStream *blob)
Definition: dotnet_type_reconstructor.cpp:204
bool reconstructFields()
Definition: dotnet_type_reconstructor.cpp:554
std::unique_ptr< DotnetDataTypeFnPtr > createFnPtr(std::vector< std::uint8_t > &data, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
Definition: dotnet_type_reconstructor.cpp:1240
std::unique_ptr< T > createDataTypeFollowedByReference(std::vector< std::uint8_t > &data)
Definition: dotnet_type_reconstructor.cpp:1039
const DotnetClass * selectClass(const TypeDefOrRef &typeDefOrRef) const
Definition: dotnet_type_reconstructor.cpp:1410
std::unique_ptr< DotnetParameter > createMethodParameter(const Param *param, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod, std::vector< std::uint8_t > &signature)
Definition: dotnet_type_reconstructor.cpp:1013
bool reconstructProperties()
Definition: dotnet_type_reconstructor.cpp:587
std::unique_ptr< DotnetField > createField(const Field *field, const DotnetClass *ownerClass)
Definition: dotnet_type_reconstructor.cpp:881
std::unique_ptr< DotnetDataTypeGenericInst > createGenericInstantiation(std::vector< std::uint8_t > &data, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
Definition: dotnet_type_reconstructor.cpp:1105
std::unique_ptr< T > createModifier(std::vector< std::uint8_t > &data, const DotnetClass *ownerClass, const DotnetMethod *ownerMethod)
Definition: dotnet_type_reconstructor.cpp:1208
std::vector< std::shared_ptr< DotnetClass > > ClassList
Definition: dotnet_type_reconstructor.h:21
bool reconstructBaseTypes()
Definition: dotnet_type_reconstructor.cpp:669
MethodTable methodTable
Definition: dotnet_type_reconstructor.h:72
std::map< std::size_t, DotnetMethod * > MethodTable
Definition: dotnet_type_reconstructor.h:24
ClassList getReferencedClasses() const
Definition: dotnet_type_reconstructor.cpp:248
ClassToMethodTable classToMethodTable
Definition: dotnet_type_reconstructor.h:73
std::unique_ptr< DotnetProperty > createProperty(const Property *property, const DotnetClass *ownerClass)
Definition: dotnet_type_reconstructor.cpp:914
bool reconstructGenericParameters()
Definition: dotnet_type_reconstructor.cpp:453
void linkReconstructedClasses()
Definition: dotnet_type_reconstructor.cpp:256
bool reconstructMethods()
Definition: dotnet_type_reconstructor.cpp:415
const BlobStream * blobStream
Definition: dotnet_type_reconstructor.h:69
std::unique_ptr< DotnetClass > createClassReference(const TypeRef *typeRef, std::size_t typeRefIndex)
Definition: dotnet_type_reconstructor.cpp:823
std::map< std::size_t, std::shared_ptr< DotnetClass > > ClassTable
Definition: dotnet_type_reconstructor.h:22
std::map< const DotnetMethod *, std::vector< std::uint8_t > > SignatureTable
Definition: dotnet_type_reconstructor.h:25
bool reconstruct()
Definition: dotnet_type_reconstructor.cpp:214
std::unique_ptr< DotnetMethod > createMethod(const MethodDef *methodDef, const DotnetClass *ownerClass)
Definition: dotnet_type_reconstructor.cpp:949
bool reconstructNestedClasses()
Definition: dotnet_type_reconstructor.cpp:640
bool reconstructMethodParameters()
Definition: dotnet_type_reconstructor.cpp:497
const MetadataStream * metadataStream
Definition: dotnet_type_reconstructor.h:67
std::unique_ptr< DotnetClass > createClassDefinition(const TypeDef *typeDef, std::size_t fieldsCount, std::size_t methodsCount, std::size_t typeDefIndex)
Definition: dotnet_type_reconstructor.cpp:787
Definition: metadata_stream.h:21
Definition: metadata_table.h:89
Definition: string_stream.h:18
Class for .NET class.
Class for #~ Stream.
Definition: archive_wrapper.h:19
Class for #Strings Stream.
Definition: metadata_tables.h:683
Definition: metadata_tables.h:712
Definition: metadata_tables.h:750
Definition: metadata_tables.h:931
Definition: metadata_tables.h:191
Definition: metadata_tables.h:641
Definition: metadata_tables.h:627