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

MDTable.cs « metadata « Mono.PEToolkit « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 418fcd219b5e908eb3ce377e6868829cebc85c87 (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
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
/*
 * Copyright (c) 2002 Sergey Chaban <serge@wildwestsoftware.com>
 */

using System;
using System.IO;
using System.Collections;
using System.Runtime.InteropServices;

namespace Mono.PEToolkit.Metadata {

	public interface MDTable {
		/// <summary>
		/// Number of rows in the table.
		/// </summary>
		int NumberOfRows {get;}

		/// <summary>
		/// Gets ot sets a row in the metadata table.
		/// </summary>
		Row this [int rowNum] {get; set;}

		void Add(Row row);

		void FromRawData(byte [] buff, int offs, int numRows);

		string Name {get;}

		TableId Id {get;}

		MDHeap Heap {get;}

		void Dump(TextWriter writer);
	}


	public abstract class MDTableBase : MDTable {
		protected ArrayList rows; // rows storage
		protected MDHeap heap;    // base heap

		public MDTableBase(MDHeap heap)
		{
			rows = new ArrayList();
			this.heap = heap;

			if (heap is TablesHeap) {
				(heap as TablesHeap).RegisterTable(this);
			}
		}

		public virtual int NumberOfRows {
			get {
				return rows.Count;
			}
		}


		public virtual Row this [int rowNum] {
			get {
				if (rowNum < 0) throw new IndexOutOfRangeException("Row[]");

				// Zero row, special case
				if (rowNum == 0) return NullRow.Instance;
				return rows [rowNum - 1] as Row;
			}
			set {
				rows.Insert(rowNum, value);
			}
		}

		public virtual void Add(Row row)
		{
			rows.Add(row);
		}

		public abstract void FromRawData(byte [] buff, int offs, int numRows);

		public abstract string Name {get;}

		public abstract TableId Id {get;}

		public virtual MDHeap Heap {
			get {
				return heap;
			}
		}

		public virtual void Dump(TextWriter writer)
		{
			writer.WriteLine("=========================================");
			writer.WriteLine("Table '{0}', id = {1} (0x{2}), rows = {3}",
				Name, Id, ((int) Id).ToString("X"), NumberOfRows);
			int n = 1;
			foreach (Row row in rows) {
				writer.WriteLine();
				writer.WriteLine("Row #{0}", n++);
				writer.WriteLine("-------------");
				row.Dump(writer);
				writer.WriteLine();
			}
		}

	}

}