Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AssemblyName.cs
Go to the documentation of this file.
4using System.IO;
7using System.Text;
8
9namespace System.Reflection;
10
12{
13 private string _name;
14
15 private byte[] _publicKey;
16
17 private byte[] _publicKeyToken;
18
20
21 private string _codeBase;
22
24
26
28
30
31 internal const char c_DummyChar = '\uffff';
32
33 private const short c_MaxAsciiCharsReallocate = 40;
34
35 private const short c_MaxUnicodeCharsReallocate = 40;
36
37 private const short c_MaxUTF_8BytesPerUnicodeChar = 4;
38
39 private const short c_EncodedCharsPerByte = 3;
40
41 private const string RFC3986ReservedMarks = ":/?#[]@!$&'()*+,;=";
42
43 private const string RFC3986UnreservedMarks = "-._~";
44
45 public string? Name
46 {
47 get
48 {
49 return _name;
50 }
51 set
52 {
53 _name = value;
54 }
55 }
56
58 {
59 get
60 {
61 return _version;
62 }
63 set
64 {
66 }
67 }
68
70 {
71 get
72 {
73 return _cultureInfo;
74 }
75 set
76 {
78 }
79 }
80
81 public string? CultureName
82 {
83 get
84 {
85 return _cultureInfo?.Name;
86 }
87 set
88 {
89 _cultureInfo = ((value == null) ? null : new CultureInfo(value));
90 }
91 }
92
93 public string? CodeBase
94 {
95 [RequiresAssemblyFiles("The code will return an empty string for assemblies embedded in a single-file app")]
96 get
97 {
98 return _codeBase;
99 }
100 set
101 {
103 }
104 }
105
106 [RequiresAssemblyFiles("The code will return an empty string for assemblies embedded in a single-file app")]
107 public string? EscapedCodeBase
108 {
109 get
110 {
111 if (_codeBase == null)
112 {
113 return null;
114 }
116 }
117 }
118
120 {
121 get
122 {
123 int num = (int)(_flags & (AssemblyNameFlags)112) >> 4;
124 if (num > 5)
125 {
126 num = 0;
127 }
128 return (ProcessorArchitecture)num;
129 }
130 set
131 {
132 int num = (int)(value & (ProcessorArchitecture)7);
133 if (num <= 5)
134 {
135 _flags = (AssemblyNameFlags)((long)_flags & 0xFFFFFF0FL);
136 _flags |= (AssemblyNameFlags)(num << 4);
137 }
138 }
139 }
140
142 {
143 get
144 {
145 int num = (int)(_flags & (AssemblyNameFlags)3584) >> 9;
146 if (num > 1)
147 {
148 num = 0;
149 }
150 return (AssemblyContentType)num;
151 }
152 set
153 {
154 int num = (int)(value & (AssemblyContentType)7);
155 if (num <= 1)
156 {
157 _flags = (AssemblyNameFlags)((long)_flags & 0xFFFFF1FFL);
158 _flags |= (AssemblyNameFlags)(num << 9);
159 }
160 }
161 }
162
163 public AssemblyNameFlags Flags
164 {
165 get
166 {
167 return _flags & (AssemblyNameFlags)(-3825);
168 }
169 set
170 {
171 _flags &= (AssemblyNameFlags)3824;
172 _flags |= value & (AssemblyNameFlags)(-3825);
173 }
174 }
175
177 {
178 get
179 {
180 return _hashAlgorithm;
181 }
182 set
183 {
185 }
186 }
187
189 {
190 get
191 {
193 }
194 set
195 {
197 }
198 }
199
200 [Obsolete("Strong name signing is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0017", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
212
213 public string FullName
214 {
215 get
216 {
217 if (string.IsNullOrEmpty(Name))
218 {
219 return string.Empty;
220 }
223 }
224 }
225
227 {
228 if (assemblyName == null)
229 {
230 throw new ArgumentNullException("assemblyName");
231 }
232 if (assemblyName.Length == 0 || assemblyName[0] == '\0')
233 {
235 }
237 nInit();
238 }
239
252
253 [MethodImpl(MethodImplOptions.InternalCall)]
254 internal extern void nInit();
255
256 [MethodImpl(MethodImplOptions.InternalCall)]
257 internal static extern AssemblyName nGetFileInformation(string s);
258
264
265 [MethodImpl(MethodImplOptions.InternalCall)]
266 private extern byte[] ComputePublicKeyToken();
267
272
274 {
275 if ((flags & (AssemblyNameFlags)240) == (AssemblyNameFlags)112)
276 {
277 return ProcessorArchitecture.None;
278 }
279 if ((pek & PortableExecutableKinds.PE32Plus) == PortableExecutableKinds.PE32Plus)
280 {
281 switch (ifm)
282 {
283 case ImageFileMachine.IA64:
284 return ProcessorArchitecture.IA64;
285 case ImageFileMachine.AMD64:
286 return ProcessorArchitecture.Amd64;
287 case ImageFileMachine.I386:
288 if ((pek & PortableExecutableKinds.ILOnly) == PortableExecutableKinds.ILOnly)
289 {
290 return ProcessorArchitecture.MSIL;
291 }
292 break;
293 }
294 }
295 else
296 {
297 switch (ifm)
298 {
299 case ImageFileMachine.I386:
300 if ((pek & PortableExecutableKinds.Required32Bit) == PortableExecutableKinds.Required32Bit)
301 {
302 return ProcessorArchitecture.X86;
303 }
304 if ((pek & PortableExecutableKinds.ILOnly) == PortableExecutableKinds.ILOnly)
305 {
306 return ProcessorArchitecture.MSIL;
307 }
308 return ProcessorArchitecture.X86;
309 case ImageFileMachine.ARM:
310 return ProcessorArchitecture.Arm;
311 }
312 }
313 return ProcessorArchitecture.None;
314 }
315
317 {
319 }
320
321 public object Clone()
322 {
323 return new AssemblyName
324 {
325 _name = _name,
326 _publicKey = (byte[])_publicKey?.Clone(),
330 _flags = _flags,
334 };
335 }
336
338 {
339 if (assemblyFile == null)
340 {
341 throw new ArgumentNullException("assemblyFile");
342 }
344 }
345
346 public byte[]? GetPublicKey()
347 {
348 return _publicKey;
349 }
350
351 public void SetPublicKey(byte[]? publicKey)
352 {
354 if (publicKey == null)
355 {
356 _flags &= ~AssemblyNameFlags.PublicKey;
357 }
358 else
359 {
360 _flags |= AssemblyNameFlags.PublicKey;
361 }
362 }
363
364 public byte[]? GetPublicKeyToken()
365 {
367 }
368
370 {
372 }
373
374 public override string ToString()
375 {
376 string fullName = FullName;
377 if (fullName == null)
378 {
379 return base.ToString();
380 }
381 return fullName;
382 }
383
385 {
387 }
388
389 public void OnDeserialization(object? sender)
390 {
392 }
393
395 {
396 if (reference == definition)
397 {
398 return true;
399 }
400 if (reference == null)
401 {
402 throw new ArgumentNullException("reference");
403 }
404 if (definition == null)
405 {
406 throw new ArgumentNullException("definition");
407 }
408 string text = reference.Name ?? string.Empty;
409 string value = definition.Name ?? string.Empty;
410 return text.Equals(value, StringComparison.OrdinalIgnoreCase);
411 }
412
413 [RequiresAssemblyFiles("The code will return an empty string for assemblies embedded in a single-file app")]
414 internal static string EscapeCodeBase(string codebase)
415 {
416 if (codebase == null)
417 {
418 return string.Empty;
419 }
420 int destPos = 0;
421 char[] array = EscapeString(codebase, 0, codebase.Length, null, ref destPos, isUriString: true, '\uffff', '\uffff', '\uffff');
422 if (array == null)
423 {
424 return codebase;
425 }
426 return new string(array, 0, destPos);
427 }
428
429 internal unsafe static char[] EscapeString(string input, int start, int end, char[] dest, ref int destPos, bool isUriString, char force1, char force2, char rsvd)
430 {
431 int i = start;
432 int num = start;
433 byte* ptr = stackalloc byte[160];
434 fixed (char* ptr2 = input)
435 {
436 for (; i < end; i++)
437 {
438 char c = ptr2[i];
439 if (c > '\u007f')
440 {
441 short num2 = (short)Math.Min(end - i, 39);
442 short num3 = 1;
443 while (num3 < num2 && ptr2[i + num3] > '\u007f')
444 {
445 num3++;
446 }
447 if (ptr2[i + num3 - 1] >= '\ud800' && ptr2[i + num3 - 1] <= '\udbff')
448 {
449 if (num3 == 1 || num3 == end - i)
450 {
452 }
453 num3++;
454 }
455 dest = EnsureDestinationSize(ptr2, dest, i, (short)(num3 * 4 * 3), 480, ref destPos, num);
456 short num4 = (short)Encoding.UTF8.GetBytes(ptr2 + i, num3, ptr, 160);
457 if (num4 == 0)
458 {
460 }
461 i += num3 - 1;
462 for (num3 = 0; num3 < num4; num3++)
463 {
465 }
466 num = i + 1;
467 }
468 else if (c == '%' && rsvd == '%')
469 {
470 dest = EnsureDestinationSize(ptr2, dest, i, 3, 120, ref destPos, num);
471 if (i + 2 < end && HexConverter.IsHexChar(ptr2[i + 1]) && HexConverter.IsHexChar(ptr2[i + 2]))
472 {
473 dest[destPos++] = '%';
474 dest[destPos++] = ptr2[i + 1];
475 dest[destPos++] = ptr2[i + 2];
476 i += 2;
477 }
478 else
479 {
481 }
482 num = i + 1;
483 }
484 else if (c == force1 || c == force2 || (c != rsvd && (isUriString ? (!IsReservedUnreservedOrHash(c)) : (!IsUnreserved(c)))))
485 {
486 dest = EnsureDestinationSize(ptr2, dest, i, 3, 120, ref destPos, num);
488 num = i + 1;
489 }
490 }
491 if (num != i && (num != start || dest != null))
492 {
493 dest = EnsureDestinationSize(ptr2, dest, i, 0, 0, ref destPos, num);
494 }
495 }
496 return dest;
497 }
498
499 private unsafe static char[] EnsureDestinationSize(char* pStr, char[] dest, int currentInputPos, short charsToAdd, short minReallocateChars, ref int destPos, int prevInputPos)
500 {
501 if (dest == null || dest.Length < destPos + (currentInputPos - prevInputPos) + charsToAdd)
502 {
504 if (dest != null && destPos != 0)
505 {
506 Buffer.BlockCopy(dest, 0, array, 0, destPos << 1);
507 }
508 dest = array;
509 }
511 {
513 }
514 return dest;
515 }
516
517 internal static void EscapeAsciiChar(char ch, char[] to, ref int pos)
518 {
519 to[pos++] = '%';
520 to[pos++] = HexConverter.ToCharUpper((int)ch >> 4);
521 to[pos++] = HexConverter.ToCharUpper(ch);
522 }
523
524 private static bool IsReservedUnreservedOrHash(char c)
525 {
526 if (IsUnreserved(c))
527 {
528 return true;
529 }
530 return ":/?#[]@!$&'()*+,;=".Contains(c);
531 }
532
533 internal static bool IsUnreserved(char c)
534 {
536 {
537 return true;
538 }
539 return "-._~".Contains(c);
540 }
541
542 internal static bool IsAsciiLetter(char character)
543 {
544 if (character < 'a' || character > 'z')
545 {
546 if (character >= 'A')
547 {
548 return character <= 'Z';
549 }
550 return false;
551 }
552 return true;
553 }
554
555 internal static bool IsAsciiLetterOrDigit(char character)
556 {
558 {
559 if (character >= '0')
560 {
561 return character <= '9';
562 }
563 return false;
564 }
565 return true;
566 }
567}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
static bool IsHexChar(int c)
static char ToCharUpper(int value)
static string GetFullPath(string path)
Definition Path.cs:881
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static string ComputeDisplayName(string name, Version version, string cultureName, byte[] pkt, AssemblyNameFlags flags=AssemblyNameFlags.None, AssemblyContentType contentType=AssemblyContentType.Default)
static bool IsUnreserved(char c)
AssemblyVersionCompatibility _versionCompatibility
AssemblyName(string name, byte[] publicKey, byte[] publicKeyToken, Version version, CultureInfo cultureInfo, AssemblyHashAlgorithm hashAlgorithm, AssemblyVersionCompatibility versionCompatibility, string codeBase, AssemblyNameFlags flags)
static bool IsAsciiLetterOrDigit(char character)
void SetPublicKeyToken(byte[]? publicKeyToken)
static AssemblyName GetFileInformationCore(string assemblyFile)
const short c_MaxUTF_8BytesPerUnicodeChar
void OnDeserialization(object? sender)
static void EscapeAsciiChar(char ch, char[] to, ref int pos)
AssemblyHashAlgorithm _hashAlgorithm
static unsafe char[] EnsureDestinationSize(char *pStr, char[] dest, int currentInputPos, short charsToAdd, short minReallocateChars, ref int destPos, int prevInputPos)
void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm)
AssemblyContentType ContentType
static bool IsReservedUnreservedOrHash(char c)
AssemblyVersionCompatibility VersionCompatibility
static bool IsAsciiLetter(char character)
static AssemblyName nGetFileInformation(string s)
static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags)
AssemblyHashAlgorithm HashAlgorithm
static string EscapeCodeBase(string codebase)
static AssemblyName GetAssemblyName(string assemblyFile)
AssemblyName(string assemblyName)
void SetPublicKey(byte[]? publicKey)
static bool ReferenceMatchesDefinition(AssemblyName? reference, AssemblyName? definition)
static unsafe char[] EscapeString(string input, int start, int end, char[] dest, ref int destPos, bool isUriString, char force1, char force2, char rsvd)
void GetObjectData(SerializationInfo info, StreamingContext context)
static string Format_StringZeroLength
Definition SR.cs:1360
static string Arg_FormatException
Definition SR.cs:172
static string PlatformNotSupported_StrongNameSigning
Definition SR.cs:1798
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526