1 #pragma once
2 
3 #define DOTNET_INDEX(i) (i - 1)
4 
5 #include "dotnet_header.h"
6 #include "dotnet_tables.h"
7 
8 namespace REDasm {
9 
10 class PeDotNet
11 {
12     private:
13         typedef std::function<void(u32**, const CorTables&, CorTablePtr&)> TableCallback;
14         typedef std::unordered_map<u32, TableCallback> TableDispatcher;
15 
16     private:
17         PeDotNet();
18 
19     public:
20         static std::string getVersion(ImageCor20MetaData *cormetadata);
21         static u16 getNumberOfStreams(ImageCor20MetaData* cormetadata);
22         static ImageStreamHeader* getStream(ImageCor20MetaData* cormetadata, const std::string &id);
23         static bool getTables(ImageCor20TablesHeader* cortablesheader, CorTables& tables);
24 
25     private:
26         static u32 getSizeOfHeap(ImageCor20TablesHeader *cortablesheader, u32 bitno);
27         static u32 getValueIdx(u32** data, u32 offsize);
28         static u32 getTableIdx(u32** data, const CorTables& tables, u32 table);
29         static u32 getStringIdx(u32** data, const CorTables& tables);
30         static u32 getGuidIdx(u32** data, const CorTables& tables);
31         static u32 getBlobIdx(u32** data, const CorTables& tables);
32         static void getModule(u32** data, const CorTables& tables, CorTablePtr& table);
33         static void getTypeRef(u32** data, const CorTables& tables, CorTablePtr& table);
34         static void getTypeDef(u32** data, const CorTables& tables, CorTablePtr& table);
35         static void getFieldDef(u32** data, const CorTables& tables, CorTablePtr& table);
36         static void getMethodDef(u32** data, const CorTables& tables, CorTablePtr& table);
37         static void getParamDef(u32** data, const CorTables& tables, CorTablePtr& table);
38         static void getInterfaceImpl(u32** data, const CorTables& tables, CorTablePtr& table);
39         static void getMemberRef(u32** data, const CorTables& tables, CorTablePtr& table);
40         static void getConstant(u32** data, const CorTables& tables, CorTablePtr& table);
41         static void getCustomAttribute(u32** data, const CorTables& tables, CorTablePtr& table);
42         static void getFieldMarshal(u32** data, const CorTables& tables, CorTablePtr& table);
43         static void getDeclSecurity(u32** data, const CorTables& tables, CorTablePtr& table);
44         static void getClassLayout(u32** data, const CorTables& tables, CorTablePtr& table);
45         static void getFieldLayout(u32** data, const CorTables& tables, CorTablePtr& table);
46         static void getStandaloneSig(u32** data, const CorTables& tables, CorTablePtr& table);
47         static void getEventMap(u32** data, const CorTables& tables, CorTablePtr& table);
48         static void getEvent(u32** data, const CorTables& tables, CorTablePtr& table);
49         static void getPropertyMap(u32** data, const CorTables& tables, CorTablePtr& table);
50         static void getProperty(u32** data, const CorTables& tables, CorTablePtr& table);
51         static void getMethodSemantics(u32** data, const CorTables& tables, CorTablePtr& table);
52         static void getMethodImpl(u32** data, const CorTables& tables, CorTablePtr& table);
53         static void getModuleRef(u32** data, const CorTables& tables, CorTablePtr& table);
54         static void getTypeSpec(u32** data, const CorTables& tables, CorTablePtr& table);
55         static void getImplMap(u32** data, const CorTables& tables, CorTablePtr& table);
56         static void getFieldRVA(u32** data, const CorTables& tables, CorTablePtr& table);
57         static void getAssembly(u32** data, const CorTables& tables, CorTablePtr& table);
58         static void getAssemblyProcessor(u32** data, const CorTables& tables, CorTablePtr& table);
59         static void getAssemblyOS(u32** data, const CorTables& tables, CorTablePtr& table);
60         static void getAssemblyRef(u32** data, const CorTables& tables, CorTablePtr& table);
61         static void getAssemblyRefProcessor(u32** data, const CorTables& tables, CorTablePtr& table);
62         static void getAssemblyRefOS(u32** data, const CorTables& tables, CorTablePtr& table);
63         static void getFile(u32** data, const CorTables& tables, CorTablePtr& table);
64         static void getExportedType(u32** data, const CorTables& tables, CorTablePtr& table);
65         static void getManifestResource(u32** data, const CorTables& tables, CorTablePtr& table);
66         static void getNestedClass(u32** data, const CorTables& tables, CorTablePtr& table);
67         static void getGenericParam(u32** data, const CorTables& tables, CorTablePtr& table);
68         static void getGenericParamConstraint(u32** data, const CorTables& tables, CorTablePtr& table);
69         static void initTables();
70 
71     private:
72         static void getTaggedField(u32** data, u32& value, u8& tag, u8 tagbits, const CorTables& tables, const std::list<u32>& tablerefs);
73         static u32 maxRows(const CorTables& tables, const std::list<u32>& tablerefs);
74 
75     private:
76         static std::list<u32> m_tables;
77         static TableDispatcher m_dispatcher;
78 };
79 
80 } // namespace REDasm
81