Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BlobHeap.cs « Mono.Cecil.Metadata - github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 574a130c985b1c7d758ee6a9d965687482737ea9 (plain)
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
//
// Author:
//   Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//

using System;

namespace Mono.Cecil.Metadata {

	sealed class BlobHeap : Heap {

		public BlobHeap (byte [] data)
			: base (data)
		{
		}

		public byte [] Read (uint index)
		{
			if (index == 0 || index > this.data.Length - 1)
				return Empty<byte>.Array;

			int position = (int) index;
			int length = (int) data.ReadCompressedUInt32 (ref position);

			if (length > data.Length - position)
				return Empty<byte>.Array;

			var buffer = new byte [length];

			Buffer.BlockCopy (data, position, buffer, 0, length);

			return buffer;
		}

		public void GetView (uint signature, out byte [] buffer, out int index, out int length)
		{
			if (signature == 0 || signature > data.Length - 1) {
				buffer = null;
				index = length = 0;
				return;
			}

			buffer = data;

			index = (int) signature;
			length = (int) buffer.ReadCompressedUInt32 (ref index);
		}
	}
}