| 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 |
namespace Mono.Cecil.Metadata { |
| 30 |
|
| 31 |
using System; |
| 32 |
using System.Collections; |
| 33 |
using System.IO; |
| 34 |
|
| 35 |
internal class BlobHeap : MetadataHeap { |
| 36 |
|
| 37 |
internal BlobHeap (MetadataStream stream) : base (stream, MetadataStream.Blob) |
| 38 |
{ |
| 39 |
} |
| 40 |
|
| 41 |
public byte [] Read (uint index) |
| 42 |
{ |
| 43 |
return ReadBytesFromStream (index); |
| 44 |
} |
| 45 |
|
| 46 |
public BinaryReader GetReader (uint index) |
| 47 |
{ |
| 48 |
return new BinaryReader (new MemoryStream (Read (index))); |
| 49 |
} |
| 50 |
|
| 51 |
public override void Accept (IMetadataVisitor visitor) |
| 52 |
{ |
| 53 |
visitor.VisitBlobHeap (this); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
class ByteArrayEqualityComparer : IHashCodeProvider, IComparer { |
| 58 |
|
| 59 |
public static readonly ByteArrayEqualityComparer Instance = new ByteArrayEqualityComparer (); |
| 60 |
|
| 61 |
public int GetHashCode (object obj) |
| 62 |
{ |
| 63 |
byte [] array = (byte []) obj; |
| 64 |
|
| 65 |
int hash = 0; |
| 66 |
for (int i = 0; i < array.Length; i++) |
| 67 |
hash = (hash * 37) ^ array [i]; |
| 68 |
|
| 69 |
return hash; |
| 70 |
} |
| 71 |
|
| 72 |
public int Compare (object a, object b) |
| 73 |
{ |
| 74 |
byte [] x = (byte []) a; |
| 75 |
byte [] y = (byte []) b; |
| 76 |
|
| 77 |
if (x == null || y == null) |
| 78 |
return x == y ? 0 : 1; |
| 79 |
|
| 80 |
if (x.Length != y.Length) |
| 81 |
return 1; |
| 82 |
|
| 83 |
for (int i = 0; i < x.Length; i++) |
| 84 |
if (x [i] != y [i]) |
| 85 |
return 1; |
| 86 |
|
| 87 |
return 0; |
| 88 |
} |
| 89 |
} |
| 90 |
} |