1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5#ifndef _mdinfo_h
6#define _mdinfo_h
7
8#include "winwrap.h"
9#include "cor.h"
10#include "corhlprpriv.h"
11
12#ifdef FEATURE_PAL
13#include <oleauto.h>
14#endif
15
16#define STRING_BUFFER_LEN 4096
17
18typedef void (*strPassBackFn)(const char *str);
19
20class MDInfo {
21public:
22 enum DUMP_FILTER
23 {
24 dumpDefault = 0x00000000, // Dump everything but debugger data.
25 dumpSchema = 0x00000002, // Dump the metadata schema.
26 dumpRaw = 0x00000004, // Dump the metadata in raw table format.
27 dumpHeader = 0x00000008, // Dump just the metadata header info.
28 dumpCSV = 0x00000010, // Dump the metadata header info in CSV format.
29 dumpUnsat = 0x00000020, // Dump unresolved methods or memberref
30 dumpAssem = 0x00000040,
31 dumpStats = 0x00000080, // Dump more statistics about tables.
32 dumpMoreHex = 0x00000100, // Dump more things in hex.
33 dumpValidate = 0x00000200, // Validate MetaData.
34 dumpRawHeaps = 0x00000400, // Also dump the heaps in the raw dump.
35 = 0x00000800, // Don't display the logo or MVID
36 dumpNames = 0x00001000, // In a hex dump, display the names, as well as string #'s.
37 };
38
39
40public:
41 MDInfo(IMetaDataImport2* pImport, IMetaDataAssemblyImport* pAssemblyImport, LPCWSTR szScope, strPassBackFn inPBFn, ULONG DumpFilter);
42 MDInfo(IMetaDataDispenserEx *pDispenser, LPCWSTR szScope, strPassBackFn inPBFn, ULONG DumpFilter=dumpDefault);
43 MDInfo(IMetaDataDispenserEx *pDispenser, PBYTE pManifest, DWORD dwSize, strPassBackFn inPBFn, ULONG DumpFilter=dumpDefault);
44 ~MDInfo();
45
46 void DisplayMD(void);
47
48#ifdef FEATURE_COMINTEROP
49 LPCWSTR VariantAsString(VARIANT *pVariant);
50#endif
51
52 void DisplayVersionInfo(void);
53
54 void DisplayScopeInfo(void);
55
56 void DisplayGlobalFunctions(void);
57 void DisplayGlobalFields(void);
58 void DisplayFieldRVA(mdFieldDef field);
59 void DisplayGlobalMemberRefs(void);
60
61 void DisplayTypeDefs(void);
62 void DisplayTypeDefInfo(mdTypeDef inTypeDef);
63 void DisplayTypeDefProps(mdTypeDef inTypeDef);
64
65 void DisplayModuleRefs(void);
66 void DisplayModuleRefInfo(mdModuleRef inModuleRef);
67
68 void DisplaySignatures(void);
69 void DisplaySignatureInfo(mdSignature inSignature);
70
71 LPCWSTR TokenName(mdToken inToken, __out_ecount(bufLen) LPWSTR buffer, ULONG bufLen);
72
73 LPCWSTR TypeDeforRefName(mdToken inToken, __out_ecount(bufLen) LPWSTR buffer, ULONG bufLen);
74 LPCWSTR TypeDefName(mdTypeDef inTypeDef, __out_ecount(bufLen) LPWSTR buffer, ULONG bufLen);
75 LPCWSTR TypeRefName(mdTypeRef tr, __out_ecount(bufLen) LPWSTR buffer, ULONG bufLen);
76
77 LPCWSTR MemberDeforRefName(mdToken inToken, __out_ecount(bufLen) LPWSTR buffer, ULONG bufLen);
78 LPCWSTR MemberRefName(mdToken inMemRef, __out_ecount(bufLen) LPWSTR buffer, ULONG bufLen);
79 LPCWSTR MemberName(mdToken inMember, __out_ecount(bufLen) LPWSTR buffer, ULONG bufLen);
80
81 LPCWSTR MethodName(mdMethodDef inToken, __out_ecount(bufLen) LPWSTR buffer, ULONG bufLen);
82 LPCWSTR FieldName(mdFieldDef inToken, __out_ecount(bufLen) LPWSTR buffer, ULONG bufLen);
83
84 char *ClassFlags(DWORD flags, __out_ecount(STRING_BUFFER_LEN) char *sFlags);
85
86 void DisplayTypeRefs(void);
87 void DisplayTypeRefInfo(mdTypeRef tr);
88 void DisplayTypeSpecs(void);
89 void DisplayTypeSpecInfo(mdTypeSpec ts, const char *preFix);
90 void DisplayMethodSpecs(void);
91 void DisplayMethodSpecInfo(mdMethodSpec ms, const char *preFix);
92
93 void DisplayCorNativeLink(COR_NATIVE_LINK *pCorNLnk, const char *preFix);
94 void DisplayCustomAttributeInfo(mdCustomAttribute inValue, const char *preFix);
95 void DisplayCustomAttributes(mdToken inToken, const char *preFix);
96
97 void DisplayInterfaceImpls(mdTypeDef inTypeDef);
98 void DisplayInterfaceImplInfo(mdInterfaceImpl inImpl);
99
100 LPWSTR GUIDAsString(GUID inGuid, __out_ecount(bufLen) LPWSTR guidString, ULONG bufLen);
101
102 const char *TokenTypeName(mdToken inToken);
103
104 void DisplayMemberInfo(mdToken inMember);
105 void DisplayMethodInfo(mdMethodDef method, DWORD *pflags = 0);
106 void DisplayFieldInfo(mdFieldDef field, DWORD *pflags = 0);
107
108 void DisplayMethods(mdTypeDef inTypeDef);
109 void DisplayFields(mdTypeDef inTypeDef, COR_FIELD_OFFSET *rFieldOffset, ULONG cFieldOffset);
110
111 void DisplaySignature(PCCOR_SIGNATURE pbSigBlob, ULONG ulSigBlob, const char *preFix);
112 HRESULT GetOneElementType(PCCOR_SIGNATURE pbSigBlob, ULONG ulSigBlob, ULONG *pcb);
113
114 void DisplayMemberRefs(mdToken tkParent, const char *preFix);
115 void DisplayMemberRefInfo(mdMemberRef inMemRef, const char *preFix);
116
117 void DisplayMethodImpls(mdTypeDef inTypeDef);
118
119 void DisplayParams(mdMethodDef inMthDef);
120 void DisplayParamInfo(mdParamDef inParam);
121
122 void DisplayGenericParams(mdToken tk, const char *prefix);
123 void DisplayGenericParamInfo(mdGenericParam tkparam, const char *prefix);
124
125 void DisplayPropertyInfo(mdProperty inProp);
126 void DisplayProperties(mdTypeDef inTypeDef);
127
128 void DisplayEventInfo(mdEvent inEvent);
129 void DisplayEvents(mdTypeDef inTypeDef);
130
131 void DisplayPermissions(mdToken tk, const char *preFix);
132 void DisplayPermissionInfo(mdPermission inPermission, const char *preFix);
133
134 void DisplayFieldMarshal(mdToken inToken);
135
136 void DisplayPinvokeInfo(mdToken inToken);
137
138 void DisplayAssembly();
139
140 void DisplayAssemblyInfo();
141
142 void DisplayAssemblyRefs();
143 void DisplayAssemblyRefInfo(mdAssemblyRef inAssemblyRef);
144
145 void DisplayFiles();
146 void DisplayFileInfo(mdFile inFile);
147
148 void DisplayExportedTypes();
149 void DisplayExportedTypeInfo(mdExportedType inExportedType);
150
151 void DisplayManifestResources();
152 void DisplayManifestResourceInfo(mdManifestResource inManifestResource);
153
154 void DisplayASSEMBLYMETADATA(ASSEMBLYMETADATA *pMetaData);
155
156 void DisplayUserStrings();
157
158 void DisplayUnsatInfo();
159
160 void DisplayRaw();
161 void DumpRawHeaps();
162 void DumpRaw(int iDump=1, bool bStats=false);
163 void DumpRawCSV();
164 void DumpRawCol(ULONG ixTbl, ULONG ixCol, ULONG rid, bool bStats);
165 ULONG DumpRawColStats(ULONG ixTbl, ULONG ixCol, ULONG cRows);
166 const char *DumpRawNameOfType(ULONG ulType);
167
168 static void Error(const char *szError, HRESULT hr = S_OK);
169private:
170 void Init(strPassBackFn inPBFn, DUMP_FILTER DumpFilter); // Common initialization code.
171
172 int DumpHex(const char *szPrefix, const void *pvData, ULONG cbData, int bText=true, ULONG nLine=16);
173
174 int Write(__in_z __in const char *str);
175 int WriteLine(__in_z __in const char *str);
176
177 int VWrite(__in_z __in const char *str, ...);
178 int VWriteLine(__in_z __in const char *str, ...);
179 int VWriteMarker(__in_z __in const char *str, va_list marker);
180
181 void InitSigBuffer();
182 HRESULT AddToSigBuffer(__in_z __in const char *string);
183
184 IMetaDataImport2 *m_pRegImport;
185 IMetaDataImport2 *m_pImport;
186 IMetaDataAssemblyImport *m_pAssemblyImport;
187 strPassBackFn m_pbFn;
188 IMetaDataTables *m_pTables;
189 IMetaDataTables2 *m_pTables2;
190
191 CQuickBytes m_output;
192 DUMP_FILTER m_DumpFilter;
193
194 // temporary buffer for TypeDef or TypeRef name. Consume immediately
195 // because other functions may overwrite it.
196 WCHAR m_szTempBuf[STRING_BUFFER_LEN];
197
198 // temporary buffer for formatted string. Consume immediately before any function calls.
199 char m_tempFormatBuffer[STRING_BUFFER_LEN];
200
201 // Signature buffer.
202 CQuickBytes m_sigBuf;
203};
204
205#endif
206