This repository was archived by the owner on Jan 23, 2023. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathsigparser.cpp
196 lines (165 loc) · 5.14 KB
/
sigparser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// sigparser.cpp
//
//
// Signature parsing code
//
#include"stdafx.h"
#include"sigparser.h"
#include"contract.h"
HRESULT SigParser::SkipExactlyOne()
{
CONTRACTL
{
INSTANCE_CHECK;
NOTHROW;
GC_NOTRIGGER;
FORBID_FAULT;
SUPPORTS_DAC;
}
CONTRACTL_END
CorElementType typ;
HRESULT hr = GetElemType(&typ);
IfFailRet(hr);
if (!CorIsPrimitiveType(typ))
{
switch ((DWORD)typ)
{
default:
// _ASSERT(!"Illegal or unimplement type in COM+ sig.");
return META_E_BAD_SIGNATURE;
break;
case ELEMENT_TYPE_VAR:
case ELEMENT_TYPE_MVAR:
IfFailRet(GetData(NULL)); // Skip variable number
break;
case ELEMENT_TYPE_VAR_ZAPSIG:
IfFailRet(GetData(NULL)); // Skip RID
break;
case ELEMENT_TYPE_OBJECT:
case ELEMENT_TYPE_STRING:
case ELEMENT_TYPE_TYPEDBYREF:
case ELEMENT_TYPE_CANON_ZAPSIG:
break;
case ELEMENT_TYPE_BYREF: //fallthru
case ELEMENT_TYPE_PTR:
case ELEMENT_TYPE_PINNED:
case ELEMENT_TYPE_SZARRAY:
case ELEMENT_TYPE_NATIVE_ARRAY_TEMPLATE_ZAPSIG:
case ELEMENT_TYPE_NATIVE_VALUETYPE_ZAPSIG:
IfFailRet(SkipExactlyOne()); // Skip referenced type
break;
case ELEMENT_TYPE_VALUETYPE: //fallthru
case ELEMENT_TYPE_CLASS:
IfFailRet(GetToken(NULL)); // Skip RID
break;
case ELEMENT_TYPE_MODULE_ZAPSIG:
IfFailRet(GetData(NULL)); // Skip index
IfFailRet(SkipExactlyOne()); // Skip type
break;
case ELEMENT_TYPE_FNPTR:
IfFailRet(SkipSignature());
break;
case ELEMENT_TYPE_ARRAY:
{
IfFailRet(SkipExactlyOne()); // Skip element type
ULONG rank;
IfFailRet(GetData(&rank)); // Get rank
if (rank)
{
ULONG nsizes;
IfFailRet(GetData(&nsizes)); // Get # of sizes
while (nsizes--)
{
IfFailRet(GetData(NULL)); // Skip size
}
ULONG nlbounds;
IfFailRet(GetData(&nlbounds)); // Get # of lower bounds
while (nlbounds--)
{
IfFailRet(GetData(NULL)); // Skip lower bounds
}
}
}
break;
case ELEMENT_TYPE_SENTINEL:
// Should be unreachable since GetElem strips it
break;
case ELEMENT_TYPE_INTERNAL:
IfFailRet(GetPointer(NULL));
break;
case ELEMENT_TYPE_GENERICINST:
IfFailRet(SkipExactlyOne()); // Skip generic type
ULONG argCnt;
IfFailRet(GetData(&argCnt)); // Get number of parameters
while (argCnt--)
{
IfFailRet(SkipExactlyOne()); // Skip the parameters
}
break;
}
}
return hr;
}
//---------------------------------------------------------------------------------------
//
// Skip only a method header signature - not the sigs of the args to the method.
//
HRESULT
SigParser::SkipMethodHeaderSignature(
ULONG * pcArgs)
{
CONTRACTL
{
INSTANCE_CHECK;
NOTHROW;
GC_NOTRIGGER;
FORBID_FAULT;
SUPPORTS_DAC;
}
CONTRACTL_END
HRESULT hr = S_OK;
// Skip calling convention
ULONG uCallConv;
IfFailRet(GetCallingConvInfo(&uCallConv));
if ((uCallConv == IMAGE_CEE_CS_CALLCONV_FIELD) ||
(uCallConv == IMAGE_CEE_CS_CALLCONV_LOCAL_SIG))
{
return META_E_BAD_SIGNATURE;
}
// Skip type parameter count
if (uCallConv & IMAGE_CEE_CS_CALLCONV_GENERIC)
IfFailRet(GetData(NULL));
// Get arg count;
IfFailRet(GetData(pcArgs));
// Skip return type;
IfFailRet(SkipExactlyOne());
return hr;
} // SigParser::SkipMethodHeaderSignature
//---------------------------------------------------------------------------------------
//
// Skip a sub signature (as immediately follows an ELEMENT_TYPE_FNPTR).
HRESULT SigParser::SkipSignature()
{
CONTRACTL
{
INSTANCE_CHECK;
NOTHROW;
GC_NOTRIGGER;
FORBID_FAULT;
SUPPORTS_DAC;
}
CONTRACTL_END
HRESULT hr = S_OK;
ULONG cArgs;
IfFailRet(SkipMethodHeaderSignature(&cArgs));
// Skip args.
while (cArgs) {
IfFailRet(SkipExactlyOne());
cArgs--;
}
return hr;
}