Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MethodBodyBlock.cs
Go to the documentation of this file.
3
5
6public sealed class MethodBodyBlock
7{
8 private readonly MemoryBlock _il;
9
10 private readonly int _size;
11
12 private readonly ushort _maxStack;
13
14 private readonly bool _localVariablesInitialized;
15
17
19
20 public int Size => _size;
21
22 public int MaxStack => _maxStack;
23
25
27
29
30 private MethodBodyBlock(bool localVariablesInitialized, ushort maxStack, StandaloneSignatureHandle localSignatureHandle, MemoryBlock il, ImmutableArray<ExceptionRegion> exceptionRegions, int size)
31 {
32 _localVariablesInitialized = localVariablesInitialized;
33 _maxStack = maxStack;
34 _localSignature = localSignatureHandle;
35 _il = il;
36 _exceptionRegions = exceptionRegions;
37 _size = size;
38 }
39
40 public byte[]? GetILBytes()
41 {
42 return _il.ToArray();
43 }
44
50
52 {
53 return new BlobReader(_il);
54 }
55
56 public static MethodBodyBlock Create(BlobReader reader)
57 {
58 int offset = reader.Offset;
59 byte b = reader.ReadByte();
60 int num;
61 if ((b & 3) == 2)
62 {
63 num = b >> 2;
64 return new MethodBodyBlock(localVariablesInitialized: false, 8, default(StandaloneSignatureHandle), reader.GetMemoryBlockAt(0, num), ImmutableArray<ExceptionRegion>.Empty, 1 + num);
65 }
66 if ((b & 3) != 3)
67 {
69 }
70 byte b2 = reader.ReadByte();
71 if (b2 >> 4 != 3)
72 {
74 }
75 bool localVariablesInitialized = (b & 0x10) == 16;
76 bool flag = (b & 8) == 8;
77 ushort maxStack = reader.ReadUInt16();
78 num = reader.ReadInt32();
79 int num2 = reader.ReadInt32();
80 StandaloneSignatureHandle localSignatureHandle;
81 if (num2 == 0)
82 {
83 localSignatureHandle = default(StandaloneSignatureHandle);
84 }
85 else
86 {
87 if (((ulong)num2 & 0x7F000000uL) != 285212672)
88 {
90 }
91 localSignatureHandle = StandaloneSignatureHandle.FromRowId(num2 & 0xFFFFFF);
92 }
93 MemoryBlock memoryBlockAt = reader.GetMemoryBlockAt(0, num);
94 reader.Offset += num;
95 ImmutableArray<ExceptionRegion> exceptionRegions;
96 if (flag)
97 {
98 reader.Align(4);
99 byte b3 = reader.ReadByte();
100 if ((b3 & 1) != 1)
101 {
103 }
104 bool flag2 = (b3 & 0x40) == 64;
105 int num3 = reader.ReadByte();
106 if (flag2)
107 {
108 num3 += reader.ReadUInt16() << 8;
109 exceptionRegions = ReadFatExceptionHandlers(ref reader, num3 / 24);
110 }
111 else
112 {
113 reader.Offset += 2;
114 exceptionRegions = ReadSmallExceptionHandlers(ref reader, num3 / 12);
115 }
116 }
117 else
118 {
119 exceptionRegions = ImmutableArray<ExceptionRegion>.Empty;
120 }
121 return new MethodBodyBlock(localVariablesInitialized, maxStack, localSignatureHandle, memoryBlockAt, exceptionRegions, reader.Offset - offset);
122 }
123
125 {
127 for (int i = 0; i < array.Length; i++)
128 {
129 ExceptionRegionKind kind = (ExceptionRegionKind)memReader.ReadUInt16();
130 ushort tryOffset = memReader.ReadUInt16();
131 byte tryLength = memReader.ReadByte();
132 ushort handlerOffset = memReader.ReadUInt16();
133 byte handlerLength = memReader.ReadByte();
134 int classTokenOrFilterOffset = memReader.ReadInt32();
135 array[i] = new ExceptionRegion(kind, tryOffset, tryLength, handlerOffset, handlerLength, classTokenOrFilterOffset);
136 }
137 return ImmutableArray.Create(array);
138 }
139
141 {
143 for (int i = 0; i < array.Length; i++)
144 {
145 ExceptionRegionKind kind = (ExceptionRegionKind)memReader.ReadUInt32();
146 int tryOffset = memReader.ReadInt32();
147 int tryLength = memReader.ReadInt32();
148 int handlerOffset = memReader.ReadInt32();
149 int handlerLength = memReader.ReadInt32();
150 int classTokenOrFilterOffset = memReader.ReadInt32();
151 array[i] = new ExceptionRegion(kind, tryOffset, tryLength, handlerOffset, handlerLength, classTokenOrFilterOffset);
152 }
153 return ImmutableArray.Create(array);
154 }
155}
static readonly ImmutableArray< T > Empty
static ImmutableArray< byte > DangerousCreateFromUnderlyingArray(ref byte[]? array)
readonly StandaloneSignatureHandle _localSignature
static ImmutableArray< ExceptionRegion > ReadSmallExceptionHandlers(ref BlobReader memReader, int count)
static MethodBodyBlock Create(BlobReader reader)
MethodBodyBlock(bool localVariablesInitialized, ushort maxStack, StandaloneSignatureHandle localSignatureHandle, MemoryBlock il, ImmutableArray< ExceptionRegion > exceptionRegions, int size)
ImmutableArray< ExceptionRegion > ExceptionRegions
readonly ImmutableArray< ExceptionRegion > _exceptionRegions
static ImmutableArray< ExceptionRegion > ReadFatExceptionHandlers(ref BlobReader memReader, int count)
static string InvalidSehHeader
Definition SR.cs:34
static string InvalidMethodHeader1
Definition SR.cs:28
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string InvalidLocalSignatureToken
Definition SR.cs:24
static string InvalidMethodHeader2
Definition SR.cs:30
Definition SR.cs:7
unsafe MemoryBlock GetMemoryBlockAt(int offset, int length)
static StandaloneSignatureHandle FromRowId(int rowId)