1 <?xml version=
"1.0" encoding=
"iso-8859-1"?>
4 <xsl:stylesheet version=
"1.0" xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform">
6 <xsl:import href=
"gen-utils.xsl"/>
7 <xsl:output method=
"text"/>
13 <xsl:template match=
"/">// Auto-generated file - DO NOT EDIT!
14 // Please edit md-schema.xml or rows.xsl if you want to make changes.
19 namespace Mono.PEToolkit.Metadata {
21 <xsl:for-each select=
"md-schema/tables/table">
24 /// Represents row in
<xsl:value-of select=
"@name"/> table.
27 ///
<xsl:if test=
"@section">See Partition II, Metadata; section
<xsl:value-of select=
"@section"/></xsl:if>
29 public class
<xsl:value-of select=
"@name"/>Row : Row {
31 private MDTable table;
33 <xsl:for-each select=
"schema/field">
34 public
<xsl:call-template name=
"get-field-type"/><xsl:value-of select=
"concat(' ',@name)"/>;
</xsl:for-each>
36 public
<xsl:value-of select=
"@name"/>Row()
40 public
<xsl:value-of select=
"@name"/>Row(MDTable parent)
47 /// Row in
<xsl:value-of select=
"@name"/> table has
<xsl:value-of select=
"count(schema/field)"/> columns.
49 public virtual int NumberOfColumns {
51 return
<xsl:value-of select=
"count(schema/field)"/>;
57 /// Logical size of this instance in bytes.
59 public virtual int Size {
68 public virtual MDTable Table {
76 /// Logical size of this type of row in bytes.
78 unsafe public static int LogicalSize {
80 return
<xsl:call-template name=
"get-expanded-size"/>;
86 /// Fills the row from the array of bytes.
88 unsafe public void FromRawData(byte [] buff, int offs)
90 if (buff == null) throw new Exception(
"buff == null");
91 if (offs + Size
> buff.Length) throw new Exception(
"bounds");
93 <xsl:for-each select=
"schema/field">
94 this.
<xsl:value-of select=
"@name"/> =
<xsl:call-template name=
"get-field-conversion-code"/>;
95 <xsl:if test=
"position() != last()">
96 <xsl:text>offs +=
</xsl:text>
97 <xsl:call-template name=
"get-expanded-size">
98 <xsl:with-param name=
"fields" select=
"."/>
100 <xsl:text>;
</xsl:text>
105 <xsl:variable name=
"spaces" select=
"' '"/>
109 public void Dump(TextWriter writer) {
110 <xsl:text>string dump = String.Format(
</xsl:text>
111 <xsl:for-each select=
"schema/field">
112 "<xsl:value-of select="concat(@name,substring($spaces,
1,
18 - string-length(@name)))
"/>: {<xsl:value-of select="position () -
1"/>}" <xsl:text>+ Environment.NewLine
</xsl:text>
113 <xsl:if test=
"position() != last()"><xsl:text> +
</xsl:text></xsl:if>
114 <xsl:if test=
"position() = last()"><xsl:text>,
</xsl:text></xsl:if>
116 <xsl:for-each select=
"schema/field">
117 <xsl:choose><!-- TODO: do something about ugly expression below -->
118 <xsl:when test=
"contains(@type,'#Strings')">
119 (
<xsl:text>Table == null) ?
</xsl:text>
120 <xsl:value-of select=
"concat(@name, '.ToString()')"/>
121 <xsl:text> :
"\"" + ((Table.Heap.Stream.Root.Streams["#Strings
"] as MDStream).Heap as StringsHeap) [</xsl:text>
122 <xsl:value-of select="@name
"/><xsl:text>] + "\
" (#Strings[0x" +
</xsl:text><xsl:value-of select=
"@name"/><xsl:text>.ToString(
"X") +
"])"</xsl:text>
124 <xsl:when test=
"contains(@type,'index') and not(contains(@type,'coded-index'))">
125 "<xsl:call-template name=
"extract-arg"/>[
" +
<xsl:value-of select=
"@name"/><xsl:text>.ToString() +
"]"</xsl:text>
128 this.
<xsl:value-of select=
"@name"/>
131 <xsl:if test=
"position() != last()"><xsl:text>,
</xsl:text></xsl:if>
134 writer.WriteLine(dump);
140 public override string ToString()
142 StringWriter sw = new StringWriter();
144 return sw.ToString();
160 <!-- ******************************************************************* -->
161 <xsl:template name=
"get-field-conversion-code">
162 <xsl:param name=
"field" select=
"."/>
163 <xsl:variable name=
"type" select=
"$field/@type"/>
166 <!-- RVA - library type -->
167 <xsl:when test=
"$type = 'RVA'">
168 <xsl:text>LEBitConverter.ToUInt32(buff, offs)
</xsl:text>
171 <!-- table indices -->
172 <xsl:when test=
"starts-with($type,'index')">
173 <xsl:text>LEBitConverter.ToInt32(buff, offs)
</xsl:text>
176 <!-- coded tokens -->
177 <xsl:when test=
"starts-with($type,'coded-index')">
178 <xsl:text>TabsDecoder.DecodeToken(CodedTokenId.
</xsl:text>
179 <xsl:call-template name=
"extract-arg">
180 <xsl:with-param name=
"expr" select=
"$type"/>
182 <xsl:text>, LEBitConverter.ToInt32(buff, offs))
</xsl:text>
185 <!-- primitive type -->
187 <!-- explicitly mapped to library type -->
188 <xsl:if test=
"$field/@cli-type">
189 <xsl:value-of select=
"concat('(', $field/@cli-type, ') ')"/>
192 <xsl:when test=
"$type = 'byte'">
193 <xsl:text>buff [offs]
</xsl:text>
195 <xsl:when test=
"$type = 'short'">
196 <xsl:text>LEBitConverter.ToInt16(buff, offs)
</xsl:text>
198 <xsl:when test=
"$type = 'ushort'">
199 <xsl:text>LEBitConverter.ToUInt16(buff, offs)
</xsl:text>
201 <xsl:when test=
"$type = 'int'">
202 <xsl:text>LEBitConverter.ToInt32(buff, offs)
</xsl:text>
204 <xsl:when test=
"$type = 'uint'">
205 <xsl:text>LEBitConverter.ToUInt32(buff, offs)
</xsl:text>
207 <xsl:when test=
"$type = 'long'">
208 <xsl:text>LEBitConverter.ToInt64(buff, offs)
</xsl:text>
210 <xsl:when test=
"$type = 'ulong'">
211 <xsl:text>LEBitConverter.ToUInt64(buff, offs)
</xsl:text>
214 <xsl:text>/* ERROR! */
</xsl:text>