-
Notifications
You must be signed in to change notification settings - Fork 0
/
ILInstruction.vb
353 lines (341 loc) · 13.4 KB
/
ILInstruction.vb
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
Imports System.Reflection
Imports System.Reflection.Emit
Public MustInherit Class ILInstruction
Protected op_code As OpCode
Protected _offset As Int32
Protected _enclosingMethod As MethodBase
Protected m As [Module]
Protected GenericTypeArgs() As System.Type
Protected GenericTypes() As System.Type
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode)
_enclosingMethod = m_enclosingMethod
_offset = offset 1
op_code = opCode
m = [Assembly].GetAssembly(_enclosingMethod.DeclaringType).ManifestModule
If _enclosingMethod.ContainsGenericParameters Then
GenericTypeArgs = _enclosingMethod.GetGenericArguments
End If
If _enclosingMethod.DeclaringType.IsGenericType Then
GenericTypes = _enclosingMethod.DeclaringType.GetGenericArguments
End If
End Sub
Public ReadOnly Property IlOffset() As Integer
Get
Return _offset
End Get
End Property
Public ReadOnly Property Code() As OpCode
Get
Return op_code
End Get
End Property
Public MustOverride ReadOnly Property Value() As Object
Public Overridable Shadows Function ToString() As String
Dim xString As String = Hex(_offset).ToLower.PadLeft(4, "0"c)
Dim InstructionName As String = Me.op_code.Name
Return String.Format("IL_{0}:{1}{2}{3}{4}", xString, vbTab, InstructionName, vbTab, vbTab)
End Function
End Class
Public Class InlineNoneInstruction
Inherits ILInstruction
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode)
MyBase.New(m_enclosingMethod, offset, opCode)
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return Nothing
End Get
End Property
Public Overrides Function ToString() As String
Return MyBase.ToString()
End Function
End Class
Public Class ShortInlineBrTargetInstruction
Inherits ILInstruction
Private short_delta As [SByte]
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal shortdelta As SByte)
MyBase.New(m_enclosingMethod, offset, opCode)
short_delta = shortdelta
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return _offset short_delta 2
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString
Dim Label As String = "IL_" & Hex(_offset short_delta 2).ToLower.PadLeft(4, "0"c)
Return String.Format("{0}{1}", baseString, Label)
End Function
End Class
Public Class InlineBrTargetInstruction
Inherits ILInstruction
Private _delta As Int32
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal delta As [Int32])
MyBase.New(m_enclosingMethod, offset, opCode)
_delta = delta
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return _offset _delta 5
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString
Return String.Format("{0}{1}", baseString, "")
End Function
End Class
Public Class ShortInlinelInstruction
Inherits ILInstruction
Private _int8 As [SByte]
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal int8 As [SByte])
MyBase.New(m_enclosingMethod, offset, opCode)
_int8 = int8
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return _int8
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString()
Return String.Format("{0}{1}", baseString, Value)
End Function
End Class
Public Class InlinelInstruction
Inherits ILInstruction
Private _int32 As Int32
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal int32 As Int32)
MyBase.New(m_enclosingMethod, offset, opCode)
_int32 = int32
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return _int32
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString()
Return String.Format("{0}{1}", baseString, Value)
End Function
End Class
Public Class Inline8Instruction
Inherits ILInstruction
Private _int64 As Int64
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal int64 As Int64)
MyBase.New(m_enclosingMethod, offset, opCode)
_int64 = int64
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return _int64
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString()
Return String.Format("{0}{1}", baseString, Value)
End Function
End Class
Public Class ShortInlineRInstruction
Inherits ILInstruction
Private _float32 As [Single]
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal float32 As [Single])
MyBase.New(m_enclosingMethod, offset, opCode)
_float32 = float32
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return _float32
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString()
Return String.Format("{0}{1}", baseString, Value)
End Function
End Class
Public Class InlineRInstruction
Inherits ILInstruction
Private _float64 As [Double]
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal float64 As [Double])
MyBase.New(m_enclosingMethod, offset, opCode)
_float64 = float64
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return _float64
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString()
Return String.Format("{0}{1}", baseString, Value)
End Function
End Class
Public Class ShortInlineVarInstruction
Inherits ILInstruction
Private _index8 As [Byte]
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal index8 As [Byte])
MyBase.New(m_enclosingMethod, offset, opCode)
_index8 = index8
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return _index8
End Get
End Property
Public Overrides Function ToString() As String
Dim t As Type = MyBase._enclosingMethod.DeclaringType
Dim baseString As String = MyBase.ToString
Return String.Format("{0}{1}", baseString, "")
End Function
End Class
Public Class InlineVarInstruction
Inherits ILInstruction
Private _index16 As UInt16
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal index16 As UInt16)
MyBase.New(m_enclosingMethod, offset, opCode)
_index16 = index16
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return _index16
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString()
Return String.Format("{0}{1}", baseString, Value)
End Function
End Class
Public Class InlineStringInstruction
Inherits ILInstruction
Private _token As Int32
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal token As Int32)
MyBase.New(m_enclosingMethod, offset, opCode)
_token = token
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return m.ResolveString(_token)
End Get
End Property
Public Overrides Function ToString() As String
Dim t As Type = MyBase._enclosingMethod.DeclaringType
Dim baseString As String = MyBase.ToString
Return String.Format("{0}""{1}""", baseString, Me.Value)
End Function
End Class
Public Class InlineSigInstruction
Inherits ILInstruction
Private _token As Int32
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal token As Int32)
MyBase.New(m_enclosingMethod, offset, opCode)
_token = token
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return m.ResolveSignature(_token)
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString()
Return String.Format("{0}{1}", baseString, Value)
End Function
End Class
Public Class InlineFieldInstruction
Inherits ILInstruction
Private _token As Int32
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal token As Int32)
MyBase.New(m_enclosingMethod, offset, opCode)
_token = token
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return m.ResolveField(_token, GenericTypes, GenericTypeArgs)
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString()
Dim type As System.Type = Me.Value.DeclaringType
Dim assem As Assembly = Assembly.GetAssembly(type)
Return String.Format("{0}[{1}]{2}::{3}", baseString, assem.FullName.Split(",")(0), type, Me.Value.Name)
End Function
End Class
Public Class InlineTypeInstruction
Inherits ILInstruction
Private _token As Int32
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal token As Int32)
MyBase.New(m_enclosingMethod, offset, opCode)
_token = token
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return m.ResolveType(_token, GenericTypes, GenericTypeArgs)
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString
Return String.Format("{0}{1}", baseString, Value.ToString)
End Function
End Class
Public Class InlineTokInstruction
Inherits ILInstruction
Private _token As Int32
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal token As Int32)
MyBase.New(m_enclosingMethod, offset, opCode)
_token = token
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return m.ResolveMember(_token, GenericTypes, GenericTypeArgs)
End Get
End Property
End Class
Public Class InlineMethodInstruction
Inherits ILInstruction
Private _token As Int32
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal token As Int32)
MyBase.New(m_enclosingMethod, offset, opCode)
_token = token
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Return m.ResolveMethod(_token, GenericTypes, GenericTypeArgs)
End Get
End Property
Public Overrides Function ToString() As String
Dim t As Type = Value.DeclaringType
Dim Assem As Assembly = Assembly.GetAssembly(t)
Dim baseString As String = MyBase.ToString
Dim AssemblyName As String = Assem.FullName.Split(",")(0)
Dim paramString As String = String.Empty
For Each p As ParameterInfo In Value.GetParameters
paramString &= p.ParameterType.ToString & ","
Next
Return String.Format("{0}[{1}]{2}::{3}({4})", baseString, AssemblyName, t.FullName, Value.Name, paramString.TrimEnd(New Char() {Chr(32), ","c}))
End Function
End Class
Public Class InlineSwitchInstruction
Inherits ILInstruction
Private _deltas As Int32()
Public Sub New(ByVal m_enclosingMethod As MethodBase, ByVal offset As Int32, ByVal opCode As OpCode, ByVal deltas As Int32())
MyBase.New(m_enclosingMethod, offset, opCode)
_deltas = deltas
End Sub
Public Overrides ReadOnly Property Value() As Object
Get
Dim _offsets As New List(Of Int32)
For Each deltas As Int32 In _deltas
_offsets.Add(deltas 82)
Next
Return _offsets
End Get
End Property
Public Overrides Function ToString() As String
Dim baseString As String = MyBase.ToString
Dim Label As String = "( "
For i As Integer = 0 To _deltas.Count - 1
Label &= "IL_" & Hex(_deltas(i) 82).ToLower.PadLeft(4, "0"c) & ","
Next
Label &= " )"
Return String.Format("{0}{1}", baseString, Label)
End Function
End Class