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 | #include "formattype.h" |
6 | |
7 | #define MAX_INTERFACES_IMPLEMENTED 256 // unused |
8 | #define MAX_CLASSNAME_LENGTH 1024 // single global buffer size |
9 | #define MAX_MEMBER_LENGTH 1024 // single global buffer size |
10 | #define MAX_SIGNATURE_LENGTH 2048 // single global buffer size |
11 | #define DESCR_SIZE 8 // unused |
12 | |
13 | #define MAX_FILENAME_LENGTH 2048 //256 |
14 | |
15 | #define MODE_DUMP_ALL 0 |
16 | #define MODE_DUMP_CLASS 1 |
17 | #define MODE_DUMP_CLASS_METHOD 2 |
18 | #define MODE_DUMP_CLASS_METHOD_SIG 3 |
19 | #define MODE_GUI 4 |
20 | |
21 | BOOL Disassemble(IMDInternalImport *pImport, BYTE *pCode, void *GUICookie, mdToken FuncToken, ParamDescriptor* pszArgname, ULONG ulArgs); |
22 | BOOL Decompile(IMDInternalImport *pImport, BYTE *pCode); |
23 | OPCODE DecodeOpcode(const BYTE *pCode, DWORD *pdwLen); |
24 | struct LineCodeDescr |
25 | { |
26 | ULONG Line; |
27 | ULONG Column; |
28 | ULONG LineEnd; |
29 | ULONG ColumnEnd; |
30 | ULONG PC; |
31 | ULONG_PTR FileToken; |
32 | }; |
33 | |
34 | void printLine(void* GUICookie, __in __nullterminated const char* string); |
35 | void printLineW(void* GUICookie, __in __nullterminated const WCHAR* string); |
36 | void printError(void* GUICookie, __in __nullterminated const char* string); |
37 | |
38 | char* AnsiToUtf(__in __nullterminated const char* sz); |
39 | char* UnicodeToAnsi(__in __nullterminated const WCHAR* wz); |
40 | char* UnicodeToUtf(__in __nullterminated const WCHAR* wz); |
41 | WCHAR* UtfToUnicode(__in __nullterminated const char* sz); |
42 | WCHAR* AnsiToUnicode(__in __nullterminated const char* sz); |
43 | void GetInputFileFullPath(); |
44 | |
45 | char* RstrUTF(unsigned id); |
46 | WCHAR* RstrW(unsigned id); |
47 | char* RstrANSI(unsigned id); |
48 | |
49 | |
50 | BOOL DumpMethod(mdToken FuncToken, const char *pszClassName, DWORD dwEntryPointToken,void *GUICookie,BOOL DumpBody); |
51 | BOOL DumpField(mdToken FuncToken, const char *pszClassName,void *GUICookie, BOOL DumpBody); |
52 | BOOL DumpEvent(mdToken FuncToken, const char *pszClassName, DWORD dwClassAttrs, void *GUICookie, BOOL DumpBody); |
53 | BOOL DumpProp(mdToken FuncToken, const char *pszClassName, DWORD dwClassAttrs, void *GUICookie, BOOL DumpBody); |
54 | void dumpEHInfo(IMDInternalImport *pImport, void *GUICookie); |
55 | BOOL DumpClass(mdTypeDef cl, DWORD dwEntryPointToken, void* GUICookie, ULONG WhatToDump); |
56 | // WhatToDump: 0-title only; 1-pack,size and custom attrs; 2-everything |
57 | BOOL GetClassLayout(mdTypeDef cl, ULONG* pulPackSize, ULONG* pulClassSize); |
58 | void DumpCustomAttribute(mdCustomAttribute tkCA, void *GUICookie, bool bWithOwner); |
59 | void DumpCustomAttributes(mdToken tkOwner, void *GUICookie); |
60 | void DumpByteArray(__inout __nullterminated char* szString, const BYTE* pBlob, ULONG ulLen, void* GUICookie); |
61 | char* DumpDataPtr(__inout __nullterminated char* buffer, DWORD ptr, DWORD size); |
62 | |
63 | void PrettyPrintToken(__inout __nullterminated char* szString, mdToken tk, IMDInternalImport *pImport,void* GUICookie,mdToken FuncToken); //TypeDef,TypeRef,TypeSpec,MethodDef,FieldDef,MemberRef,MethodSpec,String |
64 | void DumpPermissions(mdToken tkOwner, void* GUICookie); |
65 | void (IMAGE_COR20_HEADER *, void* GUICookie); |
66 | void (IMAGE_COR20_HEADER *, void* GUICookie); |
67 | void DumpMetaInfo(__in __nullterminated const WCHAR* pszFileName, __in_opt __nullterminated const char* pszObjFileName, void* GUICookie); |
68 | void (IMAGE_COR20_HEADER *, void* GUICookie); |
69 | BOOL DumpFile(); |
70 | void Cleanup(); |
71 | void CreateProgressBar(LONG lRange); |
72 | BOOL ProgressStep(); |
73 | void DestroyProgressBar(); |
74 | char * DumpQString(void* GUICookie, |
75 | __in __nullterminated const char* szToDump, |
76 | __in __nullterminated const char* szPrefix, |
77 | unsigned uMaxLen); |
78 | void DumpVtable(void* GUICookie); |
79 | char* DumpUnicodeString(void* GUICookie, |
80 | __inout __nullterminated char* szString, |
81 | __in_ecount(cbString) WCHAR* pszString, |
82 | ULONG cbString, |
83 | bool SwapString = false); |
84 | |
85 | void TokenSigInit(IMDInternalImport *pImport); |
86 | void TokenSigDelete(); |
87 | bool IsSpecialNumber(const char*); |
88 | |
89 | |
90 | //---------------- see DMAN.CPP-------------------------------------------------- |
91 | struct LocalComTypeDescr |
92 | { |
93 | mdExportedType tkComTypeTok; |
94 | mdTypeDef tkTypeDef; |
95 | mdToken tkImplementation; |
96 | WCHAR* wzName; |
97 | DWORD dwFlags; |
98 | LocalComTypeDescr() { wzName=NULL; }; |
99 | ~LocalComTypeDescr() { if(wzName) SDELETE(wzName); }; |
100 | }; |
101 | |
102 | struct MTokName |
103 | { |
104 | mdFile tok; |
105 | WCHAR* name; |
106 | MTokName() { tok = 0; name = NULL; }; |
107 | ~MTokName() { if(name) SDELETE(name); }; |
108 | }; |
109 | extern BOOL g_fPrettyPrint; |
110 | extern MTokName* rExeloc; |
111 | extern ULONG nExelocs; |
112 | void DumpImplementation(mdToken tkImplementation, |
113 | DWORD dwOffset, |
114 | __inout __nullterminated char* szString, |
115 | void* GUICookie); |
116 | void DumpComType(LocalComTypeDescr* pCTD, |
117 | __inout __nullterminated char* szString, |
118 | void* GUICookie); |
119 | void DumpManifest(void* GUICookie); |
120 | void DumpTypedefs(void* GUICookie); |
121 | IMetaDataAssemblyImport* GetAssemblyImport(void* GUICookie); |
122 | |
123 | void DumpRTFPrefix(void* GUICookie, BOOL fFontDefault); |
124 | void DumpRTFPostfix(void* GUICookie); |
125 | |
126 | //------------------------------------------------------------------------------- |
127 | #define NEW_TRY_BLOCK 0x80000000 |
128 | #define PUT_INTO_CODE 0x40000000 |
129 | #define ERR_OUT_OF_CODE 0x20000000 |
130 | #define SEH_NEW_PUT_MASK (NEW_TRY_BLOCK | PUT_INTO_CODE | ERR_OUT_OF_CODE) |
131 | //------------------------------------------------------------------------------- |
132 | |
133 | // As much as 2 * SZSTRING_SIZE seems to be needed for some corner cases. ILDasm is |
134 | // unfortunately full of constants and artificial limits, and may produce invalid |
135 | // output or overrun a buffer when fed with something unusual (like a type with |
136 | // thousands of generic parameters). Fixing all such problems effectively means |
137 | // rewriting the tool from scratch. Until this happens, let's at least try to keep it |
138 | // working for reasonable input. |
139 | #define UNIBUF_SIZE 262144 |
140 | extern WCHAR wzUniBuf[]; // defined in dis.cpp |
141 | |
142 | #define SZSTRING_SIZE 131072 |
143 | extern char szString[]; // defined in dis.cpp |
144 | |
145 | char *DumpGenericPars(__inout_ecount(SZSTRING_SIZE) char* szString, |
146 | mdToken tok, |
147 | void* GUICookie=NULL, |
148 | BOOL fSplit=FALSE); |
149 | |
150 | #include "safemath.h" |
151 | #define SZSTRING_SIZE_M4 (SZSTRING_SIZE - 4) |
152 | #define CHECK_REMAINING_SIZE if(ovadd_le((size_t)szString, SZSTRING_SIZE_M4, (size_t)szptr)) break; |
153 | #define SZSTRING_REMAINING_SIZE(x) (ovadd_le((size_t)szString,SZSTRING_SIZE,(size_t)(x))?0:(SZSTRING_SIZE-((size_t)(x)-(size_t)szString))) |
154 | |
155 | typedef int (STDAPICALLTYPE *MetaDataGetDispenserFunc) ( |
156 | REFCLSID rclsid, // The class to desired. |
157 | REFIID riid, // Interface wanted on class factory. |
158 | LPVOID FAR *ppv); // Return interface pointer here. |
159 | |
160 | typedef int (STDAPICALLTYPE *GetMetaDataInternalInterfaceFunc) ( |
161 | LPVOID pData, // [IN] in memory metadata section |
162 | ULONG cbData, // [IN] size of the metadata section |
163 | DWORD flags, // [IN] CorOpenFlags |
164 | REFIID riid, // [IN] desired interface |
165 | void **ppv); // [OUT] returned interface |
166 | |
167 | typedef int (STDAPICALLTYPE *GetMetaDataInternalInterfaceFromPublicFunc) ( |
168 | IUnknown *pv, // [IN] Given interface |
169 | REFIID riid, // [IN] desired interface |
170 | void **ppv); // [OUT] returned interface |
171 | |
172 | typedef int (STDAPICALLTYPE *GetMetaDataPublicInterfaceFromInternalFunc) ( |
173 | void *pv, // [IN] Given interface |
174 | REFIID riid, // [IN] desired interface |
175 | void **ppv); // [OUT] returned interface |
176 | |
177 | extern MetaDataGetDispenserFunc metaDataGetDispenser; |
178 | extern GetMetaDataInternalInterfaceFunc getMetaDataInternalInterface; |
179 | extern GetMetaDataInternalInterfaceFromPublicFunc getMetaDataInternalInterfaceFromPublic; |
180 | extern GetMetaDataPublicInterfaceFromInternalFunc getMetaDataPublicInterfaceFromInternal; |
181 | |
182 | |