--- /dev/null
+//
+// BaseImageVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal abstract class BaseImageVisitor : IBinaryVisitor {
+
+ public virtual void VisitImage (Image img)
+ {
+ }
+
+ public virtual void VisitDOSHeader (DOSHeader header)
+ {
+ }
+
+ public virtual void VisitPEFileHeader (PEFileHeader header)
+ {
+ }
+
+ public virtual void VisitPEOptionalHeader (PEOptionalHeader header)
+ {
+ }
+
+ public virtual void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header)
+ {
+ }
+
+ public virtual void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header)
+ {
+ }
+
+ public virtual void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header)
+ {
+ }
+
+ public virtual void VisitSectionCollection (SectionCollection coll)
+ {
+ }
+
+ public virtual void VisitSection (Section section)
+ {
+ }
+
+ public virtual void VisitImportAddressTable (ImportAddressTable iat)
+ {
+ }
+
+ public virtual void VisitDebugHeader (DebugHeader dh)
+ {
+ }
+
+ public virtual void VisitCLIHeader (CLIHeader header)
+ {
+ }
+
+ public virtual void VisitImportTable (ImportTable it)
+ {
+ }
+
+ public virtual void VisitImportLookupTable (ImportLookupTable ilt)
+ {
+ }
+
+ public virtual void VisitHintNameTable (HintNameTable hnt)
+ {
+ }
+
+ public virtual void VisitExportTable (ExportTable et)
+ {
+ }
+
+ public virtual void TerminateImage (Image img)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// CLIHeader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal sealed class CLIHeader : IHeader, IBinaryVisitable {
+
+ public uint Cb;
+ public ushort MajorRuntimeVersion;
+ public ushort MinorRuntimeVersion;
+ public DataDirectory Metadata;
+ public RuntimeImage Flags;
+ public uint EntryPointToken;
+ public DataDirectory Resources;
+ public DataDirectory StrongNameSignature;
+ public DataDirectory CodeManagerTable;
+ public DataDirectory VTableFixups;
+ public DataDirectory ExportAddressTableJumps;
+ public DataDirectory ManagedNativeHeader;
+
+ public byte [] ImageHash;
+
+ internal CLIHeader ()
+ {
+ }
+
+ public void SetDefaultValues ()
+ {
+ Cb = 0x48;
+ Flags = RuntimeImage.ILOnly;
+ CodeManagerTable = DataDirectory.Zero;
+ ExportAddressTableJumps = DataDirectory.Zero;
+ ManagedNativeHeader = DataDirectory.Zero;
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitCLIHeader (this);
+ }
+ }
+}
--- /dev/null
+//
+// CopyImageVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ sealed class CopyImageVisitor : BaseImageVisitor {
+
+ Image m_newImage;
+ Image m_originalImage;
+
+ public CopyImageVisitor (Image originalImage)
+ {
+ m_originalImage = originalImage;
+ }
+
+ public override void VisitImage (Image img)
+ {
+ m_newImage = img;
+ if (m_originalImage.DebugHeader != null)
+ m_newImage.AddDebugHeader ();
+
+ m_newImage.CLIHeader.Flags = m_originalImage.CLIHeader.Flags;
+ }
+
+ public override void VisitDebugHeader (DebugHeader dbgHeader)
+ {
+ DebugHeader old = m_originalImage.DebugHeader;
+ dbgHeader.Age = old.Age;
+ dbgHeader.Characteristics = old.Characteristics;
+ dbgHeader.FileName = old.FileName;
+ dbgHeader.Signature = old.Signature;
+ dbgHeader.TimeDateStamp = ImageInitializer.TimeDateStampFromEpoch();
+ dbgHeader.Type = old.Type;
+ }
+
+ public override void VisitSectionCollection (SectionCollection sections)
+ {
+ Section old = null;
+ foreach (Section s in m_originalImage.Sections)
+ if (s.Name == Section.Resources)
+ old = s;
+
+ if (old == null)
+ return;
+
+ Section rsrc = new Section ();
+ rsrc.Characteristics = old.Characteristics;
+ rsrc.Name = old.Name;
+
+ sections.Add (rsrc);
+ }
+
+ public override void TerminateImage (Image img)
+ {
+ if (m_originalImage.ResourceDirectoryRoot == null)
+ return;
+
+ m_newImage.ResourceDirectoryRoot = CloneResourceDirectoryTable (m_originalImage.ResourceDirectoryRoot);
+ }
+
+ ResourceDirectoryTable CloneResourceDirectoryTable (ResourceDirectoryTable old)
+ {
+ ResourceDirectoryTable rdt = new ResourceDirectoryTable ();
+ foreach (ResourceDirectoryEntry oldEntry in old.Entries)
+ rdt.Entries.Add (CloneResourceDirectoryEntry (oldEntry));
+
+ return rdt;
+ }
+
+ ResourceDirectoryEntry CloneResourceDirectoryEntry (ResourceDirectoryEntry old)
+ {
+ ResourceDirectoryEntry rde;
+ if (old.IdentifiedByName)
+ rde = new ResourceDirectoryEntry(old.Name);
+ else
+ rde = new ResourceDirectoryEntry (old.ID);
+
+ if (old.Child is ResourceDirectoryTable)
+ rde.Child = CloneResourceDirectoryTable (old.Child as ResourceDirectoryTable);
+ else
+ rde.Child = CloneResourceDataEntry (old.Child as ResourceDataEntry);
+
+ return rde;
+ }
+
+ ResourceDataEntry CloneResourceDataEntry (ResourceDataEntry old)
+ {
+ ResourceDataEntry rde = new ResourceDataEntry ();
+ rde.Size = old.Size;
+ rde.Codepage = old.Codepage;
+ rde.ResourceData = old.ResourceData;
+
+ return rde;
+ }
+ }
+}
--- /dev/null
+//
+// DOSHeader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal sealed class DOSHeader : IHeader, IBinaryVisitable {
+
+ public byte [] Start;
+ public byte [] End;
+
+ public uint Lfanew;
+
+ internal DOSHeader ()
+ {
+ }
+
+ public void SetDefaultValues ()
+ {
+ Start = new byte [60] {
+ 0x4d, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x00,
+ 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff,
+ 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+ };
+ Lfanew = 128;
+ End = new byte [64] {
+ 0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09,
+ 0xcd, 0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21,
+ 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x72,
+ 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x20, 0x63,
+ 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x62,
+ 0x65, 0x20, 0x72, 0x75, 0x6e, 0x20, 0x69,
+ 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20, 0x6d,
+ 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
+ 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00
+ };
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitDOSHeader (this);
+ }
+ }
+}
--- /dev/null
+//
+// DataDirectory.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal struct DataDirectory {
+
+ public static readonly DataDirectory Zero = new DataDirectory (RVA.Zero, 0);
+
+ RVA m_virtualAddress;
+ uint m_size;
+
+ public RVA VirtualAddress {
+ get { return m_virtualAddress; }
+ set { m_virtualAddress = value; }
+ }
+
+ public uint Size {
+ get { return m_size; }
+ set { m_size = value; }
+ }
+
+ public DataDirectory (RVA virtualAddress, uint size)
+ {
+ m_virtualAddress = virtualAddress;
+ m_size = size;
+ }
+
+ public override int GetHashCode ()
+ {
+ return (m_virtualAddress.GetHashCode () ^ (int) m_size << 1);
+ }
+
+ public override bool Equals (object other)
+ {
+ if (other is DataDirectory) {
+ DataDirectory odd = (DataDirectory) other;
+ return this.m_virtualAddress == odd.m_virtualAddress && this.m_size == odd.m_size;
+ }
+
+ return false;
+ }
+
+ public override string ToString ()
+ {
+ return string.Format ("{0} [{1}]", m_virtualAddress, m_size.ToString ("X"));
+ }
+
+ public static bool operator == (DataDirectory one, DataDirectory other)
+ {
+ return one.m_virtualAddress == other.m_virtualAddress && one.m_size == other.m_size;
+ }
+
+ public static bool operator != (DataDirectory one, DataDirectory other)
+ {
+ return one.m_virtualAddress != other.m_virtualAddress || one.m_size != other.m_size;
+ }
+ }
+}
--- /dev/null
+//
+// DebugHeader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System;
+
+ internal sealed class DebugHeader : IHeader, IBinaryVisitable {
+
+ public uint Characteristics;
+ public uint TimeDateStamp;
+ public ushort MajorVersion;
+ public ushort MinorVersion;
+ public DebugStoreType Type;
+ public uint SizeOfData;
+ public RVA AddressOfRawData;
+ public uint PointerToRawData;
+
+ public uint Magic;
+ public Guid Signature;
+ public uint Age;
+ public string FileName;
+
+ internal DebugHeader ()
+ {
+ }
+
+ public void SetDefaultValues ()
+ {
+ Characteristics = 0;
+
+ this.Magic = 0x53445352;
+ this.Age = 0;
+ this.Type = DebugStoreType.CodeView;
+ this.FileName = string.Empty;
+ }
+
+ public uint GetSize ()
+ {
+ return 0x34 + (uint) FileName.Length + 1;
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitDebugHeader (this);
+ }
+ }
+}
--- /dev/null
+//
+// DebugStoreType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal enum DebugStoreType : uint {
+ Unknown = 0x00000000,
+ COFF = 0x00000001,
+ CodeView = 0x00000002,
+ FPO = 0x00000003,
+ Misc = 0x00000004,
+ Exception = 0x00000005,
+ Fixup = 0x00000006,
+ OMAPToSrc = 0x00000007,
+ OMAPFromSrc = 0x00000008,
+ Borland = 0x00000009,
+ Reserved10 = 0x0000000a,
+ CLSID = 0x0000000b
+ }
+}
--- /dev/null
+//
+// ExportTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal sealed class ExportTable : IBinaryVisitable {
+
+ public uint Characteristics;
+ public uint TimeDateStamp;
+ public ushort MajorVersion;
+ public ushort MinorVersion;
+ public string Name;
+ public uint Base;
+ public uint NumberOfFunctions;
+ public uint NumberOfNames;
+ public RVA AddressOfFunctions;
+ public RVA AddressOfNames;
+ public RVA AddressOfNameOrdinals;
+
+ public RVA [] AddressesOfFunctions;
+ public RVA [] AddressesOfNames;
+ public ushort [] NameOrdinals;
+ public string [] Names;
+
+ internal ExportTable ()
+ {
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitExportTable (this);
+ }
+ }
+}
--- /dev/null
+//
+// IBinaryVisitable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal interface IBinaryVisitable {
+ void Accept (IBinaryVisitor visitor);
+ }
+}
+
--- /dev/null
+//
+// IBinaryVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal interface IBinaryVisitor {
+ void VisitImage (Image img);
+ void VisitDOSHeader (DOSHeader header);
+ void VisitPEFileHeader (PEFileHeader header);
+ void VisitPEOptionalHeader (PEOptionalHeader header);
+ void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header);
+ void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header);
+ void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header);
+ void VisitSectionCollection (SectionCollection coll);
+ void VisitSection (Section section);
+ void VisitImportAddressTable (ImportAddressTable iat);
+ void VisitDebugHeader (DebugHeader dh);
+ void VisitCLIHeader (CLIHeader header);
+ void VisitImportTable (ImportTable it);
+ void VisitImportLookupTable (ImportLookupTable ilt);
+ void VisitHintNameTable (HintNameTable hnt);
+ void VisitExportTable (ExportTable et);
+
+ void TerminateImage (Image img);
+ }
+}
--- /dev/null
+//
+// IHeader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal interface IHeader {
+ void SetDefaultValues ();
+ }
+}
--- /dev/null
+//
+// Image.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System;
+ using System.IO;
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class Image : IBinaryVisitable {
+
+ DOSHeader m_dosHeader;
+ PEFileHeader m_peFileHeader;
+ PEOptionalHeader m_peOptionalHeader;
+
+ SectionCollection m_sections;
+ Section m_textSection;
+
+ ImportAddressTable m_importAddressTable;
+ CLIHeader m_cliHeader;
+ ImportTable m_importTable;
+ ImportLookupTable m_importLookupTable;
+ HintNameTable m_hintNameTable;
+ ExportTable m_exportTable;
+
+ DebugHeader m_debugHeader;
+ MetadataRoot m_mdRoot;
+
+ ResourceDirectoryTable m_rsrcRoot;
+
+ FileInfo m_img;
+
+ public DOSHeader DOSHeader {
+ get { return m_dosHeader; }
+ }
+
+ public PEFileHeader PEFileHeader {
+ get { return m_peFileHeader; }
+ }
+
+ public PEOptionalHeader PEOptionalHeader {
+ get { return m_peOptionalHeader; }
+ }
+
+ public SectionCollection Sections {
+ get { return m_sections; }
+ }
+
+ public Section TextSection {
+ get { return m_textSection; }
+ set { m_textSection = value; }
+ }
+
+ public ImportAddressTable ImportAddressTable {
+ get { return m_importAddressTable; }
+ }
+
+ public CLIHeader CLIHeader {
+ get { return m_cliHeader; }
+ set { m_cliHeader = value; }
+ }
+
+ public DebugHeader DebugHeader {
+ get { return m_debugHeader; }
+ set { m_debugHeader = value; }
+ }
+
+ public MetadataRoot MetadataRoot {
+ get { return m_mdRoot; }
+ }
+
+ public ImportTable ImportTable {
+ get { return m_importTable; }
+ }
+
+ public ImportLookupTable ImportLookupTable {
+ get { return m_importLookupTable; }
+ }
+
+ public HintNameTable HintNameTable {
+ get { return m_hintNameTable; }
+ }
+
+ public ExportTable ExportTable {
+ get { return m_exportTable; }
+ set { m_exportTable = value; }
+ }
+
+ internal ResourceDirectoryTable ResourceDirectoryRoot {
+ get { return m_rsrcRoot; }
+ set { m_rsrcRoot = value; }
+ }
+
+ public FileInfo FileInformation {
+ get { return m_img; }
+ }
+
+ internal Image ()
+ {
+ m_dosHeader = new DOSHeader ();
+ m_peFileHeader = new PEFileHeader ();
+ m_peOptionalHeader = new PEOptionalHeader ();
+ m_sections = new SectionCollection ();
+ m_importAddressTable = new ImportAddressTable ();
+ m_importTable = new ImportTable ();
+ m_importLookupTable = new ImportLookupTable ();
+ m_hintNameTable = new HintNameTable ();
+ m_mdRoot = new MetadataRoot (this);
+ }
+
+ internal Image (FileInfo img) : this ()
+ {
+ m_img = img;
+ }
+
+ public long ResolveVirtualAddress (RVA rva)
+ {
+ foreach (Section sect in this.Sections) {
+ if (rva >= sect.VirtualAddress &&
+ rva < sect.VirtualAddress + sect.SizeOfRawData)
+
+ return rva + sect.PointerToRawData - sect.VirtualAddress;
+ }
+
+ throw new ArgumentOutOfRangeException ("Cannot map the rva to any section");
+ }
+
+ internal Section GetSectionAtVirtualAddress (RVA rva)
+ {
+ foreach (Section sect in this.Sections) {
+ if (rva >= sect.VirtualAddress &&
+ rva < sect.VirtualAddress + sect.SizeOfRawData) {
+ return sect;
+ }
+ }
+ return null;
+ }
+
+ public BinaryReader GetReaderAtVirtualAddress (RVA rva)
+ {
+ Section sect = GetSectionAtVirtualAddress (rva);
+ if (sect == null)
+ return null;
+
+ BinaryReader br = new BinaryReader (new MemoryStream (sect.Data));
+ br.BaseStream.Position = rva - sect.VirtualAddress;
+ return br;
+ }
+
+ public void AddDebugHeader ()
+ {
+ m_debugHeader = new DebugHeader ();
+ m_debugHeader.SetDefaultValues ();
+ }
+
+ internal void SetFileInfo (FileInfo file)
+ {
+ m_img = file;
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitImage (this);
+
+ m_dosHeader.Accept (visitor);
+ m_peFileHeader.Accept (visitor);
+ m_peOptionalHeader.Accept (visitor);
+
+ m_sections.Accept (visitor);
+
+ m_importAddressTable.Accept (visitor);
+
+ AcceptIfNotNull (m_cliHeader, visitor);
+ AcceptIfNotNull (m_debugHeader, visitor);
+
+ m_importTable.Accept (visitor);
+ m_importLookupTable.Accept (visitor);
+ m_hintNameTable.Accept (visitor);
+ AcceptIfNotNull (m_exportTable, visitor);
+
+ visitor.TerminateImage (this);
+ }
+
+ static void AcceptIfNotNull (IBinaryVisitable visitable, IBinaryVisitor visitor)
+ {
+ if (visitable == null)
+ return;
+
+ visitable.Accept (visitor);
+ }
+
+ public static Image CreateImage ()
+ {
+ Image img = new Image ();
+
+ ImageInitializer init = new ImageInitializer (img);
+ img.Accept (init);
+
+ return img;
+ }
+
+ public static Image GetImage (string file)
+ {
+ return ImageReader.Read (file).Image;
+ }
+
+ public static Image GetImage (byte [] image)
+ {
+ return ImageReader.Read (image).Image;
+ }
+
+ public static Image GetImage (Stream stream)
+ {
+ return ImageReader.Read (stream).Image;
+ }
+ }
+}
--- /dev/null
+//
+// ImageCharacteristics.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System;
+
+ [Flags]
+ internal enum ImageCharacteristics : ushort {
+ RelocsStripped = 0x0001,
+ ExecutableImage = 0x0002,
+ LineNumsStripped = 0x0004,
+ LocalSymsStripped = 0x0008,
+ AggressiveWSTrim = 0x0010,
+ LargeAddressAware = 0x0020,
+ ReservedForFutureUse = 0x0040,
+ BytesReversedLo = 0x0080,
+ _32BitsMachine = 0x0100,
+ DebugStripped = 0x0200,
+ RemovableRunFromSwap = 0x0400,
+ NetRunFromSwap = 0x0800,
+ System = 0x1000,
+ Dll = 0x2000,
+ UPSystemOnly = 0x4000,
+ BytesReversedHI = 0x8000,
+
+ __flags = 0x0002 | 0x0004 | 0x0008 | 0x0100,
+
+ CILOnlyDll = 0x2000 | (ushort) __flags,
+ CILOnlyExe = __flags
+ }
+}
--- /dev/null
+//
+// ImageFormatException.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System;
+
+ internal class ImageFormatException : Exception {
+
+ internal ImageFormatException () : base()
+ {
+ }
+
+ internal ImageFormatException (string message) : base(message)
+ {
+ }
+
+ internal ImageFormatException (string message, params string[] parameters) :
+ base(string.Format(message, parameters))
+ {
+ }
+
+ internal ImageFormatException (string message, Exception inner) :
+ base(message, inner)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// ImageInitializer.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System;
+
+ using Mono.Cecil.Metadata;
+
+ sealed class ImageInitializer : BaseImageVisitor {
+
+ Image m_image;
+ MetadataInitializer m_mdinit;
+
+ public Image Image {
+ get { return m_image; }
+ }
+
+ public MetadataInitializer Metadata {
+ get { return m_mdinit; }
+ }
+
+ public ImageInitializer (Image image)
+ {
+ m_image = image;
+ m_image.CLIHeader = new CLIHeader ();
+ m_mdinit = new MetadataInitializer (this);
+ }
+
+ public override void VisitDOSHeader (DOSHeader header)
+ {
+ header.SetDefaultValues ();
+ }
+
+ public override void VisitPEOptionalHeader (PEOptionalHeader header)
+ {
+ header.SetDefaultValues ();
+ }
+
+ public override void VisitPEFileHeader (PEFileHeader header)
+ {
+ header.SetDefaultValues ();
+ header.TimeDateStamp = TimeDateStampFromEpoch ();
+ }
+
+ public override void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header)
+ {
+ header.SetDefaultValues ();
+ }
+
+ public override void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header)
+ {
+ header.SetDefaultValues ();
+ }
+
+ public override void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header)
+ {
+ header.SetDefaultValues ();
+ }
+
+ public override void VisitSectionCollection (SectionCollection coll)
+ {
+ Section text = new Section ();
+ text.Name = Section.Text;
+ text.Characteristics = SectionCharacteristics.ContainsCode |
+ SectionCharacteristics.MemoryRead | SectionCharacteristics.MemExecute;
+ m_image.TextSection = text;
+
+ Section reloc = new Section ();
+ reloc.Name = Section.Relocs;
+ reloc.Characteristics = SectionCharacteristics.ContainsInitializedData |
+ SectionCharacteristics.MemDiscardable | SectionCharacteristics.MemoryRead;
+
+ coll.Add (text);
+ coll.Add (reloc);
+ }
+
+ public override void VisitSection (Section sect)
+ {
+ sect.SetDefaultValues ();
+ }
+
+ public override void VisitDebugHeader (DebugHeader dh)
+ {
+ if (dh != null)
+ dh.SetDefaultValues ();
+ }
+
+ public override void VisitCLIHeader (CLIHeader header)
+ {
+ header.SetDefaultValues ();
+ m_image.MetadataRoot.Accept (m_mdinit);
+ }
+
+ public override void VisitImportTable (ImportTable it)
+ {
+ it.ImportAddressTable = new RVA (0x2000);
+ }
+
+ public override void VisitHintNameTable (HintNameTable hnt)
+ {
+ hnt.Hint = 0;
+ hnt.RuntimeLibrary = HintNameTable.RuntimeCorEE;
+ hnt.EntryPoint = 0x25ff;
+ hnt.RVA = new RVA (0x402000);
+ }
+
+ public static uint TimeDateStampFromEpoch ()
+ {
+ return (uint) DateTime.UtcNow.Subtract (
+ new DateTime (1970, 1, 1)).TotalSeconds;
+ }
+ }
+}
--- /dev/null
+//
+// ImageReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System;
+ using System.IO;
+ using System.Text;
+
+ using Mono.Cecil.Metadata;
+
+ sealed class ImageReader : BaseImageVisitor {
+
+ MetadataReader m_mdReader;
+ BinaryReader m_binaryReader;
+ Image m_image;
+
+ public MetadataReader MetadataReader {
+ get { return m_mdReader; }
+ }
+
+ public Image Image {
+ get { return m_image; }
+ }
+
+ ImageReader (Image img, BinaryReader reader)
+ {
+ m_image = img;
+ m_binaryReader = reader;
+ }
+
+ static ImageReader Read (Image img, Stream stream)
+ {
+ ImageReader reader = new ImageReader (img, new BinaryReader (stream));
+ img.Accept (reader);
+ return reader;
+ }
+
+ public static ImageReader Read (string file)
+ {
+ if (file == null)
+ throw new ArgumentNullException ("file");
+
+ FileInfo fi = new FileInfo (file);
+ if (!File.Exists (fi.FullName))
+ #if CF_1_0 || CF_2_0
+ throw new FileNotFoundException (fi.FullName);
+ #else
+ throw new FileNotFoundException (string.Format ("File '{0}' not found.", fi.FullName), fi.FullName);
+ #endif
+
+ FileStream stream = null;
+ try {
+ stream = new FileStream (fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
+ return Read (new Image (fi), stream);
+ } catch (Exception e) {
+ if (stream != null)
+ stream.Close ();
+#if CF_1_0 || CF_2_0
+ throw new BadImageFormatException ("Invalid PE file: " + file, e);
+#else
+ throw new BadImageFormatException ("Invalid PE file", file, e);
+#endif
+ }
+ }
+
+ public static ImageReader Read (byte [] image)
+ {
+ if (image == null)
+ throw new ArgumentNullException ("image");
+
+ if (image.Length == 0)
+ throw new ArgumentException ("Empty image array");
+
+ return Read (new Image (), new MemoryStream (image));
+ }
+
+ public static ImageReader Read (Stream stream)
+ {
+ if (stream == null)
+ throw new ArgumentNullException ("stream");
+
+ if (!stream.CanRead)
+ throw new ArgumentException ("Can not read from stream");
+
+ return Read (new Image (), stream);
+ }
+
+ public BinaryReader GetReader ()
+ {
+ return m_binaryReader;
+ }
+
+ public override void VisitImage (Image img)
+ {
+ m_mdReader = new MetadataReader (this);
+ }
+
+ void SetPositionToAddress (RVA address)
+ {
+ m_binaryReader.BaseStream.Position = m_image.ResolveVirtualAddress (address);
+ }
+
+ public override void VisitDOSHeader (DOSHeader header)
+ {
+ header.Start = m_binaryReader.ReadBytes (60);
+ header.Lfanew = m_binaryReader.ReadUInt32 ();
+ header.End = m_binaryReader.ReadBytes (64);
+
+ m_binaryReader.BaseStream.Position = header.Lfanew;
+
+ if (m_binaryReader.ReadUInt16 () != 0x4550 ||
+ m_binaryReader.ReadUInt16 () != 0)
+
+ throw new ImageFormatException ("Invalid PE File Signature");
+ }
+
+ public override void VisitPEFileHeader (PEFileHeader header)
+ {
+ header.Machine = m_binaryReader.ReadUInt16 ();
+ header.NumberOfSections = m_binaryReader.ReadUInt16 ();
+ header.TimeDateStamp = m_binaryReader.ReadUInt32 ();
+ header.PointerToSymbolTable = m_binaryReader.ReadUInt32 ();
+ header.NumberOfSymbols = m_binaryReader.ReadUInt32 ();
+ header.OptionalHeaderSize = m_binaryReader.ReadUInt16 ();
+ header.Characteristics = (ImageCharacteristics) m_binaryReader.ReadUInt16 ();
+ }
+
+ ulong ReadIntOrLong ()
+ {
+ return m_image.PEOptionalHeader.StandardFields.IsPE64 ?
+ m_binaryReader.ReadUInt64 () :
+ m_binaryReader.ReadUInt32 ();
+ }
+
+ RVA ReadRVA ()
+ {
+ return m_binaryReader.ReadUInt32 ();
+ }
+
+ DataDirectory ReadDataDirectory ()
+ {
+ return new DataDirectory (ReadRVA (), m_binaryReader.ReadUInt32 ());
+ }
+
+ public override void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header)
+ {
+ header.ImageBase = ReadIntOrLong ();
+ header.SectionAlignment = m_binaryReader.ReadUInt32 ();
+ header.FileAlignment = m_binaryReader.ReadUInt32 ();
+ header.OSMajor = m_binaryReader.ReadUInt16 ();
+ header.OSMinor = m_binaryReader.ReadUInt16 ();
+ header.UserMajor = m_binaryReader.ReadUInt16 ();
+ header.UserMinor = m_binaryReader.ReadUInt16 ();
+ header.SubSysMajor = m_binaryReader.ReadUInt16 ();
+ header.SubSysMinor = m_binaryReader.ReadUInt16 ();
+ header.Reserved = m_binaryReader.ReadUInt32 ();
+ header.ImageSize = m_binaryReader.ReadUInt32 ();
+ header.HeaderSize = m_binaryReader.ReadUInt32 ();
+ header.FileChecksum = m_binaryReader.ReadUInt32 ();
+ header.SubSystem = (SubSystem) m_binaryReader.ReadUInt16 ();
+ header.DLLFlags = m_binaryReader.ReadUInt16 ();
+ header.StackReserveSize = ReadIntOrLong ();
+ header.StackCommitSize = ReadIntOrLong ();
+ header.HeapReserveSize = ReadIntOrLong ();
+ header.HeapCommitSize = ReadIntOrLong ();
+ header.LoaderFlags = m_binaryReader.ReadUInt32 ();
+ header.NumberOfDataDir = m_binaryReader.ReadUInt32 ();
+ }
+
+ public override void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header)
+ {
+ header.Magic = m_binaryReader.ReadUInt16 ();
+ header.LMajor = m_binaryReader.ReadByte ();
+ header.LMinor = m_binaryReader.ReadByte ();
+ header.CodeSize = m_binaryReader.ReadUInt32 ();
+ header.InitializedDataSize = m_binaryReader.ReadUInt32 ();
+ header.UninitializedDataSize = m_binaryReader.ReadUInt32 ();
+ header.EntryPointRVA = ReadRVA ();
+ header.BaseOfCode = ReadRVA ();
+ if (!header.IsPE64)
+ header.BaseOfData = ReadRVA ();
+ }
+
+ public override void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header)
+ {
+ header.ExportTable = ReadDataDirectory ();
+ header.ImportTable = ReadDataDirectory ();
+ header.ResourceTable = ReadDataDirectory ();
+ header.ExceptionTable = ReadDataDirectory ();
+ header.CertificateTable = ReadDataDirectory ();
+ header.BaseRelocationTable = ReadDataDirectory ();
+ header.Debug = ReadDataDirectory ();
+ header.Copyright = ReadDataDirectory ();
+ header.GlobalPtr = ReadDataDirectory ();
+ header.TLSTable = ReadDataDirectory ();
+ header.LoadConfigTable = ReadDataDirectory ();
+ header.BoundImport = ReadDataDirectory ();
+ header.IAT = ReadDataDirectory ();
+ header.DelayImportDescriptor = ReadDataDirectory ();
+ header.CLIHeader = ReadDataDirectory ();
+ header.Reserved = ReadDataDirectory ();
+
+ if (header.CLIHeader != DataDirectory.Zero)
+ m_image.CLIHeader = new CLIHeader ();
+ if (header.ExportTable != DataDirectory.Zero)
+ m_image.ExportTable = new ExportTable ();
+ }
+
+ public override void VisitSectionCollection (SectionCollection coll)
+ {
+ for (int i = 0; i < m_image.PEFileHeader.NumberOfSections; i++)
+ coll.Add (new Section ());
+ }
+
+ public override void VisitSection (Section sect)
+ {
+ char [] buffer = new char [8];
+ int read = 0;
+ while (read < 8) {
+ char cur = (char) m_binaryReader.ReadSByte ();
+ if (cur == '\0') {
+ m_binaryReader.BaseStream.Position += 8 - read - 1;
+ break;
+ }
+ buffer [read++] = cur;
+ }
+ sect.Name = read == 0 ? string.Empty : new string (buffer, 0, read);
+ if (sect.Name == Section.Text)
+ m_image.TextSection = sect;
+
+ sect.VirtualSize = m_binaryReader.ReadUInt32 ();
+ sect.VirtualAddress = ReadRVA ();
+ sect.SizeOfRawData = m_binaryReader.ReadUInt32 ();
+ sect.PointerToRawData = ReadRVA ();
+ sect.PointerToRelocations = ReadRVA ();
+ sect.PointerToLineNumbers = ReadRVA ();
+ sect.NumberOfRelocations = m_binaryReader.ReadUInt16 ();
+ sect.NumberOfLineNumbers = m_binaryReader.ReadUInt16 ();
+ sect.Characteristics = (SectionCharacteristics) m_binaryReader.ReadUInt32 ();
+
+ long pos = m_binaryReader.BaseStream.Position;
+ m_binaryReader.BaseStream.Position = sect.PointerToRawData;
+ sect.Data = m_binaryReader.ReadBytes ((int) sect.SizeOfRawData);
+ m_binaryReader.BaseStream.Position = pos;
+ }
+
+ public override void VisitImportAddressTable (ImportAddressTable iat)
+ {
+ if (m_image.PEOptionalHeader.DataDirectories.IAT.VirtualAddress == RVA.Zero)
+ return;
+
+ SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.IAT.VirtualAddress);
+
+ iat.HintNameTableRVA = ReadRVA ();
+ }
+
+ public override void VisitCLIHeader (CLIHeader header)
+ {
+ if (m_image.PEOptionalHeader.DataDirectories.Debug != DataDirectory.Zero) {
+ m_image.DebugHeader = new DebugHeader ();
+ VisitDebugHeader (m_image.DebugHeader);
+ }
+
+ SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.CLIHeader.VirtualAddress);
+ header.Cb = m_binaryReader.ReadUInt32 ();
+ header.MajorRuntimeVersion = m_binaryReader.ReadUInt16 ();
+ header.MinorRuntimeVersion = m_binaryReader.ReadUInt16 ();
+ header.Metadata = ReadDataDirectory ();
+ header.Flags = (RuntimeImage) m_binaryReader.ReadUInt32 ();
+ header.EntryPointToken = m_binaryReader.ReadUInt32 ();
+ header.Resources = ReadDataDirectory ();
+ header.StrongNameSignature = ReadDataDirectory ();
+ header.CodeManagerTable = ReadDataDirectory ();
+ header.VTableFixups = ReadDataDirectory ();
+ header.ExportAddressTableJumps = ReadDataDirectory ();
+ header.ManagedNativeHeader = ReadDataDirectory ();
+
+ if (header.StrongNameSignature != DataDirectory.Zero) {
+ SetPositionToAddress (header.StrongNameSignature.VirtualAddress);
+ header.ImageHash = m_binaryReader.ReadBytes ((int) header.StrongNameSignature.Size);
+ } else
+ header.ImageHash = new byte [0];
+
+ SetPositionToAddress (m_image.CLIHeader.Metadata.VirtualAddress);
+ m_image.MetadataRoot.Accept (m_mdReader);
+ }
+
+ public override void VisitDebugHeader (DebugHeader header)
+ {
+ if (m_image.PEOptionalHeader.DataDirectories.Debug == DataDirectory.Zero)
+ return;
+
+ long pos = m_binaryReader.BaseStream.Position;
+
+ SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.Debug.VirtualAddress);
+ header.Characteristics = m_binaryReader.ReadUInt32 ();
+ header.TimeDateStamp = m_binaryReader.ReadUInt32 ();
+ header.MajorVersion = m_binaryReader.ReadUInt16 ();
+ header.MinorVersion = m_binaryReader.ReadUInt16 ();
+ header.Type = (DebugStoreType) m_binaryReader.ReadUInt32 ();
+ header.SizeOfData = m_binaryReader.ReadUInt32 ();
+ header.AddressOfRawData = ReadRVA ();
+ header.PointerToRawData = m_binaryReader.ReadUInt32 ();
+
+ m_binaryReader.BaseStream.Position = header.PointerToRawData;
+
+ header.Magic = m_binaryReader.ReadUInt32 ();
+ header.Signature = new Guid (m_binaryReader.ReadBytes (16));
+ header.Age = m_binaryReader.ReadUInt32 ();
+ header.FileName = ReadZeroTerminatedString ();
+
+ m_binaryReader.BaseStream.Position = pos;
+ }
+
+ string ReadZeroTerminatedString ()
+ {
+ StringBuilder sb = new StringBuilder ();
+ while (true) {
+ byte chr = m_binaryReader.ReadByte ();
+ if (chr == 0)
+ break;
+ sb.Append ((char) chr);
+ }
+ return sb.ToString ();
+ }
+
+ public override void VisitImportTable (ImportTable it)
+ {
+ if (m_image.PEOptionalHeader.DataDirectories.ImportTable.VirtualAddress == RVA.Zero)
+ return;
+
+ SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.ImportTable.VirtualAddress);
+
+ it.ImportLookupTable = ReadRVA ();
+ it.DateTimeStamp = m_binaryReader.ReadUInt32 ();
+ it.ForwardChain = m_binaryReader.ReadUInt32 ();
+ it.Name = ReadRVA ();
+ it.ImportAddressTable = ReadRVA ();
+ }
+
+ public override void VisitImportLookupTable (ImportLookupTable ilt)
+ {
+ if (m_image.ImportTable.ImportLookupTable == RVA.Zero)
+ return;
+
+ SetPositionToAddress (m_image.ImportTable.ImportLookupTable);
+
+ ilt.HintNameRVA = ReadRVA ();
+ }
+
+ public override void VisitHintNameTable (HintNameTable hnt)
+ {
+ if (m_image.ImportAddressTable.HintNameTableRVA == RVA.Zero)
+ return;
+
+ if ((m_image.ImportAddressTable.HintNameTableRVA & 0x80000000) != 0)
+ return;
+
+ SetPositionToAddress (m_image.ImportAddressTable.HintNameTableRVA);
+
+ hnt.Hint = m_binaryReader.ReadUInt16 ();
+
+ byte [] bytes = m_binaryReader.ReadBytes (11);
+ hnt.RuntimeMain = Encoding.ASCII.GetString (bytes, 0, bytes.Length);
+
+ SetPositionToAddress (m_image.ImportTable.Name);
+
+ bytes = m_binaryReader.ReadBytes (11);
+ hnt.RuntimeLibrary = Encoding.ASCII.GetString (bytes, 0, bytes.Length);
+
+ SetPositionToAddress (m_image.PEOptionalHeader.StandardFields.EntryPointRVA);
+ hnt.EntryPoint = m_binaryReader.ReadUInt16 ();
+ hnt.RVA = ReadRVA ();
+ }
+
+ public override void VisitExportTable (ExportTable et)
+ {
+ SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.ExportTable.VirtualAddress);
+
+ et.Characteristics = m_binaryReader.ReadUInt32 ();
+ et.TimeDateStamp = m_binaryReader.ReadUInt32 ();
+ et.MajorVersion = m_binaryReader.ReadUInt16 ();
+ et.MinorVersion = m_binaryReader.ReadUInt16 ();
+
+ //et.Name =
+ m_binaryReader.ReadUInt32 ();
+
+ et.Base = m_binaryReader.ReadUInt32 ();
+ et.NumberOfFunctions = m_binaryReader.ReadUInt32 ();
+ et.NumberOfNames = m_binaryReader.ReadUInt32 ();
+ et.AddressOfFunctions = m_binaryReader.ReadUInt32 ();
+ et.AddressOfNames = m_binaryReader.ReadUInt32 ();
+ et.AddressOfNameOrdinals = m_binaryReader.ReadUInt32 ();
+
+ et.AddressesOfFunctions = ReadArrayOfRVA (et.AddressOfFunctions, et.NumberOfFunctions);
+ et.AddressesOfNames = ReadArrayOfRVA (et.AddressOfNames, et.NumberOfNames);
+ et.NameOrdinals = ReadArrayOfUInt16 (et.AddressOfNameOrdinals, et.NumberOfNames);
+ et.Names = new string [et.NumberOfFunctions];
+
+ for (int i = 0; i < et.NumberOfFunctions; i++) {
+ if (et.AddressesOfFunctions [i] == 0)
+ continue;
+
+ et.Names [i] = ReadFunctionName (et, i);
+ }
+ }
+
+ string ReadFunctionName (ExportTable et, int index)
+ {
+ for (int i = 0; i < et.NumberOfNames; i++) {
+ if (et.NameOrdinals [i] != index)
+ continue;
+
+ SetPositionToAddress (et.AddressesOfNames [i]);
+ return ReadZeroTerminatedString ();
+ }
+
+ return string.Empty;
+ }
+
+ ushort [] ReadArrayOfUInt16 (RVA position, uint length)
+ {
+ if (position == RVA.Zero)
+ return new ushort [0];
+
+ SetPositionToAddress (position);
+ ushort [] array = new ushort [length];
+ for (int i = 0; i < length; i++)
+ array [i] = m_binaryReader.ReadUInt16 ();
+
+ return array;
+ }
+
+ RVA [] ReadArrayOfRVA (RVA position, uint length)
+ {
+ if (position == RVA.Zero)
+ return new RVA [0];
+
+ SetPositionToAddress (position);
+ RVA [] addresses = new RVA [length];
+ for (int i = 0; i < length; i++)
+ addresses [i] = m_binaryReader.ReadUInt32 ();
+
+ return addresses;
+ }
+
+ public override void TerminateImage(Image img)
+ {
+ m_binaryReader.Close ();
+
+ try {
+ ResourceReader resReader = new ResourceReader (img);
+ img.ResourceDirectoryRoot = resReader.Read ();
+ } catch {
+ img.ResourceDirectoryRoot = null;
+ }
+ }
+ }
+}
--- /dev/null
+//
+// ImageWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System.IO;
+ using System.Text;
+
+ using Mono.Cecil.Metadata;
+
+ sealed class ImageWriter : BaseImageVisitor {
+
+ Image m_img;
+ AssemblyKind m_kind;
+ MetadataWriter m_mdWriter;
+ BinaryWriter m_binaryWriter;
+
+ Section m_textSect;
+ MemoryBinaryWriter m_textWriter;
+ Section m_relocSect;
+ MemoryBinaryWriter m_relocWriter;
+ Section m_rsrcSect;
+ MemoryBinaryWriter m_rsrcWriter;
+
+ public ImageWriter (MetadataWriter writer, AssemblyKind kind, BinaryWriter bw)
+ {
+ m_mdWriter= writer;
+ m_img = writer.GetMetadataRoot ().GetImage ();
+ m_kind = kind;
+ m_binaryWriter = bw;
+
+ m_textWriter = new MemoryBinaryWriter ();
+ m_textWriter.BaseStream.Position = 80;
+ m_relocWriter = new MemoryBinaryWriter ();
+ }
+
+ public Image GetImage ()
+ {
+ return m_img;
+ }
+
+ public MemoryBinaryWriter GetTextWriter ()
+ {
+ return m_textWriter;
+ }
+
+ public uint GetAligned (uint integer, uint alignWith)
+ {
+ return (integer + alignWith - 1) & ~(alignWith - 1);
+ }
+
+ public void Initialize ()
+ {
+ Image img = m_img;
+ ResourceWriter resWriter = null;
+
+ uint sectAlign = img.PEOptionalHeader.NTSpecificFields.SectionAlignment;
+ uint fileAlign = img.PEOptionalHeader.NTSpecificFields.FileAlignment;
+
+ m_textSect = img.TextSection;
+ foreach (Section s in img.Sections) {
+ if (s.Name == Section.Relocs)
+ m_relocSect = s;
+ else if (s.Name == Section.Resources) {
+ m_rsrcSect = s;
+ m_rsrcWriter = new MemoryBinaryWriter ();
+
+ resWriter = new ResourceWriter (img, m_rsrcSect, m_rsrcWriter);
+ resWriter.Write ();
+ }
+ }
+
+ // size computations, fields setting, etc.
+ uint nbSects = (uint) img.Sections.Count;
+ img.PEFileHeader.NumberOfSections = (ushort) nbSects;
+
+ // build the reloc section data
+ uint relocSize = 12;
+ m_relocWriter.Write ((uint) 0);
+ m_relocWriter.Write (relocSize);
+ m_relocWriter.Write ((ushort) 0);
+ m_relocWriter.Write ((ushort) 0);
+
+ m_textSect.VirtualSize = (uint) m_textWriter.BaseStream.Length;
+ m_relocSect.VirtualSize = (uint) m_relocWriter.BaseStream.Length;
+ if (m_rsrcSect != null)
+ m_rsrcSect.VirtualSize = (uint) m_rsrcWriter.BaseStream.Length;
+
+ // start counting before sections headers
+ // section start + section header sixe * number of sections
+ uint headersEnd = 0x178 + 0x28 * nbSects;
+ uint fileOffset = headersEnd;
+ uint sectOffset = sectAlign;
+ uint imageSize = 0;
+
+ foreach (Section sect in img.Sections) {
+ fileOffset = GetAligned (fileOffset, fileAlign);
+ sectOffset = GetAligned (sectOffset, sectAlign);
+
+ sect.PointerToRawData = new RVA (fileOffset);
+ sect.VirtualAddress = new RVA (sectOffset);
+ sect.SizeOfRawData = GetAligned (sect.VirtualSize, fileAlign);
+
+ fileOffset += sect.SizeOfRawData;
+ sectOffset += sect.SizeOfRawData;
+ imageSize += GetAligned (sect.SizeOfRawData, sectAlign);
+ }
+
+ if (m_textSect.VirtualAddress.Value != 0x2000)
+ throw new ImageFormatException ("Wrong RVA for .text section");
+
+ if (resWriter != null)
+ resWriter.Patch ();
+
+ img.PEOptionalHeader.StandardFields.CodeSize = GetAligned (
+ m_textSect.SizeOfRawData, fileAlign);
+ img.PEOptionalHeader.StandardFields.InitializedDataSize = m_textSect.SizeOfRawData;
+ if (m_rsrcSect != null)
+ img.PEOptionalHeader.StandardFields.InitializedDataSize += m_rsrcSect.SizeOfRawData;
+ img.PEOptionalHeader.StandardFields.BaseOfCode = m_textSect.VirtualAddress;
+ img.PEOptionalHeader.StandardFields.BaseOfData = m_relocSect.VirtualAddress;
+
+ imageSize += headersEnd;
+ img.PEOptionalHeader.NTSpecificFields.ImageSize = GetAligned (imageSize, sectAlign);
+
+ img.PEOptionalHeader.DataDirectories.BaseRelocationTable = new DataDirectory (
+ m_relocSect.VirtualAddress, m_relocSect.VirtualSize);
+ if (m_rsrcSect != null)
+ img.PEOptionalHeader.DataDirectories.ResourceTable = new DataDirectory (
+ m_rsrcSect.VirtualAddress, (uint) m_rsrcWriter.BaseStream.Length);
+
+ if (m_kind == AssemblyKind.Dll) {
+ img.PEFileHeader.Characteristics = ImageCharacteristics.CILOnlyDll;
+ img.HintNameTable.RuntimeMain = HintNameTable.RuntimeMainDll;
+ img.PEOptionalHeader.NTSpecificFields.DLLFlags = 0x400;
+ } else {
+ img.PEFileHeader.Characteristics = ImageCharacteristics.CILOnlyExe;
+ img.HintNameTable.RuntimeMain = HintNameTable.RuntimeMainExe;
+ }
+
+ switch (m_kind) {
+ case AssemblyKind.Dll :
+ case AssemblyKind.Console :
+ img.PEOptionalHeader.NTSpecificFields.SubSystem = SubSystem.WindowsCui;
+ break;
+ case AssemblyKind.Windows :
+ img.PEOptionalHeader.NTSpecificFields.SubSystem = SubSystem.WindowsGui;
+ break;
+ }
+
+ RVA importTable = new RVA (img.TextSection.VirtualAddress + m_mdWriter.ImportTablePosition);
+
+ img.PEOptionalHeader.DataDirectories.ImportTable = new DataDirectory (importTable, 0x57);
+
+ img.ImportTable.ImportLookupTable = new RVA ((uint) importTable + 0x28);
+
+ img.ImportLookupTable.HintNameRVA = img.ImportAddressTable.HintNameTableRVA =
+ new RVA ((uint) img.ImportTable.ImportLookupTable + 0x14);
+ img.ImportTable.Name = new RVA ((uint) img.ImportLookupTable.HintNameRVA + 0xe);
+ }
+
+ public override void VisitDOSHeader (DOSHeader header)
+ {
+ m_binaryWriter.Write (header.Start);
+ m_binaryWriter.Write (header.Lfanew);
+ m_binaryWriter.Write (header.End);
+
+ m_binaryWriter.Write ((ushort) 0x4550);
+ m_binaryWriter.Write ((ushort) 0);
+ }
+
+ public override void VisitPEFileHeader (PEFileHeader header)
+ {
+ m_binaryWriter.Write (header.Machine);
+ m_binaryWriter.Write (header.NumberOfSections);
+ m_binaryWriter.Write (header.TimeDateStamp);
+ m_binaryWriter.Write (header.PointerToSymbolTable);
+ m_binaryWriter.Write (header.NumberOfSymbols);
+ m_binaryWriter.Write (header.OptionalHeaderSize);
+ m_binaryWriter.Write ((ushort) header.Characteristics);
+ }
+
+ public override void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header)
+ {
+ WriteIntOrLong (header.ImageBase);
+ m_binaryWriter.Write (header.SectionAlignment);
+ m_binaryWriter.Write (header.FileAlignment);
+ m_binaryWriter.Write (header.OSMajor);
+ m_binaryWriter.Write (header.OSMinor);
+ m_binaryWriter.Write (header.UserMajor);
+ m_binaryWriter.Write (header.UserMinor);
+ m_binaryWriter.Write (header.SubSysMajor);
+ m_binaryWriter.Write (header.SubSysMinor);
+ m_binaryWriter.Write (header.Reserved);
+ m_binaryWriter.Write (header.ImageSize);
+ m_binaryWriter.Write (header.HeaderSize);
+ m_binaryWriter.Write (header.FileChecksum);
+ m_binaryWriter.Write ((ushort) header.SubSystem);
+ m_binaryWriter.Write (header.DLLFlags);
+ WriteIntOrLong (header.StackReserveSize);
+ WriteIntOrLong (header.StackCommitSize);
+ WriteIntOrLong (header.HeapReserveSize);
+ WriteIntOrLong (header.HeapCommitSize);
+ m_binaryWriter.Write (header.LoaderFlags);
+ m_binaryWriter.Write (header.NumberOfDataDir);
+ }
+
+ public override void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header)
+ {
+ m_binaryWriter.Write (header.Magic);
+ m_binaryWriter.Write (header.LMajor);
+ m_binaryWriter.Write (header.LMinor);
+ m_binaryWriter.Write (header.CodeSize);
+ m_binaryWriter.Write (header.InitializedDataSize);
+ m_binaryWriter.Write (header.UninitializedDataSize);
+ m_binaryWriter.Write (header.EntryPointRVA.Value);
+ m_binaryWriter.Write (header.BaseOfCode.Value);
+ if (!header.IsPE64)
+ m_binaryWriter.Write (header.BaseOfData.Value);
+ }
+
+ void WriteIntOrLong (ulong value)
+ {
+ if (m_img.PEOptionalHeader.StandardFields.IsPE64)
+ m_binaryWriter.Write (value);
+ else
+ m_binaryWriter.Write ((uint) value);
+ }
+
+ public override void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header)
+ {
+ m_binaryWriter.Write (header.ExportTable.VirtualAddress);
+ m_binaryWriter.Write (header.ExportTable.Size);
+ m_binaryWriter.Write (header.ImportTable.VirtualAddress);
+ m_binaryWriter.Write (header.ImportTable.Size);
+ m_binaryWriter.Write (header.ResourceTable.VirtualAddress);
+ m_binaryWriter.Write (header.ResourceTable.Size);
+ m_binaryWriter.Write (header.ExceptionTable.VirtualAddress);
+ m_binaryWriter.Write (header.ExceptionTable.Size);
+ m_binaryWriter.Write (header.CertificateTable.VirtualAddress);
+ m_binaryWriter.Write (header.CertificateTable.Size);
+ m_binaryWriter.Write (header.BaseRelocationTable.VirtualAddress);
+ m_binaryWriter.Write (header.BaseRelocationTable.Size);
+ m_binaryWriter.Write (header.Debug.VirtualAddress);
+ m_binaryWriter.Write (header.Debug.Size);
+ m_binaryWriter.Write (header.Copyright.VirtualAddress);
+ m_binaryWriter.Write (header.Copyright.Size);
+ m_binaryWriter.Write (header.GlobalPtr.VirtualAddress);
+ m_binaryWriter.Write (header.GlobalPtr.Size);
+ m_binaryWriter.Write (header.TLSTable.VirtualAddress);
+ m_binaryWriter.Write (header.TLSTable.Size);
+ m_binaryWriter.Write (header.LoadConfigTable.VirtualAddress);
+ m_binaryWriter.Write (header.LoadConfigTable.Size);
+ m_binaryWriter.Write (header.BoundImport.VirtualAddress);
+ m_binaryWriter.Write (header.BoundImport.Size);
+ m_binaryWriter.Write (header.IAT.VirtualAddress);
+ m_binaryWriter.Write (header.IAT.Size);
+ m_binaryWriter.Write (header.DelayImportDescriptor.VirtualAddress);
+ m_binaryWriter.Write (header.DelayImportDescriptor.Size);
+ m_binaryWriter.Write (header.CLIHeader.VirtualAddress);
+ m_binaryWriter.Write (header.CLIHeader.Size);
+ m_binaryWriter.Write (header.Reserved.VirtualAddress);
+ m_binaryWriter.Write (header.Reserved.Size);
+ }
+
+ public override void VisitSection (Section sect)
+ {
+ m_binaryWriter.Write (Encoding.ASCII.GetBytes (sect.Name));
+ int more = 8 - sect.Name.Length;
+ for (int i = 0; i < more; i++)
+ m_binaryWriter.Write ((byte) 0);
+
+ m_binaryWriter.Write (sect.VirtualSize);
+ m_binaryWriter.Write (sect.VirtualAddress.Value);
+ m_binaryWriter.Write (sect.SizeOfRawData);
+ m_binaryWriter.Write (sect.PointerToRawData.Value);
+ m_binaryWriter.Write (sect.PointerToRelocations.Value);
+ m_binaryWriter.Write (sect.PointerToLineNumbers.Value);
+ m_binaryWriter.Write (sect.NumberOfRelocations);
+ m_binaryWriter.Write (sect.NumberOfLineNumbers);
+ m_binaryWriter.Write ((uint) sect.Characteristics);
+ }
+
+ public override void VisitImportAddressTable (ImportAddressTable iat)
+ {
+ m_textWriter.BaseStream.Position = 0;
+ m_textWriter.Write (iat.HintNameTableRVA.Value);
+ m_textWriter.Write (new byte [4]);
+ }
+
+ public override void VisitCLIHeader (CLIHeader header)
+ {
+ m_textWriter.Write (header.Cb);
+
+ if (m_mdWriter.TargetRuntime >= TargetRuntime.NET_2_0) {
+ m_textWriter.Write ((ushort) 2);
+ m_textWriter.Write ((ushort) 5);
+ } else {
+ m_textWriter.Write ((ushort) 2);
+ m_textWriter.Write ((ushort) 0);
+ }
+
+ m_textWriter.Write (header.Metadata.VirtualAddress);
+ m_textWriter.Write (header.Metadata.Size);
+ m_textWriter.Write ((uint) header.Flags);
+ m_textWriter.Write (header.EntryPointToken);
+ m_textWriter.Write (header.Resources.VirtualAddress);
+ m_textWriter.Write (header.Resources.Size);
+ m_textWriter.Write (header.StrongNameSignature.VirtualAddress);
+ m_textWriter.Write (header.StrongNameSignature.Size);
+ m_textWriter.Write (header.CodeManagerTable.VirtualAddress);
+ m_textWriter.Write (header.CodeManagerTable.Size);
+ m_textWriter.Write (header.VTableFixups.VirtualAddress);
+ m_textWriter.Write (header.VTableFixups.Size);
+ m_textWriter.Write (header.ExportAddressTableJumps.VirtualAddress);
+ m_textWriter.Write (header.ExportAddressTableJumps.Size);
+ m_textWriter.Write (header.ManagedNativeHeader.VirtualAddress);
+ m_textWriter.Write (header.ManagedNativeHeader.Size);
+ }
+
+ public override void VisitDebugHeader (DebugHeader header)
+ {
+ m_textWriter.BaseStream.Position = m_mdWriter.DebugHeaderPosition;
+ uint sizeUntilData = 0x1c;
+ header.AddressOfRawData = m_img.TextSection.VirtualAddress + m_mdWriter.DebugHeaderPosition + sizeUntilData;
+ header.PointerToRawData = 0x200 + m_mdWriter.DebugHeaderPosition + sizeUntilData;
+ header.SizeOfData = 0x18 + (uint) header.FileName.Length + 1;
+
+ m_textWriter.Write (header.Characteristics);
+ m_textWriter.Write (header.TimeDateStamp);
+ m_textWriter.Write (header.MajorVersion);
+ m_textWriter.Write (header.MinorVersion);
+ m_textWriter.Write ((uint) header.Type);
+ m_textWriter.Write (header.SizeOfData);
+ m_textWriter.Write (header.AddressOfRawData.Value);
+ m_textWriter.Write (header.PointerToRawData);
+
+ m_textWriter.Write (header.Magic);
+ m_textWriter.Write (header.Signature.ToByteArray ());
+ m_textWriter.Write (header.Age);
+ m_textWriter.Write (Encoding.ASCII.GetBytes (header.FileName));
+ m_textWriter.Write ((byte) 0);
+ }
+
+ public override void VisitImportTable (ImportTable it)
+ {
+ m_textWriter.BaseStream.Position = m_mdWriter.ImportTablePosition;
+ m_textWriter.Write (it.ImportLookupTable.Value);
+ m_textWriter.Write (it.DateTimeStamp);
+ m_textWriter.Write (it.ForwardChain);
+ m_textWriter.Write (it.Name.Value);
+ m_textWriter.Write (it.ImportAddressTable.Value);
+ m_textWriter.Write (new byte [20]);
+ }
+
+ public override void VisitImportLookupTable (ImportLookupTable ilt)
+ {
+ m_textWriter.Write (ilt.HintNameRVA.Value);
+ m_textWriter.Write (new byte [16]);
+ }
+
+ public override void VisitHintNameTable (HintNameTable hnt)
+ {
+ m_textWriter.Write (hnt.Hint);
+ m_textWriter.Write (Encoding.ASCII.GetBytes (hnt.RuntimeMain));
+ m_textWriter.Write ('\0');
+ m_textWriter.Write (Encoding.ASCII.GetBytes (hnt.RuntimeLibrary));
+ m_textWriter.Write ('\0');
+ m_textWriter.Write (new byte [4]);
+
+ // patch header with ep rva
+ RVA ep = m_img.TextSection.VirtualAddress +
+ (uint) m_textWriter.BaseStream.Position;
+ long pos = m_binaryWriter.BaseStream.Position;
+ m_binaryWriter.BaseStream.Position = 0xa8;
+ m_binaryWriter.Write (ep.Value);
+ m_binaryWriter.BaseStream.Position = pos;
+
+ // patch reloc Sect with ep
+ uint reloc = (ep.Value + 2) % 0x1000;
+ uint rva = (ep.Value + 2) - reloc;
+
+ m_relocWriter.BaseStream.Position = 0;
+ m_relocWriter.Write (rva);
+ m_relocWriter.BaseStream.Position = 8;
+ m_relocWriter.Write ((ushort) ((3 << 12) | reloc));
+
+ m_textWriter.Write (hnt.EntryPoint);
+ m_textWriter.Write (hnt.RVA);
+ }
+
+ public override void TerminateImage (Image img)
+ {
+ m_binaryWriter.BaseStream.Position = 0x200;
+
+ WriteSection (m_textSect, m_textWriter);
+ WriteSection (m_relocSect, m_relocWriter);
+ if (m_rsrcSect != null)
+ WriteSection (m_rsrcSect, m_rsrcWriter);
+ }
+
+ void WriteSection (Section sect, MemoryBinaryWriter sectWriter)
+ {
+ sectWriter.MemoryStream.WriteTo (m_binaryWriter.BaseStream);
+ m_binaryWriter.Write (new byte [
+ sect.SizeOfRawData - sectWriter.BaseStream.Length]);
+ }
+ }
+}
--- /dev/null
+//
+// Imports.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal sealed class ImportAddressTable : IBinaryVisitable {
+
+ public RVA HintNameTableRVA;
+
+ internal ImportAddressTable ()
+ {
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitImportAddressTable (this);
+ }
+ }
+
+ internal sealed class ImportTable : IBinaryVisitable {
+
+ public RVA ImportLookupTable;
+ public uint DateTimeStamp;
+ public uint ForwardChain;
+ public RVA Name;
+ public RVA ImportAddressTable;
+
+ internal ImportTable ()
+ {
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitImportTable (this);
+ }
+ }
+
+ internal sealed class ImportLookupTable : IBinaryVisitable {
+
+ public RVA HintNameRVA;
+
+ internal ImportLookupTable ()
+ {
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitImportLookupTable (this);
+ }
+ }
+
+ internal sealed class HintNameTable : IBinaryVisitable {
+
+ public const string RuntimeMainExe = "_CorExeMain";
+ public const string RuntimeMainDll = "_CorDllMain";
+ public const string RuntimeCorEE = "mscoree.dll";
+
+ public ushort Hint;
+ public string RuntimeMain;
+ public string RuntimeLibrary;
+ public ushort EntryPoint;
+ public RVA RVA;
+
+ internal HintNameTable ()
+ {
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitHintNameTable (this);
+ }
+ }
+}
--- /dev/null
+//
+// MemoryBinaryWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System.IO;
+ using System.Text;
+
+ internal sealed class MemoryBinaryWriter : BinaryWriter {
+
+ public MemoryStream MemoryStream {
+ get { return (MemoryStream) this.BaseStream; }
+ }
+
+ public MemoryBinaryWriter () : base (new MemoryStream ())
+ {
+ }
+
+ public MemoryBinaryWriter (Encoding enc) : base (new MemoryStream (), enc)
+ {
+ }
+
+ public void Empty ()
+ {
+ BaseStream.Position = 0;
+ BaseStream.SetLength (0);
+ }
+
+ public void Write (MemoryBinaryWriter writer)
+ {
+ writer.MemoryStream.WriteTo (this.BaseStream);
+ }
+
+ public byte [] ToArray ()
+ {
+ return MemoryStream.ToArray ();
+ }
+
+ public void QuadAlign ()
+ {
+ BaseStream.Position += 3;
+ BaseStream.Position &= ~3;
+
+ if (BaseStream.Position > BaseStream.Length)
+ BaseStream.SetLength (BaseStream.Position);
+ }
+ }
+}
--- /dev/null
+//
+// PEFileHeader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal sealed class PEFileHeader : IHeader, IBinaryVisitable {
+
+ public ushort Machine;
+ public ushort NumberOfSections;
+ public uint TimeDateStamp;
+ public uint PointerToSymbolTable;
+ public uint NumberOfSymbols;
+ public ushort OptionalHeaderSize;
+ public ImageCharacteristics Characteristics;
+
+ internal PEFileHeader ()
+ {
+ }
+
+ public void SetDefaultValues ()
+ {
+ Machine = 0x14c;
+ PointerToSymbolTable = 0;
+ NumberOfSymbols = 0;
+ OptionalHeaderSize = 0xe0;
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitPEFileHeader (this);
+ }
+ }
+}
--- /dev/null
+//
+// PEOptionalHeader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal sealed class PEOptionalHeader : IHeader, IBinaryVisitable {
+
+ public StandardFieldsHeader StandardFields;
+ public NTSpecificFieldsHeader NTSpecificFields;
+ public DataDirectoriesHeader DataDirectories;
+
+ internal PEOptionalHeader ()
+ {
+ StandardFields = new StandardFieldsHeader ();
+ NTSpecificFields = new NTSpecificFieldsHeader ();
+ DataDirectories = new DataDirectoriesHeader ();
+ }
+
+ public void SetDefaultValues ()
+ {
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitPEOptionalHeader (this);
+
+ StandardFields.Accept (visitor);
+ NTSpecificFields.Accept (visitor);
+ DataDirectories.Accept (visitor);
+ }
+
+ internal sealed class StandardFieldsHeader : IHeader, IBinaryVisitable {
+
+ public ushort Magic;
+ public byte LMajor;
+ public byte LMinor;
+ public uint CodeSize;
+ public uint InitializedDataSize;
+ public uint UninitializedDataSize;
+ public RVA EntryPointRVA;
+ public RVA BaseOfCode;
+ public RVA BaseOfData;
+
+ public bool IsPE64 {
+ get { return Magic == 0x20b; }
+ set {
+ if (value)
+ Magic = 0x20b;
+ else
+ Magic = 0x10b;
+ }
+ }
+
+ internal StandardFieldsHeader ()
+ {
+ }
+
+ public void SetDefaultValues ()
+ {
+ Magic = 0x10b;
+ LMajor = 6;
+ LMinor = 0;
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitStandardFieldsHeader (this);
+ }
+ }
+
+ internal sealed class NTSpecificFieldsHeader : IHeader, IBinaryVisitable {
+
+ public ulong ImageBase;
+ public uint SectionAlignment;
+ public uint FileAlignment;
+ public ushort OSMajor;
+ public ushort OSMinor;
+ public ushort UserMajor;
+ public ushort UserMinor;
+ public ushort SubSysMajor;
+ public ushort SubSysMinor;
+ public uint Reserved;
+ public uint ImageSize;
+ public uint HeaderSize;
+ public uint FileChecksum;
+ public SubSystem SubSystem;
+ public ushort DLLFlags;
+ public ulong StackReserveSize;
+ public ulong StackCommitSize;
+ public ulong HeapReserveSize;
+ public ulong HeapCommitSize;
+ public uint LoaderFlags;
+ public uint NumberOfDataDir;
+
+ internal NTSpecificFieldsHeader ()
+ {
+ }
+
+ public void SetDefaultValues ()
+ {
+ ImageBase = 0x400000;
+ SectionAlignment = 0x2000;
+ FileAlignment = 0x200;
+ OSMajor = 4;
+ OSMinor = 0;
+ UserMajor = 0;
+ UserMinor = 0;
+ SubSysMajor = 4;
+ SubSysMinor = 0;
+ Reserved = 0;
+ HeaderSize = 0x200;
+ FileChecksum = 0;
+ DLLFlags = 0;
+ StackReserveSize = 0x100000;
+ StackCommitSize = 0x1000;
+ HeapReserveSize = 0x100000;
+ HeapCommitSize = 0x1000;
+ LoaderFlags = 0;
+ NumberOfDataDir = 0x10;
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitNTSpecificFieldsHeader (this);
+ }
+ }
+
+ internal sealed class DataDirectoriesHeader : IHeader, IBinaryVisitable {
+
+ public DataDirectory ExportTable;
+ public DataDirectory ImportTable;
+ public DataDirectory ResourceTable;
+ public DataDirectory ExceptionTable;
+ public DataDirectory CertificateTable;
+ public DataDirectory BaseRelocationTable;
+ public DataDirectory Debug;
+ public DataDirectory Copyright;
+ public DataDirectory GlobalPtr;
+ public DataDirectory TLSTable;
+ public DataDirectory LoadConfigTable;
+ public DataDirectory BoundImport;
+ public DataDirectory IAT;
+ public DataDirectory DelayImportDescriptor;
+ public DataDirectory CLIHeader;
+ public DataDirectory Reserved;
+
+ internal DataDirectoriesHeader ()
+ {
+ }
+
+ public void SetDefaultValues ()
+ {
+ ExportTable = DataDirectory.Zero;
+ ResourceTable = DataDirectory.Zero;
+ ExceptionTable = DataDirectory.Zero;
+ CertificateTable = DataDirectory.Zero;
+ Debug = DataDirectory.Zero;
+ Copyright = DataDirectory.Zero;
+ GlobalPtr = DataDirectory.Zero;
+ TLSTable = DataDirectory.Zero;
+ LoadConfigTable = DataDirectory.Zero;
+ BoundImport = DataDirectory.Zero;
+ IAT = new DataDirectory (new RVA (0x2000), 8);
+ DelayImportDescriptor = DataDirectory.Zero;
+ CLIHeader = new DataDirectory (new RVA (0x2008), 0x48);
+ Reserved = DataDirectory.Zero;
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitDataDirectoriesHeader (this);
+ }
+ }
+ }
+}
--- /dev/null
+//
+// RVA.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal struct RVA {
+
+ public static readonly RVA Zero = new RVA (0);
+
+ uint m_rva;
+
+ public uint Value {
+ get { return m_rva; }
+ set { m_rva = value; }
+ }
+
+ public RVA (uint rva)
+ {
+ m_rva = rva;
+ }
+
+ public override int GetHashCode ()
+ {
+ return (int) m_rva;
+ }
+
+ public override bool Equals (object other)
+ {
+ if (other is RVA)
+ return this.m_rva == ((RVA) other).m_rva;
+
+ return false;
+ }
+
+ public override string ToString ()
+ {
+ return string.Format ("0x{0}", m_rva.ToString ("X"));
+ }
+
+ public static bool operator == (RVA one, RVA other)
+ {
+ return one.m_rva == other.m_rva;
+ }
+
+ public static bool operator != (RVA one, RVA other)
+ {
+ return one.m_rva != other.m_rva;
+ }
+
+ public static bool operator < (RVA one, RVA other)
+ {
+ return one.m_rva < other.m_rva;
+ }
+
+ public static bool operator > (RVA one, RVA other)
+ {
+ return one.m_rva > other.m_rva;
+ }
+
+ public static bool operator <= (RVA one, RVA other)
+ {
+ return one.m_rva <= other.m_rva;
+ }
+
+ public static bool operator >= (RVA one, RVA other)
+ {
+ return one.m_rva >= other.m_rva;
+ }
+
+ public static RVA operator + (RVA rva, uint x)
+ {
+ return new RVA (rva.m_rva + x);
+ }
+
+ public static RVA operator - (RVA rva, uint x)
+ {
+ return new RVA (rva.m_rva - x);
+ }
+
+ public static implicit operator RVA (uint val)
+ {
+ return val == 0 ? Zero : new RVA (val);
+ }
+
+ public static implicit operator uint (RVA rva)
+ {
+ return rva.m_rva;
+ }
+ }
+}
--- /dev/null
+//
+// ResourceDataEntry.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal class ResourceDataEntry : ResourceNode {
+
+ public RVA Data;
+ public uint Size;
+ public uint Codepage;
+ public uint Reserved = 0;
+
+ public byte [] ResourceData;
+
+ public ResourceDataEntry (int offset) : base (offset)
+ {
+ }
+
+ public ResourceDataEntry ()
+ {
+ }
+ }
+}
--- /dev/null
+//
+// ResourceDirectoryEntry.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal class ResourceDirectoryEntry : ResourceNode {
+
+ private bool m_idByName;
+
+ public int ID;
+ public ResourceDirectoryString Name;
+
+ public bool IdentifiedByName {
+ get { return m_idByName; }
+ }
+
+ public ResourceNode Child;
+
+ public ResourceDirectoryEntry (ResourceDirectoryString name)
+ {
+ this.Name = name;
+ m_idByName = true;
+ }
+
+ public ResourceDirectoryEntry (ResourceDirectoryString name, int offset) : base (offset)
+ {
+ this.Name = name;
+ m_idByName = true;
+ }
+
+ public ResourceDirectoryEntry (int id)
+ {
+ this.ID = id;
+ }
+
+ public ResourceDirectoryEntry (int id, int offset) : base (offset)
+ {
+ this.ID = id;
+ }
+ }
+}
--- /dev/null
+//
+// ResourceDirectoryString.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal class ResourceDirectoryString : ResourceNode {
+
+ public string String;
+
+ public ResourceDirectoryString (string str)
+ {
+ this.String = str;
+ }
+
+ public ResourceDirectoryString (string str, int offset) : base (offset)
+ {
+ this.String = str;
+ }
+ }
+}
--- /dev/null
+//
+// ResourceDirectoryTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System.Collections;
+
+ internal class ResourceDirectoryTable : ResourceNode {
+
+ private ArrayList m_entries;
+
+ public uint Characteristics;
+ public uint TimeDateStamp;
+ public ushort MajorVersion;
+ public ushort MinorVersion;
+
+ public IList Entries {
+ get { return m_entries; }
+ }
+
+ public ResourceDirectoryTable (int offset) : base (offset)
+ {
+ m_entries = new ArrayList ();
+ }
+
+ public ResourceDirectoryTable ()
+ {
+ m_entries = new ArrayList ();
+ }
+ }
+}
--- /dev/null
+//
+// ResourceNode.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal abstract class ResourceNode {
+
+ public int Offset;
+
+ internal ResourceNode (int offset)
+ {
+ this.Offset = offset;
+ }
+
+ internal ResourceNode ()
+ {
+ }
+ }
+}
--- /dev/null
+//
+// ResourceReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System;
+ using System.IO;
+ using System.Text;
+
+ sealed class ResourceReader {
+
+ Image m_img;
+ Section m_rsrc;
+ BinaryReader m_reader;
+
+ public ResourceReader (Image img)
+ {
+ m_img = img;
+ }
+
+ public ResourceDirectoryTable Read ()
+ {
+ m_rsrc = GetResourceSection ();
+ if (m_rsrc == null)
+ return null;
+
+ m_reader = new BinaryReader (new MemoryStream (m_rsrc.Data));
+ return ReadDirectoryTable ();
+ }
+
+ Section GetResourceSection ()
+ {
+ foreach (Section s in m_img.Sections)
+ if (s.Name == Section.Resources)
+ return s;
+
+ return null;
+ }
+
+ int GetOffset ()
+ {
+ return (int) m_reader.BaseStream.Position;
+ }
+
+ ResourceDirectoryTable ReadDirectoryTable ()
+ {
+ ResourceDirectoryTable rdt = new ResourceDirectoryTable (GetOffset ());
+ rdt.Characteristics = m_reader.ReadUInt32 ();
+ rdt.TimeDateStamp = m_reader.ReadUInt32 ();
+ rdt.MajorVersion = m_reader.ReadUInt16 ();
+ rdt.MinorVersion = m_reader.ReadUInt16 ();
+ ushort nameEntries = m_reader.ReadUInt16 ();
+ ushort idEntries = m_reader.ReadUInt16 ();
+
+ for (int i = 0; i < nameEntries; i++)
+ rdt.Entries.Add (ReadDirectoryEntry ());
+
+ for (int i = 0; i < idEntries; i++)
+ rdt.Entries.Add (ReadDirectoryEntry ());
+
+ return rdt;
+ }
+
+ ResourceDirectoryEntry ReadDirectoryEntry ()
+ {
+ uint name = m_reader.ReadUInt32 ();
+ uint child = m_reader.ReadUInt32 ();
+
+ ResourceDirectoryEntry rde;
+ if ((name & 0x80000000) != 0)
+ rde = new ResourceDirectoryEntry (ReadDirectoryString ((int) name & 0x7fffffff), GetOffset ());
+ else
+ rde = new ResourceDirectoryEntry ((int) name & 0x7fffffff, GetOffset ());
+
+ long pos = m_reader.BaseStream.Position;
+ m_reader.BaseStream.Position = child & 0x7fffffff;
+
+ if ((child & 0x80000000) != 0)
+ rde.Child = ReadDirectoryTable ();
+ else
+ rde.Child = ReadDataEntry ();
+
+ m_reader.BaseStream.Position = pos;
+
+ return rde;
+ }
+
+ ResourceDirectoryString ReadDirectoryString (int offset)
+ {
+ long pos = m_reader.BaseStream.Position;
+ m_reader.BaseStream.Position = offset;
+
+ byte [] str = m_reader.ReadBytes (m_reader.ReadUInt16 ());
+
+ ResourceDirectoryString rds = new ResourceDirectoryString (
+ Encoding.Unicode.GetString (str, 0, str.Length),
+ GetOffset ());
+
+ m_reader.BaseStream.Position = pos;
+
+ return rds;
+ }
+
+ ResourceNode ReadDataEntry ()
+ {
+ ResourceDataEntry rde = new ResourceDataEntry (GetOffset ());
+ rde.Data = m_reader.ReadUInt32 ();
+ rde.Size = m_reader.ReadUInt32 ();
+ rde.Codepage = m_reader.ReadUInt32 ();
+ rde.Reserved = m_reader.ReadUInt32 ();
+
+ Section sect = m_img.GetSectionAtVirtualAddress (rde.Data);
+ byte [] data = new byte [rde.Size];
+ Buffer.BlockCopy (sect.Data, (int)(long)(rde.Data - sect.VirtualAddress), data, 0, (int)rde.Size);
+ rde.ResourceData = data;
+
+ return rde;
+ }
+ }
+}
--- /dev/null
+//
+// ResourceWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.Text;
+
+namespace Mono.Cecil.Binary {
+
+ using System.Collections;
+
+ sealed class ResourceWriter {
+
+ Image m_img;
+ Section m_rsrc;
+ MemoryBinaryWriter m_writer;
+
+ ArrayList m_dataEntries;
+ ArrayList m_stringEntries;
+
+ long m_pos;
+
+ public ResourceWriter (Image img, Section rsrc, MemoryBinaryWriter writer)
+ {
+ m_img = img;
+ m_rsrc = rsrc;
+ m_writer = writer;
+
+ m_dataEntries = new ArrayList ();
+ m_stringEntries = new ArrayList ();
+ }
+
+ public void Write ()
+ {
+ if (m_img.ResourceDirectoryRoot == null)
+ return;
+
+ ComputeOffset (m_img.ResourceDirectoryRoot);
+ WriteResourceDirectoryTable (m_img.ResourceDirectoryRoot);
+ }
+
+ public void Patch ()
+ {
+ foreach (ResourceDataEntry rde in m_dataEntries) {
+ GotoOffset (rde.Offset);
+ m_writer.Write ((uint) rde.Data + m_rsrc.VirtualAddress);
+ RestoreOffset ();
+ }
+ }
+
+ void ComputeOffset (ResourceDirectoryTable root)
+ {
+ int offset = 0;
+
+ Queue directoryTables = new Queue ();
+ directoryTables.Enqueue (root);
+
+ while (directoryTables.Count > 0) {
+ ResourceDirectoryTable rdt = directoryTables.Dequeue () as ResourceDirectoryTable;
+ rdt.Offset = offset;
+ offset += 16;
+
+ foreach (ResourceDirectoryEntry rde in rdt.Entries) {
+ rde.Offset = offset;
+ offset += 8;
+ if (rde.IdentifiedByName)
+ m_stringEntries.Add (rde.Name);
+
+ if (rde.Child is ResourceDirectoryTable)
+ directoryTables.Enqueue (rde.Child);
+ else
+ m_dataEntries.Add (rde.Child);
+ }
+ }
+
+ foreach (ResourceDataEntry rde in m_dataEntries) {
+ rde.Offset = offset;
+ offset += 16;
+ }
+
+ foreach (ResourceDirectoryString rds in m_stringEntries) {
+ rds.Offset = offset;
+ byte [] str = Encoding.Unicode.GetBytes (rds.String);
+ offset += 2 + str.Length;
+
+ offset += 3;
+ offset &= ~3;
+ }
+
+ foreach (ResourceDataEntry rde in m_dataEntries) {
+ rde.Data = (uint) offset;
+
+ offset += rde.ResourceData.Length;
+ offset += 3;
+ offset &= ~3;
+ }
+
+ m_writer.Write (new byte [offset]);
+ }
+
+ void WriteResourceDirectoryTable (ResourceDirectoryTable rdt)
+ {
+ GotoOffset (rdt.Offset);
+
+ m_writer.Write (rdt.Characteristics);
+ m_writer.Write (rdt.TimeDateStamp);
+ m_writer.Write (rdt.MajorVersion);
+ m_writer.Write (rdt.MinorVersion);
+
+ ResourceDirectoryEntry [] namedEntries = GetEntries (rdt, true);
+ ResourceDirectoryEntry [] idEntries = GetEntries (rdt, false);
+
+ m_writer.Write ((ushort) namedEntries.Length);
+ m_writer.Write ((ushort) idEntries.Length);
+
+ foreach (ResourceDirectoryEntry rde in namedEntries)
+ WriteResourceDirectoryEntry (rde);
+
+ foreach (ResourceDirectoryEntry rde in idEntries)
+ WriteResourceDirectoryEntry (rde);
+
+ RestoreOffset ();
+ }
+
+ ResourceDirectoryEntry [] GetEntries (ResourceDirectoryTable rdt, bool identifiedByName)
+ {
+ ArrayList entries = new ArrayList ();
+ foreach (ResourceDirectoryEntry rde in rdt.Entries)
+ if (rde.IdentifiedByName == identifiedByName)
+ entries.Add (rde);
+
+ return entries.ToArray (typeof (ResourceDirectoryEntry)) as ResourceDirectoryEntry [];
+ }
+
+ void WriteResourceDirectoryEntry (ResourceDirectoryEntry rde)
+ {
+ GotoOffset (rde.Offset);
+
+ if (rde.IdentifiedByName) {
+ m_writer.Write ((uint) rde.Name.Offset | 0x80000000);
+ WriteResourceDirectoryString (rde.Name);
+ } else
+ m_writer.Write ((uint) rde.ID);
+
+ if (rde.Child is ResourceDirectoryTable) {
+ m_writer.Write((uint) rde.Child.Offset | 0x80000000);
+ WriteResourceDirectoryTable (rde.Child as ResourceDirectoryTable);
+ } else {
+ m_writer.Write (rde.Child.Offset);
+ WriteResourceDataEntry (rde.Child as ResourceDataEntry);
+ }
+
+ RestoreOffset ();
+ }
+
+ void WriteResourceDataEntry (ResourceDataEntry rde)
+ {
+ GotoOffset (rde.Offset);
+
+ m_writer.Write (0);
+ m_writer.Write ((uint) rde.ResourceData.Length);
+ m_writer.Write (rde.Codepage);
+ m_writer.Write (rde.Reserved);
+
+ m_writer.BaseStream.Position = rde.Data;
+ m_writer.Write (rde.ResourceData);
+
+ RestoreOffset ();
+ }
+
+ void WriteResourceDirectoryString (ResourceDirectoryString name)
+ {
+ GotoOffset (name.Offset);
+
+ byte [] str = Encoding.Unicode.GetBytes (name.String);
+ m_writer.Write ((ushort) str.Length);
+ m_writer.Write (str);
+
+ RestoreOffset ();
+ }
+
+ void GotoOffset (int offset)
+ {
+ m_pos = m_writer.BaseStream.Position;
+ m_writer.BaseStream.Position = offset;
+ }
+
+ void RestoreOffset ()
+ {
+ m_writer.BaseStream.Position = m_pos;
+ }
+ }
+}
--- /dev/null
+//
+// RuntimeImage.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace Mono.Cecil.Binary {
+
+ [Flags]
+ internal enum RuntimeImage : uint {
+ ILOnly = 0x0000001,
+ F32BitsRequired = 0x0000002,
+ StrongNameSigned = 0x0000008,
+ TrackDebugData = 0x00010000
+ }
+}
--- /dev/null
+//
+// Section.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal sealed class Section : IHeader, IBinaryVisitable {
+
+ public const string Text = ".text";
+ public const string Resources = ".rsrc";
+ public const string Relocs = ".reloc";
+ public const string SData = ".sdata";
+
+ public uint VirtualSize;
+ public RVA VirtualAddress;
+ public uint SizeOfRawData;
+ public RVA PointerToRawData;
+ public RVA PointerToRelocations;
+ public RVA PointerToLineNumbers;
+ public ushort NumberOfRelocations;
+ public ushort NumberOfLineNumbers;
+ public SectionCharacteristics Characteristics;
+
+ public string Name;
+ public byte [] Data;
+
+ internal Section ()
+ {
+ }
+
+ public void SetDefaultValues ()
+ {
+ PointerToLineNumbers = RVA.Zero;
+ NumberOfLineNumbers = 0;
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitSection (this);
+ }
+ }
+}
--- /dev/null
+//
+// SectionCharacteristics.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System;
+
+ [Flags]
+ internal enum SectionCharacteristics : uint {
+ TypeNoPad = 0x0000008,
+ ContainsCode = 0x00000020,
+ ContainsInitializedData = 0x00000040,
+ ContainsUninitializedData = 0x00000080,
+ LnkOther = 0x0000100,
+ LnkInfo = 0x000200,
+ LnkRemove = 0x0000800,
+ LnkCOMDAT = 0x00001000,
+ GPRel = 0x00008000,
+ MemPurgeable = 0x00020000,
+ MemLocked = 0x00040000,
+ MemPreload = 0x00080000,
+ Align1Bytes = 0x00100000,
+ Align2Bytes = 0x00200000,
+ Align4Bytes = 0x00300000,
+ Align8Bytes = 0x00400000,
+ Align16Bytes = 0x00500000,
+ Align32Bytes = 0x00600000,
+ Align64Bytes = 0x00700000,
+ Align128Bytes = 0x00800000,
+ Align256Bytes = 0x00900000,
+ Align512Bytes = 0x00a00000,
+ Align1024Bytes = 0x00b00000,
+ Align2048Bytes = 0x00c00000,
+ Align4096Bytes = 0x00d00000,
+ Align8192Bytes = 0x00e00000,
+ LnkNRelocOvfl = 0x01000000,
+ MemDiscardable = 0x02000000,
+ MemNotCached = 0x04000000,
+ MemNotPaged = 0x08000000,
+ MemShared = 0x10000000,
+ MemExecute = 0x20000000,
+ MemoryRead = 0x40000000,
+ MemoryWrite = 0x80000000
+ }
+}
--- /dev/null
+//
+// SectionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ using System;
+ using System.Collections;
+
+ internal sealed class SectionCollection : ICollection, IBinaryVisitable {
+
+ IList m_items;
+
+ public Section this [int index]
+ {
+ get { return m_items [index] as Section; }
+ set { m_items [index] = value; }
+ }
+
+ public int Count {
+ get { return m_items.Count; }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ internal SectionCollection ()
+ {
+ m_items = new ArrayList (4);
+ }
+
+ internal void Add (Section value)
+ {
+ m_items.Add (value);
+ }
+
+ internal void Clear ()
+ {
+ m_items.Clear ();
+ }
+
+ public bool Contains (Section value)
+ {
+ return m_items.Contains (value);
+ }
+
+ public int IndexOf (Section value)
+ {
+ return m_items.IndexOf (value);
+ }
+
+ internal void Insert (int index, Section value)
+ {
+ m_items.Insert (index, value);
+ }
+
+ internal void Remove (Section value)
+ {
+ m_items.Remove (value);
+ }
+
+ internal void RemoveAt (int index)
+ {
+ m_items.Remove (index);
+ }
+
+ public void CopyTo (Array ary, int index)
+ {
+ m_items.CopyTo (ary, index);
+ }
+
+ public IEnumerator GetEnumerator ()
+ {
+ return m_items.GetEnumerator ();
+ }
+
+ public void Accept (IBinaryVisitor visitor)
+ {
+ visitor.VisitSectionCollection (this);
+
+ for (int i = 0; i < m_items.Count; i++)
+ this [i].Accept (visitor);
+ }
+ }
+}
--- /dev/null
+//
+// SubSystem.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Binary {
+
+ internal enum SubSystem : ushort {
+ Unknown = 0x0,
+ Native = 0x1,
+ WindowsGui = 0x2,
+ WindowsCui = 0x3,
+ PosixCui = 0x7,
+ WindowsCeGui = 0x9,
+ EfiApplication = 0x10,
+ EfiBootServiceDriver = 0x11,
+ EfiRuntimeDriver = 0x12,
+ EfiRom = 0x13,
+ Xbox = 0x14,
+ NexusAgent = 0x15
+ }
+}
--- /dev/null
+//
+// BaseCodeVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal abstract class BaseCodeVisitor : ICodeVisitor {
+
+ public virtual void VisitMethodBody (MethodBody body)
+ {
+ }
+
+ public virtual void VisitInstructionCollection (InstructionCollection instructions)
+ {
+ }
+
+ public virtual void VisitInstruction (Instruction instr)
+ {
+ }
+
+ public virtual void VisitExceptionHandlerCollection (ExceptionHandlerCollection seh)
+ {
+ }
+
+ public virtual void VisitExceptionHandler (ExceptionHandler eh)
+ {
+ }
+
+ public virtual void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
+ {
+ }
+
+ public virtual void VisitVariableDefinition (VariableDefinition var)
+ {
+ }
+
+ public virtual void VisitScopeCollection (ScopeCollection scopes)
+ {
+ }
+
+ public virtual void VisitScope (Scope s)
+ {
+ }
+
+ public virtual void TerminateMethodBody (MethodBody body)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// CilWorker.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+ using SR = System.Reflection;
+
+ internal sealed class CilWorker {
+
+ MethodBody m_mbody;
+ InstructionCollection m_instrs;
+
+ internal CilWorker (MethodBody body)
+ {
+ m_mbody = body;
+ m_instrs = m_mbody.Instructions;
+ }
+
+ public MethodBody GetBody ()
+ {
+ return m_mbody;
+ }
+
+ public Instruction Create (OpCode opcode)
+ {
+ if (opcode.OperandType != OperandType.InlineNone)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode);
+ }
+
+ public Instruction Create (OpCode opcode, TypeReference type)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+ if (opcode.OperandType != OperandType.InlineType &&
+ opcode.OperandType != OperandType.InlineTok)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, type);
+ }
+
+ public Instruction Create (OpCode opcode, CallSite site)
+ {
+ if (site == null)
+ throw new ArgumentNullException ("site");
+ if (opcode.Code != Code.Calli)
+ throw new ArgumentException ("code");
+
+ return FinalCreate (opcode, site);
+ }
+
+ public Instruction Create (OpCode opcode, MethodReference method)
+ {
+ if (method == null)
+ throw new ArgumentNullException ("method");
+ if (opcode.OperandType != OperandType.InlineMethod &&
+ opcode.OperandType != OperandType.InlineTok)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, method);
+ }
+
+ public Instruction Create (OpCode opcode, FieldReference field)
+ {
+ if (field == null)
+ throw new ArgumentNullException ("field");
+ if (opcode.OperandType != OperandType.InlineField &&
+ opcode.OperandType != OperandType.InlineTok)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, field);
+ }
+
+ public Instruction Create (OpCode opcode, string str)
+ {
+ if (str == null)
+ throw new ArgumentNullException ("str");
+ if (opcode.OperandType != OperandType.InlineString)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, str);
+ }
+
+ public Instruction Create (OpCode opcode, sbyte b)
+ {
+ if (opcode.OperandType != OperandType.ShortInlineI &&
+ opcode != OpCodes.Ldc_I4_S)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, b);
+ }
+
+ public Instruction Create (OpCode opcode, byte b)
+ {
+ if (opcode.OperandType == OperandType.ShortInlineVar)
+ return Create (opcode, m_mbody.Variables [b]);
+
+ if (opcode.OperandType == OperandType.ShortInlineParam)
+ return Create (opcode, CodeReader.GetParameter (m_mbody, b));
+
+ if (opcode.OperandType != OperandType.ShortInlineI ||
+ opcode == OpCodes.Ldc_I4_S)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, b);
+ }
+
+ public Instruction Create (OpCode opcode, int i)
+ {
+ if (opcode.OperandType == OperandType.InlineVar)
+ return Create (opcode, m_mbody.Variables [i]);
+
+ if (opcode.OperandType == OperandType.InlineParam)
+ return Create (opcode, CodeReader.GetParameter (m_mbody, i));
+
+ if (opcode.OperandType != OperandType.InlineI)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, i);
+ }
+
+ public Instruction Create (OpCode opcode, long l)
+ {
+ if (opcode.OperandType != OperandType.InlineI8)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, l);
+ }
+
+ public Instruction Create (OpCode opcode, float f)
+ {
+ if (opcode.OperandType != OperandType.ShortInlineR)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, f);
+ }
+
+ public Instruction Create (OpCode opcode, double d)
+ {
+ if (opcode.OperandType != OperandType.InlineR)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, d);
+ }
+
+ public Instruction Create (OpCode opcode, Instruction label)
+ {
+ if (label == null)
+ throw new ArgumentNullException ("label");
+ if (opcode.OperandType != OperandType.InlineBrTarget &&
+ opcode.OperandType != OperandType.ShortInlineBrTarget)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, label);
+ }
+
+ public Instruction Create (OpCode opcode, Instruction [] labels)
+ {
+ if (labels == null)
+ throw new ArgumentNullException ("labels");
+ if (opcode.OperandType != OperandType.InlineSwitch)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, labels);
+ }
+
+ public Instruction Create (OpCode opcode, VariableDefinition var)
+ {
+ if (var == null)
+ throw new ArgumentNullException ("var");
+ if (opcode.OperandType != OperandType.ShortInlineVar &&
+ opcode.OperandType != OperandType.InlineVar)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, var);
+ }
+
+ public Instruction Create (OpCode opcode, ParameterDefinition param)
+ {
+ if (param == null)
+ throw new ArgumentNullException ("param");
+ if (opcode.OperandType != OperandType.ShortInlineParam &&
+ opcode.OperandType != OperandType.InlineParam)
+ throw new ArgumentException ("opcode");
+
+ return FinalCreate (opcode, param);
+ }
+
+ static Instruction FinalCreate (OpCode opcode)
+ {
+ return FinalCreate (opcode, null);
+ }
+
+ static Instruction FinalCreate (OpCode opcode, object operand)
+ {
+ return new Instruction (opcode, operand);
+ }
+
+ public Instruction Emit (OpCode opcode)
+ {
+ Instruction instr = Create (opcode);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, TypeReference type)
+ {
+ Instruction instr = Create (opcode, type);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, MethodReference meth)
+ {
+ Instruction instr = Create (opcode, meth);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, CallSite site)
+ {
+ Instruction instr = Create (opcode, site);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, FieldReference field)
+ {
+ Instruction instr = Create (opcode, field);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, string str)
+ {
+ Instruction instr = Create (opcode, str);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, byte b)
+ {
+ Instruction instr = Create (opcode, b);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, sbyte b)
+ {
+ Instruction instr = Create (opcode, b);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, int i)
+ {
+ Instruction instr = Create (opcode, i);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, long l)
+ {
+ Instruction instr = Create (opcode, l);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, float f)
+ {
+ Instruction instr = Create (opcode, f);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, double d)
+ {
+ Instruction instr = Create (opcode, d);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, Instruction target)
+ {
+ Instruction instr = Create (opcode, target);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, Instruction [] targets)
+ {
+ Instruction instr = Create (opcode, targets);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, VariableDefinition var)
+ {
+ Instruction instr = Create (opcode, var);
+ Append (instr);
+ return instr;
+ }
+
+ public Instruction Emit (OpCode opcode, ParameterDefinition param)
+ {
+ Instruction instr = Create (opcode, param);
+ Append (instr);
+ return instr;
+ }
+
+ public void InsertBefore (Instruction target, Instruction instr)
+ {
+ int index = m_instrs.IndexOf (target);
+ if (index == -1)
+ throw new ArgumentOutOfRangeException ("Target instruction not in method body");
+
+ m_instrs.Insert (index, instr);
+ instr.Previous = target.Previous;
+ if (target.Previous != null)
+ target.Previous.Next = instr;
+ target.Previous = instr;
+ instr.Next = target;
+ }
+
+ public void InsertAfter (Instruction target, Instruction instr)
+ {
+ int index = m_instrs.IndexOf (target);
+ if (index == -1)
+ throw new ArgumentOutOfRangeException ("Target instruction not in method body");
+
+ m_instrs.Insert (index + 1, instr);
+ instr.Next = target.Next;
+ if (target.Next != null)
+ target.Next.Previous = instr;
+ target.Next = instr;
+ instr.Previous = target;
+ }
+
+ public void Append (Instruction instr)
+ {
+ Instruction last = null, current = instr;
+ if (m_instrs.Count > 0)
+ last = m_instrs [m_instrs.Count - 1];
+
+ if (last != null) {
+ last.Next = instr;
+ current.Previous = last;
+ }
+
+ m_instrs.Add (current);
+ }
+
+ public void Replace (Instruction old, Instruction instr)
+ {
+ int index = m_instrs.IndexOf (old);
+ if (index == -1)
+ throw new ArgumentOutOfRangeException ("Target instruction not in method body");
+
+ InsertAfter (old, instr);
+ Remove (old);
+ }
+
+ public void Remove (Instruction instr)
+ {
+ if (!m_instrs.Contains (instr))
+ throw new ArgumentException ("Instruction not in method body");
+
+ if (instr.Previous != null)
+ instr.Previous.Next = instr.Next;
+ if (instr.Next != null)
+ instr.Next.Previous = instr.Previous;
+ m_instrs.Remove (instr);
+ }
+ }
+}
--- /dev/null
+//
+// Code.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Mar 16 15:37:23 +0100 2007
+//
+// (C) 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal enum Code {
+ Nop,
+ Break,
+ Ldarg_0,
+ Ldarg_1,
+ Ldarg_2,
+ Ldarg_3,
+ Ldloc_0,
+ Ldloc_1,
+ Ldloc_2,
+ Ldloc_3,
+ Stloc_0,
+ Stloc_1,
+ Stloc_2,
+ Stloc_3,
+ Ldarg_S,
+ Ldarga_S,
+ Starg_S,
+ Ldloc_S,
+ Ldloca_S,
+ Stloc_S,
+ Ldnull,
+ Ldc_I4_M1,
+ Ldc_I4_0,
+ Ldc_I4_1,
+ Ldc_I4_2,
+ Ldc_I4_3,
+ Ldc_I4_4,
+ Ldc_I4_5,
+ Ldc_I4_6,
+ Ldc_I4_7,
+ Ldc_I4_8,
+ Ldc_I4_S,
+ Ldc_I4,
+ Ldc_I8,
+ Ldc_R4,
+ Ldc_R8,
+ Dup,
+ Pop,
+ Jmp,
+ Call,
+ Calli,
+ Ret,
+ Br_S,
+ Brfalse_S,
+ Brtrue_S,
+ Beq_S,
+ Bge_S,
+ Bgt_S,
+ Ble_S,
+ Blt_S,
+ Bne_Un_S,
+ Bge_Un_S,
+ Bgt_Un_S,
+ Ble_Un_S,
+ Blt_Un_S,
+ Br,
+ Brfalse,
+ Brtrue,
+ Beq,
+ Bge,
+ Bgt,
+ Ble,
+ Blt,
+ Bne_Un,
+ Bge_Un,
+ Bgt_Un,
+ Ble_Un,
+ Blt_Un,
+ Switch,
+ Ldind_I1,
+ Ldind_U1,
+ Ldind_I2,
+ Ldind_U2,
+ Ldind_I4,
+ Ldind_U4,
+ Ldind_I8,
+ Ldind_I,
+ Ldind_R4,
+ Ldind_R8,
+ Ldind_Ref,
+ Stind_Ref,
+ Stind_I1,
+ Stind_I2,
+ Stind_I4,
+ Stind_I8,
+ Stind_R4,
+ Stind_R8,
+ Add,
+ Sub,
+ Mul,
+ Div,
+ Div_Un,
+ Rem,
+ Rem_Un,
+ And,
+ Or,
+ Xor,
+ Shl,
+ Shr,
+ Shr_Un,
+ Neg,
+ Not,
+ Conv_I1,
+ Conv_I2,
+ Conv_I4,
+ Conv_I8,
+ Conv_R4,
+ Conv_R8,
+ Conv_U4,
+ Conv_U8,
+ Callvirt,
+ Cpobj,
+ Ldobj,
+ Ldstr,
+ Newobj,
+ Castclass,
+ Isinst,
+ Conv_R_Un,
+ Unbox,
+ Throw,
+ Ldfld,
+ Ldflda,
+ Stfld,
+ Ldsfld,
+ Ldsflda,
+ Stsfld,
+ Stobj,
+ Conv_Ovf_I1_Un,
+ Conv_Ovf_I2_Un,
+ Conv_Ovf_I4_Un,
+ Conv_Ovf_I8_Un,
+ Conv_Ovf_U1_Un,
+ Conv_Ovf_U2_Un,
+ Conv_Ovf_U4_Un,
+ Conv_Ovf_U8_Un,
+ Conv_Ovf_I_Un,
+ Conv_Ovf_U_Un,
+ Box,
+ Newarr,
+ Ldlen,
+ Ldelema,
+ Ldelem_I1,
+ Ldelem_U1,
+ Ldelem_I2,
+ Ldelem_U2,
+ Ldelem_I4,
+ Ldelem_U4,
+ Ldelem_I8,
+ Ldelem_I,
+ Ldelem_R4,
+ Ldelem_R8,
+ Ldelem_Ref,
+ Stelem_I,
+ Stelem_I1,
+ Stelem_I2,
+ Stelem_I4,
+ Stelem_I8,
+ Stelem_R4,
+ Stelem_R8,
+ Stelem_Ref,
+ Ldelem_Any,
+ Stelem_Any,
+ Unbox_Any,
+ Conv_Ovf_I1,
+ Conv_Ovf_U1,
+ Conv_Ovf_I2,
+ Conv_Ovf_U2,
+ Conv_Ovf_I4,
+ Conv_Ovf_U4,
+ Conv_Ovf_I8,
+ Conv_Ovf_U8,
+ Refanyval,
+ Ckfinite,
+ Mkrefany,
+ Ldtoken,
+ Conv_U2,
+ Conv_U1,
+ Conv_I,
+ Conv_Ovf_I,
+ Conv_Ovf_U,
+ Add_Ovf,
+ Add_Ovf_Un,
+ Mul_Ovf,
+ Mul_Ovf_Un,
+ Sub_Ovf,
+ Sub_Ovf_Un,
+ Endfinally,
+ Leave,
+ Leave_S,
+ Stind_I,
+ Conv_U,
+ Arglist,
+ Ceq,
+ Cgt,
+ Cgt_Un,
+ Clt,
+ Clt_Un,
+ Ldftn,
+ Ldvirtftn,
+ Ldarg,
+ Ldarga,
+ Starg,
+ Ldloc,
+ Ldloca,
+ Stloc,
+ Localloc,
+ Endfilter,
+ Unaligned,
+ Volatile,
+ Tail,
+ Initobj,
+ Constrained,
+ Cpblk,
+ Initblk,
+ No,
+ Rethrow,
+ Sizeof,
+ Refanytype,
+ Readonly,
+ }
+}
--- /dev/null
+//
+// CodeReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+ using System.Collections;
+ using System.IO;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Metadata;
+ using Mono.Cecil.Signatures;
+
+ sealed class CodeReader : BaseCodeVisitor {
+
+ ReflectionReader m_reflectReader;
+ MetadataRoot m_root;
+ IDictionary m_instructions;
+
+ public CodeReader (ReflectionReader reflectReader)
+ {
+ m_reflectReader = reflectReader;
+ m_root = m_reflectReader.MetadataRoot;
+ m_instructions = new Hashtable ();
+ }
+
+ public override void VisitMethodBody (MethodBody body)
+ {
+ MethodDefinition meth = body.Method;
+ MethodBody methBody = body;
+ BinaryReader br = m_reflectReader.Module.ImageReader.MetadataReader.GetDataReader (meth.RVA);
+
+ // lets read the method
+ int flags = br.ReadByte ();
+ switch (flags & 0x3) {
+ case (int) MethodHeader.TinyFormat :
+ methBody.CodeSize = flags >> 2;
+ methBody.MaxStack = 8;
+ ReadCilBody (methBody, br);
+ break;
+ case (int) MethodHeader.FatFormat :
+ br.BaseStream.Position--;
+ int fatflags = br.ReadUInt16 ();
+ //int headersize = (fatflags >> 12) & 0xf;
+ methBody.MaxStack = br.ReadUInt16 ();
+ methBody.CodeSize = br.ReadInt32 ();
+ methBody.LocalVarToken = br.ReadInt32 ();
+ body.InitLocals = (fatflags & (int) MethodHeader.InitLocals) != 0;
+ if (methBody.LocalVarToken != 0)
+ VisitVariableDefinitionCollection (methBody.Variables);
+ ReadCilBody (methBody, br);
+ if ((fatflags & (int) MethodHeader.MoreSects) != 0)
+ ReadSection (methBody, br);
+ break;
+ }
+ }
+
+ public static uint GetRid (int token)
+ {
+ return (uint) token & 0x00ffffff;
+ }
+
+ public static ParameterDefinition GetParameter (MethodBody body, int index)
+ {
+ if (body.Method.HasThis) {
+ if (index == 0)
+ return body.Method.This;
+ index--;
+ }
+
+ return body.Method.Parameters [index];
+ }
+
+ public static VariableDefinition GetVariable (MethodBody body, int index)
+ {
+ // bug 15727 - newer cecil does the same (in MethodDefinition.GetVariable)
+ var variables = body.Variables;
+ if (index < 0 || index >= variables.Count)
+ return null;
+ return variables [index];
+ }
+
+ void ReadCilBody (MethodBody body, BinaryReader br)
+ {
+ long start = br.BaseStream.Position;
+ Instruction last = null;
+ m_instructions.Clear();
+ InstructionCollection code = body.Instructions;
+ GenericContext context = new GenericContext (body.Method);
+
+ while (br.BaseStream.Position < start + body.CodeSize) {
+ OpCode op;
+ long offset = br.BaseStream.Position - start;
+ int cursor = br.ReadByte ();
+ if (cursor == 0xfe)
+ op = OpCodes.TwoBytesOpCode [br.ReadByte ()];
+ else
+ op = OpCodes.OneByteOpCode [cursor];
+
+ Instruction instr = new Instruction ((int) offset, op);
+ switch (op.OperandType) {
+ case OperandType.InlineNone :
+ break;
+ case OperandType.InlineSwitch :
+ uint length = br.ReadUInt32 ();
+ int [] branches = new int [length];
+ int [] buf = new int [length];
+ for (int i = 0; i < length; i++)
+ buf [i] = br.ReadInt32 ();
+ for (int i = 0; i < length; i++)
+ branches [i] = Convert.ToInt32 (br.BaseStream.Position - start + buf [i]);
+ instr.Operand = branches;
+ break;
+ case OperandType.ShortInlineBrTarget :
+ sbyte sbrtgt = br.ReadSByte ();
+ instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + sbrtgt);
+ break;
+ case OperandType.InlineBrTarget :
+ int brtgt = br.ReadInt32 ();
+ instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + brtgt);
+ break;
+ case OperandType.ShortInlineI :
+ if (op == OpCodes.Ldc_I4_S)
+ instr.Operand = br.ReadSByte ();
+ else
+ instr.Operand = br.ReadByte ();
+ break;
+ case OperandType.ShortInlineVar :
+ instr.Operand = GetVariable (body, br.ReadByte ());
+ break;
+ case OperandType.ShortInlineParam :
+ instr.Operand = GetParameter (body, br.ReadByte ());
+ break;
+ case OperandType.InlineSig :
+ instr.Operand = GetCallSiteAt (br.ReadInt32 (), context);
+ break;
+ case OperandType.InlineI :
+ instr.Operand = br.ReadInt32 ();
+ break;
+ case OperandType.InlineVar :
+ instr.Operand = GetVariable (body, br.ReadInt16 ());
+ break;
+ case OperandType.InlineParam :
+ instr.Operand = GetParameter (body, br.ReadInt16 ());
+ break;
+ case OperandType.InlineI8 :
+ instr.Operand = br.ReadInt64 ();
+ break;
+ case OperandType.ShortInlineR :
+ instr.Operand = br.ReadSingle ();
+ break;
+ case OperandType.InlineR :
+ instr.Operand = br.ReadDouble ();
+ break;
+ case OperandType.InlineString :
+ instr.Operand = m_root.Streams.UserStringsHeap [GetRid (br.ReadInt32 ())];
+ break;
+ case OperandType.InlineField :
+ case OperandType.InlineMethod :
+ case OperandType.InlineType :
+ case OperandType.InlineTok :
+ MetadataToken token = new MetadataToken (br.ReadInt32 ());
+ switch (token.TokenType) {
+ case TokenType.TypeDef:
+ instr.Operand = m_reflectReader.GetTypeDefAt (token.RID);
+ break;
+ case TokenType.TypeRef:
+ instr.Operand = m_reflectReader.GetTypeRefAt (token.RID);
+ break;
+ case TokenType.TypeSpec:
+ instr.Operand = m_reflectReader.GetTypeSpecAt (token.RID, context);
+ break;
+ case TokenType.Field:
+ instr.Operand = m_reflectReader.GetFieldDefAt (token.RID);
+ break;
+ case TokenType.Method:
+ instr.Operand = m_reflectReader.GetMethodDefAt (token.RID);
+ break;
+ case TokenType.MethodSpec:
+ instr.Operand = m_reflectReader.GetMethodSpecAt (token.RID, context);
+ break;
+ case TokenType.MemberRef:
+ instr.Operand = m_reflectReader.GetMemberRefAt (token.RID, context);
+ break;
+ default:
+ throw new ReflectionException ("Wrong token: " + token);
+ }
+ break;
+ }
+
+ m_instructions.Add (instr.Offset, instr);
+
+ if (last != null) {
+ last.Next = instr;
+ instr.Previous = last;
+ }
+
+ last = instr;
+
+ code.Add (instr);
+ }
+
+ // resolve branches
+ foreach (Instruction i in code) {
+ switch (i.OpCode.OperandType) {
+ case OperandType.ShortInlineBrTarget:
+ case OperandType.InlineBrTarget:
+ i.Operand = GetInstruction (body, (int) i.Operand);
+ break;
+ case OperandType.InlineSwitch:
+ int [] lbls = (int []) i.Operand;
+ Instruction [] instrs = new Instruction [lbls.Length];
+ for (int j = 0; j < lbls.Length; j++)
+ instrs [j] = GetInstruction (body, lbls [j]);
+ i.Operand = instrs;
+ break;
+ }
+ }
+
+ if (m_reflectReader.SymbolReader != null)
+ m_reflectReader.SymbolReader.Read (body, m_instructions);
+ }
+
+ Instruction GetInstruction (MethodBody body, int offset)
+ {
+ Instruction instruction = m_instructions [offset] as Instruction;
+ if (instruction != null)
+ return instruction;
+
+ return body.Instructions.Outside;
+ }
+
+ void ReadSection (MethodBody body, BinaryReader br)
+ {
+ br.BaseStream.Position += 3;
+ br.BaseStream.Position &= ~3;
+
+ byte flags = br.ReadByte ();
+ if ((flags & (byte) MethodDataSection.FatFormat) == 0) {
+ int length = br.ReadByte () / 12;
+ br.ReadBytes (2);
+
+ for (int i = 0; i < length; i++) {
+ ExceptionHandler eh = new ExceptionHandler (
+ (ExceptionHandlerType) (br.ReadInt16 () & 0x7));
+ eh.TryStart = GetInstruction (body, Convert.ToInt32 (br.ReadInt16 ()));
+ eh.TryEnd = GetInstruction (body, eh.TryStart.Offset + Convert.ToInt32 (br.ReadByte ()));
+ eh.HandlerStart = GetInstruction (body, Convert.ToInt32 (br.ReadInt16 ()));
+ eh.HandlerEnd = GetInstruction (body, eh.HandlerStart.Offset + Convert.ToInt32 (br.ReadByte ()));
+ ReadExceptionHandlerEnd (eh, br, body);
+ body.ExceptionHandlers.Add (eh);
+ }
+ } else {
+ br.BaseStream.Position--;
+ int length = (br.ReadInt32 () >> 8) / 24;
+ if ((flags & (int) MethodDataSection.EHTable) == 0)
+ br.ReadBytes (length * 24);
+ for (int i = 0; i < length; i++) {
+ ExceptionHandler eh = new ExceptionHandler (
+ (ExceptionHandlerType) (br.ReadInt32 () & 0x7));
+ eh.TryStart = GetInstruction (body, br.ReadInt32 ());
+ eh.TryEnd = GetInstruction (body, eh.TryStart.Offset + br.ReadInt32 ());
+ eh.HandlerStart = GetInstruction (body, br.ReadInt32 ());
+ eh.HandlerEnd = GetInstruction (body, eh.HandlerStart.Offset + br.ReadInt32 ());
+ ReadExceptionHandlerEnd (eh, br, body);
+ body.ExceptionHandlers.Add (eh);
+ }
+ }
+
+ if ((flags & (byte) MethodDataSection.MoreSects) != 0)
+ ReadSection (body, br);
+ }
+
+ void ReadExceptionHandlerEnd (ExceptionHandler eh, BinaryReader br, MethodBody body)
+ {
+ switch (eh.Type) {
+ case ExceptionHandlerType.Catch :
+ MetadataToken token = new MetadataToken (br.ReadInt32 ());
+ eh.CatchType = m_reflectReader.GetTypeDefOrRef (token, new GenericContext (body.Method));
+ break;
+ case ExceptionHandlerType.Filter :
+ eh.FilterStart = GetInstruction (body, br.ReadInt32 ());
+ eh.FilterEnd = GetInstruction (body, eh.HandlerStart.Previous.Offset);
+ break;
+ default :
+ br.ReadInt32 ();
+ break;
+ }
+ }
+
+ CallSite GetCallSiteAt (int token, GenericContext context)
+ {
+ StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable ();
+ MethodSig ms = m_reflectReader.SigReader.GetStandAloneMethodSig (
+ sasTable [(int) GetRid (token) - 1].Signature);
+ CallSite cs = new CallSite (ms.HasThis, ms.ExplicitThis,
+ ms.MethCallConv, m_reflectReader.GetMethodReturnType (ms, context));
+ cs.MetadataToken = new MetadataToken (token);
+
+ for (int i = 0; i < ms.ParamCount; i++) {
+ Param p = ms.Parameters [i];
+ cs.Parameters.Add (m_reflectReader.BuildParameterDefinition (i, p, context));
+ }
+
+ ReflectionReader.CreateSentinelIfNeeded (cs, ms);
+
+ return cs;
+ }
+
+ public override void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
+ {
+ MethodBody body = variables.Container as MethodBody;
+ if (body == null || body.LocalVarToken == 0)
+ return;
+
+ StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable ();
+ StandAloneSigRow sasRow = sasTable [(int) GetRid (body.LocalVarToken) - 1];
+ LocalVarSig sig = m_reflectReader.SigReader.GetLocalVarSig (sasRow.Signature);
+ for (int i = 0; i < sig.Count; i++) {
+ LocalVarSig.LocalVariable lv = sig.LocalVariables [i];
+ TypeReference varType = m_reflectReader.GetTypeRefFromSig (
+ lv.Type, new GenericContext (body.Method));
+
+ if (lv.ByRef)
+ varType = new ReferenceType (varType);
+ if ((lv.Constraint & Constraint.Pinned) != 0)
+ varType = new PinnedType (varType);
+
+ varType = m_reflectReader.GetModifierType (lv.CustomMods, varType);
+
+ body.Variables.Add (new VariableDefinition (
+ string.Concat ("V_", i), i, body.Method, varType));
+ }
+ }
+ }
+}
--- /dev/null
+//
+// CodeWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Binary;
+ using Mono.Cecil.Metadata;
+ using Mono.Cecil.Signatures;
+
+ sealed class CodeWriter : BaseCodeVisitor {
+
+ ReflectionWriter m_reflectWriter;
+ MemoryBinaryWriter m_binaryWriter;
+ MemoryBinaryWriter m_codeWriter;
+
+ IDictionary m_localSigCache;
+ IDictionary m_standaloneSigCache;
+
+ IDictionary m_stackSizes;
+
+ bool stripped;
+
+ public bool Stripped {
+ get { return stripped; }
+ set { stripped = value; }
+ }
+
+ public CodeWriter (ReflectionWriter reflectWriter, MemoryBinaryWriter writer)
+ {
+ m_reflectWriter = reflectWriter;
+ m_binaryWriter = writer;
+ m_codeWriter = new MemoryBinaryWriter ();
+
+ m_localSigCache = new Hashtable ();
+ m_standaloneSigCache = new Hashtable ();
+
+ m_stackSizes = new Hashtable ();
+ }
+
+ public RVA WriteMethodBody (MethodDefinition meth)
+ {
+ if (meth.Body == null)
+ return RVA.Zero;
+
+ RVA ret = m_reflectWriter.MetadataWriter.GetDataCursor ();
+ meth.Body.Accept (this);
+ return ret;
+ }
+
+ public override void VisitMethodBody (MethodBody body)
+ {
+ m_codeWriter.Empty ();
+ }
+
+ void WriteToken (MetadataToken token)
+ {
+ if (token.RID == 0)
+ m_codeWriter.Write (0);
+ else
+ m_codeWriter.Write (token.ToUInt ());
+ }
+
+ static int GetParameterIndex (MethodBody body, ParameterDefinition p)
+ {
+ int idx = body.Method.Parameters.IndexOf (p);
+ if (idx == -1 && p == body.Method.This)
+ return 0;
+ if (body.Method.HasThis)
+ idx++;
+
+ return idx;
+ }
+
+ public override void VisitInstructionCollection (InstructionCollection instructions)
+ {
+ MethodBody body = instructions.Container;
+ long start = m_codeWriter.BaseStream.Position;
+
+ ComputeMaxStack (instructions);
+
+ foreach (Instruction instr in instructions) {
+
+ instr.Offset = (int) (m_codeWriter.BaseStream.Position - start);
+
+ if (instr.OpCode.Size == 1)
+ m_codeWriter.Write (instr.OpCode.Op2);
+ else {
+ m_codeWriter.Write (instr.OpCode.Op1);
+ m_codeWriter.Write (instr.OpCode.Op2);
+ }
+
+ if (instr.OpCode.OperandType != OperandType.InlineNone &&
+ instr.Operand == null)
+ throw new ReflectionException ("OpCode {0} have null operand", instr.OpCode.Name);
+
+ switch (instr.OpCode.OperandType) {
+ case OperandType.InlineNone :
+ break;
+ case OperandType.InlineSwitch :
+ Instruction [] targets = (Instruction []) instr.Operand;
+ for (int i = 0; i < targets.Length + 1; i++)
+ m_codeWriter.Write ((uint) 0);
+ break;
+ case OperandType.ShortInlineBrTarget :
+ m_codeWriter.Write ((byte) 0);
+ break;
+ case OperandType.InlineBrTarget :
+ m_codeWriter.Write (0);
+ break;
+ case OperandType.ShortInlineI :
+ if (instr.OpCode == OpCodes.Ldc_I4_S)
+ m_codeWriter.Write ((sbyte) instr.Operand);
+ else
+ m_codeWriter.Write ((byte) instr.Operand);
+ break;
+ case OperandType.ShortInlineVar :
+ m_codeWriter.Write ((byte) body.Variables.IndexOf (
+ (VariableDefinition) instr.Operand));
+ break;
+ case OperandType.ShortInlineParam :
+ m_codeWriter.Write ((byte) GetParameterIndex (body, (ParameterDefinition) instr.Operand));
+ break;
+ case OperandType.InlineSig :
+ WriteToken (GetCallSiteToken ((CallSite) instr.Operand));
+ break;
+ case OperandType.InlineI :
+ m_codeWriter.Write ((int) instr.Operand);
+ break;
+ case OperandType.InlineVar :
+ m_codeWriter.Write ((short) body.Variables.IndexOf (
+ (VariableDefinition) instr.Operand));
+ break;
+ case OperandType.InlineParam :
+ m_codeWriter.Write ((short) GetParameterIndex (
+ body, (ParameterDefinition) instr.Operand));
+ break;
+ case OperandType.InlineI8 :
+ m_codeWriter.Write ((long) instr.Operand);
+ break;
+ case OperandType.ShortInlineR :
+ m_codeWriter.Write ((float) instr.Operand);
+ break;
+ case OperandType.InlineR :
+ m_codeWriter.Write ((double) instr.Operand);
+ break;
+ case OperandType.InlineString :
+ WriteToken (new MetadataToken (TokenType.String,
+ m_reflectWriter.MetadataWriter.AddUserString (instr.Operand as string)));
+ break;
+ case OperandType.InlineField :
+ case OperandType.InlineMethod :
+ case OperandType.InlineType :
+ case OperandType.InlineTok :
+ if (instr.Operand is TypeReference)
+ WriteToken (GetTypeToken ((TypeReference) instr.Operand));
+ else if (instr.Operand is GenericInstanceMethod)
+ WriteToken (m_reflectWriter.GetMethodSpecToken (instr.Operand as GenericInstanceMethod));
+ else if (instr.Operand is MemberReference)
+ WriteToken (m_reflectWriter.GetMemberRefToken ((MemberReference) instr.Operand));
+ else if (instr.Operand is IMetadataTokenProvider)
+ WriteToken (((IMetadataTokenProvider) instr.Operand).MetadataToken);
+ else
+ throw new ReflectionException (
+ string.Format ("Wrong operand for {0} OpCode: {1}",
+ instr.OpCode.OperandType,
+ instr.Operand.GetType ().FullName));
+ break;
+ }
+ }
+
+ // patch branches
+ long pos = m_codeWriter.BaseStream.Position;
+
+ foreach (Instruction instr in instructions) {
+ switch (instr.OpCode.OperandType) {
+ case OperandType.InlineSwitch :
+ m_codeWriter.BaseStream.Position = instr.Offset + instr.OpCode.Size;
+ Instruction [] targets = (Instruction []) instr.Operand;
+ m_codeWriter.Write ((uint) targets.Length);
+ foreach (Instruction tgt in targets)
+ m_codeWriter.Write ((tgt.Offset - (instr.Offset +
+ instr.OpCode.Size + (4 * (targets.Length + 1)))));
+ break;
+ case OperandType.ShortInlineBrTarget :
+ m_codeWriter.BaseStream.Position = instr.Offset + instr.OpCode.Size;
+ m_codeWriter.Write ((byte) (((Instruction) instr.Operand).Offset -
+ (instr.Offset + instr.OpCode.Size + 1)));
+ break;
+ case OperandType.InlineBrTarget :
+ m_codeWriter.BaseStream.Position = instr.Offset + instr.OpCode.Size;
+ m_codeWriter.Write(((Instruction) instr.Operand).Offset -
+ (instr.Offset + instr.OpCode.Size + 4));
+ break;
+ }
+ }
+
+ m_codeWriter.BaseStream.Position = pos;
+ }
+
+ MetadataToken GetTypeToken (TypeReference type)
+ {
+ return m_reflectWriter.GetTypeDefOrRefToken (type);
+ }
+
+ MetadataToken GetCallSiteToken (CallSite cs)
+ {
+ uint sig;
+ int sentinel = cs.GetSentinel ();
+ if (sentinel > 0)
+ sig = m_reflectWriter.SignatureWriter.AddMethodDefSig (
+ m_reflectWriter.GetMethodDefSig (cs));
+ else
+ sig = m_reflectWriter.SignatureWriter.AddMethodRefSig (
+ m_reflectWriter.GetMethodRefSig (cs));
+
+ if (m_standaloneSigCache.Contains (sig))
+ return (MetadataToken) m_standaloneSigCache [sig];
+
+ StandAloneSigTable sasTable = m_reflectWriter.MetadataTableWriter.GetStandAloneSigTable ();
+ StandAloneSigRow sasRow = m_reflectWriter.MetadataRowWriter.CreateStandAloneSigRow (sig);
+
+ sasTable.Rows.Add(sasRow);
+
+ MetadataToken token = new MetadataToken (TokenType.Signature, (uint) sasTable.Rows.Count);
+ m_standaloneSigCache [sig] = token;
+ return token;
+ }
+
+ static int GetLength (Instruction start, Instruction end, InstructionCollection instructions)
+ {
+ Instruction last = instructions [instructions.Count - 1];
+ return (end == instructions.Outside ? last.Offset + last.GetSize () : end.Offset) - start.Offset;
+ }
+
+ static bool IsRangeFat (Instruction start, Instruction end, InstructionCollection instructions)
+ {
+ return GetLength (start, end, instructions) >= 256 ||
+ start.Offset >= 65536;
+ }
+
+ static bool IsFat (ExceptionHandlerCollection seh)
+ {
+ for (int i = 0; i < seh.Count; i++) {
+ ExceptionHandler eh = seh [i];
+ if (IsRangeFat (eh.TryStart, eh.TryEnd, seh.Container.Instructions))
+ return true;
+
+ if (IsRangeFat (eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions))
+ return true;
+
+ switch (eh.Type) {
+ case ExceptionHandlerType.Filter :
+ if (IsRangeFat (eh.FilterStart, eh.FilterEnd, seh.Container.Instructions))
+ return true;
+ break;
+ }
+ }
+
+ return false;
+ }
+
+ void WriteExceptionHandlerCollection (ExceptionHandlerCollection seh)
+ {
+ m_codeWriter.QuadAlign ();
+
+ if (seh.Count < 0x15 && !IsFat (seh)) {
+ m_codeWriter.Write ((byte) MethodDataSection.EHTable);
+ m_codeWriter.Write ((byte) (seh.Count * 12 + 4));
+ m_codeWriter.Write (new byte [2]);
+ foreach (ExceptionHandler eh in seh) {
+ m_codeWriter.Write ((ushort) eh.Type);
+ m_codeWriter.Write ((ushort) eh.TryStart.Offset);
+ m_codeWriter.Write ((byte) (eh.TryEnd.Offset - eh.TryStart.Offset));
+ m_codeWriter.Write ((ushort) eh.HandlerStart.Offset);
+ m_codeWriter.Write ((byte) GetLength (eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions));
+ WriteHandlerSpecific (eh);
+ }
+ } else {
+ m_codeWriter.Write ((byte) (MethodDataSection.FatFormat | MethodDataSection.EHTable));
+ WriteFatBlockSize (seh);
+ foreach (ExceptionHandler eh in seh) {
+ m_codeWriter.Write ((uint) eh.Type);
+ m_codeWriter.Write ((uint) eh.TryStart.Offset);
+ m_codeWriter.Write ((uint) (eh.TryEnd.Offset - eh.TryStart.Offset));
+ m_codeWriter.Write ((uint) eh.HandlerStart.Offset);
+ m_codeWriter.Write ((uint) GetLength (eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions));
+ WriteHandlerSpecific (eh);
+ }
+ }
+ }
+
+ void WriteFatBlockSize (ExceptionHandlerCollection seh)
+ {
+ int size = seh.Count * 24 + 4;
+ m_codeWriter.Write ((byte) (size & 0xff));
+ m_codeWriter.Write ((byte) ((size >> 8) & 0xff));
+ m_codeWriter.Write ((byte) ((size >> 16) & 0xff));
+ }
+
+ void WriteHandlerSpecific (ExceptionHandler eh)
+ {
+ switch (eh.Type) {
+ case ExceptionHandlerType.Catch :
+ WriteToken (GetTypeToken (eh.CatchType));
+ break;
+ case ExceptionHandlerType.Filter :
+ m_codeWriter.Write ((uint) eh.FilterStart.Offset);
+ break;
+ default :
+ m_codeWriter.Write (0);
+ break;
+ }
+ }
+
+ public override void VisitVariableDefinitionCollection (VariableDefinitionCollection variables)
+ {
+ MethodBody body = variables.Container as MethodBody;
+ if (body == null || stripped)
+ return;
+
+ uint sig = m_reflectWriter.SignatureWriter.AddLocalVarSig (
+ GetLocalVarSig (variables));
+
+ if (m_localSigCache.Contains (sig)) {
+ body.LocalVarToken = (int) m_localSigCache [sig];
+ return;
+ }
+
+ StandAloneSigTable sasTable = m_reflectWriter.MetadataTableWriter.GetStandAloneSigTable ();
+ StandAloneSigRow sasRow = m_reflectWriter.MetadataRowWriter.CreateStandAloneSigRow (
+ sig);
+
+ sasTable.Rows.Add (sasRow);
+ body.LocalVarToken = sasTable.Rows.Count;
+ m_localSigCache [sig] = body.LocalVarToken;
+ }
+
+ public override void TerminateMethodBody (MethodBody body)
+ {
+ long pos = m_binaryWriter.BaseStream.Position;
+
+ if (body.HasVariables || body.HasExceptionHandlers
+ || m_codeWriter.BaseStream.Length >= 64 || body.MaxStack > 8) {
+
+ MethodHeader header = MethodHeader.FatFormat;
+ if (body.InitLocals)
+ header |= MethodHeader.InitLocals;
+ if (body.HasExceptionHandlers)
+ header |= MethodHeader.MoreSects;
+
+ m_binaryWriter.Write ((byte) header);
+ m_binaryWriter.Write ((byte) 0x30); // (header size / 4) << 4
+ m_binaryWriter.Write ((short) body.MaxStack);
+ m_binaryWriter.Write ((int) m_codeWriter.BaseStream.Length);
+ // the token should be zero if there are no variables
+ int token = body.HasVariables ? ((int) TokenType.Signature | body.LocalVarToken) : 0;
+ m_binaryWriter.Write (token);
+
+ if (body.HasExceptionHandlers)
+ WriteExceptionHandlerCollection (body.ExceptionHandlers);
+ } else
+ m_binaryWriter.Write ((byte) ((byte) MethodHeader.TinyFormat |
+ m_codeWriter.BaseStream.Length << 2));
+
+ m_binaryWriter.Write (m_codeWriter);
+ m_binaryWriter.QuadAlign ();
+
+ m_reflectWriter.MetadataWriter.AddData (
+ (int) (m_binaryWriter.BaseStream.Position - pos));
+ }
+
+ public LocalVarSig.LocalVariable GetLocalVariableSig (VariableDefinition var)
+ {
+ LocalVarSig.LocalVariable lv = new LocalVarSig.LocalVariable ();
+ TypeReference type = var.VariableType;
+
+ lv.CustomMods = m_reflectWriter.GetCustomMods (type);
+
+ if (type is PinnedType) {
+ lv.Constraint |= Constraint.Pinned;
+ type = (type as PinnedType).ElementType;
+ }
+
+ if (type is ReferenceType) {
+ lv.ByRef = true;
+ type = (type as ReferenceType).ElementType;
+ }
+
+ lv.Type = m_reflectWriter.GetSigType (type);
+
+ return lv;
+ }
+
+ public LocalVarSig GetLocalVarSig (VariableDefinitionCollection vars)
+ {
+ LocalVarSig lvs = new LocalVarSig ();
+ lvs.CallingConvention |= 0x7;
+ lvs.Count = vars.Count;
+ lvs.LocalVariables = new LocalVarSig.LocalVariable [lvs.Count];
+ for (int i = 0; i < lvs.Count; i++) {
+ lvs.LocalVariables [i] = GetLocalVariableSig (vars [i]);
+ }
+
+ return lvs;
+ }
+
+ void ComputeMaxStack (InstructionCollection instructions)
+ {
+ int current = 0;
+ int max = 0;
+ m_stackSizes.Clear ();
+
+ foreach (ExceptionHandler eh in instructions.Container.ExceptionHandlers) {
+ switch (eh.Type) {
+ case ExceptionHandlerType.Catch :
+ case ExceptionHandlerType.Filter :
+ m_stackSizes [eh.HandlerStart] = 1;
+ max = 1;
+ break;
+ }
+ }
+
+ foreach (Instruction instr in instructions) {
+
+ object savedSize = m_stackSizes [instr];
+ if (savedSize != null)
+ current = (int) savedSize;
+
+ current -= GetPopDelta (instructions.Container.Method, instr, current);
+
+ if (current < 0)
+ current = 0;
+
+ current += GetPushDelta (instr);
+
+ if (current > max)
+ max = current;
+
+ // for forward branches, copy the stack size for the instruction that is being branched to
+ switch (instr.OpCode.OperandType) {
+ case OperandType.InlineBrTarget:
+ case OperandType.ShortInlineBrTarget:
+ m_stackSizes [instr.Operand] = current;
+ break;
+ case OperandType.InlineSwitch:
+ foreach (Instruction target in (Instruction []) instr.Operand)
+ m_stackSizes [target] = current;
+ break;
+ }
+
+ switch (instr.OpCode.FlowControl) {
+ case FlowControl.Branch:
+ case FlowControl.Throw:
+ case FlowControl.Return:
+ // next statement is not reachable from this statement, so reset the stack depth to 0
+ current = 0;
+ break;
+ }
+ }
+
+ instructions.Container.MaxStack = max + 1; // you never know
+ }
+
+ static int GetPushDelta (Instruction instruction)
+ {
+ OpCode code = instruction.OpCode;
+ switch (code.StackBehaviourPush) {
+ case StackBehaviour.Push0:
+ return 0;
+
+ case StackBehaviour.Push1:
+ case StackBehaviour.Pushi:
+ case StackBehaviour.Pushi8:
+ case StackBehaviour.Pushr4:
+ case StackBehaviour.Pushr8:
+ case StackBehaviour.Pushref:
+ return 1;
+
+ case StackBehaviour.Push1_push1:
+ return 2;
+
+ case StackBehaviour.Varpush:
+ if (code.FlowControl != FlowControl.Call)
+ break;
+
+ IMethodSignature method = (IMethodSignature) instruction.Operand;
+ return IsVoid (method.ReturnType.ReturnType) ? 0 : 1;
+ }
+
+ throw new NotSupportedException ();
+ }
+
+ static int GetPopDelta (MethodDefinition current, Instruction instruction, int height)
+ {
+ OpCode code = instruction.OpCode;
+ switch (code.StackBehaviourPop) {
+ case StackBehaviour.Pop0:
+ return 0;
+ case StackBehaviour.Popi:
+ case StackBehaviour.Popref:
+ case StackBehaviour.Pop1:
+ return 1;
+
+ case StackBehaviour.Pop1_pop1:
+ case StackBehaviour.Popi_pop1:
+ case StackBehaviour.Popi_popi:
+ case StackBehaviour.Popi_popi8:
+ case StackBehaviour.Popi_popr4:
+ case StackBehaviour.Popi_popr8:
+ case StackBehaviour.Popref_pop1:
+ case StackBehaviour.Popref_popi:
+ return 2;
+
+ case StackBehaviour.Popi_popi_popi:
+ case StackBehaviour.Popref_popi_popi:
+ case StackBehaviour.Popref_popi_popi8:
+ case StackBehaviour.Popref_popi_popr4:
+ case StackBehaviour.Popref_popi_popr8:
+ case StackBehaviour.Popref_popi_popref:
+ return 3;
+
+ case StackBehaviour.PopAll:
+ return height;
+
+ case StackBehaviour.Varpop:
+ if (code == OpCodes.Ret)
+ return IsVoid (current.ReturnType.ReturnType) ? 0 : 1;
+
+ if (code.FlowControl != FlowControl.Call)
+ break;
+
+ IMethodSignature method = (IMethodSignature) instruction.Operand;
+ int count = method.HasParameters ? method.Parameters.Count : 0;
+ if (method.HasThis && code != OpCodes.Newobj)
+ ++count;
+
+ return count;
+ }
+
+ throw new NotSupportedException ();
+ }
+
+ static bool IsVoid (TypeReference type)
+ {
+ return type.FullName == Constants.Void;
+ }
+ }
+}
--- /dev/null
+//
+// Document.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+
+ internal class Document {
+
+ string m_url;
+
+ Guid m_type;
+ DocumentHashAlgorithm m_hashAlgorithm;
+ Guid m_language;
+ Guid m_languageVendor;
+
+ byte [] m_hash;
+
+ public string Url {
+ get { return m_url; }
+ set { m_url = value; }
+ }
+
+ public Guid Type {
+ get { return m_type; }
+ set { m_type = value; }
+ }
+
+ public DocumentHashAlgorithm HashAlgorithm {
+ get { return m_hashAlgorithm; }
+ set { m_hashAlgorithm = value; }
+ }
+
+ public Guid Language {
+ get { return m_language; }
+ set { m_language = value; }
+ }
+
+ public Guid LanguageVendor {
+ get { return m_languageVendor; }
+ set { m_languageVendor = value; }
+ }
+
+ public byte [] Hash {
+ get { return m_hash; }
+ set { m_hash = value; }
+ }
+
+ public Document (string url)
+ {
+ m_url = url;
+ m_hash = new byte [0];
+ }
+ }
+}
--- /dev/null
+//
+// DocumentHashAlgorithm.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal enum DocumentHashAlgorithm {
+ [Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)] None,
+ [Guid (0x406ea660, 0x64cf, 0x4c82, 0xb6, 0xf0, 0x42, 0xd4, 0x81, 0x72, 0xa7, 0x99)] MD5,
+ [Guid (0xff1816ec, 0xaa5e, 0x4d10, 0x87, 0xf7, 0x6f, 0x49, 0x63, 0x83, 0x34, 0x60)] SHA1
+ }
+}
--- /dev/null
+//
+// DocumentLanguage.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+
+ internal abstract class DocumentLanguage {
+#if CF_2_0
+ public static readonly Guid None = new Guid ("00000000-0000-0000-0000-000000000000");
+ public static readonly Guid C = new Guid ("63a08714-fc37-11d2-904c-00c04fa302a1");
+ public static readonly Guid Cpp = new Guid ("3a12d0b7-c26c-11d0-b442-00a0244a1dd2");
+ public static readonly Guid CSharp = new Guid ("3f5162f8-07c6-11d3-9053-00c04fa302a1");
+ public static readonly Guid Basic = new Guid ("3a12d0b8-c26c-11d0-b442-00a0244a1dd2");
+ public static readonly Guid Java = new Guid ("3a12d0b4-c26c-11d0-b442-00a0244a1dd2");
+ public static readonly Guid Cobol = new Guid ("af046cd1-d0e1-11d2-977c-00a0c9b4d50c");
+ public static readonly Guid Pascal = new Guid ("af046cd2-d0e1-11d2-977c-00a0c9b4d50c");
+ public static readonly Guid CIL = new Guid ("af046cd3-d0e1-11d2-977c-00a0c9b4d50c");
+ public static readonly Guid JScript = new Guid ("3a12d0b6-c26c-11d0-b442-00a0244a1dd2");
+ public static readonly Guid SMC = new Guid ("0d9b9f7b-6611-11d3-bd2a-0000f80849bd");
+ public static readonly Guid MCpp = new Guid ("4b35fde8-07c6-11d3-9053-00c04fa302a1");
+#else
+ public static readonly Guid None = new Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00);
+ public static readonly Guid C = new Guid (0x63a08714, 0xfc37, 0x11d2, 0x90, 0x4c, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1);
+ public static readonly Guid Cpp = new Guid (0x3a12d0b7, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2);
+ public static readonly Guid CSharp = new Guid (0x3f5162f8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1);
+ public static readonly Guid Basic = new Guid (0x3a12d0b8, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2);
+ public static readonly Guid Java = new Guid (0x3a12d0b4, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2);
+ public static readonly Guid Cobol = new Guid (0xaf046cd1, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc);
+ public static readonly Guid Pascal = new Guid (0xaf046cd2, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc);
+ public static readonly Guid CIL = new Guid (0xaf046cd3, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc);
+ public static readonly Guid JScript = new Guid (0x3a12d0b6, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2);
+ public static readonly Guid SMC = new Guid (0xd9b9f7b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x0, 0x0, 0xf8, 0x8, 0x49, 0xbd);
+ public static readonly Guid MCpp = new Guid (0x4b35fde8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1);
+#endif
+ }
+}
--- /dev/null
+//
+// DocumentLanguageVendor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+
+ internal abstract class DocumentLanguageVendor {
+#if CF_2_0
+ public static readonly Guid Other = new Guid ("00000000-0000-0000-0000-000000000000");
+ public static readonly Guid Microsoft = new Guid ("994b45c4-e6e9-11d2-903f-00c04fa302a1");
+#else
+ public static readonly Guid Other = new Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+ public static readonly Guid Microsoft = new Guid (0x994b45c4, 0xe6e9, 0x11d2, 0x90, 0x3f, 0x00, 0xc0, 0x4f, 0xa3, 0x02, 0xa1);
+#endif
+ }
+}
--- /dev/null
+//
+// DocumentType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+
+ internal abstract class DocumentType {
+
+ public static readonly Guid Other = new Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+ public static readonly Guid Text = new Guid (0x5a869d0b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x00, 0x00, 0xf8, 0x08, 0x49, 0xbd);
+ }
+}
--- /dev/null
+//
+// ExceptionHandler.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using Mono.Cecil;
+
+ internal sealed class ExceptionHandler : ICodeVisitable {
+
+ Instruction m_tryStart;
+ Instruction m_tryEnd;
+ Instruction m_filterStart;
+ Instruction m_filterEnd;
+ Instruction m_handlerStart;
+ Instruction m_handlerEnd;
+
+ TypeReference m_catchType;
+ ExceptionHandlerType m_type;
+
+ public Instruction TryStart {
+ get { return m_tryStart; }
+ set { m_tryStart = value; }
+ }
+
+ public Instruction TryEnd {
+ get { return m_tryEnd; }
+ set { m_tryEnd = value; }
+ }
+
+ public Instruction FilterStart {
+ get { return m_filterStart; }
+ set { m_filterStart = value; }
+ }
+
+ public Instruction FilterEnd {
+ get { return m_filterEnd; }
+ set { m_filterEnd = value; }
+ }
+
+ public Instruction HandlerStart {
+ get { return m_handlerStart; }
+ set { m_handlerStart = value; }
+ }
+
+ public Instruction HandlerEnd {
+ get { return m_handlerEnd; }
+ set { m_handlerEnd = value; }
+ }
+
+ public TypeReference CatchType {
+ get { return m_catchType; }
+ set { m_catchType = value; }
+ }
+
+ public ExceptionHandlerType Type {
+ get { return m_type; }
+ set { m_type = value; }
+ }
+
+ public ExceptionHandler (ExceptionHandlerType type)
+ {
+ m_type = type;
+ }
+
+ public void Accept (ICodeVisitor visitor)
+ {
+ visitor.VisitExceptionHandler (this);
+ }
+ }
+}
--- /dev/null
+//
+// ExceptionHandlerCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:53 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class ExceptionHandlerCollection : CollectionBase, ICodeVisitable {
+
+ MethodBody m_container;
+
+ public ExceptionHandler this [int index] {
+ get { return List [index] as ExceptionHandler; }
+ set { List [index] = value; }
+ }
+
+ public MethodBody Container {
+ get { return m_container; }
+ }
+
+ public ExceptionHandlerCollection (MethodBody container)
+ {
+ m_container = container;
+ }
+
+ public void Add (ExceptionHandler value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (ExceptionHandler value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (ExceptionHandler value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, ExceptionHandler value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (ExceptionHandler value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is ExceptionHandler))
+ throw new ArgumentException ("Must be of type " + typeof (ExceptionHandler).FullName);
+ }
+
+ public void Accept (ICodeVisitor visitor)
+ {
+ visitor.VisitExceptionHandlerCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// ExceptionHandlerType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal enum ExceptionHandlerType {
+ Catch = 0x0000,
+ Filter = 0x0001,
+ Finally = 0x0002,
+ Fault = 0x0004
+ }
+}
--- /dev/null
+//
+// FlowControl.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal enum FlowControl {
+ Branch,
+ Break,
+ Call,
+ Cond_Branch,
+ Meta,
+ Next,
+ Phi,
+ Return,
+ Throw
+ }
+}
--- /dev/null
+//
+// GuidAttribute.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+ using System.Reflection;
+
+ [AttributeUsage (AttributeTargets.Field)]
+ internal sealed class GuidAttribute : Attribute {
+
+ private Guid m_guid;
+
+ public Guid Guid {
+ get { return m_guid; }
+ }
+
+ GuidAttribute ()
+ {
+ m_guid = new Guid ();
+ }
+
+ public GuidAttribute (
+ uint a,
+ ushort b,
+ ushort c,
+ byte d,
+ byte e,
+ byte f,
+ byte g,
+ byte h,
+ byte i,
+ byte j,
+ byte k)
+ {
+ m_guid = new Guid ((int) a, (short) b, (short) c, d, e, f, g, h, i, j, k);
+ }
+
+ public static int GetValueFromGuid (Guid id, Type enumeration)
+ {
+ foreach (FieldInfo fi in enumeration.GetFields (BindingFlags.Static | BindingFlags.Public))
+ if (id == GetGuidAttribute (fi).Guid)
+ return (int) fi.GetValue (null);
+
+ return -1;
+ }
+
+ public static Guid GetGuidFromValue (int value, Type enumeration)
+ {
+ foreach (FieldInfo fi in enumeration.GetFields (BindingFlags.Static | BindingFlags.Public))
+ if (value == (int) fi.GetValue (null))
+ return GetGuidAttribute (fi).Guid;
+
+ return new Guid ();
+ }
+
+ static GuidAttribute GetGuidAttribute (FieldInfo fi)
+ {
+ GuidAttribute [] attributes = fi.GetCustomAttributes (typeof (GuidAttribute), false) as GuidAttribute [];
+ if (attributes == null || attributes.Length != 1)
+ return new GuidAttribute ();
+
+ return attributes [0];
+ }
+ }
+}
--- /dev/null
+//
+// ICodeVisitable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal interface ICodeVisitable {
+ void Accept (ICodeVisitor visitor);
+ }
+}
--- /dev/null
+//
+// ICodeVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal interface ICodeVisitor {
+
+ void VisitMethodBody (MethodBody body);
+ void VisitInstructionCollection (InstructionCollection instructions);
+ void VisitInstruction (Instruction instr);
+ void VisitExceptionHandlerCollection (ExceptionHandlerCollection seh);
+ void VisitExceptionHandler (ExceptionHandler eh);
+ void VisitVariableDefinitionCollection (VariableDefinitionCollection variables);
+ void VisitVariableDefinition (VariableDefinition var);
+ void VisitScopeCollection (ScopeCollection scopes);
+ void VisitScope (Scope scope);
+
+ void TerminateMethodBody (MethodBody body);
+ }
+}
--- /dev/null
+//
+// Document.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal interface IScopeProvider {
+
+ ScopeCollection Scopes { get; }
+ }
+}
--- /dev/null
+//
+// ISymbolReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+
+namespace Mono.Cecil.Cil {
+
+ internal interface ISymbolReader : IDisposable {
+
+ void Read (MethodBody body, IDictionary instructions);
+ }
+}
--- /dev/null
+//
+// ISymbolStoreFactory.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal interface ISymbolStoreFactory {
+
+ ISymbolReader CreateReader (ModuleDefinition module, string assemblyFileName);
+ ISymbolWriter CreateWriter (ModuleDefinition module, string assemblyFileName);
+ }
+}
--- /dev/null
+//
+// ISymbolWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+
+ internal interface ISymbolWriter : IDisposable {
+
+ void Write (MethodBody body);
+ }
+}
--- /dev/null
+//
+// IVariableDefinitionProvider.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal interface IVariableDefinitionProvider {
+
+ VariableDefinitionCollection Variables { get; }
+ }
+}
--- /dev/null
+//
+// Instruction.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal sealed class Instruction : ICodeVisitable {
+
+ int m_offset;
+ OpCode m_opCode;
+ object m_operand;
+
+ Instruction m_previous;
+ Instruction m_next;
+
+ SequencePoint m_sequencePoint;
+
+ public int Offset {
+ get { return m_offset; }
+ set { m_offset = value; }
+ }
+
+ public OpCode OpCode {
+ get { return m_opCode; }
+ set { m_opCode = value; }
+ }
+
+ public object Operand {
+ get { return m_operand; }
+ set { m_operand = value; }
+ }
+
+ public Instruction Previous {
+ get { return m_previous; }
+ set { m_previous = value; }
+ }
+
+ public Instruction Next {
+ get { return m_next; }
+ set { m_next = value; }
+ }
+
+ public SequencePoint SequencePoint {
+ get { return m_sequencePoint; }
+ set { m_sequencePoint = value; }
+ }
+
+ internal Instruction (int offset, OpCode opCode, object operand) : this (offset, opCode)
+ {
+ m_operand = operand;
+ }
+
+ internal Instruction (int offset, OpCode opCode)
+ {
+ m_offset = offset;
+ m_opCode = opCode;
+ }
+
+ internal Instruction (OpCode opCode, object operand) : this (0, opCode, operand)
+ {
+ }
+
+ internal Instruction (OpCode opCode) : this (0, opCode)
+ {
+ }
+
+ public int GetSize ()
+ {
+ int size = m_opCode.Size;
+
+ switch (m_opCode.OperandType) {
+ case OperandType.InlineSwitch:
+ size += (1 + ((Instruction []) m_operand).Length) * 4;
+ break;
+ case OperandType.InlineI8:
+ case OperandType.InlineR:
+ size += 8;
+ break;
+ case OperandType.InlineBrTarget:
+ case OperandType.InlineField:
+ case OperandType.InlineI:
+ case OperandType.InlineMethod:
+ case OperandType.InlineString:
+ case OperandType.InlineTok:
+ case OperandType.InlineType:
+ case OperandType.ShortInlineR:
+ size += 4;
+ break;
+ case OperandType.InlineParam:
+ case OperandType.InlineVar:
+ size += 2;
+ break;
+ case OperandType.ShortInlineBrTarget:
+ case OperandType.ShortInlineI:
+ case OperandType.ShortInlineParam:
+ case OperandType.ShortInlineVar:
+ size += 1;
+ break;
+ }
+
+ return size;
+ }
+
+ public void Accept (ICodeVisitor visitor)
+ {
+ visitor.VisitInstruction (this);
+ }
+ }
+}
--- /dev/null
+//
+// InstructionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Thu Sep 28 17:54:43 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class InstructionCollection : CollectionBase, ICodeVisitable {
+
+ MethodBody m_container;
+ public readonly Instruction Outside = new Instruction (int.MaxValue, OpCodes.Nop);
+
+ public Instruction this [int index] {
+ get { return List [index] as Instruction; }
+ set { List [index] = value; }
+ }
+
+ public MethodBody Container {
+ get { return m_container; }
+ }
+
+ public InstructionCollection (MethodBody container)
+ {
+ m_container = container;
+ }
+
+ internal void Add (Instruction value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (Instruction value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (Instruction value)
+ {
+ return List.IndexOf (value);
+ }
+
+ internal void Insert (int index, Instruction value)
+ {
+ List.Insert (index, value);
+ }
+
+ internal void Remove (Instruction value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is Instruction))
+ throw new ArgumentException ("Must be of type " + typeof (Instruction).FullName);
+ }
+
+ public void Accept (ICodeVisitor visitor)
+ {
+ visitor.VisitInstructionCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// MethodBody.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using Mono.Cecil;
+
+ internal sealed class MethodBody : IVariableDefinitionProvider, IScopeProvider, ICodeVisitable {
+
+ MethodDefinition m_method;
+ int m_maxStack;
+ int m_codeSize;
+ bool m_initLocals;
+ int m_localVarToken;
+
+ InstructionCollection m_instructions;
+ ExceptionHandlerCollection m_exceptions;
+ VariableDefinitionCollection m_variables;
+ ScopeCollection m_scopes;
+
+ private CilWorker m_cilWorker;
+
+ public MethodDefinition Method {
+ get { return m_method; }
+ }
+
+ public int MaxStack {
+ get { return m_maxStack; }
+ set { m_maxStack = value; }
+ }
+
+ public int CodeSize {
+ get { return m_codeSize; }
+ set { m_codeSize = value; }
+ }
+
+ public bool InitLocals {
+ get { return m_initLocals; }
+ set { m_initLocals = value; }
+ }
+
+ public int LocalVarToken {
+ get { return m_localVarToken; }
+ set { m_localVarToken = value; }
+ }
+
+ public CilWorker CilWorker {
+ get {
+ if (m_cilWorker == null)
+ m_cilWorker = new CilWorker (this);
+ return m_cilWorker;
+ }
+ set { m_cilWorker = value; }
+ }
+
+ public InstructionCollection Instructions {
+ get { return m_instructions; }
+ }
+
+ public bool HasExceptionHandlers {
+ get { return m_exceptions != null && m_exceptions.Count > 0; }
+ }
+
+ public ExceptionHandlerCollection ExceptionHandlers {
+ get {
+ if (m_exceptions == null)
+ m_exceptions = new ExceptionHandlerCollection (this);
+ return m_exceptions;
+ }
+ }
+
+ public bool HasVariables {
+ get { return m_variables != null && m_variables.Count > 0; }
+ }
+
+ public VariableDefinitionCollection Variables {
+ get {
+ if (m_variables == null)
+ m_variables = new VariableDefinitionCollection (this);
+ return m_variables;
+ }
+ }
+
+ public bool HasScopes {
+ get { return m_scopes != null && m_scopes.Count > 0; }
+ }
+
+ public ScopeCollection Scopes {
+ get {
+ if (m_scopes == null)
+ m_scopes = new ScopeCollection (this);
+ return m_scopes;
+ }
+ }
+
+ public MethodBody (MethodDefinition meth)
+ {
+ m_method = meth;
+ // there is always a RET instruction (if a body is present)
+ m_instructions = new InstructionCollection (this);
+ }
+
+ internal static Instruction GetInstruction (MethodBody oldBody, MethodBody newBody, Instruction i)
+ {
+ int pos = oldBody.Instructions.IndexOf (i);
+ if (pos > -1 && pos < newBody.Instructions.Count)
+ return newBody.Instructions [pos];
+
+ return newBody.Instructions.Outside;
+ }
+
+ internal static MethodBody Clone (MethodBody body, MethodDefinition parent, ImportContext context)
+ {
+ MethodBody nb = new MethodBody (parent);
+ nb.MaxStack = body.MaxStack;
+ nb.InitLocals = body.InitLocals;
+ nb.CodeSize = body.CodeSize;
+
+ CilWorker worker = nb.CilWorker;
+
+ if (body.HasVariables) {
+ foreach (VariableDefinition var in body.Variables)
+ nb.Variables.Add (new VariableDefinition (
+ var.Name, var.Index, parent,
+ context.Import (var.VariableType)));
+ }
+
+ foreach (Instruction instr in body.Instructions) {
+ Instruction ni = new Instruction (instr.OpCode);
+
+ switch (instr.OpCode.OperandType) {
+ case OperandType.InlineParam :
+ case OperandType.ShortInlineParam :
+ if (instr.Operand == body.Method.This)
+ ni.Operand = nb.Method.This;
+ else {
+ int param = body.Method.Parameters.IndexOf ((ParameterDefinition) instr.Operand);
+ ni.Operand = parent.Parameters [param];
+ }
+ break;
+ case OperandType.InlineVar :
+ case OperandType.ShortInlineVar :
+ int var = body.Variables.IndexOf ((VariableDefinition) instr.Operand);
+ ni.Operand = nb.Variables [var];
+ break;
+ case OperandType.InlineField :
+ ni.Operand = context.Import ((FieldReference) instr.Operand);
+ break;
+ case OperandType.InlineMethod :
+ ni.Operand = context.Import ((MethodReference) instr.Operand);
+ break;
+ case OperandType.InlineType :
+ ni.Operand = context.Import ((TypeReference) instr.Operand);
+ break;
+ case OperandType.InlineTok :
+ if (instr.Operand is TypeReference)
+ ni.Operand = context.Import ((TypeReference) instr.Operand);
+ else if (instr.Operand is FieldReference)
+ ni.Operand = context.Import ((FieldReference) instr.Operand);
+ else if (instr.Operand is MethodReference)
+ ni.Operand = context.Import ((MethodReference) instr.Operand);
+ break;
+ case OperandType.ShortInlineBrTarget :
+ case OperandType.InlineBrTarget :
+ case OperandType.InlineSwitch :
+ break;
+ default :
+ ni.Operand = instr.Operand;
+ break;
+ }
+
+ worker.Append (ni);
+ }
+
+ for (int i = 0; i < body.Instructions.Count; i++) {
+ Instruction instr = nb.Instructions [i];
+ Instruction oldi = body.Instructions [i];
+
+ if (instr.OpCode.OperandType == OperandType.InlineSwitch) {
+ Instruction [] olds = (Instruction []) oldi.Operand;
+ Instruction [] targets = new Instruction [olds.Length];
+
+ for (int j = 0; j < targets.Length; j++)
+ targets [j] = GetInstruction (body, nb, olds [j]);
+
+ instr.Operand = targets;
+ } else if (instr.OpCode.OperandType == OperandType.ShortInlineBrTarget || instr.OpCode.OperandType == OperandType.InlineBrTarget)
+ instr.Operand = GetInstruction (body, nb, (Instruction) oldi.Operand);
+ }
+
+ if (!body.HasExceptionHandlers)
+ return nb;
+
+ foreach (ExceptionHandler eh in body.ExceptionHandlers) {
+ ExceptionHandler neh = new ExceptionHandler (eh.Type);
+ neh.TryStart = GetInstruction (body, nb, eh.TryStart);
+ neh.TryEnd = GetInstruction (body, nb, eh.TryEnd);
+ neh.HandlerStart = GetInstruction (body, nb, eh.HandlerStart);
+ neh.HandlerEnd = GetInstruction (body, nb, eh.HandlerEnd);
+
+ switch (eh.Type) {
+ case ExceptionHandlerType.Catch :
+ neh.CatchType = context.Import (eh.CatchType);
+ break;
+ case ExceptionHandlerType.Filter :
+ neh.FilterStart = GetInstruction (body, nb, eh.FilterStart);
+ neh.FilterEnd = GetInstruction (body, nb, eh.FilterEnd);
+ break;
+ }
+
+ nb.ExceptionHandlers.Add (neh);
+ }
+
+ return nb;
+ }
+
+ public void Simplify ()
+ {
+ foreach (Instruction i in this.Instructions) {
+ if (i.OpCode.OpCodeType != OpCodeType.Macro)
+ continue;
+
+ switch (i.OpCode.Code) {
+ case Code.Ldarg_0 :
+ Modify (i, OpCodes.Ldarg,
+ CodeReader.GetParameter (this, 0));
+ break;
+ case Code.Ldarg_1 :
+ Modify (i, OpCodes.Ldarg,
+ CodeReader.GetParameter (this, 1));
+ break;
+ case Code.Ldarg_2 :
+ Modify (i, OpCodes.Ldarg,
+ CodeReader.GetParameter (this, 2));
+ break;
+ case Code.Ldarg_3 :
+ Modify (i, OpCodes.Ldarg,
+ CodeReader.GetParameter (this, 3));
+ break;
+ case Code.Ldloc_0 :
+ Modify (i, OpCodes.Ldloc,
+ CodeReader.GetVariable (this, 0));
+ break;
+ case Code.Ldloc_1 :
+ Modify (i, OpCodes.Ldloc,
+ CodeReader.GetVariable (this, 1));
+ break;
+ case Code.Ldloc_2 :
+ Modify (i, OpCodes.Ldloc,
+ CodeReader.GetVariable (this, 2));
+ break;
+ case Code.Ldloc_3 :
+ Modify (i, OpCodes.Ldloc,
+ CodeReader.GetVariable (this, 3));
+ break;
+ case Code.Stloc_0 :
+ Modify (i, OpCodes.Stloc,
+ CodeReader.GetVariable (this, 0));
+ break;
+ case Code.Stloc_1 :
+ Modify (i, OpCodes.Stloc,
+ CodeReader.GetVariable (this, 1));
+ break;
+ case Code.Stloc_2 :
+ Modify (i, OpCodes.Stloc,
+ CodeReader.GetVariable (this, 2));
+ break;
+ case Code.Stloc_3 :
+ Modify (i, OpCodes.Stloc,
+ CodeReader.GetVariable (this, 3));
+ break;
+ case Code.Ldarg_S :
+ i.OpCode = OpCodes.Ldarg;
+ break;
+ case Code.Ldarga_S :
+ i.OpCode = OpCodes.Ldarga;
+ break;
+ case Code.Starg_S :
+ i.OpCode = OpCodes.Starg;
+ break;
+ case Code.Ldloc_S :
+ i.OpCode = OpCodes.Ldloc;
+ break;
+ case Code.Ldloca_S :
+ i.OpCode = OpCodes.Ldloca;
+ break;
+ case Code.Stloc_S :
+ i.OpCode = OpCodes.Stloc;
+ break;
+ case Code.Ldc_I4_M1 :
+ Modify (i, OpCodes.Ldc_I4, -1);
+ break;
+ case Code.Ldc_I4_0 :
+ Modify (i, OpCodes.Ldc_I4, 0);
+ break;
+ case Code.Ldc_I4_1 :
+ Modify (i, OpCodes.Ldc_I4, 1);
+ break;
+ case Code.Ldc_I4_2 :
+ Modify (i, OpCodes.Ldc_I4, 2);
+ break;
+ case Code.Ldc_I4_3 :
+ Modify (i, OpCodes.Ldc_I4, 3);
+ break;
+ case Code.Ldc_I4_4 :
+ Modify (i, OpCodes.Ldc_I4, 4);
+ break;
+ case Code.Ldc_I4_5 :
+ Modify (i, OpCodes.Ldc_I4, 5);
+ break;
+ case Code.Ldc_I4_6 :
+ Modify (i, OpCodes.Ldc_I4, 6);
+ break;
+ case Code.Ldc_I4_7 :
+ Modify (i, OpCodes.Ldc_I4, 7);
+ break;
+ case Code.Ldc_I4_8 :
+ Modify (i, OpCodes.Ldc_I4, 8);
+ break;
+ case Code.Ldc_I4_S :
+ i.OpCode = OpCodes.Ldc_I4;
+ i.Operand = (int) (sbyte) i.Operand;
+ break;
+ case Code.Br_S :
+ i.OpCode = OpCodes.Br;
+ break;
+ case Code.Brfalse_S :
+ i.OpCode = OpCodes.Brfalse;
+ break;
+ case Code.Brtrue_S :
+ i.OpCode = OpCodes.Brtrue;
+ break;
+ case Code.Beq_S :
+ i.OpCode = OpCodes.Beq;
+ break;
+ case Code.Bge_S :
+ i.OpCode = OpCodes.Bge;
+ break;
+ case Code.Bgt_S :
+ i.OpCode = OpCodes.Bgt;
+ break;
+ case Code.Ble_S :
+ i.OpCode = OpCodes.Ble;
+ break;
+ case Code.Blt_S :
+ i.OpCode = OpCodes.Blt;
+ break;
+ case Code.Bne_Un_S :
+ i.OpCode = OpCodes.Bne_Un;
+ break;
+ case Code.Bge_Un_S :
+ i.OpCode = OpCodes.Bge_Un;
+ break;
+ case Code.Bgt_Un_S :
+ i.OpCode = OpCodes.Bgt_Un;
+ break;
+ case Code.Ble_Un_S :
+ i.OpCode = OpCodes.Ble_Un;
+ break;
+ case Code.Blt_Un_S :
+ i.OpCode = OpCodes.Blt_Un;
+ break;
+ case Code.Leave_S :
+ i.OpCode = OpCodes.Leave;
+ break;
+ }
+ }
+ }
+
+ public void Optimize ()
+ {
+ foreach (Instruction instr in m_instructions) {
+ int index;
+ switch (instr.OpCode.Code) {
+ case Code.Ldarg:
+ index = m_method.Parameters.IndexOf ((ParameterDefinition) instr.Operand);
+ if (index == -1 && instr.Operand == m_method.This)
+ index = 0;
+ else if (m_method.HasThis)
+ index++;
+
+ switch (index) {
+ case 0:
+ Modify (instr, OpCodes.Ldarg_0, null);
+ break;
+ case 1:
+ Modify (instr, OpCodes.Ldarg_1, null);
+ break;
+ case 2:
+ Modify (instr, OpCodes.Ldarg_2, null);
+ break;
+ case 3:
+ Modify (instr, OpCodes.Ldarg_3, null);
+ break;
+ default:
+ if (index < 256)
+ Modify (instr, OpCodes.Ldarg_S, instr.Operand);
+ break;
+ }
+ break;
+ case Code.Ldloc:
+ index = m_variables.IndexOf ((VariableDefinition) instr.Operand);
+ switch (index) {
+ case 0:
+ Modify (instr, OpCodes.Ldloc_0, null);
+ break;
+ case 1:
+ Modify (instr, OpCodes.Ldloc_1, null);
+ break;
+ case 2:
+ Modify (instr, OpCodes.Ldloc_2, null);
+ break;
+ case 3:
+ Modify (instr, OpCodes.Ldloc_3, null);
+ break;
+ default:
+ if (index < 256)
+ Modify (instr, OpCodes.Ldloc_S, instr.Operand);
+ break;
+ }
+ break;
+ case Code.Stloc:
+ index = m_variables.IndexOf ((VariableDefinition) instr.Operand);
+ switch (index) {
+ case 0:
+ Modify (instr, OpCodes.Stloc_0, null);
+ break;
+ case 1:
+ Modify (instr, OpCodes.Stloc_1, null);
+ break;
+ case 2:
+ Modify (instr, OpCodes.Stloc_2, null);
+ break;
+ case 3:
+ Modify (instr, OpCodes.Stloc_3, null);
+ break;
+ default:
+ if (index < 256)
+ Modify (instr, OpCodes.Stloc_S, instr.Operand);
+ break;
+ }
+ break;
+ case Code.Ldarga:
+ index = m_method.Parameters.IndexOf ((ParameterDefinition) instr.Operand);
+ if (index == -1 && instr.Operand == m_method.This)
+ index = 0;
+ else if (m_method.HasThis)
+ index++;
+ if (index < 256)
+ Modify (instr, OpCodes.Ldarga_S, instr.Operand);
+ break;
+ case Code.Ldloca:
+ if (m_variables.IndexOf ((VariableDefinition) instr.Operand) < 256)
+ Modify (instr, OpCodes.Ldloca_S, instr.Operand);
+ break;
+ case Code.Ldc_I4:
+ int i = (int) instr.Operand;
+ switch (i) {
+ case -1:
+ Modify (instr, OpCodes.Ldc_I4_M1, null);
+ break;
+ case 0:
+ Modify (instr, OpCodes.Ldc_I4_0, null);
+ break;
+ case 1:
+ Modify (instr, OpCodes.Ldc_I4_1, null);
+ break;
+ case 2:
+ Modify (instr, OpCodes.Ldc_I4_2, null);
+ break;
+ case 3:
+ Modify (instr, OpCodes.Ldc_I4_3, null);
+ break;
+ case 4:
+ Modify (instr, OpCodes.Ldc_I4_4, null);
+ break;
+ case 5:
+ Modify (instr, OpCodes.Ldc_I4_5, null);
+ break;
+ case 6:
+ Modify (instr, OpCodes.Ldc_I4_6, null);
+ break;
+ case 7:
+ Modify (instr, OpCodes.Ldc_I4_7, null);
+ break;
+ case 8:
+ Modify (instr, OpCodes.Ldc_I4_8, null);
+ break;
+ default:
+ if (i >= -128 && i < 128)
+ Modify (instr, OpCodes.Ldc_I4_S, (sbyte) i);
+ break;
+ }
+ break;
+ }
+ }
+
+ OptimizeBranches ();
+ }
+
+ void OptimizeBranches ()
+ {
+ ComputeOffsets ();
+
+ foreach (Instruction instr in m_instructions) {
+ if (instr.OpCode.OperandType != OperandType.InlineBrTarget)
+ continue;
+
+ if (OptimizeBranch (instr))
+ ComputeOffsets ();
+ }
+ }
+
+ static bool OptimizeBranch (Instruction instr)
+ {
+ int offset = ((Instruction) instr.Operand).Offset - (instr.Offset + instr.OpCode.Size + 4);
+ if (! (offset >= -128 && offset <= 127))
+ return false;
+
+ switch (instr.OpCode.Code) {
+ case Code.Br:
+ instr.OpCode = OpCodes.Br_S;
+ break;
+ case Code.Brfalse:
+ instr.OpCode = OpCodes.Brfalse_S;
+ break;
+ case Code.Brtrue:
+ instr.OpCode = OpCodes.Brtrue_S;
+ break;
+ case Code.Beq:
+ instr.OpCode = OpCodes.Beq_S;
+ break;
+ case Code.Bge:
+ instr.OpCode = OpCodes.Bge_S;
+ break;
+ case Code.Bgt:
+ instr.OpCode = OpCodes.Bgt_S;
+ break;
+ case Code.Ble:
+ instr.OpCode = OpCodes.Ble_S;
+ break;
+ case Code.Blt:
+ instr.OpCode = OpCodes.Blt_S;
+ break;
+ case Code.Bne_Un:
+ instr.OpCode = OpCodes.Bne_Un_S;
+ break;
+ case Code.Bge_Un:
+ instr.OpCode = OpCodes.Bge_Un_S;
+ break;
+ case Code.Bgt_Un:
+ instr.OpCode = OpCodes.Bgt_Un_S;
+ break;
+ case Code.Ble_Un:
+ instr.OpCode = OpCodes.Ble_Un_S;
+ break;
+ case Code.Blt_Un:
+ instr.OpCode = OpCodes.Blt_Un_S;
+ break;
+ case Code.Leave:
+ instr.OpCode = OpCodes.Leave_S;
+ break;
+ }
+
+ return true;
+ }
+
+ void ComputeOffsets ()
+ {
+ int offset = 0;
+
+ foreach (Instruction instr in m_instructions) {
+ instr.Offset = offset;
+ offset += instr.GetSize ();
+ }
+ }
+
+ static void Modify (Instruction i, OpCode op, object operand)
+ {
+ i.OpCode = op;
+ i.Operand = operand;
+ }
+
+ public void Accept (ICodeVisitor visitor)
+ {
+ visitor.VisitMethodBody (this);
+ if (HasVariables)
+ m_variables.Accept (visitor);
+ m_instructions.Accept (visitor);
+ if (HasExceptionHandlers)
+ m_exceptions.Accept (visitor);
+ if (HasScopes)
+ m_scopes.Accept (visitor);
+
+ visitor.TerminateMethodBody (this);
+ }
+ }
+}
--- /dev/null
+//
+// MethodDataSection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal enum MethodDataSection : ushort {
+ EHTable = 0x1,
+ OptILTable = 0x2,
+ FatFormat = 0x40,
+ MoreSects = 0x80
+ }
+}
--- /dev/null
+//
+// MethodHeader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal enum MethodHeader : ushort {
+ TinyFormat = 0x2,
+ FatFormat = 0x3,
+ MoreSects = 0x8,
+ InitLocals = 0x10
+ }
+}
--- /dev/null
+//
+// OpCode.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal struct OpCode {
+ short m_value;
+ byte m_code;
+ byte m_flowControl;
+ byte m_opCodeType;
+ byte m_operandType;
+ byte m_stackBehaviourPop;
+ byte m_stackBehaviourPush;
+
+ public string Name {
+ get {
+ int index = (Size == 1) ? Op2 : (Op2 + 256);
+ return OpCodeNames.names [index];
+ }
+ }
+
+ public int Size {
+ get { return ((m_value & 0xff00) == 0xff00) ? 1 : 2; }
+ }
+
+ public byte Op1 {
+ get { return (byte) (m_value >> 8); }
+ }
+
+ public byte Op2 {
+ get { return (byte) m_value; }
+ }
+
+ public short Value {
+ get { return (Size == 1) ? Op2 : m_value; }
+ }
+
+ public Code Code {
+ get { return (Code) m_code; }
+ }
+
+ public FlowControl FlowControl {
+ get { return (FlowControl) m_flowControl; }
+ }
+
+ public OpCodeType OpCodeType {
+ get { return (OpCodeType) m_opCodeType; }
+ }
+
+ public OperandType OperandType {
+ get { return (OperandType) m_operandType; }
+ }
+
+ public StackBehaviour StackBehaviourPop {
+ get { return (StackBehaviour) m_stackBehaviourPop; }
+ }
+
+ public StackBehaviour StackBehaviourPush {
+ get { return (StackBehaviour) m_stackBehaviourPush; }
+ }
+
+ internal OpCode (byte op1, byte op2,
+ Code code, FlowControl flowControl,
+ OpCodeType opCodeType, OperandType operandType,
+ StackBehaviour pop, StackBehaviour push)
+ {
+ m_value = (short) ((op1 << 8) | op2);
+ m_code = (byte) code;
+ m_flowControl = (byte) flowControl;
+ m_opCodeType = (byte) opCodeType;
+ m_operandType = (byte) operandType;
+ m_stackBehaviourPop = (byte) pop;
+ m_stackBehaviourPush = (byte) push;
+
+ if (op1 == 0xff)
+ OpCodes.OneByteOpCode [op2] = this;
+ else
+ OpCodes.TwoBytesOpCode [op2] = this;
+ }
+
+ public override int GetHashCode ()
+ {
+ return m_value;
+ }
+
+ public override bool Equals (object obj)
+ {
+ if (!(obj is OpCode))
+ return false;
+ OpCode v = (OpCode) obj;
+ return v.m_value == m_value;
+ }
+
+ public bool Equals (OpCode opcode)
+ {
+ return (m_value == opcode.m_value);
+ }
+
+ public static bool operator == (OpCode one, OpCode other)
+ {
+ return (one.m_value == other.m_value);
+ }
+
+ public static bool operator != (OpCode one, OpCode other)
+ {
+ return (one.m_value != other.m_value);
+ }
+
+ public override string ToString ()
+ {
+ return Name;
+ }
+ }
+}
--- /dev/null
+//
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+// copy-pasted from /mcs/class/corlib/System.Reflection.Emit/OpCodeNames.cs
+// added names for "no." and "readonly."
+
+namespace Mono.Cecil.Cil {
+
+ internal sealed class OpCodeNames {
+
+ internal static readonly string [] names = {
+ "nop",
+ "break",
+ "ldarg.0",
+ "ldarg.1",
+ "ldarg.2",
+ "ldarg.3",
+ "ldloc.0",
+ "ldloc.1",
+ "ldloc.2",
+ "ldloc.3",
+ "stloc.0",
+ "stloc.1",
+ "stloc.2",
+ "stloc.3",
+ "ldarg.s",
+ "ldarga.s",
+ "starg.s",
+ "ldloc.s",
+ "ldloca.s",
+ "stloc.s",
+ "ldnull",
+ "ldc.i4.m1",
+ "ldc.i4.0",
+ "ldc.i4.1",
+ "ldc.i4.2",
+ "ldc.i4.3",
+ "ldc.i4.4",
+ "ldc.i4.5",
+ "ldc.i4.6",
+ "ldc.i4.7",
+ "ldc.i4.8",
+ "ldc.i4.s",
+ "ldc.i4",
+ "ldc.i8",
+ "ldc.r4",
+ "ldc.r8",
+ null,
+ "dup",
+ "pop",
+ "jmp",
+ "call",
+ "calli",
+ "ret",
+ "br.s",
+ "brfalse.s",
+ "brtrue.s",
+ "beq.s",
+ "bge.s",
+ "bgt.s",
+ "ble.s",
+ "blt.s",
+ "bne.un.s",
+ "bge.un.s",
+ "bgt.un.s",
+ "ble.un.s",
+ "blt.un.s",
+ "br",
+ "brfalse",
+ "brtrue",
+ "beq",
+ "bge",
+ "bgt",
+ "ble",
+ "blt",
+ "bne.un",
+ "bge.un",
+ "bgt.un",
+ "ble.un",
+ "blt.un",
+ "switch",
+ "ldind.i1",
+ "ldind.u1",
+ "ldind.i2",
+ "ldind.u2",
+ "ldind.i4",
+ "ldind.u4",
+ "ldind.i8",
+ "ldind.i",
+ "ldind.r4",
+ "ldind.r8",
+ "ldind.ref",
+ "stind.ref",
+ "stind.i1",
+ "stind.i2",
+ "stind.i4",
+ "stind.i8",
+ "stind.r4",
+ "stind.r8",
+ "add",
+ "sub",
+ "mul",
+ "div",
+ "div.un",
+ "rem",
+ "rem.un",
+ "and",
+ "or",
+ "xor",
+ "shl",
+ "shr",
+ "shr.un",
+ "neg",
+ "not",
+ "conv.i1",
+ "conv.i2",
+ "conv.i4",
+ "conv.i8",
+ "conv.r4",
+ "conv.r8",
+ "conv.u4",
+ "conv.u8",
+ "callvirt",
+ "cpobj",
+ "ldobj",
+ "ldstr",
+ "newobj",
+ "castclass",
+ "isinst",
+ "conv.r.un",
+ null,
+ null,
+ "unbox",
+ "throw",
+ "ldfld",
+ "ldflda",
+ "stfld",
+ "ldsfld",
+ "ldsflda",
+ "stsfld",
+ "stobj",
+ "conv.ovf.i1.un",
+ "conv.ovf.i2.un",
+ "conv.ovf.i4.un",
+ "conv.ovf.i8.un",
+ "conv.ovf.u1.un",
+ "conv.ovf.u2.un",
+ "conv.ovf.u4.un",
+ "conv.ovf.u8.un",
+ "conv.ovf.i.un",
+ "conv.ovf.u.un",
+ "box",
+ "newarr",
+ "ldlen",
+ "ldelema",
+ "ldelem.i1",
+ "ldelem.u1",
+ "ldelem.i2",
+ "ldelem.u2",
+ "ldelem.i4",
+ "ldelem.u4",
+ "ldelem.i8",
+ "ldelem.i",
+ "ldelem.r4",
+ "ldelem.r8",
+ "ldelem.ref",
+ "stelem.i",
+ "stelem.i1",
+ "stelem.i2",
+ "stelem.i4",
+ "stelem.i8",
+ "stelem.r4",
+ "stelem.r8",
+ "stelem.ref",
+ "ldelem.any",
+ "stelem.any",
+ "unbox.any",
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ "conv.ovf.i1",
+ "conv.ovf.u1",
+ "conv.ovf.i2",
+ "conv.ovf.u2",
+ "conv.ovf.i4",
+ "conv.ovf.u4",
+ "conv.ovf.i8",
+ "conv.ovf.u8",
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ "refanyval",
+ "ckfinite",
+ null,
+ null,
+ "mkrefany",
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ "ldtoken",
+ "conv.u2",
+ "conv.u1",
+ "conv.i",
+ "conv.ovf.i",
+ "conv.ovf.u",
+ "add.ovf",
+ "add.ovf.un",
+ "mul.ovf",
+ "mul.ovf.un",
+ "sub.ovf",
+ "sub.ovf.un",
+ "endfinally",
+ "leave",
+ "leave.s",
+ "stind.i",
+ "conv.u",
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ "prefix7",
+ "prefix6",
+ "prefix5",
+ "prefix4",
+ "prefix3",
+ "prefix2",
+ "prefix1",
+ "prefixref",
+ "arglist",
+ "ceq",
+ "cgt",
+ "cgt.un",
+ "clt",
+ "clt.un",
+ "ldftn",
+ "ldvirtftn",
+ null,
+ "ldarg",
+ "ldarga",
+ "starg",
+ "ldloc",
+ "ldloca",
+ "stloc",
+ "localloc",
+ null,
+ "endfilter",
+ "unaligned.",
+ "volatile.",
+ "tail.",
+ "initobj",
+ "constrained.",
+ "cpblk",
+ "initblk",
+ "no.", // added by spouliot to match Cecil existing definitions
+ "rethrow",
+ null,
+ "sizeof",
+ "refanytype",
+ "readonly.", // added by spouliot to match Cecil existing definitions
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ };
+ }
+}
--- /dev/null
+//
+// OpCodeType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal enum OpCodeType {
+ Annotation,
+ Macro,
+ Nternal,
+ Objmodel,
+ Prefix,
+ Primitive
+ }
+}
--- /dev/null
+//
+// OpCodes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Jun 06 13:04:02 +0200 2008
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal sealed class OpCodes {
+
+ internal static readonly OpCode [] OneByteOpCode = new OpCode [0xe0 + 1];
+ internal static readonly OpCode [] TwoBytesOpCode = new OpCode [0x1e + 1];
+
+ public static readonly OpCode Nop = new OpCode (
+ 0xff, 0x00,
+ Code.Nop, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Break = new OpCode (
+ 0xff, 0x01,
+ Code.Break, FlowControl.Break,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Ldarg_0 = new OpCode (
+ 0xff, 0x02,
+ Code.Ldarg_0, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldarg_1 = new OpCode (
+ 0xff, 0x03,
+ Code.Ldarg_1, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldarg_2 = new OpCode (
+ 0xff, 0x04,
+ Code.Ldarg_2, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldarg_3 = new OpCode (
+ 0xff, 0x05,
+ Code.Ldarg_3, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldloc_0 = new OpCode (
+ 0xff, 0x06,
+ Code.Ldloc_0, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldloc_1 = new OpCode (
+ 0xff, 0x07,
+ Code.Ldloc_1, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldloc_2 = new OpCode (
+ 0xff, 0x08,
+ Code.Ldloc_2, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldloc_3 = new OpCode (
+ 0xff, 0x09,
+ Code.Ldloc_3, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Stloc_0 = new OpCode (
+ 0xff, 0x0a,
+ Code.Stloc_0, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Stloc_1 = new OpCode (
+ 0xff, 0x0b,
+ Code.Stloc_1, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Stloc_2 = new OpCode (
+ 0xff, 0x0c,
+ Code.Stloc_2, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Stloc_3 = new OpCode (
+ 0xff, 0x0d,
+ Code.Stloc_3, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Ldarg_S = new OpCode (
+ 0xff, 0x0e,
+ Code.Ldarg_S, FlowControl.Next,
+ OpCodeType.Macro, OperandType.ShortInlineParam,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldarga_S = new OpCode (
+ 0xff, 0x0f,
+ Code.Ldarga_S, FlowControl.Next,
+ OpCodeType.Macro, OperandType.ShortInlineParam,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Starg_S = new OpCode (
+ 0xff, 0x10,
+ Code.Starg_S, FlowControl.Next,
+ OpCodeType.Macro, OperandType.ShortInlineParam,
+ StackBehaviour.Pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Ldloc_S = new OpCode (
+ 0xff, 0x11,
+ Code.Ldloc_S, FlowControl.Next,
+ OpCodeType.Macro, OperandType.ShortInlineVar,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldloca_S = new OpCode (
+ 0xff, 0x12,
+ Code.Ldloca_S, FlowControl.Next,
+ OpCodeType.Macro, OperandType.ShortInlineVar,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Stloc_S = new OpCode (
+ 0xff, 0x13,
+ Code.Stloc_S, FlowControl.Next,
+ OpCodeType.Macro, OperandType.ShortInlineVar,
+ StackBehaviour.Pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Ldnull = new OpCode (
+ 0xff, 0x14,
+ Code.Ldnull, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushref);
+
+ public static readonly OpCode Ldc_I4_M1 = new OpCode (
+ 0xff, 0x15,
+ Code.Ldc_I4_M1, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4_0 = new OpCode (
+ 0xff, 0x16,
+ Code.Ldc_I4_0, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4_1 = new OpCode (
+ 0xff, 0x17,
+ Code.Ldc_I4_1, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4_2 = new OpCode (
+ 0xff, 0x18,
+ Code.Ldc_I4_2, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4_3 = new OpCode (
+ 0xff, 0x19,
+ Code.Ldc_I4_3, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4_4 = new OpCode (
+ 0xff, 0x1a,
+ Code.Ldc_I4_4, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4_5 = new OpCode (
+ 0xff, 0x1b,
+ Code.Ldc_I4_5, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4_6 = new OpCode (
+ 0xff, 0x1c,
+ Code.Ldc_I4_6, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4_7 = new OpCode (
+ 0xff, 0x1d,
+ Code.Ldc_I4_7, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4_8 = new OpCode (
+ 0xff, 0x1e,
+ Code.Ldc_I4_8, FlowControl.Next,
+ OpCodeType.Macro, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4_S = new OpCode (
+ 0xff, 0x1f,
+ Code.Ldc_I4_S, FlowControl.Next,
+ OpCodeType.Macro, OperandType.ShortInlineI,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I4 = new OpCode (
+ 0xff, 0x20,
+ Code.Ldc_I4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineI,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldc_I8 = new OpCode (
+ 0xff, 0x21,
+ Code.Ldc_I8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineI8,
+ StackBehaviour.Pop0, StackBehaviour.Pushi8);
+
+ public static readonly OpCode Ldc_R4 = new OpCode (
+ 0xff, 0x22,
+ Code.Ldc_R4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.ShortInlineR,
+ StackBehaviour.Pop0, StackBehaviour.Pushr4);
+
+ public static readonly OpCode Ldc_R8 = new OpCode (
+ 0xff, 0x23,
+ Code.Ldc_R8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineR,
+ StackBehaviour.Pop0, StackBehaviour.Pushr8);
+
+ public static readonly OpCode Dup = new OpCode (
+ 0xff, 0x25,
+ Code.Dup, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Push1_push1);
+
+ public static readonly OpCode Pop = new OpCode (
+ 0xff, 0x26,
+ Code.Pop, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Jmp = new OpCode (
+ 0xff, 0x27,
+ Code.Jmp, FlowControl.Call,
+ OpCodeType.Primitive, OperandType.InlineMethod,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Call = new OpCode (
+ 0xff, 0x28,
+ Code.Call, FlowControl.Call,
+ OpCodeType.Primitive, OperandType.InlineMethod,
+ StackBehaviour.Varpop, StackBehaviour.Varpush);
+
+ public static readonly OpCode Calli = new OpCode (
+ 0xff, 0x29,
+ Code.Calli, FlowControl.Call,
+ OpCodeType.Primitive, OperandType.InlineSig,
+ StackBehaviour.Varpop, StackBehaviour.Varpush);
+
+ public static readonly OpCode Ret = new OpCode (
+ 0xff, 0x2a,
+ Code.Ret, FlowControl.Return,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Varpop, StackBehaviour.Push0);
+
+ public static readonly OpCode Br_S = new OpCode (
+ 0xff, 0x2b,
+ Code.Br_S, FlowControl.Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Brfalse_S = new OpCode (
+ 0xff, 0x2c,
+ Code.Brfalse_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Brtrue_S = new OpCode (
+ 0xff, 0x2d,
+ Code.Brtrue_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Beq_S = new OpCode (
+ 0xff, 0x2e,
+ Code.Beq_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Bge_S = new OpCode (
+ 0xff, 0x2f,
+ Code.Bge_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Bgt_S = new OpCode (
+ 0xff, 0x30,
+ Code.Bgt_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Ble_S = new OpCode (
+ 0xff, 0x31,
+ Code.Ble_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Blt_S = new OpCode (
+ 0xff, 0x32,
+ Code.Blt_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Bne_Un_S = new OpCode (
+ 0xff, 0x33,
+ Code.Bne_Un_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Bge_Un_S = new OpCode (
+ 0xff, 0x34,
+ Code.Bge_Un_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Bgt_Un_S = new OpCode (
+ 0xff, 0x35,
+ Code.Bgt_Un_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Ble_Un_S = new OpCode (
+ 0xff, 0x36,
+ Code.Ble_Un_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Blt_Un_S = new OpCode (
+ 0xff, 0x37,
+ Code.Blt_Un_S, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Br = new OpCode (
+ 0xff, 0x38,
+ Code.Br, FlowControl.Branch,
+ OpCodeType.Primitive, OperandType.InlineBrTarget,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Brfalse = new OpCode (
+ 0xff, 0x39,
+ Code.Brfalse, FlowControl.Cond_Branch,
+ OpCodeType.Primitive, OperandType.InlineBrTarget,
+ StackBehaviour.Popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Brtrue = new OpCode (
+ 0xff, 0x3a,
+ Code.Brtrue, FlowControl.Cond_Branch,
+ OpCodeType.Primitive, OperandType.InlineBrTarget,
+ StackBehaviour.Popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Beq = new OpCode (
+ 0xff, 0x3b,
+ Code.Beq, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.InlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Bge = new OpCode (
+ 0xff, 0x3c,
+ Code.Bge, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.InlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Bgt = new OpCode (
+ 0xff, 0x3d,
+ Code.Bgt, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.InlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Ble = new OpCode (
+ 0xff, 0x3e,
+ Code.Ble, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.InlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Blt = new OpCode (
+ 0xff, 0x3f,
+ Code.Blt, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.InlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Bne_Un = new OpCode (
+ 0xff, 0x40,
+ Code.Bne_Un, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.InlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Bge_Un = new OpCode (
+ 0xff, 0x41,
+ Code.Bge_Un, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.InlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Bgt_Un = new OpCode (
+ 0xff, 0x42,
+ Code.Bgt_Un, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.InlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Ble_Un = new OpCode (
+ 0xff, 0x43,
+ Code.Ble_Un, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.InlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Blt_Un = new OpCode (
+ 0xff, 0x44,
+ Code.Blt_Un, FlowControl.Cond_Branch,
+ OpCodeType.Macro, OperandType.InlineBrTarget,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Switch = new OpCode (
+ 0xff, 0x45,
+ Code.Switch, FlowControl.Cond_Branch,
+ OpCodeType.Primitive, OperandType.InlineSwitch,
+ StackBehaviour.Popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Ldind_I1 = new OpCode (
+ 0xff, 0x46,
+ Code.Ldind_I1, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldind_U1 = new OpCode (
+ 0xff, 0x47,
+ Code.Ldind_U1, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldind_I2 = new OpCode (
+ 0xff, 0x48,
+ Code.Ldind_I2, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldind_U2 = new OpCode (
+ 0xff, 0x49,
+ Code.Ldind_U2, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldind_I4 = new OpCode (
+ 0xff, 0x4a,
+ Code.Ldind_I4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldind_U4 = new OpCode (
+ 0xff, 0x4b,
+ Code.Ldind_U4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldind_I8 = new OpCode (
+ 0xff, 0x4c,
+ Code.Ldind_I8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushi8);
+
+ public static readonly OpCode Ldind_I = new OpCode (
+ 0xff, 0x4d,
+ Code.Ldind_I, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldind_R4 = new OpCode (
+ 0xff, 0x4e,
+ Code.Ldind_R4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushr4);
+
+ public static readonly OpCode Ldind_R8 = new OpCode (
+ 0xff, 0x4f,
+ Code.Ldind_R8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushr8);
+
+ public static readonly OpCode Ldind_Ref = new OpCode (
+ 0xff, 0x50,
+ Code.Ldind_Ref, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushref);
+
+ public static readonly OpCode Stind_Ref = new OpCode (
+ 0xff, 0x51,
+ Code.Stind_Ref, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Stind_I1 = new OpCode (
+ 0xff, 0x52,
+ Code.Stind_I1, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Stind_I2 = new OpCode (
+ 0xff, 0x53,
+ Code.Stind_I2, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Stind_I4 = new OpCode (
+ 0xff, 0x54,
+ Code.Stind_I4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Stind_I8 = new OpCode (
+ 0xff, 0x55,
+ Code.Stind_I8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi_popi8, StackBehaviour.Push0);
+
+ public static readonly OpCode Stind_R4 = new OpCode (
+ 0xff, 0x56,
+ Code.Stind_R4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi_popr4, StackBehaviour.Push0);
+
+ public static readonly OpCode Stind_R8 = new OpCode (
+ 0xff, 0x57,
+ Code.Stind_R8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi_popr8, StackBehaviour.Push0);
+
+ public static readonly OpCode Add = new OpCode (
+ 0xff, 0x58,
+ Code.Add, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Sub = new OpCode (
+ 0xff, 0x59,
+ Code.Sub, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Mul = new OpCode (
+ 0xff, 0x5a,
+ Code.Mul, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Div = new OpCode (
+ 0xff, 0x5b,
+ Code.Div, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Div_Un = new OpCode (
+ 0xff, 0x5c,
+ Code.Div_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Rem = new OpCode (
+ 0xff, 0x5d,
+ Code.Rem, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Rem_Un = new OpCode (
+ 0xff, 0x5e,
+ Code.Rem_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode And = new OpCode (
+ 0xff, 0x5f,
+ Code.And, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Or = new OpCode (
+ 0xff, 0x60,
+ Code.Or, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Xor = new OpCode (
+ 0xff, 0x61,
+ Code.Xor, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Shl = new OpCode (
+ 0xff, 0x62,
+ Code.Shl, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Shr = new OpCode (
+ 0xff, 0x63,
+ Code.Shr, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Shr_Un = new OpCode (
+ 0xff, 0x64,
+ Code.Shr_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Neg = new OpCode (
+ 0xff, 0x65,
+ Code.Neg, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Not = new OpCode (
+ 0xff, 0x66,
+ Code.Not, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Conv_I1 = new OpCode (
+ 0xff, 0x67,
+ Code.Conv_I1, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_I2 = new OpCode (
+ 0xff, 0x68,
+ Code.Conv_I2, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_I4 = new OpCode (
+ 0xff, 0x69,
+ Code.Conv_I4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_I8 = new OpCode (
+ 0xff, 0x6a,
+ Code.Conv_I8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi8);
+
+ public static readonly OpCode Conv_R4 = new OpCode (
+ 0xff, 0x6b,
+ Code.Conv_R4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushr4);
+
+ public static readonly OpCode Conv_R8 = new OpCode (
+ 0xff, 0x6c,
+ Code.Conv_R8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushr8);
+
+ public static readonly OpCode Conv_U4 = new OpCode (
+ 0xff, 0x6d,
+ Code.Conv_U4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_U8 = new OpCode (
+ 0xff, 0x6e,
+ Code.Conv_U8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi8);
+
+ public static readonly OpCode Callvirt = new OpCode (
+ 0xff, 0x6f,
+ Code.Callvirt, FlowControl.Call,
+ OpCodeType.Objmodel, OperandType.InlineMethod,
+ StackBehaviour.Varpop, StackBehaviour.Varpush);
+
+ public static readonly OpCode Cpobj = new OpCode (
+ 0xff, 0x70,
+ Code.Cpobj, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Ldobj = new OpCode (
+ 0xff, 0x71,
+ Code.Ldobj, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popi, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldstr = new OpCode (
+ 0xff, 0x72,
+ Code.Ldstr, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineString,
+ StackBehaviour.Pop0, StackBehaviour.Pushref);
+
+ public static readonly OpCode Newobj = new OpCode (
+ 0xff, 0x73,
+ Code.Newobj, FlowControl.Call,
+ OpCodeType.Objmodel, OperandType.InlineMethod,
+ StackBehaviour.Varpop, StackBehaviour.Pushref);
+
+ public static readonly OpCode Castclass = new OpCode (
+ 0xff, 0x74,
+ Code.Castclass, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popref, StackBehaviour.Pushref);
+
+ public static readonly OpCode Isinst = new OpCode (
+ 0xff, 0x75,
+ Code.Isinst, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popref, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_R_Un = new OpCode (
+ 0xff, 0x76,
+ Code.Conv_R_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushr8);
+
+ public static readonly OpCode Unbox = new OpCode (
+ 0xff, 0x79,
+ Code.Unbox, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineType,
+ StackBehaviour.Popref, StackBehaviour.Pushi);
+
+ public static readonly OpCode Throw = new OpCode (
+ 0xff, 0x7a,
+ Code.Throw, FlowControl.Throw,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref, StackBehaviour.Push0);
+
+ public static readonly OpCode Ldfld = new OpCode (
+ 0xff, 0x7b,
+ Code.Ldfld, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineField,
+ StackBehaviour.Popref, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldflda = new OpCode (
+ 0xff, 0x7c,
+ Code.Ldflda, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineField,
+ StackBehaviour.Popref, StackBehaviour.Pushi);
+
+ public static readonly OpCode Stfld = new OpCode (
+ 0xff, 0x7d,
+ Code.Stfld, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineField,
+ StackBehaviour.Popref_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Ldsfld = new OpCode (
+ 0xff, 0x7e,
+ Code.Ldsfld, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineField,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldsflda = new OpCode (
+ 0xff, 0x7f,
+ Code.Ldsflda, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineField,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Stsfld = new OpCode (
+ 0xff, 0x80,
+ Code.Stsfld, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineField,
+ StackBehaviour.Pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Stobj = new OpCode (
+ 0xff, 0x81,
+ Code.Stobj, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popi_pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Conv_Ovf_I1_Un = new OpCode (
+ 0xff, 0x82,
+ Code.Conv_Ovf_I1_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_I2_Un = new OpCode (
+ 0xff, 0x83,
+ Code.Conv_Ovf_I2_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_I4_Un = new OpCode (
+ 0xff, 0x84,
+ Code.Conv_Ovf_I4_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_I8_Un = new OpCode (
+ 0xff, 0x85,
+ Code.Conv_Ovf_I8_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi8);
+
+ public static readonly OpCode Conv_Ovf_U1_Un = new OpCode (
+ 0xff, 0x86,
+ Code.Conv_Ovf_U1_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_U2_Un = new OpCode (
+ 0xff, 0x87,
+ Code.Conv_Ovf_U2_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_U4_Un = new OpCode (
+ 0xff, 0x88,
+ Code.Conv_Ovf_U4_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_U8_Un = new OpCode (
+ 0xff, 0x89,
+ Code.Conv_Ovf_U8_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi8);
+
+ public static readonly OpCode Conv_Ovf_I_Un = new OpCode (
+ 0xff, 0x8a,
+ Code.Conv_Ovf_I_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_U_Un = new OpCode (
+ 0xff, 0x8b,
+ Code.Conv_Ovf_U_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Box = new OpCode (
+ 0xff, 0x8c,
+ Code.Box, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineType,
+ StackBehaviour.Pop1, StackBehaviour.Pushref);
+
+ public static readonly OpCode Newarr = new OpCode (
+ 0xff, 0x8d,
+ Code.Newarr, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popi, StackBehaviour.Pushref);
+
+ public static readonly OpCode Ldlen = new OpCode (
+ 0xff, 0x8e,
+ Code.Ldlen, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldelema = new OpCode (
+ 0xff, 0x8f,
+ Code.Ldelema, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldelem_I1 = new OpCode (
+ 0xff, 0x90,
+ Code.Ldelem_I1, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldelem_U1 = new OpCode (
+ 0xff, 0x91,
+ Code.Ldelem_U1, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldelem_I2 = new OpCode (
+ 0xff, 0x92,
+ Code.Ldelem_I2, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldelem_U2 = new OpCode (
+ 0xff, 0x93,
+ Code.Ldelem_U2, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldelem_I4 = new OpCode (
+ 0xff, 0x94,
+ Code.Ldelem_I4, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldelem_U4 = new OpCode (
+ 0xff, 0x95,
+ Code.Ldelem_U4, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldelem_I8 = new OpCode (
+ 0xff, 0x96,
+ Code.Ldelem_I8, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushi8);
+
+ public static readonly OpCode Ldelem_I = new OpCode (
+ 0xff, 0x97,
+ Code.Ldelem_I, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldelem_R4 = new OpCode (
+ 0xff, 0x98,
+ Code.Ldelem_R4, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushr4);
+
+ public static readonly OpCode Ldelem_R8 = new OpCode (
+ 0xff, 0x99,
+ Code.Ldelem_R8, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushr8);
+
+ public static readonly OpCode Ldelem_Ref = new OpCode (
+ 0xff, 0x9a,
+ Code.Ldelem_Ref, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi, StackBehaviour.Pushref);
+
+ public static readonly OpCode Stelem_I = new OpCode (
+ 0xff, 0x9b,
+ Code.Stelem_I, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Stelem_I1 = new OpCode (
+ 0xff, 0x9c,
+ Code.Stelem_I1, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Stelem_I2 = new OpCode (
+ 0xff, 0x9d,
+ Code.Stelem_I2, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Stelem_I4 = new OpCode (
+ 0xff, 0x9e,
+ Code.Stelem_I4, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Stelem_I8 = new OpCode (
+ 0xff, 0x9f,
+ Code.Stelem_I8, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi_popi8, StackBehaviour.Push0);
+
+ public static readonly OpCode Stelem_R4 = new OpCode (
+ 0xff, 0xa0,
+ Code.Stelem_R4, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi_popr4, StackBehaviour.Push0);
+
+ public static readonly OpCode Stelem_R8 = new OpCode (
+ 0xff, 0xa1,
+ Code.Stelem_R8, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi_popr8, StackBehaviour.Push0);
+
+ public static readonly OpCode Stelem_Ref = new OpCode (
+ 0xff, 0xa2,
+ Code.Stelem_Ref, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Popref_popi_popref, StackBehaviour.Push0);
+
+ public static readonly OpCode Ldelem_Any = new OpCode (
+ 0xff, 0xa3,
+ Code.Ldelem_Any, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popref_popi, StackBehaviour.Push1);
+
+ public static readonly OpCode Stelem_Any = new OpCode (
+ 0xff, 0xa4,
+ Code.Stelem_Any, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popref_popi_popref, StackBehaviour.Push0);
+
+ public static readonly OpCode Unbox_Any = new OpCode (
+ 0xff, 0xa5,
+ Code.Unbox_Any, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popref, StackBehaviour.Push1);
+
+ public static readonly OpCode Conv_Ovf_I1 = new OpCode (
+ 0xff, 0xb3,
+ Code.Conv_Ovf_I1, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_U1 = new OpCode (
+ 0xff, 0xb4,
+ Code.Conv_Ovf_U1, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_I2 = new OpCode (
+ 0xff, 0xb5,
+ Code.Conv_Ovf_I2, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_U2 = new OpCode (
+ 0xff, 0xb6,
+ Code.Conv_Ovf_U2, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_I4 = new OpCode (
+ 0xff, 0xb7,
+ Code.Conv_Ovf_I4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_U4 = new OpCode (
+ 0xff, 0xb8,
+ Code.Conv_Ovf_U4, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_I8 = new OpCode (
+ 0xff, 0xb9,
+ Code.Conv_Ovf_I8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi8);
+
+ public static readonly OpCode Conv_Ovf_U8 = new OpCode (
+ 0xff, 0xba,
+ Code.Conv_Ovf_U8, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi8);
+
+ public static readonly OpCode Refanyval = new OpCode (
+ 0xff, 0xc2,
+ Code.Refanyval, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineType,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ckfinite = new OpCode (
+ 0xff, 0xc3,
+ Code.Ckfinite, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushr8);
+
+ public static readonly OpCode Mkrefany = new OpCode (
+ 0xff, 0xc6,
+ Code.Mkrefany, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineType,
+ StackBehaviour.Popi, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldtoken = new OpCode (
+ 0xff, 0xd0,
+ Code.Ldtoken, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineTok,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_U2 = new OpCode (
+ 0xff, 0xd1,
+ Code.Conv_U2, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_U1 = new OpCode (
+ 0xff, 0xd2,
+ Code.Conv_U1, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_I = new OpCode (
+ 0xff, 0xd3,
+ Code.Conv_I, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_I = new OpCode (
+ 0xff, 0xd4,
+ Code.Conv_Ovf_I, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Conv_Ovf_U = new OpCode (
+ 0xff, 0xd5,
+ Code.Conv_Ovf_U, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Add_Ovf = new OpCode (
+ 0xff, 0xd6,
+ Code.Add_Ovf, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Add_Ovf_Un = new OpCode (
+ 0xff, 0xd7,
+ Code.Add_Ovf_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Mul_Ovf = new OpCode (
+ 0xff, 0xd8,
+ Code.Mul_Ovf, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Mul_Ovf_Un = new OpCode (
+ 0xff, 0xd9,
+ Code.Mul_Ovf_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Sub_Ovf = new OpCode (
+ 0xff, 0xda,
+ Code.Sub_Ovf, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Sub_Ovf_Un = new OpCode (
+ 0xff, 0xdb,
+ Code.Sub_Ovf_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Push1);
+
+ public static readonly OpCode Endfinally = new OpCode (
+ 0xff, 0xdc,
+ Code.Endfinally, FlowControl.Return,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Leave = new OpCode (
+ 0xff, 0xdd,
+ Code.Leave, FlowControl.Branch,
+ OpCodeType.Primitive, OperandType.InlineBrTarget,
+ StackBehaviour.PopAll, StackBehaviour.Push0);
+
+ public static readonly OpCode Leave_S = new OpCode (
+ 0xff, 0xde,
+ Code.Leave_S, FlowControl.Branch,
+ OpCodeType.Macro, OperandType.ShortInlineBrTarget,
+ StackBehaviour.PopAll, StackBehaviour.Push0);
+
+ public static readonly OpCode Stind_I = new OpCode (
+ 0xff, 0xdf,
+ Code.Stind_I, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Conv_U = new OpCode (
+ 0xff, 0xe0,
+ Code.Conv_U, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Arglist = new OpCode (
+ 0xfe, 0x00,
+ Code.Arglist, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ceq = new OpCode (
+ 0xfe, 0x01,
+ Code.Ceq, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Cgt = new OpCode (
+ 0xfe, 0x02,
+ Code.Cgt, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Cgt_Un = new OpCode (
+ 0xfe, 0x03,
+ Code.Cgt_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Clt = new OpCode (
+ 0xfe, 0x04,
+ Code.Clt, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Clt_Un = new OpCode (
+ 0xfe, 0x05,
+ Code.Clt_Un, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1_pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldftn = new OpCode (
+ 0xfe, 0x06,
+ Code.Ldftn, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineMethod,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldvirtftn = new OpCode (
+ 0xfe, 0x07,
+ Code.Ldvirtftn, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineMethod,
+ StackBehaviour.Popref, StackBehaviour.Pushi);
+
+ public static readonly OpCode Ldarg = new OpCode (
+ 0xfe, 0x09,
+ Code.Ldarg, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineParam,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldarga = new OpCode (
+ 0xfe, 0x0a,
+ Code.Ldarga, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineParam,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Starg = new OpCode (
+ 0xfe, 0x0b,
+ Code.Starg, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineParam,
+ StackBehaviour.Pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Ldloc = new OpCode (
+ 0xfe, 0x0c,
+ Code.Ldloc, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineVar,
+ StackBehaviour.Pop0, StackBehaviour.Push1);
+
+ public static readonly OpCode Ldloca = new OpCode (
+ 0xfe, 0x0d,
+ Code.Ldloca, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineVar,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Stloc = new OpCode (
+ 0xfe, 0x0e,
+ Code.Stloc, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineVar,
+ StackBehaviour.Pop1, StackBehaviour.Push0);
+
+ public static readonly OpCode Localloc = new OpCode (
+ 0xfe, 0x0f,
+ Code.Localloc, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Pushi);
+
+ public static readonly OpCode Endfilter = new OpCode (
+ 0xfe, 0x11,
+ Code.Endfilter, FlowControl.Return,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Unaligned = new OpCode (
+ 0xfe, 0x12,
+ Code.Unaligned, FlowControl.Meta,
+ OpCodeType.Prefix, OperandType.ShortInlineI,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Volatile = new OpCode (
+ 0xfe, 0x13,
+ Code.Volatile, FlowControl.Meta,
+ OpCodeType.Prefix, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Tail = new OpCode (
+ 0xfe, 0x14,
+ Code.Tail, FlowControl.Meta,
+ OpCodeType.Prefix, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Initobj = new OpCode (
+ 0xfe, 0x15,
+ Code.Initobj, FlowControl.Next,
+ OpCodeType.Objmodel, OperandType.InlineType,
+ StackBehaviour.Popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Constrained = new OpCode (
+ 0xfe, 0x16,
+ Code.Constrained, FlowControl.Next,
+ OpCodeType.Prefix, OperandType.InlineType,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Cpblk = new OpCode (
+ 0xfe, 0x17,
+ Code.Cpblk, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi_popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode Initblk = new OpCode (
+ 0xfe, 0x18,
+ Code.Initblk, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Popi_popi_popi, StackBehaviour.Push0);
+
+ public static readonly OpCode No = new OpCode (
+ 0xfe, 0x19,
+ Code.No, FlowControl.Next,
+ OpCodeType.Prefix, OperandType.ShortInlineI,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Rethrow = new OpCode (
+ 0xfe, 0x1a,
+ Code.Rethrow, FlowControl.Throw,
+ OpCodeType.Objmodel, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ public static readonly OpCode Sizeof = new OpCode (
+ 0xfe, 0x1c,
+ Code.Sizeof, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineType,
+ StackBehaviour.Pop0, StackBehaviour.Pushi);
+
+ public static readonly OpCode Refanytype = new OpCode (
+ 0xfe, 0x1d,
+ Code.Refanytype, FlowControl.Next,
+ OpCodeType.Primitive, OperandType.InlineNone,
+ StackBehaviour.Pop1, StackBehaviour.Pushi);
+
+ public static readonly OpCode Readonly = new OpCode (
+ 0xfe, 0x1e,
+ Code.Readonly, FlowControl.Next,
+ OpCodeType.Prefix, OperandType.InlineNone,
+ StackBehaviour.Pop0, StackBehaviour.Push0);
+
+ OpCodes ()
+ {
+ }
+
+ public static OpCode GetOpCode (Code code)
+ {
+ switch (code) {
+ case Code.Nop : return OpCodes.Nop;
+ case Code.Break : return OpCodes.Break;
+ case Code.Ldarg_0 : return OpCodes.Ldarg_0;
+ case Code.Ldarg_1 : return OpCodes.Ldarg_1;
+ case Code.Ldarg_2 : return OpCodes.Ldarg_2;
+ case Code.Ldarg_3 : return OpCodes.Ldarg_3;
+ case Code.Ldloc_0 : return OpCodes.Ldloc_0;
+ case Code.Ldloc_1 : return OpCodes.Ldloc_1;
+ case Code.Ldloc_2 : return OpCodes.Ldloc_2;
+ case Code.Ldloc_3 : return OpCodes.Ldloc_3;
+ case Code.Stloc_0 : return OpCodes.Stloc_0;
+ case Code.Stloc_1 : return OpCodes.Stloc_1;
+ case Code.Stloc_2 : return OpCodes.Stloc_2;
+ case Code.Stloc_3 : return OpCodes.Stloc_3;
+ case Code.Ldarg_S : return OpCodes.Ldarg_S;
+ case Code.Ldarga_S : return OpCodes.Ldarga_S;
+ case Code.Starg_S : return OpCodes.Starg_S;
+ case Code.Ldloc_S : return OpCodes.Ldloc_S;
+ case Code.Ldloca_S : return OpCodes.Ldloca_S;
+ case Code.Stloc_S : return OpCodes.Stloc_S;
+ case Code.Ldnull : return OpCodes.Ldnull;
+ case Code.Ldc_I4_M1 : return OpCodes.Ldc_I4_M1;
+ case Code.Ldc_I4_0 : return OpCodes.Ldc_I4_0;
+ case Code.Ldc_I4_1 : return OpCodes.Ldc_I4_1;
+ case Code.Ldc_I4_2 : return OpCodes.Ldc_I4_2;
+ case Code.Ldc_I4_3 : return OpCodes.Ldc_I4_3;
+ case Code.Ldc_I4_4 : return OpCodes.Ldc_I4_4;
+ case Code.Ldc_I4_5 : return OpCodes.Ldc_I4_5;
+ case Code.Ldc_I4_6 : return OpCodes.Ldc_I4_6;
+ case Code.Ldc_I4_7 : return OpCodes.Ldc_I4_7;
+ case Code.Ldc_I4_8 : return OpCodes.Ldc_I4_8;
+ case Code.Ldc_I4_S : return OpCodes.Ldc_I4_S;
+ case Code.Ldc_I4 : return OpCodes.Ldc_I4;
+ case Code.Ldc_I8 : return OpCodes.Ldc_I8;
+ case Code.Ldc_R4 : return OpCodes.Ldc_R4;
+ case Code.Ldc_R8 : return OpCodes.Ldc_R8;
+ case Code.Dup : return OpCodes.Dup;
+ case Code.Pop : return OpCodes.Pop;
+ case Code.Jmp : return OpCodes.Jmp;
+ case Code.Call : return OpCodes.Call;
+ case Code.Calli : return OpCodes.Calli;
+ case Code.Ret : return OpCodes.Ret;
+ case Code.Br_S : return OpCodes.Br_S;
+ case Code.Brfalse_S : return OpCodes.Brfalse_S;
+ case Code.Brtrue_S : return OpCodes.Brtrue_S;
+ case Code.Beq_S : return OpCodes.Beq_S;
+ case Code.Bge_S : return OpCodes.Bge_S;
+ case Code.Bgt_S : return OpCodes.Bgt_S;
+ case Code.Ble_S : return OpCodes.Ble_S;
+ case Code.Blt_S : return OpCodes.Blt_S;
+ case Code.Bne_Un_S : return OpCodes.Bne_Un_S;
+ case Code.Bge_Un_S : return OpCodes.Bge_Un_S;
+ case Code.Bgt_Un_S : return OpCodes.Bgt_Un_S;
+ case Code.Ble_Un_S : return OpCodes.Ble_Un_S;
+ case Code.Blt_Un_S : return OpCodes.Blt_Un_S;
+ case Code.Br : return OpCodes.Br;
+ case Code.Brfalse : return OpCodes.Brfalse;
+ case Code.Brtrue : return OpCodes.Brtrue;
+ case Code.Beq : return OpCodes.Beq;
+ case Code.Bge : return OpCodes.Bge;
+ case Code.Bgt : return OpCodes.Bgt;
+ case Code.Ble : return OpCodes.Ble;
+ case Code.Blt : return OpCodes.Blt;
+ case Code.Bne_Un : return OpCodes.Bne_Un;
+ case Code.Bge_Un : return OpCodes.Bge_Un;
+ case Code.Bgt_Un : return OpCodes.Bgt_Un;
+ case Code.Ble_Un : return OpCodes.Ble_Un;
+ case Code.Blt_Un : return OpCodes.Blt_Un;
+ case Code.Switch : return OpCodes.Switch;
+ case Code.Ldind_I1 : return OpCodes.Ldind_I1;
+ case Code.Ldind_U1 : return OpCodes.Ldind_U1;
+ case Code.Ldind_I2 : return OpCodes.Ldind_I2;
+ case Code.Ldind_U2 : return OpCodes.Ldind_U2;
+ case Code.Ldind_I4 : return OpCodes.Ldind_I4;
+ case Code.Ldind_U4 : return OpCodes.Ldind_U4;
+ case Code.Ldind_I8 : return OpCodes.Ldind_I8;
+ case Code.Ldind_I : return OpCodes.Ldind_I;
+ case Code.Ldind_R4 : return OpCodes.Ldind_R4;
+ case Code.Ldind_R8 : return OpCodes.Ldind_R8;
+ case Code.Ldind_Ref : return OpCodes.Ldind_Ref;
+ case Code.Stind_Ref : return OpCodes.Stind_Ref;
+ case Code.Stind_I1 : return OpCodes.Stind_I1;
+ case Code.Stind_I2 : return OpCodes.Stind_I2;
+ case Code.Stind_I4 : return OpCodes.Stind_I4;
+ case Code.Stind_I8 : return OpCodes.Stind_I8;
+ case Code.Stind_R4 : return OpCodes.Stind_R4;
+ case Code.Stind_R8 : return OpCodes.Stind_R8;
+ case Code.Add : return OpCodes.Add;
+ case Code.Sub : return OpCodes.Sub;
+ case Code.Mul : return OpCodes.Mul;
+ case Code.Div : return OpCodes.Div;
+ case Code.Div_Un : return OpCodes.Div_Un;
+ case Code.Rem : return OpCodes.Rem;
+ case Code.Rem_Un : return OpCodes.Rem_Un;
+ case Code.And : return OpCodes.And;
+ case Code.Or : return OpCodes.Or;
+ case Code.Xor : return OpCodes.Xor;
+ case Code.Shl : return OpCodes.Shl;
+ case Code.Shr : return OpCodes.Shr;
+ case Code.Shr_Un : return OpCodes.Shr_Un;
+ case Code.Neg : return OpCodes.Neg;
+ case Code.Not : return OpCodes.Not;
+ case Code.Conv_I1 : return OpCodes.Conv_I1;
+ case Code.Conv_I2 : return OpCodes.Conv_I2;
+ case Code.Conv_I4 : return OpCodes.Conv_I4;
+ case Code.Conv_I8 : return OpCodes.Conv_I8;
+ case Code.Conv_R4 : return OpCodes.Conv_R4;
+ case Code.Conv_R8 : return OpCodes.Conv_R8;
+ case Code.Conv_U4 : return OpCodes.Conv_U4;
+ case Code.Conv_U8 : return OpCodes.Conv_U8;
+ case Code.Callvirt : return OpCodes.Callvirt;
+ case Code.Cpobj : return OpCodes.Cpobj;
+ case Code.Ldobj : return OpCodes.Ldobj;
+ case Code.Ldstr : return OpCodes.Ldstr;
+ case Code.Newobj : return OpCodes.Newobj;
+ case Code.Castclass : return OpCodes.Castclass;
+ case Code.Isinst : return OpCodes.Isinst;
+ case Code.Conv_R_Un : return OpCodes.Conv_R_Un;
+ case Code.Unbox : return OpCodes.Unbox;
+ case Code.Throw : return OpCodes.Throw;
+ case Code.Ldfld : return OpCodes.Ldfld;
+ case Code.Ldflda : return OpCodes.Ldflda;
+ case Code.Stfld : return OpCodes.Stfld;
+ case Code.Ldsfld : return OpCodes.Ldsfld;
+ case Code.Ldsflda : return OpCodes.Ldsflda;
+ case Code.Stsfld : return OpCodes.Stsfld;
+ case Code.Stobj : return OpCodes.Stobj;
+ case Code.Conv_Ovf_I1_Un : return OpCodes.Conv_Ovf_I1_Un;
+ case Code.Conv_Ovf_I2_Un : return OpCodes.Conv_Ovf_I2_Un;
+ case Code.Conv_Ovf_I4_Un : return OpCodes.Conv_Ovf_I4_Un;
+ case Code.Conv_Ovf_I8_Un : return OpCodes.Conv_Ovf_I8_Un;
+ case Code.Conv_Ovf_U1_Un : return OpCodes.Conv_Ovf_U1_Un;
+ case Code.Conv_Ovf_U2_Un : return OpCodes.Conv_Ovf_U2_Un;
+ case Code.Conv_Ovf_U4_Un : return OpCodes.Conv_Ovf_U4_Un;
+ case Code.Conv_Ovf_U8_Un : return OpCodes.Conv_Ovf_U8_Un;
+ case Code.Conv_Ovf_I_Un : return OpCodes.Conv_Ovf_I_Un;
+ case Code.Conv_Ovf_U_Un : return OpCodes.Conv_Ovf_U_Un;
+ case Code.Box : return OpCodes.Box;
+ case Code.Newarr : return OpCodes.Newarr;
+ case Code.Ldlen : return OpCodes.Ldlen;
+ case Code.Ldelema : return OpCodes.Ldelema;
+ case Code.Ldelem_I1 : return OpCodes.Ldelem_I1;
+ case Code.Ldelem_U1 : return OpCodes.Ldelem_U1;
+ case Code.Ldelem_I2 : return OpCodes.Ldelem_I2;
+ case Code.Ldelem_U2 : return OpCodes.Ldelem_U2;
+ case Code.Ldelem_I4 : return OpCodes.Ldelem_I4;
+ case Code.Ldelem_U4 : return OpCodes.Ldelem_U4;
+ case Code.Ldelem_I8 : return OpCodes.Ldelem_I8;
+ case Code.Ldelem_I : return OpCodes.Ldelem_I;
+ case Code.Ldelem_R4 : return OpCodes.Ldelem_R4;
+ case Code.Ldelem_R8 : return OpCodes.Ldelem_R8;
+ case Code.Ldelem_Ref : return OpCodes.Ldelem_Ref;
+ case Code.Stelem_I : return OpCodes.Stelem_I;
+ case Code.Stelem_I1 : return OpCodes.Stelem_I1;
+ case Code.Stelem_I2 : return OpCodes.Stelem_I2;
+ case Code.Stelem_I4 : return OpCodes.Stelem_I4;
+ case Code.Stelem_I8 : return OpCodes.Stelem_I8;
+ case Code.Stelem_R4 : return OpCodes.Stelem_R4;
+ case Code.Stelem_R8 : return OpCodes.Stelem_R8;
+ case Code.Stelem_Ref : return OpCodes.Stelem_Ref;
+ case Code.Ldelem_Any : return OpCodes.Ldelem_Any;
+ case Code.Stelem_Any : return OpCodes.Stelem_Any;
+ case Code.Unbox_Any : return OpCodes.Unbox_Any;
+ case Code.Conv_Ovf_I1 : return OpCodes.Conv_Ovf_I1;
+ case Code.Conv_Ovf_U1 : return OpCodes.Conv_Ovf_U1;
+ case Code.Conv_Ovf_I2 : return OpCodes.Conv_Ovf_I2;
+ case Code.Conv_Ovf_U2 : return OpCodes.Conv_Ovf_U2;
+ case Code.Conv_Ovf_I4 : return OpCodes.Conv_Ovf_I4;
+ case Code.Conv_Ovf_U4 : return OpCodes.Conv_Ovf_U4;
+ case Code.Conv_Ovf_I8 : return OpCodes.Conv_Ovf_I8;
+ case Code.Conv_Ovf_U8 : return OpCodes.Conv_Ovf_U8;
+ case Code.Refanyval : return OpCodes.Refanyval;
+ case Code.Ckfinite : return OpCodes.Ckfinite;
+ case Code.Mkrefany : return OpCodes.Mkrefany;
+ case Code.Ldtoken : return OpCodes.Ldtoken;
+ case Code.Conv_U2 : return OpCodes.Conv_U2;
+ case Code.Conv_U1 : return OpCodes.Conv_U1;
+ case Code.Conv_I : return OpCodes.Conv_I;
+ case Code.Conv_Ovf_I : return OpCodes.Conv_Ovf_I;
+ case Code.Conv_Ovf_U : return OpCodes.Conv_Ovf_U;
+ case Code.Add_Ovf : return OpCodes.Add_Ovf;
+ case Code.Add_Ovf_Un : return OpCodes.Add_Ovf_Un;
+ case Code.Mul_Ovf : return OpCodes.Mul_Ovf;
+ case Code.Mul_Ovf_Un : return OpCodes.Mul_Ovf_Un;
+ case Code.Sub_Ovf : return OpCodes.Sub_Ovf;
+ case Code.Sub_Ovf_Un : return OpCodes.Sub_Ovf_Un;
+ case Code.Endfinally : return OpCodes.Endfinally;
+ case Code.Leave : return OpCodes.Leave;
+ case Code.Leave_S : return OpCodes.Leave_S;
+ case Code.Stind_I : return OpCodes.Stind_I;
+ case Code.Conv_U : return OpCodes.Conv_U;
+ case Code.Arglist : return OpCodes.Arglist;
+ case Code.Ceq : return OpCodes.Ceq;
+ case Code.Cgt : return OpCodes.Cgt;
+ case Code.Cgt_Un : return OpCodes.Cgt_Un;
+ case Code.Clt : return OpCodes.Clt;
+ case Code.Clt_Un : return OpCodes.Clt_Un;
+ case Code.Ldftn : return OpCodes.Ldftn;
+ case Code.Ldvirtftn : return OpCodes.Ldvirtftn;
+ case Code.Ldarg : return OpCodes.Ldarg;
+ case Code.Ldarga : return OpCodes.Ldarga;
+ case Code.Starg : return OpCodes.Starg;
+ case Code.Ldloc : return OpCodes.Ldloc;
+ case Code.Ldloca : return OpCodes.Ldloca;
+ case Code.Stloc : return OpCodes.Stloc;
+ case Code.Localloc : return OpCodes.Localloc;
+ case Code.Endfilter : return OpCodes.Endfilter;
+ case Code.Unaligned : return OpCodes.Unaligned;
+ case Code.Volatile : return OpCodes.Volatile;
+ case Code.Tail : return OpCodes.Tail;
+ case Code.Initobj : return OpCodes.Initobj;
+ case Code.Constrained : return OpCodes.Constrained;
+ case Code.Cpblk : return OpCodes.Cpblk;
+ case Code.Initblk : return OpCodes.Initblk;
+ case Code.No : return OpCodes.No;
+ case Code.Rethrow : return OpCodes.Rethrow;
+ case Code.Sizeof : return OpCodes.Sizeof;
+ case Code.Refanytype : return OpCodes.Refanytype;
+ case Code.Readonly : return OpCodes.Readonly;
+ default : return OpCodes.Nop;
+ }
+ }
+ }
+}
--- /dev/null
+//
+// OperandType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal enum OperandType {
+ InlineBrTarget,
+ InlineField,
+ InlineI,
+ InlineI8,
+ InlineMethod,
+ InlineNone,
+ InlinePhi,
+ InlineR,
+ InlineSig,
+ InlineString,
+ InlineSwitch,
+ InlineTok,
+ InlineType,
+ InlineVar,
+ InlineParam,
+ ShortInlineBrTarget,
+ ShortInlineI,
+ ShortInlineR,
+ ShortInlineVar,
+ ShortInlineParam
+ }
+}
--- /dev/null
+//
+// Scope.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal class Scope : IScopeProvider, IVariableDefinitionProvider, ICodeVisitable {
+
+ Instruction m_start;
+ Instruction m_end;
+
+ Scope m_parent;
+ ScopeCollection m_scopes;
+
+ VariableDefinitionCollection m_variables;
+
+ public Instruction Start {
+ get { return m_start; }
+ set { m_start = value; }
+ }
+
+ public Instruction End {
+ get { return m_end; }
+ set { m_end = value; }
+ }
+
+ public Scope Parent {
+ get { return m_parent; }
+ set { m_parent = value; }
+ }
+
+ public ScopeCollection Scopes {
+ get {
+ if (m_scopes == null)
+ m_scopes = new ScopeCollection (this);
+
+ return m_scopes;
+ }
+ }
+
+ public VariableDefinitionCollection Variables {
+ get {
+ if (m_variables == null)
+ m_variables = new VariableDefinitionCollection (this);
+
+ return m_variables;
+ }
+ }
+
+ public void Accept (ICodeVisitor visitor)
+ {
+ visitor.VisitScope (this);
+ }
+ }
+}
--- /dev/null
+//
+// ScopeCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:54 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class ScopeCollection : CollectionBase, ICodeVisitable {
+
+ IScopeProvider m_container;
+
+ public Scope this [int index] {
+ get { return List [index] as Scope; }
+ set { List [index] = value; }
+ }
+
+ public IScopeProvider Container {
+ get { return m_container; }
+ }
+
+ public ScopeCollection (IScopeProvider container)
+ {
+ m_container = container;
+ }
+
+ public void Add (Scope value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (Scope value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (Scope value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, Scope value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (Scope value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is Scope))
+ throw new ArgumentException ("Must be of type " + typeof (Scope).FullName);
+ }
+
+ public void Accept (ICodeVisitor visitor)
+ {
+ visitor.VisitScopeCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// SequencePoint.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal class SequencePoint {
+
+ Document m_document;
+
+ int m_startLine;
+ int m_startColumn;
+ int m_endLine;
+ int m_endColumn;
+
+ public int StartLine {
+ get { return m_startLine; }
+ set { m_startLine = value; }
+ }
+
+ public int StartColumn {
+ get { return m_startColumn; }
+ set { m_startColumn = value; }
+ }
+
+ public int EndLine {
+ get { return m_endLine; }
+ set { m_endLine = value; }
+ }
+
+ public int EndColumn {
+ get { return m_endColumn; }
+ set { m_endColumn = value; }
+ }
+
+ public Document Document {
+ get { return m_document; }
+ set { m_document = value; }
+ }
+
+ public SequencePoint (Document document)
+ {
+ m_document = document;
+ }
+
+ public SequencePoint (Document doc, int startLine, int startCol, int endLine, int endCol) : this (doc)
+ {
+ m_startLine = startLine;
+ m_startColumn = startCol;
+ m_endLine = endLine;
+ m_endColumn = endCol;
+ }
+ }
+}
--- /dev/null
+//
+// StackBehaviour.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal enum StackBehaviour {
+ Pop0,
+ Pop1,
+ Pop1_pop1,
+ Popi,
+ Popi_pop1,
+ Popi_popi,
+ Popi_popi8,
+ Popi_popi_popi,
+ Popi_popr4,
+ Popi_popr8,
+ Popref,
+ Popref_pop1,
+ Popref_popi,
+ Popref_popi_popi,
+ Popref_popi_popi8,
+ Popref_popi_popr4,
+ Popref_popi_popr8,
+ Popref_popi_popref,
+ PopAll,
+ Push0,
+ Push1,
+ Push1_push1,
+ Pushi,
+ Pushi8,
+ Pushr4,
+ Pushr8,
+ Pushref,
+ Varpop,
+ Varpush
+ }
+}
--- /dev/null
+//
+// SymbolStoreHelper.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+ using SR = System.Reflection;
+
+ sealed class SymbolStoreHelper {
+
+ static ISymbolStoreFactory s_factory;
+
+ SymbolStoreHelper ()
+ {
+ }
+
+ public static ISymbolReader GetReader (ModuleDefinition module)
+ {
+ InitFactory ();
+
+ return s_factory.CreateReader (module, module.Image.FileInformation.FullName);
+ }
+
+ public static ISymbolWriter GetWriter (ModuleDefinition module, string assemblyFileName)
+ {
+ InitFactory ();
+
+ return s_factory.CreateWriter (module, assemblyFileName);
+ }
+
+ static void InitFactory ()
+ {
+ if (s_factory != null)
+ return;
+
+ string assembly_name;
+ string type_name = GetSymbolSupportType (out assembly_name);
+
+ Type factoryType = Type.GetType (type_name + ", " + assembly_name, false);
+ if (factoryType == null) {
+ try {
+ SR.Assembly assembly = SR.Assembly.LoadWithPartialName (assembly_name);
+ factoryType = assembly.GetType (type_name);
+ } catch {}
+ }
+
+ if (factoryType == null)
+ throw new NotSupportedException ();
+
+ s_factory = (ISymbolStoreFactory) Activator.CreateInstance (factoryType);
+ }
+
+ static string GetSymbolSupportType (out string assembly)
+ {
+ string kind = GetSymbolKind ();
+ assembly = "Mono.Cecil." + kind;
+ return string.Format (assembly + "." + kind + "Factory");
+ }
+
+ static string GetSymbolKind ()
+ {
+ return OnMono () ? "Mdb" : "Pdb";
+ }
+
+ static bool OnMono ()
+ {
+ return Type.GetType ("Mono.Runtime") != null;
+ }
+ }
+}
--- /dev/null
+//
+// VariableDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal sealed class VariableDefinition : VariableReference {
+
+ MethodDefinition m_method;
+
+ public MethodDefinition Method {
+ get { return m_method; }
+ set { m_method = value; }
+ }
+
+ public VariableDefinition (TypeReference variableType) : base (variableType)
+ {
+ }
+
+ public VariableDefinition (string name, int index, MethodDefinition method, TypeReference variableType) :
+ base (name, index, variableType)
+ {
+ m_method = method;
+ }
+
+ public override VariableDefinition Resolve ()
+ {
+ return this;
+ }
+
+ public override void Accept (ICodeVisitor visitor)
+ {
+ visitor.VisitVariableDefinition (this);
+ }
+ }
+}
--- /dev/null
+//
+// VariableDefinitionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:53 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class VariableDefinitionCollection : CollectionBase, ICodeVisitable {
+
+ IVariableDefinitionProvider m_container;
+
+ public VariableDefinition this [int index] {
+ get { return List [index] as VariableDefinition; }
+ set { List [index] = value; }
+ }
+
+ public IVariableDefinitionProvider Container {
+ get { return m_container; }
+ }
+
+ public VariableDefinitionCollection (IVariableDefinitionProvider container)
+ {
+ m_container = container;
+ }
+
+ public void Add (VariableDefinition value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (VariableDefinition value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (VariableDefinition value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, VariableDefinition value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (VariableDefinition value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is VariableDefinition))
+ throw new ArgumentException ("Must be of type " + typeof (VariableDefinition).FullName);
+ }
+
+ public void Accept (ICodeVisitor visitor)
+ {
+ visitor.VisitVariableDefinitionCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// VariableReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Cil {
+
+ internal abstract class VariableReference : ICodeVisitable {
+
+ string m_name;
+ int m_index;
+ TypeReference m_variableType;
+
+ public string Name {
+ get { return m_name; }
+ set { m_name = value; }
+ }
+
+ public int Index {
+ get { return m_index; }
+ set { m_index = value; }
+ }
+
+ public TypeReference VariableType {
+ get { return m_variableType; }
+ set { m_variableType = value; }
+ }
+
+ public VariableReference (TypeReference variableType)
+ {
+ m_variableType = variableType;
+ }
+
+ public VariableReference (string name, int index, TypeReference variableType) : this (variableType)
+ {
+ m_name = name;
+ m_index = index;
+ }
+
+ public abstract VariableDefinition Resolve ();
+
+ public override string ToString ()
+ {
+ if (m_name != null && m_name.Length > 0)
+ return m_name;
+
+ return string.Concat ("V_", m_index);
+ }
+
+ public abstract void Accept (ICodeVisitor visitor);
+ }
+}
--- /dev/null
+//
+// AssemblyTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:25 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class AssemblyTable : IMetadataTable {
+
+ public const int RId = 0x20;
+
+ RowCollection m_rows;
+
+ public AssemblyRow this [int index] {
+ get { return m_rows [index] as AssemblyRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal AssemblyTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitAssemblyTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class AssemblyRow : IMetadataRow {
+
+ public AssemblyHashAlgorithm HashAlgId;
+ public ushort MajorVersion;
+ public ushort MinorVersion;
+ public ushort BuildNumber;
+ public ushort RevisionNumber;
+ public AssemblyFlags Flags;
+ public uint PublicKey;
+ public uint Name;
+ public uint Culture;
+
+ internal AssemblyRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitAssemblyRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyOSTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:25 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class AssemblyOSTable : IMetadataTable {
+
+ public const int RId = 0x22;
+
+ RowCollection m_rows;
+
+ public AssemblyOSRow this [int index] {
+ get { return m_rows [index] as AssemblyOSRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal AssemblyOSTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitAssemblyOSTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class AssemblyOSRow : IMetadataRow {
+
+ public uint OSPlatformID;
+ public uint OSMajorVersion;
+ public uint OSMinorVersion;
+
+ internal AssemblyOSRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitAssemblyOSRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyProcessorTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:25 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class AssemblyProcessorTable : IMetadataTable {
+
+ public const int RId = 0x21;
+
+ RowCollection m_rows;
+
+ public AssemblyProcessorRow this [int index] {
+ get { return m_rows [index] as AssemblyProcessorRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal AssemblyProcessorTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitAssemblyProcessorTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class AssemblyProcessorRow : IMetadataRow {
+
+ public uint Processor;
+
+ internal AssemblyProcessorRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitAssemblyProcessorRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyRefTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:25 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class AssemblyRefTable : IMetadataTable {
+
+ public const int RId = 0x23;
+
+ RowCollection m_rows;
+
+ public AssemblyRefRow this [int index] {
+ get { return m_rows [index] as AssemblyRefRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal AssemblyRefTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitAssemblyRefTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class AssemblyRefRow : IMetadataRow {
+
+ public ushort MajorVersion;
+ public ushort MinorVersion;
+ public ushort BuildNumber;
+ public ushort RevisionNumber;
+ public AssemblyFlags Flags;
+ public uint PublicKeyOrToken;
+ public uint Name;
+ public uint Culture;
+ public uint HashValue;
+
+ internal AssemblyRefRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitAssemblyRefRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyRefOSTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:25 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class AssemblyRefOSTable : IMetadataTable {
+
+ public const int RId = 0x25;
+
+ RowCollection m_rows;
+
+ public AssemblyRefOSRow this [int index] {
+ get { return m_rows [index] as AssemblyRefOSRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal AssemblyRefOSTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitAssemblyRefOSTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class AssemblyRefOSRow : IMetadataRow {
+
+ public uint OSPlatformID;
+ public uint OSMajorVersion;
+ public uint OSMinorVersion;
+ public uint AssemblyRef;
+
+ internal AssemblyRefOSRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitAssemblyRefOSRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyRefProcessorTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:25 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class AssemblyRefProcessorTable : IMetadataTable {
+
+ public const int RId = 0x24;
+
+ RowCollection m_rows;
+
+ public AssemblyRefProcessorRow this [int index] {
+ get { return m_rows [index] as AssemblyRefProcessorRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal AssemblyRefProcessorTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitAssemblyRefProcessorTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class AssemblyRefProcessorRow : IMetadataRow {
+
+ public uint Processor;
+ public uint AssemblyRef;
+
+ internal AssemblyRefProcessorRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitAssemblyRefProcessorRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// BaseMetadataVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Thu Feb 22 14:39:38 CET 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal abstract class BaseMetadataVisitor : IMetadataVisitor {
+
+ public virtual void VisitMetadataRoot (MetadataRoot root)
+ {
+ }
+
+ public virtual void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header)
+ {
+ }
+
+ public virtual void VisitMetadataStreamCollection (MetadataStreamCollection streams)
+ {
+ }
+
+ public virtual void VisitMetadataStream (MetadataStream stream)
+ {
+ }
+
+ public virtual void VisitMetadataStreamHeader (MetadataStream.MetadataStreamHeader header)
+ {
+ }
+
+ public virtual void VisitGuidHeap (GuidHeap heap)
+ {
+ }
+
+ public virtual void VisitStringsHeap (StringsHeap heap)
+ {
+ }
+
+ public virtual void VisitTablesHeap (TablesHeap heap)
+ {
+ }
+
+ public virtual void VisitBlobHeap (BlobHeap heap)
+ {
+ }
+
+ public virtual void VisitUserStringsHeap (UserStringsHeap heap)
+ {
+ }
+
+ public virtual void TerminateMetadataRoot (MetadataRoot root)
+ {
+ }
+ }
+
+ internal abstract class BaseMetadataTableVisitor : IMetadataTableVisitor {
+
+ public virtual void VisitTableCollection (TableCollection coll)
+ {
+ }
+
+ public virtual void VisitAssemblyTable (AssemblyTable table)
+ {
+ }
+
+ public virtual void VisitAssemblyOSTable (AssemblyOSTable table)
+ {
+ }
+
+ public virtual void VisitAssemblyProcessorTable (AssemblyProcessorTable table)
+ {
+ }
+
+ public virtual void VisitAssemblyRefTable (AssemblyRefTable table)
+ {
+ }
+
+ public virtual void VisitAssemblyRefOSTable (AssemblyRefOSTable table)
+ {
+ }
+
+ public virtual void VisitAssemblyRefProcessorTable (AssemblyRefProcessorTable table)
+ {
+ }
+
+ public virtual void VisitClassLayoutTable (ClassLayoutTable table)
+ {
+ }
+
+ public virtual void VisitConstantTable (ConstantTable table)
+ {
+ }
+
+ public virtual void VisitCustomAttributeTable (CustomAttributeTable table)
+ {
+ }
+
+ public virtual void VisitDeclSecurityTable (DeclSecurityTable table)
+ {
+ }
+
+ public virtual void VisitEventTable (EventTable table)
+ {
+ }
+
+ public virtual void VisitEventMapTable (EventMapTable table)
+ {
+ }
+
+ public virtual void VisitEventPtrTable (EventPtrTable table)
+ {
+ }
+
+ public virtual void VisitExportedTypeTable (ExportedTypeTable table)
+ {
+ }
+
+ public virtual void VisitFieldTable (FieldTable table)
+ {
+ }
+
+ public virtual void VisitFieldLayoutTable (FieldLayoutTable table)
+ {
+ }
+
+ public virtual void VisitFieldMarshalTable (FieldMarshalTable table)
+ {
+ }
+
+ public virtual void VisitFieldPtrTable (FieldPtrTable table)
+ {
+ }
+
+ public virtual void VisitFieldRVATable (FieldRVATable table)
+ {
+ }
+
+ public virtual void VisitFileTable (FileTable table)
+ {
+ }
+
+ public virtual void VisitGenericParamTable (GenericParamTable table)
+ {
+ }
+
+ public virtual void VisitGenericParamConstraintTable (GenericParamConstraintTable table)
+ {
+ }
+
+ public virtual void VisitImplMapTable (ImplMapTable table)
+ {
+ }
+
+ public virtual void VisitInterfaceImplTable (InterfaceImplTable table)
+ {
+ }
+
+ public virtual void VisitManifestResourceTable (ManifestResourceTable table)
+ {
+ }
+
+ public virtual void VisitMemberRefTable (MemberRefTable table)
+ {
+ }
+
+ public virtual void VisitMethodTable (MethodTable table)
+ {
+ }
+
+ public virtual void VisitMethodImplTable (MethodImplTable table)
+ {
+ }
+
+ public virtual void VisitMethodPtrTable (MethodPtrTable table)
+ {
+ }
+
+ public virtual void VisitMethodSemanticsTable (MethodSemanticsTable table)
+ {
+ }
+
+ public virtual void VisitMethodSpecTable (MethodSpecTable table)
+ {
+ }
+
+ public virtual void VisitModuleTable (ModuleTable table)
+ {
+ }
+
+ public virtual void VisitModuleRefTable (ModuleRefTable table)
+ {
+ }
+
+ public virtual void VisitNestedClassTable (NestedClassTable table)
+ {
+ }
+
+ public virtual void VisitParamTable (ParamTable table)
+ {
+ }
+
+ public virtual void VisitParamPtrTable (ParamPtrTable table)
+ {
+ }
+
+ public virtual void VisitPropertyTable (PropertyTable table)
+ {
+ }
+
+ public virtual void VisitPropertyMapTable (PropertyMapTable table)
+ {
+ }
+
+ public virtual void VisitPropertyPtrTable (PropertyPtrTable table)
+ {
+ }
+
+ public virtual void VisitStandAloneSigTable (StandAloneSigTable table)
+ {
+ }
+
+ public virtual void VisitTypeDefTable (TypeDefTable table)
+ {
+ }
+
+ public virtual void VisitTypeRefTable (TypeRefTable table)
+ {
+ }
+
+ public virtual void VisitTypeSpecTable (TypeSpecTable table)
+ {
+ }
+
+ public virtual void TerminateTableCollection (TableCollection coll)
+ {
+ }
+
+ public abstract IMetadataRowVisitor GetRowVisitor();
+ }
+
+ internal abstract class BaseMetadataRowVisitor : IMetadataRowVisitor {
+
+ public virtual void VisitRowCollection (RowCollection coll)
+ {
+ }
+
+ public virtual void VisitAssemblyRow (AssemblyRow row)
+ {
+ }
+
+ public virtual void VisitAssemblyOSRow (AssemblyOSRow row)
+ {
+ }
+
+ public virtual void VisitAssemblyProcessorRow (AssemblyProcessorRow row)
+ {
+ }
+
+ public virtual void VisitAssemblyRefRow (AssemblyRefRow row)
+ {
+ }
+
+ public virtual void VisitAssemblyRefOSRow (AssemblyRefOSRow row)
+ {
+ }
+
+ public virtual void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row)
+ {
+ }
+
+ public virtual void VisitClassLayoutRow (ClassLayoutRow row)
+ {
+ }
+
+ public virtual void VisitConstantRow (ConstantRow row)
+ {
+ }
+
+ public virtual void VisitCustomAttributeRow (CustomAttributeRow row)
+ {
+ }
+
+ public virtual void VisitDeclSecurityRow (DeclSecurityRow row)
+ {
+ }
+
+ public virtual void VisitEventRow (EventRow row)
+ {
+ }
+
+ public virtual void VisitEventMapRow (EventMapRow row)
+ {
+ }
+
+ public virtual void VisitEventPtrRow (EventPtrRow row)
+ {
+ }
+
+ public virtual void VisitExportedTypeRow (ExportedTypeRow row)
+ {
+ }
+
+ public virtual void VisitFieldRow (FieldRow row)
+ {
+ }
+
+ public virtual void VisitFieldLayoutRow (FieldLayoutRow row)
+ {
+ }
+
+ public virtual void VisitFieldMarshalRow (FieldMarshalRow row)
+ {
+ }
+
+ public virtual void VisitFieldPtrRow (FieldPtrRow row)
+ {
+ }
+
+ public virtual void VisitFieldRVARow (FieldRVARow row)
+ {
+ }
+
+ public virtual void VisitFileRow (FileRow row)
+ {
+ }
+
+ public virtual void VisitGenericParamRow (GenericParamRow row)
+ {
+ }
+
+ public virtual void VisitGenericParamConstraintRow (GenericParamConstraintRow row)
+ {
+ }
+
+ public virtual void VisitImplMapRow (ImplMapRow row)
+ {
+ }
+
+ public virtual void VisitInterfaceImplRow (InterfaceImplRow row)
+ {
+ }
+
+ public virtual void VisitManifestResourceRow (ManifestResourceRow row)
+ {
+ }
+
+ public virtual void VisitMemberRefRow (MemberRefRow row)
+ {
+ }
+
+ public virtual void VisitMethodRow (MethodRow row)
+ {
+ }
+
+ public virtual void VisitMethodImplRow (MethodImplRow row)
+ {
+ }
+
+ public virtual void VisitMethodPtrRow (MethodPtrRow row)
+ {
+ }
+
+ public virtual void VisitMethodSemanticsRow (MethodSemanticsRow row)
+ {
+ }
+
+ public virtual void VisitMethodSpecRow (MethodSpecRow row)
+ {
+ }
+
+ public virtual void VisitModuleRow (ModuleRow row)
+ {
+ }
+
+ public virtual void VisitModuleRefRow (ModuleRefRow row)
+ {
+ }
+
+ public virtual void VisitNestedClassRow (NestedClassRow row)
+ {
+ }
+
+ public virtual void VisitParamRow (ParamRow row)
+ {
+ }
+
+ public virtual void VisitParamPtrRow (ParamPtrRow row)
+ {
+ }
+
+ public virtual void VisitPropertyRow (PropertyRow row)
+ {
+ }
+
+ public virtual void VisitPropertyMapRow (PropertyMapRow row)
+ {
+ }
+
+ public virtual void VisitPropertyPtrRow (PropertyPtrRow row)
+ {
+ }
+
+ public virtual void VisitStandAloneSigRow (StandAloneSigRow row)
+ {
+ }
+
+ public virtual void VisitTypeDefRow (TypeDefRow row)
+ {
+ }
+
+ public virtual void VisitTypeRefRow (TypeRefRow row)
+ {
+ }
+
+ public virtual void VisitTypeSpecRow (TypeSpecRow row)
+ {
+ }
+
+ public virtual void TerminateRowCollection (RowCollection coll)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// BlobHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+ using System.IO;
+
+ internal class BlobHeap : MetadataHeap {
+
+ internal BlobHeap (MetadataStream stream) : base (stream, MetadataStream.Blob)
+ {
+ }
+
+ public byte [] Read (uint index)
+ {
+ return ReadBytesFromStream (index);
+ }
+
+ public BinaryReader GetReader (uint index)
+ {
+ return new BinaryReader (new MemoryStream (Read (index)));
+ }
+
+ public override void Accept (IMetadataVisitor visitor)
+ {
+ visitor.VisitBlobHeap (this);
+ }
+ }
+
+ class ByteArrayEqualityComparer : IHashCodeProvider, IComparer {
+
+ public static readonly ByteArrayEqualityComparer Instance = new ByteArrayEqualityComparer ();
+
+ public int GetHashCode (object obj)
+ {
+ byte [] array = (byte []) obj;
+
+ int hash = 0;
+ for (int i = 0; i < array.Length; i++)
+ hash = (hash * 37) ^ array [i];
+
+ return hash;
+ }
+
+ public int Compare (object a, object b)
+ {
+ byte [] x = (byte []) a;
+ byte [] y = (byte []) b;
+
+ if (x == null || y == null)
+ return x == y ? 0 : 1;
+
+ if (x.Length != y.Length)
+ return 1;
+
+ for (int i = 0; i < x.Length; i++)
+ if (x [i] != y [i])
+ return 1;
+
+ return 0;
+ }
+ }
+}
--- /dev/null
+//
+// ClassLayoutTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:25 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class ClassLayoutTable : IMetadataTable {
+
+ public const int RId = 0x0f;
+
+ RowCollection m_rows;
+
+ public ClassLayoutRow this [int index] {
+ get { return m_rows [index] as ClassLayoutRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal ClassLayoutTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitClassLayoutTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class ClassLayoutRow : IMetadataRow {
+
+ public ushort PackingSize;
+ public uint ClassSize;
+ public uint Parent;
+
+ internal ClassLayoutRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitClassLayoutRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// CodedIndex.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Mar 20 16:02:16 +0100 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal enum CodedIndex {
+ TypeDefOrRef,
+ HasConstant,
+ HasCustomAttribute,
+ HasFieldMarshal,
+ HasDeclSecurity,
+ MemberRefParent,
+ HasSemantics,
+ MethodDefOrRef,
+ MemberForwarded,
+ Implementation,
+ CustomAttributeType,
+ ResolutionScope,
+ TypeOrMethodDef
+ }
+}
--- /dev/null
+//
+// ConstantTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:25 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class ConstantTable : IMetadataTable {
+
+ public const int RId = 0x0b;
+
+ RowCollection m_rows;
+
+ public ConstantRow this [int index] {
+ get { return m_rows [index] as ConstantRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal ConstantTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitConstantTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class ConstantRow : IMetadataRow {
+
+ public ElementType Type;
+ public MetadataToken Parent;
+ public uint Value;
+
+ internal ConstantRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitConstantRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// CultureUtils.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+ using System.Globalization;
+
+ sealed class CultureUtils {
+
+ static IDictionary m_cultures;
+
+ CultureUtils ()
+ {
+ }
+
+ static void LoadCultures ()
+ {
+ if (m_cultures != null)
+ return;
+
+#if CF_1_0 || CF_2_0
+ CultureInfo [] cultures = new CultureInfo [0];
+#else
+ CultureInfo [] cultures = CultureInfo.GetCultures (CultureTypes.AllCultures);
+#endif
+ m_cultures = new Hashtable (cultures.Length + 2);
+
+ foreach (CultureInfo ci in cultures)
+ if (!m_cultures.Contains (ci.Name))
+ m_cultures.Add (ci.Name, ci);
+
+ if (!m_cultures.Contains (string.Empty))
+ m_cultures.Add (string.Empty, CultureInfo.InvariantCulture);
+
+ m_cultures.Add ("neutral", CultureInfo.InvariantCulture);
+ }
+
+ public static bool IsValid (string culture)
+ {
+ if (culture == null)
+ throw new ArgumentNullException ("culture");
+
+ LoadCultures ();
+
+ return m_cultures.Contains (culture);
+ }
+
+ public static CultureInfo GetCultureInfo (string culture)
+ {
+ if (IsValid (culture))
+ return m_cultures [culture] as CultureInfo;
+
+ return CultureInfo.InvariantCulture;
+ }
+ }
+}
--- /dev/null
+//
+// CustomAttributeTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:25 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class CustomAttributeTable : IMetadataTable {
+
+ public const int RId = 0x0c;
+
+ RowCollection m_rows;
+
+ public CustomAttributeRow this [int index] {
+ get { return m_rows [index] as CustomAttributeRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal CustomAttributeTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitCustomAttributeTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class CustomAttributeRow : IMetadataRow {
+
+ public MetadataToken Parent;
+ public MetadataToken Type;
+ public uint Value;
+
+ internal CustomAttributeRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitCustomAttributeRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// DeclSecurityTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class DeclSecurityTable : IMetadataTable {
+
+ public const int RId = 0x0e;
+
+ RowCollection m_rows;
+
+ public DeclSecurityRow this [int index] {
+ get { return m_rows [index] as DeclSecurityRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal DeclSecurityTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitDeclSecurityTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class DeclSecurityRow : IMetadataRow {
+
+ public SecurityAction Action;
+ public MetadataToken Parent;
+ public uint PermissionSet;
+
+ internal DeclSecurityRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitDeclSecurityRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// ElementType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal enum ElementType {
+ End = 0x00, // Marks end of a list
+ Void = 0x01,
+ Boolean = 0x02,
+ Char = 0x03,
+ I1 = 0x04,
+ U1 = 0x05,
+ I2 = 0x06,
+ U2 = 0x07,
+ I4 = 0x08,
+ U4 = 0x09,
+ I8 = 0x0a,
+ U8 = 0x0b,
+ R4 = 0x0c,
+ R8 = 0x0d,
+ String = 0x0e,
+ Ptr = 0x0f, // Followed by <type> token
+ ByRef = 0x10, // Followed by <type> token
+ ValueType = 0x11, // Followed by <type> token
+ Class = 0x12, // Followed by <type> token
+ Var = 0x13, // Followed by generic parameter number
+ Array = 0x14, // <type> <rank> <boundsCount> <bound1> <loCount> <lo1>
+ GenericInst = 0x15, // <type> <type-arg-count> <type-1> ... <type-n> */
+ TypedByRef = 0x16,
+ I = 0x18, // System.IntPtr
+ U = 0x19, // System.UIntPtr
+ FnPtr = 0x1b, // Followed by full method signature
+ Object = 0x1c, // System.Object
+ SzArray = 0x1d, // Single-dim array with 0 lower bound
+ MVar = 0x1e, // Followed by generic parameter number
+ CModReqD = 0x1f, // Required modifier : followed by a TypeDef or TypeRef token
+ CModOpt = 0x20, // Optional modifier : followed by a TypeDef or TypeRef token
+ Internal = 0x21, // Implemented within the CLI
+ Modifier = 0x40, // Or'd with following element types
+ Sentinel = 0x41, // Sentinel for varargs method signature
+ Pinned = 0x45, // Denotes a local variable that points at a pinned object
+
+ // special undocumented constants
+ Type = 0x50,
+ Boxed = 0x51,
+ Enum = 0x55
+ }
+}
--- /dev/null
+//
+// EventTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class EventTable : IMetadataTable {
+
+ public const int RId = 0x14;
+
+ RowCollection m_rows;
+
+ public EventRow this [int index] {
+ get { return m_rows [index] as EventRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal EventTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitEventTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class EventRow : IMetadataRow {
+
+ public EventAttributes EventFlags;
+ public uint Name;
+ public MetadataToken EventType;
+
+ internal EventRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitEventRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// EventMapTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class EventMapTable : IMetadataTable {
+
+ public const int RId = 0x12;
+
+ RowCollection m_rows;
+
+ public EventMapRow this [int index] {
+ get { return m_rows [index] as EventMapRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal EventMapTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitEventMapTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class EventMapRow : IMetadataRow {
+
+ public uint Parent;
+ public uint EventList;
+
+ internal EventMapRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitEventMapRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// EventPtrTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Thu Feb 22 14:39:38 CET 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class EventPtrTable : IMetadataTable {
+
+ public const int RId = 0x13;
+
+ RowCollection m_rows;
+
+ public EventPtrRow this [int index] {
+ get { return m_rows [index] as EventPtrRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal EventPtrTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitEventPtrTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class EventPtrRow : IMetadataRow {
+
+ public uint Event;
+
+ internal EventPtrRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitEventPtrRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// ExportedTypeTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class ExportedTypeTable : IMetadataTable {
+
+ public const int RId = 0x27;
+
+ RowCollection m_rows;
+
+ public ExportedTypeRow this [int index] {
+ get { return m_rows [index] as ExportedTypeRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal ExportedTypeTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitExportedTypeTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class ExportedTypeRow : IMetadataRow {
+
+ public TypeAttributes Flags;
+ public uint TypeDefId;
+ public uint TypeName;
+ public uint TypeNamespace;
+ public MetadataToken Implementation;
+
+ internal ExportedTypeRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitExportedTypeRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// FieldTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class FieldTable : IMetadataTable {
+
+ public const int RId = 0x04;
+
+ RowCollection m_rows;
+
+ public FieldRow this [int index] {
+ get { return m_rows [index] as FieldRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal FieldTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitFieldTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class FieldRow : IMetadataRow {
+
+ public FieldAttributes Flags;
+ public uint Name;
+ public uint Signature;
+
+ internal FieldRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitFieldRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// FieldLayoutTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class FieldLayoutTable : IMetadataTable {
+
+ public const int RId = 0x10;
+
+ RowCollection m_rows;
+
+ public FieldLayoutRow this [int index] {
+ get { return m_rows [index] as FieldLayoutRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal FieldLayoutTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitFieldLayoutTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class FieldLayoutRow : IMetadataRow {
+
+ public uint Offset;
+ public uint Field;
+
+ internal FieldLayoutRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitFieldLayoutRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// FieldMarshalTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class FieldMarshalTable : IMetadataTable {
+
+ public const int RId = 0x0d;
+
+ RowCollection m_rows;
+
+ public FieldMarshalRow this [int index] {
+ get { return m_rows [index] as FieldMarshalRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal FieldMarshalTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitFieldMarshalTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class FieldMarshalRow : IMetadataRow {
+
+ public MetadataToken Parent;
+ public uint NativeType;
+
+ internal FieldMarshalRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitFieldMarshalRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// FieldPtrTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Thu Feb 22 14:39:38 CET 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class FieldPtrTable : IMetadataTable {
+
+ public const int RId = 0x03;
+
+ RowCollection m_rows;
+
+ public FieldPtrRow this [int index] {
+ get { return m_rows [index] as FieldPtrRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal FieldPtrTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitFieldPtrTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class FieldPtrRow : IMetadataRow {
+
+ public uint Field;
+
+ internal FieldPtrRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitFieldPtrRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// FieldRVATable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil.Binary;
+
+ internal sealed class FieldRVATable : IMetadataTable {
+
+ public const int RId = 0x1d;
+
+ RowCollection m_rows;
+
+ public FieldRVARow this [int index] {
+ get { return m_rows [index] as FieldRVARow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal FieldRVATable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitFieldRVATable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class FieldRVARow : IMetadataRow {
+
+ public RVA RVA;
+ public uint Field;
+
+ internal FieldRVARow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitFieldRVARow (this);
+ }
+ }
+}
--- /dev/null
+//
+// FileTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class FileTable : IMetadataTable {
+
+ public const int RId = 0x26;
+
+ RowCollection m_rows;
+
+ public FileRow this [int index] {
+ get { return m_rows [index] as FileRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal FileTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitFileTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class FileRow : IMetadataRow {
+
+ public FileAttributes Flags;
+ public uint Name;
+ public uint HashValue;
+
+ internal FileRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitFileRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// GenericParamTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class GenericParamTable : IMetadataTable {
+
+ public const int RId = 0x2a;
+
+ RowCollection m_rows;
+
+ public GenericParamRow this [int index] {
+ get { return m_rows [index] as GenericParamRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal GenericParamTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitGenericParamTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class GenericParamRow : IMetadataRow {
+
+ public ushort Number;
+ public GenericParameterAttributes Flags;
+ public MetadataToken Owner;
+ public uint Name;
+
+ internal GenericParamRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitGenericParamRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// GenericParamConstraintTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class GenericParamConstraintTable : IMetadataTable {
+
+ public const int RId = 0x2c;
+
+ RowCollection m_rows;
+
+ public GenericParamConstraintRow this [int index] {
+ get { return m_rows [index] as GenericParamConstraintRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal GenericParamConstraintTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitGenericParamConstraintTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class GenericParamConstraintRow : IMetadataRow {
+
+ public uint Owner;
+ public MetadataToken Constraint;
+
+ internal GenericParamConstraintRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitGenericParamConstraintRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// GuidHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+
+ internal class GuidHeap : MetadataHeap {
+
+ readonly IDictionary m_guids;
+
+ public IDictionary Guids {
+ get { return m_guids; }
+ }
+
+ public GuidHeap (MetadataStream stream) : base (stream, MetadataStream.GUID)
+ {
+ int capacity = (int)(stream.Header.Size / 16);
+ m_guids = new Hashtable (capacity);
+ }
+
+ public Guid this [uint index] {
+ get {
+ if (index == 0)
+ return new Guid (new byte [16]);
+
+ int idx = (int) index - 1;
+
+ if (m_guids.Contains (idx))
+ return (Guid) m_guids [idx];
+
+ if (idx + 16 > this.Data.Length)
+ throw new IndexOutOfRangeException ();
+
+ byte [] buffer = null;
+ if (this.Data.Length == 16) {
+ buffer = this.Data;
+ } else {
+ buffer = new byte [16];
+ Buffer.BlockCopy (this.Data, idx, buffer, 0, 16);
+ }
+ Guid res = new Guid (buffer);
+ m_guids [idx] = res;
+ return res;
+ }
+ set { m_guids [index] = value; }
+ }
+
+ public override void Accept (IMetadataVisitor visitor)
+ {
+ visitor.VisitGuidHeap (this);
+ }
+ }
+}
--- /dev/null
+//
+// IMetadataRow.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal interface IMetadataRow : IMetadataRowVisitable {
+ }
+}
--- /dev/null
+//
+// IMetadataTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal interface IMetadataTable : IMetadataTableVisitable {
+ int Id { get; }
+ RowCollection Rows { get; set; }
+ }
+}
--- /dev/null
+//
+// IMetadataVisitable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal interface IMetadataVisitable {
+ void Accept (IMetadataVisitor visitor);
+ }
+
+ internal interface IMetadataTableVisitable {
+ void Accept (IMetadataTableVisitor visitor);
+ }
+
+ internal interface IMetadataRowVisitable {
+ void Accept (IMetadataRowVisitor visitor);
+ }
+}
--- /dev/null
+//
+// IMetadataVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Thu Feb 22 14:39:38 CET 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal interface IMetadataVisitor {
+ void VisitMetadataRoot (MetadataRoot root);
+ void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header);
+ void VisitMetadataStreamCollection (MetadataStreamCollection streams);
+ void VisitMetadataStream (MetadataStream stream);
+ void VisitMetadataStreamHeader (MetadataStream.MetadataStreamHeader header);
+ void VisitGuidHeap (GuidHeap heap);
+ void VisitStringsHeap (StringsHeap heap);
+ void VisitTablesHeap (TablesHeap heap);
+ void VisitBlobHeap (BlobHeap heap);
+ void VisitUserStringsHeap (UserStringsHeap heap);
+
+ void TerminateMetadataRoot (MetadataRoot root);
+ }
+
+ internal interface IMetadataTableVisitor {
+ void VisitTableCollection (TableCollection coll);
+
+ void VisitAssemblyTable (AssemblyTable table);
+ void VisitAssemblyOSTable (AssemblyOSTable table);
+ void VisitAssemblyProcessorTable (AssemblyProcessorTable table);
+ void VisitAssemblyRefTable (AssemblyRefTable table);
+ void VisitAssemblyRefOSTable (AssemblyRefOSTable table);
+ void VisitAssemblyRefProcessorTable (AssemblyRefProcessorTable table);
+ void VisitClassLayoutTable (ClassLayoutTable table);
+ void VisitConstantTable (ConstantTable table);
+ void VisitCustomAttributeTable (CustomAttributeTable table);
+ void VisitDeclSecurityTable (DeclSecurityTable table);
+ void VisitEventTable (EventTable table);
+ void VisitEventMapTable (EventMapTable table);
+ void VisitEventPtrTable (EventPtrTable table);
+ void VisitExportedTypeTable (ExportedTypeTable table);
+ void VisitFieldTable (FieldTable table);
+ void VisitFieldLayoutTable (FieldLayoutTable table);
+ void VisitFieldMarshalTable (FieldMarshalTable table);
+ void VisitFieldPtrTable (FieldPtrTable table);
+ void VisitFieldRVATable (FieldRVATable table);
+ void VisitFileTable (FileTable table);
+ void VisitGenericParamTable (GenericParamTable table);
+ void VisitGenericParamConstraintTable (GenericParamConstraintTable table);
+ void VisitImplMapTable (ImplMapTable table);
+ void VisitInterfaceImplTable (InterfaceImplTable table);
+ void VisitManifestResourceTable (ManifestResourceTable table);
+ void VisitMemberRefTable (MemberRefTable table);
+ void VisitMethodTable (MethodTable table);
+ void VisitMethodImplTable (MethodImplTable table);
+ void VisitMethodPtrTable (MethodPtrTable table);
+ void VisitMethodSemanticsTable (MethodSemanticsTable table);
+ void VisitMethodSpecTable (MethodSpecTable table);
+ void VisitModuleTable (ModuleTable table);
+ void VisitModuleRefTable (ModuleRefTable table);
+ void VisitNestedClassTable (NestedClassTable table);
+ void VisitParamTable (ParamTable table);
+ void VisitParamPtrTable (ParamPtrTable table);
+ void VisitPropertyTable (PropertyTable table);
+ void VisitPropertyMapTable (PropertyMapTable table);
+ void VisitPropertyPtrTable (PropertyPtrTable table);
+ void VisitStandAloneSigTable (StandAloneSigTable table);
+ void VisitTypeDefTable (TypeDefTable table);
+ void VisitTypeRefTable (TypeRefTable table);
+ void VisitTypeSpecTable (TypeSpecTable table);
+
+ void TerminateTableCollection (TableCollection coll);
+ IMetadataRowVisitor GetRowVisitor();
+}
+
+ internal interface IMetadataRowVisitor {
+ void VisitRowCollection (RowCollection coll);
+
+ void VisitAssemblyRow (AssemblyRow row);
+ void VisitAssemblyOSRow (AssemblyOSRow row);
+ void VisitAssemblyProcessorRow (AssemblyProcessorRow row);
+ void VisitAssemblyRefRow (AssemblyRefRow row);
+ void VisitAssemblyRefOSRow (AssemblyRefOSRow row);
+ void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row);
+ void VisitClassLayoutRow (ClassLayoutRow row);
+ void VisitConstantRow (ConstantRow row);
+ void VisitCustomAttributeRow (CustomAttributeRow row);
+ void VisitDeclSecurityRow (DeclSecurityRow row);
+ void VisitEventRow (EventRow row);
+ void VisitEventMapRow (EventMapRow row);
+ void VisitEventPtrRow (EventPtrRow row);
+ void VisitExportedTypeRow (ExportedTypeRow row);
+ void VisitFieldRow (FieldRow row);
+ void VisitFieldLayoutRow (FieldLayoutRow row);
+ void VisitFieldMarshalRow (FieldMarshalRow row);
+ void VisitFieldPtrRow (FieldPtrRow row);
+ void VisitFieldRVARow (FieldRVARow row);
+ void VisitFileRow (FileRow row);
+ void VisitGenericParamRow (GenericParamRow row);
+ void VisitGenericParamConstraintRow (GenericParamConstraintRow row);
+ void VisitImplMapRow (ImplMapRow row);
+ void VisitInterfaceImplRow (InterfaceImplRow row);
+ void VisitManifestResourceRow (ManifestResourceRow row);
+ void VisitMemberRefRow (MemberRefRow row);
+ void VisitMethodRow (MethodRow row);
+ void VisitMethodImplRow (MethodImplRow row);
+ void VisitMethodPtrRow (MethodPtrRow row);
+ void VisitMethodSemanticsRow (MethodSemanticsRow row);
+ void VisitMethodSpecRow (MethodSpecRow row);
+ void VisitModuleRow (ModuleRow row);
+ void VisitModuleRefRow (ModuleRefRow row);
+ void VisitNestedClassRow (NestedClassRow row);
+ void VisitParamRow (ParamRow row);
+ void VisitParamPtrRow (ParamPtrRow row);
+ void VisitPropertyRow (PropertyRow row);
+ void VisitPropertyMapRow (PropertyMapRow row);
+ void VisitPropertyPtrRow (PropertyPtrRow row);
+ void VisitStandAloneSigRow (StandAloneSigRow row);
+ void VisitTypeDefRow (TypeDefRow row);
+ void VisitTypeRefRow (TypeRefRow row);
+ void VisitTypeSpecRow (TypeSpecRow row);
+
+ void TerminateRowCollection (RowCollection coll);
+ }
+}
--- /dev/null
+//
+// ImplMapTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class ImplMapTable : IMetadataTable {
+
+ public const int RId = 0x1c;
+
+ RowCollection m_rows;
+
+ public ImplMapRow this [int index] {
+ get { return m_rows [index] as ImplMapRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal ImplMapTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitImplMapTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class ImplMapRow : IMetadataRow {
+
+ public PInvokeAttributes MappingFlags;
+ public MetadataToken MemberForwarded;
+ public uint ImportName;
+ public uint ImportScope;
+
+ internal ImplMapRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitImplMapRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// InterfaceImplTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class InterfaceImplTable : IMetadataTable {
+
+ public const int RId = 0x09;
+
+ RowCollection m_rows;
+
+ public InterfaceImplRow this [int index] {
+ get { return m_rows [index] as InterfaceImplRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal InterfaceImplTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitInterfaceImplTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class InterfaceImplRow : IMetadataRow {
+
+ public uint Class;
+ public MetadataToken Interface;
+
+ internal InterfaceImplRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitInterfaceImplRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// ManifestResourceTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class ManifestResourceTable : IMetadataTable {
+
+ public const int RId = 0x28;
+
+ RowCollection m_rows;
+
+ public ManifestResourceRow this [int index] {
+ get { return m_rows [index] as ManifestResourceRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal ManifestResourceTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitManifestResourceTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class ManifestResourceRow : IMetadataRow {
+
+ public uint Offset;
+ public ManifestResourceAttributes Flags;
+ public uint Name;
+ public MetadataToken Implementation;
+
+ internal ManifestResourceRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitManifestResourceRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// MemberRefTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class MemberRefTable : IMetadataTable {
+
+ public const int RId = 0x0a;
+
+ RowCollection m_rows;
+
+ public MemberRefRow this [int index] {
+ get { return m_rows [index] as MemberRefRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal MemberRefTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitMemberRefTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class MemberRefRow : IMetadataRow {
+
+ public MetadataToken Class;
+ public uint Name;
+ public uint Signature;
+
+ internal MemberRefRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitMemberRefRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// MetadataFormatException.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+
+ using Mono.Cecil.Binary;
+
+ internal class MetadataFormatException : ImageFormatException {
+
+ internal MetadataFormatException () : base ()
+ {
+ }
+
+ internal MetadataFormatException (string message) : base (message)
+ {
+ }
+
+ internal MetadataFormatException (string message, params string [] parameters) :
+ base (string.Format (message, parameters))
+ {
+ }
+
+ internal MetadataFormatException (string message, Exception inner) :
+ base (message, inner)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// MetadataHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+
+ using Mono.Cecil;
+
+ internal abstract class MetadataHeap : IMetadataVisitable {
+
+ MetadataStream m_stream;
+ string m_name;
+ byte [] m_data;
+
+ public string Name {
+ get { return m_name; }
+ }
+
+ public byte [] Data {
+ get { return m_data; }
+ set { m_data = value; }
+ }
+
+ public int IndexSize;
+
+ internal MetadataHeap (MetadataStream stream, string name)
+ {
+ m_name = name;
+ m_stream = stream;
+ }
+
+ public static MetadataHeap HeapFactory (MetadataStream stream)
+ {
+ switch (stream.Header.Name) {
+ case MetadataStream.Tables :
+ case MetadataStream.IncrementalTables :
+ return new TablesHeap (stream);
+ case MetadataStream.GUID :
+ return new GuidHeap (stream);
+ case MetadataStream.Strings :
+ return new StringsHeap (stream);
+ case MetadataStream.UserStrings :
+ return new UserStringsHeap (stream);
+ case MetadataStream.Blob :
+ return new BlobHeap (stream);
+ default :
+ return null;
+ }
+ }
+
+ public MetadataStream GetStream ()
+ {
+ return m_stream;
+ }
+
+ protected virtual byte [] ReadBytesFromStream (uint pos)
+ {
+ int start, length = Utilities.ReadCompressedInteger (m_data, (int) pos, out start);
+ byte [] buffer = new byte [length];
+ Buffer.BlockCopy (m_data, start, buffer, 0, length);
+ return buffer;
+ }
+
+ public abstract void Accept (IMetadataVisitor visitor);
+ }
+}
--- /dev/null
+//
+// MetadataInitializer.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.IO;
+ using System.Text;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Binary;
+
+ sealed class MetadataInitializer : BaseMetadataVisitor {
+
+ MetadataRoot m_root;
+
+ public MetadataInitializer (ImageInitializer init)
+ {
+ m_root = init.Image.MetadataRoot;
+ }
+
+ public override void VisitMetadataRoot (MetadataRoot root)
+ {
+ root.Header = new MetadataRoot.MetadataRootHeader ();
+ root.Streams = new MetadataStreamCollection ();
+ }
+
+ public override void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header)
+ {
+ header.SetDefaultValues ();
+ }
+
+ public override void VisitMetadataStreamCollection (MetadataStreamCollection coll)
+ {
+ MetadataStream tables = new MetadataStream ();
+ tables.Header.Name = MetadataStream.Tables;
+ tables.Heap = MetadataHeap.HeapFactory (tables);
+ TablesHeap th = tables.Heap as TablesHeap;
+ th.Tables = new TableCollection (th);
+ m_root.Streams.Add (tables);
+ }
+
+ public override void VisitTablesHeap (TablesHeap th)
+ {
+ th.Reserved = 0;
+ th.MajorVersion = 1;
+ th.MinorVersion = 0;
+ th.Reserved2 = 1;
+ th.Sorted = 0x2003301fa00;
+ }
+ }
+}
--- /dev/null
+//
+// MetadataReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.IO;
+ using System.Text;
+
+ using Mono.Cecil.Binary;
+
+ sealed class MetadataReader : BaseMetadataVisitor {
+
+ ImageReader m_ir;
+ BinaryReader m_binaryReader;
+ MetadataTableReader m_tableReader;
+ MetadataRoot m_root;
+
+ public MetadataTableReader TableReader {
+ get { return m_tableReader; }
+ }
+
+ public MetadataReader (ImageReader brv)
+ {
+ m_ir = brv;
+ m_binaryReader = brv.GetReader ();
+ }
+
+ public MetadataRoot GetMetadataRoot ()
+ {
+ return m_root;
+ }
+
+ public BinaryReader GetDataReader (RVA rva)
+ {
+ return m_ir.Image.GetReaderAtVirtualAddress (rva);
+ }
+
+ public override void VisitMetadataRoot (MetadataRoot root)
+ {
+ m_root = root;
+ root.Header = new MetadataRoot.MetadataRootHeader ();
+ root.Streams = new MetadataStreamCollection ();
+ }
+
+ public override void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header)
+ {
+ long headpos = m_binaryReader.BaseStream.Position;
+
+ header.Signature = m_binaryReader.ReadUInt32 ();
+
+ if (header.Signature != MetadataRoot.MetadataRootHeader.StandardSignature)
+ throw new MetadataFormatException ("Wrong magic number");
+
+ header.MajorVersion = m_binaryReader.ReadUInt16 ();
+ header.MinorVersion = m_binaryReader.ReadUInt16 ();
+ header.Reserved = m_binaryReader.ReadUInt32 ();
+
+ // read version
+ uint length = m_binaryReader.ReadUInt32 ();
+ if (length != 0) {
+ long pos = m_binaryReader.BaseStream.Position;
+
+ byte [] version, buffer = new byte [length];
+ int read = 0;
+ while (read < length) {
+ byte cur = (byte)m_binaryReader.ReadSByte ();
+ if (cur == 0)
+ break;
+ buffer [read++] = cur;
+ }
+ version = new byte [read];
+ Buffer.BlockCopy (buffer, 0, version, 0, read);
+ header.Version = Encoding.UTF8.GetString (version, 0, version.Length);
+
+ pos += length - headpos + 3;
+ pos &= ~3;
+ pos += headpos;
+
+ m_binaryReader.BaseStream.Position = pos;
+ } else
+ header.Version = string.Empty;
+
+ header.Flags = m_binaryReader.ReadUInt16 ();
+ header.Streams = m_binaryReader.ReadUInt16 ();
+ }
+
+ public override void VisitMetadataStreamCollection (MetadataStreamCollection coll)
+ {
+ for (int i = 0; i < m_root.Header.Streams; i++)
+ coll.Add (new MetadataStream ());
+ }
+
+ public override void VisitMetadataStreamHeader (MetadataStream.MetadataStreamHeader header)
+ {
+ header.Offset = m_binaryReader.ReadUInt32 ();
+ header.Size = m_binaryReader.ReadUInt32 ();
+
+ StringBuilder buffer = new StringBuilder ();
+ while (true) {
+ char cur = (char) m_binaryReader.ReadSByte ();
+ if (cur == '\0')
+ break;
+ buffer.Append (cur);
+ }
+ header.Name = buffer.ToString ();
+ if (header.Name.Length == 0)
+ throw new MetadataFormatException ("Invalid stream name");
+
+ long rootpos = m_root.GetImage ().ResolveVirtualAddress (
+ m_root.GetImage ().CLIHeader.Metadata.VirtualAddress);
+
+ long curpos = m_binaryReader.BaseStream.Position;
+
+ if (header.Size != 0)
+ curpos -= rootpos;
+
+ curpos += 3;
+ curpos &= ~3;
+
+ if (header.Size != 0)
+ curpos += rootpos;
+
+ m_binaryReader.BaseStream.Position = curpos;
+
+ header.Stream.Heap = MetadataHeap.HeapFactory (header.Stream);
+ }
+
+ public override void VisitGuidHeap (GuidHeap heap)
+ {
+ VisitHeap (heap);
+ }
+
+ public override void VisitStringsHeap (StringsHeap heap)
+ {
+ VisitHeap (heap);
+
+ if (heap.Data.Length < 1 && heap.Data [0] != 0)
+ throw new MetadataFormatException ("Malformed #Strings heap");
+
+ heap [(uint) 0] = string.Empty;
+ }
+
+ public override void VisitTablesHeap (TablesHeap heap)
+ {
+ VisitHeap (heap);
+ heap.Tables = new TableCollection (heap);
+
+ BinaryReader br = new BinaryReader (new MemoryStream (heap.Data));
+ try {
+ heap.Reserved = br.ReadUInt32 ();
+ heap.MajorVersion = br.ReadByte ();
+ heap.MinorVersion = br.ReadByte ();
+ heap.HeapSizes = br.ReadByte ();
+ heap.Reserved2 = br.ReadByte ();
+ heap.Valid = br.ReadInt64 ();
+ heap.Sorted = br.ReadInt64 ();
+ } finally {
+ // COMPACT FRAMEWORK NOTE: BinaryReader is not IDisposable
+ br.Close ();
+ }
+ }
+
+ public override void VisitBlobHeap (BlobHeap heap)
+ {
+ VisitHeap (heap);
+ }
+
+ public override void VisitUserStringsHeap (UserStringsHeap heap)
+ {
+ VisitHeap (heap);
+ }
+
+ void VisitHeap (MetadataHeap heap)
+ {
+ long cursor = m_binaryReader.BaseStream.Position;
+
+ m_binaryReader.BaseStream.Position = m_root.GetImage ().ResolveVirtualAddress (
+ m_root.GetImage ().CLIHeader.Metadata.VirtualAddress)
+ + heap.GetStream ().Header.Offset;
+
+ heap.Data = m_binaryReader.ReadBytes ((int) heap.GetStream ().Header.Size);
+
+ m_binaryReader.BaseStream.Position = cursor;
+ }
+
+ void SetHeapIndexSize (MetadataHeap heap, byte flag)
+ {
+ if (heap == null)
+ return;
+ TablesHeap th = m_root.Streams.TablesHeap;
+ heap.IndexSize = ((th.HeapSizes & flag) > 0) ? 4 : 2;
+ }
+
+ public override void TerminateMetadataRoot (MetadataRoot root)
+ {
+ SetHeapIndexSize (root.Streams.StringsHeap, 0x01);
+ SetHeapIndexSize (root.Streams.GuidHeap, 0x02);
+ SetHeapIndexSize (root.Streams.BlobHeap, 0x04);
+ m_tableReader = new MetadataTableReader (this);
+ root.Streams.TablesHeap.Tables.Accept (m_tableReader);
+ }
+ }
+}
--- /dev/null
+//
+// MetadataRoot.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil.Binary;
+
+ internal sealed class MetadataRoot : IMetadataVisitable {
+
+ MetadataRootHeader m_header;
+ Image m_image;
+
+ MetadataStreamCollection m_streams;
+
+ public MetadataRootHeader Header {
+ get { return m_header; }
+ set { m_header = value; }
+ }
+
+ public MetadataStreamCollection Streams {
+ get { return m_streams; }
+ set { m_streams = value; }
+ }
+
+ internal MetadataRoot (Image img)
+ {
+ m_image = img;
+ }
+
+ public Image GetImage ()
+ {
+ return m_image;
+ }
+
+ public void Accept (IMetadataVisitor visitor)
+ {
+ visitor.VisitMetadataRoot (this);
+
+ m_header.Accept (visitor);
+ m_streams.Accept (visitor);
+
+ visitor.TerminateMetadataRoot (this);
+ }
+
+ internal sealed class MetadataRootHeader : IHeader, IMetadataVisitable {
+
+ public const uint StandardSignature = 0x424a5342;
+
+ public uint Signature;
+ public ushort MinorVersion;
+ public ushort MajorVersion;
+ public uint Reserved;
+ public string Version;
+ public ushort Flags;
+ public ushort Streams;
+
+ internal MetadataRootHeader ()
+ {
+ }
+
+ public void SetDefaultValues ()
+ {
+ Signature = StandardSignature;
+ Reserved = 0;
+ Flags = 0;
+ }
+
+ public void Accept (IMetadataVisitor visitor)
+ {
+ visitor.VisitMetadataRootHeader (this);
+ }
+ }
+ }
+}
--- /dev/null
+//
+// MetadataRowReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Sat Feb 16 23:24:17 +0100 2008
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+ using System.IO;
+
+ using Mono.Cecil.Binary;
+
+ sealed class MetadataRowReader : BaseMetadataRowVisitor {
+
+ MetadataTableReader m_mtrv;
+ BinaryReader m_binaryReader;
+ MetadataRoot m_metadataRoot;
+
+ Utilities.TableRowCounter m_counter;
+ int [] m_ciCache;
+
+ int m_blobHeapIdxSz;
+ int m_stringsHeapIdxSz;
+ int m_guidHeapIdxSz;
+
+ public MetadataRowReader (MetadataTableReader mtrv)
+ {
+ m_mtrv = mtrv;
+ m_binaryReader = mtrv.GetReader ();
+ m_metadataRoot = mtrv.GetMetadataRoot ();
+ m_ciCache = new int [13];
+ m_counter = new Utilities.TableRowCounter (m_mtrv.GetNumberOfRows);
+ }
+
+ int GetIndexSize (int rid)
+ {
+ return m_mtrv.GetNumberOfRows (rid) < (1 << 16) ? 2 : 4;
+ }
+
+ int GetCodedIndexSize (CodedIndex ci)
+ {
+ return Utilities.GetCodedIndexSize (ci, m_counter, m_ciCache);
+ }
+
+ uint ReadByIndexSize (int size)
+ {
+ if (size == 2) {
+ return (uint) m_binaryReader.ReadUInt16 ();
+ } else if (size == 4) {
+ return m_binaryReader.ReadUInt32 ();
+ } else {
+ throw new MetadataFormatException ("Non valid size for indexing");
+ }
+ }
+
+ public override void VisitRowCollection (RowCollection coll)
+ {
+ m_blobHeapIdxSz = m_metadataRoot.Streams.BlobHeap != null ?
+ m_metadataRoot.Streams.BlobHeap.IndexSize : 2;
+ m_stringsHeapIdxSz = m_metadataRoot.Streams.StringsHeap != null ?
+ m_metadataRoot.Streams.StringsHeap.IndexSize : 2;
+ m_guidHeapIdxSz = m_metadataRoot.Streams.GuidHeap != null ?
+ m_metadataRoot.Streams.GuidHeap.IndexSize : 2;
+ }
+
+ public override void VisitAssemblyRow (AssemblyRow row)
+ {
+ row.HashAlgId = (Mono.Cecil.AssemblyHashAlgorithm) m_binaryReader.ReadUInt32 ();
+ row.MajorVersion = m_binaryReader.ReadUInt16 ();
+ row.MinorVersion = m_binaryReader.ReadUInt16 ();
+ row.BuildNumber = m_binaryReader.ReadUInt16 ();
+ row.RevisionNumber = m_binaryReader.ReadUInt16 ();
+ row.Flags = (Mono.Cecil.AssemblyFlags) m_binaryReader.ReadUInt32 ();
+ row.PublicKey = ReadByIndexSize (m_blobHeapIdxSz);
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Culture = ReadByIndexSize (m_stringsHeapIdxSz);
+ }
+ public override void VisitAssemblyOSRow (AssemblyOSRow row)
+ {
+ row.OSPlatformID = m_binaryReader.ReadUInt32 ();
+ row.OSMajorVersion = m_binaryReader.ReadUInt32 ();
+ row.OSMinorVersion = m_binaryReader.ReadUInt32 ();
+ }
+ public override void VisitAssemblyProcessorRow (AssemblyProcessorRow row)
+ {
+ row.Processor = m_binaryReader.ReadUInt32 ();
+ }
+ public override void VisitAssemblyRefRow (AssemblyRefRow row)
+ {
+ row.MajorVersion = m_binaryReader.ReadUInt16 ();
+ row.MinorVersion = m_binaryReader.ReadUInt16 ();
+ row.BuildNumber = m_binaryReader.ReadUInt16 ();
+ row.RevisionNumber = m_binaryReader.ReadUInt16 ();
+ row.Flags = (Mono.Cecil.AssemblyFlags) m_binaryReader.ReadUInt32 ();
+ row.PublicKeyOrToken = ReadByIndexSize (m_blobHeapIdxSz);
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Culture = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.HashValue = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitAssemblyRefOSRow (AssemblyRefOSRow row)
+ {
+ row.OSPlatformID = m_binaryReader.ReadUInt32 ();
+ row.OSMajorVersion = m_binaryReader.ReadUInt32 ();
+ row.OSMinorVersion = m_binaryReader.ReadUInt32 ();
+ row.AssemblyRef = ReadByIndexSize (GetIndexSize (AssemblyRefTable.RId));
+ }
+ public override void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row)
+ {
+ row.Processor = m_binaryReader.ReadUInt32 ();
+ row.AssemblyRef = ReadByIndexSize (GetIndexSize (AssemblyRefTable.RId));
+ }
+ public override void VisitClassLayoutRow (ClassLayoutRow row)
+ {
+ row.PackingSize = m_binaryReader.ReadUInt16 ();
+ row.ClassSize = m_binaryReader.ReadUInt32 ();
+ row.Parent = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
+ }
+ public override void VisitConstantRow (ConstantRow row)
+ {
+ row.Type = (Mono.Cecil.Metadata.ElementType) m_binaryReader.ReadUInt16 ();
+ row.Parent = Utilities.GetMetadataToken (CodedIndex.HasConstant,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasConstant)));
+ row.Value = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitCustomAttributeRow (CustomAttributeRow row)
+ {
+ row.Parent = Utilities.GetMetadataToken (CodedIndex.HasCustomAttribute,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasCustomAttribute)));
+ row.Type = Utilities.GetMetadataToken (CodedIndex.CustomAttributeType,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.CustomAttributeType)));
+ row.Value = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitDeclSecurityRow (DeclSecurityRow row)
+ {
+ row.Action = (Mono.Cecil.SecurityAction) m_binaryReader.ReadInt16 ();
+ row.Parent = Utilities.GetMetadataToken (CodedIndex.HasDeclSecurity,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasDeclSecurity)));
+ row.PermissionSet = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitEventRow (EventRow row)
+ {
+ row.EventFlags = (Mono.Cecil.EventAttributes) m_binaryReader.ReadUInt16 ();
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.EventType = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef)));
+ }
+ public override void VisitEventMapRow (EventMapRow row)
+ {
+ row.Parent = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
+ row.EventList = ReadByIndexSize (GetIndexSize (EventTable.RId));
+ }
+ public override void VisitEventPtrRow (EventPtrRow row)
+ {
+ row.Event = ReadByIndexSize (GetIndexSize (EventTable.RId));
+ }
+ public override void VisitExportedTypeRow (ExportedTypeRow row)
+ {
+ row.Flags = (Mono.Cecil.TypeAttributes) m_binaryReader.ReadUInt32 ();
+ row.TypeDefId = m_binaryReader.ReadUInt32 ();
+ row.TypeName = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.TypeNamespace = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Implementation = Utilities.GetMetadataToken (CodedIndex.Implementation,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.Implementation)));
+ }
+ public override void VisitFieldRow (FieldRow row)
+ {
+ row.Flags = (Mono.Cecil.FieldAttributes) m_binaryReader.ReadUInt16 ();
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Signature = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitFieldLayoutRow (FieldLayoutRow row)
+ {
+ row.Offset = m_binaryReader.ReadUInt32 ();
+ row.Field = ReadByIndexSize (GetIndexSize (FieldTable.RId));
+ }
+ public override void VisitFieldMarshalRow (FieldMarshalRow row)
+ {
+ row.Parent = Utilities.GetMetadataToken (CodedIndex.HasFieldMarshal,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasFieldMarshal)));
+ row.NativeType = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitFieldPtrRow (FieldPtrRow row)
+ {
+ row.Field = ReadByIndexSize (GetIndexSize (FieldTable.RId));
+ }
+ public override void VisitFieldRVARow (FieldRVARow row)
+ {
+ row.RVA = new RVA (m_binaryReader.ReadUInt32 ());
+ row.Field = ReadByIndexSize (GetIndexSize (FieldTable.RId));
+ }
+ public override void VisitFileRow (FileRow row)
+ {
+ row.Flags = (Mono.Cecil.FileAttributes) m_binaryReader.ReadUInt32 ();
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.HashValue = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitGenericParamRow (GenericParamRow row)
+ {
+ row.Number = m_binaryReader.ReadUInt16 ();
+ row.Flags = (Mono.Cecil.GenericParameterAttributes) m_binaryReader.ReadUInt16 ();
+ row.Owner = Utilities.GetMetadataToken (CodedIndex.TypeOrMethodDef,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeOrMethodDef)));
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ }
+ public override void VisitGenericParamConstraintRow (GenericParamConstraintRow row)
+ {
+ row.Owner = ReadByIndexSize (GetIndexSize (GenericParamTable.RId));
+ row.Constraint = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef)));
+ }
+ public override void VisitImplMapRow (ImplMapRow row)
+ {
+ row.MappingFlags = (Mono.Cecil.PInvokeAttributes) m_binaryReader.ReadUInt16 ();
+ row.MemberForwarded = Utilities.GetMetadataToken (CodedIndex.MemberForwarded,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.MemberForwarded)));
+ row.ImportName = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.ImportScope = ReadByIndexSize (GetIndexSize (ModuleRefTable.RId));
+ }
+ public override void VisitInterfaceImplRow (InterfaceImplRow row)
+ {
+ row.Class = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
+ row.Interface = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef)));
+ }
+ public override void VisitManifestResourceRow (ManifestResourceRow row)
+ {
+ row.Offset = m_binaryReader.ReadUInt32 ();
+ row.Flags = (Mono.Cecil.ManifestResourceAttributes) m_binaryReader.ReadUInt32 ();
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Implementation = Utilities.GetMetadataToken (CodedIndex.Implementation,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.Implementation)));
+ }
+ public override void VisitMemberRefRow (MemberRefRow row)
+ {
+ row.Class = Utilities.GetMetadataToken (CodedIndex.MemberRefParent,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.MemberRefParent)));
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Signature = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitMethodRow (MethodRow row)
+ {
+ row.RVA = new RVA (m_binaryReader.ReadUInt32 ());
+ row.ImplFlags = (Mono.Cecil.MethodImplAttributes) m_binaryReader.ReadUInt16 ();
+ row.Flags = (Mono.Cecil.MethodAttributes) m_binaryReader.ReadUInt16 ();
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Signature = ReadByIndexSize (m_blobHeapIdxSz);
+ row.ParamList = ReadByIndexSize (GetIndexSize (ParamTable.RId));
+ }
+ public override void VisitMethodImplRow (MethodImplRow row)
+ {
+ row.Class = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
+ row.MethodBody = Utilities.GetMetadataToken (CodedIndex.MethodDefOrRef,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.MethodDefOrRef)));
+ row.MethodDeclaration = Utilities.GetMetadataToken (CodedIndex.MethodDefOrRef,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.MethodDefOrRef)));
+ }
+ public override void VisitMethodPtrRow (MethodPtrRow row)
+ {
+ row.Method = ReadByIndexSize (GetIndexSize (MethodTable.RId));
+ }
+ public override void VisitMethodSemanticsRow (MethodSemanticsRow row)
+ {
+ row.Semantics = (Mono.Cecil.MethodSemanticsAttributes) m_binaryReader.ReadUInt16 ();
+ row.Method = ReadByIndexSize (GetIndexSize (MethodTable.RId));
+ row.Association = Utilities.GetMetadataToken (CodedIndex.HasSemantics,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasSemantics)));
+ }
+ public override void VisitMethodSpecRow (MethodSpecRow row)
+ {
+ row.Method = Utilities.GetMetadataToken (CodedIndex.MethodDefOrRef,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.MethodDefOrRef)));
+ row.Instantiation = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitModuleRow (ModuleRow row)
+ {
+ row.Generation = m_binaryReader.ReadUInt16 ();
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Mvid = ReadByIndexSize (m_guidHeapIdxSz);
+ row.EncId = ReadByIndexSize (m_guidHeapIdxSz);
+ row.EncBaseId = ReadByIndexSize (m_guidHeapIdxSz);
+ }
+ public override void VisitModuleRefRow (ModuleRefRow row)
+ {
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ }
+ public override void VisitNestedClassRow (NestedClassRow row)
+ {
+ row.NestedClass = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
+ row.EnclosingClass = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
+ }
+ public override void VisitParamRow (ParamRow row)
+ {
+ row.Flags = (Mono.Cecil.ParameterAttributes) m_binaryReader.ReadUInt16 ();
+ row.Sequence = m_binaryReader.ReadUInt16 ();
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ }
+ public override void VisitParamPtrRow (ParamPtrRow row)
+ {
+ row.Param = ReadByIndexSize (GetIndexSize (ParamTable.RId));
+ }
+ public override void VisitPropertyRow (PropertyRow row)
+ {
+ row.Flags = (Mono.Cecil.PropertyAttributes) m_binaryReader.ReadUInt16 ();
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Type = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitPropertyMapRow (PropertyMapRow row)
+ {
+ row.Parent = ReadByIndexSize (GetIndexSize (TypeDefTable.RId));
+ row.PropertyList = ReadByIndexSize (GetIndexSize (PropertyTable.RId));
+ }
+ public override void VisitPropertyPtrRow (PropertyPtrRow row)
+ {
+ row.Property = ReadByIndexSize (GetIndexSize (PropertyTable.RId));
+ }
+ public override void VisitStandAloneSigRow (StandAloneSigRow row)
+ {
+ row.Signature = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ public override void VisitTypeDefRow (TypeDefRow row)
+ {
+ row.Flags = (Mono.Cecil.TypeAttributes) m_binaryReader.ReadUInt32 ();
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Namespace = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Extends = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef)));
+ row.FieldList = ReadByIndexSize (GetIndexSize (FieldTable.RId));
+ row.MethodList = ReadByIndexSize (GetIndexSize (MethodTable.RId));
+ }
+ public override void VisitTypeRefRow (TypeRefRow row)
+ {
+ row.ResolutionScope = Utilities.GetMetadataToken (CodedIndex.ResolutionScope,
+ ReadByIndexSize (GetCodedIndexSize (CodedIndex.ResolutionScope)));
+ row.Name = ReadByIndexSize (m_stringsHeapIdxSz);
+ row.Namespace = ReadByIndexSize (m_stringsHeapIdxSz);
+ }
+ public override void VisitTypeSpecRow (TypeSpecRow row)
+ {
+ row.Signature = ReadByIndexSize (m_blobHeapIdxSz);
+ }
+ }
+}
--- /dev/null
+//
+// MetadataRowWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Sat Feb 16 23:24:17 +0100 2008
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Binary;
+
+ sealed class MetadataRowWriter : BaseMetadataRowVisitor {
+
+ MetadataRoot m_root;
+ MemoryBinaryWriter m_binaryWriter;
+
+ Utilities.TableRowCounter m_counter;
+ int [] m_ciCache;
+
+ int m_blobHeapIdxSz;
+ int m_stringsHeapIdxSz;
+ int m_guidHeapIdxSz;
+
+ public MetadataRowWriter (MetadataTableWriter mtwv)
+ {
+ m_binaryWriter = mtwv.GetWriter ();
+ m_root = mtwv.GetMetadataRoot ();
+ m_ciCache = new int [13];
+ m_counter = new Utilities.TableRowCounter (GetNumberOfRows);
+ }
+
+ void WriteBlobPointer (uint pointer)
+ {
+ WriteByIndexSize (pointer, m_blobHeapIdxSz);
+ }
+
+ void WriteStringPointer (uint pointer)
+ {
+ WriteByIndexSize (pointer, m_stringsHeapIdxSz);
+ }
+
+ void WriteGuidPointer (uint pointer)
+ {
+ WriteByIndexSize (pointer, m_guidHeapIdxSz);
+ }
+
+ void WriteTablePointer (uint pointer, int rid)
+ {
+ WriteByIndexSize (pointer, GetNumberOfRows (rid) < (1 << 16) ? 2 : 4);
+ }
+
+ void WriteMetadataToken (MetadataToken token, CodedIndex ci)
+ {
+ WriteByIndexSize (Utilities.CompressMetadataToken (ci, token),
+ Utilities.GetCodedIndexSize (ci, m_counter, m_ciCache));
+ }
+
+ int GetNumberOfRows (int rid)
+ {
+ IMetadataTable t = m_root.Streams.TablesHeap [rid];
+ if (t == null || t.Rows == null)
+ return 0;
+ return t.Rows.Count;
+ }
+
+ void WriteByIndexSize (uint value, int size)
+ {
+ if (size == 4)
+ m_binaryWriter.Write (value);
+ else if (size == 2)
+ m_binaryWriter.Write ((ushort) value);
+ else
+ throw new MetadataFormatException ("Non valid size for indexing");
+ }
+
+ public AssemblyRow CreateAssemblyRow (AssemblyHashAlgorithm _hashAlgId, ushort _majorVersion, ushort _minorVersion, ushort _buildNumber, ushort _revisionNumber, AssemblyFlags _flags, uint _publicKey, uint _name, uint _culture)
+ {
+ AssemblyRow row = new AssemblyRow ();
+ row.HashAlgId = _hashAlgId;
+ row.MajorVersion = _majorVersion;
+ row.MinorVersion = _minorVersion;
+ row.BuildNumber = _buildNumber;
+ row.RevisionNumber = _revisionNumber;
+ row.Flags = _flags;
+ row.PublicKey = _publicKey;
+ row.Name = _name;
+ row.Culture = _culture;
+ return row;
+ }
+
+ public AssemblyOSRow CreateAssemblyOSRow (uint _oSPlatformID, uint _oSMajorVersion, uint _oSMinorVersion)
+ {
+ AssemblyOSRow row = new AssemblyOSRow ();
+ row.OSPlatformID = _oSPlatformID;
+ row.OSMajorVersion = _oSMajorVersion;
+ row.OSMinorVersion = _oSMinorVersion;
+ return row;
+ }
+
+ public AssemblyProcessorRow CreateAssemblyProcessorRow (uint _processor)
+ {
+ AssemblyProcessorRow row = new AssemblyProcessorRow ();
+ row.Processor = _processor;
+ return row;
+ }
+
+ public AssemblyRefRow CreateAssemblyRefRow (ushort _majorVersion, ushort _minorVersion, ushort _buildNumber, ushort _revisionNumber, AssemblyFlags _flags, uint _publicKeyOrToken, uint _name, uint _culture, uint _hashValue)
+ {
+ AssemblyRefRow row = new AssemblyRefRow ();
+ row.MajorVersion = _majorVersion;
+ row.MinorVersion = _minorVersion;
+ row.BuildNumber = _buildNumber;
+ row.RevisionNumber = _revisionNumber;
+ row.Flags = _flags;
+ row.PublicKeyOrToken = _publicKeyOrToken;
+ row.Name = _name;
+ row.Culture = _culture;
+ row.HashValue = _hashValue;
+ return row;
+ }
+
+ public AssemblyRefOSRow CreateAssemblyRefOSRow (uint _oSPlatformID, uint _oSMajorVersion, uint _oSMinorVersion, uint _assemblyRef)
+ {
+ AssemblyRefOSRow row = new AssemblyRefOSRow ();
+ row.OSPlatformID = _oSPlatformID;
+ row.OSMajorVersion = _oSMajorVersion;
+ row.OSMinorVersion = _oSMinorVersion;
+ row.AssemblyRef = _assemblyRef;
+ return row;
+ }
+
+ public AssemblyRefProcessorRow CreateAssemblyRefProcessorRow (uint _processor, uint _assemblyRef)
+ {
+ AssemblyRefProcessorRow row = new AssemblyRefProcessorRow ();
+ row.Processor = _processor;
+ row.AssemblyRef = _assemblyRef;
+ return row;
+ }
+
+ public ClassLayoutRow CreateClassLayoutRow (ushort _packingSize, uint _classSize, uint _parent)
+ {
+ ClassLayoutRow row = new ClassLayoutRow ();
+ row.PackingSize = _packingSize;
+ row.ClassSize = _classSize;
+ row.Parent = _parent;
+ return row;
+ }
+
+ public ConstantRow CreateConstantRow (ElementType _type, MetadataToken _parent, uint _value)
+ {
+ ConstantRow row = new ConstantRow ();
+ row.Type = _type;
+ row.Parent = _parent;
+ row.Value = _value;
+ return row;
+ }
+
+ public CustomAttributeRow CreateCustomAttributeRow (MetadataToken _parent, MetadataToken _type, uint _value)
+ {
+ CustomAttributeRow row = new CustomAttributeRow ();
+ row.Parent = _parent;
+ row.Type = _type;
+ row.Value = _value;
+ return row;
+ }
+
+ public DeclSecurityRow CreateDeclSecurityRow (SecurityAction _action, MetadataToken _parent, uint _permissionSet)
+ {
+ DeclSecurityRow row = new DeclSecurityRow ();
+ row.Action = _action;
+ row.Parent = _parent;
+ row.PermissionSet = _permissionSet;
+ return row;
+ }
+
+ public EventRow CreateEventRow (EventAttributes _eventFlags, uint _name, MetadataToken _eventType)
+ {
+ EventRow row = new EventRow ();
+ row.EventFlags = _eventFlags;
+ row.Name = _name;
+ row.EventType = _eventType;
+ return row;
+ }
+
+ public EventMapRow CreateEventMapRow (uint _parent, uint _eventList)
+ {
+ EventMapRow row = new EventMapRow ();
+ row.Parent = _parent;
+ row.EventList = _eventList;
+ return row;
+ }
+
+ public EventPtrRow CreateEventPtrRow (uint _event)
+ {
+ EventPtrRow row = new EventPtrRow ();
+ row.Event = _event;
+ return row;
+ }
+
+ public ExportedTypeRow CreateExportedTypeRow (TypeAttributes _flags, uint _typeDefId, uint _typeName, uint _typeNamespace, MetadataToken _implementation)
+ {
+ ExportedTypeRow row = new ExportedTypeRow ();
+ row.Flags = _flags;
+ row.TypeDefId = _typeDefId;
+ row.TypeName = _typeName;
+ row.TypeNamespace = _typeNamespace;
+ row.Implementation = _implementation;
+ return row;
+ }
+
+ public FieldRow CreateFieldRow (FieldAttributes _flags, uint _name, uint _signature)
+ {
+ FieldRow row = new FieldRow ();
+ row.Flags = _flags;
+ row.Name = _name;
+ row.Signature = _signature;
+ return row;
+ }
+
+ public FieldLayoutRow CreateFieldLayoutRow (uint _offset, uint _field)
+ {
+ FieldLayoutRow row = new FieldLayoutRow ();
+ row.Offset = _offset;
+ row.Field = _field;
+ return row;
+ }
+
+ public FieldMarshalRow CreateFieldMarshalRow (MetadataToken _parent, uint _nativeType)
+ {
+ FieldMarshalRow row = new FieldMarshalRow ();
+ row.Parent = _parent;
+ row.NativeType = _nativeType;
+ return row;
+ }
+
+ public FieldPtrRow CreateFieldPtrRow (uint _field)
+ {
+ FieldPtrRow row = new FieldPtrRow ();
+ row.Field = _field;
+ return row;
+ }
+
+ public FieldRVARow CreateFieldRVARow (RVA _rVA, uint _field)
+ {
+ FieldRVARow row = new FieldRVARow ();
+ row.RVA = _rVA;
+ row.Field = _field;
+ return row;
+ }
+
+ public FileRow CreateFileRow (FileAttributes _flags, uint _name, uint _hashValue)
+ {
+ FileRow row = new FileRow ();
+ row.Flags = _flags;
+ row.Name = _name;
+ row.HashValue = _hashValue;
+ return row;
+ }
+
+ public GenericParamRow CreateGenericParamRow (ushort _number, GenericParameterAttributes _flags, MetadataToken _owner, uint _name)
+ {
+ GenericParamRow row = new GenericParamRow ();
+ row.Number = _number;
+ row.Flags = _flags;
+ row.Owner = _owner;
+ row.Name = _name;
+ return row;
+ }
+
+ public GenericParamConstraintRow CreateGenericParamConstraintRow (uint _owner, MetadataToken _constraint)
+ {
+ GenericParamConstraintRow row = new GenericParamConstraintRow ();
+ row.Owner = _owner;
+ row.Constraint = _constraint;
+ return row;
+ }
+
+ public ImplMapRow CreateImplMapRow (PInvokeAttributes _mappingFlags, MetadataToken _memberForwarded, uint _importName, uint _importScope)
+ {
+ ImplMapRow row = new ImplMapRow ();
+ row.MappingFlags = _mappingFlags;
+ row.MemberForwarded = _memberForwarded;
+ row.ImportName = _importName;
+ row.ImportScope = _importScope;
+ return row;
+ }
+
+ public InterfaceImplRow CreateInterfaceImplRow (uint _class, MetadataToken _interface)
+ {
+ InterfaceImplRow row = new InterfaceImplRow ();
+ row.Class = _class;
+ row.Interface = _interface;
+ return row;
+ }
+
+ public ManifestResourceRow CreateManifestResourceRow (uint _offset, ManifestResourceAttributes _flags, uint _name, MetadataToken _implementation)
+ {
+ ManifestResourceRow row = new ManifestResourceRow ();
+ row.Offset = _offset;
+ row.Flags = _flags;
+ row.Name = _name;
+ row.Implementation = _implementation;
+ return row;
+ }
+
+ public MemberRefRow CreateMemberRefRow (MetadataToken _class, uint _name, uint _signature)
+ {
+ MemberRefRow row = new MemberRefRow ();
+ row.Class = _class;
+ row.Name = _name;
+ row.Signature = _signature;
+ return row;
+ }
+
+ public MethodRow CreateMethodRow (RVA _rVA, MethodImplAttributes _implFlags, MethodAttributes _flags, uint _name, uint _signature, uint _paramList)
+ {
+ MethodRow row = new MethodRow ();
+ row.RVA = _rVA;
+ row.ImplFlags = _implFlags;
+ row.Flags = _flags;
+ row.Name = _name;
+ row.Signature = _signature;
+ row.ParamList = _paramList;
+ return row;
+ }
+
+ public MethodImplRow CreateMethodImplRow (uint _class, MetadataToken _methodBody, MetadataToken _methodDeclaration)
+ {
+ MethodImplRow row = new MethodImplRow ();
+ row.Class = _class;
+ row.MethodBody = _methodBody;
+ row.MethodDeclaration = _methodDeclaration;
+ return row;
+ }
+
+ public MethodPtrRow CreateMethodPtrRow (uint _method)
+ {
+ MethodPtrRow row = new MethodPtrRow ();
+ row.Method = _method;
+ return row;
+ }
+
+ public MethodSemanticsRow CreateMethodSemanticsRow (MethodSemanticsAttributes _semantics, uint _method, MetadataToken _association)
+ {
+ MethodSemanticsRow row = new MethodSemanticsRow ();
+ row.Semantics = _semantics;
+ row.Method = _method;
+ row.Association = _association;
+ return row;
+ }
+
+ public MethodSpecRow CreateMethodSpecRow (MetadataToken _method, uint _instantiation)
+ {
+ MethodSpecRow row = new MethodSpecRow ();
+ row.Method = _method;
+ row.Instantiation = _instantiation;
+ return row;
+ }
+
+ public ModuleRow CreateModuleRow (ushort _generation, uint _name, uint _mvid, uint _encId, uint _encBaseId)
+ {
+ ModuleRow row = new ModuleRow ();
+ row.Generation = _generation;
+ row.Name = _name;
+ row.Mvid = _mvid;
+ row.EncId = _encId;
+ row.EncBaseId = _encBaseId;
+ return row;
+ }
+
+ public ModuleRefRow CreateModuleRefRow (uint _name)
+ {
+ ModuleRefRow row = new ModuleRefRow ();
+ row.Name = _name;
+ return row;
+ }
+
+ public NestedClassRow CreateNestedClassRow (uint _nestedClass, uint _enclosingClass)
+ {
+ NestedClassRow row = new NestedClassRow ();
+ row.NestedClass = _nestedClass;
+ row.EnclosingClass = _enclosingClass;
+ return row;
+ }
+
+ public ParamRow CreateParamRow (ParameterAttributes _flags, ushort _sequence, uint _name)
+ {
+ ParamRow row = new ParamRow ();
+ row.Flags = _flags;
+ row.Sequence = _sequence;
+ row.Name = _name;
+ return row;
+ }
+
+ public ParamPtrRow CreateParamPtrRow (uint _param)
+ {
+ ParamPtrRow row = new ParamPtrRow ();
+ row.Param = _param;
+ return row;
+ }
+
+ public PropertyRow CreatePropertyRow (PropertyAttributes _flags, uint _name, uint _type)
+ {
+ PropertyRow row = new PropertyRow ();
+ row.Flags = _flags;
+ row.Name = _name;
+ row.Type = _type;
+ return row;
+ }
+
+ public PropertyMapRow CreatePropertyMapRow (uint _parent, uint _propertyList)
+ {
+ PropertyMapRow row = new PropertyMapRow ();
+ row.Parent = _parent;
+ row.PropertyList = _propertyList;
+ return row;
+ }
+
+ public PropertyPtrRow CreatePropertyPtrRow (uint _property)
+ {
+ PropertyPtrRow row = new PropertyPtrRow ();
+ row.Property = _property;
+ return row;
+ }
+
+ public StandAloneSigRow CreateStandAloneSigRow (uint _signature)
+ {
+ StandAloneSigRow row = new StandAloneSigRow ();
+ row.Signature = _signature;
+ return row;
+ }
+
+ public TypeDefRow CreateTypeDefRow (TypeAttributes _flags, uint _name, uint _namespace, MetadataToken _extends, uint _fieldList, uint _methodList)
+ {
+ TypeDefRow row = new TypeDefRow ();
+ row.Flags = _flags;
+ row.Name = _name;
+ row.Namespace = _namespace;
+ row.Extends = _extends;
+ row.FieldList = _fieldList;
+ row.MethodList = _methodList;
+ return row;
+ }
+
+ public TypeRefRow CreateTypeRefRow (MetadataToken _resolutionScope, uint _name, uint _namespace)
+ {
+ TypeRefRow row = new TypeRefRow ();
+ row.ResolutionScope = _resolutionScope;
+ row.Name = _name;
+ row.Namespace = _namespace;
+ return row;
+ }
+
+ public TypeSpecRow CreateTypeSpecRow (uint _signature)
+ {
+ TypeSpecRow row = new TypeSpecRow ();
+ row.Signature = _signature;
+ return row;
+ }
+
+ public override void VisitRowCollection (RowCollection coll)
+ {
+ m_blobHeapIdxSz = m_root.Streams.BlobHeap != null ?
+ m_root.Streams.BlobHeap.IndexSize : 2;
+ m_stringsHeapIdxSz = m_root.Streams.StringsHeap != null ?
+ m_root.Streams.StringsHeap.IndexSize : 2;
+ m_guidHeapIdxSz = m_root.Streams.GuidHeap != null ?
+ m_root.Streams.GuidHeap.IndexSize : 2;
+ }
+
+ public override void VisitAssemblyRow (AssemblyRow row)
+ {
+ m_binaryWriter.Write ((uint) row.HashAlgId);
+ m_binaryWriter.Write (row.MajorVersion);
+ m_binaryWriter.Write (row.MinorVersion);
+ m_binaryWriter.Write (row.BuildNumber);
+ m_binaryWriter.Write (row.RevisionNumber);
+ m_binaryWriter.Write ((uint) row.Flags);
+ WriteBlobPointer (row.PublicKey);
+ WriteStringPointer (row.Name);
+ WriteStringPointer (row.Culture);
+ }
+
+ public override void VisitAssemblyOSRow (AssemblyOSRow row)
+ {
+ m_binaryWriter.Write (row.OSPlatformID);
+ m_binaryWriter.Write (row.OSMajorVersion);
+ m_binaryWriter.Write (row.OSMinorVersion);
+ }
+
+ public override void VisitAssemblyProcessorRow (AssemblyProcessorRow row)
+ {
+ m_binaryWriter.Write (row.Processor);
+ }
+
+ public override void VisitAssemblyRefRow (AssemblyRefRow row)
+ {
+ m_binaryWriter.Write (row.MajorVersion);
+ m_binaryWriter.Write (row.MinorVersion);
+ m_binaryWriter.Write (row.BuildNumber);
+ m_binaryWriter.Write (row.RevisionNumber);
+ m_binaryWriter.Write ((uint) row.Flags);
+ WriteBlobPointer (row.PublicKeyOrToken);
+ WriteStringPointer (row.Name);
+ WriteStringPointer (row.Culture);
+ WriteBlobPointer (row.HashValue);
+ }
+
+ public override void VisitAssemblyRefOSRow (AssemblyRefOSRow row)
+ {
+ m_binaryWriter.Write (row.OSPlatformID);
+ m_binaryWriter.Write (row.OSMajorVersion);
+ m_binaryWriter.Write (row.OSMinorVersion);
+ WriteTablePointer (row.AssemblyRef, AssemblyRefTable.RId);
+ }
+
+ public override void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row)
+ {
+ m_binaryWriter.Write (row.Processor);
+ WriteTablePointer (row.AssemblyRef, AssemblyRefTable.RId);
+ }
+
+ public override void VisitClassLayoutRow (ClassLayoutRow row)
+ {
+ m_binaryWriter.Write (row.PackingSize);
+ m_binaryWriter.Write (row.ClassSize);
+ WriteTablePointer (row.Parent, TypeDefTable.RId);
+ }
+
+ public override void VisitConstantRow (ConstantRow row)
+ {
+ m_binaryWriter.Write ((ushort) row.Type);
+ WriteMetadataToken (row.Parent, CodedIndex.HasConstant);
+ WriteBlobPointer (row.Value);
+ }
+
+ public override void VisitCustomAttributeRow (CustomAttributeRow row)
+ {
+ WriteMetadataToken (row.Parent, CodedIndex.HasCustomAttribute);
+ WriteMetadataToken (row.Type, CodedIndex.CustomAttributeType);
+ WriteBlobPointer (row.Value);
+ }
+
+ public override void VisitDeclSecurityRow (DeclSecurityRow row)
+ {
+ m_binaryWriter.Write ((short) row.Action);
+ WriteMetadataToken (row.Parent, CodedIndex.HasDeclSecurity);
+ WriteBlobPointer (row.PermissionSet);
+ }
+
+ public override void VisitEventRow (EventRow row)
+ {
+ m_binaryWriter.Write ((ushort) row.EventFlags);
+ WriteStringPointer (row.Name);
+ WriteMetadataToken (row.EventType, CodedIndex.TypeDefOrRef);
+ }
+
+ public override void VisitEventMapRow (EventMapRow row)
+ {
+ WriteTablePointer (row.Parent, TypeDefTable.RId);
+ WriteTablePointer (row.EventList, EventTable.RId);
+ }
+
+ public override void VisitEventPtrRow (EventPtrRow row)
+ {
+ WriteTablePointer (row.Event, EventTable.RId);
+ }
+
+ public override void VisitExportedTypeRow (ExportedTypeRow row)
+ {
+ m_binaryWriter.Write ((uint) row.Flags);
+ m_binaryWriter.Write (row.TypeDefId);
+ WriteStringPointer (row.TypeName);
+ WriteStringPointer (row.TypeNamespace);
+ WriteMetadataToken (row.Implementation, CodedIndex.Implementation);
+ }
+
+ public override void VisitFieldRow (FieldRow row)
+ {
+ m_binaryWriter.Write ((ushort) row.Flags);
+ WriteStringPointer (row.Name);
+ WriteBlobPointer (row.Signature);
+ }
+
+ public override void VisitFieldLayoutRow (FieldLayoutRow row)
+ {
+ m_binaryWriter.Write (row.Offset);
+ WriteTablePointer (row.Field, FieldTable.RId);
+ }
+
+ public override void VisitFieldMarshalRow (FieldMarshalRow row)
+ {
+ WriteMetadataToken (row.Parent, CodedIndex.HasFieldMarshal);
+ WriteBlobPointer (row.NativeType);
+ }
+
+ public override void VisitFieldPtrRow (FieldPtrRow row)
+ {
+ WriteTablePointer (row.Field, FieldTable.RId);
+ }
+
+ public override void VisitFieldRVARow (FieldRVARow row)
+ {
+ m_binaryWriter.Write (row.RVA.Value);
+ WriteTablePointer (row.Field, FieldTable.RId);
+ }
+
+ public override void VisitFileRow (FileRow row)
+ {
+ m_binaryWriter.Write ((uint) row.Flags);
+ WriteStringPointer (row.Name);
+ WriteBlobPointer (row.HashValue);
+ }
+
+ public override void VisitGenericParamRow (GenericParamRow row)
+ {
+ m_binaryWriter.Write (row.Number);
+ m_binaryWriter.Write ((ushort) row.Flags);
+ WriteMetadataToken (row.Owner, CodedIndex.TypeOrMethodDef);
+ WriteStringPointer (row.Name);
+ }
+
+ public override void VisitGenericParamConstraintRow (GenericParamConstraintRow row)
+ {
+ WriteTablePointer (row.Owner, GenericParamTable.RId);
+ WriteMetadataToken (row.Constraint, CodedIndex.TypeDefOrRef);
+ }
+
+ public override void VisitImplMapRow (ImplMapRow row)
+ {
+ m_binaryWriter.Write ((ushort) row.MappingFlags);
+ WriteMetadataToken (row.MemberForwarded, CodedIndex.MemberForwarded);
+ WriteStringPointer (row.ImportName);
+ WriteTablePointer (row.ImportScope, ModuleRefTable.RId);
+ }
+
+ public override void VisitInterfaceImplRow (InterfaceImplRow row)
+ {
+ WriteTablePointer (row.Class, TypeDefTable.RId);
+ WriteMetadataToken (row.Interface, CodedIndex.TypeDefOrRef);
+ }
+
+ public override void VisitManifestResourceRow (ManifestResourceRow row)
+ {
+ m_binaryWriter.Write (row.Offset);
+ m_binaryWriter.Write ((uint) row.Flags);
+ WriteStringPointer (row.Name);
+ WriteMetadataToken (row.Implementation, CodedIndex.Implementation);
+ }
+
+ public override void VisitMemberRefRow (MemberRefRow row)
+ {
+ WriteMetadataToken (row.Class, CodedIndex.MemberRefParent);
+ WriteStringPointer (row.Name);
+ WriteBlobPointer (row.Signature);
+ }
+
+ public override void VisitMethodRow (MethodRow row)
+ {
+ m_binaryWriter.Write (row.RVA.Value);
+ m_binaryWriter.Write ((ushort) row.ImplFlags);
+ m_binaryWriter.Write ((ushort) row.Flags);
+ WriteStringPointer (row.Name);
+ WriteBlobPointer (row.Signature);
+ WriteTablePointer (row.ParamList, ParamTable.RId);
+ }
+
+ public override void VisitMethodImplRow (MethodImplRow row)
+ {
+ WriteTablePointer (row.Class, TypeDefTable.RId);
+ WriteMetadataToken (row.MethodBody, CodedIndex.MethodDefOrRef);
+ WriteMetadataToken (row.MethodDeclaration, CodedIndex.MethodDefOrRef);
+ }
+
+ public override void VisitMethodPtrRow (MethodPtrRow row)
+ {
+ WriteTablePointer (row.Method, MethodTable.RId);
+ }
+
+ public override void VisitMethodSemanticsRow (MethodSemanticsRow row)
+ {
+ m_binaryWriter.Write ((ushort) row.Semantics);
+ WriteTablePointer (row.Method, MethodTable.RId);
+ WriteMetadataToken (row.Association, CodedIndex.HasSemantics);
+ }
+
+ public override void VisitMethodSpecRow (MethodSpecRow row)
+ {
+ WriteMetadataToken (row.Method, CodedIndex.MethodDefOrRef);
+ WriteBlobPointer (row.Instantiation);
+ }
+
+ public override void VisitModuleRow (ModuleRow row)
+ {
+ m_binaryWriter.Write (row.Generation);
+ WriteStringPointer (row.Name);
+ WriteGuidPointer (row.Mvid);
+ WriteGuidPointer (row.EncId);
+ WriteGuidPointer (row.EncBaseId);
+ }
+
+ public override void VisitModuleRefRow (ModuleRefRow row)
+ {
+ WriteStringPointer (row.Name);
+ }
+
+ public override void VisitNestedClassRow (NestedClassRow row)
+ {
+ WriteTablePointer (row.NestedClass, TypeDefTable.RId);
+ WriteTablePointer (row.EnclosingClass, TypeDefTable.RId);
+ }
+
+ public override void VisitParamRow (ParamRow row)
+ {
+ m_binaryWriter.Write ((ushort) row.Flags);
+ m_binaryWriter.Write (row.Sequence);
+ WriteStringPointer (row.Name);
+ }
+
+ public override void VisitParamPtrRow (ParamPtrRow row)
+ {
+ WriteTablePointer (row.Param, ParamTable.RId);
+ }
+
+ public override void VisitPropertyRow (PropertyRow row)
+ {
+ m_binaryWriter.Write ((ushort) row.Flags);
+ WriteStringPointer (row.Name);
+ WriteBlobPointer (row.Type);
+ }
+
+ public override void VisitPropertyMapRow (PropertyMapRow row)
+ {
+ WriteTablePointer (row.Parent, TypeDefTable.RId);
+ WriteTablePointer (row.PropertyList, PropertyTable.RId);
+ }
+
+ public override void VisitPropertyPtrRow (PropertyPtrRow row)
+ {
+ WriteTablePointer (row.Property, PropertyTable.RId);
+ }
+
+ public override void VisitStandAloneSigRow (StandAloneSigRow row)
+ {
+ WriteBlobPointer (row.Signature);
+ }
+
+ public override void VisitTypeDefRow (TypeDefRow row)
+ {
+ m_binaryWriter.Write ((uint) row.Flags);
+ WriteStringPointer (row.Name);
+ WriteStringPointer (row.Namespace);
+ WriteMetadataToken (row.Extends, CodedIndex.TypeDefOrRef);
+ WriteTablePointer (row.FieldList, FieldTable.RId);
+ WriteTablePointer (row.MethodList, MethodTable.RId);
+ }
+
+ public override void VisitTypeRefRow (TypeRefRow row)
+ {
+ WriteMetadataToken (row.ResolutionScope, CodedIndex.ResolutionScope);
+ WriteStringPointer (row.Name);
+ WriteStringPointer (row.Namespace);
+ }
+
+ public override void VisitTypeSpecRow (TypeSpecRow row)
+ {
+ WriteBlobPointer (row.Signature);
+ }
+
+ }
+}
--- /dev/null
+//
+// MetadataStream.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal class MetadataStream : IMetadataVisitable {
+
+ public const string Strings = "#Strings";
+ public const string Tables = "#~";
+ public const string IncrementalTables = "#-";
+ public const string Blob = "#Blob";
+ public const string GUID = "#GUID";
+ public const string UserStrings = "#US";
+
+ MetadataStreamHeader m_header;
+ MetadataHeap m_heap;
+
+ public MetadataStreamHeader Header {
+ get { return m_header; }
+ set { m_header = value; }
+ }
+
+ public MetadataHeap Heap {
+ get { return m_heap; }
+ set { m_heap = value; }
+ }
+
+ internal MetadataStream ()
+ {
+ m_header = new MetadataStreamHeader (this);
+ }
+
+ public void Accept (IMetadataVisitor visitor)
+ {
+ visitor.VisitMetadataStream (this);
+
+ m_header.Accept (visitor);
+ if (m_heap != null)
+ m_heap.Accept (visitor);
+ }
+
+ internal class MetadataStreamHeader : IMetadataVisitable {
+
+ public uint Offset;
+ public uint Size;
+ public string Name;
+
+ private MetadataStream m_stream;
+
+ public MetadataStream Stream {
+ get { return m_stream; }
+ }
+
+ internal MetadataStreamHeader (MetadataStream stream)
+ {
+ m_stream = stream;
+ }
+
+ public void Accept (IMetadataVisitor visitor)
+ {
+ visitor.VisitMetadataStreamHeader (this);
+ }
+ }
+ }
+}
--- /dev/null
+//
+// MetadataStreamCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+
+ internal class MetadataStreamCollection : ICollection, IMetadataVisitable {
+
+ IList m_items;
+
+ BlobHeap m_blobHeap;
+ GuidHeap m_guidHeap;
+ StringsHeap m_stringsHeap;
+ UserStringsHeap m_usHeap;
+ TablesHeap m_tablesHeap;
+
+ public MetadataStream this [int index] {
+ get { return m_items [index] as MetadataStream; }
+ set { m_items [index] = value; }
+ }
+
+ public int Count {
+ get { return m_items.Count; }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ public BlobHeap BlobHeap {
+ get {
+ if (m_blobHeap == null)
+ m_blobHeap = GetHeap (MetadataStream.Blob) as BlobHeap;
+ return m_blobHeap;
+ }
+ }
+
+ public GuidHeap GuidHeap {
+ get {
+ if (m_guidHeap == null)
+ m_guidHeap = GetHeap (MetadataStream.GUID) as GuidHeap;
+ return m_guidHeap;
+ }
+ }
+
+ public StringsHeap StringsHeap {
+ get {
+ if (m_stringsHeap == null)
+ m_stringsHeap = GetHeap (MetadataStream.Strings) as StringsHeap;
+ return m_stringsHeap;
+ }
+ }
+
+ public TablesHeap TablesHeap {
+ get {
+ if (m_tablesHeap == null)
+ m_tablesHeap = GetHeap (MetadataStream.Tables) as TablesHeap;
+ return m_tablesHeap;
+ }
+ }
+
+ public UserStringsHeap UserStringsHeap {
+ get {
+ if (m_usHeap == null)
+ m_usHeap = GetHeap (MetadataStream.UserStrings) as UserStringsHeap;
+ return m_usHeap;
+ }
+ }
+
+ public MetadataStreamCollection ()
+ {
+ m_items = new ArrayList (5);
+ }
+
+ private MetadataHeap GetHeap (string name)
+ {
+ for (int i = 0; i < m_items.Count; i++) {
+ MetadataStream stream = m_items [i] as MetadataStream;
+ if (stream.Heap.Name == name)
+ return stream.Heap;
+ }
+
+ return null;
+ }
+
+ internal void Add (MetadataStream value)
+ {
+ m_items.Add (value);
+ }
+
+ internal void Remove (MetadataStream value)
+ {
+ m_items.Remove (value);
+ }
+
+ public void CopyTo (Array ary, int index)
+ {
+ m_items.CopyTo (ary, index);
+ }
+
+ public IEnumerator GetEnumerator ()
+ {
+ return m_items.GetEnumerator ();
+ }
+
+ public void Accept (IMetadataVisitor visitor)
+ {
+ visitor.VisitMetadataStreamCollection (this);
+
+ for (int i = 0; i < m_items.Count; i++)
+ this [i].Accept (visitor);
+ }
+ }
+}
--- /dev/null
+//
+// MetadataTableReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Jul 17 00:22:32 +0200 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+ using System.IO;
+
+ sealed class MetadataTableReader : BaseMetadataTableVisitor {
+
+ MetadataRoot m_metadataRoot;
+ TablesHeap m_heap;
+ MetadataRowReader m_mrrv;
+ BinaryReader m_binaryReader;
+
+ int [] m_rows = new int [TablesHeap.MaxTableCount];
+
+ public MetadataTableReader (MetadataReader mrv)
+ {
+ m_metadataRoot = mrv.GetMetadataRoot ();
+ m_heap = m_metadataRoot.Streams.TablesHeap;
+ m_binaryReader = new BinaryReader (new MemoryStream (m_heap.Data));
+ m_binaryReader.BaseStream.Position = 24;
+ m_mrrv = new MetadataRowReader (this);
+ }
+
+ public MetadataRoot GetMetadataRoot ()
+ {
+ return m_metadataRoot;
+ }
+
+ public BinaryReader GetReader ()
+ {
+ return m_binaryReader;
+ }
+
+ public override IMetadataRowVisitor GetRowVisitor ()
+ {
+ return m_mrrv;
+ }
+
+ public int GetNumberOfRows (int rid)
+ {
+ return m_rows [rid];
+ }
+
+ public AssemblyTable GetAssemblyTable ()
+ {
+ return (AssemblyTable) m_heap [AssemblyTable.RId];
+ }
+
+ public AssemblyOSTable GetAssemblyOSTable ()
+ {
+ return (AssemblyOSTable) m_heap [AssemblyOSTable.RId];
+ }
+
+ public AssemblyProcessorTable GetAssemblyProcessorTable ()
+ {
+ return (AssemblyProcessorTable) m_heap [AssemblyProcessorTable.RId];
+ }
+
+ public AssemblyRefTable GetAssemblyRefTable ()
+ {
+ return (AssemblyRefTable) m_heap [AssemblyRefTable.RId];
+ }
+
+ public AssemblyRefOSTable GetAssemblyRefOSTable ()
+ {
+ return (AssemblyRefOSTable) m_heap [AssemblyRefOSTable.RId];
+ }
+
+ public AssemblyRefProcessorTable GetAssemblyRefProcessorTable ()
+ {
+ return (AssemblyRefProcessorTable) m_heap [AssemblyRefProcessorTable.RId];
+ }
+
+ public ClassLayoutTable GetClassLayoutTable ()
+ {
+ return (ClassLayoutTable) m_heap [ClassLayoutTable.RId];
+ }
+
+ public ConstantTable GetConstantTable ()
+ {
+ return (ConstantTable) m_heap [ConstantTable.RId];
+ }
+
+ public CustomAttributeTable GetCustomAttributeTable ()
+ {
+ return (CustomAttributeTable) m_heap [CustomAttributeTable.RId];
+ }
+
+ public DeclSecurityTable GetDeclSecurityTable ()
+ {
+ return (DeclSecurityTable) m_heap [DeclSecurityTable.RId];
+ }
+
+ public EventTable GetEventTable ()
+ {
+ return (EventTable) m_heap [EventTable.RId];
+ }
+
+ public EventMapTable GetEventMapTable ()
+ {
+ return (EventMapTable) m_heap [EventMapTable.RId];
+ }
+
+ public EventPtrTable GetEventPtrTable ()
+ {
+ return (EventPtrTable) m_heap [EventPtrTable.RId];
+ }
+
+ public ExportedTypeTable GetExportedTypeTable ()
+ {
+ return (ExportedTypeTable) m_heap [ExportedTypeTable.RId];
+ }
+
+ public FieldTable GetFieldTable ()
+ {
+ return (FieldTable) m_heap [FieldTable.RId];
+ }
+
+ public FieldLayoutTable GetFieldLayoutTable ()
+ {
+ return (FieldLayoutTable) m_heap [FieldLayoutTable.RId];
+ }
+
+ public FieldMarshalTable GetFieldMarshalTable ()
+ {
+ return (FieldMarshalTable) m_heap [FieldMarshalTable.RId];
+ }
+
+ public FieldPtrTable GetFieldPtrTable ()
+ {
+ return (FieldPtrTable) m_heap [FieldPtrTable.RId];
+ }
+
+ public FieldRVATable GetFieldRVATable ()
+ {
+ return (FieldRVATable) m_heap [FieldRVATable.RId];
+ }
+
+ public FileTable GetFileTable ()
+ {
+ return (FileTable) m_heap [FileTable.RId];
+ }
+
+ public GenericParamTable GetGenericParamTable ()
+ {
+ return (GenericParamTable) m_heap [GenericParamTable.RId];
+ }
+
+ public GenericParamConstraintTable GetGenericParamConstraintTable ()
+ {
+ return (GenericParamConstraintTable) m_heap [GenericParamConstraintTable.RId];
+ }
+
+ public ImplMapTable GetImplMapTable ()
+ {
+ return (ImplMapTable) m_heap [ImplMapTable.RId];
+ }
+
+ public InterfaceImplTable GetInterfaceImplTable ()
+ {
+ return (InterfaceImplTable) m_heap [InterfaceImplTable.RId];
+ }
+
+ public ManifestResourceTable GetManifestResourceTable ()
+ {
+ return (ManifestResourceTable) m_heap [ManifestResourceTable.RId];
+ }
+
+ public MemberRefTable GetMemberRefTable ()
+ {
+ return (MemberRefTable) m_heap [MemberRefTable.RId];
+ }
+
+ public MethodTable GetMethodTable ()
+ {
+ return (MethodTable) m_heap [MethodTable.RId];
+ }
+
+ public MethodImplTable GetMethodImplTable ()
+ {
+ return (MethodImplTable) m_heap [MethodImplTable.RId];
+ }
+
+ public MethodPtrTable GetMethodPtrTable ()
+ {
+ return (MethodPtrTable) m_heap [MethodPtrTable.RId];
+ }
+
+ public MethodSemanticsTable GetMethodSemanticsTable ()
+ {
+ return (MethodSemanticsTable) m_heap [MethodSemanticsTable.RId];
+ }
+
+ public MethodSpecTable GetMethodSpecTable ()
+ {
+ return (MethodSpecTable) m_heap [MethodSpecTable.RId];
+ }
+
+ public ModuleTable GetModuleTable ()
+ {
+ return (ModuleTable) m_heap [ModuleTable.RId];
+ }
+
+ public ModuleRefTable GetModuleRefTable ()
+ {
+ return (ModuleRefTable) m_heap [ModuleRefTable.RId];
+ }
+
+ public NestedClassTable GetNestedClassTable ()
+ {
+ return (NestedClassTable) m_heap [NestedClassTable.RId];
+ }
+
+ public ParamTable GetParamTable ()
+ {
+ return (ParamTable) m_heap [ParamTable.RId];
+ }
+
+ public ParamPtrTable GetParamPtrTable ()
+ {
+ return (ParamPtrTable) m_heap [ParamPtrTable.RId];
+ }
+
+ public PropertyTable GetPropertyTable ()
+ {
+ return (PropertyTable) m_heap [PropertyTable.RId];
+ }
+
+ public PropertyMapTable GetPropertyMapTable ()
+ {
+ return (PropertyMapTable) m_heap [PropertyMapTable.RId];
+ }
+
+ public PropertyPtrTable GetPropertyPtrTable ()
+ {
+ return (PropertyPtrTable) m_heap [PropertyPtrTable.RId];
+ }
+
+ public StandAloneSigTable GetStandAloneSigTable ()
+ {
+ return (StandAloneSigTable) m_heap [StandAloneSigTable.RId];
+ }
+
+ public TypeDefTable GetTypeDefTable ()
+ {
+ return (TypeDefTable) m_heap [TypeDefTable.RId];
+ }
+
+ public TypeRefTable GetTypeRefTable ()
+ {
+ return (TypeRefTable) m_heap [TypeRefTable.RId];
+ }
+
+ public TypeSpecTable GetTypeSpecTable ()
+ {
+ return (TypeSpecTable) m_heap [TypeSpecTable.RId];
+ }
+
+ public override void VisitTableCollection (TableCollection coll)
+ {
+ if (m_heap.HasTable (ModuleTable.RId)) {
+ coll.Add (new ModuleTable ());
+ m_rows [ModuleTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (TypeRefTable.RId)) {
+ coll.Add (new TypeRefTable ());
+ m_rows [TypeRefTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (TypeDefTable.RId)) {
+ coll.Add (new TypeDefTable ());
+ m_rows [TypeDefTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (FieldPtrTable.RId)) {
+ coll.Add (new FieldPtrTable ());
+ m_rows [FieldPtrTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (FieldTable.RId)) {
+ coll.Add (new FieldTable ());
+ m_rows [FieldTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (MethodPtrTable.RId)) {
+ coll.Add (new MethodPtrTable ());
+ m_rows [MethodPtrTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (MethodTable.RId)) {
+ coll.Add (new MethodTable ());
+ m_rows [MethodTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (ParamPtrTable.RId)) {
+ coll.Add (new ParamPtrTable ());
+ m_rows [ParamPtrTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (ParamTable.RId)) {
+ coll.Add (new ParamTable ());
+ m_rows [ParamTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (InterfaceImplTable.RId)) {
+ coll.Add (new InterfaceImplTable ());
+ m_rows [InterfaceImplTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (MemberRefTable.RId)) {
+ coll.Add (new MemberRefTable ());
+ m_rows [MemberRefTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (ConstantTable.RId)) {
+ coll.Add (new ConstantTable ());
+ m_rows [ConstantTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (CustomAttributeTable.RId)) {
+ coll.Add (new CustomAttributeTable ());
+ m_rows [CustomAttributeTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (FieldMarshalTable.RId)) {
+ coll.Add (new FieldMarshalTable ());
+ m_rows [FieldMarshalTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (DeclSecurityTable.RId)) {
+ coll.Add (new DeclSecurityTable ());
+ m_rows [DeclSecurityTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (ClassLayoutTable.RId)) {
+ coll.Add (new ClassLayoutTable ());
+ m_rows [ClassLayoutTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (FieldLayoutTable.RId)) {
+ coll.Add (new FieldLayoutTable ());
+ m_rows [FieldLayoutTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (StandAloneSigTable.RId)) {
+ coll.Add (new StandAloneSigTable ());
+ m_rows [StandAloneSigTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (EventMapTable.RId)) {
+ coll.Add (new EventMapTable ());
+ m_rows [EventMapTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (EventPtrTable.RId)) {
+ coll.Add (new EventPtrTable ());
+ m_rows [EventPtrTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (EventTable.RId)) {
+ coll.Add (new EventTable ());
+ m_rows [EventTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (PropertyMapTable.RId)) {
+ coll.Add (new PropertyMapTable ());
+ m_rows [PropertyMapTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (PropertyPtrTable.RId)) {
+ coll.Add (new PropertyPtrTable ());
+ m_rows [PropertyPtrTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (PropertyTable.RId)) {
+ coll.Add (new PropertyTable ());
+ m_rows [PropertyTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (MethodSemanticsTable.RId)) {
+ coll.Add (new MethodSemanticsTable ());
+ m_rows [MethodSemanticsTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (MethodImplTable.RId)) {
+ coll.Add (new MethodImplTable ());
+ m_rows [MethodImplTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (ModuleRefTable.RId)) {
+ coll.Add (new ModuleRefTable ());
+ m_rows [ModuleRefTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (TypeSpecTable.RId)) {
+ coll.Add (new TypeSpecTable ());
+ m_rows [TypeSpecTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (ImplMapTable.RId)) {
+ coll.Add (new ImplMapTable ());
+ m_rows [ImplMapTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (FieldRVATable.RId)) {
+ coll.Add (new FieldRVATable ());
+ m_rows [FieldRVATable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (AssemblyTable.RId)) {
+ coll.Add (new AssemblyTable ());
+ m_rows [AssemblyTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (AssemblyProcessorTable.RId)) {
+ coll.Add (new AssemblyProcessorTable ());
+ m_rows [AssemblyProcessorTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (AssemblyOSTable.RId)) {
+ coll.Add (new AssemblyOSTable ());
+ m_rows [AssemblyOSTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (AssemblyRefTable.RId)) {
+ coll.Add (new AssemblyRefTable ());
+ m_rows [AssemblyRefTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (AssemblyRefProcessorTable.RId)) {
+ coll.Add (new AssemblyRefProcessorTable ());
+ m_rows [AssemblyRefProcessorTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (AssemblyRefOSTable.RId)) {
+ coll.Add (new AssemblyRefOSTable ());
+ m_rows [AssemblyRefOSTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (FileTable.RId)) {
+ coll.Add (new FileTable ());
+ m_rows [FileTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (ExportedTypeTable.RId)) {
+ coll.Add (new ExportedTypeTable ());
+ m_rows [ExportedTypeTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (ManifestResourceTable.RId)) {
+ coll.Add (new ManifestResourceTable ());
+ m_rows [ManifestResourceTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (NestedClassTable.RId)) {
+ coll.Add (new NestedClassTable ());
+ m_rows [NestedClassTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (GenericParamTable.RId)) {
+ coll.Add (new GenericParamTable ());
+ m_rows [GenericParamTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (MethodSpecTable.RId)) {
+ coll.Add (new MethodSpecTable ());
+ m_rows [MethodSpecTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ if (m_heap.HasTable (GenericParamConstraintTable.RId)) {
+ coll.Add (new GenericParamConstraintTable ());
+ m_rows [GenericParamConstraintTable.RId] = m_binaryReader.ReadInt32 ();
+ }
+ }
+
+ public override void VisitAssemblyTable (AssemblyTable table)
+ {
+ int number = m_rows [AssemblyTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new AssemblyRow ());
+ }
+ public override void VisitAssemblyOSTable (AssemblyOSTable table)
+ {
+ int number = m_rows [AssemblyOSTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new AssemblyOSRow ());
+ }
+ public override void VisitAssemblyProcessorTable (AssemblyProcessorTable table)
+ {
+ int number = m_rows [AssemblyProcessorTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new AssemblyProcessorRow ());
+ }
+ public override void VisitAssemblyRefTable (AssemblyRefTable table)
+ {
+ int number = m_rows [AssemblyRefTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new AssemblyRefRow ());
+ }
+ public override void VisitAssemblyRefOSTable (AssemblyRefOSTable table)
+ {
+ int number = m_rows [AssemblyRefOSTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new AssemblyRefOSRow ());
+ }
+ public override void VisitAssemblyRefProcessorTable (AssemblyRefProcessorTable table)
+ {
+ int number = m_rows [AssemblyRefProcessorTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new AssemblyRefProcessorRow ());
+ }
+ public override void VisitClassLayoutTable (ClassLayoutTable table)
+ {
+ int number = m_rows [ClassLayoutTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new ClassLayoutRow ());
+ }
+ public override void VisitConstantTable (ConstantTable table)
+ {
+ int number = m_rows [ConstantTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new ConstantRow ());
+ }
+ public override void VisitCustomAttributeTable (CustomAttributeTable table)
+ {
+ int number = m_rows [CustomAttributeTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new CustomAttributeRow ());
+ }
+ public override void VisitDeclSecurityTable (DeclSecurityTable table)
+ {
+ int number = m_rows [DeclSecurityTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new DeclSecurityRow ());
+ }
+ public override void VisitEventTable (EventTable table)
+ {
+ int number = m_rows [EventTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new EventRow ());
+ }
+ public override void VisitEventMapTable (EventMapTable table)
+ {
+ int number = m_rows [EventMapTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new EventMapRow ());
+ }
+ public override void VisitEventPtrTable (EventPtrTable table)
+ {
+ int number = m_rows [EventPtrTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new EventPtrRow ());
+ }
+ public override void VisitExportedTypeTable (ExportedTypeTable table)
+ {
+ int number = m_rows [ExportedTypeTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new ExportedTypeRow ());
+ }
+ public override void VisitFieldTable (FieldTable table)
+ {
+ int number = m_rows [FieldTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new FieldRow ());
+ }
+ public override void VisitFieldLayoutTable (FieldLayoutTable table)
+ {
+ int number = m_rows [FieldLayoutTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new FieldLayoutRow ());
+ }
+ public override void VisitFieldMarshalTable (FieldMarshalTable table)
+ {
+ int number = m_rows [FieldMarshalTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new FieldMarshalRow ());
+ }
+ public override void VisitFieldPtrTable (FieldPtrTable table)
+ {
+ int number = m_rows [FieldPtrTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new FieldPtrRow ());
+ }
+ public override void VisitFieldRVATable (FieldRVATable table)
+ {
+ int number = m_rows [FieldRVATable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new FieldRVARow ());
+ }
+ public override void VisitFileTable (FileTable table)
+ {
+ int number = m_rows [FileTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new FileRow ());
+ }
+ public override void VisitGenericParamTable (GenericParamTable table)
+ {
+ int number = m_rows [GenericParamTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new GenericParamRow ());
+ }
+ public override void VisitGenericParamConstraintTable (GenericParamConstraintTable table)
+ {
+ int number = m_rows [GenericParamConstraintTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new GenericParamConstraintRow ());
+ }
+ public override void VisitImplMapTable (ImplMapTable table)
+ {
+ int number = m_rows [ImplMapTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new ImplMapRow ());
+ }
+ public override void VisitInterfaceImplTable (InterfaceImplTable table)
+ {
+ int number = m_rows [InterfaceImplTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new InterfaceImplRow ());
+ }
+ public override void VisitManifestResourceTable (ManifestResourceTable table)
+ {
+ int number = m_rows [ManifestResourceTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new ManifestResourceRow ());
+ }
+ public override void VisitMemberRefTable (MemberRefTable table)
+ {
+ int number = m_rows [MemberRefTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new MemberRefRow ());
+ }
+ public override void VisitMethodTable (MethodTable table)
+ {
+ int number = m_rows [MethodTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new MethodRow ());
+ }
+ public override void VisitMethodImplTable (MethodImplTable table)
+ {
+ int number = m_rows [MethodImplTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new MethodImplRow ());
+ }
+ public override void VisitMethodPtrTable (MethodPtrTable table)
+ {
+ int number = m_rows [MethodPtrTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new MethodPtrRow ());
+ }
+ public override void VisitMethodSemanticsTable (MethodSemanticsTable table)
+ {
+ int number = m_rows [MethodSemanticsTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new MethodSemanticsRow ());
+ }
+ public override void VisitMethodSpecTable (MethodSpecTable table)
+ {
+ int number = m_rows [MethodSpecTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new MethodSpecRow ());
+ }
+ public override void VisitModuleTable (ModuleTable table)
+ {
+ int number = m_rows [ModuleTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new ModuleRow ());
+ }
+ public override void VisitModuleRefTable (ModuleRefTable table)
+ {
+ int number = m_rows [ModuleRefTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new ModuleRefRow ());
+ }
+ public override void VisitNestedClassTable (NestedClassTable table)
+ {
+ int number = m_rows [NestedClassTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new NestedClassRow ());
+ }
+ public override void VisitParamTable (ParamTable table)
+ {
+ int number = m_rows [ParamTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new ParamRow ());
+ }
+ public override void VisitParamPtrTable (ParamPtrTable table)
+ {
+ int number = m_rows [ParamPtrTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new ParamPtrRow ());
+ }
+ public override void VisitPropertyTable (PropertyTable table)
+ {
+ int number = m_rows [PropertyTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new PropertyRow ());
+ }
+ public override void VisitPropertyMapTable (PropertyMapTable table)
+ {
+ int number = m_rows [PropertyMapTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new PropertyMapRow ());
+ }
+ public override void VisitPropertyPtrTable (PropertyPtrTable table)
+ {
+ int number = m_rows [PropertyPtrTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new PropertyPtrRow ());
+ }
+ public override void VisitStandAloneSigTable (StandAloneSigTable table)
+ {
+ int number = m_rows [StandAloneSigTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new StandAloneSigRow ());
+ }
+ public override void VisitTypeDefTable (TypeDefTable table)
+ {
+ int number = m_rows [TypeDefTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new TypeDefRow ());
+ }
+ public override void VisitTypeRefTable (TypeRefTable table)
+ {
+ int number = m_rows [TypeRefTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new TypeRefRow ());
+ }
+ public override void VisitTypeSpecTable (TypeSpecTable table)
+ {
+ int number = m_rows [TypeSpecTable.RId];
+ table.Rows = new RowCollection (number);
+ for (int i = 0; i < number; i++)
+ table.Rows.Add (new TypeSpecRow ());
+ }
+ }
+}
--- /dev/null
+//
+// MetadataTableWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Thu Feb 22 14:39:38 CET 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Binary;
+
+ internal sealed class MetadataTableWriter : BaseMetadataTableVisitor {
+
+ MetadataRoot m_root;
+ TablesHeap m_heap;
+ MetadataRowWriter m_mrrw;
+ MemoryBinaryWriter m_binaryWriter;
+
+ public MetadataTableWriter (MetadataWriter mrv, MemoryBinaryWriter writer)
+ {
+ m_root = mrv.GetMetadataRoot ();
+ m_heap = m_root.Streams.TablesHeap;
+ m_binaryWriter = writer;
+ m_mrrw = new MetadataRowWriter (this);
+ }
+
+ public MetadataRoot GetMetadataRoot ()
+ {
+ return m_root;
+ }
+
+ public override IMetadataRowVisitor GetRowVisitor ()
+ {
+ return m_mrrw;
+ }
+
+ public MemoryBinaryWriter GetWriter ()
+ {
+ return m_binaryWriter;
+ }
+
+ void InitializeTable (IMetadataTable table)
+ {
+ table.Rows = new RowCollection ();
+ m_heap.Valid |= 1L << table.Id;
+ m_heap.Tables.Add (table);
+ }
+
+ void WriteCount (int rid)
+ {
+ if (m_heap.HasTable (rid))
+ m_binaryWriter.Write (m_heap [rid].Rows.Count);
+ }
+
+ public AssemblyTable GetAssemblyTable ()
+ {
+ AssemblyTable table = m_heap [AssemblyTable.RId] as AssemblyTable;
+ if (table != null)
+ return table;
+
+ table = new AssemblyTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public AssemblyOSTable GetAssemblyOSTable ()
+ {
+ AssemblyOSTable table = m_heap [AssemblyOSTable.RId] as AssemblyOSTable;
+ if (table != null)
+ return table;
+
+ table = new AssemblyOSTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public AssemblyProcessorTable GetAssemblyProcessorTable ()
+ {
+ AssemblyProcessorTable table = m_heap [AssemblyProcessorTable.RId] as AssemblyProcessorTable;
+ if (table != null)
+ return table;
+
+ table = new AssemblyProcessorTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public AssemblyRefTable GetAssemblyRefTable ()
+ {
+ AssemblyRefTable table = m_heap [AssemblyRefTable.RId] as AssemblyRefTable;
+ if (table != null)
+ return table;
+
+ table = new AssemblyRefTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public AssemblyRefOSTable GetAssemblyRefOSTable ()
+ {
+ AssemblyRefOSTable table = m_heap [AssemblyRefOSTable.RId] as AssemblyRefOSTable;
+ if (table != null)
+ return table;
+
+ table = new AssemblyRefOSTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public AssemblyRefProcessorTable GetAssemblyRefProcessorTable ()
+ {
+ AssemblyRefProcessorTable table = m_heap [AssemblyRefProcessorTable.RId] as AssemblyRefProcessorTable;
+ if (table != null)
+ return table;
+
+ table = new AssemblyRefProcessorTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public ClassLayoutTable GetClassLayoutTable ()
+ {
+ ClassLayoutTable table = m_heap [ClassLayoutTable.RId] as ClassLayoutTable;
+ if (table != null)
+ return table;
+
+ table = new ClassLayoutTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public ConstantTable GetConstantTable ()
+ {
+ ConstantTable table = m_heap [ConstantTable.RId] as ConstantTable;
+ if (table != null)
+ return table;
+
+ table = new ConstantTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public CustomAttributeTable GetCustomAttributeTable ()
+ {
+ CustomAttributeTable table = m_heap [CustomAttributeTable.RId] as CustomAttributeTable;
+ if (table != null)
+ return table;
+
+ table = new CustomAttributeTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public DeclSecurityTable GetDeclSecurityTable ()
+ {
+ DeclSecurityTable table = m_heap [DeclSecurityTable.RId] as DeclSecurityTable;
+ if (table != null)
+ return table;
+
+ table = new DeclSecurityTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public EventTable GetEventTable ()
+ {
+ EventTable table = m_heap [EventTable.RId] as EventTable;
+ if (table != null)
+ return table;
+
+ table = new EventTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public EventMapTable GetEventMapTable ()
+ {
+ EventMapTable table = m_heap [EventMapTable.RId] as EventMapTable;
+ if (table != null)
+ return table;
+
+ table = new EventMapTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public EventPtrTable GetEventPtrTable ()
+ {
+ EventPtrTable table = m_heap [EventPtrTable.RId] as EventPtrTable;
+ if (table != null)
+ return table;
+
+ table = new EventPtrTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public ExportedTypeTable GetExportedTypeTable ()
+ {
+ ExportedTypeTable table = m_heap [ExportedTypeTable.RId] as ExportedTypeTable;
+ if (table != null)
+ return table;
+
+ table = new ExportedTypeTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public FieldTable GetFieldTable ()
+ {
+ FieldTable table = m_heap [FieldTable.RId] as FieldTable;
+ if (table != null)
+ return table;
+
+ table = new FieldTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public FieldLayoutTable GetFieldLayoutTable ()
+ {
+ FieldLayoutTable table = m_heap [FieldLayoutTable.RId] as FieldLayoutTable;
+ if (table != null)
+ return table;
+
+ table = new FieldLayoutTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public FieldMarshalTable GetFieldMarshalTable ()
+ {
+ FieldMarshalTable table = m_heap [FieldMarshalTable.RId] as FieldMarshalTable;
+ if (table != null)
+ return table;
+
+ table = new FieldMarshalTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public FieldPtrTable GetFieldPtrTable ()
+ {
+ FieldPtrTable table = m_heap [FieldPtrTable.RId] as FieldPtrTable;
+ if (table != null)
+ return table;
+
+ table = new FieldPtrTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public FieldRVATable GetFieldRVATable ()
+ {
+ FieldRVATable table = m_heap [FieldRVATable.RId] as FieldRVATable;
+ if (table != null)
+ return table;
+
+ table = new FieldRVATable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public FileTable GetFileTable ()
+ {
+ FileTable table = m_heap [FileTable.RId] as FileTable;
+ if (table != null)
+ return table;
+
+ table = new FileTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public GenericParamTable GetGenericParamTable ()
+ {
+ GenericParamTable table = m_heap [GenericParamTable.RId] as GenericParamTable;
+ if (table != null)
+ return table;
+
+ table = new GenericParamTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public GenericParamConstraintTable GetGenericParamConstraintTable ()
+ {
+ GenericParamConstraintTable table = m_heap [GenericParamConstraintTable.RId] as GenericParamConstraintTable;
+ if (table != null)
+ return table;
+
+ table = new GenericParamConstraintTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public ImplMapTable GetImplMapTable ()
+ {
+ ImplMapTable table = m_heap [ImplMapTable.RId] as ImplMapTable;
+ if (table != null)
+ return table;
+
+ table = new ImplMapTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public InterfaceImplTable GetInterfaceImplTable ()
+ {
+ InterfaceImplTable table = m_heap [InterfaceImplTable.RId] as InterfaceImplTable;
+ if (table != null)
+ return table;
+
+ table = new InterfaceImplTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public ManifestResourceTable GetManifestResourceTable ()
+ {
+ ManifestResourceTable table = m_heap [ManifestResourceTable.RId] as ManifestResourceTable;
+ if (table != null)
+ return table;
+
+ table = new ManifestResourceTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public MemberRefTable GetMemberRefTable ()
+ {
+ MemberRefTable table = m_heap [MemberRefTable.RId] as MemberRefTable;
+ if (table != null)
+ return table;
+
+ table = new MemberRefTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public MethodTable GetMethodTable ()
+ {
+ MethodTable table = m_heap [MethodTable.RId] as MethodTable;
+ if (table != null)
+ return table;
+
+ table = new MethodTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public MethodImplTable GetMethodImplTable ()
+ {
+ MethodImplTable table = m_heap [MethodImplTable.RId] as MethodImplTable;
+ if (table != null)
+ return table;
+
+ table = new MethodImplTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public MethodPtrTable GetMethodPtrTable ()
+ {
+ MethodPtrTable table = m_heap [MethodPtrTable.RId] as MethodPtrTable;
+ if (table != null)
+ return table;
+
+ table = new MethodPtrTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public MethodSemanticsTable GetMethodSemanticsTable ()
+ {
+ MethodSemanticsTable table = m_heap [MethodSemanticsTable.RId] as MethodSemanticsTable;
+ if (table != null)
+ return table;
+
+ table = new MethodSemanticsTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public MethodSpecTable GetMethodSpecTable ()
+ {
+ MethodSpecTable table = m_heap [MethodSpecTable.RId] as MethodSpecTable;
+ if (table != null)
+ return table;
+
+ table = new MethodSpecTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public ModuleTable GetModuleTable ()
+ {
+ ModuleTable table = m_heap [ModuleTable.RId] as ModuleTable;
+ if (table != null)
+ return table;
+
+ table = new ModuleTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public ModuleRefTable GetModuleRefTable ()
+ {
+ ModuleRefTable table = m_heap [ModuleRefTable.RId] as ModuleRefTable;
+ if (table != null)
+ return table;
+
+ table = new ModuleRefTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public NestedClassTable GetNestedClassTable ()
+ {
+ NestedClassTable table = m_heap [NestedClassTable.RId] as NestedClassTable;
+ if (table != null)
+ return table;
+
+ table = new NestedClassTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public ParamTable GetParamTable ()
+ {
+ ParamTable table = m_heap [ParamTable.RId] as ParamTable;
+ if (table != null)
+ return table;
+
+ table = new ParamTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public ParamPtrTable GetParamPtrTable ()
+ {
+ ParamPtrTable table = m_heap [ParamPtrTable.RId] as ParamPtrTable;
+ if (table != null)
+ return table;
+
+ table = new ParamPtrTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public PropertyTable GetPropertyTable ()
+ {
+ PropertyTable table = m_heap [PropertyTable.RId] as PropertyTable;
+ if (table != null)
+ return table;
+
+ table = new PropertyTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public PropertyMapTable GetPropertyMapTable ()
+ {
+ PropertyMapTable table = m_heap [PropertyMapTable.RId] as PropertyMapTable;
+ if (table != null)
+ return table;
+
+ table = new PropertyMapTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public PropertyPtrTable GetPropertyPtrTable ()
+ {
+ PropertyPtrTable table = m_heap [PropertyPtrTable.RId] as PropertyPtrTable;
+ if (table != null)
+ return table;
+
+ table = new PropertyPtrTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public StandAloneSigTable GetStandAloneSigTable ()
+ {
+ StandAloneSigTable table = m_heap [StandAloneSigTable.RId] as StandAloneSigTable;
+ if (table != null)
+ return table;
+
+ table = new StandAloneSigTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public TypeDefTable GetTypeDefTable ()
+ {
+ TypeDefTable table = m_heap [TypeDefTable.RId] as TypeDefTable;
+ if (table != null)
+ return table;
+
+ table = new TypeDefTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public TypeRefTable GetTypeRefTable ()
+ {
+ TypeRefTable table = m_heap [TypeRefTable.RId] as TypeRefTable;
+ if (table != null)
+ return table;
+
+ table = new TypeRefTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public TypeSpecTable GetTypeSpecTable ()
+ {
+ TypeSpecTable table = m_heap [TypeSpecTable.RId] as TypeSpecTable;
+ if (table != null)
+ return table;
+
+ table = new TypeSpecTable ();
+ InitializeTable (table);
+ return table;
+ }
+
+ public override void VisitTableCollection (TableCollection coll)
+ {
+ WriteCount (ModuleTable.RId);
+ WriteCount (TypeRefTable.RId);
+ WriteCount (TypeDefTable.RId);
+ WriteCount (FieldPtrTable.RId);
+ WriteCount (FieldTable.RId);
+ WriteCount (MethodPtrTable.RId);
+ WriteCount (MethodTable.RId);
+ WriteCount (ParamPtrTable.RId);
+ WriteCount (ParamTable.RId);
+ WriteCount (InterfaceImplTable.RId);
+ WriteCount (MemberRefTable.RId);
+ WriteCount (ConstantTable.RId);
+ WriteCount (CustomAttributeTable.RId);
+ WriteCount (FieldMarshalTable.RId);
+ WriteCount (DeclSecurityTable.RId);
+ WriteCount (ClassLayoutTable.RId);
+ WriteCount (FieldLayoutTable.RId);
+ WriteCount (StandAloneSigTable.RId);
+ WriteCount (EventMapTable.RId);
+ WriteCount (EventPtrTable.RId);
+ WriteCount (EventTable.RId);
+ WriteCount (PropertyMapTable.RId);
+ WriteCount (PropertyPtrTable.RId);
+ WriteCount (PropertyTable.RId);
+ WriteCount (MethodSemanticsTable.RId);
+ WriteCount (MethodImplTable.RId);
+ WriteCount (ModuleRefTable.RId);
+ WriteCount (TypeSpecTable.RId);
+ WriteCount (ImplMapTable.RId);
+ WriteCount (FieldRVATable.RId);
+ WriteCount (AssemblyTable.RId);
+ WriteCount (AssemblyProcessorTable.RId);
+ WriteCount (AssemblyOSTable.RId);
+ WriteCount (AssemblyRefTable.RId);
+ WriteCount (AssemblyRefProcessorTable.RId);
+ WriteCount (AssemblyRefOSTable.RId);
+ WriteCount (FileTable.RId);
+ WriteCount (ExportedTypeTable.RId);
+ WriteCount (ManifestResourceTable.RId);
+ WriteCount (NestedClassTable.RId);
+ WriteCount (GenericParamTable.RId);
+ WriteCount (MethodSpecTable.RId);
+ WriteCount (GenericParamConstraintTable.RId);
+ }
+ }
+}
--- /dev/null
+//
+// MetadataToken.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal struct MetadataToken {
+
+ uint m_rid;
+ TokenType m_type;
+
+ public uint RID {
+ get { return m_rid; }
+ }
+
+ public TokenType TokenType {
+ get { return m_type; }
+ }
+
+ public static readonly MetadataToken Zero = new MetadataToken ((TokenType) 0, 0);
+
+ public MetadataToken (int token)
+ {
+ m_type = (TokenType) (token & 0xff000000);
+ m_rid = (uint) token & 0x00ffffff;
+ }
+
+ public MetadataToken (TokenType table, uint rid)
+ {
+ m_type = table;
+ m_rid = rid;
+ }
+
+ internal static MetadataToken FromMetadataRow (TokenType table, int rowIndex)
+ {
+ return new MetadataToken (table, (uint) rowIndex + 1);
+ }
+
+ public uint ToUInt ()
+ {
+ return (uint) m_type | m_rid;
+ }
+
+ public override int GetHashCode ()
+ {
+ return (int) ToUInt ();
+ }
+
+ public override bool Equals (object other)
+ {
+ if (other is MetadataToken)
+ return Equals ((MetadataToken) other);
+
+ return false;
+ }
+
+ private bool Equals (MetadataToken other)
+ {
+ return other.m_rid == m_rid && other.m_type == m_type;
+ }
+
+ public static bool operator == (MetadataToken one, MetadataToken other)
+ {
+ return one.Equals (other);
+ }
+
+ public static bool operator != (MetadataToken one, MetadataToken other)
+ {
+ return !one.Equals (other);
+ }
+
+ public override string ToString ()
+ {
+ return string.Format ("{0} [0x{1}]",
+ m_type, m_rid.ToString ("x4"));
+ }
+ }
+}
--- /dev/null
+//
+// MetadataWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+ using System.IO;
+ using System.Text;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Binary;
+
+ internal sealed class MetadataWriter : BaseMetadataVisitor {
+
+ AssemblyDefinition m_assembly;
+ MetadataRoot m_root;
+ TargetRuntime m_runtime;
+ ImageWriter m_imgWriter;
+ MetadataTableWriter m_tableWriter;
+ MemoryBinaryWriter m_binaryWriter;
+
+ IDictionary m_stringCache;
+ MemoryBinaryWriter m_stringWriter;
+
+ IDictionary m_guidCache;
+ MemoryBinaryWriter m_guidWriter;
+
+ IDictionary m_usCache;
+ MemoryBinaryWriter m_usWriter;
+
+ IDictionary m_blobCache;
+ MemoryBinaryWriter m_blobWriter;
+
+ MemoryBinaryWriter m_tWriter;
+
+ MemoryBinaryWriter m_cilWriter;
+
+ MemoryBinaryWriter m_fieldDataWriter;
+ MemoryBinaryWriter m_resWriter;
+
+ uint m_mdStart, m_mdSize;
+ uint m_resStart, m_resSize;
+ uint m_snsStart, m_snsSize;
+ uint m_debugHeaderStart;
+ uint m_imporTableStart;
+
+ uint m_entryPointToken;
+
+ RVA m_cursor = new RVA (0x2050);
+
+ public MemoryBinaryWriter CilWriter {
+ get { return m_cilWriter; }
+ }
+
+ public MemoryBinaryWriter StringWriter {
+ get { return m_stringWriter; }
+ }
+
+ public MemoryBinaryWriter GuidWriter {
+ get { return m_guidWriter; }
+ }
+
+ public MemoryBinaryWriter UserStringWriter {
+ get { return m_usWriter; }
+ }
+
+ public MemoryBinaryWriter BlobWriter {
+ get { return m_blobWriter; }
+ }
+
+ public uint DebugHeaderPosition {
+ get { return m_debugHeaderStart; }
+ }
+
+ public uint ImportTablePosition {
+ get { return m_imporTableStart; }
+ }
+
+ public uint EntryPointToken {
+ get { return m_entryPointToken; }
+ set { m_entryPointToken = value; }
+ }
+
+ public TargetRuntime TargetRuntime {
+ get { return m_runtime; }
+ }
+
+ public MetadataWriter (AssemblyDefinition asm, MetadataRoot root,
+ AssemblyKind kind, TargetRuntime rt, BinaryWriter writer)
+ {
+ m_assembly = asm;
+ m_root = root;
+ m_runtime = rt;
+ m_imgWriter = new ImageWriter (this, kind, writer);
+ m_binaryWriter = m_imgWriter.GetTextWriter ();
+
+ m_stringCache = new Hashtable ();
+ m_stringWriter = new MemoryBinaryWriter (Encoding.UTF8);
+ m_stringWriter.Write ((byte) 0);
+
+ m_guidCache = new Hashtable ();
+ m_guidWriter = new MemoryBinaryWriter ();
+
+ m_usCache = new Hashtable ();
+ m_usWriter = new MemoryBinaryWriter (Encoding.Unicode);
+ m_usWriter.Write ((byte) 0);
+
+ m_blobCache = new Hashtable (ByteArrayEqualityComparer.Instance, ByteArrayEqualityComparer.Instance);
+ m_blobWriter = new MemoryBinaryWriter ();
+ m_blobWriter.Write ((byte) 0);
+
+ m_tWriter = new MemoryBinaryWriter ();
+ m_tableWriter = new MetadataTableWriter (this, m_tWriter);
+
+ m_cilWriter = new MemoryBinaryWriter ();
+
+ m_fieldDataWriter = new MemoryBinaryWriter ();
+ m_resWriter = new MemoryBinaryWriter ();
+ }
+
+ public MetadataRoot GetMetadataRoot ()
+ {
+ return m_root;
+ }
+
+ public ImageWriter GetImageWriter ()
+ {
+ return m_imgWriter;
+ }
+
+ public MemoryBinaryWriter GetWriter ()
+ {
+ return m_binaryWriter;
+ }
+
+ public MetadataTableWriter GetTableVisitor ()
+ {
+ return m_tableWriter;
+ }
+
+ public void AddData (int length)
+ {
+ m_cursor += new RVA ((uint) length);
+ }
+
+ public RVA GetDataCursor ()
+ {
+ return m_cursor;
+ }
+
+ public uint AddString (string str)
+ {
+ if (str == null || str.Length == 0)
+ return 0;
+
+ if (m_stringCache.Contains (str))
+ return (uint) m_stringCache [str];
+
+ uint pointer = (uint) m_stringWriter.BaseStream.Position;
+ m_stringCache [str] = pointer;
+ m_stringWriter.Write (Encoding.UTF8.GetBytes (str));
+ m_stringWriter.Write ('\0');
+ return pointer;
+ }
+
+ public uint AddBlob (byte [] data)
+ {
+ if (data == null || data.Length == 0)
+ return 0;
+
+ object cached = m_blobCache [data];
+ if (cached != null)
+ return (uint) cached;
+
+ uint pointer = (uint) m_blobWriter.BaseStream.Position;
+ m_blobCache [data] = pointer;
+ Utilities.WriteCompressedInteger (m_blobWriter, data.Length);
+ m_blobWriter.Write (data);
+ return pointer;
+ }
+
+ public uint AddGuid (Guid g)
+ {
+ if (m_guidCache.Contains (g))
+ return (uint) m_guidCache [g];
+
+ uint pointer = (uint) m_guidWriter.BaseStream.Position;
+ m_guidCache [g] = pointer;
+ m_guidWriter.Write (g.ToByteArray ());
+ return pointer + 1;
+ }
+
+ public uint AddUserString (string str)
+ {
+ if (str == null)
+ return 0;
+
+ if (m_usCache.Contains (str))
+ return (uint) m_usCache [str];
+
+ uint pointer = (uint) m_usWriter.BaseStream.Position;
+ m_usCache [str] = pointer;
+ byte [] us = Encoding.Unicode.GetBytes (str);
+ Utilities.WriteCompressedInteger (m_usWriter, us.Length + 1);
+ m_usWriter.Write (us);
+ m_usWriter.Write ((byte) (RequiresSpecialHandling (us) ? 1 : 0));
+ return pointer;
+ }
+
+ static bool RequiresSpecialHandling (byte [] chars)
+ {
+ for (int i = 0; i < chars.Length; i++) {
+ byte c = chars [i];
+ if ((i % 2) == 1)
+ if (c != 0)
+ return true;
+
+ if (InRange (0x01, 0x08, c) ||
+ InRange (0x0e, 0x1f, c) ||
+ c == 0x27 ||
+ c == 0x2d ||
+ c == 0x7f) {
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ static bool InRange (int left, int right, int value)
+ {
+ return left <= value && value <= right;
+ }
+
+ void CreateStream (string name)
+ {
+ MetadataStream stream = new MetadataStream ();
+ stream.Header.Name = name;
+ stream.Heap = MetadataHeap.HeapFactory (stream);
+ m_root.Streams.Add (stream);
+ }
+
+ void SetHeapSize (MetadataHeap heap, MemoryBinaryWriter data, byte flag)
+ {
+ if (data.BaseStream.Length > 65536) {
+ m_root.Streams.TablesHeap.HeapSizes |= flag;
+ heap.IndexSize = 4;
+ } else
+ heap.IndexSize = 2;
+ }
+
+ public uint AddResource (byte [] data)
+ {
+ uint offset = (uint) m_resWriter.BaseStream.Position;
+ m_resWriter.Write (data.Length);
+ m_resWriter.Write (data);
+ m_resWriter.QuadAlign ();
+ return offset;
+ }
+
+ public void AddFieldInitData (byte [] data)
+ {
+ m_fieldDataWriter.Write (data);
+ m_fieldDataWriter.QuadAlign ();
+ }
+
+ uint GetStrongNameSignatureSize ()
+ {
+ if (m_assembly.Name.PublicKey != null) {
+ // in fx 2.0 the key may be from 384 to 16384 bits
+ // so we must calculate the signature size based on
+ // the size of the public key (minus the 32 byte header)
+ int size = m_assembly.Name.PublicKey.Length;
+ if (size > 32)
+ return (uint) (size - 32);
+ // note: size == 16 for the ECMA "key" which is replaced
+ // by the runtime with a 1024 bits key (128 bytes)
+ }
+ return 128; // default strongname signature size
+ }
+
+ public override void VisitMetadataRoot (MetadataRoot root)
+ {
+ WriteMemStream (m_cilWriter);
+ WriteMemStream (m_fieldDataWriter);
+ m_resStart = (uint) m_binaryWriter.BaseStream.Position;
+ WriteMemStream (m_resWriter);
+ m_resSize = (uint) (m_binaryWriter.BaseStream.Position - m_resStart);
+
+ // for now, we only reserve the place for the strong name signature
+ if ((m_assembly.Name.Flags & AssemblyFlags.PublicKey) > 0) {
+ m_snsStart = (uint) m_binaryWriter.BaseStream.Position;
+ m_snsSize = GetStrongNameSignatureSize ();
+ m_binaryWriter.Write (new byte [m_snsSize]);
+ m_binaryWriter.QuadAlign ();
+ }
+
+ // save place for debug header
+ if (m_imgWriter.GetImage ().DebugHeader != null) {
+ m_debugHeaderStart = (uint) m_binaryWriter.BaseStream.Position;
+ m_binaryWriter.Write (new byte [m_imgWriter.GetImage ().DebugHeader.GetSize ()]);
+ m_binaryWriter.QuadAlign ();
+ }
+
+ m_mdStart = (uint) m_binaryWriter.BaseStream.Position;
+
+ if (m_stringWriter.BaseStream.Length > 1) {
+ CreateStream (MetadataStream.Strings);
+ SetHeapSize (root.Streams.StringsHeap, m_stringWriter, 0x01);
+ m_stringWriter.QuadAlign ();
+ }
+
+ if (m_guidWriter.BaseStream.Length > 0) {
+ CreateStream (MetadataStream.GUID);
+ SetHeapSize (root.Streams.GuidHeap, m_guidWriter, 0x02);
+ }
+
+ if (m_blobWriter.BaseStream.Length > 1) {
+ CreateStream (MetadataStream.Blob);
+ SetHeapSize (root.Streams.BlobHeap, m_blobWriter, 0x04);
+ m_blobWriter.QuadAlign ();
+ }
+
+ if (m_usWriter.BaseStream.Length > 2) {
+ CreateStream (MetadataStream.UserStrings);
+ m_usWriter.QuadAlign ();
+ }
+
+ m_root.Header.MajorVersion = 1;
+ m_root.Header.MinorVersion = 1;
+
+ switch (m_runtime) {
+ case TargetRuntime.NET_1_0 :
+ m_root.Header.Version = "v1.0.3705";
+ break;
+ case TargetRuntime.NET_1_1 :
+ m_root.Header.Version = "v1.1.4322";
+ break;
+ case TargetRuntime.NET_2_0 :
+ m_root.Header.Version = "v2.0.50727";
+ break;
+ case TargetRuntime.NET_4_0 :
+ m_root.Header.Version = "v4.0.30319";
+ break;
+ }
+
+ m_root.Streams.TablesHeap.Tables.Accept (m_tableWriter);
+
+ if (m_tWriter.BaseStream.Length == 0)
+ m_root.Streams.Remove (m_root.Streams.TablesHeap.GetStream ());
+ }
+
+ public override void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header)
+ {
+ m_binaryWriter.Write (header.Signature);
+ m_binaryWriter.Write (header.MajorVersion);
+ m_binaryWriter.Write (header.MinorVersion);
+ m_binaryWriter.Write (header.Reserved);
+ m_binaryWriter.Write (header.Version.Length + 3 & (~3));
+ m_binaryWriter.Write (Encoding.ASCII.GetBytes (header.Version));
+ m_binaryWriter.QuadAlign ();
+ m_binaryWriter.Write (header.Flags);
+ m_binaryWriter.Write ((ushort) m_root.Streams.Count);
+ }
+
+ public override void VisitMetadataStreamCollection (MetadataStreamCollection streams)
+ {
+ foreach (MetadataStream stream in streams) {
+ MetadataStream.MetadataStreamHeader header = stream.Header;
+
+ header.Offset = (uint) (m_binaryWriter.BaseStream.Position);
+ m_binaryWriter.Write (header.Offset);
+ MemoryBinaryWriter container;
+ string name = header.Name;
+ uint size = 0;
+ switch (header.Name) {
+ case MetadataStream.Tables :
+ container = m_tWriter;
+ size += 24; // header
+ break;
+ case MetadataStream.Strings :
+ name += "\0\0\0\0";
+ container = m_stringWriter;
+ break;
+ case MetadataStream.GUID :
+ container = m_guidWriter;
+ break;
+ case MetadataStream.Blob :
+ container = m_blobWriter;
+ break;
+ case MetadataStream.UserStrings :
+ container = m_usWriter;
+ break;
+ default :
+ throw new MetadataFormatException ("Unknown stream kind");
+ }
+
+ size += (uint) (container.BaseStream.Length + 3 & (~3));
+ m_binaryWriter.Write (size);
+ m_binaryWriter.Write (Encoding.ASCII.GetBytes (name));
+ m_binaryWriter.QuadAlign ();
+ }
+ }
+
+ void WriteMemStream (MemoryBinaryWriter writer)
+ {
+ m_binaryWriter.Write (writer);
+ m_binaryWriter.QuadAlign ();
+ }
+
+ void PatchStreamHeaderOffset (MetadataHeap heap)
+ {
+ long pos = m_binaryWriter.BaseStream.Position;
+ m_binaryWriter.BaseStream.Position = heap.GetStream ().Header.Offset;
+ m_binaryWriter.Write ((uint) (pos - m_mdStart));
+ m_binaryWriter.BaseStream.Position = pos;
+ }
+
+ public override void VisitGuidHeap (GuidHeap heap)
+ {
+ PatchStreamHeaderOffset (heap);
+ WriteMemStream (m_guidWriter);
+ }
+
+ public override void VisitStringsHeap (StringsHeap heap)
+ {
+ PatchStreamHeaderOffset (heap);
+ WriteMemStream (m_stringWriter);
+ }
+
+ public override void VisitTablesHeap (TablesHeap heap)
+ {
+ PatchStreamHeaderOffset (heap);
+ m_binaryWriter.Write (heap.Reserved);
+ switch (m_runtime) {
+ case TargetRuntime.NET_1_0 :
+ case TargetRuntime.NET_1_1 :
+ heap.MajorVersion = 1;
+ heap.MinorVersion = 0;
+ break;
+ case TargetRuntime.NET_2_0 :
+ case TargetRuntime.NET_4_0 :
+ heap.MajorVersion = 2;
+ heap.MinorVersion = 0;
+ break;
+ }
+ m_binaryWriter.Write (heap.MajorVersion);
+ m_binaryWriter.Write (heap.MinorVersion);
+ m_binaryWriter.Write (heap.HeapSizes);
+ m_binaryWriter.Write (heap.Reserved2);
+ m_binaryWriter.Write (heap.Valid);
+ m_binaryWriter.Write (heap.Sorted);
+ WriteMemStream (m_tWriter);
+ }
+
+ public override void VisitBlobHeap (BlobHeap heap)
+ {
+ PatchStreamHeaderOffset (heap);
+ WriteMemStream (m_blobWriter);
+ }
+
+ public override void VisitUserStringsHeap (UserStringsHeap heap)
+ {
+ PatchStreamHeaderOffset (heap);
+ WriteMemStream (m_usWriter);
+ }
+
+ void PatchHeader ()
+ {
+ Image img = m_imgWriter.GetImage ();
+
+ img.CLIHeader.EntryPointToken = m_entryPointToken;
+
+ if ((m_assembly.Name.Flags & AssemblyFlags.PublicKey) == 0)
+ img.CLIHeader.Flags &= ~RuntimeImage.StrongNameSigned;
+
+ if (m_mdSize > 0)
+ img.CLIHeader.Metadata = new DataDirectory (
+ img.TextSection.VirtualAddress + m_mdStart, m_imporTableStart - m_mdStart);
+
+ if (m_resSize > 0)
+ img.CLIHeader.Resources = new DataDirectory (
+ img.TextSection.VirtualAddress + m_resStart, m_resSize);
+
+ if (m_snsStart > 0)
+ img.CLIHeader.StrongNameSignature = new DataDirectory (
+ img.TextSection.VirtualAddress + m_snsStart, m_snsSize);
+
+ if (m_debugHeaderStart > 0)
+ img.PEOptionalHeader.DataDirectories.Debug = new DataDirectory (
+ img.TextSection.VirtualAddress + m_debugHeaderStart, 0x1c);
+ }
+
+ public override void TerminateMetadataRoot (MetadataRoot root)
+ {
+ m_mdSize = (uint) (m_binaryWriter.BaseStream.Position - m_mdStart);
+ m_imporTableStart = (uint) m_binaryWriter.BaseStream.Position;
+ m_binaryWriter.Write (new byte [0x60]); // imports
+ m_imgWriter.Initialize ();
+ PatchHeader ();
+ root.GetImage ().Accept (m_imgWriter);
+ }
+ }
+}
--- /dev/null
+//
+// MethodTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ using Mono.Cecil.Binary;
+
+ internal sealed class MethodTable : IMetadataTable {
+
+ public const int RId = 0x06;
+
+ RowCollection m_rows;
+
+ public MethodRow this [int index] {
+ get { return m_rows [index] as MethodRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal MethodTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitMethodTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class MethodRow : IMetadataRow {
+
+ public RVA RVA;
+ public MethodImplAttributes ImplFlags;
+ public MethodAttributes Flags;
+ public uint Name;
+ public uint Signature;
+ public uint ParamList;
+
+ internal MethodRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitMethodRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// MethodImplTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class MethodImplTable : IMetadataTable {
+
+ public const int RId = 0x19;
+
+ RowCollection m_rows;
+
+ public MethodImplRow this [int index] {
+ get { return m_rows [index] as MethodImplRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal MethodImplTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitMethodImplTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class MethodImplRow : IMetadataRow {
+
+ public uint Class;
+ public MetadataToken MethodBody;
+ public MetadataToken MethodDeclaration;
+
+ internal MethodImplRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitMethodImplRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// MethodPtrTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Thu Feb 22 14:39:38 CET 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class MethodPtrTable : IMetadataTable {
+
+ public const int RId = 0x05;
+
+ RowCollection m_rows;
+
+ public MethodPtrRow this [int index] {
+ get { return m_rows [index] as MethodPtrRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal MethodPtrTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitMethodPtrTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class MethodPtrRow : IMetadataRow {
+
+ public uint Method;
+
+ internal MethodPtrRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitMethodPtrRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// MethodSemanticsTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class MethodSemanticsTable : IMetadataTable {
+
+ public const int RId = 0x18;
+
+ RowCollection m_rows;
+
+ public MethodSemanticsRow this [int index] {
+ get { return m_rows [index] as MethodSemanticsRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal MethodSemanticsTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitMethodSemanticsTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class MethodSemanticsRow : IMetadataRow {
+
+ public MethodSemanticsAttributes Semantics;
+ public uint Method;
+ public MetadataToken Association;
+
+ internal MethodSemanticsRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitMethodSemanticsRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// MethodSpecTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class MethodSpecTable : IMetadataTable {
+
+ public const int RId = 0x2b;
+
+ RowCollection m_rows;
+
+ public MethodSpecRow this [int index] {
+ get { return m_rows [index] as MethodSpecRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal MethodSpecTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitMethodSpecTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class MethodSpecRow : IMetadataRow {
+
+ public MetadataToken Method;
+ public uint Instantiation;
+
+ internal MethodSpecRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitMethodSpecRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// ModuleTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class ModuleTable : IMetadataTable {
+
+ public const int RId = 0x00;
+
+ RowCollection m_rows;
+
+ public ModuleRow this [int index] {
+ get { return m_rows [index] as ModuleRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal ModuleTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitModuleTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class ModuleRow : IMetadataRow {
+
+ public ushort Generation;
+ public uint Name;
+ public uint Mvid;
+ public uint EncId;
+ public uint EncBaseId;
+
+ internal ModuleRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitModuleRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// ModuleRefTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class ModuleRefTable : IMetadataTable {
+
+ public const int RId = 0x1a;
+
+ RowCollection m_rows;
+
+ public ModuleRefRow this [int index] {
+ get { return m_rows [index] as ModuleRefRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal ModuleRefTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitModuleRefTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class ModuleRefRow : IMetadataRow {
+
+ public uint Name;
+
+ internal ModuleRefRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitModuleRefRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// NestedClassTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class NestedClassTable : IMetadataTable {
+
+ public const int RId = 0x29;
+
+ RowCollection m_rows;
+
+ public NestedClassRow this [int index] {
+ get { return m_rows [index] as NestedClassRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal NestedClassTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitNestedClassTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class NestedClassRow : IMetadataRow {
+
+ public uint NestedClass;
+ public uint EnclosingClass;
+
+ internal NestedClassRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitNestedClassRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// ParamTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class ParamTable : IMetadataTable {
+
+ public const int RId = 0x08;
+
+ RowCollection m_rows;
+
+ public ParamRow this [int index] {
+ get { return m_rows [index] as ParamRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal ParamTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitParamTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class ParamRow : IMetadataRow {
+
+ public ParameterAttributes Flags;
+ public ushort Sequence;
+ public uint Name;
+
+ internal ParamRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitParamRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// ParamPtrTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Thu Feb 22 14:39:38 CET 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class ParamPtrTable : IMetadataTable {
+
+ public const int RId = 0x07;
+
+ RowCollection m_rows;
+
+ public ParamPtrRow this [int index] {
+ get { return m_rows [index] as ParamPtrRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal ParamPtrTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitParamPtrTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class ParamPtrRow : IMetadataRow {
+
+ public uint Param;
+
+ internal ParamPtrRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitParamPtrRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// PropertyTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class PropertyTable : IMetadataTable {
+
+ public const int RId = 0x17;
+
+ RowCollection m_rows;
+
+ public PropertyRow this [int index] {
+ get { return m_rows [index] as PropertyRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal PropertyTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitPropertyTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class PropertyRow : IMetadataRow {
+
+ public PropertyAttributes Flags;
+ public uint Name;
+ public uint Type;
+
+ internal PropertyRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitPropertyRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// PropertyMapTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class PropertyMapTable : IMetadataTable {
+
+ public const int RId = 0x15;
+
+ RowCollection m_rows;
+
+ public PropertyMapRow this [int index] {
+ get { return m_rows [index] as PropertyMapRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal PropertyMapTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitPropertyMapTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class PropertyMapRow : IMetadataRow {
+
+ public uint Parent;
+ public uint PropertyList;
+
+ internal PropertyMapRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitPropertyMapRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// PropertyPtrTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Thu Feb 22 14:39:38 CET 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class PropertyPtrTable : IMetadataTable {
+
+ public const int RId = 0x16;
+
+ RowCollection m_rows;
+
+ public PropertyPtrRow this [int index] {
+ get { return m_rows [index] as PropertyPtrRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal PropertyPtrTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitPropertyPtrTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class PropertyPtrRow : IMetadataRow {
+
+ public uint Property;
+
+ internal PropertyPtrRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitPropertyPtrRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// RowCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+
+ internal class RowCollection : ICollection, IMetadataRowVisitable {
+
+ ArrayList m_items;
+
+ public IMetadataRow this [int index] {
+ get { return m_items [index] as IMetadataRow; }
+ set { m_items [index] = value; }
+ }
+
+ public int Count {
+ get { return m_items.Count; }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ internal RowCollection (int size)
+ {
+ m_items = new ArrayList (size);
+ }
+
+ internal RowCollection ()
+ {
+ m_items = new ArrayList ();
+ }
+
+ internal void Add (IMetadataRow value)
+ {
+ m_items.Add (value);
+ }
+
+ public void Clear ()
+ {
+ m_items.Clear ();
+ }
+
+ public bool Contains (IMetadataRow value)
+ {
+ return m_items.Contains (value);
+ }
+
+ public int IndexOf (IMetadataRow value)
+ {
+ return m_items.IndexOf (value);
+ }
+
+ public void Insert (int index, IMetadataRow value)
+ {
+ m_items.Insert (index, value);
+ }
+
+ public void Remove (IMetadataRow value)
+ {
+ m_items.Remove (value);
+ }
+
+ public void RemoveAt (int index)
+ {
+ m_items.Remove (index);
+ }
+
+ public void CopyTo (Array ary, int index)
+ {
+ m_items.CopyTo (ary, index);
+ }
+
+ public void Sort (IComparer comp)
+ {
+ m_items.Sort (comp);
+ }
+
+ public IEnumerator GetEnumerator ()
+ {
+ return m_items.GetEnumerator ();
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitRowCollection (this);
+
+ for (int i = 0; i < m_items.Count; i++)
+ this [i].Accept (visitor);
+
+ visitor.TerminateRowCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// StandAloneSigTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class StandAloneSigTable : IMetadataTable {
+
+ public const int RId = 0x11;
+
+ RowCollection m_rows;
+
+ public StandAloneSigRow this [int index] {
+ get { return m_rows [index] as StandAloneSigRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal StandAloneSigTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitStandAloneSigTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class StandAloneSigRow : IMetadataRow {
+
+ public uint Signature;
+
+ internal StandAloneSigRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitStandAloneSigRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// StringsHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System.Collections;
+ using System.Text;
+
+ internal class StringsHeap : MetadataHeap {
+
+ IDictionary m_strings;
+
+ public string this [uint index] {
+ get {
+ string str = m_strings [index] as string;
+ if (str == null) {
+ str = ReadStringAt (index);
+ m_strings [index] = str;
+ }
+ return str;
+ }
+ set { m_strings [index] = value; }
+ }
+
+ internal StringsHeap (MetadataStream stream) : base (stream, MetadataStream.Strings)
+ {
+ m_strings = new Hashtable ();
+ }
+
+ string ReadStringAt (uint index)
+ {
+ byte [] data = this.Data;
+ int heap_length = data.Length;
+
+ if (index > heap_length - 1)
+ return string.Empty;
+
+ int length = 0;
+ for (int i = (int) index; i < heap_length; i++) {
+ if (data [i] == 0)
+ break;
+
+ length++;
+ }
+
+ return Encoding.UTF8.GetString (data, (int) index, length);
+ }
+
+ public override void Accept (IMetadataVisitor visitor)
+ {
+ visitor.VisitStringsHeap (this);
+ }
+ }
+}
--- /dev/null
+//
+// TableCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+
+ internal class TableCollection : ICollection, IMetadataTableVisitable {
+
+ IMetadataTable [] m_tables = new IMetadataTable [TablesHeap.MaxTableCount];
+
+ TablesHeap m_heap;
+
+ public IMetadataTable this [int index] {
+ get { return m_tables [index]; }
+ set { m_tables [index] = value; }
+ }
+
+ public int Count {
+ get {
+ return GetList ().Count;
+ }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ public TablesHeap Heap {
+ get { return m_heap; }
+ }
+
+ internal TableCollection (TablesHeap heap)
+ {
+ m_heap = heap;
+ }
+
+ internal void Add (IMetadataTable value)
+ {
+ m_tables [value.Id] = value;
+ }
+
+ public bool Contains (IMetadataTable value)
+ {
+ return m_tables [value.Id] != null;
+ }
+
+ internal void Remove (IMetadataTable value)
+ {
+ m_tables [value.Id] = null;
+ }
+
+ public void CopyTo (Array array, int index)
+ {
+ GetList ().CopyTo (array, index);
+ }
+
+ internal IList GetList ()
+ {
+ IList tables = new ArrayList ();
+ for (int i = 0; i < m_tables.Length; i++) {
+ IMetadataTable table = m_tables [i];
+ if (table != null)
+ tables.Add (table);
+ }
+
+ return tables;
+ }
+
+ public IEnumerator GetEnumerator ()
+ {
+ return GetList ().GetEnumerator ();
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitTableCollection (this);
+
+ foreach (IMetadataTable table in GetList ())
+ table.Accept (visitor);
+
+ visitor.TerminateTableCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// TablesHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+
+ internal class TablesHeap : MetadataHeap {
+
+ public uint Reserved;
+ public byte MajorVersion;
+ public byte MinorVersion;
+ public byte HeapSizes;
+ public byte Reserved2;
+ public long Valid;
+ public long Sorted;
+
+ TableCollection m_tables;
+
+ public const int MaxTableCount = 45;
+
+ public TableCollection Tables {
+ get { return m_tables; }
+ set { m_tables = value; }
+ }
+
+ public IMetadataTable this [int id]
+ {
+ get { return m_tables [id]; }
+ set { m_tables [id] = value; }
+ }
+
+ internal TablesHeap (MetadataStream stream) : base(stream, MetadataStream.Tables)
+ {
+ }
+
+ public bool HasTable (int id)
+ {
+ return (Valid & (1L << id)) != 0;
+ }
+
+ public override void Accept (IMetadataVisitor visitor)
+ {
+ visitor.VisitTablesHeap (this);
+ }
+ }
+}
--- /dev/null
+//
+// TokenType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal enum TokenType : uint {
+ Module = 0x00000000,
+ TypeRef = 0x01000000,
+ TypeDef = 0x02000000,
+ Field = 0x04000000,
+ Method = 0x06000000,
+ Param = 0x08000000,
+ InterfaceImpl = 0x09000000,
+ MemberRef = 0x0a000000,
+ CustomAttribute = 0x0c000000,
+ Permission = 0x0e000000,
+ Signature = 0x11000000,
+ Event = 0x14000000,
+ Property = 0x17000000,
+ ModuleRef = 0x1a000000,
+ TypeSpec = 0x1b000000,
+ Assembly = 0x20000000,
+ AssemblyRef = 0x23000000,
+ File = 0x26000000,
+ ExportedType = 0x27000000,
+ ManifestResource = 0x28000000,
+ GenericParam = 0x2a000000,
+ MethodSpec = 0x2b000000,
+ String = 0x70000000,
+ Name = 0x71000000,
+ BaseType = 0x72000000
+ }
+}
--- /dev/null
+//
+// TypeDefTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using Mono.Cecil;
+
+ internal sealed class TypeDefTable : IMetadataTable {
+
+ public const int RId = 0x02;
+
+ RowCollection m_rows;
+
+ public TypeDefRow this [int index] {
+ get { return m_rows [index] as TypeDefRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal TypeDefTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitTypeDefTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class TypeDefRow : IMetadataRow {
+
+ public TypeAttributes Flags;
+ public uint Name;
+ public uint Namespace;
+ public MetadataToken Extends;
+ public uint FieldList;
+ public uint MethodList;
+
+ internal TypeDefRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitTypeDefRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// TypeRefTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class TypeRefTable : IMetadataTable {
+
+ public const int RId = 0x01;
+
+ RowCollection m_rows;
+
+ public TypeRefRow this [int index] {
+ get { return m_rows [index] as TypeRefRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal TypeRefTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitTypeRefTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class TypeRefRow : IMetadataRow {
+
+ public MetadataToken ResolutionScope;
+ public uint Name;
+ public uint Namespace;
+
+ internal TypeRefRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitTypeRefRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// TypeSpecTable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Tue Oct 10 23:08:26 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ internal sealed class TypeSpecTable : IMetadataTable {
+
+ public const int RId = 0x1b;
+
+ RowCollection m_rows;
+
+ public TypeSpecRow this [int index] {
+ get { return m_rows [index] as TypeSpecRow; }
+ set { m_rows [index] = value; }
+ }
+
+ public RowCollection Rows {
+ get { return m_rows; }
+ set { m_rows = value; }
+ }
+
+ public int Id {
+ get { return RId; }
+ }
+
+ internal TypeSpecTable ()
+ {
+ }
+
+ public void Accept (IMetadataTableVisitor visitor)
+ {
+ visitor.VisitTypeSpecTable (this);
+ this.Rows.Accept (visitor.GetRowVisitor ());
+ }
+ }
+
+ internal sealed class TypeSpecRow : IMetadataRow {
+
+ public uint Signature;
+
+ internal TypeSpecRow ()
+ {
+ }
+
+ public void Accept (IMetadataRowVisitor visitor)
+ {
+ visitor.VisitTypeSpecRow (this);
+ }
+ }
+}
--- /dev/null
+//
+// UserStringsHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System.Collections;
+ using System.Text;
+
+ internal class UserStringsHeap : MetadataHeap {
+
+ readonly IDictionary m_strings;
+
+ public string this [uint offset] {
+ get {
+ string us = m_strings [offset] as string;
+ if (us != null)
+ return us;
+
+ us = ReadStringAt ((int) offset);
+ if (us != null && us.Length != 0)
+ m_strings [offset] = us;
+
+ return us;
+ }
+ set { m_strings [offset] = value; }
+ }
+
+ internal UserStringsHeap (MetadataStream stream) : base (stream, MetadataStream.UserStrings)
+ {
+ m_strings = new Hashtable ();
+ }
+
+ string ReadStringAt (int offset)
+ {
+ int length = Utilities.ReadCompressedInteger (this.Data, offset, out offset) - 1;
+ if (length < 1)
+ return string.Empty;
+
+ char [] chars = new char [length / 2];
+
+ for (int i = offset, j = 0; i < offset + length; i += 2)
+ chars [j++] = (char) (Data [i] | (Data [i + 1] << 8));
+
+ return new string (chars);
+ }
+
+ public override void Accept (IMetadataVisitor visitor)
+ {
+ visitor.VisitUserStringsHeap (this);
+ }
+ }
+}
--- /dev/null
+//
+// Utilities.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Sat Feb 16 23:23:29 +0100 2008
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Metadata {
+
+ using System;
+ using System.Collections;
+ using System.IO;
+
+ sealed class Utilities {
+
+ Utilities ()
+ {
+ }
+
+ public static int ReadCompressedInteger (byte [] data, int pos, out int start)
+ {
+ int integer;
+ start = pos;
+ if ((data [pos] & 0x80) == 0) {
+ integer = data [pos];
+ start++;
+ } else if ((data [pos] & 0x40) == 0) {
+ integer = (data [start] & ~0x80) << 8;
+ integer |= data [pos + 1];
+ start += 2;
+ } else {
+ integer = (data [start] & ~0xc0) << 24;
+ integer |= data [pos + 1] << 16;
+ integer |= data [pos + 2] << 8;
+ integer |= data [pos + 3];
+ start += 4;
+ }
+ return integer;
+ }
+
+ public static int ReadCompressedSignedInteger (byte [] data, int pos, out int start)
+ {
+ int integer = ReadCompressedInteger (data, pos, out start) >> 1;
+ if ((integer & 1) == 0)
+ return integer;
+
+ if (integer < 0x40)
+ return integer - 0x40;
+
+ if (integer < 0x2000)
+ return integer - 0x2000;
+
+ if (integer < 0x10000000)
+ return integer - 0x10000000;
+
+ return integer - 0x20000000;
+ }
+
+ public static int WriteCompressedInteger (BinaryWriter writer, int value)
+ {
+ if (value < 0x80)
+ writer.Write ((byte) value);
+ else if (value < 0x4000) {
+ writer.Write ((byte) (0x80 | (value >> 8)));
+ writer.Write ((byte) (value & 0xff));
+ } else {
+ writer.Write ((byte) ((value >> 24) | 0xc0));
+ writer.Write ((byte) ((value >> 16) & 0xff));
+ writer.Write ((byte) ((value >> 8) & 0xff));
+ writer.Write ((byte) (value & 0xff));
+ }
+ return (int) writer.BaseStream.Position;
+ }
+
+ public static MetadataToken GetMetadataToken (CodedIndex cidx, uint data)
+ {
+ uint rid = 0;
+ switch (cidx) {
+ case CodedIndex.TypeDefOrRef :
+ rid = data >> 2;
+ switch (data & 3) {
+ case 0 :
+ return new MetadataToken (TokenType.TypeDef, rid);
+ case 1 :
+ return new MetadataToken (TokenType.TypeRef, rid);
+ case 2 :
+ return new MetadataToken (TokenType.TypeSpec, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.HasConstant :
+ rid = data >> 2;
+ switch (data & 3) {
+ case 0 :
+ return new MetadataToken (TokenType.Field, rid);
+ case 1 :
+ return new MetadataToken (TokenType.Param, rid);
+ case 2 :
+ return new MetadataToken (TokenType.Property, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.HasCustomAttribute :
+ rid = data >> 5;
+ switch (data & 31) {
+ case 0 :
+ return new MetadataToken (TokenType.Method, rid);
+ case 1 :
+ return new MetadataToken (TokenType.Field, rid);
+ case 2 :
+ return new MetadataToken (TokenType.TypeRef, rid);
+ case 3 :
+ return new MetadataToken (TokenType.TypeDef, rid);
+ case 4 :
+ return new MetadataToken (TokenType.Param, rid);
+ case 5 :
+ return new MetadataToken (TokenType.InterfaceImpl, rid);
+ case 6 :
+ return new MetadataToken (TokenType.MemberRef, rid);
+ case 7 :
+ return new MetadataToken (TokenType.Module, rid);
+ case 8 :
+ return new MetadataToken (TokenType.Permission, rid);
+ case 9 :
+ return new MetadataToken (TokenType.Property, rid);
+ case 10 :
+ return new MetadataToken (TokenType.Event, rid);
+ case 11 :
+ return new MetadataToken (TokenType.Signature, rid);
+ case 12 :
+ return new MetadataToken (TokenType.ModuleRef, rid);
+ case 13 :
+ return new MetadataToken (TokenType.TypeSpec, rid);
+ case 14 :
+ return new MetadataToken (TokenType.Assembly, rid);
+ case 15 :
+ return new MetadataToken (TokenType.AssemblyRef, rid);
+ case 16 :
+ return new MetadataToken (TokenType.File, rid);
+ case 17 :
+ return new MetadataToken (TokenType.ExportedType, rid);
+ case 18 :
+ return new MetadataToken (TokenType.ManifestResource, rid);
+ case 19 :
+ return new MetadataToken (TokenType.GenericParam, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.HasFieldMarshal :
+ rid = data >> 1;
+ switch (data & 1) {
+ case 0 :
+ return new MetadataToken (TokenType.Field, rid);
+ case 1 :
+ return new MetadataToken (TokenType.Param, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.HasDeclSecurity :
+ rid = data >> 2;
+ switch (data & 3) {
+ case 0 :
+ return new MetadataToken (TokenType.TypeDef, rid);
+ case 1 :
+ return new MetadataToken (TokenType.Method, rid);
+ case 2 :
+ return new MetadataToken (TokenType.Assembly, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.MemberRefParent :
+ rid = data >> 3;
+ switch (data & 7) {
+ case 0 :
+ return new MetadataToken (TokenType.TypeDef, rid);
+ case 1 :
+ return new MetadataToken (TokenType.TypeRef, rid);
+ case 2 :
+ return new MetadataToken (TokenType.ModuleRef, rid);
+ case 3 :
+ return new MetadataToken (TokenType.Method, rid);
+ case 4 :
+ return new MetadataToken (TokenType.TypeSpec, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.HasSemantics :
+ rid = data >> 1;
+ switch (data & 1) {
+ case 0 :
+ return new MetadataToken (TokenType.Event, rid);
+ case 1 :
+ return new MetadataToken (TokenType.Property, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.MethodDefOrRef :
+ rid = data >> 1;
+ switch (data & 1) {
+ case 0 :
+ return new MetadataToken (TokenType.Method, rid);
+ case 1 :
+ return new MetadataToken (TokenType.MemberRef, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.MemberForwarded :
+ rid = data >> 1;
+ switch (data & 1) {
+ case 0 :
+ return new MetadataToken (TokenType.Field, rid);
+ case 1 :
+ return new MetadataToken (TokenType.Method, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.Implementation :
+ rid = data >> 2;
+ switch (data & 3) {
+ case 0 :
+ return new MetadataToken (TokenType.File, rid);
+ case 1 :
+ return new MetadataToken (TokenType.AssemblyRef, rid);
+ case 2 :
+ return new MetadataToken (TokenType.ExportedType, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.CustomAttributeType :
+ rid = data >> 3;
+ switch (data & 7) {
+ case 2 :
+ return new MetadataToken (TokenType.Method, rid);
+ case 3 :
+ return new MetadataToken (TokenType.MemberRef, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.ResolutionScope :
+ rid = data >> 2;
+ switch (data & 3) {
+ case 0 :
+ return new MetadataToken (TokenType.Module, rid);
+ case 1 :
+ return new MetadataToken (TokenType.ModuleRef, rid);
+ case 2 :
+ return new MetadataToken (TokenType.AssemblyRef, rid);
+ case 3 :
+ return new MetadataToken (TokenType.TypeRef, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ case CodedIndex.TypeOrMethodDef :
+ rid = data >> 1;
+ switch (data & 1) {
+ case 0 :
+ return new MetadataToken (TokenType.TypeDef, rid);
+ case 1 :
+ return new MetadataToken (TokenType.Method, rid);
+ default :
+ return MetadataToken.Zero;
+ }
+ default :
+ return MetadataToken.Zero;
+ }
+ }
+
+ public static uint CompressMetadataToken (CodedIndex cidx, MetadataToken token)
+ {
+ uint ret = 0;
+ if (token.RID == 0)
+ return ret;
+ switch (cidx) {
+ case CodedIndex.TypeDefOrRef :
+ ret = token.RID << 2;
+ switch (token.TokenType) {
+ case TokenType.TypeDef :
+ return ret | 0;
+ case TokenType.TypeRef :
+ return ret | 1;
+ case TokenType.TypeSpec :
+ return ret | 2;
+ default :
+ throw new MetadataFormatException("Non valid Token for TypeDefOrRef");
+ }
+ case CodedIndex.HasConstant :
+ ret = token.RID << 2;
+ switch (token.TokenType) {
+ case TokenType.Field :
+ return ret | 0;
+ case TokenType.Param :
+ return ret | 1;
+ case TokenType.Property :
+ return ret | 2;
+ default :
+ throw new MetadataFormatException("Non valid Token for HasConstant");
+ }
+ case CodedIndex.HasCustomAttribute :
+ ret = token.RID << 5;
+ switch (token.TokenType) {
+ case TokenType.Method :
+ return ret | 0;
+ case TokenType.Field :
+ return ret | 1;
+ case TokenType.TypeRef :
+ return ret | 2;
+ case TokenType.TypeDef :
+ return ret | 3;
+ case TokenType.Param :
+ return ret | 4;
+ case TokenType.InterfaceImpl :
+ return ret | 5;
+ case TokenType.MemberRef :
+ return ret | 6;
+ case TokenType.Module :
+ return ret | 7;
+ case TokenType.Permission :
+ return ret | 8;
+ case TokenType.Property :
+ return ret | 9;
+ case TokenType.Event :
+ return ret | 10;
+ case TokenType.Signature :
+ return ret | 11;
+ case TokenType.ModuleRef :
+ return ret | 12;
+ case TokenType.TypeSpec :
+ return ret | 13;
+ case TokenType.Assembly :
+ return ret | 14;
+ case TokenType.AssemblyRef :
+ return ret | 15;
+ case TokenType.File :
+ return ret | 16;
+ case TokenType.ExportedType :
+ return ret | 17;
+ case TokenType.ManifestResource :
+ return ret | 18;
+ case TokenType.GenericParam :
+ return ret | 19;
+ default :
+ throw new MetadataFormatException("Non valid Token for HasCustomAttribute");
+ }
+ case CodedIndex.HasFieldMarshal :
+ ret = token.RID << 1;
+ switch (token.TokenType) {
+ case TokenType.Field :
+ return ret | 0;
+ case TokenType.Param :
+ return ret | 1;
+ default :
+ throw new MetadataFormatException("Non valid Token for HasFieldMarshal");
+ }
+ case CodedIndex.HasDeclSecurity :
+ ret = token.RID << 2;
+ switch (token.TokenType) {
+ case TokenType.TypeDef :
+ return ret | 0;
+ case TokenType.Method :
+ return ret | 1;
+ case TokenType.Assembly :
+ return ret | 2;
+ default :
+ throw new MetadataFormatException("Non valid Token for HasDeclSecurity");
+ }
+ case CodedIndex.MemberRefParent :
+ ret = token.RID << 3;
+ switch (token.TokenType) {
+ case TokenType.TypeDef :
+ return ret | 0;
+ case TokenType.TypeRef :
+ return ret | 1;
+ case TokenType.ModuleRef :
+ return ret | 2;
+ case TokenType.Method :
+ return ret | 3;
+ case TokenType.TypeSpec :
+ return ret | 4;
+ default :
+ throw new MetadataFormatException("Non valid Token for MemberRefParent");
+ }
+ case CodedIndex.HasSemantics :
+ ret = token.RID << 1;
+ switch (token.TokenType) {
+ case TokenType.Event :
+ return ret | 0;
+ case TokenType.Property :
+ return ret | 1;
+ default :
+ throw new MetadataFormatException("Non valid Token for HasSemantics");
+ }
+ case CodedIndex.MethodDefOrRef :
+ ret = token.RID << 1;
+ switch (token.TokenType) {
+ case TokenType.Method :
+ return ret | 0;
+ case TokenType.MemberRef :
+ return ret | 1;
+ default :
+ throw new MetadataFormatException("Non valid Token for MethodDefOrRef");
+ }
+ case CodedIndex.MemberForwarded :
+ ret = token.RID << 1;
+ switch (token.TokenType) {
+ case TokenType.Field :
+ return ret | 0;
+ case TokenType.Method :
+ return ret | 1;
+ default :
+ throw new MetadataFormatException("Non valid Token for MemberForwarded");
+ }
+ case CodedIndex.Implementation :
+ ret = token.RID << 2;
+ switch (token.TokenType) {
+ case TokenType.File :
+ return ret | 0;
+ case TokenType.AssemblyRef :
+ return ret | 1;
+ case TokenType.ExportedType :
+ return ret | 2;
+ default :
+ throw new MetadataFormatException("Non valid Token for Implementation");
+ }
+ case CodedIndex.CustomAttributeType :
+ ret = token.RID << 3;
+ switch (token.TokenType) {
+ case TokenType.Method :
+ return ret | 2;
+ case TokenType.MemberRef :
+ return ret | 3;
+ default :
+ throw new MetadataFormatException("Non valid Token for CustomAttributeType");
+ }
+ case CodedIndex.ResolutionScope :
+ ret = token.RID << 2;
+ switch (token.TokenType) {
+ case TokenType.Module :
+ return ret | 0;
+ case TokenType.ModuleRef :
+ return ret | 1;
+ case TokenType.AssemblyRef :
+ return ret | 2;
+ case TokenType.TypeRef :
+ return ret | 3;
+ default :
+ throw new MetadataFormatException("Non valid Token for ResolutionScope");
+ }
+ case CodedIndex.TypeOrMethodDef :
+ ret = token.RID << 1;
+ switch (token.TokenType) {
+ case TokenType.TypeDef :
+ return ret | 0;
+ case TokenType.Method :
+ return ret | 1;
+ default :
+ throw new MetadataFormatException("Non valid Token for TypeOrMethodDef");
+ }
+ default :
+ throw new MetadataFormatException ("Non valid CodedIndex");
+ }
+ }
+
+ internal static Type GetCorrespondingTable (TokenType t)
+ {
+ switch (t) {
+ case TokenType.Assembly :
+ return typeof (AssemblyTable);
+ case TokenType.AssemblyRef :
+ return typeof (AssemblyRefTable);
+ case TokenType.CustomAttribute :
+ return typeof (CustomAttributeTable);
+ case TokenType.Event :
+ return typeof (EventTable);
+ case TokenType.ExportedType :
+ return typeof (ExportedTypeTable);
+ case TokenType.Field :
+ return typeof (FieldTable);
+ case TokenType.File :
+ return typeof (FileTable);
+ case TokenType.InterfaceImpl :
+ return typeof (InterfaceImplTable);
+ case TokenType.MemberRef :
+ return typeof (MemberRefTable);
+ case TokenType.Method :
+ return typeof (MethodTable);
+ case TokenType.Module :
+ return typeof (ModuleTable);
+ case TokenType.ModuleRef :
+ return typeof (ModuleRefTable);
+ case TokenType.Param :
+ return typeof (ParamTable);
+ case TokenType.Permission :
+ return typeof (DeclSecurityTable);
+ case TokenType.Property :
+ return typeof (PropertyTable);
+ case TokenType.Signature :
+ return typeof (StandAloneSigTable);
+ case TokenType.TypeDef :
+ return typeof (TypeDefTable);
+ case TokenType.TypeRef :
+ return typeof (TypeRefTable);
+ case TokenType.TypeSpec :
+ return typeof (TypeSpecTable);
+ default :
+ return null;
+ }
+ }
+
+ internal delegate int TableRowCounter (int rid);
+
+ internal static int GetCodedIndexSize (CodedIndex ci, TableRowCounter rowCounter, int [] codedIndexCache)
+ {
+ int bits = 0, max = 0, index = (int) ci;
+ if (codedIndexCache [index] != 0)
+ return codedIndexCache [index];
+
+ int res = 0;
+ int [] rids;
+ switch (ci) {
+ case CodedIndex.TypeDefOrRef :
+ bits = 2;
+ rids = new int [3];
+ rids [0] = TypeDefTable.RId;
+ rids [1] = TypeRefTable.RId;
+ rids [2] = TypeSpecTable.RId;
+ break;
+ case CodedIndex.HasConstant :
+ bits = 2;
+ rids = new int [3];
+ rids [0] = FieldTable.RId;
+ rids [1] = ParamTable.RId;
+ rids [2] = PropertyTable.RId;
+ break;
+ case CodedIndex.HasCustomAttribute :
+ bits = 5;
+ rids = new int [20];
+ rids [0] = MethodTable.RId;
+ rids [1] = FieldTable.RId;
+ rids [2] = TypeRefTable.RId;
+ rids [3] = TypeDefTable.RId;
+ rids [4] = ParamTable.RId;
+ rids [5] = InterfaceImplTable.RId;
+ rids [6] = MemberRefTable.RId;
+ rids [7] = ModuleTable.RId;
+ rids [8] = DeclSecurityTable.RId;
+ rids [9] = PropertyTable.RId;
+ rids [10] = EventTable.RId;
+ rids [11] = StandAloneSigTable.RId;
+ rids [12] = ModuleRefTable.RId;
+ rids [13] = TypeSpecTable.RId;
+ rids [14] = AssemblyTable.RId;
+ rids [15] = AssemblyRefTable.RId;
+ rids [16] = FileTable.RId;
+ rids [17] = ExportedTypeTable.RId;
+ rids [18] = ManifestResourceTable.RId;
+ rids [19] = GenericParamTable.RId;
+ break;
+ case CodedIndex.HasFieldMarshal :
+ bits = 1;
+ rids = new int [2];
+ rids [0] = FieldTable.RId;
+ rids [1] = ParamTable.RId;
+ break;
+ case CodedIndex.HasDeclSecurity :
+ bits = 2;
+ rids = new int [3];
+ rids [0] = TypeDefTable.RId;
+ rids [1] = MethodTable.RId;
+ rids [2] = AssemblyTable.RId;
+ break;
+ case CodedIndex.MemberRefParent :
+ bits = 3;
+ rids = new int [5];
+ rids [0] = TypeDefTable.RId;
+ rids [1] = TypeRefTable.RId;
+ rids [2] = ModuleRefTable.RId;
+ rids [3] = MethodTable.RId;
+ rids [4] = TypeSpecTable.RId;
+ break;
+ case CodedIndex.HasSemantics :
+ bits = 1;
+ rids = new int [2];
+ rids [0] = EventTable.RId;
+ rids [1] = PropertyTable.RId;
+ break;
+ case CodedIndex.MethodDefOrRef :
+ bits = 1;
+ rids = new int [2];
+ rids [0] = MethodTable.RId;
+ rids [1] = MemberRefTable.RId;
+ break;
+ case CodedIndex.MemberForwarded :
+ bits = 1;
+ rids = new int [2];
+ rids [0] = FieldTable.RId;
+ rids [1] = MethodTable.RId;
+ break;
+ case CodedIndex.Implementation :
+ bits = 2;
+ rids = new int [3];
+ rids [0] = FileTable.RId;
+ rids [1] = AssemblyRefTable.RId;
+ rids [2] = ExportedTypeTable.RId;
+ break;
+ case CodedIndex.CustomAttributeType :
+ bits = 3;
+ rids = new int [2];
+ rids [0] = MethodTable.RId;
+ rids [1] = MemberRefTable.RId;
+ break;
+ case CodedIndex.ResolutionScope :
+ bits = 2;
+ rids = new int [4];
+ rids [0] = ModuleTable.RId;
+ rids [1] = ModuleRefTable.RId;
+ rids [2] = AssemblyRefTable.RId;
+ rids [3] = TypeRefTable.RId;
+ break;
+ case CodedIndex.TypeOrMethodDef :
+ bits = 1;
+ rids = new int [2];
+ rids [0] = TypeDefTable.RId;
+ rids [1] = MethodTable.RId;
+ break;
+ default :
+ throw new MetadataFormatException ("Non valid CodedIndex");
+ }
+
+ for (int i = 0; i < rids.Length; i++) {
+ int rows = rowCounter (rids [i]);
+ if (rows > max) max = rows;
+ }
+
+ res = max < (1 << (16 - bits)) ? 2 : 4;
+ codedIndexCache [index] = res;
+ return res;
+ }
+ }
+}
--- /dev/null
+//
+// Array.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class ARRAY : SigType {
+
+ public CustomMod [] CustomMods;
+ public SigType Type;
+ public ArrayShape Shape;
+
+ public ARRAY () : base (ElementType.Array)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// ArrayShape.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class ArrayShape {
+
+ public int Rank;
+ public int NumSizes;
+ public int [] Sizes;
+ public int NumLoBounds;
+ public int [] LoBounds;
+
+ public ArrayShape ()
+ {
+ }
+ }
+}
--- /dev/null
+//
+// BaseSignatureVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal abstract class BaseSignatureVisitor : ISignatureVisitor {
+
+ public virtual void VisitMethodDefSig (MethodDefSig methodDef)
+ {
+ }
+
+ public virtual void VisitMethodRefSig (MethodRefSig methodRef)
+ {
+ }
+
+ public virtual void VisitFieldSig (FieldSig field)
+ {
+ }
+
+ public virtual void VisitPropertySig (PropertySig property)
+ {
+ }
+
+ public virtual void VisitLocalVarSig (LocalVarSig localvar)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// Class.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class CLASS : SigType {
+
+ public MetadataToken Type;
+
+ public CLASS () : base (ElementType.Class)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// Constraints.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal enum Constraint : byte {
+ None = 0x0,
+ Pinned = (byte) ElementType.Pinned
+ }
+}
--- /dev/null
+//
+// CustomAttrib.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class CustomAttrib {
+
+ public const ushort StdProlog = 0x0001;
+
+ public MethodReference Constructor;
+
+ public ushort Prolog;
+ public FixedArg [] FixedArgs;
+ public ushort NumNamed;
+ public NamedArg [] NamedArgs;
+ public bool Read;
+
+ public CustomAttrib (MethodReference ctor)
+ {
+ Constructor = ctor;
+ }
+
+ internal struct FixedArg {
+
+ public bool SzArray;
+ public uint NumElem;
+ public Elem [] Elems;
+
+ internal static FixedArg [] Empty = new FixedArg [0];
+ }
+
+ internal struct Elem {
+
+ public bool Simple;
+ public bool String;
+ public bool Type;
+ public bool BoxedValueType;
+
+ public ElementType FieldOrPropType;
+ public object Value;
+
+ public TypeReference ElemType;
+ }
+
+ internal struct NamedArg {
+
+ public bool Field;
+ public bool Property;
+
+ public ElementType FieldOrPropType;
+ public string FieldOrPropName;
+ public FixedArg FixedArg;
+
+ internal static NamedArg [] Empty = new NamedArg [0];
+ }
+ }
+}
--- /dev/null
+//
+// CustomMod.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class CustomMod {
+
+ public static CustomMod [] EmptyCustomMod = new CustomMod [0];
+
+ internal enum CMODType : byte {
+ None = 0x0,
+ OPT = (byte) ElementType.CModOpt,
+ REQD = (byte) ElementType.CModReqD
+ }
+
+ public CMODType CMOD;
+ public MetadataToken TypeDefOrRef;
+
+ public CustomMod ()
+ {
+ }
+ }
+}
--- /dev/null
+//
+// FieldSig.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class FieldSig : Signature {
+
+ public bool Field;
+ public CustomMod [] CustomMods;
+ public SigType Type;
+
+ public FieldSig () : base ()
+ {
+ }
+
+ public FieldSig (uint blobIndex) : base (blobIndex)
+ {
+ }
+
+ public override void Accept (ISignatureVisitor visitor)
+ {
+ visitor.VisitFieldSig (this);
+ }
+ }
+}
--- /dev/null
+//
+// FnPtr.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class FNPTR : SigType {
+
+ public MethodSig Method;
+
+ public FNPTR () : base (ElementType.FnPtr)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// GenericArg.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ sealed class GenericArg {
+
+ public CustomMod [] CustomMods;
+ public SigType Type;
+
+ public GenericArg (SigType type)
+ {
+ Type = type;
+ }
+ }
+}
--- /dev/null
+//
+// GenericInst.cs
+//
+// Author:
+// Martin Baulig <baulig@ximian.com>
+// Jb Evain <jbevain@gmail.com>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil;
+ using Mono.Cecil.Metadata;
+
+ internal sealed class GENERICINST : SigType {
+
+ public bool ValueType;
+ public MetadataToken Type;
+
+ public GenericInstSignature Signature;
+
+ public GENERICINST () : base (ElementType.GenericInst)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// GenericInstSignature.cs
+//
+// Author:
+// Martin Baulig <martin@ximian.com>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class GenericInstSignature {
+
+ public int Arity;
+ public GenericArg [] Types;
+
+ public GenericInstSignature ()
+ {
+ }
+ }
+}
--- /dev/null
+//
+// ISignatureVisitable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal interface ISignatureVisitable {
+
+ void Accept (ISignatureVisitor visitor);
+ }
+}
--- /dev/null
+//
+// ISignatureVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal interface ISignatureVisitor {
+
+ void VisitMethodDefSig (MethodDefSig methodDef);
+ void VisitMethodRefSig (MethodRefSig methodRef);
+ void VisitFieldSig (FieldSig field);
+ void VisitPropertySig (PropertySig property);
+ void VisitLocalVarSig (LocalVarSig localvar);
+ }
+}
--- /dev/null
+//
+// InputOutputItem.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal abstract class InputOutputItem {
+
+ public CustomMod [] CustomMods;
+ public bool ByRef;
+ public SigType Type;
+ public bool TypedByRef;
+ }
+}
--- /dev/null
+//
+// LocalVarSig.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class LocalVarSig : Signature {
+
+ public bool Local;
+ public int Count;
+ public LocalVariable [] LocalVariables;
+
+ public LocalVarSig () : base ()
+ {
+ }
+
+ public LocalVarSig (uint blobIndex) : base (blobIndex)
+ {
+ }
+
+ public override void Accept (ISignatureVisitor visitor)
+ {
+ visitor.VisitLocalVarSig (this);
+ }
+
+ internal struct LocalVariable {
+
+ public CustomMod [] CustomMods;
+ public Constraint Constraint;
+ public bool ByRef;
+ public SigType Type;
+ }
+ }
+}
--- /dev/null
+//
+// MVar.cs
+//
+// Author:
+// Martin Baulig <martin@ximian.com>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class MVAR : SigType {
+
+ public int Index;
+
+ public MVAR (int index) : base (ElementType.MVar)
+ {
+ this.Index = index;
+ }
+ }
+}
--- /dev/null
+//
+// MarshalSig.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using System;
+
+ using Mono.Cecil;
+
+ internal sealed class MarshalSig {
+
+ public NativeType NativeInstrinsic;
+ public IMarshalSigSpec Spec;
+
+ public MarshalSig (NativeType nt)
+ {
+ this.NativeInstrinsic = nt;
+ }
+
+ internal interface IMarshalSigSpec {
+ }
+
+ internal sealed class Array : IMarshalSigSpec {
+
+ public NativeType ArrayElemType;
+ public int ParamNum;
+ public int ElemMult;
+ public int NumElem;
+
+ public Array ()
+ {
+ this.ParamNum = 0;
+ this.ElemMult = 0;
+ this.NumElem = 0;
+ }
+ }
+
+ internal sealed class CustomMarshaler : IMarshalSigSpec {
+
+ public string Guid;
+ public string UnmanagedType;
+ public string ManagedType;
+ public string Cookie;
+ }
+
+ internal sealed class FixedArray : IMarshalSigSpec {
+
+ public int NumElem;
+ public NativeType ArrayElemType;
+
+ public FixedArray ()
+ {
+ this.NumElem = 0;
+ this.ArrayElemType = NativeType.NONE;
+ }
+ }
+
+ internal sealed class SafeArray : IMarshalSigSpec {
+
+ public VariantType ArrayElemType;
+ }
+
+ internal sealed class FixedSysString : IMarshalSigSpec {
+
+ public int Size;
+ }
+ }
+}
--- /dev/null
+//
+// MethodDefSig.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class MethodDefSig : MethodRefSig {
+
+ public int GenericParameterCount;
+
+ public MethodDefSig () : this (0)
+ {
+ }
+
+ public MethodDefSig (uint blobIndex) : base (blobIndex)
+ {
+ }
+
+ public override void Accept (ISignatureVisitor visitor)
+ {
+ visitor.VisitMethodDefSig (this);
+ }
+ }
+}
--- /dev/null
+//
+// MethodRefSig.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal class MethodRefSig : MethodSig {
+
+ public int Sentinel;
+
+ public MethodRefSig () : this (0)
+ {
+ }
+
+ public MethodRefSig (uint blobIndex) : base (blobIndex)
+ {
+ Sentinel = -1;
+ }
+
+ public override void Accept (ISignatureVisitor visitor)
+ {
+ visitor.VisitMethodRefSig (this);
+ }
+ }
+}
--- /dev/null
+//
+// MethodSig.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Mono.Cecil;
+
+namespace Mono.Cecil.Signatures {
+
+ internal abstract class MethodSig : Signature {
+
+ public bool HasThis;
+ public bool ExplicitThis;
+ public MethodCallingConvention MethCallConv;
+ public int ParamCount;
+ public RetType RetType;
+ public Param [] Parameters;
+
+ public MethodSig () : base ()
+ {
+ }
+
+ public MethodSig (uint blobIndex) : base (blobIndex)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// TypeSpec.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class MethodSpec {
+
+ public GenericInstSignature Signature;
+
+ public MethodSpec (GenericInstSignature sig)
+ {
+ this.Signature = sig;
+ }
+ }
+}
--- /dev/null
+//
+// Param.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class Param : InputOutputItem {
+ }
+}
--- /dev/null
+//
+// PropertySig.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class PropertySig : Signature {
+
+ public bool Property;
+ public int ParamCount;
+ public CustomMod [] CustomMods;
+ public SigType Type;
+ public Param [] Parameters;
+
+ public PropertySig () : base ()
+ {
+ }
+
+ public PropertySig (uint blobIndex) : base (blobIndex)
+ {
+ }
+
+ public override void Accept (ISignatureVisitor visitor)
+ {
+ visitor.VisitPropertySig (this);
+ }
+ }
+}
--- /dev/null
+//
+// Ptr.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class PTR : SigType {
+
+ public CustomMod [] CustomMods;
+ public SigType PtrType;
+ public bool Void;
+
+ public PTR () : base (ElementType.Ptr)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// RetType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class RetType : InputOutputItem {
+
+ public bool Void;
+
+ public RetType ()
+ {
+ }
+ }
+}
--- /dev/null
+//
+// SigType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal class SigType {
+
+ public ElementType ElementType;
+
+ public SigType (ElementType elem)
+ {
+ ElementType = elem;
+ }
+ }
+}
--- /dev/null
+//
+// Signature.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using System;
+
+ internal abstract class Signature : ISignatureVisitable {
+
+ public byte CallingConvention;
+ public uint BlobIndex;
+
+ public Signature (uint blobIndex)
+ {
+ BlobIndex = blobIndex;
+ }
+
+ public Signature ()
+ {
+ BlobIndex = 0;
+ }
+
+ public abstract void Accept (ISignatureVisitor visitor);
+ }
+}
--- /dev/null
+//
+// SignatureReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using System;
+ using System.Collections;
+ using System.IO;
+ using System.Text;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Metadata;
+
+ internal sealed class SignatureReader : BaseSignatureVisitor {
+
+ MetadataRoot m_root;
+ ReflectionReader m_reflectReader;
+ byte [] m_blobData;
+
+ IDictionary m_signatures;
+
+ IAssemblyResolver AssemblyResolver {
+ get { return m_reflectReader.Module.Assembly.Resolver; }
+ }
+
+ public SignatureReader (MetadataRoot root, ReflectionReader reflectReader)
+ {
+ m_root = root;
+ m_reflectReader = reflectReader;
+
+ m_blobData = m_root.Streams.BlobHeap != null ? m_root.Streams.BlobHeap.Data : new byte [0];
+
+ m_signatures = new Hashtable ();
+ }
+
+ public FieldSig GetFieldSig (uint index)
+ {
+ FieldSig f = m_signatures [index] as FieldSig;
+ if (f == null) {
+ f = new FieldSig (index);
+ f.Accept (this);
+ m_signatures [index] = f;
+ }
+ return f;
+ }
+
+ public PropertySig GetPropSig (uint index)
+ {
+ PropertySig p = m_signatures [index] as PropertySig;
+ if (p == null) {
+ p = new PropertySig (index);
+ p.Accept (this);
+ m_signatures [index] = p;
+ }
+ return p;
+ }
+
+ public MethodDefSig GetMethodDefSig (uint index)
+ {
+ MethodDefSig m = m_signatures [index] as MethodDefSig;
+ if (m == null) {
+ m = new MethodDefSig (index);
+ m.Accept (this);
+ m_signatures [index] = m;
+ }
+ return m;
+ }
+
+ public MethodRefSig GetMethodRefSig (uint index)
+ {
+ MethodRefSig m = m_signatures [index] as MethodRefSig;
+ if (m == null) {
+ m = new MethodRefSig (index);
+ m.Accept (this);
+ m_signatures [index] = m;
+ }
+ return m;
+ }
+
+ public TypeSpec GetTypeSpec (uint index)
+ {
+ TypeSpec ts = m_signatures [index] as TypeSpec;
+
+ if (ts == null) {
+ ts = ReadTypeSpec (m_blobData, (int) index);
+ m_signatures [index] = ts;
+ }
+
+ return ts;
+ }
+
+ public MethodSpec GetMethodSpec (uint index)
+ {
+ MethodSpec ms = m_signatures [index] as MethodSpec;
+
+ if (ms == null) {
+ ms = ReadMethodSpec (m_blobData, (int) index);
+ m_signatures [index] = ms;
+ }
+
+ return ms;
+ }
+
+ public LocalVarSig GetLocalVarSig (uint index)
+ {
+ LocalVarSig lv = m_signatures [index] as LocalVarSig;
+ if (lv == null) {
+ lv = new LocalVarSig (index);
+ lv.Accept (this);
+ m_signatures [index] = lv;
+ }
+ return lv;
+ }
+
+ public CustomAttrib GetCustomAttrib (uint index, MethodReference ctor)
+ {
+ return GetCustomAttrib (index, ctor, false);
+ }
+
+ public CustomAttrib GetCustomAttrib (uint index, MethodReference ctor, bool resolve)
+ {
+ return ReadCustomAttrib ((int) index, ctor, resolve);
+ }
+
+ public CustomAttrib GetCustomAttrib (byte [] data, MethodReference ctor)
+ {
+ return GetCustomAttrib (data, ctor, false);
+ }
+
+ public CustomAttrib GetCustomAttrib (byte [] data, MethodReference ctor, bool resolve)
+ {
+ BinaryReader br = new BinaryReader (new MemoryStream (data));
+ return ReadCustomAttrib (br, data, ctor, resolve);
+ }
+
+ public Signature GetMemberRefSig (TokenType tt, uint index)
+ {
+ int start, callconv;
+ Utilities.ReadCompressedInteger (m_blobData, (int) index, out start);
+ callconv = m_blobData [start];
+ if ((callconv & 0x5) == 0x5 || (callconv & 0x10) == 0x10) // vararg || generic?
+ return GetMethodDefSig (index);
+ if ((callconv & 0x6) != 0) // field ?
+ return GetFieldSig (index);
+
+ switch (tt) {
+ case TokenType.TypeDef :
+ case TokenType.TypeRef :
+ case TokenType.TypeSpec :
+ return GetMethodRefSig (index);
+ case TokenType.ModuleRef :
+ case TokenType.Method :
+ return GetMethodDefSig (index);
+ }
+ return null;
+ }
+
+ public MarshalSig GetMarshalSig (uint index)
+ {
+ MarshalSig ms = m_signatures [index] as MarshalSig;
+ if (ms == null) {
+ byte [] data = m_root.Streams.BlobHeap.Read (index);
+ ms = ReadMarshalSig (data);
+ m_signatures [index] = ms;
+ }
+ return ms;
+ }
+
+ public MethodSig GetStandAloneMethodSig (uint index)
+ {
+ byte [] data = m_root.Streams.BlobHeap.Read (index);
+ int start;
+ if ((data [0] & 0x5) > 0) {
+ MethodRefSig mrs = new MethodRefSig (index);
+ ReadMethodRefSig (mrs, data, 0, out start);
+ return mrs;
+ } else {
+ MethodDefSig mds = new MethodDefSig (index);
+ ReadMethodDefSig (mds, data, 0, out start);
+ return mds;
+ }
+ }
+
+ public override void VisitMethodDefSig (MethodDefSig methodDef)
+ {
+ int start;
+ ReadMethodDefSig (methodDef, m_root.Streams.BlobHeap.Read (methodDef.BlobIndex), 0, out start);
+ }
+
+ public override void VisitMethodRefSig (MethodRefSig methodRef)
+ {
+ int start;
+ ReadMethodRefSig (methodRef, m_root.Streams.BlobHeap.Read (methodRef.BlobIndex), 0, out start);
+ }
+
+ public override void VisitFieldSig (FieldSig field)
+ {
+ int start;
+ Utilities.ReadCompressedInteger (m_blobData, (int) field.BlobIndex, out start);
+ field.CallingConvention = m_blobData [start];
+ field.Field = (field.CallingConvention & 0x6) != 0;
+ field.CustomMods = ReadCustomMods (m_blobData, start + 1, out start);
+ field.Type = ReadType (m_blobData, start, out start);
+ }
+
+ public override void VisitPropertySig (PropertySig property)
+ {
+ int start;
+ Utilities.ReadCompressedInteger (m_blobData, (int) property.BlobIndex, out start);
+ property.CallingConvention = m_blobData [start];
+ property.Property = (property.CallingConvention & 0x8) != 0;
+ property.ParamCount = Utilities.ReadCompressedInteger (m_blobData, start + 1, out start);
+ property.CustomMods = ReadCustomMods (m_blobData, start, out start);
+ property.Type = ReadType (m_blobData, start, out start);
+ property.Parameters = ReadParameters (property.ParamCount, m_blobData, start, out start);
+ }
+
+ public override void VisitLocalVarSig (LocalVarSig localvar)
+ {
+ int start;
+ Utilities.ReadCompressedInteger (m_blobData, (int) localvar.BlobIndex, out start);
+ localvar.CallingConvention = m_blobData [start];
+ localvar.Local = (localvar.CallingConvention & 0x7) != 0;
+ localvar.Count = Utilities.ReadCompressedInteger (m_blobData, start + 1, out start);
+ localvar.LocalVariables = ReadLocalVariables (localvar.Count, m_blobData, start);
+ }
+
+ void ReadMethodDefSig (MethodDefSig methodDef, byte [] data, int pos, out int start)
+ {
+ methodDef.CallingConvention = data [pos];
+ start = pos + 1;
+ methodDef.HasThis = (methodDef.CallingConvention & 0x20) != 0;
+ methodDef.ExplicitThis = (methodDef.CallingConvention & 0x40) != 0;
+ if ((methodDef.CallingConvention & 0x5) != 0)
+ methodDef.MethCallConv |= MethodCallingConvention.VarArg;
+ else if ((methodDef.CallingConvention & 0x10) != 0) {
+ methodDef.MethCallConv |= MethodCallingConvention.Generic;
+ methodDef.GenericParameterCount = Utilities.ReadCompressedInteger (data, start, out start);
+ } else
+ methodDef.MethCallConv |= MethodCallingConvention.Default;
+
+ methodDef.ParamCount = Utilities.ReadCompressedInteger (data, start, out start);
+ methodDef.RetType = ReadRetType (data, start, out start);
+ int sentpos;
+ methodDef.Parameters = ReadParameters (methodDef.ParamCount, data, start, out start, out sentpos);
+ methodDef.Sentinel = sentpos;
+ }
+
+ void ReadMethodRefSig (MethodRefSig methodRef, byte [] data, int pos, out int start)
+ {
+ methodRef.CallingConvention = data [pos];
+ start = pos + 1;
+ methodRef.HasThis = (methodRef.CallingConvention & 0x20) != 0;
+ methodRef.ExplicitThis = (methodRef.CallingConvention & 0x40) != 0;
+ if ((methodRef.CallingConvention & 0x1) != 0)
+ methodRef.MethCallConv |= MethodCallingConvention.C;
+ else if ((methodRef.CallingConvention & 0x2) != 0)
+ methodRef.MethCallConv |= MethodCallingConvention.StdCall;
+ else if ((methodRef.CallingConvention & 0x3) != 0)
+ methodRef.MethCallConv |= MethodCallingConvention.ThisCall;
+ else if ((methodRef.CallingConvention & 0x4) != 0)
+ methodRef.MethCallConv |= MethodCallingConvention.FastCall;
+ else if ((methodRef.CallingConvention & 0x5) != 0)
+ methodRef.MethCallConv |= MethodCallingConvention.VarArg;
+ else
+ methodRef.MethCallConv |= MethodCallingConvention.Default;
+ methodRef.ParamCount = Utilities.ReadCompressedInteger (data, start, out start);
+ methodRef.RetType = ReadRetType (data, start, out start);
+ int sentpos;
+ methodRef.Parameters = ReadParameters (methodRef.ParamCount, data, start, out start, out sentpos);
+ methodRef.Sentinel = sentpos;
+ }
+
+ LocalVarSig.LocalVariable [] ReadLocalVariables (int length, byte [] data, int pos)
+ {
+ int start = pos;
+ LocalVarSig.LocalVariable [] types = new LocalVarSig.LocalVariable [length];
+ for (int i = 0; i < length; i++)
+ types [i] = ReadLocalVariable (data, start, out start);
+ return types;
+ }
+
+ LocalVarSig.LocalVariable ReadLocalVariable (byte [] data, int pos, out int start)
+ {
+ start = pos;
+ LocalVarSig.LocalVariable lv = new LocalVarSig.LocalVariable ();
+ lv.ByRef = false;
+ int cursor;
+ while (true) {
+ lv.CustomMods = ReadCustomMods (data, start, out start);
+ cursor = start;
+ int current = Utilities.ReadCompressedInteger (data, start, out start);
+ if (current == (int) ElementType.Pinned) // the only possible constraint
+ lv.Constraint |= Constraint.Pinned;
+ else if (current == (int) ElementType.ByRef) {
+ lv.ByRef = true;
+
+ if (lv.CustomMods == null || lv.CustomMods.Length == 0)
+ lv.CustomMods = ReadCustomMods (data, start, out start);
+ } else {
+ lv.Type = ReadType (data, cursor, out start);
+ break;
+ }
+ }
+ return lv;
+ }
+
+ TypeSpec ReadTypeSpec (byte [] data, int pos)
+ {
+ int start = pos;
+ Utilities.ReadCompressedInteger (data, start, out start);
+ TypeSpec ts = new TypeSpec ();
+ ts.CustomMods = ReadCustomMods (data, start, out start);
+ ts.Type = ReadType (data, start, out start);
+ return ts;
+ }
+
+ MethodSpec ReadMethodSpec (byte [] data, int pos)
+ {
+ int start = pos;
+
+ Utilities.ReadCompressedInteger (data, start, out start);
+ if (Utilities.ReadCompressedInteger (data, start, out start) != 0x0a)
+ throw new ReflectionException ("Invalid MethodSpec signature");
+
+ return new MethodSpec (ReadGenericInstSignature (data, start, out start));
+ }
+
+ RetType ReadRetType (byte [] data, int pos, out int start)
+ {
+ RetType rt = new RetType ();
+ start = pos;
+ rt.CustomMods = ReadCustomMods (data, start, out start);
+ int curs = start;
+ ElementType flag = (ElementType) Utilities.ReadCompressedInteger (data, start, out start);
+ switch (flag) {
+ case ElementType.Void :
+ rt.ByRef = rt.TypedByRef = false;
+ rt.Void = true;
+ break;
+ case ElementType.TypedByRef :
+ rt.ByRef = rt.Void = false;
+ rt.TypedByRef = true;
+ break;
+ case ElementType.ByRef :
+ rt.TypedByRef = rt.Void = false;
+ rt.ByRef = true;
+ rt.CustomMods = CombineCustomMods(rt.CustomMods, ReadCustomMods (data, start, out start));
+ rt.Type = ReadType (data, start, out start);
+ break;
+ default :
+ rt.TypedByRef = rt.Void = rt.ByRef = false;
+ rt.Type = ReadType (data, curs, out start);
+ break;
+ }
+
+ return rt;
+ }
+
+ static CustomMod [] CombineCustomMods (CustomMod [] original, CustomMod [] next)
+ {
+ if (next == null || next.Length == 0)
+ return original;
+
+ CustomMod [] mods = new CustomMod [original.Length + next.Length];
+ Array.Copy (original, mods, original.Length);
+ Array.Copy (next, 0, mods, original.Length, next.Length);
+ return mods;
+ }
+
+ Param [] ReadParameters (int length, byte [] data, int pos, out int start)
+ {
+ Param [] ret = new Param [length];
+ start = pos;
+ for (int i = 0; i < length; i++)
+ ret [i] = ReadParameter (data, start, out start);
+ return ret;
+ }
+
+ Param [] ReadParameters (int length, byte [] data, int pos, out int start, out int sentinelpos)
+ {
+ Param [] ret = new Param [length];
+ start = pos;
+ sentinelpos = -1;
+
+ for (int i = 0; i < length; i++) {
+ int curs = start;
+ int flag = Utilities.ReadCompressedInteger (data, start, out start);
+
+ if (flag == (int) ElementType.Sentinel) {
+ sentinelpos = i;
+ curs = start;
+ }
+
+ ret [i] = ReadParameter (data, curs, out start);
+ }
+
+ return ret;
+ }
+
+ Param ReadParameter (byte [] data, int pos, out int start)
+ {
+ Param p = new Param ();
+ start = pos;
+
+ p.CustomMods = ReadCustomMods (data, start, out start);
+ int curs = start;
+ ElementType flag = (ElementType) Utilities.ReadCompressedInteger (data, start, out start);
+ switch (flag) {
+ case ElementType.TypedByRef :
+ p.TypedByRef = true;
+ p.ByRef = false;
+ break;
+ case ElementType.ByRef :
+ p.TypedByRef = false;
+ p.ByRef = true;
+
+ if (p.CustomMods == null || p.CustomMods.Length == 0)
+ p.CustomMods = ReadCustomMods (data, start, out start);
+
+ p.Type = ReadType (data, start, out start);
+ break;
+ default :
+ p.TypedByRef = false;
+ p.ByRef = false;
+ p.Type = ReadType (data, curs, out start);
+ break;
+ }
+ return p;
+ }
+
+ SigType ReadType (byte [] data, int pos, out int start)
+ {
+ start = pos;
+ ElementType element = (ElementType) Utilities.ReadCompressedInteger (data, start, out start);
+ switch (element) {
+ case ElementType.ValueType :
+ VALUETYPE vt = new VALUETYPE ();
+ vt.Type = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
+ (uint) Utilities.ReadCompressedInteger (data, start, out start));
+ return vt;
+ case ElementType.Class :
+ CLASS c = new CLASS ();
+ c.Type = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
+ (uint) Utilities.ReadCompressedInteger (data, start, out start));
+ return c;
+ case ElementType.Ptr :
+ PTR p = new PTR ();
+ int buf = start;
+ int flag = Utilities.ReadCompressedInteger (data, start, out start);
+ p.Void = flag == (int) ElementType.Void;
+ if (p.Void)
+ return p;
+ start = buf;
+ p.CustomMods = ReadCustomMods (data, start, out start);
+ p.PtrType = ReadType (data, start, out start);
+ return p;
+ case ElementType.FnPtr :
+ FNPTR fp = new FNPTR ();
+ if ((data [start] & 0x5) != 0) {
+ MethodRefSig mr = new MethodRefSig ((uint) start);
+ ReadMethodRefSig (mr, data, start, out start);
+ fp.Method = mr;
+ } else {
+ MethodDefSig md = new MethodDefSig ((uint) start);
+ ReadMethodDefSig (md, data, start, out start);
+ fp.Method = md;
+ }
+ return fp;
+ case ElementType.Array :
+ ARRAY ary = new ARRAY ();
+ ary.CustomMods = ReadCustomMods (data, start, out start);
+ ArrayShape shape = new ArrayShape ();
+ ary.Type = ReadType (data, start, out start);
+ shape.Rank = Utilities.ReadCompressedInteger (data, start, out start);
+ shape.NumSizes = Utilities.ReadCompressedInteger (data, start, out start);
+ shape.Sizes = new int [shape.NumSizes];
+ for (int i = 0; i < shape.NumSizes; i++)
+ shape.Sizes [i] = Utilities.ReadCompressedInteger (data, start, out start);
+ shape.NumLoBounds = Utilities.ReadCompressedInteger (data, start, out start);
+ shape.LoBounds = new int [shape.NumLoBounds];
+ for (int i = 0; i < shape.NumLoBounds; i++)
+ shape.LoBounds [i] = Utilities.ReadCompressedInteger (data, start, out start);
+ ary.Shape = shape;
+ return ary;
+ case ElementType.SzArray :
+ SZARRAY sa = new SZARRAY ();
+ sa.CustomMods = ReadCustomMods (data, start, out start);
+ sa.Type = ReadType (data, start, out start);
+ return sa;
+ case ElementType.Var:
+ return new VAR (Utilities.ReadCompressedInteger (data, start, out start));
+ case ElementType.MVar:
+ return new MVAR (Utilities.ReadCompressedInteger (data, start, out start));
+ case ElementType.GenericInst:
+ GENERICINST ginst = new GENERICINST ();
+
+ ginst.ValueType = ((ElementType) Utilities.ReadCompressedInteger (
+ data, start, out start)) == ElementType.ValueType;
+
+ ginst.Type = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
+ (uint) Utilities.ReadCompressedInteger (data, start, out start));
+
+ ginst.Signature = ReadGenericInstSignature (data, start, out start);
+
+ return ginst;
+ default :
+ return new SigType (element);
+ }
+ }
+
+ GenericInstSignature ReadGenericInstSignature (byte [] data, int pos, out int start)
+ {
+ start = pos;
+ GenericInstSignature gis = new GenericInstSignature ();
+ gis.Arity = Utilities.ReadCompressedInteger (data, start, out start);
+ gis.Types = new GenericArg [gis.Arity];
+ for (int i = 0; i < gis.Arity; i++)
+ gis.Types [i] = ReadGenericArg (data, start, out start);
+
+ return gis;
+ }
+
+ GenericArg ReadGenericArg (byte[] data, int pos, out int start)
+ {
+ start = pos;
+ CustomMod [] mods = ReadCustomMods (data, start, out start);
+ GenericArg arg = new GenericArg (ReadType (data, start, out start));
+ arg.CustomMods = mods;
+ return arg;
+ }
+
+ CustomMod [] ReadCustomMods (byte [] data, int pos, out int start)
+ {
+ ArrayList cmods = null;
+ start = pos;
+ while (true) {
+ int buf = start;
+ if (buf >= data.Length - 1)
+ break;
+
+ ElementType flag = (ElementType) Utilities.ReadCompressedInteger (data, start, out start);
+ start = buf;
+ if (!((flag == ElementType.CModOpt) || (flag == ElementType.CModReqD)))
+ break;
+
+ if (cmods == null)
+ cmods = new ArrayList (2);
+
+ cmods.Add (ReadCustomMod (data, start, out start));
+ }
+
+ return cmods == null ? CustomMod.EmptyCustomMod : cmods.ToArray (typeof (CustomMod)) as CustomMod [];
+ }
+
+ CustomMod ReadCustomMod (byte [] data, int pos, out int start)
+ {
+ CustomMod cm = new CustomMod ();
+ start = pos;
+ ElementType cmod = (ElementType) Utilities.ReadCompressedInteger (data, start, out start);
+ if (cmod == ElementType.CModOpt)
+ cm.CMOD = CustomMod.CMODType.OPT;
+ else if (cmod == ElementType.CModReqD)
+ cm.CMOD = CustomMod.CMODType.REQD;
+ else
+ cm.CMOD = CustomMod.CMODType.None;
+ cm.TypeDefOrRef = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef,
+ (uint) Utilities.ReadCompressedInteger (data, start, out start));
+ return cm;
+ }
+
+ CustomAttrib ReadCustomAttrib (int pos, MethodReference ctor, bool resolve)
+ {
+ int start, length = Utilities.ReadCompressedInteger (m_blobData, pos, out start);
+ byte [] data = new byte [length];
+ Buffer.BlockCopy (m_blobData, start, data, 0, length);
+ try {
+ return ReadCustomAttrib (new BinaryReader (
+ new MemoryStream (data)), data, ctor, resolve);
+ } catch {
+ CustomAttrib ca = new CustomAttrib (ctor);
+ ca.Read = false;
+ return ca;
+ }
+ }
+
+ CustomAttrib ReadCustomAttrib (BinaryReader br, byte [] data, MethodReference ctor, bool resolve)
+ {
+ CustomAttrib ca = new CustomAttrib (ctor);
+ if (data.Length == 0) {
+ ca.FixedArgs = CustomAttrib.FixedArg.Empty;
+ ca.NamedArgs = CustomAttrib.NamedArg.Empty;
+ return ca;
+ }
+
+ bool read = true;
+
+ ca.Prolog = br.ReadUInt16 ();
+ if (ca.Prolog != CustomAttrib.StdProlog)
+ throw new MetadataFormatException ("Non standard prolog for custom attribute");
+
+ if (ctor.HasParameters) {
+ ca.FixedArgs = new CustomAttrib.FixedArg [ctor.Parameters.Count];
+ for (int i = 0; i < ca.FixedArgs.Length && read; i++)
+ ca.FixedArgs [i] = ReadFixedArg (data, br,
+ ctor.Parameters [i].ParameterType, ref read, resolve);
+ } else {
+ ca.FixedArgs = CustomAttrib.FixedArg.Empty;
+ }
+
+ if (br.BaseStream.Position == br.BaseStream.Length)
+ read = false;
+
+ if (!read) {
+ ca.Read = read;
+ return ca;
+ }
+
+ ca.NumNamed = br.ReadUInt16 ();
+ if (ca.NumNamed > 0) {
+ ca.NamedArgs = new CustomAttrib.NamedArg [ca.NumNamed];
+ for (int i = 0; i < ca.NumNamed && read; i++)
+ ca.NamedArgs [i] = ReadNamedArg (data, br, ref read, resolve);
+ } else {
+ ca.NamedArgs = CustomAttrib.NamedArg.Empty;
+ }
+
+ ca.Read = read;
+ return ca;
+ }
+
+ CustomAttrib.FixedArg ReadFixedArg (byte [] data, BinaryReader br,
+ TypeReference param, ref bool read, bool resolve)
+ {
+ CustomAttrib.FixedArg fa = new CustomAttrib.FixedArg ();
+ if (param is ArrayType) {
+ param = ((ArrayType) param).ElementType;
+ fa.SzArray = true;
+ fa.NumElem = br.ReadUInt32 ();
+
+ if (fa.NumElem == 0 || fa.NumElem == 0xffffffff) {
+ fa.Elems = new CustomAttrib.Elem [0];
+ fa.NumElem = 0;
+ return fa;
+ }
+
+ fa.Elems = new CustomAttrib.Elem [fa.NumElem];
+ for (int i = 0; i < fa.NumElem; i++)
+ fa.Elems [i] = ReadElem (data, br, param, ref read, resolve);
+ } else
+ fa.Elems = new CustomAttrib.Elem [] { ReadElem (data, br, param, ref read, resolve) };
+
+ return fa;
+ }
+
+ TypeReference CreateEnumTypeReference (string enumName)
+ {
+ string asmName = null;
+ int asmStart = enumName.IndexOf (',');
+ if (asmStart != -1) {
+ asmName = enumName.Substring (asmStart + 1);
+ enumName = enumName.Substring (0, asmStart);
+ }
+ // Inner class style is reflection style.
+ enumName = enumName.Replace ('+', '/');
+ AssemblyNameReference asm;
+ if (asmName == null) {
+ // If no assembly is given then the ECMA standard says the
+ // assembly is either the current one or mscorlib.
+ if (m_reflectReader.Module.Types.Contains (enumName))
+ return m_reflectReader.Module.Types [enumName];
+
+ asm = m_reflectReader.Corlib;
+ } else
+ asm = AssemblyNameReference.Parse (asmName);
+
+ string [] outers = enumName.Split ('/');
+ string outerfullname = outers [0];
+ string ns = null;
+ int nsIndex = outerfullname.LastIndexOf ('.');
+ if (nsIndex != -1)
+ ns = outerfullname.Substring (0, nsIndex);
+ string name = outerfullname.Substring (nsIndex + 1);
+ TypeReference decType = new TypeReference (name, ns, asm);
+ for (int i = 1; i < outers.Length; i++) {
+ TypeReference t = new TypeReference (outers [i], null, asm);
+ t.Module = m_reflectReader.Module;
+ t.DeclaringType = decType;
+ decType = t;
+ }
+ decType.Module = m_reflectReader.Module;
+ decType.IsValueType = true;
+
+ return decType;
+ }
+
+ TypeReference ReadTypeReference (byte [] data, BinaryReader br, out ElementType elemType)
+ {
+ bool array = false;
+ elemType = (ElementType) br.ReadByte ();
+ if (elemType == ElementType.SzArray) {
+ elemType = (ElementType) br.ReadByte ();
+ array = true;
+ }
+
+ TypeReference res;
+ if (elemType == ElementType.Enum)
+ res = CreateEnumTypeReference (ReadUTF8String (data, br));
+ else
+ res = TypeReferenceFromElemType (elemType);
+
+ if (array)
+ res = new ArrayType (res);
+
+ return res;
+ }
+
+ TypeReference TypeReferenceFromElemType (ElementType elemType)
+ {
+ switch (elemType) {
+ case ElementType.Boxed :
+ case ElementType.Object:
+ return m_reflectReader.SearchCoreType (Constants.Object);
+ case ElementType.String :
+ return m_reflectReader.SearchCoreType (Constants.String);
+ case ElementType.Type :
+ return m_reflectReader.SearchCoreType (Constants.Type);
+ case ElementType.Boolean :
+ return m_reflectReader.SearchCoreType (Constants.Boolean);
+ case ElementType.Char :
+ return m_reflectReader.SearchCoreType (Constants.Char);
+ case ElementType.R4 :
+ return m_reflectReader.SearchCoreType (Constants.Single);
+ case ElementType.R8 :
+ return m_reflectReader.SearchCoreType (Constants.Double);
+ case ElementType.I1 :
+ return m_reflectReader.SearchCoreType (Constants.SByte);
+ case ElementType.I2 :
+ return m_reflectReader.SearchCoreType (Constants.Int16);
+ case ElementType.I4 :
+ return m_reflectReader.SearchCoreType (Constants.Int32);
+ case ElementType.I8 :
+ return m_reflectReader.SearchCoreType (Constants.Int64);
+ case ElementType.U1 :
+ return m_reflectReader.SearchCoreType (Constants.Byte);
+ case ElementType.U2 :
+ return m_reflectReader.SearchCoreType (Constants.UInt16);
+ case ElementType.U4 :
+ return m_reflectReader.SearchCoreType (Constants.UInt32);
+ case ElementType.U8 :
+ return m_reflectReader.SearchCoreType (Constants.UInt64);
+ default :
+ throw new MetadataFormatException ("Non valid type in CustomAttrib.Elem: 0x{0}",
+ ((byte) elemType).ToString("x2"));
+ }
+ }
+
+ internal CustomAttrib.NamedArg ReadNamedArg (byte [] data, BinaryReader br, ref bool read, bool resolve)
+ {
+ CustomAttrib.NamedArg na = new CustomAttrib.NamedArg ();
+ byte kind = br.ReadByte ();
+ if (kind == 0x53) { // field
+ na.Field = true;
+ na.Property = false;
+ } else if (kind == 0x54) { // property
+ na.Field = false;
+ na.Property = true;
+ } else
+ throw new MetadataFormatException ("Wrong kind of namedarg found: 0x" + kind.ToString("x2"));
+
+ TypeReference elemType = ReadTypeReference (data, br, out na.FieldOrPropType);
+ na.FieldOrPropName = ReadUTF8String (data, br);
+ na.FixedArg = ReadFixedArg (data, br, elemType, ref read, resolve);
+
+ return na;
+ }
+
+ CustomAttrib.Elem ReadElem (byte [] data, BinaryReader br, TypeReference elemType, ref bool read, bool resolve)
+ {
+ CustomAttrib.Elem elem = new CustomAttrib.Elem ();
+
+ string elemName = elemType.FullName;
+
+ if (elemName == Constants.Object) {
+ elemType = ReadTypeReference (data, br, out elem.FieldOrPropType);
+ if (elemType is ArrayType) {
+ read = false; // Don't know how to represent arrays as an object value.
+ return elem;
+ } else if (elemType.FullName == Constants.Object)
+ throw new MetadataFormatException ("Non valid type in CustomAttrib.Elem after boxed prefix: 0x{0}",
+ ((byte) elem.FieldOrPropType).ToString ("x2"));
+
+ elem = ReadElem (data, br, elemType, ref read, resolve);
+ elem.String = elem.Simple = elem.Type = false;
+ elem.BoxedValueType = true;
+ return elem;
+ }
+
+ elem.ElemType = elemType;
+
+ if (elemName == Constants.Type || elemName == Constants.String) {
+ switch (elemType.FullName) {
+ case Constants.String:
+ elem.String = true;
+ elem.BoxedValueType = elem.Simple = elem.Type = false;
+ break;
+ case Constants.Type:
+ elem.Type = true;
+ elem.BoxedValueType = elem.Simple = elem.String = false;
+ break;
+ }
+
+ if (data [br.BaseStream.Position] == 0xff) { // null
+ elem.Value = null;
+ br.BaseStream.Position++;
+ } else {
+ elem.Value = ReadUTF8String (data, br);
+ }
+ return elem;
+ }
+
+ elem.String = elem.Type = elem.BoxedValueType = false;
+ if (!ReadSimpleValue (br, ref elem, elem.ElemType)) {
+ if (!resolve) { // until enums writing is implemented
+ read = false;
+ return elem;
+ }
+ TypeReference typeRef = GetEnumUnderlyingType (elem.ElemType, resolve);
+ if (typeRef == null || !ReadSimpleValue (br, ref elem, typeRef))
+ read = false;
+ }
+
+ return elem;
+ }
+
+ TypeReference GetEnumUnderlyingType (TypeReference enumType, bool resolve)
+ {
+ TypeDefinition type = enumType as TypeDefinition;
+ if (type == null && resolve && AssemblyResolver != null) {
+ if (enumType.Scope is ModuleDefinition)
+ throw new NotSupportedException ();
+
+ AssemblyDefinition asm = AssemblyResolver.Resolve (
+ ((AssemblyNameReference) enumType.Scope).FullName);
+
+ if (asm != null)
+ type = asm.MainModule.Types [enumType.FullName];
+ }
+
+ if (type != null && type.IsEnum)
+ return type.Fields.GetField ("value__").FieldType;
+
+ return null;
+ }
+
+ bool ReadSimpleValue (BinaryReader br, ref CustomAttrib.Elem elem, TypeReference type)
+ {
+ switch (type.FullName) {
+ case Constants.Boolean :
+ elem.Value = br.ReadByte () == 1;
+ break;
+ case Constants.Char :
+ elem.Value = (char) br.ReadUInt16 ();
+ break;
+ case Constants.Single :
+ elem.Value = br.ReadSingle ();
+ break;
+ case Constants.Double :
+ elem.Value = br.ReadDouble ();
+ break;
+ case Constants.Byte :
+ elem.Value = br.ReadByte ();
+ break;
+ case Constants.Int16 :
+ elem.Value = br.ReadInt16 ();
+ break;
+ case Constants.Int32 :
+ elem.Value = br.ReadInt32 ();
+ break;
+ case Constants.Int64 :
+ elem.Value = br.ReadInt64 ();
+ break;
+ case Constants.SByte :
+ elem.Value = br.ReadSByte ();
+ break;
+ case Constants.UInt16 :
+ elem.Value = br.ReadUInt16 ();
+ break;
+ case Constants.UInt32 :
+ elem.Value = br.ReadUInt32 ();
+ break;
+ case Constants.UInt64 :
+ elem.Value = br.ReadUInt64 ();
+ break;
+ default : // enum
+ return false;
+ }
+ elem.Simple = true;
+ return true;
+ }
+
+ MarshalSig ReadMarshalSig (byte [] data)
+ {
+ int start;
+ MarshalSig ms = new MarshalSig ((NativeType) Utilities.ReadCompressedInteger (data, 0, out start));
+ switch (ms.NativeInstrinsic) {
+ case NativeType.ARRAY:
+ MarshalSig.Array ar = new MarshalSig.Array ();
+ ar.ArrayElemType = (NativeType) Utilities.ReadCompressedInteger (data, start, out start);
+ if (start < data.Length)
+ ar.ParamNum = Utilities.ReadCompressedInteger (data, start, out start);
+ if (start < data.Length)
+ ar.NumElem = Utilities.ReadCompressedInteger (data, start, out start);
+ if (start < data.Length)
+ ar.ElemMult = Utilities.ReadCompressedInteger (data, start, out start);
+ ms.Spec = ar;
+ break;
+ case NativeType.CUSTOMMARSHALER:
+ MarshalSig.CustomMarshaler cm = new MarshalSig.CustomMarshaler ();
+ cm.Guid = ReadUTF8String (data, start, out start);
+ cm.UnmanagedType = ReadUTF8String (data, start, out start);
+ cm.ManagedType = ReadUTF8String (data, start, out start);
+ cm.Cookie = ReadUTF8String (data, start, out start);
+ ms.Spec = cm;
+ break;
+ case NativeType.FIXEDARRAY:
+ MarshalSig.FixedArray fa = new MarshalSig.FixedArray ();
+ fa.NumElem = Utilities.ReadCompressedInteger (data, start, out start);
+ if (start < data.Length)
+ fa.ArrayElemType = (NativeType) Utilities.ReadCompressedInteger (data, start, out start);
+ ms.Spec = fa;
+ break;
+ case NativeType.SAFEARRAY:
+ MarshalSig.SafeArray sa = new MarshalSig.SafeArray ();
+ if (start < data.Length)
+ sa.ArrayElemType = (VariantType) Utilities.ReadCompressedInteger (data, start, out start);
+ ms.Spec = sa;
+ break;
+ case NativeType.FIXEDSYSSTRING:
+ MarshalSig.FixedSysString fss = new MarshalSig.FixedSysString ();
+ if (start < data.Length)
+ fss.Size = Utilities.ReadCompressedInteger (data, start, out start);
+ ms.Spec = fss;
+ break;
+ }
+ return ms;
+ }
+
+ static internal string ReadUTF8String (byte [] data, BinaryReader br)
+ {
+ int start = (int)br.BaseStream.Position;
+ string val = ReadUTF8String (data, start, out start);
+ br.BaseStream.Position = start;
+ return val;
+ }
+
+ static internal string ReadUTF8String (byte [] data, int pos, out int start)
+ {
+ int length = Utilities.ReadCompressedInteger (data, pos, out start);
+ pos = start;
+ start += length;
+ // COMPACT FRAMEWORK NOTE: Encoding.GetString (byte[]) is not supported.
+ return Encoding.UTF8.GetString (data, pos, length);
+ }
+ }
+}
--- /dev/null
+//
+// SignatureWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using System;
+ using System.Text;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Binary;
+ using Mono.Cecil.Metadata;
+
+ internal sealed class SignatureWriter : BaseSignatureVisitor {
+
+ MetadataWriter m_mdWriter;
+ MemoryBinaryWriter m_sigWriter;
+
+ public SignatureWriter (MetadataWriter mdWriter)
+ {
+ m_mdWriter = mdWriter;
+ m_sigWriter = new MemoryBinaryWriter ();
+ }
+
+ uint GetPointer ()
+ {
+ return m_mdWriter.AddBlob (m_sigWriter.ToArray ());
+ }
+
+ public uint AddMethodDefSig (MethodDefSig methSig)
+ {
+ return AddSignature (methSig);
+ }
+
+ public uint AddMethodRefSig (MethodRefSig methSig)
+ {
+ return AddSignature (methSig);
+ }
+
+ public uint AddPropertySig (PropertySig ps)
+ {
+ return AddSignature (ps);
+ }
+
+ public uint AddFieldSig (FieldSig fSig)
+ {
+ return AddSignature (fSig);
+ }
+
+ public uint AddLocalVarSig (LocalVarSig lvs)
+ {
+ return AddSignature (lvs);
+ }
+
+ uint AddSignature (Signature s)
+ {
+ m_sigWriter.Empty ();
+ s.Accept (this);
+ return GetPointer ();
+ }
+
+ public uint AddTypeSpec (TypeSpec ts)
+ {
+ m_sigWriter.Empty ();
+ Write (ts);
+ return GetPointer ();
+ }
+
+ public uint AddMethodSpec (MethodSpec ms)
+ {
+ m_sigWriter.Empty ();
+ Write (ms);
+ return GetPointer ();
+ }
+
+ public uint AddMarshalSig (MarshalSig ms)
+ {
+ m_sigWriter.Empty ();
+ Write (ms);
+ return GetPointer ();
+ }
+
+ public uint AddCustomAttribute (CustomAttrib ca, MethodReference ctor)
+ {
+ CompressCustomAttribute (ca, ctor, m_sigWriter);
+ return GetPointer ();
+ }
+
+ public byte [] CompressCustomAttribute (CustomAttrib ca, MethodReference ctor)
+ {
+ MemoryBinaryWriter writer = new MemoryBinaryWriter ();
+ CompressCustomAttribute (ca, ctor, writer);
+ return writer.ToArray ();
+ }
+
+ public byte [] CompressFieldSig (FieldSig field)
+ {
+ m_sigWriter.Empty ();
+ VisitFieldSig (field);
+ return m_sigWriter.ToArray ();
+ }
+
+ public byte [] CompressLocalVar (LocalVarSig.LocalVariable var)
+ {
+ m_sigWriter.Empty ();
+ Write (var);
+ return m_sigWriter.ToArray ();
+ }
+
+ void CompressCustomAttribute (CustomAttrib ca, MethodReference ctor, MemoryBinaryWriter writer)
+ {
+ m_sigWriter.Empty ();
+ Write (ca, ctor, writer);
+ }
+
+ public override void VisitMethodDefSig (MethodDefSig methodDef)
+ {
+ m_sigWriter.Write (methodDef.CallingConvention);
+ if (methodDef.GenericParameterCount > 0)
+ Write (methodDef.GenericParameterCount);
+ Write (methodDef.ParamCount);
+ Write (methodDef.RetType);
+ Write (methodDef.Parameters, methodDef.Sentinel);
+ }
+
+ public override void VisitMethodRefSig (MethodRefSig methodRef)
+ {
+ m_sigWriter.Write (methodRef.CallingConvention);
+ Write (methodRef.ParamCount);
+ Write (methodRef.RetType);
+ Write (methodRef.Parameters, methodRef.Sentinel);
+ }
+
+ public override void VisitFieldSig (FieldSig field)
+ {
+ m_sigWriter.Write (field.CallingConvention);
+ Write (field.CustomMods);
+ Write (field.Type);
+ }
+
+ public override void VisitPropertySig (PropertySig property)
+ {
+ m_sigWriter.Write (property.CallingConvention);
+ Write (property.ParamCount);
+ Write (property.CustomMods);
+ Write (property.Type);
+ Write (property.Parameters);
+ }
+
+ public override void VisitLocalVarSig (LocalVarSig localvar)
+ {
+ m_sigWriter.Write (localvar.CallingConvention);
+ Write (localvar.Count);
+ Write (localvar.LocalVariables);
+ }
+
+ void Write (LocalVarSig.LocalVariable [] vars)
+ {
+ foreach (LocalVarSig.LocalVariable var in vars)
+ Write (var);
+ }
+
+ void Write (LocalVarSig.LocalVariable var)
+ {
+ Write (var.CustomMods);
+ if ((var.Constraint & Constraint.Pinned) != 0)
+ Write (ElementType.Pinned);
+ if (var.ByRef)
+ Write (ElementType.ByRef);
+ Write (var.Type);
+ }
+
+ void Write (RetType retType)
+ {
+ Write (retType.CustomMods);
+ if (retType.Void)
+ Write (ElementType.Void);
+ else if (retType.TypedByRef)
+ Write (ElementType.TypedByRef);
+ else if (retType.ByRef) {
+ Write (ElementType.ByRef);
+ Write (retType.Type);
+ } else
+ Write (retType.Type);
+ }
+
+ void Write (Param [] parameters, int sentinel)
+ {
+ for (int i = 0; i < parameters.Length; i++) {
+ if (i == sentinel)
+ Write (ElementType.Sentinel);
+
+ Write (parameters [i]);
+ }
+ }
+
+ void Write (Param [] parameters)
+ {
+ foreach (Param p in parameters)
+ Write (p);
+ }
+
+ void Write (ElementType et)
+ {
+ Write ((int) et);
+ }
+
+ void Write (SigType t)
+ {
+ Write ((int) t.ElementType);
+
+ switch (t.ElementType) {
+ case ElementType.ValueType :
+ Write ((int) Utilities.CompressMetadataToken (
+ CodedIndex.TypeDefOrRef, ((VALUETYPE) t).Type));
+ break;
+ case ElementType.Class :
+ Write ((int) Utilities.CompressMetadataToken (
+ CodedIndex.TypeDefOrRef, ((CLASS) t).Type));
+ break;
+ case ElementType.Ptr :
+ PTR p = (PTR) t;
+ if (p.Void)
+ Write (ElementType.Void);
+ else {
+ Write (p.CustomMods);
+ Write (p.PtrType);
+ }
+ break;
+ case ElementType.FnPtr :
+ FNPTR fp = (FNPTR) t;
+ if (fp.Method is MethodRefSig)
+ (fp.Method as MethodRefSig).Accept (this);
+ else
+ (fp.Method as MethodDefSig).Accept (this);
+ break;
+ case ElementType.Array :
+ ARRAY ary = (ARRAY) t;
+ Write (ary.CustomMods);
+ ArrayShape shape = ary.Shape;
+ Write (ary.Type);
+ Write (shape.Rank);
+ Write (shape.NumSizes);
+ foreach (int size in shape.Sizes)
+ Write (size);
+ Write (shape.NumLoBounds);
+ foreach (int loBound in shape.LoBounds)
+ Write (loBound);
+ break;
+ case ElementType.SzArray :
+ SZARRAY sa = (SZARRAY) t;
+ Write (sa.CustomMods);
+ Write (sa.Type);
+ break;
+ case ElementType.Var :
+ Write (((VAR) t).Index);
+ break;
+ case ElementType.MVar :
+ Write (((MVAR) t).Index);
+ break;
+ case ElementType.GenericInst :
+ GENERICINST gi = t as GENERICINST;
+ Write (gi.ValueType ? ElementType.ValueType : ElementType.Class);
+ Write ((int) Utilities.CompressMetadataToken (
+ CodedIndex.TypeDefOrRef, gi.Type));
+ Write (gi.Signature);
+ break;
+ }
+ }
+
+ void Write (TypeSpec ts)
+ {
+ Write (ts.CustomMods);
+ Write (ts.Type);
+ }
+
+ void Write (MethodSpec ms)
+ {
+ Write (0x0a);
+ Write (ms.Signature);
+ }
+
+ void Write (GenericInstSignature gis)
+ {
+ Write (gis.Arity);
+ for (int i = 0; i < gis.Arity; i++)
+ Write (gis.Types [i]);
+ }
+
+ void Write (GenericArg arg)
+ {
+ Write (arg.CustomMods);
+ Write (arg.Type);
+ }
+
+ void Write (Param p)
+ {
+ Write (p.CustomMods);
+ if (p.TypedByRef)
+ Write (ElementType.TypedByRef);
+ else if (p.ByRef) {
+ Write (ElementType.ByRef);
+ Write (p.Type);
+ } else
+ Write (p.Type);
+ }
+
+ void Write (CustomMod [] customMods)
+ {
+ foreach (CustomMod cm in customMods)
+ Write (cm);
+ }
+
+ void Write (CustomMod cm)
+ {
+ switch (cm.CMOD) {
+ case CustomMod.CMODType.OPT :
+ Write (ElementType.CModOpt);
+ break;
+ case CustomMod.CMODType.REQD :
+ Write (ElementType.CModReqD);
+ break;
+ }
+
+ Write ((int) Utilities.CompressMetadataToken (
+ CodedIndex.TypeDefOrRef, cm.TypeDefOrRef));
+ }
+
+ void Write (MarshalSig ms)
+ {
+ Write ((int) ms.NativeInstrinsic);
+ switch (ms.NativeInstrinsic) {
+ case NativeType.ARRAY :
+ MarshalSig.Array ar = (MarshalSig.Array) ms.Spec;
+ Write ((int) ar.ArrayElemType);
+ if (ar.ParamNum != -1)
+ Write (ar.ParamNum);
+ if (ar.NumElem != -1)
+ Write (ar.NumElem);
+ if (ar.ElemMult != -1)
+ Write (ar.ElemMult);
+ break;
+ case NativeType.CUSTOMMARSHALER :
+ MarshalSig.CustomMarshaler cm = (MarshalSig.CustomMarshaler) ms.Spec;
+ Write (cm.Guid);
+ Write (cm.UnmanagedType);
+ Write (cm.ManagedType);
+ Write (cm.Cookie);
+ break;
+ case NativeType.FIXEDARRAY :
+ MarshalSig.FixedArray fa = (MarshalSig.FixedArray) ms.Spec;
+ Write (fa.NumElem);
+ if (fa.ArrayElemType != NativeType.NONE)
+ Write ((int) fa.ArrayElemType);
+ break;
+ case NativeType.SAFEARRAY :
+ Write ((int) ((MarshalSig.SafeArray) ms.Spec).ArrayElemType);
+ break;
+ case NativeType.FIXEDSYSSTRING :
+ Write (((MarshalSig.FixedSysString) ms.Spec).Size);
+ break;
+ }
+ }
+
+ void Write (CustomAttrib ca, MethodReference ctor, MemoryBinaryWriter writer)
+ {
+ if (ca == null)
+ return;
+
+ if (ca.Prolog != CustomAttrib.StdProlog)
+ return;
+
+ writer.Write (ca.Prolog);
+
+ for (int i = 0; i < ctor.Parameters.Count; i++)
+ Write (ca.FixedArgs [i], writer);
+
+ writer.Write (ca.NumNamed);
+
+ for (int i = 0; i < ca.NumNamed; i++)
+ Write (ca.NamedArgs [i], writer);
+ }
+
+ void Write (CustomAttrib.FixedArg fa, MemoryBinaryWriter writer)
+ {
+ if (fa.SzArray)
+ writer.Write (fa.NumElem);
+
+ foreach (CustomAttrib.Elem elem in fa.Elems)
+ Write (elem, writer);
+ }
+
+ static string GetEnumFullName (TypeReference type)
+ {
+ string fullname = type.FullName;
+
+ if (type.IsNested)
+ fullname = fullname.Replace ('/', '+');
+
+ if (type is TypeDefinition)
+ return fullname;
+
+ return string.Concat (fullname, ", ", type.Module.Assembly.Name.FullName);
+ }
+
+ void Write (CustomAttrib.NamedArg na, MemoryBinaryWriter writer)
+ {
+ if (na.Field)
+ writer.Write ((byte) 0x53);
+ else if (na.Property)
+ writer.Write ((byte) 0x54);
+ else
+ throw new MetadataFormatException ("Unknown kind of namedarg");
+
+ if (na.FieldOrPropType == ElementType.Class)
+ na.FieldOrPropType = ElementType.Enum;
+
+ if (na.FixedArg.SzArray)
+ writer.Write ((byte) ElementType.SzArray);
+
+ if (na.FieldOrPropType == ElementType.Object)
+ writer.Write ((byte) ElementType.Boxed);
+ else
+ writer.Write ((byte) na.FieldOrPropType);
+
+ if (na.FieldOrPropType == ElementType.Enum)
+ Write (GetEnumFullName (na.FixedArg.Elems [0].ElemType));
+
+ Write (na.FieldOrPropName);
+
+ Write (na.FixedArg, writer);
+ }
+
+ static ElementType GetElementTypeFromTypeCode (TypeCode tc)
+ {
+ switch (tc) {
+ case TypeCode.Byte:
+ return ElementType.U1;
+ case TypeCode.SByte:
+ return ElementType.I1;
+ case TypeCode.Int16:
+ return ElementType.I2;
+ case TypeCode.UInt16:
+ return ElementType.U2;
+ case TypeCode.Int32:
+ return ElementType.I4;
+ case TypeCode.UInt32:
+ return ElementType.U4;
+ case TypeCode.Int64:
+ return ElementType.I8;
+ case TypeCode.UInt64:
+ return ElementType.U8;
+ default:
+ throw new ArgumentException ("tc");
+ }
+ }
+
+ void Write (CustomAttrib.Elem elem, MemoryBinaryWriter writer)
+ {
+ if (elem.String)
+ elem.FieldOrPropType = ElementType.String;
+ else if (elem.Type)
+ elem.FieldOrPropType = ElementType.Type;
+
+ if (elem.FieldOrPropType == ElementType.Class) // an enum in fact
+ elem.FieldOrPropType = GetElementTypeFromTypeCode (Type.GetTypeCode (elem.Value.GetType ()));
+
+ if (elem.BoxedValueType)
+ Write (elem.FieldOrPropType);
+
+ switch (elem.FieldOrPropType) {
+ case ElementType.Boolean :
+ writer.Write ((byte) ((bool) elem.Value ? 1 : 0));
+ break;
+ case ElementType.Char :
+ writer.Write ((ushort) (char) elem.Value);
+ break;
+ case ElementType.R4 :
+ writer.Write ((float) elem.Value);
+ break;
+ case ElementType.R8 :
+ writer.Write ((double) elem.Value);
+ break;
+ case ElementType.I1 :
+ writer.Write ((sbyte) elem.Value);
+ break;
+ case ElementType.I2 :
+ writer.Write ((short) elem.Value);
+ break;
+ case ElementType.I4 :
+ writer.Write ((int) elem.Value);
+ break;
+ case ElementType.I8 :
+ writer.Write ((long) elem.Value);
+ break;
+ case ElementType.U1 :
+ writer.Write ((byte) elem.Value);
+ break;
+ case ElementType.U2 :
+ writer.Write ((ushort) elem.Value);
+ break;
+ case ElementType.U4 :
+ writer.Write ((uint) elem.Value);
+ break;
+ case ElementType.U8 :
+ writer.Write ((ulong) elem.Value);
+ break;
+ case ElementType.String :
+ case ElementType.Type :
+ string s = elem.Value as string;
+ if (s == null)
+ writer.Write ((byte) 0xff);
+ else if (s.Length == 0)
+ writer.Write ((byte) 0x00);
+ else
+ Write (s);
+ break;
+ case ElementType.Object :
+ if (elem.Value != null)
+ throw new NotSupportedException ("Unknown state");
+ writer.Write ((byte) 0xff);
+ break;
+ default :
+ throw new NotImplementedException ("WriteElem " + elem.FieldOrPropType.ToString ());
+ }
+ }
+
+ void Write (string s)
+ {
+ byte [] str = Encoding.UTF8.GetBytes (s);
+ Write (str.Length);
+ m_sigWriter.Write (str);
+ }
+
+ void Write (int i)
+ {
+ Utilities.WriteCompressedInteger (m_sigWriter, i);
+ }
+ }
+}
--- /dev/null
+//
+// SzArray.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class SZARRAY : SigType {
+
+ public CustomMod [] CustomMods;
+ public SigType Type;
+
+ public SZARRAY () : base (ElementType.SzArray)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// TypeSpec.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ internal sealed class TypeSpec {
+
+ public CustomMod [] CustomMods;
+ public SigType Type;
+ }
+}
--- /dev/null
+//
+// ValueType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class VALUETYPE : SigType {
+
+ public MetadataToken Type;
+
+ public VALUETYPE () : base (ElementType.ValueType)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// Var.cs
+//
+// Author:
+// Martin Baulig <martin@ximian.com>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil.Signatures {
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class VAR : SigType {
+
+ public int Index;
+
+ public VAR (int index) : base (ElementType.Var)
+ {
+ this.Index = index;
+ }
+ }
+}
--- /dev/null
+//
+// AggressiveRefletionReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ using Mono.Cecil.Metadata;
+ using Mono.Cecil.Signatures;
+
+ internal sealed class AggressiveReflectionReader : ReflectionReader {
+
+ public AggressiveReflectionReader (ModuleDefinition module) : base (module)
+ {
+ }
+
+ public override void VisitTypeDefinitionCollection (TypeDefinitionCollection types)
+ {
+ base.VisitTypeDefinitionCollection (types);
+
+ ReadGenericParameterConstraints ();
+ ReadClassLayoutInfos ();
+ ReadFieldLayoutInfos ();
+ ReadPInvokeInfos ();
+ ReadProperties ();
+ ReadEvents ();
+ ReadSemantics ();
+ ReadInterfaces ();
+ ReadOverrides ();
+ ReadSecurityDeclarations ();
+ ReadCustomAttributes ();
+ ReadConstants ();
+ ReadExternTypes ();
+ ReadMarshalSpecs ();
+ ReadInitialValues ();
+
+ m_events = null;
+ m_properties = null;
+ m_parameters = null;
+ }
+
+ void ReadGenericParameterConstraints ()
+ {
+ if (!m_tHeap.HasTable (GenericParamConstraintTable.RId))
+ return;
+
+ GenericParamConstraintTable gpcTable = m_tableReader.GetGenericParamConstraintTable ();
+ for (int i = 0; i < gpcTable.Rows.Count; i++) {
+ GenericParamConstraintRow gpcRow = gpcTable [i];
+ GenericParameter gp = GetGenericParameterAt (gpcRow.Owner);
+
+ gp.Constraints.Add (GetTypeDefOrRef (gpcRow.Constraint, new GenericContext (gp.Owner)));
+ }
+ }
+
+ void ReadClassLayoutInfos ()
+ {
+ if (!m_tHeap.HasTable (ClassLayoutTable.RId))
+ return;
+
+ ClassLayoutTable clTable = m_tableReader.GetClassLayoutTable ();
+ for (int i = 0; i < clTable.Rows.Count; i++) {
+ ClassLayoutRow clRow = clTable [i];
+ TypeDefinition type = GetTypeDefAt (clRow.Parent);
+ type.PackingSize = clRow.PackingSize;
+ type.ClassSize = clRow.ClassSize;
+ }
+ }
+
+ void ReadFieldLayoutInfos ()
+ {
+ if (!m_tHeap.HasTable (FieldLayoutTable.RId))
+ return;
+
+ FieldLayoutTable flTable = m_tableReader.GetFieldLayoutTable ();
+ for (int i = 0; i < flTable.Rows.Count; i++) {
+ FieldLayoutRow flRow = flTable [i];
+ FieldDefinition field = GetFieldDefAt (flRow.Field);
+ field.Offset = flRow.Offset;
+ }
+ }
+
+ void ReadPInvokeInfos ()
+ {
+ if (!m_tHeap.HasTable (ImplMapTable.RId))
+ return;
+
+ ImplMapTable imTable = m_tableReader.GetImplMapTable ();
+ for (int i = 0; i < imTable.Rows.Count; i++) {
+ ImplMapRow imRow = imTable [i];
+ if (imRow.MemberForwarded.TokenType == TokenType.Method) { // should always be true
+ MethodDefinition meth = GetMethodDefAt (imRow.MemberForwarded.RID);
+ meth.PInvokeInfo = new PInvokeInfo (
+ meth, imRow.MappingFlags, MetadataRoot.Streams.StringsHeap [imRow.ImportName],
+ Module.ModuleReferences [(int) imRow.ImportScope - 1]);
+ }
+ }
+ }
+
+ void ReadProperties ()
+ {
+ if (!m_tHeap.HasTable (PropertyTable.RId)) {
+ m_properties = new PropertyDefinition [0];
+ return;
+ }
+
+ PropertyTable propsTable = m_tableReader.GetPropertyTable ();
+ PropertyMapTable pmapTable = m_tableReader.GetPropertyMapTable ();
+ m_properties = new PropertyDefinition [propsTable.Rows.Count];
+ for (int i = 0; i < pmapTable.Rows.Count; i++) {
+ PropertyMapRow pmapRow = pmapTable [i];
+ if (pmapRow.Parent == 0)
+ continue;
+
+ TypeDefinition owner = GetTypeDefAt (pmapRow.Parent);
+
+ GenericContext context = new GenericContext (owner);
+
+ int start = (int) pmapRow.PropertyList, last = propsTable.Rows.Count + 1, end;
+ if (i < pmapTable.Rows.Count - 1)
+ end = (int) pmapTable [i + 1].PropertyList;
+ else
+ end = last;
+
+ if (end > last)
+ end = last;
+
+ for (int j = start; j < end; j++) {
+ PropertyRow prow = propsTable [j - 1];
+ PropertySig psig = m_sigReader.GetPropSig (prow.Type);
+ PropertyDefinition pdef = new PropertyDefinition (
+ m_root.Streams.StringsHeap [prow.Name],
+ GetTypeRefFromSig (psig.Type, context),
+ prow.Flags);
+ pdef.MetadataToken = MetadataToken.FromMetadataRow (TokenType.Property, j - 1);
+
+ pdef.PropertyType = GetModifierType (psig.CustomMods, pdef.PropertyType);
+
+ if (!IsDeleted (pdef))
+ owner.Properties.Add (pdef);
+
+ m_properties [j - 1] = pdef;
+ }
+ }
+ }
+
+ void ReadEvents ()
+ {
+ if (!m_tHeap.HasTable (EventTable.RId)) {
+ m_events = new EventDefinition [0];
+ return;
+ }
+
+ EventTable evtTable = m_tableReader.GetEventTable ();
+ EventMapTable emapTable = m_tableReader.GetEventMapTable ();
+ m_events = new EventDefinition [evtTable.Rows.Count];
+ for (int i = 0; i < emapTable.Rows.Count; i++) {
+ EventMapRow emapRow = emapTable [i];
+ if (emapRow.Parent == 0)
+ continue;
+
+ TypeDefinition owner = GetTypeDefAt (emapRow.Parent);
+ GenericContext context = new GenericContext (owner);
+
+ int start = (int) emapRow.EventList, last = evtTable.Rows.Count + 1, end;
+ if (i < (emapTable.Rows.Count - 1))
+ end = (int) emapTable [i + 1].EventList;
+ else
+ end = last;
+
+ if (end > last)
+ end = last;
+
+ for (int j = start; j < end; j++) {
+ EventRow erow = evtTable [j - 1];
+ EventDefinition edef = new EventDefinition (
+ m_root.Streams.StringsHeap [erow.Name],
+ GetTypeDefOrRef (erow.EventType, context), erow.EventFlags);
+ edef.MetadataToken = MetadataToken.FromMetadataRow (TokenType.Event, j - 1);
+
+ if (!IsDeleted (edef))
+ owner.Events.Add (edef);
+
+ m_events [j - 1] = edef;
+ }
+ }
+ }
+
+ void ReadSemantics ()
+ {
+ if (!m_tHeap.HasTable (MethodSemanticsTable.RId))
+ return;
+
+ MethodSemanticsTable semTable = m_tableReader.GetMethodSemanticsTable ();
+ for (int i = 0; i < semTable.Rows.Count; i++) {
+ MethodSemanticsRow semRow = semTable [i];
+ MethodDefinition semMeth = GetMethodDefAt (semRow.Method);
+ semMeth.SemanticsAttributes = semRow.Semantics;
+ switch (semRow.Association.TokenType) {
+ case TokenType.Event :
+ EventDefinition evt = GetEventDefAt (semRow.Association.RID);
+ if ((semRow.Semantics & MethodSemanticsAttributes.AddOn) != 0)
+ evt.AddMethod = semMeth;
+ else if ((semRow.Semantics & MethodSemanticsAttributes.Fire) != 0)
+ evt.InvokeMethod = semMeth;
+ else if ((semRow.Semantics & MethodSemanticsAttributes.RemoveOn) != 0)
+ evt.RemoveMethod = semMeth;
+ break;
+ case TokenType.Property :
+ PropertyDefinition prop = GetPropertyDefAt (semRow.Association.RID);
+ if ((semRow.Semantics & MethodSemanticsAttributes.Getter) != 0)
+ prop.GetMethod = semMeth;
+ else if ((semRow.Semantics & MethodSemanticsAttributes.Setter) != 0)
+ prop.SetMethod = semMeth;
+ break;
+ }
+ }
+ }
+
+ void ReadInterfaces ()
+ {
+ if (!m_tHeap.HasTable (InterfaceImplTable.RId))
+ return;
+
+ InterfaceImplTable intfsTable = m_tableReader.GetInterfaceImplTable ();
+ for (int i = 0; i < intfsTable.Rows.Count; i++) {
+ InterfaceImplRow intfsRow = intfsTable [i];
+ TypeDefinition owner = GetTypeDefAt (intfsRow.Class);
+ owner.Interfaces.Add (GetTypeDefOrRef (intfsRow.Interface, new GenericContext (owner)));
+ }
+ }
+
+ void ReadOverrides ()
+ {
+ if (!m_tHeap.HasTable (MethodImplTable.RId))
+ return;
+
+ MethodImplTable implTable = m_tableReader.GetMethodImplTable ();
+ for (int i = 0; i < implTable.Rows.Count; i++) {
+ MethodImplRow implRow = implTable [i];
+ if (implRow.MethodBody.TokenType == TokenType.Method) {
+ MethodDefinition owner = GetMethodDefAt (implRow.MethodBody.RID);
+ switch (implRow.MethodDeclaration.TokenType) {
+ case TokenType.Method :
+ owner.Overrides.Add (
+ GetMethodDefAt (implRow.MethodDeclaration.RID));
+ break;
+ case TokenType.MemberRef :
+ owner.Overrides.Add (
+ (MethodReference) GetMemberRefAt (
+ implRow.MethodDeclaration.RID, new GenericContext (owner)));
+ break;
+ }
+ }
+ }
+ }
+
+ void ReadSecurityDeclarations ()
+ {
+ if (!m_tHeap.HasTable (DeclSecurityTable.RId))
+ return;
+
+ DeclSecurityTable dsTable = m_tableReader.GetDeclSecurityTable ();
+ for (int i = 0; i < dsTable.Rows.Count; i++) {
+ DeclSecurityRow dsRow = dsTable [i];
+ SecurityDeclaration dec = BuildSecurityDeclaration (dsRow);
+
+ if (dsRow.Parent.RID == 0)
+ continue;
+
+ IHasSecurity owner = null;
+ switch (dsRow.Parent.TokenType) {
+ case TokenType.Assembly :
+ owner = this.Module.Assembly;
+ break;
+ case TokenType.TypeDef :
+ owner = GetTypeDefAt (dsRow.Parent.RID);
+ break;
+ case TokenType.Method :
+ owner = GetMethodDefAt (dsRow.Parent.RID);
+ break;
+ }
+
+ owner.SecurityDeclarations.Add (dec);
+ }
+ }
+
+ void ReadCustomAttributes ()
+ {
+ if (!m_tHeap.HasTable (CustomAttributeTable.RId))
+ return;
+
+ CustomAttributeTable caTable = m_tableReader.GetCustomAttributeTable ();
+ for (int i = 0; i < caTable.Rows.Count; i++) {
+ CustomAttributeRow caRow = caTable [i];
+ MethodReference ctor;
+
+ if (caRow.Type.RID == 0)
+ continue;
+
+ if (caRow.Type.TokenType == TokenType.Method)
+ ctor = GetMethodDefAt (caRow.Type.RID);
+ else
+ ctor = GetMemberRefAt (caRow.Type.RID, new GenericContext ()) as MethodReference;
+
+ CustomAttrib ca = m_sigReader.GetCustomAttrib (caRow.Value, ctor);
+ CustomAttribute cattr = BuildCustomAttribute (ctor, m_root.Streams.BlobHeap.Read (caRow.Value), ca);
+
+ if (caRow.Parent.RID == 0)
+ continue;
+
+ ICustomAttributeProvider owner = null;
+ switch (caRow.Parent.TokenType) {
+ case TokenType.Assembly :
+ owner = this.Module.Assembly;
+ break;
+ case TokenType.Module :
+ owner = this.Module;
+ break;
+ case TokenType.TypeDef :
+ owner = GetTypeDefAt (caRow.Parent.RID);
+ break;
+ case TokenType.TypeRef :
+ owner = GetTypeRefAt (caRow.Parent.RID);
+ break;
+ case TokenType.Field :
+ owner = GetFieldDefAt (caRow.Parent.RID);
+ break;
+ case TokenType.Method :
+ owner = GetMethodDefAt (caRow.Parent.RID);
+ break;
+ case TokenType.Property :
+ owner = GetPropertyDefAt (caRow.Parent.RID);
+ break;
+ case TokenType.Event :
+ owner = GetEventDefAt (caRow.Parent.RID);
+ break;
+ case TokenType.Param :
+ owner = GetParamDefAt (caRow.Parent.RID);
+ break;
+ case TokenType.GenericParam :
+ owner = GetGenericParameterAt (caRow.Parent.RID);
+ break;
+ default :
+ //TODO: support other ?
+ break;
+ }
+
+ if (owner != null)
+ owner.CustomAttributes.Add (cattr);
+ }
+ }
+
+ void ReadConstants ()
+ {
+ if (!m_tHeap.HasTable (ConstantTable.RId))
+ return;
+
+ ConstantTable csTable = m_tableReader.GetConstantTable ();
+ for (int i = 0; i < csTable.Rows.Count; i++) {
+ ConstantRow csRow = csTable [i];
+
+ object constant = GetConstant (csRow.Value, csRow.Type);
+
+ IHasConstant owner = null;
+ switch (csRow.Parent.TokenType) {
+ case TokenType.Field :
+ owner = GetFieldDefAt (csRow.Parent.RID);
+ break;
+ case TokenType.Property :
+ owner = GetPropertyDefAt (csRow.Parent.RID);
+ break;
+ case TokenType.Param :
+ owner = GetParamDefAt (csRow.Parent.RID);
+ break;
+ }
+
+ owner.Constant = constant;
+ }
+ }
+
+ void ReadExternTypes ()
+ {
+ base.VisitExternTypeCollection (Module.ExternTypes);
+ }
+
+ void ReadMarshalSpecs ()
+ {
+ if (!m_tHeap.HasTable (FieldMarshalTable.RId))
+ return;
+
+ FieldMarshalTable fmTable = m_tableReader.GetFieldMarshalTable ();
+ for (int i = 0; i < fmTable.Rows.Count; i++) {
+ FieldMarshalRow fmRow = fmTable [i];
+
+ if (fmRow.Parent.RID == 0)
+ continue;
+
+ IHasMarshalSpec owner = null;
+ switch (fmRow.Parent.TokenType) {
+ case TokenType.Field:
+ owner = GetFieldDefAt (fmRow.Parent.RID);
+ break;
+ case TokenType.Param:
+ owner = GetParamDefAt (fmRow.Parent.RID);
+ break;
+ }
+
+ owner.MarshalSpec = BuildMarshalDesc (
+ m_sigReader.GetMarshalSig (fmRow.NativeType), owner);
+ }
+ }
+
+ void ReadInitialValues ()
+ {
+ if (!m_tHeap.HasTable (FieldRVATable.RId))
+ return;
+
+ FieldRVATable frTable = m_tableReader.GetFieldRVATable ();
+ for (int i = 0; i < frTable.Rows.Count; i++) {
+ FieldRVARow frRow = frTable [i];
+ FieldDefinition field = GetFieldDefAt (frRow.Field);
+ field.RVA = frRow.RVA;
+ SetInitialValue (field);
+ }
+ }
+ }
+}
--- /dev/null
+//
+// ArrayDimension.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class ArrayDimension {
+
+ int m_lowerBound;
+ int m_upperBound;
+
+ public int LowerBound {
+ get { return m_lowerBound; }
+ set { m_lowerBound = value; }
+ }
+
+ public int UpperBound {
+ get { return m_upperBound; }
+ set { m_upperBound = value; }
+ }
+
+ public ArrayDimension (int lb, int ub)
+ {
+ m_lowerBound = lb;
+ m_upperBound = ub;
+ }
+
+ public override string ToString ()
+ {
+ if (m_upperBound == 0)
+ return string.Empty;
+ return string.Concat (m_lowerBound, "...", m_upperBound);
+ }
+ }
+}
--- /dev/null
+//
+// ArrayDimensionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:53 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class ArrayDimensionCollection : CollectionBase {
+
+ ArrayType m_container;
+
+ public ArrayDimension this [int index] {
+ get { return List [index] as ArrayDimension; }
+ set { List [index] = value; }
+ }
+
+ public ArrayType Container {
+ get { return m_container; }
+ }
+
+ public ArrayDimensionCollection (ArrayType container)
+ {
+ m_container = container;
+ }
+
+ public void Add (ArrayDimension value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (ArrayDimension value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (ArrayDimension value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, ArrayDimension value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (ArrayDimension value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is ArrayDimension))
+ throw new ArgumentException ("Must be of type " + typeof (ArrayDimension).FullName);
+ }
+ }
+}
--- /dev/null
+//
+// ArrayType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Text;
+
+ using Mono.Cecil.Signatures;
+
+ internal sealed class ArrayType : TypeSpecification {
+
+ private ArrayDimensionCollection m_dimensions;
+
+ public ArrayDimensionCollection Dimensions {
+ get { return m_dimensions; }
+ }
+
+ public int Rank {
+ get { return m_dimensions.Count; }
+ }
+
+ public bool IsSizedArray {
+ get {
+ if (this.Rank != 1)
+ return false;
+ ArrayDimension dim = m_dimensions [0];
+ return dim.UpperBound == 0;
+ }
+ }
+
+ public override string Name {
+ get { return string.Concat (base.Name, Suffix ()); }
+ }
+
+ public override string FullName {
+ get { return string.Concat (base.FullName, Suffix ()); }
+ }
+
+ string Suffix ()
+ {
+ StringBuilder sb = new StringBuilder ();
+ sb.Append ("[");
+ for (int i = 0; i < m_dimensions.Count; i++) {
+ ArrayDimension dim = m_dimensions [i];
+ string rank = dim.ToString ();
+ if (i < m_dimensions.Count - 1)
+ sb.Append (",");
+ if (rank.Length > 0) {
+ sb.Append (" ");
+ sb.Append (rank);
+ }
+ }
+ sb.Append ("]");
+ return sb.ToString ();
+ }
+
+ internal ArrayType (TypeReference elementType, ArrayShape shape) : base (elementType)
+ {
+ m_dimensions = new ArrayDimensionCollection (this);
+ for (int i = 0; i < shape.Rank; i++) {
+ int lower = 0, upper = 0;
+ if (i < shape.NumSizes)
+ if (i < shape.NumLoBounds) {
+ lower = shape.LoBounds [i];
+ upper = shape.LoBounds [i] + shape.Sizes [i] - 1;
+ } else
+ upper = shape.Sizes [i] - 1;
+
+ m_dimensions.Add (new ArrayDimension (lower, upper));
+ }
+ }
+
+ public ArrayType (TypeReference elementType, int rank) : base (elementType)
+ {
+ m_dimensions = new ArrayDimensionCollection (this);
+ for (int i = 0; i < rank; i++)
+ m_dimensions.Add (new ArrayDimension (0, 0));
+ }
+
+ public ArrayType (TypeReference elementType) : this (elementType, 1)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Metadata;
+
+ internal class AssemblyDefinition : ICustomAttributeProvider,
+ IHasSecurity, IAnnotationProvider, IReflectionStructureVisitable {
+
+ MetadataToken m_token;
+ AssemblyNameDefinition m_asmName;
+ ModuleDefinitionCollection m_modules;
+ SecurityDeclarationCollection m_secDecls;
+ CustomAttributeCollection m_customAttrs;
+ MethodDefinition m_ep;
+ TargetRuntime m_runtime;
+ AssemblyKind m_kind;
+
+ ModuleDefinition m_mainModule;
+ StructureReader m_reader;
+
+ IAssemblyResolver m_resolver;
+ IDictionary m_annotations;
+
+ public MetadataToken MetadataToken {
+ get { return m_token; }
+ set { m_token = value; }
+ }
+
+ public AssemblyNameDefinition Name {
+ get { return m_asmName; }
+ }
+
+ public ModuleDefinitionCollection Modules {
+ get { return m_modules; }
+ }
+
+ public bool HasSecurityDeclarations {
+ get { return (m_secDecls == null) ? false : (m_secDecls.Count > 0); }
+ }
+
+ public SecurityDeclarationCollection SecurityDeclarations {
+ get {
+ if (m_secDecls == null)
+ m_secDecls = new SecurityDeclarationCollection (this);
+
+ return m_secDecls;
+ }
+ }
+
+ public bool HasCustomAttributes {
+ get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
+ }
+
+ public CustomAttributeCollection CustomAttributes {
+ get {
+ if (m_customAttrs == null)
+ m_customAttrs = new CustomAttributeCollection (this);
+
+ return m_customAttrs;
+ }
+ }
+
+ public MethodDefinition EntryPoint {
+ get { return m_ep; }
+ set { m_ep = value; }
+ }
+
+ public TargetRuntime Runtime {
+ get { return m_runtime; }
+ set { m_runtime = value; }
+ }
+
+ public AssemblyKind Kind {
+ get { return m_kind; }
+ set { m_kind = value; }
+ }
+
+ public ModuleDefinition MainModule {
+ get {
+ if (m_mainModule == null) {
+ foreach (ModuleDefinition module in m_modules) {
+ if (module.Main) {
+ m_mainModule = module;
+ break;
+ }
+ }
+ }
+ return m_mainModule;
+ }
+ }
+
+ internal StructureReader Reader {
+ get { return m_reader; }
+ }
+
+ public IAssemblyResolver Resolver {
+ get { return m_resolver; }
+ set { m_resolver = value; }
+ }
+
+ IDictionary IAnnotationProvider.Annotations {
+ get {
+ if (m_annotations == null)
+ m_annotations = new Hashtable ();
+ return m_annotations;
+ }
+ }
+
+ internal AssemblyDefinition (AssemblyNameDefinition name)
+ {
+ if (name == null)
+ throw new ArgumentNullException ("name");
+
+ m_asmName = name;
+ m_modules = new ModuleDefinitionCollection (this);
+ m_resolver = new DefaultAssemblyResolver ();
+ }
+
+ internal AssemblyDefinition (AssemblyNameDefinition name, StructureReader reader) : this (name)
+ {
+ m_reader = reader;
+ }
+
+ public void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitAssemblyDefinition (this);
+
+ m_asmName.Accept (visitor);
+ m_modules.Accept (visitor);
+
+ visitor.TerminateAssemblyDefinition (this);
+ }
+
+ public override string ToString ()
+ {
+ return m_asmName.FullName;
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyFactory.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.IO;
+ using SR = System.Reflection;
+
+ using Mono.Cecil.Binary;
+
+ internal sealed class AssemblyFactory {
+
+ AssemblyFactory ()
+ {
+ }
+
+ static AssemblyDefinition GetAssembly (ImageReader irv, bool manifestOnly)
+ {
+ StructureReader srv = new StructureReader (irv, manifestOnly);
+ AssemblyDefinition asm = new AssemblyDefinition (
+ new AssemblyNameDefinition (), srv);
+
+ asm.Accept (srv);
+ return asm;
+ }
+
+ static AssemblyDefinition GetAssembly (ImageReader reader)
+ {
+ return GetAssembly (reader, false);
+ }
+
+ static AssemblyDefinition GetAssemblyManifest (ImageReader reader)
+ {
+ return GetAssembly (reader, true);
+ }
+
+ public static AssemblyDefinition GetAssembly (string file)
+ {
+ return GetAssembly (ImageReader.Read (file));
+ }
+
+ public static AssemblyDefinition GetAssembly (byte [] assembly)
+ {
+ return GetAssembly (ImageReader.Read (assembly));
+ }
+
+ public static AssemblyDefinition GetAssembly (Stream stream)
+ {
+ return GetAssembly (ImageReader.Read (stream));
+ }
+
+ public static AssemblyDefinition GetAssemblyManifest (string file)
+ {
+ return GetAssemblyManifest (ImageReader.Read (file));
+ }
+
+ public static AssemblyDefinition GetAssemblyManifest (byte [] assembly)
+ {
+ return GetAssemblyManifest (ImageReader.Read (assembly));
+ }
+
+ public static AssemblyDefinition GetAssemblyManifest (Stream stream)
+ {
+ return GetAssemblyManifest (ImageReader.Read (stream));
+ }
+
+ static TargetRuntime CurrentRuntime ()
+ {
+ Version corlib = typeof (object).Assembly.GetName ().Version;
+
+ switch (corlib.Major) {
+ case 1:
+ return corlib.Minor == 0 ? TargetRuntime.NET_1_0 : TargetRuntime.NET_1_1;
+ case 2:
+ return TargetRuntime.NET_2_0;
+ case 4:
+ return TargetRuntime.NET_4_0;
+ default:
+ throw new NotSupportedException ();
+ }
+ }
+
+ public static AssemblyDefinition DefineAssembly (string name, AssemblyKind kind)
+ {
+ return DefineAssembly (name, name, CurrentRuntime (), kind);
+ }
+
+ public static AssemblyDefinition DefineAssembly (string name, TargetRuntime rt, AssemblyKind kind)
+ {
+ return DefineAssembly (name, name, rt, kind);
+ }
+
+ public static AssemblyDefinition DefineAssembly (string assemblyName, string moduleName, TargetRuntime rt, AssemblyKind kind)
+ {
+ AssemblyNameDefinition asmName = new AssemblyNameDefinition ();
+ asmName.Name = assemblyName;
+ AssemblyDefinition asm = new AssemblyDefinition (asmName);
+ asm.Runtime = rt;
+ asm.Kind = kind;
+ ModuleDefinition main = new ModuleDefinition (moduleName, asm, true);
+ asm.Modules.Add (main);
+ return asm;
+ }
+
+ static void WriteAssembly (AssemblyDefinition asm, BinaryWriter bw)
+ {
+ asm.Accept (new StructureWriter (asm, bw));
+ }
+
+ public static void SaveAssembly (AssemblyDefinition asm, string file)
+ {
+ using (FileStream fs = new FileStream (
+ file, FileMode.Create, FileAccess.Write, FileShare.None)) {
+
+ SaveAssembly (asm, fs);
+ asm.MainModule.Image.SetFileInfo (new FileInfo (file));
+ }
+ }
+
+ public static void SaveAssembly (AssemblyDefinition asm, out byte [] assembly)
+ {
+ MemoryBinaryWriter bw = new MemoryBinaryWriter ();
+ SaveAssembly (asm, bw.BaseStream);
+ assembly = bw.ToArray ();
+ }
+
+ public static void SaveAssembly (AssemblyDefinition asm, Stream stream)
+ {
+ BinaryWriter bw = new BinaryWriter (stream);
+ try {
+ WriteAssembly (asm, bw);
+ } finally {
+ bw.Close ();
+ }
+
+ foreach (ModuleDefinition module in asm.Modules)
+ if (module.Controller.Writer.SaveSymbols)
+ module.Controller.Writer.WriteSymbols (module);
+ }
+
+#if !CF_1_0 && !CF_2_0
+ public static SR.Assembly CreateReflectionAssembly (AssemblyDefinition asm, AppDomain domain)
+ {
+ using (MemoryBinaryWriter writer = new MemoryBinaryWriter ()) {
+
+ WriteAssembly (asm, writer);
+ return domain.Load (writer.ToArray ());
+ }
+ }
+
+ public static SR.Assembly CreateReflectionAssembly (AssemblyDefinition asm)
+ {
+ return CreateReflectionAssembly (asm, AppDomain.CurrentDomain);
+ }
+#endif
+ }
+}
--- /dev/null
+//
+// AssemblyFlags.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum AssemblyFlags : uint {
+ PublicKey = 0x0001,
+ SideBySideCompatible = 0x0000,
+ Retargetable = 0x0100,
+ EnableJITcompileTracking = 0x8000,
+ DisableJITcompileOptimizer = 0x4000
+ }
+}
--- /dev/null
+//
+// AssemblyHashAlgorithm.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal enum AssemblyHashAlgorithm : uint {
+ None = 0x0000,
+ Reserved = 0x8003, // MD5
+ SHA1 = 0x8004
+ }
+}
+
--- /dev/null
+//
+// AssemblyInfo.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+#if !EMBEDDED
+
+[assembly: AssemblyTitle ("Mono.Cecil")]
+[assembly: AssemblyDescription ("Library for reading and writing CIL images")]
+[assembly: AssemblyConfiguration ("")]
+[assembly: AssemblyProduct ("Mono.Cecil")]
+[assembly: AssemblyCopyright ("(C) 2005 - 2007, Jb Evain")]
+[assembly: AssemblyCulture ("")]
+
+[assembly: CLSCompliant (false)]
+[assembly: ComVisible (false)]
+
+[assembly: AssemblyVersion (
+ //
+ // DO NOT MODIFY THE STRING BELOWS WITOUT UPDATING cecil.pc.in in mono/data
+ //
+ "0.6.9.0"
+ //
+ // DO NOT MODIFY THE STRING ABOVE WITHOUT UPDATING cecil.pc.in in mono/data
+)]
+
+#if KEYFILE
+[assembly: AssemblyKeyFile("../../mono.snk")]
+#endif
+
+#endif
+
+
+
--- /dev/null
+//
+// AssemblyKind.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal enum AssemblyKind {
+ Dll,
+ Console,
+ Windows
+ }
+}
--- /dev/null
+//
+// AssemblyLinkedResource.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class AssemblyLinkedResource : Resource {
+
+ private AssemblyNameReference m_asmRef;
+
+ public AssemblyNameReference Assembly {
+ get { return m_asmRef; }
+ set { m_asmRef = value; }
+ }
+
+ public AssemblyLinkedResource (string name, ManifestResourceAttributes flags,
+ AssemblyNameReference asmRef) : base (name, flags)
+ {
+ m_asmRef = asmRef;
+ }
+
+ public override void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitAssemblyLinkedResource (this);
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyNameDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ internal sealed class AssemblyNameDefinition : AssemblyNameReference {
+
+ public override byte [] Hash {
+ get { return new byte [0]; }
+ }
+
+ public AssemblyNameDefinition () : base()
+ {
+ }
+
+ public AssemblyNameDefinition (string name, string culture, Version version) : base (name, culture, version)
+ {
+ }
+
+ public override void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitAssemblyNameDefinition (this);
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyNameReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+ using System.Globalization;
+ using System.Security.Cryptography;
+ using System.Text;
+
+ using Mono.Cecil.Metadata;
+
+ internal class AssemblyNameReference : IMetadataScope, IAnnotationProvider, IReflectionStructureVisitable {
+
+ string m_name;
+ string m_culture;
+ Version m_version;
+ AssemblyFlags m_flags;
+ byte [] m_publicKey;
+ byte [] m_publicKeyToken;
+ AssemblyHashAlgorithm m_hashAlgo;
+ byte [] m_hash;
+ MetadataToken m_token;
+ IDictionary m_annotations;
+
+ bool m_fullNameDiscarded = true;
+ string m_fullName;
+
+ public string Name {
+ get { return m_name; }
+ set {
+ m_name = value;
+ m_fullNameDiscarded = true;
+ }
+ }
+
+ public string Culture {
+ get { return m_culture; }
+ set {
+ m_culture = value;
+ m_fullNameDiscarded = true;
+ }
+ }
+
+ public Version Version {
+ get { return m_version; }
+ set {
+ m_version = value;
+ m_fullNameDiscarded = true;
+ }
+ }
+
+ public AssemblyFlags Flags {
+ get { return m_flags; }
+ set { m_flags = value; }
+ }
+
+ public bool HasPublicKey {
+ get { return (m_flags & AssemblyFlags.PublicKey) != 0; }
+ set {
+ if (value)
+ m_flags |= AssemblyFlags.PublicKey;
+ else
+ m_flags &= ~AssemblyFlags.PublicKey;
+ }
+ }
+
+ public bool IsSideBySideCompatible {
+ get { return (m_flags & AssemblyFlags.SideBySideCompatible) != 0; }
+ set {
+ if (value)
+ m_flags |= AssemblyFlags.SideBySideCompatible;
+ else
+ m_flags &= ~AssemblyFlags.SideBySideCompatible;
+ }
+ }
+
+ public bool IsRetargetable {
+ get { return (m_flags & AssemblyFlags.Retargetable) != 0; }
+ set {
+ if (value)
+ m_flags |= AssemblyFlags.Retargetable;
+ else
+ m_flags &= ~AssemblyFlags.Retargetable;
+ }
+ }
+
+ public byte [] PublicKey {
+ get { return m_publicKey; }
+ set {
+ m_publicKey = value;
+ m_publicKeyToken = null;
+ m_fullNameDiscarded = true;
+ }
+ }
+
+ public byte [] PublicKeyToken {
+ get {
+#if !CF_1_0
+ if ((m_publicKeyToken == null || m_publicKeyToken.Length == 0) && (m_publicKey != null && m_publicKey.Length > 0)) {
+ HashAlgorithm ha;
+ switch (m_hashAlgo) {
+ case AssemblyHashAlgorithm.Reserved:
+ ha = MD5.Create (); break;
+ default:
+ // None default to SHA1
+ ha = SHA1.Create (); break;
+ }
+ byte [] hash = ha.ComputeHash (m_publicKey);
+ // we need the last 8 bytes in reverse order
+ m_publicKeyToken = new byte [8];
+ Array.Copy (hash, (hash.Length - 8), m_publicKeyToken, 0, 8);
+ Array.Reverse (m_publicKeyToken, 0, 8);
+ }
+#endif
+ return m_publicKeyToken;
+ }
+ set {
+ m_publicKeyToken = value;
+ m_fullNameDiscarded = true;
+ }
+ }
+
+ public string FullName {
+ get {
+ if (m_fullName != null && !m_fullNameDiscarded)
+ return m_fullName;
+
+ StringBuilder sb = new StringBuilder ();
+ string sep = ", ";
+ sb.Append (m_name);
+ if (m_version != null) {
+ sb.Append (sep);
+ sb.Append ("Version=");
+ sb.Append (m_version.ToString ());
+ }
+ sb.Append (sep);
+ sb.Append ("Culture=");
+ sb.Append (m_culture == null || m_culture.Length == 0 ? "neutral" : m_culture);
+ sb.Append (sep);
+ sb.Append ("PublicKeyToken=");
+ if (this.PublicKeyToken != null && m_publicKeyToken.Length > 0) {
+ for (int i = 0 ; i < m_publicKeyToken.Length ; i++) {
+ sb.Append (m_publicKeyToken [i].ToString ("x2"));
+ }
+ } else {
+ sb.Append ("null");
+ }
+ m_fullName = sb.ToString ();
+ m_fullNameDiscarded = false;
+ return m_fullName;
+ }
+ }
+
+ public static AssemblyNameReference Parse (string fullName)
+ {
+ if (fullName == null)
+ throw new ArgumentNullException ("fullName");
+ if (fullName.Length == 0)
+ throw new ArgumentException ("Name can not be empty");
+
+ AssemblyNameReference name = new AssemblyNameReference ();
+ string [] tokens = fullName.Split (',');
+ for (int i = 0; i < tokens.Length; i++) {
+ string token = tokens [i].Trim ();
+
+ if (i == 0) {
+ name.Name = token;
+ continue;
+ }
+
+ string [] parts = token.Split ('=');
+ if (parts.Length != 2)
+ throw new ArgumentException ("Malformed name");
+
+ switch (parts [0]) {
+ case "Version":
+ name.Version = new Version (parts [1]);
+ break;
+ case "Culture":
+ name.Culture = parts [1];
+ break;
+ case "PublicKeyToken":
+ string pkToken = parts [1];
+ if (pkToken == "null")
+ break;
+
+ name.PublicKeyToken = new byte [pkToken.Length / 2];
+ for (int j = 0; j < name.PublicKeyToken.Length; j++) {
+ name.PublicKeyToken [j] = Byte.Parse (pkToken.Substring (j * 2, 2), NumberStyles.HexNumber);
+ }
+ break;
+ }
+ }
+
+ return name;
+ }
+
+ public AssemblyHashAlgorithm HashAlgorithm
+ {
+ get { return m_hashAlgo; }
+ set { m_hashAlgo = value; }
+ }
+
+ public virtual byte [] Hash {
+ get { return m_hash; }
+ set { m_hash = value; }
+ }
+
+ public MetadataToken MetadataToken {
+ get { return m_token; }
+ set { m_token = value; }
+ }
+
+ IDictionary IAnnotationProvider.Annotations {
+ get {
+ if (m_annotations == null)
+ m_annotations = new Hashtable ();
+ return m_annotations;
+ }
+ }
+
+ public AssemblyNameReference () : this (string.Empty, string.Empty, new Version (0, 0, 0, 0))
+ {
+ }
+
+ public AssemblyNameReference (string name, string culture, Version version)
+ {
+ if (name == null)
+ throw new ArgumentNullException ("name");
+ if (culture == null)
+ throw new ArgumentNullException ("culture");
+ m_name = name;
+ m_culture = culture;
+ m_version = version;
+ m_hashAlgo = AssemblyHashAlgorithm.None;
+ }
+
+ public override string ToString ()
+ {
+ return this.FullName;
+ }
+
+ public virtual void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitAssemblyNameReference (this);
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyNameReferenceCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:52 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class AssemblyNameReferenceCollection : CollectionBase, IReflectionStructureVisitable {
+
+ ModuleDefinition m_container;
+
+ public AssemblyNameReference this [int index] {
+ get { return List [index] as AssemblyNameReference; }
+ set { List [index] = value; }
+ }
+
+ public ModuleDefinition Container {
+ get { return m_container; }
+ }
+
+ public AssemblyNameReferenceCollection (ModuleDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (AssemblyNameReference value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (AssemblyNameReference value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (AssemblyNameReference value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, AssemblyNameReference value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (AssemblyNameReference value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is AssemblyNameReference))
+ throw new ArgumentException ("Must be of type " + typeof (AssemblyNameReference).FullName);
+ }
+
+ public void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitAssemblyNameReferenceCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// BaseAssemblyResolver.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+ using System.IO;
+ using SR = System.Reflection;
+ using System.Text;
+
+ internal abstract class BaseAssemblyResolver : IAssemblyResolver {
+
+ ArrayList m_directories;
+ string[] m_monoGacPaths;
+
+ public void AddSearchDirectory (string directory)
+ {
+ m_directories.Add (directory);
+ }
+
+ public void RemoveSearchDirectory (string directory)
+ {
+ m_directories.Remove (directory);
+ }
+
+ public string [] GetSearchDirectories ()
+ {
+ return (string []) m_directories.ToArray (typeof (string));
+ }
+
+ public virtual AssemblyDefinition Resolve (string fullName)
+ {
+ return Resolve (AssemblyNameReference.Parse (fullName));
+ }
+
+ public BaseAssemblyResolver ()
+ {
+ m_directories = new ArrayList ();
+ m_directories.Add (".");
+ m_directories.Add ("bin");
+ }
+
+ public virtual AssemblyDefinition Resolve (AssemblyNameReference name)
+ {
+ AssemblyDefinition assembly;
+ string frameworkdir = Path.GetDirectoryName (typeof (object).Module.FullyQualifiedName);
+
+ assembly = SearchDirectory (name, m_directories);
+ if (assembly != null)
+ return assembly;
+
+ if (IsZero (name.Version)) {
+ assembly = SearchDirectory (name, new string [] {frameworkdir});
+ if (assembly != null)
+ return assembly;
+ }
+
+#if !CF_1_0 && !CF_2_0 && !NO_SYSTEM_DLL
+ if (name.Name == "mscorlib") {
+ assembly = GetCorlib (name);
+ if (assembly != null)
+ return assembly;
+ }
+
+ assembly = GetAssemblyInGac (name);
+ if (assembly != null)
+ return assembly;
+#endif
+
+ assembly = SearchDirectory (name, new string [] {frameworkdir});
+ if (assembly != null)
+ return assembly;
+
+ throw new FileNotFoundException ("Could not resolve: " + name);
+ }
+
+ static readonly string [] _extentions = new string [] { ".dll", ".exe" };
+
+ static AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable directories)
+ {
+ foreach (string dir in directories) {
+ foreach (string ext in _extentions) {
+ string file = Path.Combine (dir, name.Name + ext);
+ if (File.Exists (file))
+ return AssemblyFactory.GetAssembly (file);
+ }
+ }
+
+ return null;
+ }
+
+ static bool IsZero (Version version)
+ {
+ return version.Major == 0 && version.Minor == 0 && version.Build == 0 && version.Revision == 0;
+ }
+
+#if !CF_1_0 && !CF_2_0 && !NO_SYSTEM_DLL
+ static AssemblyDefinition GetCorlib (AssemblyNameReference reference)
+ {
+ SR.AssemblyName corlib = typeof (object).Assembly.GetName ();
+ if (corlib.Version == reference.Version || IsZero (reference.Version))
+ return AssemblyFactory.GetAssembly (typeof (object).Module.FullyQualifiedName);
+
+ string path = Directory.GetParent (
+ Directory.GetParent (
+ typeof (object).Module.FullyQualifiedName).FullName
+ ).FullName;
+
+ string runtime_path = null;
+ if (OnMono ()) {
+ if (reference.Version.Major == 1)
+ runtime_path = "1.0";
+ else if (reference.Version.Major == 2) {
+ if (reference.Version.Minor == 1)
+ runtime_path = "2.1";
+ else
+ runtime_path = "2.0";
+ } else if (reference.Version.Major == 4)
+ runtime_path = "4.0";
+ } else {
+ switch (reference.Version.ToString ()) {
+ case "1.0.3300.0":
+ runtime_path = "v1.0.3705";
+ break;
+ case "1.0.5000.0":
+ runtime_path = "v1.1.4322";
+ break;
+ case "2.0.0.0":
+ runtime_path = "v2.0.50727";
+ break;
+ case "4.0.0.0":
+ runtime_path = "v4.0.30319";
+ break;
+ }
+ }
+
+ if (runtime_path == null)
+ throw new NotSupportedException ("Version not supported: " + reference.Version);
+
+ path = Path.Combine (path, runtime_path);
+
+ if (File.Exists (Path.Combine (path, "mscorlib.dll")))
+ return AssemblyFactory.GetAssembly (Path.Combine (path, "mscorlib.dll"));
+
+ return null;
+ }
+
+ public static bool OnMono ()
+ {
+ return typeof (object).Assembly.GetType ("System.MonoType", false) != null;
+ }
+
+ string[] MonoGacPaths {
+ get {
+ if (m_monoGacPaths == null)
+ m_monoGacPaths = GetDefaultMonoGacPaths ();
+ return m_monoGacPaths;
+ }
+ }
+
+ static string[] GetDefaultMonoGacPaths ()
+ {
+ ArrayList paths = new ArrayList ();
+ string s = GetCurrentGacPath ();
+ if (s != null)
+ paths.Add (s);
+ string gacPathsEnv = Environment.GetEnvironmentVariable ("MONO_GAC_PREFIX");
+ if (gacPathsEnv != null && gacPathsEnv.Length > 0) {
+ string[] gacPrefixes = gacPathsEnv.Split (Path.PathSeparator);
+ foreach (string gacPrefix in gacPrefixes) {
+ if (gacPrefix != null && gacPrefix.Length > 0) {
+ string gac = Path.Combine (Path.Combine (Path.Combine (gacPrefix, "lib"), "mono"), "gac");
+ if (Directory.Exists (gac) && !paths.Contains (gac))
+ paths.Add (gac);
+ }
+ }
+ }
+ return (string[]) paths.ToArray (typeof (String));
+ }
+
+ AssemblyDefinition GetAssemblyInGac (AssemblyNameReference reference)
+ {
+ if (reference.PublicKeyToken == null || reference.PublicKeyToken.Length == 0)
+ return null;
+
+ if (OnMono ()) {
+ foreach (string gacpath in MonoGacPaths) {
+ string s = GetAssemblyFile (reference, gacpath);
+ if (File.Exists (s))
+ return AssemblyFactory.GetAssembly (s);
+ }
+ } else {
+ string currentGac = GetCurrentGacPath ();
+ if (currentGac == null)
+ return null;
+
+ string [] gacs = new string [] {"GAC_MSIL", "GAC_32", "GAC"};
+ for (int i = 0; i < gacs.Length; i++) {
+ string gac = Path.Combine (Directory.GetParent (currentGac).FullName, gacs [i]);
+ string asm = GetAssemblyFile (reference, gac);
+ if (Directory.Exists (gac) && File.Exists (asm))
+ return AssemblyFactory.GetAssembly (asm);
+ }
+ }
+
+ return null;
+ }
+
+ static string GetAssemblyFile (AssemblyNameReference reference, string gac)
+ {
+ StringBuilder sb = new StringBuilder ();
+ sb.Append (reference.Version);
+ sb.Append ("__");
+ for (int i = 0; i < reference.PublicKeyToken.Length; i++)
+ sb.Append (reference.PublicKeyToken [i].ToString ("x2"));
+
+ return Path.Combine (
+ Path.Combine (
+ Path.Combine (gac, reference.Name), sb.ToString ()),
+ string.Concat (reference.Name, ".dll"));
+ }
+
+ static string GetCurrentGacPath ()
+ {
+ string file = typeof (Uri).Module.FullyQualifiedName;
+ if (!File.Exists (file))
+ return null;
+
+ return Directory.GetParent (
+ Directory.GetParent (
+ Path.GetDirectoryName (
+ file)
+ ).FullName
+ ).FullName;
+ }
+#endif
+ }
+}
--- /dev/null
+//
+// BaseReflectionReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal abstract class BaseReflectionReader : BaseReflectionVisitor, IDetailReader {
+
+ public virtual void ReadSemantic (EventDefinition evt)
+ {
+ }
+
+ public virtual void ReadSemantic (PropertyDefinition prop)
+ {
+ }
+
+ public virtual void ReadMarshalSpec (ParameterDefinition param)
+ {
+ }
+
+ public virtual void ReadMarshalSpec (FieldDefinition field)
+ {
+ }
+
+ public virtual void ReadLayout (TypeDefinition type)
+ {
+ }
+
+ public virtual void ReadLayout (FieldDefinition field)
+ {
+ }
+
+ public virtual void ReadConstant (FieldDefinition field)
+ {
+ }
+
+ public virtual void ReadConstant (PropertyDefinition prop)
+ {
+ }
+
+ public virtual void ReadConstant (ParameterDefinition param)
+ {
+ }
+
+ public virtual void ReadInitialValue (FieldDefinition field)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// BaseReflectionVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ internal abstract class BaseReflectionVisitor : IReflectionVisitor {
+
+ public virtual void VisitModuleDefinition (ModuleDefinition module)
+ {
+ }
+
+ public virtual void VisitTypeDefinitionCollection (TypeDefinitionCollection types)
+ {
+ }
+
+ public virtual void VisitTypeDefinition (TypeDefinition type)
+ {
+ }
+
+ public virtual void VisitTypeReferenceCollection (TypeReferenceCollection refs)
+ {
+ }
+
+ public virtual void VisitTypeReference (TypeReference type)
+ {
+ }
+
+ public virtual void VisitMemberReferenceCollection (MemberReferenceCollection members)
+ {
+ }
+
+ public virtual void VisitMemberReference (MemberReference member)
+ {
+ }
+
+ public virtual void VisitInterfaceCollection (InterfaceCollection interfaces)
+ {
+ }
+
+ public virtual void VisitInterface (TypeReference interf)
+ {
+ }
+
+ public virtual void VisitExternTypeCollection (ExternTypeCollection externs)
+ {
+ }
+
+ public virtual void VisitExternType (TypeReference externType)
+ {
+ }
+
+ public virtual void VisitOverrideCollection (OverrideCollection meth)
+ {
+ }
+
+ public virtual void VisitOverride (MethodReference ov)
+ {
+ }
+
+ public virtual void VisitNestedTypeCollection (NestedTypeCollection nestedTypes)
+ {
+ }
+
+ public virtual void VisitNestedType (TypeDefinition nestedType)
+ {
+ }
+
+ public virtual void VisitParameterDefinitionCollection (ParameterDefinitionCollection parameters)
+ {
+ }
+
+ public virtual void VisitParameterDefinition (ParameterDefinition parameter)
+ {
+ }
+
+ public virtual void VisitMethodDefinitionCollection (MethodDefinitionCollection methods)
+ {
+ }
+
+ public virtual void VisitMethodDefinition (MethodDefinition method)
+ {
+ }
+
+ public virtual void VisitConstructorCollection (ConstructorCollection ctors)
+ {
+ }
+
+ public virtual void VisitConstructor (MethodDefinition ctor)
+ {
+ }
+
+ public virtual void VisitPInvokeInfo (PInvokeInfo pinvk)
+ {
+ }
+
+ public virtual void VisitEventDefinitionCollection (EventDefinitionCollection events)
+ {
+ }
+
+ public virtual void VisitEventDefinition (EventDefinition evt)
+ {
+ }
+
+ public virtual void VisitFieldDefinitionCollection (FieldDefinitionCollection fields)
+ {
+ }
+
+ public virtual void VisitFieldDefinition (FieldDefinition field)
+ {
+ }
+
+ public virtual void VisitPropertyDefinitionCollection (PropertyDefinitionCollection properties)
+ {
+ }
+
+ public virtual void VisitPropertyDefinition (PropertyDefinition property)
+ {
+ }
+
+ public virtual void VisitSecurityDeclarationCollection (SecurityDeclarationCollection secDecls)
+ {
+ }
+
+ public virtual void VisitSecurityDeclaration (SecurityDeclaration secDecl)
+ {
+ }
+
+ public virtual void VisitCustomAttributeCollection (CustomAttributeCollection customAttrs)
+ {
+ }
+
+ public virtual void VisitCustomAttribute (CustomAttribute customAttr)
+ {
+ }
+
+ public virtual void VisitGenericParameterCollection (GenericParameterCollection genparams)
+ {
+ }
+
+ public virtual void VisitGenericParameter (GenericParameter genparam)
+ {
+ }
+
+ public virtual void VisitMarshalSpec (MarshalSpec marshalSpec)
+ {
+ }
+
+ public virtual void TerminateModuleDefinition (ModuleDefinition module)
+ {
+ }
+
+ protected void VisitCollection (ICollection coll)
+ {
+ if (coll.Count == 0)
+ return;
+
+ foreach (IReflectionVisitable visitable in coll)
+ visitable.Accept (this);
+ }
+ }
+}
--- /dev/null
+//
+// BaseStructureVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ internal abstract class BaseStructureVisitor : IReflectionStructureVisitor {
+
+ public virtual void VisitAssemblyDefinition (AssemblyDefinition asm)
+ {
+ }
+
+ public virtual void VisitAssemblyNameDefinition (AssemblyNameDefinition name)
+ {
+ }
+
+ public virtual void VisitAssemblyNameReferenceCollection (AssemblyNameReferenceCollection names)
+ {
+ }
+
+ public virtual void VisitAssemblyNameReference (AssemblyNameReference name)
+ {
+ }
+
+ public virtual void VisitResourceCollection (ResourceCollection resources)
+ {
+ }
+
+ public virtual void VisitEmbeddedResource (EmbeddedResource res)
+ {
+ }
+
+ public virtual void VisitLinkedResource (LinkedResource res)
+ {
+ }
+
+ public virtual void VisitAssemblyLinkedResource (AssemblyLinkedResource res)
+ {
+ }
+
+ public virtual void VisitModuleDefinition (ModuleDefinition module)
+ {
+ }
+
+ public virtual void VisitModuleDefinitionCollection (ModuleDefinitionCollection modules)
+ {
+ }
+
+ public virtual void VisitModuleReference (ModuleReference module)
+ {
+ }
+
+ public virtual void VisitModuleReferenceCollection (ModuleReferenceCollection modules)
+ {
+ }
+
+ public virtual void TerminateAssemblyDefinition (AssemblyDefinition asm)
+ {
+ }
+
+ protected void VisitCollection (ICollection coll)
+ {
+ if (coll.Count == 0)
+ return;
+
+ foreach (IReflectionStructureVisitable visitable in coll)
+ visitable.Accept (this);
+ }
+ }
+}
--- /dev/null
+//
+// CallSite.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+ using System.Text;
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class CallSite : IMethodSignature, IAnnotationProvider, IMetadataTokenProvider {
+
+ MethodReference m_function;
+
+ public bool HasThis {
+ get { return m_function.HasThis; }
+ set { m_function.HasThis = value; }
+ }
+
+ public bool ExplicitThis {
+ get { return m_function.ExplicitThis; }
+ set { m_function.ExplicitThis = value; }
+ }
+
+ public MethodCallingConvention CallingConvention {
+ get { return m_function.CallingConvention; }
+ set { m_function.CallingConvention = value; }
+ }
+
+ public bool HasParameters {
+ get { return m_function.HasParameters; }
+ }
+
+ public ParameterDefinitionCollection Parameters {
+ get { return m_function.Parameters; }
+ }
+
+ public MethodReturnType ReturnType {
+ get { return m_function.ReturnType; }
+ set { m_function.ReturnType = value; }
+ }
+
+ public MetadataToken MetadataToken {
+ get { return m_function.MetadataToken; }
+ set { m_function.MetadataToken = value; }
+ }
+
+ IDictionary IAnnotationProvider.Annotations {
+ get { return ((IAnnotationProvider) m_function).Annotations; }
+ }
+
+ public CallSite (bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType)
+ {
+ m_function = new MethodReference (string.Empty, hasThis, explicitThis, callConv);
+ m_function.ReturnType = retType;
+ }
+
+ public int GetSentinel ()
+ {
+ return m_function.GetSentinel ();
+ }
+
+ public override string ToString ()
+ {
+ int sentinel = GetSentinel ();
+ StringBuilder sb = new StringBuilder ();
+ sb.Append (m_function.ReturnType.ReturnType.FullName);
+ sb.Append ("(");
+ if (m_function.HasParameters) {
+ for (int i = 0; i < m_function.Parameters.Count; i++) {
+ if (i > 0)
+ sb.Append (",");
+
+ if (i == sentinel)
+ sb.Append ("...,");
+
+ sb.Append (m_function.Parameters [i].ParameterType.FullName);
+ }
+ }
+ sb.Append (")");
+ return sb.ToString ();
+ }
+ }
+}
--- /dev/null
+//
+// FrameworkCompatibility.cs
+//
+// Author:
+// Rodrigo B. de Oliveira (rodrigobamboo@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+#if CF_1_0
+namespace System {
+
+ internal class NotImplementedException : System.Exception {
+
+ public NotImplementedException (string message) : base (message)
+ {
+ }
+
+ public NotImplementedException ()
+ {
+ }
+ }
+}
+#endif
+
+#if CF_1_0 || CF_2_0
+namespace System.Security {
+
+ internal class SecurityElement {
+
+ public SecurityElement (string tag)
+ {
+ }
+
+ public string Text
+ {
+ get { return string.Empty; }
+ set {}
+ }
+
+ public void AddChild (SecurityElement child)
+ {
+ }
+
+ public void AddAttribute (string name, string value)
+ {
+ }
+ }
+}
+#endif
--- /dev/null
+//
+// Constants.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal class Constants {
+
+ Constants ()
+ {
+ }
+
+ public const string Corlib = "mscorlib";
+
+ public const string ModuleType = "<Module>";
+ public const string PrivateImplDetails = "<PrivateImplementationDetails>";
+ public const string Deleted = "_Deleted";
+
+ public const string Void = "System.Void";
+ public const string Object = "System.Object";
+ public const string String = "System.String";
+ public const string Boolean = "System.Boolean";
+ public const string Char = "System.Char";
+ public const string Single = "System.Single";
+ public const string Double = "System.Double";
+ public const string SByte = "System.SByte";
+ public const string Byte = "System.Byte";
+ public const string Int16 = "System.Int16";
+ public const string UInt16 = "System.UInt16";
+ public const string Int32 = "System.Int32";
+ public const string UInt32 = "System.UInt32";
+ public const string Int64 = "System.Int64";
+ public const string UInt64 = "System.UInt64";
+ public const string IntPtr = "System.IntPtr";
+ public const string UIntPtr = "System.UIntPtr";
+ public const string TypedReference = "System.TypedReference";
+ public const string Type = "System.Type";
+ public const string ValueType = "System.ValueType";
+ public const string Enum = "System.Enum";
+ }
+}
--- /dev/null
+//
+// ConstraintCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:54 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class ConstraintCollection : CollectionBase {
+
+ GenericParameter m_container;
+
+ public TypeReference this [int index] {
+ get { return List [index] as TypeReference; }
+ set { List [index] = value; }
+ }
+
+ public GenericParameter Container {
+ get { return m_container; }
+ }
+
+ public ConstraintCollection (GenericParameter container)
+ {
+ m_container = container;
+ }
+
+ public void Add (TypeReference value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (TypeReference value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (TypeReference value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, TypeReference value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (TypeReference value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is TypeReference))
+ throw new ArgumentException ("Must be of type " + typeof (TypeReference).FullName);
+ }
+ }
+}
--- /dev/null
+//
+// ConstructorCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Mar 30 18:43:56 +0200 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class ConstructorCollection : CollectionBase, IReflectionVisitable {
+
+ TypeDefinition m_container;
+
+ public MethodDefinition this [int index] {
+ get { return List [index] as MethodDefinition; }
+ set { List [index] = value; }
+ }
+
+ public TypeDefinition Container {
+ get { return m_container; }
+ }
+
+ public ConstructorCollection (TypeDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (MethodDefinition value)
+ {
+ Attach (value);
+
+ List.Add (value);
+ }
+
+
+ public new void Clear ()
+ {
+ foreach (MethodDefinition item in this)
+ Detach (item);
+
+ base.Clear ();
+ }
+
+ public bool Contains (MethodDefinition value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (MethodDefinition value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, MethodDefinition value)
+ {
+ Attach (value);
+
+ List.Insert (index, value);
+ }
+
+ public void Remove (MethodDefinition value)
+ {
+ List.Remove (value);
+
+ Detach (value);
+ }
+
+
+ public new void RemoveAt (int index)
+ {
+ MethodDefinition item = this [index];
+ Remove (item);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is MethodDefinition))
+ throw new ArgumentException ("Must be of type " + typeof (MethodDefinition).FullName);
+ }
+
+ internal MethodDefinition GetConstructorInternal (bool isStatic, IList parameters)
+ {
+ if (parameters == null)
+#if CF_2_0 || CF_1_0
+ parameters = new Type[0];
+#else
+ parameters = Type.EmptyTypes;
+#endif
+
+ foreach (MethodDefinition ctor in this) {
+ if (ctor.IsStatic != isStatic || ctor.Parameters.Count != parameters.Count)
+ continue;
+
+ bool match = true;
+ for (int i = 0; i < parameters.Count; i++) {
+ string pname;
+ object param = parameters [i];
+ if (param is Type)
+ pname = ReflectionHelper.GetTypeSignature (param as Type);
+ else if (param is TypeReference)
+ pname = (param as TypeReference).FullName;
+ else if (param is ParameterDefinition)
+ pname = (param as ParameterDefinition).ParameterType.FullName;
+ else
+ throw new NotSupportedException ();
+
+ if (ctor.Parameters [i].ParameterType.FullName != pname) {
+ match = false;
+ break;
+ }
+ }
+
+ if (match)
+ return ctor;
+ }
+
+ return null;
+ }
+
+ public MethodDefinition GetConstructor (bool isStatic, Type [] parameters)
+ {
+ return GetConstructorInternal (isStatic, parameters);
+ }
+
+ public MethodDefinition GetConstructor (bool isStatic, TypeReference [] parameters)
+ {
+ return GetConstructorInternal (isStatic, parameters);
+ }
+
+ public MethodDefinition GetConstructor (bool isStatic, ParameterDefinitionCollection parameters)
+ {
+ return GetConstructorInternal (isStatic, parameters);
+ }
+
+ void Attach (MemberReference member)
+ {
+ if (member.DeclaringType != null)
+ throw new ReflectionException ("Member already attached, clone it instead");
+
+ member.DeclaringType = m_container;
+ }
+
+ void Detach (MemberReference member)
+ {
+ member.DeclaringType = null;
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitConstructorCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// CustomAttribute.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ internal sealed class CustomAttribute : IRequireResolving, IAnnotationProvider, IReflectionVisitable {
+
+ MethodReference m_ctor;
+ IList m_parameters;
+ IDictionary m_fields;
+ IDictionary m_properties;
+ IDictionary m_fieldTypes;
+ IDictionary m_propTypes;
+ IDictionary m_annotations;
+
+ bool m_resolved;
+ byte [] m_blob;
+
+ public MethodReference Constructor {
+ get { return m_ctor; }
+ set { m_ctor = value; }
+ }
+
+ public IList ConstructorParameters {
+ get {
+ if (m_parameters == null)
+ m_parameters = new ArrayList ();
+ return m_parameters;
+ }
+ }
+
+ public IDictionary Fields {
+ get {
+ if (m_fields == null)
+ m_fields = new Hashtable ();
+
+ return m_fields;
+ }
+ }
+
+ public IDictionary Properties {
+ get {
+ if (m_properties == null)
+ m_properties = new Hashtable ();
+
+ return m_properties;
+ }
+ }
+
+ internal IDictionary FieldTypes {
+ get {
+ if (m_fieldTypes == null)
+ m_fieldTypes = new Hashtable ();
+
+ return m_fieldTypes;
+ }
+ }
+
+ internal IDictionary PropertyTypes {
+ get {
+ if (m_propTypes == null)
+ m_propTypes = new Hashtable ();
+
+ return m_propTypes;
+ }
+ }
+
+ public bool Resolved {
+ get { return m_resolved; }
+ set { m_resolved = value; }
+ }
+
+ public byte [] Blob {
+ get { return m_blob; }
+ set { m_blob = value; }
+ }
+
+ IDictionary IAnnotationProvider.Annotations {
+ get {
+ if (m_annotations == null)
+ m_annotations = new Hashtable ();
+ return m_annotations;
+ }
+ }
+
+ public CustomAttribute (MethodReference ctor)
+ {
+ m_ctor = ctor;
+ m_resolved = true;
+ }
+
+ public CustomAttribute (MethodReference ctor, byte [] blob)
+ {
+ m_ctor = ctor;
+ m_blob = blob;
+ }
+
+ public TypeReference GetFieldType (string fieldName)
+ {
+ return (TypeReference) FieldTypes [fieldName];
+ }
+
+ public TypeReference GetPropertyType (string propertyName)
+ {
+ return (TypeReference) PropertyTypes [propertyName];
+ }
+
+ public void SetFieldType (string fieldName, TypeReference type)
+ {
+ FieldTypes [fieldName] = type;
+ }
+
+ public void SetPropertyType (string propertyName, TypeReference type)
+ {
+ PropertyTypes [propertyName] = type;
+ }
+
+ public CustomAttribute Clone ()
+ {
+ return Clone (this, new ImportContext (NullReferenceImporter.Instance));
+ }
+
+ static void Clone (IDictionary original, IDictionary target)
+ {
+ target.Clear ();
+ foreach (DictionaryEntry entry in original)
+ target.Add (entry.Key, entry.Value);
+ }
+
+ internal static CustomAttribute Clone (CustomAttribute custattr, ImportContext context)
+ {
+ CustomAttribute ca = new CustomAttribute (context.Import (custattr.Constructor));
+ custattr.CopyTo (ca);
+ return ca;
+ }
+
+ void CopyTo (CustomAttribute target)
+ {
+ target.Resolved = Resolved;
+ if (!Resolved) {
+ target.Blob = Blob;
+ return;
+ }
+
+ foreach (object o in ConstructorParameters)
+ target.ConstructorParameters.Add (o);
+ Clone (Fields, target.Fields);
+ Clone (FieldTypes, target.FieldTypes);
+ Clone (Properties, target.Properties);
+ Clone (PropertyTypes, target.PropertyTypes);
+ }
+
+ public bool Resolve ()
+ {
+ if (Resolved)
+ return true;
+
+ ReflectionReader r = m_ctor.DeclaringType.Module.Controller.Reader;
+ CustomAttribute newCa = r.GetCustomAttribute (m_ctor, Blob, true);
+ if (!newCa.Resolved)
+ return false;
+
+ newCa.CopyTo (this);
+ return true;
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitCustomAttribute (this);
+ }
+ }
+}
--- /dev/null
+//
+// CustomAttributeCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:53 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class CustomAttributeCollection : CollectionBase, IReflectionVisitable {
+
+ ICustomAttributeProvider m_container;
+
+ public CustomAttribute this [int index] {
+ get { return List [index] as CustomAttribute; }
+ set { List [index] = value; }
+ }
+
+ public ICustomAttributeProvider Container {
+ get { return m_container; }
+ }
+
+ public CustomAttributeCollection (ICustomAttributeProvider container)
+ {
+ m_container = container;
+ }
+
+ public void Add (CustomAttribute value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (CustomAttribute value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (CustomAttribute value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, CustomAttribute value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (CustomAttribute value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is CustomAttribute))
+ throw new ArgumentException ("Must be of type " + typeof (CustomAttribute).FullName);
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitCustomAttributeCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// DefaultAssemblyResolver.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ internal class DefaultAssemblyResolver : BaseAssemblyResolver {
+
+ IDictionary m_cache;
+
+ public DefaultAssemblyResolver ()
+ {
+ m_cache = new Hashtable ();
+ }
+
+ public override AssemblyDefinition Resolve (AssemblyNameReference name)
+ {
+ AssemblyDefinition asm = (AssemblyDefinition) m_cache [name.FullName];
+ if (asm == null) {
+ asm = base.Resolve (name);
+ m_cache [name.FullName] = asm;
+ }
+
+ return asm;
+ }
+
+ protected void RegisterAssembly (AssemblyDefinition assembly)
+ {
+ string key = assembly.Name.FullName;
+ if (m_cache.Contains (key))
+ return;
+
+ m_cache [key] = assembly;
+ }
+ }
+}
--- /dev/null
+//
+// DefaultReferenceImporter.cs
+//
+// Author:
+// Jb Evain (jbevain@novell.com)
+//
+// (C) 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ internal class DefaultImporter : IImporter {
+
+ ModuleDefinition m_module;
+
+ public ModuleDefinition Module {
+ get { return m_module; }
+ }
+
+ public DefaultImporter (ModuleDefinition module)
+ {
+ m_module = module;
+ }
+
+ public AssemblyNameReference ImportAssembly (AssemblyNameReference asm)
+ {
+ AssemblyNameReference asmRef = GetAssemblyNameReference (asm);
+ if (asmRef != null)
+ return asmRef;
+
+ asmRef = new AssemblyNameReference (
+ asm.Name, asm.Culture, asm.Version);
+ asmRef.PublicKeyToken = asm.PublicKeyToken;
+ asmRef.HashAlgorithm = asm.HashAlgorithm;
+ m_module.AssemblyReferences.Add (asmRef);
+ return asmRef;
+ }
+
+ AssemblyNameReference GetAssemblyNameReference (AssemblyNameReference asm)
+ {
+ foreach (AssemblyNameReference reference in m_module.AssemblyReferences)
+ if (reference.FullName == asm.FullName)
+ return reference;
+
+ return null;
+ }
+
+ TypeSpecification GetTypeSpec (TypeSpecification original, ImportContext context)
+ {
+ TypeSpecification typeSpec;
+
+ TypeReference elementType = ImportTypeReference (original.ElementType, context);
+ if (original is PointerType) {
+ typeSpec = new PointerType (elementType);
+ } else if (original is ArrayType) { // deal with complex arrays
+ typeSpec = new ArrayType (elementType);
+ } else if (original is ReferenceType) {
+ typeSpec = new ReferenceType (elementType);
+ } else if (original is GenericInstanceType) {
+ GenericInstanceType git = original as GenericInstanceType;
+ GenericInstanceType genElemType = new GenericInstanceType (elementType);
+
+ context.GenericContext.CheckProvider (genElemType.GetOriginalType (), git.GenericArguments.Count);
+ foreach (TypeReference arg in git.GenericArguments)
+ genElemType.GenericArguments.Add (ImportTypeReference (arg, context));
+
+ typeSpec = genElemType;
+ } else if (original is ModifierOptional) {
+ TypeReference mt = (original as ModifierOptional).ModifierType;
+ typeSpec = new ModifierOptional (elementType, ImportTypeReference (mt, context));
+ } else if (original is ModifierRequired) {
+ TypeReference mt = (original as ModifierRequired).ModifierType;
+ typeSpec = new ModifierRequired (elementType, ImportTypeReference (mt, context));
+ } else if (original is SentinelType) {
+ typeSpec = new SentinelType (elementType);
+ } else if (original is FunctionPointerType) {
+ FunctionPointerType ori = original as FunctionPointerType;
+
+ FunctionPointerType fnptr = new FunctionPointerType (
+ ori.HasThis,
+ ori.ExplicitThis,
+ ori.CallingConvention,
+ new MethodReturnType (ImportTypeReference (ori.ReturnType.ReturnType, context)));
+
+ foreach (ParameterDefinition parameter in ori.Parameters)
+ fnptr.Parameters.Add (new ParameterDefinition (ImportTypeReference (parameter.ParameterType, context)));
+
+ typeSpec = fnptr;
+ } else
+ throw new ReflectionException ("Unknown element type: {0}", original.GetType ().Name);
+
+ return typeSpec;
+ }
+
+ static GenericParameter GetGenericParameter (GenericParameter gp, ImportContext context)
+ {
+ GenericParameter p;
+ if (gp.Owner is TypeReference)
+ p = context.GenericContext.Type.GenericParameters [gp.Position];
+ else if (gp.Owner is MethodReference)
+ p = context.GenericContext.Method.GenericParameters [gp.Position];
+ else
+ throw new NotSupportedException ();
+
+ return p;
+ }
+
+ TypeReference AdjustReference (TypeReference type, TypeReference reference)
+ {
+ if (type.IsValueType && !reference.IsValueType)
+ reference.IsValueType = true;
+
+ if (type.HasGenericParameters) {
+ for (int i = reference.GenericParameters.Count; i < type.GenericParameters.Count; i++)
+ reference.GenericParameters.Add (new GenericParameter (i, reference));
+ }
+
+ return reference;
+ }
+
+ public virtual TypeReference ImportTypeReference (TypeReference t, ImportContext context)
+ {
+ if (t.Module == m_module)
+ return t;
+
+ if (t is TypeSpecification)
+ return GetTypeSpec (t as TypeSpecification, context);
+
+ if (t is GenericParameter)
+ return GetGenericParameter (t as GenericParameter, context);
+
+ TypeReference type = m_module.TypeReferences [t.FullName];
+ if (type != null)
+ return AdjustReference (t, type);
+
+ AssemblyNameReference asm;
+ if (t.Scope is AssemblyNameReference)
+ asm = ImportAssembly ((AssemblyNameReference) t.Scope);
+ else if (t.Scope is ModuleDefinition)
+ asm = ImportAssembly (((ModuleDefinition) t.Scope).Assembly.Name);
+ else
+ throw new NotImplementedException ();
+
+ if (t.DeclaringType != null) {
+ type = new TypeReference (t.Name, string.Empty, asm, t.IsValueType);
+ type.DeclaringType = ImportTypeReference (t.DeclaringType, context);
+ } else
+ type = new TypeReference (t.Name, t.Namespace, asm, t.IsValueType);
+
+ TypeReference contextType = context.GenericContext.Type;
+
+ context.GenericContext.Type = type;
+
+ GenericParameter.CloneInto (t, type, context);
+
+ context.GenericContext.Type = contextType;
+
+ m_module.TypeReferences.Add (type);
+ return type;
+ }
+
+ public virtual FieldReference ImportFieldReference (FieldReference fr, ImportContext context)
+ {
+ if (fr.DeclaringType.Module == m_module)
+ return fr;
+
+ FieldReference field = (FieldReference) GetMemberReference (fr);
+ if (field != null)
+ return field;
+
+ field = new FieldReference (
+ fr.Name,
+ ImportTypeReference (fr.DeclaringType, context),
+ ImportTypeReference (fr.FieldType, context));
+
+ m_module.MemberReferences.Add (field);
+ return field;
+ }
+
+ MethodReference GetMethodSpec (MethodReference meth, ImportContext context)
+ {
+ if (!(meth is GenericInstanceMethod))
+ return null;
+
+ GenericInstanceMethod gim = meth as GenericInstanceMethod;
+ GenericInstanceMethod ngim = new GenericInstanceMethod (
+ ImportMethodReference (gim.ElementMethod, context));
+
+ context.GenericContext.CheckProvider (ngim.GetOriginalMethod (), gim.GenericArguments.Count);
+ foreach (TypeReference arg in gim.GenericArguments)
+ ngim.GenericArguments.Add (ImportTypeReference (arg, context));
+
+ return ngim;
+ }
+
+ public virtual MethodReference ImportMethodReference (MethodReference mr, ImportContext context)
+ {
+ if (mr.DeclaringType.Module == m_module)
+ return mr;
+
+ if (mr is MethodSpecification)
+ return GetMethodSpec (mr, context);
+
+ MethodReference meth = (MethodReference) GetMemberReference (mr);
+ if (meth != null)
+ return meth;
+
+ meth = new MethodReference (
+ mr.Name,
+ mr.HasThis,
+ mr.ExplicitThis,
+ mr.CallingConvention);
+ meth.DeclaringType = ImportTypeReference (mr.DeclaringType, context);
+
+ TypeReference contextType = context.GenericContext.Type;
+ MethodReference contextMethod = context.GenericContext.Method;
+
+ context.GenericContext.Method = meth;
+ context.GenericContext.Type = meth.DeclaringType.GetOriginalType();
+
+ GenericParameter.CloneInto (mr, meth, context);
+
+ meth.ReturnType.ReturnType = ImportTypeReference (mr.ReturnType.ReturnType, context);
+
+ foreach (ParameterDefinition param in mr.Parameters)
+ meth.Parameters.Add (new ParameterDefinition (
+ ImportTypeReference (param.ParameterType, context)));
+
+ context.GenericContext.Type = contextType;
+ context.GenericContext.Method = contextMethod;
+
+ m_module.MemberReferences.Add (meth);
+ return meth;
+ }
+
+ MemberReference GetMemberReference (MemberReference member)
+ {
+ foreach (MemberReference reference in m_module.MemberReferences)
+ if (reference.ToString () == member.ToString ())
+ return reference;
+
+ return null;
+ }
+ }
+}
--- /dev/null
+//
+// EmbeddedResource.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class EmbeddedResource : Resource {
+
+ byte [] m_data;
+
+ public byte [] Data {
+ get { return m_data; }
+ set { m_data = value; }
+ }
+
+ public EmbeddedResource (string name, ManifestResourceAttributes flags) :
+ base (name, flags)
+ {
+ }
+
+ public EmbeddedResource (string name, ManifestResourceAttributes flags, byte [] data) :
+ base (name, flags)
+ {
+ m_data = data;
+ }
+
+ public override void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitEmbeddedResource (this);
+ }
+ }
+}
--- /dev/null
+//
+// EventAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum EventAttributes : ushort {
+ SpecialName = 0x0200, // Event is special
+ RTSpecialName = 0x0400 // CLI provides 'special' behavior, depending upon the name of the event
+ }
+}
--- /dev/null
+//
+// EventDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class EventDefinition : EventReference, IMemberDefinition, ICustomAttributeProvider {
+
+ EventAttributes m_attributes;
+
+ CustomAttributeCollection m_customAttrs;
+
+ MethodDefinition m_addMeth;
+ MethodDefinition m_invMeth;
+ MethodDefinition m_remMeth;
+
+ public EventAttributes Attributes {
+ get { return m_attributes; }
+ set { m_attributes = value; }
+ }
+
+ public MethodDefinition AddMethod {
+ get { return m_addMeth; }
+ set { m_addMeth = value; }
+ }
+
+ public MethodDefinition InvokeMethod {
+ get { return m_invMeth; }
+ set { m_invMeth = value; }
+ }
+
+ public MethodDefinition RemoveMethod {
+ get { return m_remMeth; }
+ set { m_remMeth = value; }
+ }
+
+ public bool HasCustomAttributes {
+ get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
+ }
+
+ public CustomAttributeCollection CustomAttributes {
+ get {
+ if (m_customAttrs == null)
+ m_customAttrs = new CustomAttributeCollection (this);
+
+ return m_customAttrs;
+ }
+ }
+
+ #region EventAttributes
+
+ public bool IsSpecialName {
+ get { return (m_attributes & EventAttributes.SpecialName) != 0; }
+ set {
+ if (value)
+ m_attributes |= EventAttributes.SpecialName;
+ else
+ m_attributes &= ~EventAttributes.SpecialName;
+ }
+ }
+
+ public bool IsRuntimeSpecialName {
+ get { return (m_attributes & EventAttributes.RTSpecialName) != 0; }
+ set {
+ if (value)
+ m_attributes |= EventAttributes.RTSpecialName;
+ else
+ m_attributes &= ~EventAttributes.RTSpecialName;
+ }
+ }
+
+ #endregion
+
+ public new TypeDefinition DeclaringType {
+ get { return (TypeDefinition) base.DeclaringType; }
+ set { base.DeclaringType = value; }
+ }
+
+ public EventDefinition (string name, TypeReference eventType,
+ EventAttributes attrs) : base (name, eventType)
+ {
+ m_attributes = attrs;
+ }
+
+ public override EventDefinition Resolve ()
+ {
+ return this;
+ }
+
+ public static MethodDefinition CreateAddMethod (EventDefinition evt)
+ {
+ MethodDefinition add = new MethodDefinition (
+ string.Concat ("add_", evt.Name), (MethodAttributes) 0, evt.EventType);
+ evt.AddMethod = add;
+ return add;
+ }
+
+ public static MethodDefinition CreateRemoveMethod (EventDefinition evt)
+ {
+ MethodDefinition remove = new MethodDefinition (
+ string.Concat ("remove_", evt.Name), (MethodAttributes) 0, evt.EventType);
+ evt.RemoveMethod = remove;
+ return remove;
+ }
+
+ public static MethodDefinition CreateInvokeMethod (EventDefinition evt)
+ {
+ MethodDefinition raise = new MethodDefinition (
+ string.Concat ("raise_", evt.Name), (MethodAttributes) 0, evt.EventType);
+ evt.InvokeMethod = raise;
+ return raise;
+ }
+
+ public EventDefinition Clone ()
+ {
+ return Clone (this, new ImportContext (NullReferenceImporter.Instance, this.DeclaringType));
+ }
+
+ internal static EventDefinition Clone (EventDefinition evt, ImportContext context)
+ {
+ EventDefinition ne = new EventDefinition (
+ evt.Name,
+ context.Import (evt.EventType),
+ evt.Attributes);
+
+ if (context.GenericContext.Type is TypeDefinition) {
+ TypeDefinition type = context.GenericContext.Type as TypeDefinition;
+ if (evt.AddMethod != null)
+ ne.AddMethod = type.Methods.GetMethod (evt.AddMethod.Name) [0];
+ if (evt.InvokeMethod != null)
+ ne.InvokeMethod = type.Methods.GetMethod (evt.InvokeMethod.Name) [0];
+ if (evt.RemoveMethod != null)
+ ne.RemoveMethod = type.Methods.GetMethod (evt.RemoveMethod.Name) [0];
+ }
+
+ foreach (CustomAttribute ca in evt.CustomAttributes)
+ ne.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
+
+ return ne;
+ }
+
+ public override void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitEventDefinition (this);
+
+ this.CustomAttributes.Accept (visitor);
+ }
+ }
+}
--- /dev/null
+//
+// EventDefinitionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Mar 30 18:43:57 +0200 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class EventDefinitionCollection : CollectionBase, IReflectionVisitable {
+
+ TypeDefinition m_container;
+
+ public EventDefinition this [int index] {
+ get { return List [index] as EventDefinition; }
+ set { List [index] = value; }
+ }
+
+ public TypeDefinition Container {
+ get { return m_container; }
+ }
+
+ public EventDefinitionCollection (TypeDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (EventDefinition value)
+ {
+ Attach (value);
+
+ List.Add (value);
+ }
+
+
+ public new void Clear ()
+ {
+ foreach (EventDefinition item in this)
+ Detach (item);
+
+ base.Clear ();
+ }
+
+ public bool Contains (EventDefinition value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (EventDefinition value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, EventDefinition value)
+ {
+ Attach (value);
+
+ List.Insert (index, value);
+ }
+
+ public void Remove (EventDefinition value)
+ {
+ List.Remove (value);
+
+ Detach (value);
+ }
+
+
+ public new void RemoveAt (int index)
+ {
+ EventDefinition item = this [index];
+ Remove (item);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is EventDefinition))
+ throw new ArgumentException ("Must be of type " + typeof (EventDefinition).FullName);
+ }
+
+ public EventDefinition GetEvent (string name)
+ {
+ foreach (EventDefinition evt in this)
+ if (evt.Name == name)
+ return evt;
+
+ return null;
+ }
+
+ void Attach (MemberReference member)
+ {
+ if (member.DeclaringType != null)
+ throw new ReflectionException ("Member already attached, clone it instead");
+
+ member.DeclaringType = m_container;
+ }
+
+ void Detach (MemberReference member)
+ {
+ member.DeclaringType = null;
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitEventDefinitionCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// EventReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal abstract class EventReference : MemberReference {
+
+ TypeReference m_eventType;
+
+ public TypeReference EventType {
+ get { return m_eventType; }
+ set { m_eventType = value; }
+ }
+
+ public EventReference (string name, TypeReference eventType) : base (name)
+ {
+ m_eventType = eventType;
+ }
+
+ public abstract EventDefinition Resolve ();
+
+ public override string ToString ()
+ {
+ return string.Concat (m_eventType.FullName, " ", base.ToString ());
+ }
+ }
+}
--- /dev/null
+//
+// ExternTypeCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Mar 30 18:43:57 +0200 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Specialized;
+
+ using Mono.Cecil.Cil;
+
+ using Hcp = Mono.Cecil.HashCodeProvider;
+ using Cmp = System.Collections.Comparer;
+
+ internal sealed class ExternTypeCollection : NameObjectCollectionBase, IList, IReflectionVisitable {
+
+ ModuleDefinition m_container;
+
+ public TypeReference this [int index] {
+ get { return this.BaseGet (index) as TypeReference; }
+ set { this.BaseSet (index, value); }
+ }
+
+ public TypeReference this [string fullName] {
+ get { return this.BaseGet (fullName) as TypeReference; }
+ set { this.BaseSet (fullName, value); }
+ }
+
+ public ModuleDefinition Container {
+ get { return m_container; }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ bool IList.IsReadOnly {
+ get { return false; }
+ }
+
+ bool IList.IsFixedSize {
+ get { return false; }
+ }
+
+ object IList.this [int index] {
+ get { return BaseGet (index); }
+ set {
+ Check (value);
+ BaseSet (index, value);
+ }
+ }
+
+ public ExternTypeCollection (ModuleDefinition container) :
+ base (Hcp.Instance, Cmp.Default)
+ {
+ m_container = container;
+ }
+
+ public void Add (TypeReference value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
+ this.BaseAdd (value.FullName, value);
+ }
+
+ public void Clear ()
+ {
+ this.BaseClear ();
+ }
+
+ public bool Contains (TypeReference value)
+ {
+ return Contains (value.FullName);
+ }
+
+ public bool Contains (string fullName)
+ {
+ return this.BaseGet (fullName) != null;
+ }
+
+ public int IndexOf (TypeReference value)
+ {
+ string [] keys = this.BaseGetAllKeys ();
+ return Array.IndexOf (keys, value.FullName, 0, keys.Length);
+ }
+
+ public void Remove (TypeReference value)
+ {
+ this.BaseRemove (value.FullName);
+ }
+
+ public void RemoveAt (int index)
+ {
+ TypeReference item = this [index];
+ Remove (item);
+ }
+
+ public void CopyTo (Array ary, int index)
+ {
+ this.BaseGetAllValues ().CopyTo (ary, index);
+ }
+
+ public new IEnumerator GetEnumerator ()
+ {
+ return this.BaseGetAllValues ().GetEnumerator ();
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitExternTypeCollection (this);
+ }
+
+#if CF_1_0 || CF_2_0
+ internal object [] BaseGetAllValues ()
+ {
+ object [] values = new object [this.Count];
+ for (int i=0; i < values.Length; ++i) {
+ values [i] = this.BaseGet (i);
+ }
+ return values;
+ }
+#endif
+
+ void Check (object value)
+ {
+ if (!(value is TypeReference))
+ throw new ArgumentException ();
+ }
+
+ int IList.Add (object value)
+ {
+ Check (value);
+ Add (value as TypeReference);
+ return 0;
+ }
+
+ bool IList.Contains (object value)
+ {
+ Check (value);
+ return Contains (value as TypeReference);
+ }
+
+ int IList.IndexOf (object value)
+ {
+ throw new NotSupportedException ();
+ }
+
+ void IList.Insert (int index, object value)
+ {
+ throw new NotSupportedException ();
+ }
+
+ void IList.Remove (object value)
+ {
+ Check (value);
+ Remove (value as TypeReference);
+ }
+ }
+}
--- /dev/null
+//
+// FieldAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum FieldAttributes : ushort {
+ FieldAccessMask = 0x0007,
+ Compilercontrolled = 0x0000, // Member not referenceable
+ Private = 0x0001, // Accessible only by the parent type
+ FamANDAssem = 0x0002, // Accessible by sub-types only in this assembly
+ Assembly = 0x0003, // Accessible by anyone in the Assembly
+ Family = 0x0004, // Accessible only by type and sub-types
+ FamORAssem = 0x0005, // Accessible by sub-types anywhere, plus anyone in the assembly
+ Public = 0x0006, // Accessible by anyone who has visibility to this scope field contract attributes
+
+ Static = 0x0010, // Defined on type, else per instance
+ InitOnly = 0x0020, // Field may only be initialized, not written after init
+ Literal = 0x0040, // Value is compile time constant
+ NotSerialized = 0x0080, // Field does not have to be serialized when type is remoted
+ SpecialName = 0x0200, // Field is special
+
+ // Interop Attributes
+ PInvokeImpl = 0x2000, // Implementation is forwarded through PInvoke
+
+ // Additional flags
+ RTSpecialName = 0x0400, // CLI provides 'special' behavior, depending upon the name of the field
+ HasFieldMarshal = 0x1000, // Field has marshalling information
+ HasDefault = 0x8000, // Field has default
+ HasFieldRVA = 0x0100 // Field has RVA
+ }
+}
--- /dev/null
+//
+// FieldDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using Mono.Cecil;
+ using Mono.Cecil.Binary;
+
+ internal sealed class FieldDefinition : FieldReference, IMemberDefinition,
+ ICustomAttributeProvider, IHasMarshalSpec, IHasConstant {
+
+ FieldAttributes m_attributes;
+
+ CustomAttributeCollection m_customAttrs;
+
+ bool m_hasInfo;
+ uint m_offset;
+
+ RVA m_rva;
+ byte [] m_initVal;
+
+ bool m_hasConstant;
+ object m_const;
+
+ MarshalSpec m_marshalDesc;
+
+ public bool HasLayoutInfo {
+ get { return m_hasInfo; }
+ }
+
+ public uint Offset {
+ get { return m_offset; }
+ set {
+ m_hasInfo = true;
+ m_offset = value;
+ }
+ }
+
+ public RVA RVA {
+ get { return m_rva; }
+ set { m_rva = value; }
+ }
+
+ public byte [] InitialValue {
+ get { return m_initVal; }
+ set { m_initVal = value; }
+ }
+
+ public FieldAttributes Attributes {
+ get { return m_attributes; }
+ set { m_attributes = value; }
+ }
+
+ public bool HasConstant {
+ get { return m_hasConstant; }
+ }
+
+ public object Constant {
+ get { return m_const; }
+ set {
+ m_hasConstant = true;
+ m_const = value;
+ }
+ }
+
+ public bool HasCustomAttributes {
+ get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
+ }
+
+ public CustomAttributeCollection CustomAttributes {
+ get {
+ if (m_customAttrs == null)
+ m_customAttrs = new CustomAttributeCollection (this);
+
+ return m_customAttrs;
+ }
+ }
+
+ public MarshalSpec MarshalSpec {
+ get { return m_marshalDesc; }
+ set {
+ m_marshalDesc = value;
+ if (value != null)
+ m_attributes |= FieldAttributes.HasFieldMarshal;
+ else
+ m_attributes &= FieldAttributes.HasFieldMarshal;
+ }
+ }
+
+ #region FieldAttributes
+
+ public bool IsCompilerControlled {
+ get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Compilercontrolled; }
+ set {
+ if (value) {
+ m_attributes &= ~FieldAttributes.FieldAccessMask;
+ m_attributes |= FieldAttributes.Compilercontrolled;
+ } else
+ m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.Compilercontrolled);
+ }
+ }
+
+ public bool IsPrivate {
+ get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private; }
+ set {
+ if (value) {
+ m_attributes &= ~FieldAttributes.FieldAccessMask;
+ m_attributes |= FieldAttributes.Private;
+ } else
+ m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.Private);
+ }
+ }
+
+ public bool IsFamilyAndAssembly {
+ get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem; }
+ set {
+ if (value) {
+ m_attributes &= ~FieldAttributes.FieldAccessMask;
+ m_attributes |= FieldAttributes.FamANDAssem;
+ } else
+ m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.FamANDAssem);
+ }
+ }
+
+ public bool IsAssembly {
+ get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly; }
+ set {
+ if (value) {
+ m_attributes &= ~FieldAttributes.FieldAccessMask;
+ m_attributes |= FieldAttributes.Assembly;
+ } else
+ m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.Assembly);
+ }
+ }
+
+ public bool IsFamily {
+ get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family; }
+ set {
+ if (value) {
+ m_attributes &= ~FieldAttributes.FieldAccessMask;
+ m_attributes |= FieldAttributes.Family;
+ } else
+ m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.Family);
+ }
+ }
+
+ public bool IsFamilyOrAssembly {
+ get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem; }
+ set {
+ if (value) {
+ m_attributes &= ~FieldAttributes.FieldAccessMask;
+ m_attributes |= FieldAttributes.FamORAssem;
+ } else
+ m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.FamORAssem);
+ }
+ }
+
+ public bool IsPublic {
+ get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public; }
+ set {
+ if (value) {
+ m_attributes &= ~FieldAttributes.FieldAccessMask;
+ m_attributes |= FieldAttributes.Public;
+ } else
+ m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.Public);
+ }
+ }
+
+ public bool IsStatic {
+ get { return (m_attributes & FieldAttributes.Static) != 0; }
+ set {
+ if (value)
+ m_attributes |= FieldAttributes.Static;
+ else
+ m_attributes &= ~FieldAttributes.Static;
+ }
+ }
+
+ public bool IsInitOnly {
+ get { return (m_attributes & FieldAttributes.InitOnly) != 0; }
+ set {
+ if (value)
+ m_attributes |= FieldAttributes.InitOnly;
+ else
+ m_attributes &= ~FieldAttributes.InitOnly;
+ }
+ }
+
+ public bool IsLiteral {
+ get { return (m_attributes & FieldAttributes.Literal) != 0; }
+ set {
+ if (value)
+ m_attributes |= FieldAttributes.Literal;
+ else
+ m_attributes &= ~FieldAttributes.Literal;
+ }
+ }
+
+ public bool IsNotSerialized {
+ get { return (m_attributes & FieldAttributes.NotSerialized) != 0; }
+ set {
+ if (value)
+ m_attributes |= FieldAttributes.NotSerialized;
+ else
+ m_attributes &= ~FieldAttributes.NotSerialized;
+ }
+ }
+
+ public bool IsSpecialName {
+ get { return (m_attributes & FieldAttributes.SpecialName) != 0; }
+ set {
+ if (value)
+ m_attributes |= FieldAttributes.SpecialName;
+ else
+ m_attributes &= ~FieldAttributes.SpecialName;
+ }
+ }
+
+ public bool IsPInvokeImpl {
+ get { return (m_attributes & FieldAttributes.PInvokeImpl) != 0; }
+ set {
+ if (value)
+ m_attributes |= FieldAttributes.PInvokeImpl;
+ else
+ m_attributes &= ~FieldAttributes.PInvokeImpl;
+ }
+ }
+
+ public bool IsRuntimeSpecialName {
+ get { return (m_attributes & FieldAttributes.RTSpecialName) != 0; }
+ set {
+ if (value)
+ m_attributes |= FieldAttributes.RTSpecialName;
+ else
+ m_attributes &= ~FieldAttributes.RTSpecialName;
+ }
+ }
+
+ public bool HasDefault {
+ get { return (m_attributes & FieldAttributes.HasDefault) != 0; }
+ set {
+ if (value)
+ m_attributes |= FieldAttributes.HasDefault;
+ else
+ m_attributes &= ~FieldAttributes.HasDefault;
+ }
+ }
+
+ #endregion
+
+ public new TypeDefinition DeclaringType {
+ get { return (TypeDefinition) base.DeclaringType; }
+ set { base.DeclaringType = value; }
+ }
+
+ public FieldDefinition (string name, TypeReference fieldType,
+ FieldAttributes attrs) : base (name, fieldType)
+ {
+ m_attributes = attrs;
+ }
+
+ public override FieldDefinition Resolve ()
+ {
+ return this;
+ }
+
+ public FieldDefinition Clone ()
+ {
+ return Clone (this, new ImportContext (NullReferenceImporter.Instance, this.DeclaringType));
+ }
+
+ internal static FieldDefinition Clone (FieldDefinition field, ImportContext context)
+ {
+ FieldDefinition nf = new FieldDefinition (
+ field.Name,
+ context.Import (field.FieldType),
+ field.Attributes);
+
+ if (field.HasConstant)
+ nf.Constant = field.Constant;
+ if (field.MarshalSpec != null)
+ nf.MarshalSpec = field.MarshalSpec.CloneInto (nf);
+ if (field.RVA != RVA.Zero)
+ nf.InitialValue = field.InitialValue;
+ else
+ nf.InitialValue = new byte [0];
+ if (field.HasLayoutInfo)
+ nf.Offset = field.Offset;
+
+ foreach (CustomAttribute ca in field.CustomAttributes)
+ nf.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
+
+ return nf;
+ }
+
+ public override void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitFieldDefinition (this);
+
+ if (this.MarshalSpec != null)
+ this.MarshalSpec.Accept (visitor);
+
+ this.CustomAttributes.Accept (visitor);
+ }
+ }
+}
--- /dev/null
+//
+// FieldDefinitionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Mar 30 18:43:57 +0200 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class FieldDefinitionCollection : CollectionBase, IReflectionVisitable {
+
+ TypeDefinition m_container;
+
+ public FieldDefinition this [int index] {
+ get { return List [index] as FieldDefinition; }
+ set { List [index] = value; }
+ }
+
+ public TypeDefinition Container {
+ get { return m_container; }
+ }
+
+ public FieldDefinitionCollection (TypeDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (FieldDefinition value)
+ {
+ Attach (value);
+
+ List.Add (value);
+ }
+
+
+ public new void Clear ()
+ {
+ foreach (FieldDefinition item in this)
+ Detach (item);
+
+ base.Clear ();
+ }
+
+ public bool Contains (FieldDefinition value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (FieldDefinition value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, FieldDefinition value)
+ {
+ Attach (value);
+
+ List.Insert (index, value);
+ }
+
+ public void Remove (FieldDefinition value)
+ {
+ List.Remove (value);
+
+ Detach (value);
+ }
+
+
+ public new void RemoveAt (int index)
+ {
+ FieldDefinition item = this [index];
+ Remove (item);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is FieldDefinition))
+ throw new ArgumentException ("Must be of type " + typeof (FieldDefinition).FullName);
+ }
+
+ public FieldDefinition GetField (string name)
+ {
+ foreach (FieldDefinition field in this)
+ if (field.Name == name)
+ return field;
+
+ return null;
+ }
+
+ void Attach (MemberReference member)
+ {
+ if (member.DeclaringType != null)
+ throw new ReflectionException ("Member already attached, clone it instead");
+
+ member.DeclaringType = m_container;
+ }
+
+ void Detach (MemberReference member)
+ {
+ member.DeclaringType = null;
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitFieldDefinitionCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// FieldReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using Mono.Cecil;
+
+ internal class FieldReference : MemberReference {
+
+ TypeReference m_fieldType;
+
+ public TypeReference FieldType {
+ get { return m_fieldType; }
+ set { m_fieldType = value; }
+ }
+
+ internal FieldReference (string name, TypeReference fieldType) : base (name)
+ {
+ m_fieldType = fieldType;
+ }
+
+ public FieldReference (string name, TypeReference declaringType, TypeReference fieldType) :
+ this (name, fieldType)
+ {
+ this.DeclaringType = declaringType;
+ }
+
+ public virtual FieldDefinition Resolve ()
+ {
+ TypeReference declaringType = DeclaringType;
+ if (declaringType == null)
+ return null;
+
+ return declaringType.Module.Resolver.Resolve (this);
+ }
+
+ public override string ToString ()
+ {
+ return string.Concat (m_fieldType.FullName, " ", base.ToString ());
+ }
+ }
+}
--- /dev/null
+//
+// FileAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal enum FileAttributes : uint {
+ ContainsMetaData = 0x0000, // This is not a resource file
+ ContainsNoMetaData = 0x0001, // This is a resource file or other non-metadata-containing file
+ }
+}
--- /dev/null
+//
+// FunctionPointerType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Text;
+
+ internal sealed class FunctionPointerType : TypeSpecification, IMethodSignature {
+
+ MethodReference m_function;
+
+ public bool HasThis {
+ get { return m_function.HasThis; }
+ set { m_function.HasThis = value; }
+ }
+
+ public bool ExplicitThis {
+ get { return m_function.ExplicitThis; }
+ set { m_function.ExplicitThis = value; }
+ }
+
+ public MethodCallingConvention CallingConvention {
+ get { return m_function.CallingConvention; }
+ set { m_function.CallingConvention = value; }
+ }
+
+ public bool HasParameters {
+ get { return m_function.HasParameters; }
+ }
+
+ public ParameterDefinitionCollection Parameters {
+ get { return m_function.Parameters; }
+ }
+
+ public MethodReturnType ReturnType {
+ get { return m_function.ReturnType; }
+ set { m_function.ReturnType = value; }
+ }
+
+ public override string Name {
+ get { return m_function.Name; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string Namespace {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override IMetadataScope Scope {
+ get { return m_function.DeclaringType.Scope; }
+ }
+
+ public override string FullName {
+ get {
+ int sentinel = GetSentinel ();
+ StringBuilder sb = new StringBuilder ();
+ sb.Append (m_function.Name);
+ sb.Append (" ");
+ sb.Append (m_function.ReturnType.ReturnType.FullName);
+ sb.Append (" *(");
+ if (m_function.HasParameters) {
+ for (int i = 0; i < m_function.Parameters.Count; i++) {
+ if (i > 0)
+ sb.Append (",");
+
+ if (i == sentinel)
+ sb.Append ("...,");
+
+ sb.Append (m_function.Parameters [i].ParameterType.FullName);
+ }
+ }
+ sb.Append (")");
+ return sb.ToString ();
+ }
+ }
+
+ public FunctionPointerType (bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType) :
+ base (retType.ReturnType)
+ {
+ m_function = new MethodReference ("method", hasThis, explicitThis, callConv);
+ m_function.ReturnType = retType;
+ }
+
+ public int GetSentinel ()
+ {
+ return m_function.GetSentinel ();
+ }
+ }
+}
--- /dev/null
+//
+// GenericArgumentCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:54 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class GenericArgumentCollection : CollectionBase {
+
+ IGenericInstance m_container;
+
+ public TypeReference this [int index] {
+ get { return List [index] as TypeReference; }
+ set { List [index] = value; }
+ }
+
+ public IGenericInstance Container {
+ get { return m_container; }
+ }
+
+ public GenericArgumentCollection (IGenericInstance container)
+ {
+ m_container = container;
+ }
+
+ public void Add (TypeReference value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (TypeReference value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (TypeReference value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, TypeReference value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (TypeReference value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is TypeReference))
+ throw new ArgumentException ("Must be of type " + typeof (TypeReference).FullName);
+ }
+ }
+}
--- /dev/null
+//
+// GenericContext.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal class GenericContext {
+
+ TypeReference m_type;
+ MethodReference m_method;
+
+ public TypeReference Type {
+ get { return m_type; }
+ set { m_type = value; }
+ }
+
+ public MethodReference Method {
+ get { return m_method; }
+ set { m_method = value; }
+ }
+
+ public bool AllowCreation {
+ get { return m_type != null && m_type.GetType () == typeof (TypeReference); }
+ }
+
+ public bool Null {
+ get { return m_type == null && m_method == null; }
+ }
+
+ public GenericContext ()
+ {
+ }
+
+ public GenericContext (TypeReference type, MethodReference meth)
+ {
+ m_type = type;
+ m_method = meth;
+ }
+
+ public GenericContext (IGenericParameterProvider provider)
+ {
+ if (provider is TypeReference)
+ m_type = provider as TypeReference;
+ else if (provider is MethodReference) {
+ MethodReference meth = provider as MethodReference;
+ m_method = meth;
+ m_type = meth.DeclaringType;
+ }
+ }
+
+ internal void CheckProvider (IGenericParameterProvider provider, int count)
+ {
+ if (!AllowCreation)
+ return;
+
+ for (int i = provider.GenericParameters.Count; i < count; i++)
+ provider.GenericParameters.Add (new GenericParameter (i, provider));
+ }
+
+ public GenericContext Clone ()
+ {
+ GenericContext ctx = new GenericContext ();
+ ctx.Type = m_type;
+ ctx.Method = m_method;
+ return ctx;
+ }
+ }
+}
--- /dev/null
+//
+// IGenericInstanceMethod.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Text;
+
+ internal sealed class GenericInstanceMethod : MethodSpecification, IGenericInstance {
+
+ private GenericArgumentCollection m_genArgs;
+
+ public GenericArgumentCollection GenericArguments {
+ get {
+ if (m_genArgs == null)
+ m_genArgs = new GenericArgumentCollection (this);
+ return m_genArgs;
+ }
+ }
+
+ public bool HasGenericArguments {
+ get { return m_genArgs == null ? false : m_genArgs.Count > 0; }
+ }
+
+ public GenericInstanceMethod (MethodReference elemMethod) : base (elemMethod)
+ {
+ }
+
+ public override string ToString ()
+ {
+ StringBuilder sb = new StringBuilder ();
+ MethodReference meth = this.ElementMethod;
+ sb.Append (meth.ReturnType.ReturnType.FullName);
+ sb.Append (" ");
+ sb.Append (meth.DeclaringType.FullName);
+ sb.Append ("::");
+ sb.Append (meth.Name);
+ sb.Append ("<");
+ for (int i = 0; i < this.GenericArguments.Count; i++) {
+ if (i > 0)
+ sb.Append (",");
+ sb.Append (this.GenericArguments [i].FullName);
+ }
+ sb.Append (">");
+ sb.Append ("(");
+ if (meth.HasParameters) {
+ for (int i = 0; i < meth.Parameters.Count; i++) {
+ sb.Append (meth.Parameters [i].ParameterType.FullName);
+ if (i < meth.Parameters.Count - 1)
+ sb.Append (",");
+ }
+ }
+ sb.Append (")");
+ return sb.ToString ();
+ }
+ }
+}
--- /dev/null
+//
+// GenericInstanceType.cs
+//
+// Author:
+// Martin Baulig <martin@ximian.com>
+// Jb Evain <jbevain@gmail.com>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Text;
+
+ internal sealed class GenericInstanceType : TypeSpecification, IGenericInstance {
+
+ private GenericArgumentCollection m_genArgs;
+
+ public GenericArgumentCollection GenericArguments {
+ get {
+ if (m_genArgs == null)
+ m_genArgs = new GenericArgumentCollection (this);
+ return m_genArgs;
+ }
+ }
+
+ public bool HasGenericArguments {
+ get { return m_genArgs == null ? false : m_genArgs.Count > 0; }
+ }
+
+ public override bool IsValueType {
+ get { return m_isValueType; }
+ set { m_isValueType = value; }
+ }
+
+ public override string FullName {
+ get {
+ StringBuilder sb = new StringBuilder ();
+ sb.Append (base.FullName);
+ sb.Append ("<");
+ for (int i = 0; i < this.GenericArguments.Count; i++) {
+ if (i > 0)
+ sb.Append (",");
+ sb.Append (this.GenericArguments [i].FullName);
+ }
+ sb.Append (">");
+ return sb.ToString ();
+ }
+ }
+
+ public GenericInstanceType (TypeReference elementType) : base (elementType)
+ {
+ m_isValueType = elementType.IsValueType;
+ }
+ }
+}
--- /dev/null
+//
+// GenericParameter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ internal sealed class GenericParameter : TypeReference {
+
+ int m_position;
+ string m_name;
+ GenericParameterAttributes m_attributes;
+ IGenericParameterProvider m_owner;
+ ConstraintCollection m_constraints;
+
+ public int Position {
+ get { return m_position; }
+ set { m_position = value; }
+ }
+
+ public GenericParameterAttributes Attributes {
+ get { return m_attributes; }
+ set { m_attributes = value; }
+ }
+
+ public IGenericParameterProvider Owner {
+ get { return m_owner; }
+ }
+
+ public bool HasConstraints {
+ get { return (m_constraints == null) ? false : (m_constraints.Count > 0); }
+ }
+
+ public ConstraintCollection Constraints {
+ get {
+ if (m_constraints == null)
+ m_constraints = new ConstraintCollection (this);
+
+ return m_constraints;
+ }
+ }
+
+ public override IMetadataScope Scope {
+ get {
+ if (m_owner is TypeReference)
+ return ((TypeReference) m_owner).Scope;
+ if (m_owner is MethodReference)
+ return ((MethodReference) m_owner).DeclaringType.Scope;
+
+ throw new InvalidOperationException ();
+ }
+ }
+
+ public override ModuleDefinition Module {
+ get {
+ if (m_owner is TypeReference)
+ return ((TypeReference) m_owner).Module;
+ if (m_owner is MethodReference)
+ return ((MethodReference) m_owner).DeclaringType.Module;
+
+ throw new InvalidOperationException ();
+ }
+ }
+
+ public override string Name {
+ get {
+ if (m_name != null)
+ return m_name;
+
+ if (m_owner is TypeReference)
+ return string.Concat ("!", m_position.ToString ());
+ else if (m_owner is MethodReference)
+ return string.Concat ("!!", m_position.ToString ());
+ else
+ throw new InvalidOperationException ();
+ }
+ set { m_name = value; }
+ }
+
+ public override string Namespace {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string FullName {
+ get { return Name; }
+ }
+
+ #region GenericParameterAttributes
+
+ public bool IsNonVariant {
+ get { return (m_attributes & GenericParameterAttributes.VarianceMask) == GenericParameterAttributes.NonVariant; }
+ set {
+ if (value) {
+ m_attributes &= ~GenericParameterAttributes.VarianceMask;
+ m_attributes |= GenericParameterAttributes.NonVariant;
+ } else
+ m_attributes &= ~(GenericParameterAttributes.VarianceMask & GenericParameterAttributes.NonVariant);
+ }
+ }
+
+ public bool IsCovariant {
+ get { return (m_attributes & GenericParameterAttributes.VarianceMask) == GenericParameterAttributes.Covariant; }
+ set {
+ if (value) {
+ m_attributes &= ~GenericParameterAttributes.VarianceMask;
+ m_attributes |= GenericParameterAttributes.Covariant;
+ } else
+ m_attributes &= ~(GenericParameterAttributes.VarianceMask & GenericParameterAttributes.Covariant);
+ }
+ }
+
+ public bool IsContravariant {
+ get { return (m_attributes & GenericParameterAttributes.VarianceMask) == GenericParameterAttributes.Contravariant; }
+ set {
+ if (value) {
+ m_attributes &= ~GenericParameterAttributes.VarianceMask;
+ m_attributes |= GenericParameterAttributes.Contravariant;
+ } else
+ m_attributes &= ~(GenericParameterAttributes.VarianceMask & GenericParameterAttributes.Contravariant);
+ }
+ }
+
+ public bool HasReferenceTypeConstraint {
+ get { return (m_attributes & GenericParameterAttributes.ReferenceTypeConstraint) != 0; }
+ set {
+ if (value) {
+ m_attributes |= GenericParameterAttributes.ReferenceTypeConstraint;
+ } else
+ m_attributes &= ~GenericParameterAttributes.ReferenceTypeConstraint;
+ }
+ }
+
+ public bool HasNotNullableValueTypeConstraint {
+ get { return (m_attributes & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0; }
+ set {
+ if (value) {
+ m_attributes |= GenericParameterAttributes.NotNullableValueTypeConstraint;
+ } else
+ m_attributes &= ~GenericParameterAttributes.NotNullableValueTypeConstraint;
+ }
+ }
+
+ public bool HasDefaultConstructorConstraint {
+ get { return (m_attributes & GenericParameterAttributes.DefaultConstructorConstraint) != 0; }
+ set {
+ if (value) {
+ m_attributes |= GenericParameterAttributes.DefaultConstructorConstraint;
+ } else
+ m_attributes &= ~GenericParameterAttributes.DefaultConstructorConstraint;
+ }
+ }
+
+ #endregion
+
+ internal GenericParameter (int pos, IGenericParameterProvider owner) :
+ base (string.Empty, string.Empty)
+ {
+ m_position = pos;
+ m_owner = owner;
+ }
+
+ public GenericParameter (string name, IGenericParameterProvider owner) :
+ base (string.Empty, string.Empty)
+ {
+ m_name = name;
+ m_owner = owner;
+ }
+
+ public override TypeDefinition Resolve ()
+ {
+ return null;
+ }
+
+ internal static void CloneInto (IGenericParameterProvider old, IGenericParameterProvider np, ImportContext context)
+ {
+ foreach (GenericParameter gp in old.GenericParameters) {
+ GenericParameter ngp = Clone (gp, context);
+ np.GenericParameters.Add (ngp);
+ CloneConstraints (gp, ngp, context);
+ }
+ }
+
+ internal static GenericParameter Clone (GenericParameter gp, ImportContext context)
+ {
+ GenericParameter ngp;
+ if (gp.Owner is TypeReference)
+ ngp = new GenericParameter (gp.m_name, context.GenericContext.Type);
+ else if (gp.Owner is MethodReference)
+ ngp = new GenericParameter (gp.m_name, context.GenericContext.Method);
+ else
+ throw new NotSupportedException ();
+
+ ngp.Position = gp.Owner.GenericParameters.IndexOf (gp);
+ ngp.Attributes = gp.Attributes;
+
+ if (gp.HasCustomAttributes) {
+ foreach (CustomAttribute ca in gp.CustomAttributes)
+ ngp.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
+ }
+
+ return ngp;
+ }
+
+ static void CloneConstraints (GenericParameter gp, GenericParameter ngp, ImportContext context)
+ {
+ if (gp.HasConstraints) {
+ foreach (TypeReference constraint in gp.Constraints)
+ ngp.Constraints.Add (context.Import (constraint));
+ }
+ }
+ }
+}
--- /dev/null
+//
+// GenericParameterAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum GenericParameterAttributes : ushort {
+ VarianceMask = 0x0003,
+ NonVariant = 0x0000,
+ Covariant = 0x0001,
+ Contravariant = 0x0002,
+
+ SpecialConstraintMask = 0x001c,
+ ReferenceTypeConstraint = 0x0004,
+ NotNullableValueTypeConstraint = 0x0008,
+ DefaultConstructorConstraint = 0x0010
+ }
+}
--- /dev/null
+//
+// GenericParameterCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:53 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class GenericParameterCollection : CollectionBase, IReflectionVisitable {
+
+ IGenericParameterProvider m_container;
+
+ public GenericParameter this [int index] {
+ get { return List [index] as GenericParameter; }
+ set { List [index] = value; }
+ }
+
+ public IGenericParameterProvider Container {
+ get { return m_container; }
+ }
+
+ public GenericParameterCollection (IGenericParameterProvider container)
+ {
+ m_container = container;
+ }
+
+ public void Add (GenericParameter value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (GenericParameter value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (GenericParameter value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, GenericParameter value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (GenericParameter value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is GenericParameter))
+ throw new ArgumentException ("Must be of type " + typeof (GenericParameter).FullName);
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitGenericParameterCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// HashCodeProvider.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ internal sealed class HashCodeProvider : IHashCodeProvider {
+
+ public static readonly HashCodeProvider Instance = new HashCodeProvider ();
+
+ HashCodeProvider ()
+ {
+ }
+
+ public int GetHashCode (object o)
+ {
+ return o.GetHashCode ();
+ }
+ }
+}
--- /dev/null
+//
+// AssemblyDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@novell.com)
+//
+// (C) 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ internal interface IAnnotationProvider {
+
+ IDictionary Annotations { get; }
+ }
+}
--- /dev/null
+//
+// IAssemblyResolver.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IAssemblyResolver {
+
+ AssemblyDefinition Resolve (string fullName);
+ AssemblyDefinition Resolve (AssemblyNameReference name);
+ }
+}
--- /dev/null
+//
+// ICustomAttributeProvider.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Reflection;
+
+ internal interface ICustomAttributeProvider {
+
+ CustomAttributeCollection CustomAttributes { get; }
+
+ bool HasCustomAttributes { get; }
+ }
+}
--- /dev/null
+//
+// IDetailReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IDetailReader {
+
+ void ReadSemantic (EventDefinition evt);
+ void ReadSemantic (PropertyDefinition prop);
+
+ void ReadMarshalSpec (ParameterDefinition param);
+ void ReadMarshalSpec (FieldDefinition field);
+
+ void ReadLayout (TypeDefinition type);
+ void ReadLayout (FieldDefinition field);
+
+ void ReadConstant (FieldDefinition field);
+ void ReadConstant (PropertyDefinition prop);
+ void ReadConstant (ParameterDefinition param);
+
+ void ReadInitialValue (FieldDefinition field);
+ }
+}
--- /dev/null
+//
+// IGenericInstanceMethod.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IGenericInstance : IMetadataTokenProvider {
+
+ GenericArgumentCollection GenericArguments { get; }
+
+ bool HasGenericArguments { get; }
+ }
+}
--- /dev/null
+//
+// IGenericParameterProvider.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IGenericParameterProvider : IMetadataTokenProvider {
+
+ GenericParameterCollection GenericParameters { get; }
+
+ bool HasGenericParameters { get; }
+ }
+}
--- /dev/null
+//
+// IHasConstant.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IHasConstant : IMetadataTokenProvider {
+
+ bool HasConstant { get; }
+ object Constant { get; set; }
+ }
+}
--- /dev/null
+//
+// IHasMarshalSpec.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IHasMarshalSpec : IMetadataTokenProvider {
+
+ MarshalSpec MarshalSpec { get; set; }
+ }
+}
--- /dev/null
+//
+// IHasSecurity.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IHasSecurity : IMetadataTokenProvider {
+
+ SecurityDeclarationCollection SecurityDeclarations { get; }
+
+ bool HasSecurityDeclarations { get; }
+ }
+}
--- /dev/null
+//
+// IImporter.cs
+//
+// Author:
+// Jb Evain (jbevain@novell.com)
+//
+// (C) 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IImporter {
+
+ TypeReference ImportTypeReference (TypeReference type, ImportContext context);
+ FieldReference ImportFieldReference (FieldReference field, ImportContext context);
+ MethodReference ImportMethodReference (MethodReference method, ImportContext context);
+ }
+}
--- /dev/null
+//
+// IMemberDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IMemberDefinition : IMemberReference, ICustomAttributeProvider {
+
+ new TypeDefinition DeclaringType { get; set; }
+ bool IsSpecialName { get; set; }
+ bool IsRuntimeSpecialName { get; set; }
+ }
+}
--- /dev/null
+//
+// IMemberReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IMemberReference : IMetadataTokenProvider, IAnnotationProvider, IReflectionVisitable {
+
+ string Name { get; set; }
+ TypeReference DeclaringType { get; }
+ }
+}
--- /dev/null
+//
+// IMetadataScope.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IMetadataScope : IMetadataTokenProvider {
+ string Name { get; set; }
+ }
+}
--- /dev/null
+//
+// IMetadataTokenProvider.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using Mono.Cecil.Metadata;
+
+ internal interface IMetadataTokenProvider {
+
+ MetadataToken MetadataToken { get; set; }
+ }
+}
--- /dev/null
+//
+// IMethodSignature.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IMethodSignature {
+
+ bool HasParameters { get; }
+ bool HasThis { get; set; }
+ bool ExplicitThis { get; set; }
+ MethodCallingConvention CallingConvention { get; set; }
+
+ ParameterDefinitionCollection Parameters { get; }
+ MethodReturnType ReturnType { get; }
+
+ int GetSentinel ();
+ }
+}
--- /dev/null
+//
+// IReflectionStructureVisitable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IReflectionStructureVisitable {
+
+ void Accept (IReflectionStructureVisitor visitor);
+ }
+}
+
--- /dev/null
+//
+// IReflectionStructureVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IReflectionStructureVisitor {
+
+ void VisitAssemblyDefinition (AssemblyDefinition asm);
+ void VisitAssemblyNameDefinition (AssemblyNameDefinition name);
+ void VisitAssemblyNameReferenceCollection (AssemblyNameReferenceCollection names);
+ void VisitAssemblyNameReference (AssemblyNameReference name);
+ void VisitResourceCollection (ResourceCollection resources);
+ void VisitEmbeddedResource (EmbeddedResource res);
+ void VisitLinkedResource (LinkedResource res);
+ void VisitAssemblyLinkedResource (AssemblyLinkedResource res);
+ void VisitModuleDefinition (ModuleDefinition module);
+ void VisitModuleDefinitionCollection (ModuleDefinitionCollection modules);
+ void VisitModuleReference (ModuleReference module);
+ void VisitModuleReferenceCollection (ModuleReferenceCollection modules);
+
+ void TerminateAssemblyDefinition (AssemblyDefinition asm);
+ }
+}
+
--- /dev/null
+//
+// IReflectionVisitable.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IReflectionVisitable {
+
+ void Accept (IReflectionVisitor visitor);
+ }
+}
+
--- /dev/null
+//
+// IReflectionVisitor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IReflectionVisitor {
+
+ void VisitModuleDefinition (ModuleDefinition module);
+ void VisitTypeDefinitionCollection (TypeDefinitionCollection types);
+ void VisitTypeDefinition (TypeDefinition type);
+ void VisitTypeReferenceCollection (TypeReferenceCollection refs);
+ void VisitTypeReference (TypeReference type);
+ void VisitMemberReferenceCollection (MemberReferenceCollection members);
+ void VisitMemberReference (MemberReference member);
+ void VisitInterfaceCollection (InterfaceCollection interfaces);
+ void VisitInterface (TypeReference interf);
+ void VisitExternTypeCollection (ExternTypeCollection externs);
+ void VisitExternType (TypeReference externType);
+ void VisitOverrideCollection (OverrideCollection meth);
+ void VisitOverride (MethodReference ov);
+ void VisitNestedTypeCollection (NestedTypeCollection nestedTypes);
+ void VisitNestedType (TypeDefinition nestedType);
+ void VisitParameterDefinitionCollection (ParameterDefinitionCollection parameters);
+ void VisitParameterDefinition (ParameterDefinition parameter);
+ void VisitMethodDefinitionCollection (MethodDefinitionCollection methods);
+ void VisitMethodDefinition (MethodDefinition method);
+ void VisitConstructorCollection (ConstructorCollection ctors);
+ void VisitConstructor (MethodDefinition ctor);
+ void VisitPInvokeInfo (PInvokeInfo pinvk);
+ void VisitEventDefinitionCollection (EventDefinitionCollection events);
+ void VisitEventDefinition (EventDefinition evt);
+ void VisitFieldDefinitionCollection (FieldDefinitionCollection fields);
+ void VisitFieldDefinition (FieldDefinition field);
+ void VisitPropertyDefinitionCollection (PropertyDefinitionCollection properties);
+ void VisitPropertyDefinition (PropertyDefinition property);
+ void VisitSecurityDeclarationCollection (SecurityDeclarationCollection secDecls);
+ void VisitSecurityDeclaration (SecurityDeclaration secDecl);
+ void VisitCustomAttributeCollection (CustomAttributeCollection customAttrs);
+ void VisitCustomAttribute (CustomAttribute customAttr);
+ void VisitGenericParameterCollection (GenericParameterCollection genparams);
+ void VisitGenericParameter (GenericParameter genparam);
+ void VisitMarshalSpec (MarshalSpec marshalSpec);
+
+ void TerminateModuleDefinition (ModuleDefinition module);
+ }
+}
--- /dev/null
+//
+// IRequireResolving.cs
+//
+// Author:
+// Jb Evain <jbevain@gmail.com>
+//
+// Copyright (C) 2006 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal interface IRequireResolving {
+
+ byte [] Blob { get; }
+ bool Resolved { get; }
+ bool Resolve ();
+ }
+}
--- /dev/null
+//
+// ImportContext.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2006 Evaluant RC S.A.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal class ImportContext {
+
+ GenericContext m_genContext;
+ IImporter m_importer;
+
+ public GenericContext GenericContext {
+ get { return m_genContext; }
+ set { m_genContext = value; }
+ }
+
+ public ImportContext (IImporter importer)
+ {
+ m_genContext = new GenericContext ();
+ m_importer = importer;
+ }
+
+ public ImportContext (IImporter importer, IGenericParameterProvider provider)
+ {
+ m_importer = importer;
+ m_genContext = new GenericContext (provider);
+ }
+
+ public TypeReference Import (TypeReference type)
+ {
+ return m_importer.ImportTypeReference (type, this);
+ }
+
+ public MethodReference Import (MethodReference meth)
+ {
+ return m_importer.ImportMethodReference (meth, this);
+ }
+
+ public FieldReference Import (FieldReference field)
+ {
+ return m_importer.ImportFieldReference (field, this);
+ }
+ }
+}
--- /dev/null
+//
+// InterfaceCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:52 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class InterfaceCollection : CollectionBase, IReflectionVisitable {
+
+ TypeDefinition m_container;
+
+ public TypeReference this [int index] {
+ get { return List [index] as TypeReference; }
+ set { List [index] = value; }
+ }
+
+ public TypeDefinition Container {
+ get { return m_container; }
+ }
+
+ public InterfaceCollection (TypeDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (TypeReference value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (TypeReference value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (TypeReference value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, TypeReference value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (TypeReference value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is TypeReference))
+ throw new ArgumentException ("Must be of type " + typeof (TypeReference).FullName);
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitInterfaceCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// LinkedResource.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class LinkedResource : Resource {
+
+ byte [] m_hash;
+ string m_file;
+
+ public byte [] Hash {
+ get { return m_hash; }
+ set { m_hash = value; }
+ }
+
+ public string File {
+ get { return m_file; }
+ set { m_file = value; }
+ }
+
+ public LinkedResource (string name, ManifestResourceAttributes flags, string file) :
+ base (name, flags)
+ {
+ m_file = file;
+ }
+
+ public override void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitLinkedResource (this);
+ }
+ }
+}
--- /dev/null
+//
+// ManigestResourceAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum ManifestResourceAttributes {
+ VisibilityMask = 0x0007,
+ Public = 0x0001, // The resource is exported from the Assembly
+ Private = 0x0002 // The resource is private to the Assembly
+ }
+}
--- /dev/null
+//
+// MarshalDesc.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ internal class MarshalSpec {
+
+ NativeType m_natIntr;
+ IHasMarshalSpec m_container;
+
+ public NativeType NativeIntrinsic {
+ get { return m_natIntr; }
+ set { m_natIntr = value; }
+ }
+
+ public IHasMarshalSpec Container {
+ get { return m_container; }
+ set { m_container = value; }
+ }
+
+ public MarshalSpec (NativeType natIntr, IHasMarshalSpec container)
+ {
+ m_natIntr = natIntr;
+ m_container = container;
+ }
+
+ public virtual void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitMarshalSpec (this);
+ }
+
+ public virtual MarshalSpec CloneInto (IHasMarshalSpec container)
+ {
+ return new MarshalSpec (m_natIntr, container);
+ }
+ }
+
+ internal sealed class ArrayMarshalSpec : MarshalSpec {
+
+ NativeType m_elemType;
+ int m_paramNum;
+ int m_elemMult;
+ int m_numElem;
+
+ public NativeType ElemType {
+ get { return m_elemType; }
+ set { m_elemType = value; }
+ }
+
+ public int ParamNum {
+ get { return m_paramNum; }
+ set { m_paramNum = value; }
+ }
+
+ public int ElemMult {
+ get { return m_elemMult; }
+ set { m_elemMult = value; }
+ }
+
+ public int NumElem {
+ get { return m_numElem; }
+ set { m_numElem = value; }
+ }
+
+ public ArrayMarshalSpec (IHasMarshalSpec container) : base (NativeType.ARRAY, container)
+ {
+ }
+
+ public override MarshalSpec CloneInto (IHasMarshalSpec container)
+ {
+ ArrayMarshalSpec spec = new ArrayMarshalSpec (container);
+ spec.m_elemType = m_elemType;
+ spec.m_paramNum = m_paramNum;
+ spec.m_elemMult = m_elemMult;
+ spec.m_numElem = m_numElem;
+ return spec;
+ }
+ }
+
+ internal sealed class CustomMarshalerSpec : MarshalSpec {
+
+ Guid m_guid;
+ string m_unmanagedType;
+ string m_managedType;
+ string m_cookie;
+
+ public Guid Guid {
+ get { return m_guid; }
+ set { m_guid = value; }
+ }
+
+ public String UnmanagedType {
+ get { return m_unmanagedType; }
+ set { m_unmanagedType = value; }
+ }
+
+ public string ManagedType {
+ get { return m_managedType; }
+ set { m_managedType = value; }
+ }
+
+ public string Cookie {
+ get { return m_cookie; }
+ set { m_cookie = value; }
+ }
+
+ public CustomMarshalerSpec (IHasMarshalSpec container) : base (NativeType.CUSTOMMARSHALER, container)
+ {
+ }
+
+ public override MarshalSpec CloneInto (IHasMarshalSpec container)
+ {
+ CustomMarshalerSpec spec = new CustomMarshalerSpec (container);
+ spec.m_guid = m_guid;
+ spec.m_unmanagedType = m_unmanagedType;
+ spec.m_managedType = m_managedType;
+ spec.m_cookie = m_cookie;
+ return spec;
+ }
+ }
+
+ internal sealed class SafeArraySpec : MarshalSpec {
+
+ private VariantType m_elemType;
+
+ public VariantType ElemType {
+ get { return m_elemType; }
+ set { m_elemType = value; }
+ }
+
+ public SafeArraySpec (IHasMarshalSpec container) : base (NativeType.SAFEARRAY, container)
+ {
+ }
+
+ public override MarshalSpec CloneInto(IHasMarshalSpec container)
+ {
+ SafeArraySpec spec = new SafeArraySpec (container);
+ spec.m_elemType = m_elemType;
+ return spec;
+ }
+ }
+
+ internal sealed class FixedArraySpec : MarshalSpec {
+
+ private int m_numElem;
+ private NativeType m_elemType;
+
+ public int NumElem {
+ get { return m_numElem; }
+ set { m_numElem = value; }
+ }
+
+ public NativeType ElemType {
+ get { return m_elemType; }
+ set { m_elemType = value; }
+ }
+
+ public FixedArraySpec (IHasMarshalSpec container) : base (NativeType.FIXEDARRAY, container)
+ {
+ }
+
+ public override MarshalSpec CloneInto (IHasMarshalSpec container)
+ {
+ FixedArraySpec spec = new FixedArraySpec (container);
+ spec.m_numElem = m_numElem;
+ spec.m_elemType = m_elemType;
+ return spec;
+ }
+ }
+
+ internal sealed class FixedSysStringSpec : MarshalSpec {
+
+ private int m_size;
+
+ public int Size {
+ get { return m_size; }
+ set { m_size = value; }
+ }
+
+ public FixedSysStringSpec (IHasMarshalSpec container) : base (NativeType.FIXEDSYSSTRING, container)
+ {
+ }
+
+ public override MarshalSpec CloneInto (IHasMarshalSpec container)
+ {
+ FixedSysStringSpec spec = new FixedSysStringSpec (container);
+ spec.m_size = m_size;
+ return spec;
+ }
+ }
+}
--- /dev/null
+//
+// MemberReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ using Mono.Cecil.Metadata;
+
+ internal abstract class MemberReference : IMemberReference {
+
+ string m_name;
+ TypeReference m_decType;
+ MetadataToken m_token;
+ IDictionary m_annotations;
+
+ public virtual string Name {
+ get { return m_name; }
+ set { m_name = value; }
+ }
+
+ public virtual TypeReference DeclaringType {
+ get { return m_decType; }
+ set { m_decType = value; }
+ }
+
+ public MetadataToken MetadataToken {
+ get { return m_token; }
+ set { m_token = value; }
+ }
+
+ IDictionary IAnnotationProvider.Annotations {
+ get {
+ if (m_annotations == null)
+ m_annotations = new Hashtable ();
+ return m_annotations;
+ }
+ }
+
+ public MemberReference (string name)
+ {
+ m_name = name;
+ }
+
+ public override string ToString ()
+ {
+ if (m_decType == null)
+ return m_name;
+
+ return string.Concat (m_decType.FullName, "::", m_name);
+ }
+
+ public virtual void Accept (IReflectionVisitor visitor)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// MemberReferenceCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:53 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class MemberReferenceCollection : CollectionBase, IReflectionVisitable {
+
+ ModuleDefinition m_container;
+
+ public MemberReference this [int index] {
+ get { return List [index] as MemberReference; }
+ set { List [index] = value; }
+ }
+
+ public ModuleDefinition Container {
+ get { return m_container; }
+ }
+
+ public MemberReferenceCollection (ModuleDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (MemberReference value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (MemberReference value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (MemberReference value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, MemberReference value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (MemberReference value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is MemberReference))
+ throw new ArgumentException ("Must be of type " + typeof (MemberReference).FullName);
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitMemberReferenceCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// MetadataResolver.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2008 Jb Evain (http://evain.net)
+// (C) 2008 Novell, Inc. (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+
+namespace Mono.Cecil {
+
+ class MetadataResolver {
+
+ AssemblyDefinition assembly;
+
+ public IAssemblyResolver AssemblyResolver {
+ get { return assembly.Resolver; }
+ }
+
+ public MetadataResolver (AssemblyDefinition assembly)
+ {
+ this.assembly = assembly;
+ }
+
+ public TypeDefinition Resolve (TypeReference type)
+ {
+ type = type.GetOriginalType ();
+
+ if (type is TypeDefinition)
+ return (TypeDefinition) type;
+
+ AssemblyNameReference reference = type.Scope as AssemblyNameReference;
+ if (reference != null) {
+ AssemblyDefinition assembly = AssemblyResolver.Resolve (reference);
+ if (assembly == null)
+ return null;
+
+ return assembly.MainModule.Types [type.FullName];
+ }
+
+ ModuleDefinition module = type.Scope as ModuleDefinition;
+ if (module != null)
+ return module.Types [type.FullName];
+
+ ModuleReference mod_reference = type.Scope as ModuleReference;
+ if (mod_reference != null) {
+ foreach (ModuleDefinition netmodule in type.Module.Assembly.Modules)
+ if (netmodule.Name == mod_reference.Name)
+ return netmodule.Types [type.FullName];
+ }
+
+ throw new NotImplementedException ();
+ }
+
+ public FieldDefinition Resolve (FieldReference field)
+ {
+ TypeDefinition type = Resolve (field.DeclaringType);
+ if (type == null)
+ return null;
+
+ return type.HasFields ? GetField (type.Fields, field) : null;
+ }
+
+ static FieldDefinition GetField (ICollection collection, FieldReference reference)
+ {
+ foreach (FieldDefinition field in collection) {
+ if (field.Name != reference.Name)
+ continue;
+
+ if (!AreSame (field.FieldType, reference.FieldType))
+ continue;
+
+ return field;
+ }
+
+ return null;
+ }
+
+ public MethodDefinition Resolve (MethodReference method)
+ {
+ TypeDefinition type = Resolve (method.DeclaringType);
+ if (type == null)
+ return null;
+
+ method = method.GetOriginalMethod ();
+ if (method.Name == MethodDefinition.Cctor || method.Name == MethodDefinition.Ctor)
+ return type.HasConstructors ? GetMethod (type.Constructors, method) : null;
+ else
+ return type.HasMethods ? GetMethod (type, method) : null;
+ }
+
+ MethodDefinition GetMethod (TypeDefinition type, MethodReference reference)
+ {
+ while (type != null) {
+ MethodDefinition method = GetMethod (type.Methods, reference);
+ if (method == null) {
+ if (type.BaseType == null)
+ return null;
+
+ type = Resolve (type.BaseType);
+ } else
+ return method;
+ }
+
+ return null;
+ }
+
+ static MethodDefinition GetMethod (ICollection collection, MethodReference reference)
+ {
+ foreach (MethodDefinition meth in collection) {
+ if (meth.Name != reference.Name)
+ continue;
+
+ if (!AreSame (meth.ReturnType.ReturnType, reference.ReturnType.ReturnType))
+ continue;
+
+ if (meth.HasParameters != reference.HasParameters)
+ continue;
+
+ if (!meth.HasParameters && !reference.HasParameters)
+ return meth; //both have no parameters hence meth is the good one
+
+ if (!AreSame (meth.Parameters, reference.Parameters))
+ continue;
+
+ return meth;
+ }
+
+ return null;
+ }
+
+ static bool AreSame (ParameterDefinitionCollection a, ParameterDefinitionCollection b)
+ {
+ if (a.Count != b.Count)
+ return false;
+
+ if (a.Count == 0)
+ return true;
+
+ for (int i = 0; i < a.Count; i++)
+ if (!AreSame (a [i].ParameterType, b [i].ParameterType))
+ return false;
+
+ return true;
+ }
+
+ static bool AreSame (ModType a, ModType b)
+ {
+ if (!AreSame (a.ModifierType, b.ModifierType))
+ return false;
+
+ return AreSame (a.ElementType, b.ElementType);
+ }
+
+ static bool AreSame (TypeSpecification a, TypeSpecification b)
+ {
+ if (a is GenericInstanceType)
+ return AreSame ((GenericInstanceType) a, (GenericInstanceType) b);
+
+ if (a is ModType)
+ return AreSame ((ModType) a, (ModType) b);
+
+ return AreSame (a.ElementType, b.ElementType);
+ }
+
+ static bool AreSame (GenericInstanceType a, GenericInstanceType b)
+ {
+ if (!AreSame (a.ElementType, b.ElementType))
+ return false;
+
+ if (a.GenericArguments.Count != b.GenericArguments.Count)
+ return false;
+
+ if (a.GenericArguments.Count == 0)
+ return true;
+
+ for (int i = 0; i < a.GenericArguments.Count; i++)
+ if (!AreSame (a.GenericArguments [i], b.GenericArguments [i]))
+ return false;
+
+ return true;
+ }
+
+ static bool AreSame (GenericParameter a, GenericParameter b)
+ {
+ return a.Position == b.Position;
+ }
+
+ static bool AreSame (TypeReference a, TypeReference b)
+ {
+ if (a is TypeSpecification || b is TypeSpecification) {
+ if (a.GetType () != b.GetType ())
+ return false;
+
+ return AreSame ((TypeSpecification) a, (TypeSpecification) b);
+ }
+
+ if (a is GenericParameter || b is GenericParameter) {
+ if (a.GetType () != b.GetType ())
+ return false;
+
+ return AreSame ((GenericParameter) a, (GenericParameter) b);
+ }
+
+ return a.FullName == b.FullName;
+ }
+ }
+}
--- /dev/null
+//
+// MethodAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum MethodAttributes : ushort {
+ MemberAccessMask = 0x0007,
+ Compilercontrolled = 0x0000, // Member not referenceable
+ Private = 0x0001, // Accessible only by the parent type
+ FamANDAssem = 0x0002, // Accessible by sub-types only in this Assembly
+ Assem = 0x0003, // Accessibly by anyone in the Assembly
+ Family = 0x0004, // Accessible only by type and sub-types
+ FamORAssem = 0x0005, // Accessibly by sub-types anywhere, plus anyone in assembly
+ Public = 0x0006, // Accessibly by anyone who has visibility to this scope
+
+ Static = 0x0010, // Defined on type, else per instance
+ Final = 0x0020, // Method may not be overridden
+ Virtual = 0x0040, // Method is virtual
+ HideBySig = 0x0080, // Method hides by name+sig, else just by name
+
+ VtableLayoutMask = 0x0100, // Use this mask to retrieve vtable attributes
+ ReuseSlot = 0x0000, // Method reuses existing slot in vtable
+ NewSlot = 0x0100, // Method always gets a new slot in the vtable
+
+ Strict = 0x0200, // Method can only be overriden if also accessible
+ Abstract = 0x0400, // Method does not provide an implementation
+ SpecialName = 0x0800, // Method is special
+
+ // Interop Attributes
+ PInvokeImpl = 0x2000, // Implementation is forwarded through PInvoke
+ UnmanagedExport = 0x0008, // Reserved: shall be zero for conforming implementations
+
+ // Additional flags
+ RTSpecialName = 0x1000, // CLI provides 'special' behavior, depending upon the name of the method
+ HasSecurity = 0x4000, // Method has security associate with it
+ RequireSecObject = 0x8000 // Method calls another method containing security code
+ }
+}
--- /dev/null
+//
+// MethodCallingConvention.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal enum MethodCallingConvention : byte {
+ Default = 0x0,
+ C = 0x1,
+ StdCall = 0x2,
+ ThisCall = 0x3,
+ FastCall = 0x4,
+ VarArg = 0x5,
+ Generic = 0x10
+ }
+}
--- /dev/null
+//
+// MethodDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using Mono.Cecil.Binary;
+ using Mono.Cecil.Cil;
+
+ internal sealed class MethodDefinition : MethodReference, IMemberDefinition,
+ IHasSecurity, ICustomAttributeProvider {
+
+ public const string Cctor = ".cctor";
+ public const string Ctor = ".ctor";
+
+ MethodAttributes m_attributes;
+ MethodImplAttributes m_implAttrs;
+ MethodSemanticsAttributes m_semAttrs;
+ SecurityDeclarationCollection m_secDecls;
+ CustomAttributeCollection m_customAttrs;
+
+ MethodBody m_body;
+ RVA m_rva;
+ OverrideCollection m_overrides;
+ PInvokeInfo m_pinvoke;
+ readonly ParameterDefinition m_this;
+
+ public MethodAttributes Attributes {
+ get { return m_attributes; }
+ set { m_attributes = value; }
+ }
+
+ public MethodImplAttributes ImplAttributes {
+ get { return m_implAttrs; }
+ set { m_implAttrs = value; }
+ }
+
+ public MethodSemanticsAttributes SemanticsAttributes {
+ get { return m_semAttrs; }
+ set { m_semAttrs = value; }
+ }
+
+ public bool HasSecurityDeclarations {
+ get { return (m_secDecls == null) ? false : (m_secDecls.Count > 0); }
+ }
+
+ public SecurityDeclarationCollection SecurityDeclarations {
+ get {
+ if (m_secDecls == null)
+ m_secDecls = new SecurityDeclarationCollection (this);
+
+ return m_secDecls;
+ }
+ }
+
+ public bool HasCustomAttributes {
+ get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
+ }
+
+ public CustomAttributeCollection CustomAttributes {
+ get {
+ if (m_customAttrs == null)
+ m_customAttrs = new CustomAttributeCollection (this);
+
+ return m_customAttrs;
+ }
+ }
+
+ public RVA RVA {
+ get { return m_rva; }
+ set { m_rva = value; }
+ }
+
+ public MethodBody Body {
+ get {
+ LoadBody ();
+ return m_body;
+ }
+ set { m_body = value; }
+ }
+
+ public PInvokeInfo PInvokeInfo {
+ get { return m_pinvoke; }
+ set { m_pinvoke = value; }
+ }
+
+ public bool HasOverrides {
+ get { return (m_overrides == null) ? false : (m_overrides.Count > 0); }
+ }
+
+ public OverrideCollection Overrides {
+ get {
+ if (m_overrides == null)
+ m_overrides = new OverrideCollection (this);
+
+ return m_overrides;
+ }
+ }
+
+ public ParameterDefinition This {
+ get { return m_this; }
+ }
+
+ #region MethodAttributes
+
+ public bool IsCompilerControlled {
+ get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Compilercontrolled; }
+ set {
+ if (value) {
+ m_attributes &= ~MethodAttributes.MemberAccessMask;
+ m_attributes |= MethodAttributes.Compilercontrolled;
+ } else
+ m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Compilercontrolled);
+ }
+ }
+
+ public bool IsPrivate {
+ get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private; }
+ set {
+ if (value) {
+ m_attributes &= ~MethodAttributes.MemberAccessMask;
+ m_attributes |= MethodAttributes.Private;
+ } else
+ m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Private);
+ }
+ }
+
+ public bool IsFamilyAndAssembly {
+ get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem; }
+ set {
+ if (value) {
+ m_attributes &= ~MethodAttributes.MemberAccessMask;
+ m_attributes |= MethodAttributes.FamANDAssem;
+ } else
+ m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.FamANDAssem);
+ }
+ }
+
+ public bool IsAssembly {
+ get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assem; }
+ set {
+ if (value) {
+ m_attributes &= ~MethodAttributes.MemberAccessMask;
+ m_attributes |= MethodAttributes.Assem;
+ } else
+ m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Assem);
+ }
+ }
+
+ public bool IsFamily {
+ get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family; }
+ set {
+ if (value) {
+ m_attributes &= ~MethodAttributes.MemberAccessMask;
+ m_attributes |= MethodAttributes.Family;
+ } else
+ m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Family);
+ }
+ }
+
+ public bool IsFamilyOrAssembly {
+ get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem; }
+ set {
+ if (value) {
+ m_attributes &= ~MethodAttributes.MemberAccessMask;
+ m_attributes |= MethodAttributes.FamORAssem;
+ } else
+ m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.FamORAssem);
+ }
+ }
+
+ public bool IsPublic {
+ get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public; }
+ set {
+ if (value) {
+ m_attributes &= ~MethodAttributes.MemberAccessMask;
+ m_attributes |= MethodAttributes.Public;
+ } else
+ m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Public);
+ }
+ }
+
+ public bool IsStatic {
+ get { return (m_attributes & MethodAttributes.Static) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.Static;
+ else
+ m_attributes &= ~MethodAttributes.Static;
+ }
+ }
+
+ public bool IsFinal {
+ get { return (m_attributes & MethodAttributes.Final) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.Final;
+ else
+ m_attributes &= ~MethodAttributes.Final;
+ }
+ }
+
+ public bool IsVirtual {
+ get { return (m_attributes & MethodAttributes.Virtual) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.Virtual;
+ else
+ m_attributes &= ~MethodAttributes.Virtual;
+ }
+ }
+
+ public bool IsHideBySig {
+ get { return (m_attributes & MethodAttributes.HideBySig) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.HideBySig;
+ else
+ m_attributes &= ~MethodAttributes.HideBySig;
+ }
+ }
+
+ public bool IsReuseSlot {
+ get { return (m_attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.ReuseSlot; }
+ set {
+ if (value) {
+ m_attributes &= ~MethodAttributes.VtableLayoutMask;
+ m_attributes |= MethodAttributes.ReuseSlot;
+ } else
+ m_attributes &= ~(MethodAttributes.VtableLayoutMask & MethodAttributes.ReuseSlot);
+ }
+ }
+
+ public bool IsNewSlot {
+ get { return (m_attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot; }
+ set {
+ if (value) {
+ m_attributes &= ~MethodAttributes.VtableLayoutMask;
+ m_attributes |= MethodAttributes.NewSlot;
+ } else
+ m_attributes &= ~(MethodAttributes.VtableLayoutMask & MethodAttributes.NewSlot);
+ }
+ }
+
+ public bool IsStrict {
+ get { return (m_attributes & MethodAttributes.Strict) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.Strict;
+ else
+ m_attributes &= ~MethodAttributes.Strict;
+ }
+ }
+
+ public bool IsAbstract {
+ get { return (m_attributes & MethodAttributes.Abstract) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.Abstract;
+ else
+ m_attributes &= ~MethodAttributes.Abstract;
+ }
+ }
+
+ public bool IsSpecialName {
+ get { return (m_attributes & MethodAttributes.SpecialName) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.SpecialName;
+ else
+ m_attributes &= ~MethodAttributes.SpecialName;
+ }
+ }
+
+ public bool IsPInvokeImpl {
+ get { return (m_attributes & MethodAttributes.PInvokeImpl) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.PInvokeImpl;
+ else
+ m_attributes &= ~MethodAttributes.PInvokeImpl;
+ }
+ }
+
+ public bool IsUnmanagedExport {
+ get { return (m_attributes & MethodAttributes.UnmanagedExport) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.UnmanagedExport;
+ else
+ m_attributes &= ~MethodAttributes.UnmanagedExport;
+ }
+ }
+
+ public bool IsRuntimeSpecialName {
+ get { return (m_attributes & MethodAttributes.RTSpecialName) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.RTSpecialName;
+ else
+ m_attributes &= ~MethodAttributes.RTSpecialName;
+ }
+ }
+
+ public bool HasSecurity {
+ get { return (m_attributes & MethodAttributes.HasSecurity) != 0; }
+ set {
+ if (value)
+ m_attributes |= MethodAttributes.HasSecurity;
+ else
+ m_attributes &= ~MethodAttributes.HasSecurity;
+ }
+ }
+
+ #endregion
+
+ #region MethodImplAttributes
+
+ public bool IsIL {
+ get { return (m_implAttrs & MethodImplAttributes.CodeTypeMask) == MethodImplAttributes.IL; }
+ set {
+ if (value) {
+ m_implAttrs &= ~MethodImplAttributes.CodeTypeMask;
+ m_implAttrs |= MethodImplAttributes.IL;
+ } else
+ m_implAttrs &= ~(MethodImplAttributes.CodeTypeMask & MethodImplAttributes.IL);
+ }
+ }
+
+ public bool IsNative {
+ get { return (m_implAttrs & MethodImplAttributes.CodeTypeMask) == MethodImplAttributes.Native; }
+ set {
+ if (value) {
+ m_implAttrs &= ~MethodImplAttributes.CodeTypeMask;
+ m_implAttrs |= MethodImplAttributes.Native;
+ } else
+ m_implAttrs &= ~(MethodImplAttributes.CodeTypeMask & MethodImplAttributes.Native);
+ }
+ }
+
+ public bool IsRuntime {
+ get { return (m_implAttrs & MethodImplAttributes.CodeTypeMask) == MethodImplAttributes.Runtime; }
+ set {
+ if (value) {
+ m_implAttrs &= ~MethodImplAttributes.CodeTypeMask;
+ m_implAttrs |= MethodImplAttributes.Runtime;
+ } else
+ m_implAttrs &= ~(MethodImplAttributes.CodeTypeMask & MethodImplAttributes.Runtime);
+ }
+ }
+
+ public bool IsUnmanaged {
+ get { return (m_implAttrs & MethodImplAttributes.ManagedMask) == MethodImplAttributes.Unmanaged; }
+ set {
+ if (value) {
+ m_implAttrs &= ~MethodImplAttributes.ManagedMask;
+ m_implAttrs |= MethodImplAttributes.Unmanaged;
+ } else
+ m_implAttrs &= ~(MethodImplAttributes.ManagedMask & MethodImplAttributes.Unmanaged);
+ }
+ }
+
+ public bool IsManaged {
+ get { return (m_implAttrs & MethodImplAttributes.ManagedMask) == MethodImplAttributes.Managed; }
+ set {
+ if (value) {
+ m_implAttrs &= ~MethodImplAttributes.ManagedMask;
+ m_implAttrs |= MethodImplAttributes.Managed;
+ } else
+ m_implAttrs &= ~(MethodImplAttributes.ManagedMask & MethodImplAttributes.Managed);
+ }
+ }
+
+ public bool IsForwardRef {
+ get { return (m_implAttrs & MethodImplAttributes.ForwardRef) != 0; }
+ set {
+ if (value)
+ m_implAttrs |= MethodImplAttributes.ForwardRef;
+ else
+ m_implAttrs &= ~MethodImplAttributes.ForwardRef;
+ }
+ }
+
+ public bool IsPreserveSig {
+ get { return (m_implAttrs & MethodImplAttributes.PreserveSig) != 0; }
+ set {
+ if (value)
+ m_implAttrs |= MethodImplAttributes.PreserveSig;
+ else
+ m_implAttrs &= ~MethodImplAttributes.PreserveSig;
+ }
+ }
+
+ public bool IsInternalCall {
+ get { return (m_implAttrs & MethodImplAttributes.InternalCall) != 0; }
+ set {
+ if (value)
+ m_implAttrs |= MethodImplAttributes.InternalCall;
+ else
+ m_implAttrs &= ~MethodImplAttributes.InternalCall;
+ }
+ }
+
+ public bool IsSynchronized {
+ get { return (m_implAttrs & MethodImplAttributes.Synchronized) != 0; }
+ set {
+ if (value)
+ m_implAttrs |= MethodImplAttributes.Synchronized;
+ else
+ m_implAttrs &= ~MethodImplAttributes.Synchronized;
+ }
+ }
+
+ public bool NoInlining {
+ get { return (m_implAttrs & MethodImplAttributes.NoInlining) != 0; }
+ set {
+ if (value)
+ m_implAttrs |= MethodImplAttributes.NoInlining;
+ else
+ m_implAttrs &= ~MethodImplAttributes.NoInlining;
+ }
+ }
+
+ #endregion
+
+ #region MethodSemanticsAttributes
+ public bool IsSetter {
+ get { return (m_semAttrs & MethodSemanticsAttributes.Setter) != 0; }
+ set {
+ if (value)
+ m_semAttrs |= MethodSemanticsAttributes.Setter;
+ else
+ m_semAttrs &= ~MethodSemanticsAttributes.Setter;
+ }
+ }
+
+ public bool IsGetter {
+ get { return (m_semAttrs & MethodSemanticsAttributes.Getter) != 0; }
+ set {
+ if (value)
+ m_semAttrs |= MethodSemanticsAttributes.Getter;
+ else
+ m_semAttrs &= ~MethodSemanticsAttributes.Getter;
+ }
+ }
+
+ public bool IsOther {
+ get { return (m_semAttrs & MethodSemanticsAttributes.Other) != 0; }
+ set {
+ if (value)
+ m_semAttrs |= MethodSemanticsAttributes.Other;
+ else
+ m_semAttrs &= ~MethodSemanticsAttributes.Other;
+ }
+ }
+
+ public bool IsAddOn {
+ get { return (m_semAttrs & MethodSemanticsAttributes.AddOn) != 0; }
+ set {
+ if (value)
+ m_semAttrs |= MethodSemanticsAttributes.AddOn;
+ else
+ m_semAttrs &= ~MethodSemanticsAttributes.AddOn;
+ }
+ }
+
+ public bool IsRemoveOn {
+ get { return (m_semAttrs & MethodSemanticsAttributes.RemoveOn) != 0; }
+ set {
+ if (value)
+ m_semAttrs |= MethodSemanticsAttributes.RemoveOn;
+ else
+ m_semAttrs &= ~MethodSemanticsAttributes.RemoveOn;
+ }
+ }
+
+ public bool IsFire {
+ get { return (m_semAttrs & MethodSemanticsAttributes.Fire) != 0; }
+ set {
+ if (value)
+ m_semAttrs |= MethodSemanticsAttributes.Fire;
+ else
+ m_semAttrs &= ~MethodSemanticsAttributes.Fire;
+ }
+ }
+
+ #endregion
+
+ public bool IsConstructor {
+ get {
+ return this.IsRuntimeSpecialName && this.IsSpecialName &&
+ (this.Name == Cctor || this.Name == Ctor);
+ }
+ }
+
+ public bool HasBody {
+ get {
+ return (m_attributes & MethodAttributes.Abstract) == 0 &&
+ (m_attributes & MethodAttributes.PInvokeImpl) == 0 &&
+ (m_implAttrs & MethodImplAttributes.InternalCall) == 0 &&
+ (m_implAttrs & MethodImplAttributes.Native) == 0 &&
+ (m_implAttrs & MethodImplAttributes.Unmanaged) == 0 &&
+ (m_implAttrs & MethodImplAttributes.Runtime) == 0;
+ }
+ }
+
+ public new TypeDefinition DeclaringType {
+ get { return (TypeDefinition) base.DeclaringType; }
+ set { base.DeclaringType = value; }
+ }
+
+ public MethodDefinition (string name, RVA rva,
+ MethodAttributes attrs, MethodImplAttributes implAttrs,
+ bool hasThis, bool explicitThis, MethodCallingConvention callConv) :
+ base (name, hasThis, explicitThis, callConv)
+ {
+ m_rva = rva;
+ m_attributes = attrs;
+ m_implAttrs = implAttrs;
+
+ if (!IsStatic)
+ m_this = new ParameterDefinition ("this", 0, (ParameterAttributes) 0, null);
+ }
+
+ internal MethodDefinition (string name, MethodAttributes attrs) : base (name)
+ {
+ m_attributes = attrs;
+
+ this.HasThis = !this.IsStatic;
+ if (!IsStatic)
+ m_this = new ParameterDefinition ("this", 0, (ParameterAttributes) 0, null);
+ }
+
+ public MethodDefinition (string name, MethodAttributes attrs, TypeReference returnType) :
+ this (name, attrs)
+ {
+ this.ReturnType.ReturnType = returnType;
+ }
+
+ internal void LoadBody ()
+ {
+ if (m_body == null && this.HasBody) {
+ m_body = new MethodBody (this);
+
+ ModuleDefinition module = DeclaringType != null ? DeclaringType.Module : null;
+
+ if (module != null && m_rva != RVA.Zero)
+ module.Controller.Reader.Code.VisitMethodBody (m_body);
+ }
+ }
+
+ public override MethodDefinition Resolve ()
+ {
+ return this;
+ }
+
+ public MethodDefinition Clone ()
+ {
+ return Clone (this, new ImportContext (NullReferenceImporter.Instance, this));
+ }
+
+ internal static MethodDefinition Clone (MethodDefinition meth, ImportContext context)
+ {
+ MethodDefinition nm = new MethodDefinition (
+ meth.Name,
+ RVA.Zero,
+ meth.Attributes,
+ meth.ImplAttributes,
+ meth.HasThis,
+ meth.ExplicitThis,
+ meth.CallingConvention);
+
+ MethodReference contextMethod = context.GenericContext.Method;
+
+ context.GenericContext.Method = nm;
+
+ GenericParameter.CloneInto (meth, nm, context);
+
+ nm.ReturnType.ReturnType = context.Import (meth.ReturnType.ReturnType);
+
+ if (meth.ReturnType.Parameter != null) {
+ nm.ReturnType.Parameter = ParameterDefinition.Clone (meth.ReturnType.Parameter, context);
+ nm.ReturnType.Parameter.Method = nm;
+ }
+
+ if (meth.PInvokeInfo != null)
+ nm.PInvokeInfo = meth.PInvokeInfo; // TODO: import module ?
+
+ if (meth.HasParameters) {
+ foreach (ParameterDefinition param in meth.Parameters)
+ nm.Parameters.Add (ParameterDefinition.Clone (param, context));
+ }
+ if (meth.HasOverrides) {
+ foreach (MethodReference ov in meth.Overrides)
+ nm.Overrides.Add (context.Import (ov));
+ }
+ if (meth.HasCustomAttributes) {
+ foreach (CustomAttribute ca in meth.CustomAttributes)
+ nm.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
+ }
+ if (meth.HasSecurityDeclarations) {
+ foreach (SecurityDeclaration sec in meth.SecurityDeclarations)
+ nm.SecurityDeclarations.Add (SecurityDeclaration.Clone (sec));
+ }
+
+ if (meth.Body != null)
+ nm.Body = MethodBody.Clone (meth.Body, nm, context);
+
+ context.GenericContext.Method = contextMethod;
+
+ return nm;
+ }
+
+ public override void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitMethodDefinition (this);
+
+ this.GenericParameters.Accept (visitor);
+ this.Parameters.Accept (visitor);
+
+ if (this.PInvokeInfo != null)
+ this.PInvokeInfo.Accept (visitor);
+
+ this.SecurityDeclarations.Accept (visitor);
+ this.Overrides.Accept (visitor);
+ this.CustomAttributes.Accept (visitor);
+ }
+ }
+}
--- /dev/null
+//
+// MethodDefinitionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Mar 30 18:43:56 +0200 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class MethodDefinitionCollection : CollectionBase, IReflectionVisitable {
+
+ TypeDefinition m_container;
+
+ public MethodDefinition this [int index] {
+ get { return List [index] as MethodDefinition; }
+ set { List [index] = value; }
+ }
+
+ public TypeDefinition Container {
+ get { return m_container; }
+ }
+
+ public MethodDefinitionCollection (TypeDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (MethodDefinition value)
+ {
+ Attach (value);
+
+ List.Add (value);
+ }
+
+
+ public new void Clear ()
+ {
+ foreach (MethodDefinition item in this)
+ Detach (item);
+
+ base.Clear ();
+ }
+
+ public bool Contains (MethodDefinition value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (MethodDefinition value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, MethodDefinition value)
+ {
+ Attach (value);
+
+ List.Insert (index, value);
+ }
+
+ public void Remove (MethodDefinition value)
+ {
+ List.Remove (value);
+
+ Detach (value);
+ }
+
+
+ public new void RemoveAt (int index)
+ {
+ MethodDefinition item = this [index];
+ Remove (item);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is MethodDefinition))
+ throw new ArgumentException ("Must be of type " + typeof (MethodDefinition).FullName);
+ }
+
+ public MethodDefinition [] GetMethod (string name)
+ {
+ ArrayList ret = new ArrayList ();
+ foreach (MethodDefinition meth in this)
+ if (meth.Name == name)
+ ret.Add (meth);
+
+ return ret.ToArray (typeof (MethodDefinition)) as MethodDefinition [];
+ }
+
+ internal MethodDefinition GetMethodInternal (string name, IList parameters)
+ {
+ foreach (MethodDefinition meth in this) {
+ if (meth.Name != name || meth.Parameters.Count != parameters.Count)
+ continue;
+
+ bool match = true;
+ for (int i = 0; i < parameters.Count; i++) {
+ string pname;
+ object param = parameters [i];
+ if (param is Type)
+ pname = ReflectionHelper.GetTypeSignature (param as Type);
+ else if (param is TypeReference)
+ pname = (param as TypeReference).FullName;
+ else if (param is ParameterDefinition)
+ pname = (param as ParameterDefinition).ParameterType.FullName;
+ else
+ throw new NotSupportedException ();
+
+ if (meth.Parameters [i].ParameterType.FullName != pname) {
+ match = false;
+ break;
+ }
+ }
+
+ if (match)
+ return meth;
+ }
+
+ return null;
+ }
+
+ public MethodDefinition GetMethod (string name, Type [] parameters)
+ {
+ return GetMethodInternal (name, parameters);
+ }
+
+ public MethodDefinition GetMethod (string name, TypeReference [] parameters)
+ {
+ return GetMethodInternal (name, parameters);
+ }
+
+ public MethodDefinition GetMethod (string name, ParameterDefinitionCollection parameters)
+ {
+ return GetMethodInternal (name, parameters);
+ }
+
+ void Attach (MemberReference member)
+ {
+ if (member.DeclaringType != null)
+ throw new ReflectionException ("Member already attached, clone it instead");
+
+ member.DeclaringType = m_container;
+ }
+
+ void Detach (MemberReference member)
+ {
+ member.DeclaringType = null;
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitMethodDefinitionCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// MethodImplAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum MethodImplAttributes : ushort {
+ CodeTypeMask = 0x0003,
+ IL = 0x0000, // Method impl is CIL
+ Native = 0x0001, // Method impl is native
+ OPTIL = 0x0002, // Reserved: shall be zero in conforming implementations
+ Runtime = 0x0003, // Method impl is provided by the runtime
+
+ ManagedMask = 0x0004, // Flags specifying whether the code is managed or unmanaged
+ Unmanaged = 0x0004, // Method impl is unmanaged, otherwise managed
+ Managed = 0x0000, // Method impl is managed
+
+ // Implementation info and interop
+ ForwardRef = 0x0010, // Indicates method is defined; used primarily in merge scenarios
+ PreserveSig = 0x0080, // Reserved: conforming implementations may ignore
+ InternalCall = 0x1000, // Reserved: shall be zero in conforming implementations
+ Synchronized = 0x0020, // Method is single threaded through the body
+ NoInlining = 0x0008, // Method may not be inlined
+ MaxMethodImplVal = 0xffff // Range check value
+ }
+}
--- /dev/null
+//
+// MethodReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Text;
+
+ internal class MethodReference : MemberReference, IMethodSignature, IGenericParameterProvider {
+
+ ParameterDefinitionCollection m_parameters;
+ MethodReturnType m_returnType;
+
+ bool m_hasThis;
+ bool m_explicitThis;
+ MethodCallingConvention m_callConv;
+ GenericParameterCollection m_genparams;
+
+ public virtual bool HasThis {
+ get { return m_hasThis; }
+ set { m_hasThis = value; }
+ }
+
+ public virtual bool ExplicitThis {
+ get { return m_explicitThis; }
+ set { m_explicitThis = value; }
+ }
+
+ public virtual MethodCallingConvention CallingConvention {
+ get { return m_callConv; }
+ set { m_callConv = value; }
+ }
+
+ public virtual bool HasParameters {
+ get { return (m_parameters == null) ? false : (m_parameters.Count > 0); }
+ }
+
+ public virtual ParameterDefinitionCollection Parameters {
+ get {
+ if (m_parameters == null)
+ m_parameters = new ParameterDefinitionCollection (this);
+ return m_parameters;
+ }
+ }
+
+ public bool HasGenericParameters {
+ get { return (m_genparams == null) ? false : (m_genparams.Count > 0); }
+ }
+
+ public GenericParameterCollection GenericParameters {
+ get {
+ if (m_genparams == null)
+ m_genparams = new GenericParameterCollection (this);
+ return m_genparams;
+ }
+ }
+
+ public virtual MethodReturnType ReturnType {
+ get { return m_returnType;}
+ set { m_returnType = value; }
+ }
+
+ internal MethodReference (string name, bool hasThis,
+ bool explicitThis, MethodCallingConvention callConv) : this (name)
+ {
+ m_parameters = new ParameterDefinitionCollection (this);
+ m_hasThis = hasThis;
+ m_explicitThis = explicitThis;
+ m_callConv = callConv;
+ }
+
+ internal MethodReference (string name) : base (name)
+ {
+ m_returnType = new MethodReturnType (null);
+ }
+
+ public MethodReference (string name,
+ TypeReference declaringType, TypeReference returnType,
+ bool hasThis, bool explicitThis, MethodCallingConvention callConv) :
+ this (name, hasThis, explicitThis, callConv)
+ {
+ this.DeclaringType = declaringType;
+ this.ReturnType.ReturnType = returnType;
+ }
+
+ public virtual MethodDefinition Resolve ()
+ {
+ TypeReference declaringType = DeclaringType;
+ if (declaringType == null)
+ return null;
+
+ return declaringType.Module.Resolver.Resolve (this);
+ }
+
+ public virtual MethodReference GetOriginalMethod ()
+ {
+ return this;
+ }
+
+ public int GetSentinel ()
+ {
+ if (HasParameters) {
+ for (int i = 0; i < Parameters.Count; i++)
+ if (Parameters [i].ParameterType is SentinelType)
+ return i;
+ }
+ return -1;
+ }
+
+ public override string ToString ()
+ {
+ int sentinel = GetSentinel ();
+
+ StringBuilder sb = new StringBuilder ();
+ sb.Append (m_returnType.ReturnType.FullName);
+ sb.Append (" ");
+ sb.Append (base.ToString ());
+ sb.Append ("(");
+ if (this.HasParameters) {
+ for (int i = 0; i < this.Parameters.Count; i++) {
+ if (i > 0)
+ sb.Append (",");
+
+ if (i == sentinel)
+ sb.Append ("...,");
+
+ sb.Append (this.Parameters [i].ParameterType.FullName);
+ }
+ }
+ sb.Append (")");
+ return sb.ToString ();
+ }
+ }
+}
--- /dev/null
+//
+// MethodReturnType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+using Mono.Cecil.Metadata;
+
+namespace Mono.Cecil {
+
+ internal sealed class MethodReturnType : ICustomAttributeProvider, IHasMarshalSpec, IHasConstant {
+
+ MethodReference m_method;
+ ParameterDefinition m_param;
+
+ TypeReference m_returnType;
+
+ public MethodReference Method {
+ get { return m_method; }
+ set { m_method = value; }
+ }
+
+ public TypeReference ReturnType {
+ get { return m_returnType; }
+ set { m_returnType = value; }
+ }
+
+ internal ParameterDefinition Parameter {
+ get {
+ if (m_param == null) {
+ m_param = new ParameterDefinition (m_returnType);
+ m_param.Method = m_method;
+ }
+
+ return m_param;
+ }
+ set { m_param = value; }
+ }
+
+ public MetadataToken MetadataToken {
+ get { return Parameter.MetadataToken; }
+ set { Parameter.MetadataToken = value; }
+ }
+
+ public bool HasCustomAttributes {
+ get { return m_param != null && m_param.HasCustomAttributes; }
+ }
+
+ public CustomAttributeCollection CustomAttributes {
+ get { return Parameter.CustomAttributes; }
+ }
+
+ public bool HasConstant {
+ get { return m_param != null && m_param.HasConstant; }
+ }
+
+ public object Constant {
+ get { return Parameter.Constant; }
+ set { Parameter.Constant = value; }
+ }
+
+ public MarshalSpec MarshalSpec {
+ get { return Parameter.MarshalSpec; }
+ set { Parameter.MarshalSpec = value; }
+ }
+
+ public MethodReturnType (TypeReference retType)
+ {
+ m_returnType = retType;
+ }
+
+ public override string ToString ()
+ {
+ return String.Format ("[return: {0}]", m_returnType);
+ }
+ }
+}
--- /dev/null
+//
+// MethodSemanticsAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum MethodSemanticsAttributes : ushort {
+ Setter = 0x0001, // Setter for property
+ Getter = 0x0002, // Getter for property
+ Other = 0x0004, // Other method for property or event
+ AddOn = 0x0008, // AddOn method for event
+ RemoveOn = 0x0010, // RemoveOn method for event
+ Fire = 0x0020 // Fire method for event
+ }
+}
--- /dev/null
+//
+// MethodSpecification.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ internal abstract class MethodSpecification : MethodReference {
+
+ MethodReference m_elementMethod;
+
+ public MethodReference ElementMethod {
+ get { return m_elementMethod; }
+ set { m_elementMethod = value; }
+ }
+
+ public override string Name {
+ get { return m_elementMethod.Name; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override MethodCallingConvention CallingConvention {
+ get { return m_elementMethod.CallingConvention; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override bool HasThis {
+ get { return m_elementMethod.HasThis; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override bool ExplicitThis {
+ get { return m_elementMethod.ExplicitThis; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override MethodReturnType ReturnType {
+ get { return m_elementMethod.ReturnType; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override TypeReference DeclaringType {
+ get { return m_elementMethod.DeclaringType; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override bool HasParameters {
+ get { return m_elementMethod.HasParameters; }
+ }
+
+ public override ParameterDefinitionCollection Parameters {
+ get { return m_elementMethod.Parameters; }
+ }
+
+ internal MethodSpecification (MethodReference elemMethod) : base (string.Empty)
+ {
+ m_elementMethod = elemMethod;
+ }
+
+ public override MethodReference GetOriginalMethod()
+ {
+ return m_elementMethod.GetOriginalMethod ();
+ }
+ }
+}
--- /dev/null
+//
+// Modifiers.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal abstract class ModType : TypeSpecification {
+
+ TypeReference m_modifierType;
+
+ public TypeReference ModifierType {
+ get { return m_modifierType; }
+ set { m_modifierType = value; }
+ }
+
+ public override string Name
+ {
+ get { return string.Concat (base.Name, Suffix ()); }
+ }
+
+ public override string FullName
+ {
+ get { return string.Concat (base.FullName, Suffix ()); }
+ }
+
+ string Suffix ()
+ {
+ return string.Concat (" ", ModifierName, "(", this.ModifierType.FullName, ")");
+ }
+
+ protected abstract string ModifierName {
+ get;
+ }
+
+ public ModType (TypeReference elemType, TypeReference modType) : base (elemType)
+ {
+ m_modifierType = modType;
+ }
+ }
+
+ internal sealed class ModifierOptional : ModType {
+
+ protected override string ModifierName {
+ get { return "modopt"; }
+ }
+
+ public ModifierOptional (TypeReference elemType, TypeReference modType) : base (elemType, modType)
+ {
+ }
+
+ }
+
+ internal sealed class ModifierRequired : ModType {
+
+ protected override string ModifierName {
+ get { return "modreq"; }
+ }
+
+ public ModifierRequired (TypeReference elemType, TypeReference modType) : base (elemType, modType)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// ModuleDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using SR = System.Reflection;
+ using SS = System.Security;
+ using SSP = System.Security.Permissions;
+ using System.Text;
+
+ using Mono.Cecil.Cil;
+ using Mono.Cecil.Binary;
+ using Mono.Cecil.Metadata;
+
+ internal sealed class ModuleDefinition : ModuleReference, ICustomAttributeProvider, IMetadataScope,
+ IReflectionStructureVisitable, IReflectionVisitable {
+
+ Guid m_mvid;
+ bool m_main;
+ bool m_manifestOnly;
+
+ AssemblyNameReferenceCollection m_asmRefs;
+ ModuleReferenceCollection m_modRefs;
+ ResourceCollection m_res;
+ TypeDefinitionCollection m_types;
+ TypeReferenceCollection m_refs;
+ ExternTypeCollection m_externs;
+ MemberReferenceCollection m_members;
+ CustomAttributeCollection m_customAttrs;
+
+ AssemblyDefinition m_asm;
+ Image m_image;
+
+ ImageReader m_imgReader;
+ ReflectionController m_controller;
+ MetadataResolver m_resolver;
+ SecurityDeclarationReader m_secReader;
+
+ public Guid Mvid {
+ get { return m_mvid; }
+ set { m_mvid = value; }
+ }
+
+ public bool Main {
+ get { return m_main; }
+ set { m_main = value; }
+ }
+
+ public AssemblyNameReferenceCollection AssemblyReferences {
+ get { return m_asmRefs; }
+ }
+
+ public ModuleReferenceCollection ModuleReferences {
+ get { return m_modRefs; }
+ }
+
+ public ResourceCollection Resources {
+ get { return m_res; }
+ }
+
+ public TypeDefinitionCollection Types {
+ get { return m_types; }
+ }
+
+ public TypeReferenceCollection TypeReferences {
+ get { return m_refs; }
+ }
+
+ public MemberReferenceCollection MemberReferences {
+ get { return m_members; }
+ }
+
+ public ExternTypeCollection ExternTypes {
+ get {
+ if (m_externs == null)
+ m_externs = new ExternTypeCollection (this);
+
+ return m_externs;
+ }
+ }
+
+ public bool HasCustomAttributes {
+ get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
+ }
+
+ public CustomAttributeCollection CustomAttributes {
+ get {
+ if (m_customAttrs == null)
+ m_customAttrs = new CustomAttributeCollection (this);
+
+ return m_customAttrs;
+ }
+ }
+
+ public AssemblyDefinition Assembly {
+ get { return m_asm; }
+ }
+
+ internal ReflectionController Controller {
+ get { return m_controller; }
+ }
+
+ internal MetadataResolver Resolver {
+ get { return m_resolver; }
+ }
+
+ internal ImageReader ImageReader {
+ get { return m_imgReader; }
+ }
+
+ public Image Image {
+ get { return m_image; }
+ set {
+ m_image = value;
+ m_secReader = null;
+ }
+ }
+
+ public ModuleDefinition (string name, AssemblyDefinition asm) :
+ this (name, asm, null, false)
+ {
+ }
+
+ public ModuleDefinition (string name, AssemblyDefinition asm, bool main) :
+ this (name, asm, null, main)
+ {
+ }
+
+ internal ModuleDefinition (string name, AssemblyDefinition asm, StructureReader reader, bool main) : base (name)
+ {
+ if (asm == null)
+ throw new ArgumentNullException ("asm");
+ if (name == null || name.Length == 0)
+ throw new ArgumentNullException ("name");
+
+ m_asm = asm;
+ m_main = main;
+#if !CF_1_0
+ m_mvid = Guid.NewGuid ();
+#endif
+ if (reader != null) {
+ m_image = reader.Image;
+ m_imgReader = reader.ImageReader;
+ m_manifestOnly = reader.ManifestOnly;
+ } else
+ m_image = Image.CreateImage ();
+
+ m_modRefs = new ModuleReferenceCollection (this);
+ m_asmRefs = new AssemblyNameReferenceCollection (this);
+ m_res = new ResourceCollection (this);
+ m_types = new TypeDefinitionCollection (this);
+ m_refs = new TypeReferenceCollection (this);
+ m_members = new MemberReferenceCollection (this);
+
+ m_controller = new ReflectionController (this);
+ m_resolver = new MetadataResolver (asm);
+ }
+
+ public IMetadataTokenProvider LookupByToken (MetadataToken token)
+ {
+ return m_controller.Reader.LookupByToken (token);
+ }
+
+ public IMetadataTokenProvider LookupByToken (TokenType table, int rid)
+ {
+ return LookupByToken (new MetadataToken (table, (uint) rid));
+ }
+
+ void CheckContext (TypeDefinition context)
+ {
+ if (context.Module != this)
+ throw new ArgumentException ("The context parameter does not belongs to this module");
+
+ CheckGenericParameterProvider (context);
+ }
+
+ void CheckContext (MethodDefinition context)
+ {
+ CheckGenericParameterProvider (context);
+ }
+
+ static void CheckGenericParameterProvider (IGenericParameterProvider context)
+ {
+ if (context == null)
+ throw new ArgumentNullException ("context");
+ if (context.GenericParameters.Count == 0)
+ throw new ArgumentException ("The context parameter is not a generic type");
+ }
+
+ ImportContext GetContext ()
+ {
+ return new ImportContext (m_controller.Importer);
+ }
+
+ static ImportContext GetContext (IImporter importer)
+ {
+ return new ImportContext (importer);
+ }
+
+ ImportContext GetContext (TypeDefinition context)
+ {
+ return new ImportContext (m_controller.Importer, context);
+ }
+
+ ImportContext GetContext (MethodDefinition context)
+ {
+ return new ImportContext (m_controller.Importer, context);
+ }
+
+ static ImportContext GetContext (IImporter importer, TypeDefinition context)
+ {
+ return new ImportContext (importer, context);
+ }
+
+ public TypeReference Import (Type type)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+
+ return m_controller.Helper.ImportSystemType (type, GetContext ());
+ }
+
+ public TypeReference Import (Type type, TypeDefinition context)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+ CheckContext (context);
+
+ return m_controller.Helper.ImportSystemType (type, GetContext (context));
+ }
+
+ public TypeReference Import (Type type, MethodDefinition context)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+ CheckContext (context);
+
+ return m_controller.Helper.ImportSystemType (type, GetContext (context));
+ }
+
+ public MethodReference Import (SR.MethodBase meth)
+ {
+ if (meth == null)
+ throw new ArgumentNullException ("meth");
+
+ if (meth is SR.ConstructorInfo)
+ return m_controller.Helper.ImportConstructorInfo (
+ meth as SR.ConstructorInfo, GetContext ());
+ else
+ return m_controller.Helper.ImportMethodInfo (
+ meth as SR.MethodInfo, GetContext ());
+ }
+
+ public MethodReference Import (SR.MethodBase meth, TypeDefinition context)
+ {
+ if (meth == null)
+ throw new ArgumentNullException ("meth");
+ CheckContext (context);
+
+ ImportContext import_context = GetContext (context);
+
+ if (meth is SR.ConstructorInfo)
+ return m_controller.Helper.ImportConstructorInfo (
+ meth as SR.ConstructorInfo, import_context);
+ else
+ return m_controller.Helper.ImportMethodInfo (
+ meth as SR.MethodInfo, import_context);
+ }
+
+ public FieldReference Import (SR.FieldInfo field)
+ {
+ if (field == null)
+ throw new ArgumentNullException ("field");
+
+ return m_controller.Helper.ImportFieldInfo (field, GetContext ());
+ }
+
+ public FieldReference Import (SR.FieldInfo field, TypeDefinition context)
+ {
+ if (field == null)
+ throw new ArgumentNullException ("field");
+ CheckContext (context);
+
+ return m_controller.Helper.ImportFieldInfo (field, GetContext (context));
+ }
+
+ public FieldReference Import (SR.FieldInfo field, MethodDefinition context)
+ {
+ if (field == null)
+ throw new ArgumentNullException ("field");
+ CheckContext (context);
+
+ return m_controller.Helper.ImportFieldInfo (field, GetContext (context));
+ }
+
+ public TypeReference Import (TypeReference type)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+
+ return m_controller.Importer.ImportTypeReference (type, GetContext ());
+ }
+
+ public TypeReference Import (TypeReference type, TypeDefinition context)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+ CheckContext (context);
+
+ return m_controller.Importer.ImportTypeReference (type, GetContext (context));
+ }
+
+ public TypeReference Import (TypeReference type, MethodDefinition context)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+ CheckContext (context);
+
+ return m_controller.Importer.ImportTypeReference (type, GetContext (context));
+ }
+
+ public MethodReference Import (MethodReference meth)
+ {
+ if (meth == null)
+ throw new ArgumentNullException ("meth");
+
+ return m_controller.Importer.ImportMethodReference (meth, GetContext ());
+ }
+
+ public MethodReference Import (MethodReference meth, TypeDefinition context)
+ {
+ if (meth == null)
+ throw new ArgumentNullException ("meth");
+ CheckContext (context);
+
+ return m_controller.Importer.ImportMethodReference (meth, GetContext (context));
+ }
+
+ public MethodReference Import (MethodReference meth, MethodDefinition context)
+ {
+ if (meth == null)
+ throw new ArgumentNullException ("meth");
+ CheckContext (context);
+
+ return m_controller.Importer.ImportMethodReference (meth, GetContext (context));
+ }
+
+ public FieldReference Import (FieldReference field)
+ {
+ if (field == null)
+ throw new ArgumentNullException ("field");
+
+ return m_controller.Importer.ImportFieldReference (field, GetContext ());
+ }
+
+ public FieldReference Import (FieldReference field, TypeDefinition context)
+ {
+ if (field == null)
+ throw new ArgumentNullException ("field");
+ CheckContext (context);
+
+ return m_controller.Importer.ImportFieldReference (field, GetContext (context));
+ }
+
+ public FieldReference Import (FieldReference field, MethodDefinition context)
+ {
+ if (field == null)
+ throw new ArgumentNullException ("field");
+ CheckContext (context);
+
+ return m_controller.Importer.ImportFieldReference (field, GetContext (context));
+ }
+
+ static FieldDefinition ImportFieldDefinition (FieldDefinition field, ImportContext context)
+ {
+ return FieldDefinition.Clone (field, context);
+ }
+
+ static MethodDefinition ImportMethodDefinition (MethodDefinition meth, ImportContext context)
+ {
+ return MethodDefinition.Clone (meth, context);
+ }
+
+ static TypeDefinition ImportTypeDefinition (TypeDefinition type, ImportContext context)
+ {
+ return TypeDefinition.Clone (type, context);
+ }
+
+ public TypeDefinition Inject (TypeDefinition type)
+ {
+ return Inject (type, m_controller.Importer);
+ }
+
+ public TypeDefinition Inject (TypeDefinition type, IImporter importer)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+ if (importer == null)
+ throw new ArgumentNullException ("importer");
+
+ TypeDefinition definition = ImportTypeDefinition (type, GetContext (importer));
+ this.Types.Add (definition);
+ return definition;
+ }
+
+ public TypeDefinition Inject (TypeDefinition type, TypeDefinition context)
+ {
+ return Inject (type, context, m_controller.Importer);
+ }
+
+ public TypeDefinition Inject (TypeDefinition type, TypeDefinition context, IImporter importer)
+ {
+ Check (type, context, importer);
+
+ TypeDefinition definition = ImportTypeDefinition (type, GetContext (importer, context));
+ context.NestedTypes.Add (definition);
+ return definition;
+ }
+
+ public MethodDefinition Inject (MethodDefinition meth, TypeDefinition context)
+ {
+ return Inject (meth, context, m_controller.Importer);
+ }
+
+ void Check (IMemberDefinition definition, TypeDefinition context, IImporter importer)
+ {
+ if (definition == null)
+ throw new ArgumentNullException ("definition");
+ if (context == null)
+ throw new ArgumentNullException ("context");
+ if (importer == null)
+ throw new ArgumentNullException ("importer");
+ if (context.Module != this)
+ throw new ArgumentException ("The context parameter does not belongs to this module");
+ }
+
+ public MethodDefinition Inject (MethodDefinition meth, TypeDefinition context, IImporter importer)
+ {
+ Check (meth, context, importer);
+
+ MethodDefinition definition = ImportMethodDefinition (meth, GetContext (importer, context));
+ context.Methods.Add (definition);
+ return definition;
+ }
+
+ public FieldDefinition Inject (FieldDefinition field, TypeDefinition context)
+ {
+ return Inject (field, context, m_controller.Importer);
+ }
+
+ public FieldDefinition Inject (FieldDefinition field, TypeDefinition context, IImporter importer)
+ {
+ Check (field, context, importer);
+
+ FieldDefinition definition = ImportFieldDefinition (field, GetContext (importer, context));
+ context.Fields.Add (definition);
+ return definition;
+ }
+
+ public void FullLoad ()
+ {
+ if (m_manifestOnly)
+ m_controller.Reader.VisitModuleDefinition (this);
+
+ foreach (TypeDefinition type in this.Types) {
+ foreach (MethodDefinition meth in type.Methods)
+ meth.LoadBody ();
+ foreach (MethodDefinition ctor in type.Constructors)
+ ctor.LoadBody ();
+ }
+
+ if (m_controller.Reader.SymbolReader == null)
+ return;
+
+ m_controller.Reader.SymbolReader.Dispose ();
+ m_controller.Reader.SymbolReader = null;
+ }
+
+ public void LoadSymbols ()
+ {
+ m_controller.Reader.SymbolReader = SymbolStoreHelper.GetReader (this);
+ }
+
+ public void LoadSymbols (ISymbolReader reader)
+ {
+ m_controller.Reader.SymbolReader = reader;
+ }
+
+ public void SaveSymbols ()
+ {
+ m_controller.Writer.SaveSymbols = true;
+ }
+
+ public void SaveSymbols (ISymbolWriter writer)
+ {
+ SaveSymbols ();
+ m_controller.Writer.SymbolWriter = writer;
+ }
+
+ public void SaveSymbols (string outputDirectory)
+ {
+ SaveSymbols ();
+ m_controller.Writer.OutputFile = outputDirectory;
+ }
+
+ public void SaveSymbols (string outputDirectory, ISymbolWriter writer)
+ {
+ SaveSymbols (outputDirectory);
+ m_controller.Writer.SymbolWriter = writer;
+ }
+
+ public byte [] GetAsByteArray (CustomAttribute ca)
+ {
+ CustomAttribute customAttr = ca;
+ if (!ca.Resolved)
+ if (customAttr.Blob != null)
+ return customAttr.Blob;
+ else
+ return new byte [0];
+
+ return m_controller.Writer.SignatureWriter.CompressCustomAttribute (
+ ReflectionWriter.GetCustomAttributeSig (ca), ca.Constructor);
+ }
+
+ public byte [] GetAsByteArray (SecurityDeclaration dec)
+ {
+ // TODO - add support for 2.0 format
+ // note: the 1.x format is still supported in 2.0 so this isn't an immediate problem
+ if (!dec.Resolved)
+ return dec.Blob;
+
+#if !CF_1_0 && !CF_2_0
+ if (dec.PermissionSet != null)
+ return Encoding.Unicode.GetBytes (dec.PermissionSet.ToXml ().ToString ());
+#endif
+
+ return new byte [0];
+ }
+
+ public CustomAttribute FromByteArray (MethodReference ctor, byte [] data)
+ {
+ return m_controller.Reader.GetCustomAttribute (ctor, data);
+ }
+
+ public SecurityDeclaration FromByteArray (SecurityAction action, byte [] declaration)
+ {
+ if (m_secReader == null)
+ m_secReader = new SecurityDeclarationReader (Image.MetadataRoot, m_controller.Reader);
+ return m_secReader.FromByteArray (action, declaration);
+ }
+
+ public override void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitModuleDefinition (this);
+
+ this.AssemblyReferences.Accept (visitor);
+ this.ModuleReferences.Accept (visitor);
+ this.Resources.Accept (visitor);
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitModuleDefinition (this);
+
+ this.Types.Accept (visitor);
+ this.TypeReferences.Accept (visitor);
+ }
+
+ public override string ToString ()
+ {
+ string s = (m_main ? "(main), Mvid=" : "Mvid=");
+ return s + m_mvid;
+ }
+ }
+}
--- /dev/null
+//
+// ModuleDefinitionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:54 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class ModuleDefinitionCollection : CollectionBase, IReflectionStructureVisitable {
+
+ AssemblyDefinition m_container;
+
+ public ModuleDefinition this [int index] {
+ get { return List [index] as ModuleDefinition; }
+ set { List [index] = value; }
+ }
+
+ public AssemblyDefinition Container {
+ get { return m_container; }
+ }
+
+ public ModuleDefinitionCollection (AssemblyDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (ModuleDefinition value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (ModuleDefinition value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (ModuleDefinition value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, ModuleDefinition value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (ModuleDefinition value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is ModuleDefinition))
+ throw new ArgumentException ("Must be of type " + typeof (ModuleDefinition).FullName);
+ }
+
+ public void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitModuleDefinitionCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// ModuleReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ using Mono.Cecil;
+ using Mono.Cecil.Metadata;
+
+ internal class ModuleReference : IMetadataScope, IAnnotationProvider, IReflectionStructureVisitable {
+
+ string m_name;
+ MetadataToken m_token;
+ IDictionary m_annotations;
+
+ public string Name {
+ get { return m_name; }
+ set { m_name = value; }
+ }
+
+ public MetadataToken MetadataToken {
+ get { return m_token; }
+ set { m_token = value; }
+ }
+
+ IDictionary IAnnotationProvider.Annotations {
+ get {
+ if (m_annotations == null)
+ m_annotations = new Hashtable ();
+ return m_annotations;
+ }
+ }
+
+ public ModuleReference (string name)
+ {
+ m_name = name;
+ }
+
+ public virtual void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitModuleReference (this);
+ }
+ }
+}
+
--- /dev/null
+//
+// ModuleReferenceCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:53 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class ModuleReferenceCollection : CollectionBase, IReflectionStructureVisitable {
+
+ ModuleDefinition m_container;
+
+ public ModuleReference this [int index] {
+ get { return List [index] as ModuleReference; }
+ set { List [index] = value; }
+ }
+
+ public ModuleDefinition Container {
+ get { return m_container; }
+ }
+
+ public ModuleReferenceCollection (ModuleDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (ModuleReference value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (ModuleReference value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (ModuleReference value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, ModuleReference value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (ModuleReference value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is ModuleReference))
+ throw new ArgumentException ("Must be of type " + typeof (ModuleReference).FullName);
+ }
+
+ public void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitModuleReferenceCollection (this);
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections;
+using System.Runtime.Serialization;
+
+#if NO_SYSTEM_DLL
+namespace System.Collections.Specialized
+{
+ [Serializable]
+ internal abstract class NameObjectCollectionBase : ICollection, IEnumerable, ISerializable, IDeserializationCallback
+ {
+ private Hashtable m_ItemsContainer;
+ /// <summary>
+ /// Extends Hashtable based Items container to support storing null-key pairs
+ /// </summary>
+ private _Item m_NullKeyItem;
+ private ArrayList m_ItemsArray;
+ private IHashCodeProvider m_hashprovider;
+ private IComparer m_comparer;
+ private int m_defCapacity;
+ private bool m_readonly;
+ SerializationInfo infoCopy;
+ private KeysCollection keyscoll;
+ private IEqualityComparer equality_comparer;
+
+ internal IEqualityComparer EqualityComparer {
+ get { return equality_comparer; }
+ }
+ internal IComparer Comparer
+ {
+ get { return m_comparer; }
+ }
+
+ internal IHashCodeProvider HashCodeProvider
+ {
+ get { return m_hashprovider; }
+ }
+
+ internal class _Item
+ {
+ public string key;
+ public object value;
+ public _Item(string key, object value)
+ {
+ this.key = key;
+ this.value = value;
+ }
+ }
+ /// <summary>
+ /// Implements IEnumerable interface for KeysCollection
+ /// </summary>
+ [Serializable]
+ internal class _KeysEnumerator : IEnumerator
+ {
+ private NameObjectCollectionBase m_collection;
+ private int m_position;
+
+ internal _KeysEnumerator(NameObjectCollectionBase collection)
+ {
+ m_collection = collection;
+ Reset();
+ }
+ public object Current
+ {
+
+ get
+ {
+ if ((m_position < m_collection.Count) || (m_position < 0))
+ return m_collection.BaseGetKey(m_position);
+ else
+ throw new InvalidOperationException();
+ }
+
+ }
+ public bool MoveNext()
+ {
+ return ((++m_position) < m_collection.Count);
+ }
+ public void Reset()
+ {
+ m_position = -1;
+ }
+ }
+
+ /// <summary>
+ /// SDK: Represents a collection of the String keys of a collection.
+ /// </summary>
+ [Serializable]
+ internal class KeysCollection : ICollection, IEnumerable
+ {
+ private NameObjectCollectionBase m_collection;
+
+ internal KeysCollection(NameObjectCollectionBase collection)
+ {
+ this.m_collection = collection;
+ }
+
+ public virtual string Get(int index)
+ {
+ return m_collection.BaseGetKey(index);
+ }
+
+ // ICollection methods -----------------------------------
+ void ICollection.CopyTo(Array array, int arrayIndex)
+ {
+ ArrayList items = m_collection.m_ItemsArray;
+ if (null == array)
+ throw new ArgumentNullException ("array");
+
+ if (arrayIndex < 0)
+ throw new ArgumentOutOfRangeException ("arrayIndex");
+
+ if ((array.Length > 0) && (arrayIndex >= array.Length))
+ throw new ArgumentException ("arrayIndex is equal to or greater than array.Length");
+
+ if (arrayIndex + items.Count > array.Length)
+ throw new ArgumentException ("Not enough room from arrayIndex to end of array for this KeysCollection");
+
+ if (array != null && array.Rank > 1)
+ throw new ArgumentException("array is multidimensional");
+
+ object[] objArray = (object[])array;
+ for (int i = 0; i < items.Count; i++, arrayIndex++)
+ objArray[arrayIndex] = ((_Item)items[i]).key;
+ }
+
+ bool ICollection.IsSynchronized
+ {
+ get
+ {
+ return false;
+ }
+ }
+ object ICollection.SyncRoot
+ {
+ get
+ {
+ return m_collection;
+ }
+ }
+ /// <summary>
+ /// Gets the number of keys in the NameObjectCollectionBase.KeysCollection
+ /// </summary>
+ public int Count
+ {
+ get
+ {
+ return m_collection.Count;
+ }
+ }
+
+ public string this[int index]
+ {
+ get { return Get(index); }
+ }
+
+ // IEnumerable methods --------------------------------
+ /// <summary>
+ /// SDK: Returns an enumerator that can iterate through the NameObjectCollectionBase.KeysCollection.
+ /// </summary>
+ /// <returns></returns>
+ public IEnumerator GetEnumerator()
+ {
+ return new _KeysEnumerator(m_collection);
+ }
+ }
+
+ //--------------- Protected Instance Constructors --------------
+
+ /// <summary>
+ /// SDK: Initializes a new instance of the NameObjectCollectionBase class that is empty.
+ /// </summary>
+ protected NameObjectCollectionBase()
+ {
+ m_readonly = false;
+#if NET_1_0
+ m_hashprovider = CaseInsensitiveHashCodeProvider.Default;
+ m_comparer = CaseInsensitiveComparer.Default;
+#else
+ m_hashprovider = CaseInsensitiveHashCodeProvider.DefaultInvariant;
+ m_comparer = CaseInsensitiveComparer.DefaultInvariant;
+#endif
+ m_defCapacity = 0;
+ Init();
+ }
+
+ protected NameObjectCollectionBase(int capacity)
+ {
+ m_readonly = false;
+#if NET_1_0
+ m_hashprovider = CaseInsensitiveHashCodeProvider.Default;
+ m_comparer = CaseInsensitiveComparer.Default;
+#else
+ m_hashprovider = CaseInsensitiveHashCodeProvider.DefaultInvariant;
+ m_comparer = CaseInsensitiveComparer.DefaultInvariant;
+#endif
+ m_defCapacity = capacity;
+ Init();
+ }
+
+
+ internal NameObjectCollectionBase (IEqualityComparer equalityComparer, IComparer comparer, IHashCodeProvider hcp)
+ {
+ equality_comparer = equalityComparer;
+ m_comparer = comparer;
+ m_hashprovider = hcp;
+ m_readonly = false;
+ m_defCapacity = 0;
+ Init ();
+ }
+
+ protected NameObjectCollectionBase (IEqualityComparer equalityComparer) : this( (equalityComparer == null ? StringComparer.InvariantCultureIgnoreCase : equalityComparer), null, null)
+ {
+ }
+
+ [Obsolete ("Use NameObjectCollectionBase(IEqualityComparer)")]
+ protected NameObjectCollectionBase(IHashCodeProvider hashProvider, IComparer comparer)
+ {
+ m_comparer = comparer;
+ m_hashprovider = hashProvider;
+ m_readonly = false;
+ m_defCapacity = 0;
+ Init();
+ }
+
+ protected NameObjectCollectionBase(SerializationInfo info, StreamingContext context)
+ {
+ infoCopy = info;
+ }
+
+ protected NameObjectCollectionBase (int capacity, IEqualityComparer equalityComparer)
+ {
+ m_readonly = false;
+ equality_comparer = (equalityComparer == null ? StringComparer.InvariantCultureIgnoreCase : equalityComparer);
+ m_defCapacity = capacity;
+ Init();
+ }
+
+ [Obsolete ("Use NameObjectCollectionBase(int,IEqualityComparer)")]
+ protected NameObjectCollectionBase(int capacity, IHashCodeProvider hashProvider, IComparer comparer)
+ {
+ m_readonly = false;
+
+ m_hashprovider = hashProvider;
+ m_comparer = comparer;
+ m_defCapacity = capacity;
+ Init();
+ }
+
+ private void Init()
+ {
+ if (equality_comparer != null)
+ m_ItemsContainer = new Hashtable (m_defCapacity, equality_comparer);
+ else
+ m_ItemsContainer = new Hashtable (m_defCapacity, m_hashprovider, m_comparer);
+ m_ItemsArray = new ArrayList();
+ m_NullKeyItem = null;
+ }
+
+ //--------------- Public Instance Properties -------------------
+
+ public virtual NameObjectCollectionBase.KeysCollection Keys
+ {
+ get
+ {
+ if (keyscoll == null)
+ keyscoll = new KeysCollection(this);
+ return keyscoll;
+ }
+ }
+
+ //--------------- Public Instance Methods ----------------------
+ //
+ /// <summary>
+ /// SDK: Returns an enumerator that can iterate through the NameObjectCollectionBase.
+ ///
+ /// <remark>This enumerator returns the keys of the collection as strings.</remark>
+ /// </summary>
+ /// <returns></returns>
+ public
+ virtual
+ IEnumerator GetEnumerator()
+ {
+ return new _KeysEnumerator(this);
+ }
+
+ // ISerializable
+ public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ if (info == null)
+ throw new ArgumentNullException("info");
+
+ int count = Count;
+ string[] keys = new string[count];
+ object[] values = new object[count];
+ int i = 0;
+ foreach (_Item item in m_ItemsArray)
+ {
+ keys[i] = item.key;
+ values[i] = item.value;
+ i++;
+ }
+
+ if (equality_comparer != null) {
+ info.AddValue ("KeyComparer", equality_comparer, typeof (IEqualityComparer));
+ info.AddValue ("Version", 4, typeof (int));
+ } else {
+ info.AddValue ("HashProvider", m_hashprovider, typeof (IHashCodeProvider));
+ info.AddValue ("Comparer", m_comparer, typeof (IComparer));
+ info.AddValue ("Version", 2, typeof (int));
+ }
+ info.AddValue("ReadOnly", m_readonly);
+ info.AddValue("Count", count);
+ info.AddValue("Keys", keys, typeof(string[]));
+ info.AddValue("Values", values, typeof(object[]));
+ }
+
+ // ICollection
+ public virtual int Count
+ {
+ get
+ {
+ return m_ItemsArray.Count;
+ }
+ }
+
+ bool ICollection.IsSynchronized
+ {
+ get { return false; }
+ }
+
+ object ICollection.SyncRoot
+ {
+ get { return this; }
+ }
+
+ void ICollection.CopyTo(Array array, int index)
+ {
+ ((ICollection)Keys).CopyTo(array, index);
+ }
+
+ // IDeserializationCallback
+ public virtual void OnDeserialization(object sender)
+ {
+ SerializationInfo info = infoCopy;
+
+ // If a subclass overrides the serialization constructor
+ // and inplements its own serialization process, infoCopy will
+ // be null and we can ignore this callback.
+ if (info == null)
+ return;
+
+ infoCopy = null;
+ m_hashprovider = (IHashCodeProvider)info.GetValue("HashProvider",
+ typeof(IHashCodeProvider));
+ if (m_hashprovider == null) {
+ equality_comparer = (IEqualityComparer) info.GetValue ("KeyComparer", typeof (IEqualityComparer));
+ } else {
+ m_comparer = (IComparer) info.GetValue ("Comparer", typeof (IComparer));
+ if (m_comparer == null)
+ throw new SerializationException ("The comparer is null");
+ }
+ m_readonly = info.GetBoolean("ReadOnly");
+ string[] keys = (string[])info.GetValue("Keys", typeof(string[]));
+ if (keys == null)
+ throw new SerializationException("keys is null");
+
+ object[] values = (object[])info.GetValue("Values", typeof(object[]));
+ if (values == null)
+ throw new SerializationException("values is null");
+
+ Init();
+ int count = keys.Length;
+ for (int i = 0; i < count; i++)
+ BaseAdd(keys[i], values[i]);
+ }
+
+ //--------------- Protected Instance Properties ----------------
+ /// <summary>
+ /// SDK: Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only.
+ /// </summary>
+ protected bool IsReadOnly
+ {
+ get
+ {
+ return m_readonly;
+ }
+ set
+ {
+ m_readonly = value;
+ }
+ }
+
+ //--------------- Protected Instance Methods -------------------
+ /// <summary>
+ /// Adds an Item with the specified key and value into the <see cref="NameObjectCollectionBase"/>NameObjectCollectionBase instance.
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="value"></param>
+ protected void BaseAdd(string name, object value)
+ {
+ if (this.IsReadOnly)
+ throw new NotSupportedException("Collection is read-only");
+
+ _Item newitem = new _Item(name, value);
+
+ if (name == null)
+ {
+ //todo: consider nullkey entry
+ if (m_NullKeyItem == null)
+ m_NullKeyItem = newitem;
+ }
+ else
+ if (m_ItemsContainer[name] == null)
+ {
+ m_ItemsContainer.Add(name, newitem);
+ }
+ m_ItemsArray.Add(newitem);
+ }
+
+ protected void BaseClear()
+ {
+ if (this.IsReadOnly)
+ throw new NotSupportedException("Collection is read-only");
+ Init();
+ }
+
+ /// <summary>
+ /// SDK: Gets the value of the entry at the specified index of the NameObjectCollectionBase instance.
+ /// </summary>
+ /// <param name="index"></param>
+ /// <returns></returns>
+ protected object BaseGet(int index)
+ {
+ return ((_Item)m_ItemsArray[index]).value;
+ }
+
+ /// <summary>
+ /// SDK: Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance.
+ /// </summary>
+ /// <remark>CAUTION: The BaseGet method does not distinguish between a null reference which is returned because the specified key is not found and a null reference which is returned because the value associated with the key is a null reference.</remark>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ protected object BaseGet(string name)
+ {
+ _Item item = FindFirstMatchedItem(name);
+ /// CAUTION: The BaseGet method does not distinguish between a null reference which is returned because the specified key is not found and a null reference which is returned because the value associated with the key is a null reference.
+ if (item == null)
+ return null;
+ else
+ return item.value;
+ }
+
+ /// <summary>
+ /// SDK:Returns a String array that contains all the keys in the NameObjectCollectionBase instance.
+ /// </summary>
+ /// <returns>A String array that contains all the keys in the NameObjectCollectionBase instance.</returns>
+ protected string[] BaseGetAllKeys()
+ {
+ int cnt = m_ItemsArray.Count;
+ string[] allKeys = new string[cnt];
+ for (int i = 0; i < cnt; i++)
+ allKeys[i] = BaseGetKey(i);//((_Item)m_ItemsArray[i]).key;
+
+ return allKeys;
+ }
+
+ /// <summary>
+ /// SDK: Returns an Object array that contains all the values in the NameObjectCollectionBase instance.
+ /// </summary>
+ /// <returns>An Object array that contains all the values in the NameObjectCollectionBase instance.</returns>
+ protected object[] BaseGetAllValues()
+ {
+ int cnt = m_ItemsArray.Count;
+ object[] allValues = new object[cnt];
+ for (int i = 0; i < cnt; i++)
+ allValues[i] = BaseGet(i);
+
+ return allValues;
+ }
+
+ protected object[] BaseGetAllValues(Type type)
+ {
+ if (type == null)
+ throw new ArgumentNullException("'type' argument can't be null");
+ int cnt = m_ItemsArray.Count;
+ object[] allValues = (object[])Array.CreateInstance(type, cnt);
+ for (int i = 0; i < cnt; i++)
+ allValues[i] = BaseGet(i);
+
+ return allValues;
+ }
+
+ protected string BaseGetKey(int index)
+ {
+ return ((_Item)m_ItemsArray[index]).key;
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not a null reference
+ /// </summary>
+ /// <returns>true if the NameObjectCollectionBase instance contains entries whose keys are not a null reference otherwise, false.</returns>
+ protected bool BaseHasKeys()
+ {
+ return (m_ItemsContainer.Count > 0);
+ }
+
+ protected void BaseRemove(string name)
+ {
+ int cnt = 0;
+ String key;
+ if (this.IsReadOnly)
+ throw new NotSupportedException("Collection is read-only");
+ if (name != null)
+ {
+ m_ItemsContainer.Remove(name);
+ }
+ else
+ {
+ m_NullKeyItem = null;
+ }
+
+ cnt = m_ItemsArray.Count;
+ for (int i = 0; i < cnt; )
+ {
+ key = BaseGetKey(i);
+ if (Equals(key, name))
+ {
+ m_ItemsArray.RemoveAt(i);
+ cnt--;
+ }
+ else
+ i++;
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="index"></param>
+ /// <LAME>This function implemented the way Microsoft implemented it -
+ /// item is removed from hashtable and array without considering the case when there are two items with the same key but different values in array.
+ /// E.g. if
+ /// hashtable is [("Key1","value1")] and array contains [("Key1","value1")("Key1","value2")] then
+ /// after RemoveAt(1) the collection will be in following state:
+ /// hashtable:[]
+ /// array: [("Key1","value1")]
+ /// It's ok only then the key is uniquely assosiated with the value
+ /// To fix it a comparsion of objects stored under the same key in the hashtable and in the arraylist should be added
+ /// </LAME>>
+ protected void BaseRemoveAt(int index)
+ {
+ if (this.IsReadOnly)
+ throw new NotSupportedException("Collection is read-only");
+ string key = BaseGetKey(index);
+ if (key != null)
+ {
+ // TODO: see LAME description above
+ m_ItemsContainer.Remove(key);
+ }
+ else
+ m_NullKeyItem = null;
+ m_ItemsArray.RemoveAt(index);
+ }
+
+ /// <summary>
+ /// SDK: Sets the value of the entry at the specified index of the NameObjectCollectionBase instance.
+ /// </summary>
+ /// <param name="index"></param>
+ /// <param name="value"></param>
+ protected void BaseSet(int index, object value)
+ {
+ if (this.IsReadOnly)
+ throw new NotSupportedException("Collection is read-only");
+ _Item item = (_Item)m_ItemsArray[index];
+ item.value = value;
+ }
+
+ /// <summary>
+ /// Sets the value of the first entry with the specified key in the NameObjectCollectionBase instance, if found; otherwise, adds an entry with the specified key and value into the NameObjectCollectionBase instance.
+ /// </summary>
+ /// <param name="name">The String key of the entry to set. The key can be a null reference </param>
+ /// <param name="value">The Object that represents the new value of the entry to set. The value can be a null reference</param>
+ protected void BaseSet(string name, object value)
+ {
+ if (this.IsReadOnly)
+ throw new NotSupportedException("Collection is read-only");
+ _Item item = FindFirstMatchedItem(name);
+ if (item != null)
+ item.value = value;
+ else
+ BaseAdd(name, value);
+ }
+
+ private _Item FindFirstMatchedItem(string name)
+ {
+ if (name != null)
+ return (_Item)m_ItemsContainer[name];
+ else
+ {
+ //TODO: consider null key case
+ return m_NullKeyItem;
+ }
+ }
+
+ internal bool Equals(string s1, string s2)
+ {
+ if (m_comparer != null)
+ return (m_comparer.Compare (s1, s2) == 0);
+ else
+ return equality_comparer.Equals (s1, s2);
+ }
+ }
+}
+#endif
--- /dev/null
+//
+// NativeType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal enum NativeType {
+ NONE = 0x66,
+
+ BOOLEAN = 0x02,
+ I1 = 0x03,
+ U1 = 0x04,
+ I2 = 0x05,
+ U2 = 0x06,
+ I4 = 0x07,
+ U4 = 0x08,
+ I8 = 0x09,
+ U8 = 0x0a,
+ R4 = 0x0b,
+ R8 = 0x0c,
+ LPSTR = 0x14,
+ INT = 0x1f,
+ UINT = 0x20,
+ FUNC = 0x26,
+ ARRAY = 0x2a,
+
+ // Msft specific
+ CURRENCY = 0x0f,
+ BSTR = 0x13,
+ LPWSTR = 0x15,
+ LPTSTR = 0x16,
+ FIXEDSYSSTRING = 0x17,
+ IUNKNOWN = 0x19,
+ IDISPATCH = 0x1a,
+ STRUCT = 0x1b,
+ INTF = 0x1c,
+ SAFEARRAY = 0x1d,
+ FIXEDARRAY = 0x1e,
+ BYVALSTR = 0x22,
+ ANSIBSTR = 0x23,
+ TBSTR = 0x24,
+ VARIANTBOOL = 0x25,
+ ASANY = 0x28,
+ LPSTRUCT = 0x2b,
+ CUSTOMMARSHALER = 0x2c,
+ ERROR = 0x2d,
+ MAX = 0x50
+ }
+}
--- /dev/null
+//
+// NestedTypeCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Mar 30 18:43:57 +0200 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class NestedTypeCollection : CollectionBase, IReflectionVisitable {
+
+ TypeDefinition m_container;
+
+ public TypeDefinition this [int index] {
+ get { return List [index] as TypeDefinition; }
+ set { List [index] = value; }
+ }
+
+ public TypeDefinition Container {
+ get { return m_container; }
+ }
+
+ public NestedTypeCollection (TypeDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (TypeDefinition value)
+ {
+ Attach (value);
+
+ List.Add (value);
+ }
+
+
+ public new void Clear ()
+ {
+ foreach (TypeDefinition item in this)
+ Detach (item);
+
+ base.Clear ();
+ }
+
+ public bool Contains (TypeDefinition value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (TypeDefinition value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, TypeDefinition value)
+ {
+ Attach (value);
+
+ List.Insert (index, value);
+ }
+
+ public void Remove (TypeDefinition value)
+ {
+ List.Remove (value);
+
+ Detach (value);
+ }
+
+
+ public new void RemoveAt (int index)
+ {
+ TypeDefinition item = this [index];
+ Remove (item);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is TypeDefinition))
+ throw new ArgumentException ("Must be of type " + typeof (TypeDefinition).FullName);
+ }
+
+ void Attach (MemberReference member)
+ {
+ if (member.DeclaringType != null)
+ throw new ReflectionException ("Member already attached, clone it instead");
+
+ member.DeclaringType = m_container;
+ }
+
+ void Detach (MemberReference member)
+ {
+ member.DeclaringType = null;
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitNestedTypeCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// NullReferenceImporter.cs
+//
+// Author:
+// Jb Evain (jbevain@novell.com)
+//
+// (C) 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ sealed class NullReferenceImporter : IImporter {
+
+ public static readonly NullReferenceImporter Instance = new NullReferenceImporter ();
+
+ public TypeReference ImportTypeReference (TypeReference type, ImportContext context)
+ {
+ return type;
+ }
+
+ public FieldReference ImportFieldReference (FieldReference field, ImportContext context)
+ {
+ return field;
+ }
+
+ public MethodReference ImportMethodReference (MethodReference method, ImportContext context)
+ {
+ return method;
+ }
+ }
+}
--- /dev/null
+//
+// OverrideCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:53 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class OverrideCollection : CollectionBase, IReflectionVisitable {
+
+ MethodDefinition m_container;
+
+ public MethodReference this [int index] {
+ get { return List [index] as MethodReference; }
+ set { List [index] = value; }
+ }
+
+ public MethodDefinition Container {
+ get { return m_container; }
+ }
+
+ public OverrideCollection (MethodDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (MethodReference value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (MethodReference value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (MethodReference value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, MethodReference value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (MethodReference value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is MethodReference))
+ throw new ArgumentException ("Must be of type " + typeof (MethodReference).FullName);
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitOverrideCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// PInvokeAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum PInvokeAttributes : ushort {
+ NoMangle = 0x0001, // PInvoke is to use the member name as specified
+
+ // Character set
+ CharSetMask = 0x0006,
+ CharSetNotSpec = 0x0000,
+ CharSetAnsi = 0x0002,
+ CharSetUnicode = 0x0004,
+ CharSetAuto = 0x0006,
+ SupportsLastError = 0x0040, // Information about target function. Not relevant for fields
+
+ // Calling convetion
+ CallConvMask = 0x0700,
+ CallConvWinapi = 0x0100,
+ CallConvCdecl = 0x0200,
+ CallConvStdCall = 0x0300,
+ CallConvThiscall = 0x0400,
+ CallConvFastcall = 0x0500
+ }
+}
--- /dev/null
+//
+// PInvokeInfo.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class PInvokeInfo : IReflectionVisitable {
+
+ MethodDefinition m_meth;
+
+ PInvokeAttributes m_attributes;
+ string m_entryPoint;
+ ModuleReference m_module;
+
+ public MethodDefinition Method {
+ get { return m_meth; }
+ }
+
+ public PInvokeAttributes Attributes {
+ get { return m_attributes; }
+ set { m_attributes = value; }
+ }
+
+ public string EntryPoint {
+ get { return m_entryPoint; }
+ set { m_entryPoint = value; }
+ }
+
+ public ModuleReference Module {
+ get { return m_module; }
+ set { m_module = value; }
+ }
+
+ #region PInvokeAttributes
+
+ public bool IsNoMangle {
+ get { return (m_attributes & PInvokeAttributes.NoMangle) != 0; }
+ set {
+ if (value)
+ m_attributes |= PInvokeAttributes.NoMangle;
+ else
+ m_attributes &= ~PInvokeAttributes.NoMangle;
+ }
+ }
+
+ public bool IsCharSetNotSpec {
+ get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetNotSpec; }
+ set {
+ if (value) {
+ m_attributes &= ~PInvokeAttributes.CharSetMask;
+ m_attributes |= PInvokeAttributes.CharSetNotSpec;
+ } else
+ m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetNotSpec);
+ }
+ }
+
+ public bool IsCharSetAnsi {
+ get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetAnsi; }
+ set {
+ if (value) {
+ m_attributes &= ~PInvokeAttributes.CharSetMask;
+ m_attributes |= PInvokeAttributes.CharSetAnsi;
+ } else
+ m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetAnsi);
+ }
+ }
+
+ public bool IsCharSetUnicode {
+ get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetUnicode; }
+ set {
+ if (value) {
+ m_attributes &= ~PInvokeAttributes.CharSetMask;
+ m_attributes |= PInvokeAttributes.CharSetUnicode;
+ } else
+ m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetUnicode);
+ }
+ }
+
+ public bool IsCharSetAuto {
+ get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetAuto; }
+ set {
+ if (value) {
+ m_attributes &= ~PInvokeAttributes.CharSetMask;
+ m_attributes |= PInvokeAttributes.CharSetAuto;
+ } else
+ m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetAuto);
+ }
+ }
+
+ public bool SupportsLastError {
+ get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.SupportsLastError; }
+ set {
+ if (value) {
+ m_attributes &= ~PInvokeAttributes.CharSetMask;
+ m_attributes |= PInvokeAttributes.SupportsLastError;
+ } else
+ m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.SupportsLastError);
+ }
+ }
+
+ public bool IsCallConvWinapi {
+ get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvWinapi; }
+ set {
+ if (value) {
+ m_attributes &= ~PInvokeAttributes.CallConvMask;
+ m_attributes |= PInvokeAttributes.CallConvWinapi;
+ } else
+ m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvWinapi);
+ }
+ }
+
+ public bool IsCallConvCdecl {
+ get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvCdecl; }
+ set {
+ if (value) {
+ m_attributes &= ~PInvokeAttributes.CallConvMask;
+ m_attributes |= PInvokeAttributes.CallConvCdecl;
+ } else
+ m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvCdecl);
+ }
+ }
+
+ public bool IsCallConvStdCall {
+ get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvStdCall; }
+ set {
+ if (value) {
+ m_attributes &= ~PInvokeAttributes.CallConvMask;
+ m_attributes |= PInvokeAttributes.CallConvStdCall;
+ } else
+ m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvStdCall);
+ }
+ }
+
+ public bool IsCallConvThiscall {
+ get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvThiscall; }
+ set {
+ if (value) {
+ m_attributes &= ~PInvokeAttributes.CallConvMask;
+ m_attributes |= PInvokeAttributes.CallConvThiscall;
+ } else
+ m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvThiscall);
+ }
+ }
+
+ public bool IsCallConvFastcall {
+ get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvFastcall; }
+ set {
+ if (value) {
+ m_attributes &= ~PInvokeAttributes.CallConvMask;
+ m_attributes |= PInvokeAttributes.CallConvFastcall;
+ } else
+ m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvFastcall);
+ }
+ }
+
+ #endregion
+
+ public PInvokeInfo (MethodDefinition meth)
+ {
+ m_meth = meth;
+ }
+
+ public PInvokeInfo (MethodDefinition meth, PInvokeAttributes attrs,
+ string entryPoint, ModuleReference mod) : this (meth)
+ {
+ m_attributes = attrs;
+ m_entryPoint = entryPoint;
+ m_module = mod;
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitPInvokeInfo (this);
+ }
+ }
+}
--- /dev/null
+//
+// ParameterAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum ParameterAttributes : ushort {
+ None = 0x0000,
+ In = 0x0001, // Param is [In]
+ Out = 0x0002, // Param is [Out]
+ Lcid = 0x0004,
+ Retval = 0x0008,
+ Optional = 0x0010, // Param is optional
+ HasDefault = 0x1000, // Param has default value
+ HasFieldMarshal = 0x2000, // Param has field marshal
+ Unused = 0xcfe0 // Reserved: shall be zero in a conforming implementation
+ }
+}
--- /dev/null
+//
+// ParameterDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class ParameterDefinition : ParameterReference, IHasMarshalSpec,
+ IMetadataTokenProvider, ICustomAttributeProvider, IHasConstant {
+
+ ParameterAttributes m_attributes;
+
+ bool m_hasConstant;
+ object m_const;
+
+ MethodReference m_method;
+ CustomAttributeCollection m_customAttrs;
+
+ MarshalSpec m_marshalDesc;
+
+ public ParameterAttributes Attributes {
+ get { return m_attributes; }
+ set { m_attributes = value; }
+ }
+
+ public bool HasConstant {
+ get { return m_hasConstant; }
+ }
+
+ public object Constant {
+ get { return m_const; }
+ set {
+ m_hasConstant = true;
+ m_const = value;
+ }
+ }
+
+ public MethodReference Method {
+ get { return m_method; }
+ set { m_method = value; }
+ }
+
+ public bool HasCustomAttributes {
+ get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
+ }
+
+ public CustomAttributeCollection CustomAttributes {
+ get {
+ if (m_customAttrs == null)
+ m_customAttrs = new CustomAttributeCollection (this);
+
+ return m_customAttrs;
+ }
+ }
+
+ public MarshalSpec MarshalSpec {
+ get { return m_marshalDesc; }
+ set {
+ m_marshalDesc = value;
+ if (value != null)
+ m_attributes |= ParameterAttributes.HasFieldMarshal;
+ else
+ m_attributes &= ~ParameterAttributes.HasFieldMarshal;
+ }
+ }
+
+ #region ParameterAttributes
+
+ public bool IsIn {
+ get { return (m_attributes & ParameterAttributes.In) != 0; }
+ set {
+ if (value)
+ m_attributes |= ParameterAttributes.In;
+ else
+ m_attributes &= ~ParameterAttributes.In;
+ }
+ }
+
+ public bool IsOut {
+ get { return (m_attributes & ParameterAttributes.Out) != 0; }
+ set {
+ if (value)
+ m_attributes |= ParameterAttributes.Out;
+ else
+ m_attributes &= ~ParameterAttributes.Out;
+ }
+ }
+
+ public bool IsRetval {
+ get { return (m_attributes & ParameterAttributes.Retval) != 0; }
+ set {
+ if (value)
+ m_attributes |= ParameterAttributes.Retval;
+ else
+ m_attributes &= ~ParameterAttributes.Retval;
+ }
+ }
+
+ public bool IsLcid {
+ get { return (m_attributes & ParameterAttributes.Lcid) != 0; }
+ set {
+ if (value)
+ m_attributes |= ParameterAttributes.Lcid;
+ else
+ m_attributes &= ~ParameterAttributes.Lcid;
+ }
+ }
+
+ public bool IsOptional {
+ get { return (m_attributes & ParameterAttributes.Optional) != 0; }
+ set {
+ if (value)
+ m_attributes |= ParameterAttributes.Optional;
+ else
+ m_attributes &= ~ParameterAttributes.Optional;
+ }
+ }
+
+ public bool HasDefault {
+ get { return (m_attributes & ParameterAttributes.HasDefault) != 0; }
+ set {
+ if (value)
+ m_attributes |= ParameterAttributes.HasDefault;
+ else
+ m_attributes &= ~ParameterAttributes.HasDefault;
+ }
+ }
+
+ #endregion
+
+ public ParameterDefinition (TypeReference paramType) :
+ this (string.Empty, -1, (ParameterAttributes) 0, paramType)
+ {
+ }
+
+ public override ParameterDefinition Resolve ()
+ {
+ return this;
+ }
+
+ public ParameterDefinition (string name, int seq, ParameterAttributes attrs, TypeReference paramType) : base (name, seq, paramType)
+ {
+ m_attributes = attrs;
+ }
+
+ public ParameterDefinition Clone ()
+ {
+ return Clone (this, new ImportContext (NullReferenceImporter.Instance, m_method));
+ }
+
+ internal static ParameterDefinition Clone (ParameterDefinition param, ImportContext context)
+ {
+ ParameterDefinition np = new ParameterDefinition (
+ param.Name,
+ param.Sequence,
+ param.Attributes,
+ context.Import (param.ParameterType));
+
+ if (param.HasConstant)
+ np.Constant = param.Constant;
+
+ if (param.MarshalSpec != null)
+ np.MarshalSpec = param.MarshalSpec.CloneInto (np);
+
+ foreach (CustomAttribute ca in param.CustomAttributes)
+ np.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
+
+ return np;
+ }
+
+ public override void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitParameterDefinition (this);
+
+ if (this.MarshalSpec != null)
+ this.MarshalSpec.Accept (visitor);
+
+ this.CustomAttributes.Accept (visitor);
+ }
+ }
+}
--- /dev/null
+//
+// ParameterDefinitionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:52 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class ParameterDefinitionCollection : CollectionBase, IReflectionVisitable {
+
+ IMemberReference m_container;
+
+ public ParameterDefinition this [int index] {
+ get { return List [index] as ParameterDefinition; }
+ set { List [index] = value; }
+ }
+
+ public IMemberReference Container {
+ get { return m_container; }
+ }
+
+ public ParameterDefinitionCollection (IMemberReference container)
+ {
+ m_container = container;
+ }
+
+ public void Add (ParameterDefinition value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (ParameterDefinition value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (ParameterDefinition value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, ParameterDefinition value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (ParameterDefinition value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is ParameterDefinition))
+ throw new ArgumentException ("Must be of type " + typeof (ParameterDefinition).FullName);
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitParameterDefinitionCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// ParameterReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ using Mono.Cecil.Metadata;
+
+ internal abstract class ParameterReference : IMetadataTokenProvider, IAnnotationProvider, IReflectionVisitable {
+
+ string m_name;
+ int m_sequence;
+ TypeReference m_paramType;
+ MetadataToken m_token;
+ IDictionary m_annotations;
+
+ public string Name {
+ get { return m_name; }
+ set { m_name = value; }
+ }
+
+ public int Sequence {
+ get { return m_sequence; }
+ set { m_sequence = value; }
+ }
+
+ public TypeReference ParameterType {
+ get { return m_paramType; }
+ set { m_paramType = value; }
+ }
+
+ public MetadataToken MetadataToken {
+ get { return m_token; }
+ set { m_token = value; }
+ }
+
+ IDictionary IAnnotationProvider.Annotations {
+ get {
+ if (m_annotations == null)
+ m_annotations = new Hashtable ();
+ return m_annotations;
+ }
+ }
+
+ public ParameterReference (string name, int sequence, TypeReference parameterType)
+ {
+ m_name = name;
+ m_sequence = sequence;
+ m_paramType = parameterType;
+ }
+
+ public abstract ParameterDefinition Resolve ();
+
+ public override string ToString ()
+ {
+ if (m_name != null && m_name.Length > 0)
+ return m_name;
+
+ return string.Concat ("A_", m_sequence);
+ }
+
+ public abstract void Accept (IReflectionVisitor visitor);
+ }
+}
--- /dev/null
+//
+// PinnedType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class PinnedType : TypeSpecification {
+
+ public PinnedType (TypeReference pType) : base (pType)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// PointerType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class PointerType : TypeSpecification {
+
+ public override string Name {
+ get { return string.Concat (base.Name, "*"); }
+ }
+
+ public override string FullName {
+ get { return string.Concat (base.FullName, "*"); }
+ }
+
+ public PointerType (TypeReference pType) : base (pType)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// PropertyAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum PropertyAttributes : ushort {
+ SpecialName = 0x0200, // Property is special
+ RTSpecialName = 0x0400, // Runtime(metadata internal APIs) should check name encoding
+ HasDefault = 0x1000, // Property has default
+ Unused = 0xe9ff // Reserved: shall be zero in a conforming implementation
+ }
+}
--- /dev/null
+//
+// PropertyDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Text;
+
+ internal sealed class PropertyDefinition : PropertyReference,
+ IMemberDefinition, ICustomAttributeProvider, IHasConstant {
+
+ PropertyAttributes m_attributes;
+
+ CustomAttributeCollection m_customAttrs;
+
+ MethodDefinition m_getMeth;
+ MethodDefinition m_setMeth;
+
+ bool m_hasConstant;
+ object m_const;
+
+ public PropertyAttributes Attributes {
+ get { return m_attributes; }
+ set { m_attributes = value; }
+ }
+
+ public bool HasCustomAttributes {
+ get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
+ }
+
+ public CustomAttributeCollection CustomAttributes {
+ get {
+ if (m_customAttrs == null)
+ m_customAttrs = new CustomAttributeCollection (this);
+
+ return m_customAttrs;
+ }
+ }
+
+ public override bool HasParameters {
+ get {
+ if (m_getMeth != null)
+ return m_getMeth.HasParameters;
+ else if (m_setMeth != null)
+ return m_setMeth.HasParameters;
+ else if (m_parameters == null)
+ return false;
+ else
+ return m_parameters.Count > 0;
+ }
+ }
+
+ public override ParameterDefinitionCollection Parameters {
+ get {
+ if (this.GetMethod != null)
+ return CloneParameterCollection (this.GetMethod.Parameters);
+ else if (this.SetMethod != null) {
+ ParameterDefinitionCollection parameters =
+ CloneParameterCollection (this.SetMethod.Parameters);
+ if (parameters.Count > 0)
+ parameters.RemoveAt (parameters.Count - 1);
+ return parameters;
+ }
+
+ if (m_parameters == null)
+ m_parameters = new ParameterDefinitionCollection (this);
+
+ return m_parameters;
+ }
+ }
+
+ public MethodDefinition GetMethod {
+ get { return m_getMeth; }
+ set { m_getMeth = value; }
+ }
+
+ public MethodDefinition SetMethod {
+ get { return m_setMeth; }
+ set { m_setMeth = value; }
+ }
+
+ ParameterDefinitionCollection CloneParameterCollection (ParameterDefinitionCollection original)
+ {
+ ParameterDefinitionCollection clone = new ParameterDefinitionCollection (
+ original.Container);
+ foreach (ParameterDefinition param in original)
+ clone.Add (param);
+ return clone;
+ }
+
+ public bool HasConstant {
+ get { return m_hasConstant; }
+ }
+
+ public object Constant {
+ get { return m_const; }
+ set {
+ m_hasConstant = true;
+ m_const = value;
+ }
+ }
+
+ #region PropertyAttributes
+
+ public bool IsSpecialName {
+ get { return (m_attributes & PropertyAttributes.SpecialName) != 0; }
+ set {
+ if (value)
+ m_attributes |= PropertyAttributes.SpecialName;
+ else
+ m_attributes &= ~PropertyAttributes.SpecialName;
+ }
+ }
+
+ public bool IsRuntimeSpecialName {
+ get { return (m_attributes & PropertyAttributes.RTSpecialName) != 0; }
+ set {
+ if (value)
+ m_attributes |= PropertyAttributes.RTSpecialName;
+ else
+ m_attributes &= ~PropertyAttributes.RTSpecialName;
+ }
+ }
+
+ public bool HasDefault {
+ get { return (m_attributes & PropertyAttributes.HasDefault) != 0; }
+ set {
+ if (value)
+ m_attributes |= PropertyAttributes.HasDefault;
+ else
+ m_attributes &= ~PropertyAttributes.HasDefault;
+ }
+ }
+
+ #endregion
+
+ public new TypeDefinition DeclaringType {
+ get { return (TypeDefinition) base.DeclaringType; }
+ set { base.DeclaringType = value; }
+ }
+
+ public PropertyDefinition (string name, TypeReference propertyType, PropertyAttributes attrs) : base (name, propertyType)
+ {
+ m_attributes = attrs;
+ }
+
+ public override PropertyDefinition Resolve ()
+ {
+ return this;
+ }
+
+ public static MethodDefinition CreateGetMethod (PropertyDefinition prop)
+ {
+ MethodDefinition get = new MethodDefinition (
+ string.Concat ("get_", prop.Name), (MethodAttributes) 0, prop.PropertyType);
+ prop.GetMethod = get;
+ return get;
+ }
+
+ public static MethodDefinition CreateSetMethod (PropertyDefinition prop)
+ {
+ MethodDefinition set = new MethodDefinition (
+ string.Concat ("set_", prop.Name), (MethodAttributes) 0, prop.PropertyType);
+ prop.SetMethod = set;
+ return set;
+ }
+
+ public PropertyDefinition Clone ()
+ {
+ return Clone (this, new ImportContext (NullReferenceImporter.Instance, this.DeclaringType));
+ }
+
+ internal static PropertyDefinition Clone (PropertyDefinition prop, ImportContext context)
+ {
+ PropertyDefinition np = new PropertyDefinition (
+ prop.Name,
+ context.Import (prop.PropertyType),
+ prop.Attributes);
+
+ if (prop.HasConstant)
+ np.Constant = prop.Constant;
+
+ if (context.GenericContext.Type is TypeDefinition) {
+ TypeDefinition type = context.GenericContext.Type as TypeDefinition;
+ if (prop.SetMethod != null)
+ np.SetMethod = type.Methods.GetMethod (prop.SetMethod.Name, prop.SetMethod.Parameters);
+ if (prop.GetMethod != null)
+ np.GetMethod = type.Methods.GetMethod (prop.GetMethod.Name, prop.GetMethod.Parameters);
+ }
+
+ foreach (CustomAttribute ca in prop.CustomAttributes)
+ np.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
+
+ return np;
+ }
+
+ public override string ToString ()
+ {
+ StringBuilder sb = new StringBuilder ();
+ sb.Append (PropertyType.ToString ());
+ sb.Append (' ');
+
+ if (this.DeclaringType != null) {
+ sb.Append (this.DeclaringType.ToString ());
+ sb.Append ("::");
+ }
+
+ sb.Append (this.Name);
+ sb.Append ('(');
+ ParameterDefinitionCollection parameters = this.Parameters;
+ for (int i = 0; i < parameters.Count; i++) {
+ if (i > 0)
+ sb.Append (',');
+ sb.Append (parameters [i].ParameterType.ToString ());
+ }
+ sb.Append (')');
+ return sb.ToString ();
+ }
+
+ public override void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitPropertyDefinition (this);
+
+ this.CustomAttributes.Accept (visitor);
+ }
+ }
+}
--- /dev/null
+//
+// PropertyDefinitionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Mar 30 18:43:57 +0200 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class PropertyDefinitionCollection : CollectionBase, IReflectionVisitable {
+
+ TypeDefinition m_container;
+
+ public PropertyDefinition this [int index] {
+ get { return List [index] as PropertyDefinition; }
+ set { List [index] = value; }
+ }
+
+ public TypeDefinition Container {
+ get { return m_container; }
+ }
+
+ public PropertyDefinitionCollection (TypeDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (PropertyDefinition value)
+ {
+ Attach (value);
+
+ List.Add (value);
+ }
+
+
+ public new void Clear ()
+ {
+ foreach (PropertyDefinition item in this)
+ Detach (item);
+
+ base.Clear ();
+ }
+
+ public bool Contains (PropertyDefinition value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (PropertyDefinition value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, PropertyDefinition value)
+ {
+ Attach (value);
+
+ List.Insert (index, value);
+ }
+
+ public void Remove (PropertyDefinition value)
+ {
+ List.Remove (value);
+
+ Detach (value);
+ }
+
+
+ public new void RemoveAt (int index)
+ {
+ PropertyDefinition item = this [index];
+ Remove (item);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is PropertyDefinition))
+ throw new ArgumentException ("Must be of type " + typeof (PropertyDefinition).FullName);
+ }
+
+ public PropertyDefinition [] GetProperties (string name)
+ {
+ ArrayList ret = new ArrayList ();
+ foreach (PropertyDefinition prop in this)
+ if (prop.Name == name)
+ ret.Add (prop);
+
+ return ret.ToArray (typeof (PropertyDefinition)) as PropertyDefinition [];
+ }
+
+ void Attach (MemberReference member)
+ {
+ if (member.DeclaringType != null)
+ throw new ReflectionException ("Member already attached, clone it instead");
+
+ member.DeclaringType = m_container;
+ }
+
+ void Detach (MemberReference member)
+ {
+ member.DeclaringType = null;
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitPropertyDefinitionCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// PropertyReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal abstract class PropertyReference : MemberReference {
+
+ TypeReference m_propertyType;
+ protected ParameterDefinitionCollection m_parameters;
+
+ public TypeReference PropertyType {
+ get { return m_propertyType; }
+ set { m_propertyType = value; }
+ }
+
+ public abstract bool HasParameters {
+ get;
+ }
+
+ public abstract ParameterDefinitionCollection Parameters {
+ get;
+ }
+
+ public PropertyReference (string name, TypeReference propertyType) : base (name)
+ {
+ m_propertyType = propertyType;
+ }
+
+ public abstract PropertyDefinition Resolve ();
+ }
+}
--- /dev/null
+//
+// ReferenceType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class ReferenceType : TypeSpecification {
+
+ public override string Name {
+ get { return string.Concat (base.Name, "&"); }
+ }
+
+ public override string FullName {
+ get { return string.Concat (base.FullName, "&"); }
+ }
+
+ public ReferenceType (TypeReference type) : base (type)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// ReflectionController.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class ReflectionController {
+
+ ReflectionReader m_reader;
+ ReflectionWriter m_writer;
+ ReflectionHelper m_helper;
+ DefaultImporter m_importer;
+
+ public ReflectionReader Reader {
+ get { return m_reader; }
+ }
+
+ public ReflectionWriter Writer {
+ get { return m_writer; }
+ }
+
+ public ReflectionHelper Helper {
+ get { return m_helper; }
+ }
+
+ public IImporter Importer {
+ get { return m_importer; }
+ }
+
+ public ReflectionController (ModuleDefinition module)
+ {
+ m_reader = new AggressiveReflectionReader (module);
+ m_writer = new ReflectionWriter (module);
+ m_helper = new ReflectionHelper (module);
+ m_importer = new DefaultImporter (module);
+ }
+ }
+}
--- /dev/null
+//
+// ReflectionException.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ using Mono.Cecil.Metadata;
+
+ internal sealed class ReflectionException : MetadataFormatException {
+
+ internal ReflectionException () : base ()
+ {
+ }
+
+ internal ReflectionException (string message) : base (message)
+ {
+ }
+
+ internal ReflectionException (string message, params string [] parameters) :
+ base (string.Format (message, parameters))
+ {
+ }
+
+ internal ReflectionException (string message, Exception inner) :
+ base (message, inner)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// ReflectionHelper.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+// (C) 2006 Evaluant RC S.A.
+// (C) 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+ using SR = System.Reflection;
+ using System.Text;
+
+ internal sealed class ReflectionHelper {
+
+ ModuleDefinition m_module;
+
+ public ReflectionHelper (ModuleDefinition module)
+ {
+ m_module = module;
+ }
+
+ public AssemblyNameReference ImportAssembly (SR.Assembly asm)
+ {
+ AssemblyNameReference asmRef = GetAssemblyNameReference (asm.GetName ());
+ if (asmRef != null)
+ return asmRef;
+
+ SR.AssemblyName asmName = asm.GetName ();
+ asmRef = new AssemblyNameReference (
+ asmName.Name, asmName.CultureInfo.Name, asmName.Version);
+ asmRef.PublicKeyToken = asmName.GetPublicKeyToken ();
+ asmRef.HashAlgorithm = (AssemblyHashAlgorithm) asmName.HashAlgorithm;
+ asmRef.Culture = asmName.CultureInfo.ToString ();
+ m_module.AssemblyReferences.Add (asmRef);
+ return asmRef;
+ }
+
+ AssemblyNameReference GetAssemblyNameReference (SR.AssemblyName name)
+ {
+ foreach (AssemblyNameReference reference in m_module.AssemblyReferences)
+ if (reference.FullName == name.FullName)
+ return reference;
+
+ return null;
+ }
+
+ public static string GetTypeSignature (Type t)
+ {
+ if (t.HasElementType) {
+ if (t.IsPointer)
+ return string.Concat (GetTypeSignature (t.GetElementType ()), "*");
+ else if (t.IsArray) {
+ int rank = t.GetArrayRank ();
+ if (rank == 1)
+ return string.Concat (GetTypeSignature (t.GetElementType ()), "[]");
+
+ StringBuilder sb = new StringBuilder ();
+ sb.Append ('[');
+ for (int i = 1; i < rank; i++)
+ sb.Append (',');
+ sb.Append (']');
+
+ return string.Concat (GetTypeSignature (t.GetElementType ()), sb.ToString ());
+ } else if (t.IsByRef)
+ return string.Concat(GetTypeSignature(t.GetElementType()), "&");
+ }
+
+ if (IsGenericTypeSpec (t)) {
+ StringBuilder sb = new StringBuilder ();
+ sb.Append (GetTypeSignature (GetGenericTypeDefinition (t)));
+ sb.Append ("<");
+ Type [] genArgs = GetGenericArguments (t);
+ for (int i = 0; i < genArgs.Length; i++) {
+ if (i > 0)
+ sb.Append (",");
+ sb.Append (GetTypeSignature (genArgs [i]));
+ }
+ sb.Append (">");
+ return sb.ToString ();
+ }
+
+ if (IsGenericParameter (t))
+ return t.Name;
+
+ if (t.DeclaringType != null)
+ return string.Concat (t.DeclaringType.FullName, "/", t.Name);
+
+ if (t.Namespace == null || t.Namespace.Length == 0)
+ return t.Name;
+
+ return string.Concat (t.Namespace, ".", t.Name);
+ }
+
+ static bool GetProperty (object o, string prop)
+ {
+ SR.PropertyInfo pi = o.GetType ().GetProperty (prop);
+ if (pi == null)
+ return false;
+
+ return (bool) pi.GetValue (o, null);
+ }
+
+ public static bool IsGenericType (Type t)
+ {
+ return GetProperty (t, "IsGenericType");
+ }
+
+ static bool IsGenericParameter (Type t)
+ {
+ return GetProperty (t, "IsGenericParameter");
+ }
+
+ static bool IsGenericTypeDefinition (Type t)
+ {
+ return GetProperty (t, "IsGenericTypeDefinition");
+ }
+
+ static bool IsGenericTypeSpec (Type t)
+ {
+ return IsGenericType (t) && !IsGenericTypeDefinition (t);
+ }
+
+ static Type GetGenericTypeDefinition (Type t)
+ {
+ return (Type) t.GetType ().GetMethod ("GetGenericTypeDefinition").Invoke (t, null);
+ }
+
+ static Type [] GetGenericArguments (Type t)
+ {
+ return (Type []) t.GetType ().GetMethod ("GetGenericArguments").Invoke (t, null);
+ }
+
+ GenericInstanceType GetGenericType (Type t, TypeReference element, ImportContext context)
+ {
+ GenericInstanceType git = new GenericInstanceType (element);
+ foreach (Type genArg in GetGenericArguments (t))
+ git.GenericArguments.Add (ImportSystemType (genArg, context));
+
+ return git;
+ }
+
+ static bool GenericParameterOfMethod (Type t)
+ {
+ return t.GetType ().GetProperty ("DeclaringMethod").GetValue (t, null) != null;
+ }
+
+ static GenericParameter GetGenericParameter (Type t, ImportContext context)
+ {
+ int pos = (int) t.GetType ().GetProperty ("GenericParameterPosition").GetValue (t, null);
+ IGenericParameterProvider provider;
+ if (GenericParameterOfMethod (t))
+ provider = context.GenericContext.Method;
+ else
+ provider = context.GenericContext.Type;
+
+ if (provider == null)
+ throw new InvalidOperationException ("Invalid context");
+
+ return provider.GenericParameters [pos];
+ }
+
+ TypeReference GetTypeSpec (Type t, ImportContext context)
+ {
+ Stack s = new Stack ();
+ while (t.HasElementType || IsGenericTypeSpec (t)) {
+ s.Push (t);
+ if (t.HasElementType)
+ t = t.GetElementType ();
+ else if (IsGenericTypeSpec (t)) {
+ t = (Type) t.GetType ().GetMethod ("GetGenericTypeDefinition").Invoke (t, null);
+ break;
+ }
+ }
+
+ TypeReference elementType = ImportSystemType (t, context);
+ while (s.Count > 0) {
+ t = (Type) s.Pop ();
+ if (t.IsPointer)
+ elementType = new PointerType (elementType);
+ else if (t.IsArray)
+ elementType = new ArrayType (elementType, t.GetArrayRank ());
+ else if (t.IsByRef)
+ elementType = new ReferenceType (elementType);
+ else if (IsGenericTypeSpec (t))
+ elementType = GetGenericType (t, elementType, context);
+ else
+ throw new ReflectionException ("Unknown element type");
+ }
+
+ return elementType;
+ }
+
+ TypeReference AdjustReference (Type type, TypeReference reference)
+ {
+ if (type.IsValueType && !reference.IsValueType)
+ reference.IsValueType = true;
+
+ if (IsGenericTypeDefinition (type)) {
+ Type [] parameters = GetGenericArguments (type);
+ for (int i = reference.GenericParameters.Count; i < parameters.Length; i++)
+ reference.GenericParameters.Add (new GenericParameter (i, reference));
+ }
+
+ return reference;
+ }
+
+ public TypeReference ImportSystemType (Type t, ImportContext context)
+ {
+ if (t.HasElementType || IsGenericTypeSpec (t))
+ return GetTypeSpec (t, context);
+
+ if (IsGenericParameter (t))
+ return GetGenericParameter (t, context);
+
+ TypeReference type = m_module.TypeReferences [GetTypeSignature (t)];
+ if (type != null)
+ return AdjustReference (t, type);
+
+ AssemblyNameReference asm = ImportAssembly (t.Assembly);
+ if (t.DeclaringType != null) {
+ type = new TypeReference (t.Name, string.Empty, asm, t.IsValueType);
+ type.DeclaringType = ImportSystemType (t.DeclaringType, context);
+ } else
+ type = new TypeReference (t.Name, t.Namespace, asm, t.IsValueType);
+
+ if (IsGenericTypeDefinition (t))
+ foreach (Type genParam in GetGenericArguments (t))
+ type.GenericParameters.Add (new GenericParameter (genParam.Name, type));
+
+ context.GenericContext.Type = type;
+
+ m_module.TypeReferences.Add (type);
+ return type;
+ }
+
+ static string GetMethodBaseSignature (SR.MethodBase meth, Type declaringType, Type retType)
+ {
+ StringBuilder sb = new StringBuilder ();
+ sb.Append (GetTypeSignature (retType));
+ sb.Append (' ');
+ sb.Append (GetTypeSignature (declaringType));
+ sb.Append ("::");
+ sb.Append (meth.Name);
+ if (IsGenericMethodSpec (meth)) {
+ sb.Append ("<");
+ Type [] genArgs = GetGenericArguments (meth as SR.MethodInfo);
+ for (int i = 0; i < genArgs.Length; i++) {
+ if (i > 0)
+ sb.Append (",");
+ sb.Append (GetTypeSignature (genArgs [i]));
+ }
+ sb.Append (">");
+ }
+ sb.Append ("(");
+ SR.ParameterInfo [] parameters = meth.GetParameters ();
+ for (int i = 0; i < parameters.Length; i++) {
+ if (i > 0)
+ sb.Append (",");
+ sb.Append (GetTypeSignature (parameters [i].ParameterType));
+ }
+ sb.Append (")");
+ return sb.ToString ();
+ }
+
+ static bool IsGenericMethod (SR.MethodBase mb)
+ {
+ return GetProperty (mb, "IsGenericMethod");
+ }
+
+ static bool IsGenericMethodDefinition (SR.MethodBase mb)
+ {
+ return GetProperty (mb, "IsGenericMethodDefinition");
+ }
+
+ static bool IsGenericMethodSpec (SR.MethodBase mb)
+ {
+ return IsGenericMethod (mb) && !IsGenericMethodDefinition (mb);
+ }
+
+ static Type [] GetGenericArguments (SR.MethodInfo mi)
+ {
+ return (Type []) mi.GetType ().GetMethod ("GetGenericArguments").Invoke (mi, null);
+ }
+
+ static int GetMetadataToken (SR.MethodInfo mi)
+ {
+ return (int) mi.GetType ().GetProperty ("MetadataToken").GetValue (mi, null);
+ }
+
+ MethodReference ImportGenericInstanceMethod (SR.MethodInfo mi, ImportContext context)
+ {
+ SR.MethodInfo gmd = (SR.MethodInfo) mi.GetType ().GetMethod ("GetGenericMethodDefinition").Invoke (mi, null);
+ GenericInstanceMethod gim = new GenericInstanceMethod (
+ ImportMethodBase (gmd, gmd.ReturnType, context));
+
+ foreach (Type genArg in GetGenericArguments (mi))
+ gim.GenericArguments.Add (ImportSystemType (genArg, context));
+
+ return gim;
+ }
+
+ MethodReference ImportMethodBase (SR.MethodBase mb, Type retType, ImportContext context)
+ {
+ if (IsGenericMethod (mb) && !IsGenericMethodDefinition (mb))
+ return ImportGenericInstanceMethod ((SR.MethodInfo) mb, context);
+
+ Type originalDecType = mb.DeclaringType;
+ Type declaringTypeDef = originalDecType;
+ while (IsGenericTypeSpec (declaringTypeDef))
+ declaringTypeDef = GetGenericTypeDefinition (declaringTypeDef);
+
+ if (mb.DeclaringType != declaringTypeDef && mb is SR.MethodInfo) {
+ int mt = GetMetadataToken (mb as SR.MethodInfo);
+ // hack to get the generic method definition from the constructed method
+ foreach (SR.MethodInfo mi in declaringTypeDef.GetMethods ()) {
+ if (GetMetadataToken (mi) == mt) {
+ mb = mi;
+ retType = mi.ReturnType;
+ break;
+ }
+ }
+ }
+
+ string sig = GetMethodBaseSignature (mb, originalDecType, retType);
+ MethodReference meth = (MethodReference) GetMemberReference (sig);
+ if (meth != null)
+ return meth;
+
+ meth = new MethodReference (
+ mb.Name,
+ (mb.CallingConvention & SR.CallingConventions.HasThis) > 0,
+ (mb.CallingConvention & SR.CallingConventions.ExplicitThis) > 0,
+ MethodCallingConvention.Default); // TODO: get the real callconv
+ meth.DeclaringType = ImportSystemType (originalDecType, context);
+
+ if (IsGenericMethod (mb))
+ foreach (Type genParam in GetGenericArguments (mb as SR.MethodInfo))
+ meth.GenericParameters.Add (new GenericParameter (genParam.Name, meth));
+
+ TypeReference contextType = context.GenericContext.Type;
+ MethodReference contextMethod = context.GenericContext.Method;
+
+ context.GenericContext.Method = meth;
+ context.GenericContext.Type = ImportSystemType (declaringTypeDef, context);
+
+ meth.ReturnType.ReturnType = ImportSystemType (retType, context);
+
+ SR.ParameterInfo [] parameters = mb.GetParameters ();
+ for (int i = 0; i < parameters.Length; i++)
+ meth.Parameters.Add (new ParameterDefinition (
+ ImportSystemType (parameters [i].ParameterType, context)));
+
+ context.GenericContext.Type = contextType;
+ context.GenericContext.Method = contextMethod;
+
+ m_module.MemberReferences.Add (meth);
+ return meth;
+ }
+
+ public MethodReference ImportConstructorInfo (SR.ConstructorInfo ci, ImportContext context)
+ {
+ return ImportMethodBase (ci, typeof (void), context);
+ }
+
+ public MethodReference ImportMethodInfo (SR.MethodInfo mi, ImportContext context)
+ {
+ return ImportMethodBase (mi, mi.ReturnType, context);
+ }
+
+ static string GetFieldSignature (SR.FieldInfo field)
+ {
+ StringBuilder sb = new StringBuilder ();
+ sb.Append (GetTypeSignature (field.FieldType));
+ sb.Append (' ');
+ sb.Append (GetTypeSignature (field.DeclaringType));
+ sb.Append ("::");
+ sb.Append (field.Name);
+ return sb.ToString ();
+ }
+
+ public FieldReference ImportFieldInfo (SR.FieldInfo fi, ImportContext context)
+ {
+ string sig = GetFieldSignature (fi);
+ FieldReference f = (FieldReference) GetMemberReference (sig);
+ if (f != null)
+ return f;
+
+ f = new FieldReference (
+ fi.Name,
+ ImportSystemType (fi.DeclaringType, context),
+ ImportSystemType (fi.FieldType, context));
+
+ m_module.MemberReferences.Add (f);
+ return f;
+ }
+
+ MemberReference GetMemberReference (string signature)
+ {
+ foreach (MemberReference reference in m_module.MemberReferences)
+ if (reference.ToString () == signature)
+ return reference;
+
+ return null;
+ }
+ }
+}
--- /dev/null
+//
+// ReflectionReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.IO;
+ using System.Text;
+
+ using Mono.Cecil.Binary;
+ using Mono.Cecil.Cil;
+ using Mono.Cecil.Metadata;
+ using Mono.Cecil.Signatures;
+
+ internal abstract class ReflectionReader : BaseReflectionReader {
+
+ ModuleDefinition m_module;
+ ImageReader m_reader;
+ SecurityDeclarationReader m_secReader;
+ protected MetadataTableReader m_tableReader;
+ protected MetadataRoot m_root;
+ protected TablesHeap m_tHeap;
+ protected bool m_checkDeleted;
+
+ protected TypeDefinition [] m_typeDefs;
+ protected TypeReference [] m_typeRefs;
+ protected TypeReference [] m_typeSpecs;
+ protected MethodDefinition [] m_meths;
+ protected FieldDefinition [] m_fields;
+ protected EventDefinition [] m_events;
+ protected PropertyDefinition [] m_properties;
+ protected MemberReference [] m_memberRefs;
+ protected ParameterDefinition [] m_parameters;
+ protected GenericParameter [] m_genericParameters;
+ protected GenericInstanceMethod [] m_methodSpecs;
+
+ bool m_isCorlib;
+ AssemblyNameReference m_corlib;
+
+ protected SignatureReader m_sigReader;
+ protected CodeReader m_codeReader;
+ protected ISymbolReader m_symbolReader;
+
+ internal AssemblyNameReference Corlib {
+ get {
+ if (m_corlib != null)
+ return m_corlib;
+
+ foreach (AssemblyNameReference ar in m_module.AssemblyReferences) {
+ if (ar.Name == Constants.Corlib) {
+ m_corlib = ar;
+ return m_corlib;
+ }
+ }
+
+ return null;
+ }
+ }
+
+ public ModuleDefinition Module {
+ get { return m_module; }
+ }
+
+ public SignatureReader SigReader {
+ get { return m_sigReader; }
+ }
+
+ public MetadataTableReader TableReader {
+ get { return m_tableReader; }
+ }
+
+ public CodeReader Code {
+ get { return m_codeReader; }
+ }
+
+ public ISymbolReader SymbolReader {
+ get { return m_symbolReader; }
+ set { m_symbolReader = value; }
+ }
+
+ public MetadataRoot MetadataRoot {
+ get { return m_root; }
+ }
+
+ public ReflectionReader (ModuleDefinition module)
+ {
+ m_module = module;
+ m_reader = m_module.ImageReader;
+ m_root = m_module.Image.MetadataRoot;
+ m_tHeap = m_root.Streams.TablesHeap;
+ m_checkDeleted = (m_tHeap.HeapSizes & 0x80) != 0;
+ if (m_reader != null)
+ m_tableReader = m_reader.MetadataReader.TableReader;
+ m_codeReader = new CodeReader (this);
+ m_sigReader = new SignatureReader (m_root, this);
+ m_isCorlib = module.Assembly.Name.Name == Constants.Corlib;
+ }
+
+ public TypeDefinition GetTypeDefAt (uint rid)
+ {
+ if (rid > m_typeDefs.Length)
+ return null;
+
+ return m_typeDefs [rid - 1];
+ }
+
+ public TypeReference GetTypeRefAt (uint rid)
+ {
+ if (rid > m_typeRefs.Length)
+ return null;
+
+ return m_typeRefs [rid - 1];
+ }
+
+ public TypeReference GetTypeSpecAt (uint rid, GenericContext context)
+ {
+ if (rid > m_typeSpecs.Length)
+ return null;
+
+ int index = (int) rid - 1;
+
+ TypeSpecTable tsTable = m_tableReader.GetTypeSpecTable ();
+ TypeSpecRow tsRow = tsTable [index];
+ TypeSpec ts = m_sigReader.GetTypeSpec (tsRow.Signature);
+
+ // don't cache context dependent generic stuff
+ if (IsGenericTypeSpec (ts.Type.ElementType))
+ return CreateTypeSpecFromSig (ts, index, context);
+
+ TypeReference tspec = m_typeSpecs [index];
+ if (tspec != null)
+ return tspec;
+
+ tspec = CreateTypeSpecFromSig (ts, index, context);
+ m_typeSpecs [index] = tspec;
+
+ return tspec;
+ }
+
+ static bool IsGenericTypeSpec (ElementType etype)
+ {
+ return etype == ElementType.GenericInst
+ || etype == ElementType.Var
+ || etype == ElementType.MVar;
+ }
+
+ TypeReference CreateTypeSpecFromSig (TypeSpec ts, int index, GenericContext context)
+ {
+ TypeReference tspec = GetTypeRefFromSig (ts.Type, context);
+ tspec = GetModifierType (ts.CustomMods, tspec);
+ tspec.MetadataToken = MetadataToken.FromMetadataRow (TokenType.TypeSpec, index);
+ return tspec;
+ }
+
+ public FieldDefinition GetFieldDefAt (uint rid)
+ {
+ if (rid > m_fields.Length)
+ return null;
+
+ return m_fields [rid - 1];
+ }
+
+ public MethodDefinition GetMethodDefAt (uint rid)
+ {
+ if (rid > m_meths.Length)
+ return null;
+
+ return m_meths [rid - 1];
+ }
+
+ protected bool IsDeleted (IMemberDefinition member)
+ {
+ if (!m_checkDeleted)
+ return false;
+
+ if (!member.IsSpecialName || !member.IsRuntimeSpecialName)
+ return false;
+
+ return member.Name.StartsWith (Constants.Deleted);
+ }
+
+ public MemberReference GetMemberRefAt (uint rid, GenericContext context)
+ {
+ if (rid > m_memberRefs.Length)
+ return null;
+
+ int index = (int) rid - 1;
+ MemberReference member = m_memberRefs [index];
+ if (member != null)
+ return member;
+
+ MemberRefTable mrTable = m_tableReader.GetMemberRefTable ();
+ MemberRefRow mrefRow = mrTable [index];
+
+ Signature sig = m_sigReader.GetMemberRefSig (mrefRow.Class.TokenType, mrefRow.Signature);
+ switch (mrefRow.Class.TokenType) {
+ case TokenType.TypeDef :
+ case TokenType.TypeRef :
+ case TokenType.TypeSpec :
+ TypeReference declaringType = GetTypeDefOrRef (mrefRow.Class, context);
+ GenericContext nc = context.Clone ();
+
+ if (declaringType is GenericInstanceType) {
+ TypeReference ct = declaringType;
+ while (ct is GenericInstanceType)
+ ct = (ct as GenericInstanceType).ElementType;
+
+ nc.Type = ct;
+ }
+
+ if (sig is FieldSig) {
+ FieldSig fs = sig as FieldSig;
+ TypeReference fieldType = GetTypeRefFromSig (fs.Type, nc);
+ fieldType = GetModifierType (fs.CustomMods, fieldType);
+
+ member = new FieldReference (
+ m_root.Streams.StringsHeap [mrefRow.Name],
+ declaringType,
+ fieldType);
+ } else {
+ string name = m_root.Streams.StringsHeap [mrefRow.Name];
+ MethodSig ms = (MethodSig) sig;
+
+ member = CreateMethodReferenceFromSig (ms, name, declaringType, nc);
+ }
+ break;
+ case TokenType.Method :
+ // really not sure about this
+ MethodDefinition methdef = GetMethodDefAt (mrefRow.Class.RID);
+
+ member = CreateMethodReferenceFromSig ((MethodSig) sig, methdef.Name, methdef.DeclaringType, new GenericContext ());
+ break;
+ case TokenType.ModuleRef :
+ break; // TODO, implement that, or not
+ }
+
+ member.MetadataToken = MetadataToken.FromMetadataRow (TokenType.MemberRef, index);
+ m_module.MemberReferences.Add (member);
+ m_memberRefs [index] = member;
+
+ return member;
+ }
+
+ MethodReference CreateMethodReferenceFromSig (MethodSig ms, string name, TypeReference declaringType, GenericContext context)
+ {
+ MethodReference methref = new MethodReference (
+ name, ms.HasThis, ms.ExplicitThis, ms.MethCallConv);
+ methref.DeclaringType = declaringType;
+
+ if (ms is MethodDefSig) {
+ int arity = (ms as MethodDefSig).GenericParameterCount;
+ for (int i = 0; i < arity; i++)
+ methref.GenericParameters.Add (new GenericParameter (i, methref));
+ }
+
+ if (methref.GenericParameters.Count > 0)
+ context.Method = methref;
+
+ methref.ReturnType = GetMethodReturnType (ms, context);
+
+ methref.ReturnType.Method = methref;
+ for (int j = 0; j < ms.ParamCount; j++) {
+ Param p = ms.Parameters [j];
+ ParameterDefinition pdef = BuildParameterDefinition (j, p, context);
+ pdef.Method = methref;
+ methref.Parameters.Add (pdef);
+ }
+
+ CreateSentinelIfNeeded (methref, ms);
+
+ return methref;
+ }
+
+ public static void CreateSentinelIfNeeded (IMethodSignature meth, MethodSig signature)
+ {
+ MethodDefSig sig = signature as MethodDefSig;
+ if (sig == null)
+ return;
+
+ int sentinel = sig.Sentinel;
+
+ if (sig.Sentinel < 0 || sig.Sentinel >= meth.Parameters.Count)
+ return;
+
+ ParameterDefinition param = meth.Parameters [sentinel];
+ param.ParameterType = new SentinelType (param.ParameterType);
+ }
+
+ public PropertyDefinition GetPropertyDefAt (uint rid)
+ {
+ if (rid > m_properties.Length)
+ return null;
+
+ return m_properties [rid - 1];
+ }
+
+ public EventDefinition GetEventDefAt (uint rid)
+ {
+ if (rid > m_events.Length)
+ return null;
+
+ return m_events [rid - 1];
+ }
+
+ public ParameterDefinition GetParamDefAt (uint rid)
+ {
+ if (rid > m_parameters.Length)
+ return null;
+
+ return m_parameters [rid - 1];
+ }
+
+ public GenericParameter GetGenericParameterAt (uint rid)
+ {
+ if (rid > m_genericParameters.Length)
+ return null;
+
+ return m_genericParameters [rid - 1];
+ }
+
+ public GenericInstanceMethod GetMethodSpecAt (uint rid, GenericContext context)
+ {
+ if (rid > m_methodSpecs.Length)
+ return null;
+
+ int index = (int) rid - 1;
+ GenericInstanceMethod gim = m_methodSpecs [index];
+ if (gim != null)
+ return gim;
+
+ MethodSpecTable msTable = m_tableReader.GetMethodSpecTable ();
+ MethodSpecRow msRow = msTable [index];
+
+ MethodSpec sig = m_sigReader.GetMethodSpec (msRow.Instantiation);
+
+ MethodReference meth;
+ if (msRow.Method.TokenType == TokenType.Method)
+ meth = GetMethodDefAt (msRow.Method.RID);
+ else if (msRow.Method.TokenType == TokenType.MemberRef)
+ meth = (MethodReference) GetMemberRefAt (msRow.Method.RID, context);
+ else
+ throw new ReflectionException ("Unknown method type for method spec");
+
+ gim = new GenericInstanceMethod (meth);
+ context.CheckProvider (meth, sig.Signature.Arity);
+ foreach (GenericArg arg in sig.Signature.Types)
+ gim.GenericArguments.Add (GetGenericArg (arg, context));
+
+ m_methodSpecs [index] = gim;
+
+ return gim;
+ }
+
+ public TypeReference GetTypeDefOrRef (MetadataToken token, GenericContext context)
+ {
+ if (token.RID == 0)
+ return null;
+
+ switch (token.TokenType) {
+ case TokenType.TypeDef :
+ return GetTypeDefAt (token.RID);
+ case TokenType.TypeRef :
+ return GetTypeRefAt (token.RID);
+ case TokenType.TypeSpec :
+ return GetTypeSpecAt (token.RID, context);
+ default :
+ return null;
+ }
+ }
+
+ public TypeReference SearchCoreType (string fullName)
+ {
+ if (m_isCorlib)
+ return m_module.Types [fullName];
+
+ TypeReference coreType = m_module.TypeReferences [fullName];
+ if (coreType == null) {
+ string [] parts = fullName.Split ('.');
+ if (parts.Length != 2)
+ throw new ReflectionException ("Unvalid core type name");
+ coreType = new TypeReference (parts [1], parts [0], Corlib);
+ m_module.TypeReferences.Add (coreType);
+ }
+ if (!coreType.IsValueType) {
+ switch (coreType.FullName) {
+ case Constants.Boolean :
+ case Constants.Char :
+ case Constants.Single :
+ case Constants.Double :
+ case Constants.SByte :
+ case Constants.Byte :
+ case Constants.Int16 :
+ case Constants.UInt16 :
+ case Constants.Int32 :
+ case Constants.UInt32 :
+ case Constants.Int64 :
+ case Constants.UInt64 :
+ case Constants.IntPtr :
+ case Constants.UIntPtr :
+ coreType.IsValueType = true;
+ break;
+ }
+ }
+ return coreType;
+ }
+
+ public IMetadataTokenProvider LookupByToken (MetadataToken token)
+ {
+ switch (token.TokenType) {
+ case TokenType.TypeDef :
+ return GetTypeDefAt (token.RID);
+ case TokenType.TypeRef :
+ return GetTypeRefAt (token.RID);
+ case TokenType.Method :
+ return GetMethodDefAt (token.RID);
+ case TokenType.Field :
+ return GetFieldDefAt (token.RID);
+ case TokenType.Event :
+ return GetEventDefAt (token.RID);
+ case TokenType.Property :
+ return GetPropertyDefAt (token.RID);
+ case TokenType.Param :
+ return GetParamDefAt (token.RID);
+ default :
+ throw new NotSupportedException ("Lookup is not allowed on this kind of token");
+ }
+ }
+
+ public CustomAttribute GetCustomAttribute (MethodReference ctor, byte [] data, bool resolve)
+ {
+ CustomAttrib sig = m_sigReader.GetCustomAttrib (data, ctor, resolve);
+ return BuildCustomAttribute (ctor, data, sig);
+ }
+
+ public CustomAttribute GetCustomAttribute (MethodReference ctor, byte [] data)
+ {
+ return GetCustomAttribute (ctor, data, false);
+ }
+
+ public override void VisitModuleDefinition (ModuleDefinition mod)
+ {
+ VisitTypeDefinitionCollection (mod.Types);
+ }
+
+ public override void VisitTypeDefinitionCollection (TypeDefinitionCollection types)
+ {
+ // type def reading
+ TypeDefTable typesTable = m_tableReader.GetTypeDefTable ();
+ m_typeDefs = new TypeDefinition [typesTable.Rows.Count];
+ for (int i = 0; i < typesTable.Rows.Count; i++) {
+ TypeDefRow type = typesTable [i];
+ TypeDefinition t = new TypeDefinition (
+ m_root.Streams.StringsHeap [type.Name],
+ m_root.Streams.StringsHeap [type.Namespace],
+ type.Flags);
+ t.MetadataToken = MetadataToken.FromMetadataRow (TokenType.TypeDef, i);
+
+ m_typeDefs [i] = t;
+ }
+
+ // nested types
+ if (m_tHeap.HasTable (NestedClassTable.RId)) {
+ NestedClassTable nested = m_tableReader.GetNestedClassTable ();
+ for (int i = 0; i < nested.Rows.Count; i++) {
+ NestedClassRow row = nested [i];
+
+ TypeDefinition parent = GetTypeDefAt (row.EnclosingClass);
+ TypeDefinition child = GetTypeDefAt (row.NestedClass);
+
+ if (!IsDeleted (child))
+ parent.NestedTypes.Add (child);
+ }
+ }
+
+ foreach (TypeDefinition type in m_typeDefs)
+ if (!IsDeleted (type))
+ types.Add (type);
+
+ // type ref reading
+ if (m_tHeap.HasTable (TypeRefTable.RId)) {
+ TypeRefTable typesRef = m_tableReader.GetTypeRefTable ();
+
+ m_typeRefs = new TypeReference [typesRef.Rows.Count];
+
+ for (int i = 0; i < typesRef.Rows.Count; i++)
+ AddTypeRef (typesRef, i);
+ } else
+ m_typeRefs = new TypeReference [0];
+
+ ReadTypeSpecs ();
+ ReadMethodSpecs ();
+
+ ReadMethods ();
+ ReadGenericParameters ();
+
+ // set base types
+ for (int i = 0; i < typesTable.Rows.Count; i++) {
+ TypeDefRow type = typesTable [i];
+ TypeDefinition child = m_typeDefs [i];
+ child.BaseType = GetTypeDefOrRef (type.Extends, new GenericContext (child));
+ }
+
+ CompleteMethods ();
+ ReadAllFields ();
+ ReadMemberReferences ();
+ }
+
+ void AddTypeRef (TypeRefTable typesRef, int i)
+ {
+ if (i >= typesRef.Rows.Count)
+ return;
+
+ // Check if index has been already added.
+ if (m_typeRefs [i] != null)
+ return;
+
+ TypeRefRow type = typesRef [i];
+ IMetadataScope scope = null;
+ TypeReference parent = null;
+
+ if (type.ResolutionScope.RID != 0) {
+ int rid = (int) type.ResolutionScope.RID - 1;
+ switch (type.ResolutionScope.TokenType) {
+ case TokenType.AssemblyRef:
+ scope = m_module.AssemblyReferences [rid];
+ break;
+ case TokenType.ModuleRef:
+ scope = m_module.ModuleReferences [rid];
+ break;
+ case TokenType.Module:
+ scope = m_module.Assembly.Modules [rid];
+ break;
+ case TokenType.TypeRef:
+ AddTypeRef (typesRef, rid);
+ parent = GetTypeRefAt (type.ResolutionScope.RID);
+ if (parent != null)
+ scope = parent.Scope;
+ break;
+ }
+ }
+
+ TypeReference t = new TypeReference (
+ m_root.Streams.StringsHeap [type.Name],
+ m_root.Streams.StringsHeap [type.Namespace],
+ scope);
+ t.MetadataToken = MetadataToken.FromMetadataRow (TokenType.TypeRef, i);
+
+ if (parent != null)
+ t.DeclaringType = parent;
+
+ m_typeRefs [i] = t;
+ m_module.TypeReferences.Add (t);
+ }
+
+ void ReadTypeSpecs ()
+ {
+ if (!m_tHeap.HasTable (TypeSpecTable.RId))
+ return;
+
+ TypeSpecTable tsTable = m_tableReader.GetTypeSpecTable ();
+ m_typeSpecs = new TypeReference [tsTable.Rows.Count];
+ }
+
+ void ReadMethodSpecs ()
+ {
+ if (!m_tHeap.HasTable (MethodSpecTable.RId))
+ return;
+
+ MethodSpecTable msTable = m_tableReader.GetMethodSpecTable ();
+ m_methodSpecs = new GenericInstanceMethod [msTable.Rows.Count];
+ }
+
+ void ReadGenericParameters ()
+ {
+ if (!m_tHeap.HasTable (GenericParamTable.RId))
+ return;
+
+ GenericParamTable gpTable = m_tableReader.GetGenericParamTable ();
+ m_genericParameters = new GenericParameter [gpTable.Rows.Count];
+ for (int i = 0; i < gpTable.Rows.Count; i++) {
+ GenericParamRow gpRow = gpTable [i];
+ IGenericParameterProvider owner;
+ if (gpRow.Owner.TokenType == TokenType.Method)
+ owner = GetMethodDefAt (gpRow.Owner.RID);
+ else if (gpRow.Owner.TokenType == TokenType.TypeDef)
+ owner = GetTypeDefAt (gpRow.Owner.RID);
+ else
+ throw new ReflectionException ("Unknown owner type for generic parameter");
+
+ GenericParameter gp = new GenericParameter (gpRow.Number, owner);
+ gp.Attributes = gpRow.Flags;
+ gp.Name = MetadataRoot.Streams.StringsHeap [gpRow.Name];
+ gp.MetadataToken = MetadataToken.FromMetadataRow (TokenType.GenericParam, i);
+
+ owner.GenericParameters.Add (gp);
+ m_genericParameters [i] = gp;
+ }
+ }
+
+ void ReadAllFields ()
+ {
+ TypeDefTable tdefTable = m_tableReader.GetTypeDefTable ();
+
+ if (!m_tHeap.HasTable (FieldTable.RId)) {
+ m_fields = new FieldDefinition [0];
+ return;
+ }
+
+ FieldTable fldTable = m_tableReader.GetFieldTable ();
+ m_fields = new FieldDefinition [fldTable.Rows.Count];
+
+ for (int i = 0; i < m_typeDefs.Length; i++) {
+ TypeDefinition dec = m_typeDefs [i];
+ GenericContext context = new GenericContext (dec);
+
+ int index = i, next;
+
+ if (index == tdefTable.Rows.Count - 1)
+ next = fldTable.Rows.Count + 1;
+ else
+ next = (int) (tdefTable [index + 1]).FieldList;
+
+ for (int j = (int) tdefTable [index].FieldList; j < next; j++) {
+ FieldRow frow = fldTable [j - 1];
+ FieldSig fsig = m_sigReader.GetFieldSig (frow.Signature);
+
+ FieldDefinition fdef = new FieldDefinition (
+ m_root.Streams.StringsHeap [frow.Name],
+ GetTypeRefFromSig (fsig.Type, context), frow.Flags);
+ fdef.MetadataToken = MetadataToken.FromMetadataRow (TokenType.Field, j - 1);
+
+ if (fsig.CustomMods.Length > 0)
+ fdef.FieldType = GetModifierType (fsig.CustomMods, fdef.FieldType);
+
+ if (!IsDeleted (fdef))
+ dec.Fields.Add (fdef);
+
+ m_fields [j - 1] = fdef;
+ }
+ }
+ }
+
+ void ReadMethods ()
+ {
+ if (!m_tHeap.HasTable (MethodTable.RId)) {
+ m_meths = new MethodDefinition [0];
+ return;
+ }
+
+ MethodTable mTable = m_tableReader.GetMethodTable ();
+ m_meths = new MethodDefinition [mTable.Rows.Count];
+ for (int i = 0; i < mTable.Rows.Count; i++) {
+ MethodRow mRow = mTable [i];
+ MethodDefinition meth = new MethodDefinition (
+ m_root.Streams.StringsHeap [mRow.Name],
+ mRow.Flags);
+ meth.RVA = mRow.RVA;
+ meth.ImplAttributes = mRow.ImplFlags;
+
+ meth.MetadataToken = MetadataToken.FromMetadataRow (TokenType.Method, i);
+
+ m_meths [i] = meth;
+ }
+ }
+
+ void CompleteMethods ()
+ {
+ TypeDefTable tdefTable = m_tableReader.GetTypeDefTable ();
+
+ if (!m_tHeap.HasTable (MethodTable.RId)) {
+ m_meths = new MethodDefinition [0];
+ return;
+ }
+
+ MethodTable methTable = m_tableReader.GetMethodTable ();
+ ParamTable paramTable = m_tableReader.GetParamTable ();
+ if (!m_tHeap.HasTable (ParamTable.RId))
+ m_parameters = new ParameterDefinition [0];
+ else
+ m_parameters = new ParameterDefinition [paramTable.Rows.Count];
+
+ for (int i = 0; i < m_typeDefs.Length; i++) {
+ TypeDefinition dec = m_typeDefs [i];
+
+ int index = i, next;
+
+ if (index == tdefTable.Rows.Count - 1)
+ next = methTable.Rows.Count + 1;
+ else
+ next = (int) (tdefTable [index + 1]).MethodList;
+
+ for (int j = (int) tdefTable [index].MethodList; j < next; j++) {
+ MethodRow methRow = methTable [j - 1];
+ MethodDefinition mdef = m_meths [j - 1];
+
+ if (!IsDeleted (mdef)) {
+ if (mdef.IsConstructor)
+ dec.Constructors.Add (mdef);
+ else
+ dec.Methods.Add (mdef);
+ }
+
+ GenericContext context = new GenericContext (mdef);
+
+ MethodDefSig msig = m_sigReader.GetMethodDefSig (methRow.Signature);
+ mdef.HasThis = msig.HasThis;
+ mdef.ExplicitThis = msig.ExplicitThis;
+ mdef.CallingConvention = msig.MethCallConv;
+
+ int prms;
+ if (j == methTable.Rows.Count)
+ prms = m_parameters.Length + 1;
+ else
+ prms = (int) (methTable [j]).ParamList;
+
+ ParameterDefinition retparam = null;
+
+ //TODO: optimize this
+ int start = (int) methRow.ParamList - 1;
+
+ if (paramTable != null && start < prms - 1) {
+
+ ParamRow pRetRow = paramTable [start];
+
+ if (pRetRow != null && pRetRow.Sequence == 0) { // ret type
+
+ retparam = new ParameterDefinition (
+ m_root.Streams.StringsHeap [pRetRow.Name],
+ 0,
+ pRetRow.Flags,
+ null);
+
+ retparam.Method = mdef;
+ m_parameters [start] = retparam;
+ start++;
+ }
+ }
+
+ for (int k = 0; k < msig.ParamCount; k++) {
+
+ int pointer = start + k;
+
+ ParamRow pRow = null;
+
+ if (paramTable != null && pointer < prms - 1)
+ pRow = paramTable [pointer];
+
+ Param psig = msig.Parameters [k];
+
+ ParameterDefinition pdef;
+ if (pRow != null) {
+ pdef = BuildParameterDefinition (
+ m_root.Streams.StringsHeap [pRow.Name],
+ pRow.Sequence, pRow.Flags, psig, context);
+ pdef.MetadataToken = MetadataToken.FromMetadataRow (TokenType.Param, pointer);
+ m_parameters [pointer] = pdef;
+ } else
+ pdef = BuildParameterDefinition (k + 1, psig, context);
+
+ pdef.Method = mdef;
+ mdef.Parameters.Add (pdef);
+ }
+
+ mdef.ReturnType = GetMethodReturnType (msig, context);
+ MethodReturnType mrt = mdef.ReturnType;
+ mrt.Method = mdef;
+ if (retparam != null) {
+ mrt.Parameter = retparam;
+ mrt.Parameter.ParameterType = mrt.ReturnType;
+ }
+ }
+ }
+
+ uint eprid = CodeReader.GetRid ((int) m_reader.Image.CLIHeader.EntryPointToken);
+ if (eprid > 0 && eprid <= m_meths.Length)
+ m_module.Assembly.EntryPoint = GetMethodDefAt (eprid);
+ }
+
+ void ReadMemberReferences ()
+ {
+ if (!m_tHeap.HasTable (MemberRefTable.RId))
+ return;
+
+ MemberRefTable mrefTable = m_tableReader.GetMemberRefTable ();
+ m_memberRefs = new MemberReference [mrefTable.Rows.Count];
+ }
+
+ public override void VisitExternTypeCollection (ExternTypeCollection externs)
+ {
+ ExternTypeCollection ext = externs;
+
+ if (!m_tHeap.HasTable (ExportedTypeTable.RId))
+ return;
+
+ ExportedTypeTable etTable = m_tableReader.GetExportedTypeTable ();
+ TypeReference [] buffer = new TypeReference [etTable.Rows.Count];
+
+ for (int i = 0; i < etTable.Rows.Count; i++) {
+ ExportedTypeRow etRow = etTable [i];
+
+ buffer [i] = new TypeDefinition (
+ m_root.Streams.StringsHeap [etRow.TypeName],
+ m_root.Streams.StringsHeap [etRow.TypeNamespace],
+ etRow.Flags);
+ buffer [i].AttachToScope (GetExportedTypeScope (etRow.Implementation));
+ }
+
+ for (int i = 0; i < etTable.Rows.Count; i++) {
+ ExportedTypeRow etRow = etTable [i];
+ if (etRow.Implementation.TokenType != TokenType.ExportedType)
+ continue;
+
+ TypeReference exported = buffer [i];
+ TypeReference owner = buffer [etRow.Implementation.RID - 1];
+ exported.DeclaringType = owner;
+ exported.AttachToScope (owner.Scope);
+ }
+
+ for (int i = 0; i < buffer.Length; i++) {
+ TypeReference curs = buffer [i];
+ if (curs != null)
+ ext.Add (curs);
+ }
+ }
+
+ IMetadataScope GetExportedTypeScope (MetadataToken scope)
+ {
+ int index = (int) scope.RID - 1;
+ switch (scope.TokenType) {
+ case TokenType.AssemblyRef:
+ return Module.AssemblyReferences [index];
+ case TokenType.File:
+ return Module.ModuleReferences [index];
+ case TokenType.ExportedType:
+ return null; // resolved later
+ default:
+ throw new NotSupportedException ();
+ }
+ }
+
+ static object GetFixedArgValue (CustomAttrib.FixedArg fa)
+ {
+ if (fa.SzArray) {
+ object [] vals = new object [fa.NumElem];
+ for (int j = 0; j < vals.Length; j++)
+ vals [j] = fa.Elems [j].Value;
+ return vals;
+ } else
+ return fa.Elems [0].Value;
+ }
+
+ TypeReference GetFixedArgType (CustomAttrib.FixedArg fa)
+ {
+ if (fa.SzArray) {
+ if (fa.NumElem == 0)
+ return new ArrayType (SearchCoreType (Constants.Object));
+ else
+ return new ArrayType (fa.Elems [0].ElemType);
+ } else
+ return fa.Elems [0].ElemType;
+ }
+
+ TypeReference GetNamedArgType (CustomAttrib.NamedArg na)
+ {
+ if (na.FieldOrPropType == ElementType.Boxed)
+ return SearchCoreType (Constants.Object);
+
+ return GetFixedArgType (na.FixedArg);
+ }
+
+ protected CustomAttribute BuildCustomAttribute (MethodReference ctor, byte [] data, CustomAttrib sig)
+ {
+ CustomAttribute cattr = new CustomAttribute (ctor);
+ if (!sig.Read) {
+ cattr.Resolved = false;
+ cattr.Blob = data;
+ return cattr;
+ }
+
+ foreach (CustomAttrib.FixedArg fa in sig.FixedArgs)
+ cattr.ConstructorParameters.Add (GetFixedArgValue (fa));
+
+ foreach (CustomAttrib.NamedArg na in sig.NamedArgs) {
+ object value = GetFixedArgValue (na.FixedArg);
+ if (na.Field) {
+ cattr.Fields [na.FieldOrPropName] = value;
+ cattr.SetFieldType (na.FieldOrPropName, GetNamedArgType (na));
+ } else if (na.Property) {
+ cattr.Properties [na.FieldOrPropName] = value;
+ cattr.SetPropertyType (na.FieldOrPropName, GetNamedArgType (na));
+ } else
+ throw new ReflectionException ("Non valid named arg");
+ }
+
+ return cattr;
+ }
+
+ void CompleteParameter (ParameterDefinition parameter, Param signature, GenericContext context)
+ {
+ TypeReference paramType;
+
+ if (signature.TypedByRef)
+ paramType = SearchCoreType (Constants.TypedReference);
+ else
+ paramType = GetTypeRefFromSig (signature.Type, context);
+
+ paramType = GetModifierType (signature.CustomMods, paramType);
+
+ if (signature.ByRef)
+ paramType = new ReferenceType (paramType);
+
+ parameter.ParameterType = paramType;
+ }
+
+ public ParameterDefinition BuildParameterDefinition (int sequence, Param psig, GenericContext context)
+ {
+ ParameterDefinition parameter = new ParameterDefinition (null);
+ parameter.Sequence = sequence;
+
+ CompleteParameter (parameter, psig, context);
+
+ return parameter;
+ }
+
+ public ParameterDefinition BuildParameterDefinition (string name, int sequence, ParameterAttributes attrs, Param psig, GenericContext context)
+ {
+ ParameterDefinition parameter = new ParameterDefinition (name, sequence, attrs, null);
+
+ CompleteParameter (parameter, psig, context);
+
+ return parameter;
+ }
+
+ protected SecurityDeclaration BuildSecurityDeclaration (DeclSecurityRow dsRow)
+ {
+ return BuildSecurityDeclaration (dsRow.Action, m_root.Streams.BlobHeap.Read (dsRow.PermissionSet));
+ }
+
+ public SecurityDeclaration BuildSecurityDeclaration (SecurityAction action, byte [] permset)
+ {
+ if (m_secReader == null)
+ m_secReader = new SecurityDeclarationReader (m_root, this);
+
+ return m_secReader.FromByteArray (action, permset);
+ }
+
+ protected MarshalSpec BuildMarshalDesc (MarshalSig ms, IHasMarshalSpec container)
+ {
+ if (ms.Spec is MarshalSig.Array) {
+ ArrayMarshalSpec amd = new ArrayMarshalSpec (container);
+ MarshalSig.Array ar = (MarshalSig.Array) ms.Spec;
+ amd.ElemType = ar.ArrayElemType;
+ amd.NumElem = ar.NumElem;
+ amd.ParamNum = ar.ParamNum;
+ amd.ElemMult = ar.ElemMult;
+ return amd;
+ } else if (ms.Spec is MarshalSig.CustomMarshaler) {
+ CustomMarshalerSpec cmd = new CustomMarshalerSpec (container);
+ MarshalSig.CustomMarshaler cmsig = (MarshalSig.CustomMarshaler) ms.Spec;
+ cmd.Guid = cmsig.Guid.Length > 0 ? new Guid (cmsig.Guid) : new Guid ();
+ cmd.UnmanagedType = cmsig.UnmanagedType;
+ cmd.ManagedType = cmsig.ManagedType;
+ cmd.Cookie = cmsig.Cookie;
+ return cmd;
+ } else if (ms.Spec is MarshalSig.FixedArray) {
+ FixedArraySpec fad = new FixedArraySpec (container);
+ MarshalSig.FixedArray fasig = (MarshalSig.FixedArray) ms.Spec;
+ fad.ElemType = fasig.ArrayElemType;
+ fad.NumElem = fasig.NumElem;
+ return fad;
+ } else if (ms.Spec is MarshalSig.FixedSysString) {
+ FixedSysStringSpec fssc = new FixedSysStringSpec (container);
+ fssc.Size = ((MarshalSig.FixedSysString) ms.Spec).Size;
+ return fssc;
+ } else if (ms.Spec is MarshalSig.SafeArray) {
+ SafeArraySpec sad = new SafeArraySpec (container);
+ sad.ElemType = ((MarshalSig.SafeArray) ms.Spec).ArrayElemType;
+ return sad;
+ } else {
+ return new MarshalSpec (ms.NativeInstrinsic, container);
+ }
+ }
+
+ public TypeReference GetModifierType (CustomMod [] cmods, TypeReference type)
+ {
+ if (cmods == null || cmods.Length == 0)
+ return type;
+
+ TypeReference ret = type;
+ for (int i = cmods.Length - 1; i >= 0; i--) {
+ CustomMod cmod = cmods [i];
+ TypeReference modType;
+
+ if (cmod.TypeDefOrRef.RID == 0)
+ continue;
+
+ if (cmod.TypeDefOrRef.TokenType == TokenType.TypeDef)
+ modType = GetTypeDefAt (cmod.TypeDefOrRef.RID);
+ else
+ modType = GetTypeRefAt (cmod.TypeDefOrRef.RID);
+
+ if (cmod.CMOD == CustomMod.CMODType.OPT)
+ ret = new ModifierOptional (ret, modType);
+ else if (cmod.CMOD == CustomMod.CMODType.REQD)
+ ret = new ModifierRequired (ret, modType);
+ }
+ return ret;
+ }
+
+ public MethodReturnType GetMethodReturnType (MethodSig msig, GenericContext context)
+ {
+ TypeReference retType;
+ if (msig.RetType.Void)
+ retType = SearchCoreType (Constants.Void);
+ else if (msig.RetType.TypedByRef)
+ retType = SearchCoreType (Constants.TypedReference);
+ else
+ retType = GetTypeRefFromSig (msig.RetType.Type, context);
+
+ retType = GetModifierType (msig.RetType.CustomMods, retType);
+
+ if (msig.RetType.ByRef)
+ retType = new ReferenceType (retType);
+
+ return new MethodReturnType (retType);
+ }
+
+ public TypeReference GetTypeRefFromSig (SigType t, GenericContext context)
+ {
+ switch (t.ElementType) {
+ case ElementType.Class :
+ CLASS c = t as CLASS;
+ return GetTypeDefOrRef (c.Type, context);
+ case ElementType.ValueType :
+ VALUETYPE vt = t as VALUETYPE;
+ TypeReference vtr = GetTypeDefOrRef (vt.Type, context);
+ vtr.IsValueType = true;
+ return vtr;
+ case ElementType.String :
+ return SearchCoreType (Constants.String);
+ case ElementType.Object :
+ return SearchCoreType (Constants.Object);
+ case ElementType.Void :
+ return SearchCoreType (Constants.Void);
+ case ElementType.Boolean :
+ return SearchCoreType (Constants.Boolean);
+ case ElementType.Char :
+ return SearchCoreType (Constants.Char);
+ case ElementType.I1 :
+ return SearchCoreType (Constants.SByte);
+ case ElementType.U1 :
+ return SearchCoreType (Constants.Byte);
+ case ElementType.I2 :
+ return SearchCoreType (Constants.Int16);
+ case ElementType.U2 :
+ return SearchCoreType (Constants.UInt16);
+ case ElementType.I4 :
+ return SearchCoreType (Constants.Int32);
+ case ElementType.U4 :
+ return SearchCoreType (Constants.UInt32);
+ case ElementType.I8 :
+ return SearchCoreType (Constants.Int64);
+ case ElementType.U8 :
+ return SearchCoreType (Constants.UInt64);
+ case ElementType.R4 :
+ return SearchCoreType (Constants.Single);
+ case ElementType.R8 :
+ return SearchCoreType (Constants.Double);
+ case ElementType.I :
+ return SearchCoreType (Constants.IntPtr);
+ case ElementType.U :
+ return SearchCoreType (Constants.UIntPtr);
+ case ElementType.TypedByRef :
+ return SearchCoreType (Constants.TypedReference);
+ case ElementType.Array :
+ ARRAY ary = t as ARRAY;
+ return new ArrayType (GetTypeRefFromSig (ary.Type, context), ary.Shape);
+ case ElementType.SzArray :
+ SZARRAY szary = t as SZARRAY;
+ ArrayType at = new ArrayType (GetTypeRefFromSig (szary.Type, context));
+ return at;
+ case ElementType.Ptr :
+ PTR pointer = t as PTR;
+ if (pointer.Void)
+ return new PointerType (SearchCoreType (Constants.Void));
+ return new PointerType (GetTypeRefFromSig (pointer.PtrType, context));
+ case ElementType.FnPtr :
+ FNPTR funcptr = t as FNPTR;
+ FunctionPointerType fnptr = new FunctionPointerType (funcptr.Method.HasThis, funcptr.Method.ExplicitThis,
+ funcptr.Method.MethCallConv, GetMethodReturnType (funcptr.Method, context));
+
+ for (int i = 0; i < funcptr.Method.ParamCount; i++) {
+ Param p = funcptr.Method.Parameters [i];
+ fnptr.Parameters.Add (BuildParameterDefinition (i, p, context));
+ }
+
+ CreateSentinelIfNeeded (fnptr, funcptr.Method);
+
+ return fnptr;
+ case ElementType.Var:
+ VAR var = t as VAR;
+ context.CheckProvider (context.Type, var.Index + 1);
+
+ if (context.Type is GenericInstanceType)
+ return (context.Type as GenericInstanceType).GenericArguments [var.Index];
+ else
+ return context.Type.GenericParameters [var.Index];
+ case ElementType.MVar:
+ MVAR mvar = t as MVAR;
+ context.CheckProvider (context.Method, mvar.Index + 1);
+
+ if (context.Method is GenericInstanceMethod)
+ return (context.Method as GenericInstanceMethod).GenericArguments [mvar.Index];
+ else
+ return context.Method.GenericParameters [mvar.Index];
+ case ElementType.GenericInst:
+ GENERICINST ginst = t as GENERICINST;
+ GenericInstanceType instance = new GenericInstanceType (GetTypeDefOrRef (ginst.Type, context));
+ instance.IsValueType = ginst.ValueType;
+ context.CheckProvider (instance.GetOriginalType (), ginst.Signature.Arity);
+
+ for (int i = 0; i < ginst.Signature.Arity; i++)
+ instance.GenericArguments.Add (GetGenericArg (
+ ginst.Signature.Types [i], context));
+
+ return instance;
+ default:
+ break;
+ }
+ return null;
+ }
+
+ TypeReference GetGenericArg (GenericArg arg, GenericContext context)
+ {
+ TypeReference type = GetTypeRefFromSig (arg.Type, context);
+ type = GetModifierType (arg.CustomMods, type);
+ return type;
+ }
+
+ static bool IsOdd (int i)
+ {
+ return (i & 1) == 1;
+ }
+
+ protected object GetConstant (uint pos, ElementType elemType)
+ {
+ if (elemType == ElementType.Class)
+ return null;
+
+ byte [] constant = m_root.Streams.BlobHeap.Read (pos);
+
+ if (elemType == ElementType.String) {
+ int length = constant.Length;
+ if (IsOdd (length))
+ length--;
+
+ return Encoding.Unicode.GetString (constant, 0, length);
+ }
+
+ // One byte types can always be read using BitConverter. However it can't be used
+ // elsewhere since it behaves differently in Mono compared to CF on BE architectures
+ switch (elemType) {
+ case ElementType.Boolean :
+ return BitConverter.ToBoolean (constant, 0);
+ case ElementType.I1 :
+ return (sbyte) constant [0];
+ case ElementType.U1 :
+ return (byte) constant [0];
+ case ElementType.Object: // illegal, but foundable
+ return null;
+ default :
+ if (BitConverter.IsLittleEndian)
+ return GetConstantLittleEndian (elemType, constant);
+ else
+ return GetConstantBigEndian (elemType, constant);
+ }
+ }
+
+ static object GetConstantLittleEndian (ElementType elemType, byte [] constant)
+ {
+ switch (elemType) {
+ case ElementType.Char :
+ return BitConverter.ToChar (constant, 0);
+ case ElementType.I2 :
+ return BitConverter.ToInt16 (constant, 0);
+ case ElementType.I4 :
+ return BitConverter.ToInt32 (constant, 0);
+ case ElementType.I8 :
+ return BitConverter.ToInt64 (constant, 0);
+ case ElementType.U2 :
+ return BitConverter.ToUInt16 (constant, 0);
+ case ElementType.U4 :
+ return BitConverter.ToUInt32 (constant, 0);
+ case ElementType.U8 :
+ return BitConverter.ToUInt64 (constant, 0);
+ case ElementType.R4 :
+ return BitConverter.ToSingle (constant, 0);
+ case ElementType.R8 :
+ return BitConverter.ToDouble (constant, 0);
+ default:
+ throw new ReflectionException ("Non valid element in constant table");
+ }
+ }
+
+ static object GetConstantBigEndian (ElementType elemType, byte [] constant)
+ {
+ // BinaryReader always read it's data in LE format
+ // note: this could be further optimized (even without unsafe code)
+ BinaryReader br = new BinaryReader (new MemoryStream (constant));
+ switch (elemType) {
+ case ElementType.Char :
+ return (char) br.ReadUInt16 ();
+ case ElementType.I2 :
+ return br.ReadInt16 ();
+ case ElementType.I4 :
+ return br.ReadInt32 ();
+ case ElementType.I8 :
+ return br.ReadInt64 ();
+ case ElementType.U2 :
+ return br.ReadUInt16 ();
+ case ElementType.U4 :
+ return br.ReadUInt32 ();
+ case ElementType.U8 :
+ return br.ReadUInt64 ();
+ case ElementType.R4 :
+ return br.ReadSingle ();
+ case ElementType.R8 :
+ return br.ReadDouble ();
+ default:
+ throw new ReflectionException ("Non valid element in constant table");
+ }
+ }
+
+ protected void SetInitialValue (FieldDefinition field)
+ {
+ int size = 0;
+ TypeReference fieldType = field.FieldType;
+ switch (fieldType.FullName) {
+ case Constants.Boolean:
+ case Constants.Byte:
+ case Constants.SByte:
+ size = 1;
+ break;
+ case Constants.Int16:
+ case Constants.UInt16:
+ case Constants.Char:
+ size = 2;
+ break;
+ case Constants.Int32:
+ case Constants.UInt32:
+ case Constants.Single:
+ size = 4;
+ break;
+ case Constants.Int64:
+ case Constants.UInt64:
+ case Constants.Double:
+ size = 8;
+ break;
+ default:
+ fieldType = fieldType.GetOriginalType ();
+
+ TypeDefinition fieldTypeDef = fieldType as TypeDefinition;
+
+ if (fieldTypeDef != null)
+ size = (int) fieldTypeDef.ClassSize;
+ break;
+ }
+
+ if (size > 0 && field.RVA != RVA.Zero) {
+ byte [] data = new byte [size];
+ Section sect = m_reader.Image.GetSectionAtVirtualAddress (field.RVA);
+ if (sect != null)
+ Buffer.BlockCopy (sect.Data, (int) (long) (field.RVA - sect.VirtualAddress), data, 0, size);
+ field.InitialValue = data;
+ } else
+ field.InitialValue = new byte [0];
+ }
+ }
+}
--- /dev/null
+//
+// ReflectionWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 - 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+ using System.Globalization;
+ using System.Text;
+
+ using Mono.Cecil.Binary;
+ using Mono.Cecil.Cil;
+ using Mono.Cecil.Metadata;
+ using Mono.Cecil.Signatures;
+
+ internal sealed class ReflectionWriter : BaseReflectionVisitor {
+
+ StructureWriter m_structureWriter;
+ ModuleDefinition m_mod;
+ SignatureWriter m_sigWriter;
+ CodeWriter m_codeWriter;
+ MetadataWriter m_mdWriter;
+ MetadataTableWriter m_tableWriter;
+ MetadataRowWriter m_rowWriter;
+
+ bool m_saveSymbols;
+ string m_asmOutput;
+ ISymbolWriter m_symbolWriter;
+
+ ArrayList m_typeDefStack;
+ ArrayList m_methodStack;
+ ArrayList m_fieldStack;
+ ArrayList m_genericParamStack;
+ IDictionary m_typeSpecTokenCache;
+ IDictionary m_memberRefTokenCache;
+
+ uint m_methodIndex;
+ uint m_fieldIndex;
+ uint m_paramIndex;
+ uint m_eventIndex;
+ uint m_propertyIndex;
+
+ MemoryBinaryWriter m_constWriter;
+
+ public StructureWriter StructureWriter {
+ get { return m_structureWriter; }
+ set {
+ m_structureWriter = value;
+
+ Initialize ();
+ }
+ }
+
+ public CodeWriter CodeWriter {
+ get { return m_codeWriter; }
+ }
+
+ public bool SaveSymbols {
+ get { return m_saveSymbols; }
+ set { m_saveSymbols = value; }
+ }
+
+ public string OutputFile
+ {
+ get { return m_asmOutput; }
+ set { m_asmOutput = value; }
+ }
+
+ public ISymbolWriter SymbolWriter {
+ get { return m_symbolWriter; }
+ set { m_symbolWriter = value; }
+ }
+
+ public SignatureWriter SignatureWriter {
+ get { return m_sigWriter; }
+ }
+
+ public MetadataWriter MetadataWriter {
+ get { return m_mdWriter; }
+ }
+
+ public MetadataTableWriter MetadataTableWriter {
+ get { return m_tableWriter; }
+ }
+
+ public MetadataRowWriter MetadataRowWriter {
+ get { return m_rowWriter; }
+ }
+
+ public ReflectionWriter (ModuleDefinition mod)
+ {
+ m_mod = mod;
+ }
+
+ void Initialize ()
+ {
+ m_mdWriter = new MetadataWriter (
+ m_mod.Assembly,
+ m_mod.Image.MetadataRoot,
+ m_structureWriter.Assembly.Kind,
+ m_mod.Assembly.Runtime,
+ m_structureWriter.GetWriter ());
+ m_tableWriter = m_mdWriter.GetTableVisitor ();
+ m_rowWriter = m_tableWriter.GetRowVisitor () as MetadataRowWriter;
+ m_sigWriter = new SignatureWriter (m_mdWriter);
+ m_codeWriter = new CodeWriter (this, m_mdWriter.CilWriter);
+
+ m_typeDefStack = new ArrayList ();
+ m_methodStack = new ArrayList ();
+ m_fieldStack = new ArrayList ();
+ m_genericParamStack = new ArrayList ();
+ m_typeSpecTokenCache = new Hashtable ();
+ m_memberRefTokenCache = new Hashtable ();
+
+ m_methodIndex = 1;
+ m_fieldIndex = 1;
+ m_paramIndex = 1;
+ m_eventIndex = 1;
+ m_propertyIndex = 1;
+
+ m_constWriter = new MemoryBinaryWriter ();
+ }
+
+ public TypeReference GetCoreType (string name)
+ {
+ return m_mod.Controller.Reader.SearchCoreType (name);
+ }
+
+ public static uint GetRidFor (IMetadataTokenProvider tp)
+ {
+ return tp.MetadataToken.RID;
+ }
+
+ public uint GetRidFor (AssemblyNameReference asmName)
+ {
+ return (uint) m_mod.AssemblyReferences.IndexOf (asmName) + 1;
+ }
+
+ public uint GetRidFor (ModuleDefinition mod)
+ {
+ return (uint) m_mod.Assembly.Modules.IndexOf (mod) + 1;
+ }
+
+ public uint GetRidFor (ModuleReference modRef)
+ {
+ return (uint) m_mod.ModuleReferences.IndexOf (modRef) + 1;
+ }
+
+ static bool IsTypeSpec (TypeReference type)
+ {
+ return type is TypeSpecification || type is GenericParameter;
+ }
+
+ public MetadataToken GetTypeDefOrRefToken (TypeReference type)
+ {
+ if (IsTypeSpec (type)) {
+ uint sig = m_sigWriter.AddTypeSpec (GetTypeSpecSig (type));
+ if (m_typeSpecTokenCache.Contains (sig))
+ return (MetadataToken) m_typeSpecTokenCache [sig];
+
+ TypeSpecTable tsTable = m_tableWriter.GetTypeSpecTable ();
+ TypeSpecRow tsRow = m_rowWriter.CreateTypeSpecRow (sig);
+ tsTable.Rows.Add (tsRow);
+
+ MetadataToken token = new MetadataToken (TokenType.TypeSpec, (uint) tsTable.Rows.Count);
+ if (! (type is GenericParameter))
+ type.MetadataToken = token;
+
+ m_typeSpecTokenCache [sig] = token;
+ return token;
+ } else if (type != null)
+ return type.MetadataToken;
+ else // <Module> and interfaces
+ return new MetadataToken (TokenType.TypeRef, 0);
+ }
+
+ public MetadataToken GetMemberRefToken (MemberReference member)
+ {
+ if (member is MethodSpecification)
+ return GetMemberRefToken (((MethodSpecification) member).ElementMethod);
+ if (member is IMemberDefinition)
+ return member.MetadataToken;
+ if (m_memberRefTokenCache.Contains (member))
+ return (MetadataToken) m_memberRefTokenCache [member];
+
+ MemberRefTable mrTable = m_tableWriter.GetMemberRefTable ();
+
+ uint sig = 0;
+ if (member is FieldReference)
+ sig = m_sigWriter.AddFieldSig (GetFieldSig ((FieldReference) member));
+ else if (member is MethodReference)
+ sig = m_sigWriter.AddMethodRefSig (GetMethodRefSig ((MethodReference) member));
+
+ MetadataToken declaringType = GetTypeDefOrRefToken (member.DeclaringType);
+ uint name = m_mdWriter.AddString (member.Name);
+
+ for (int i = 0; i < mrTable.Rows.Count; i++) {
+ MemberRefRow row = mrTable [i];
+ if (row.Class == declaringType && row.Name == name && row.Signature == sig)
+ return MetadataToken.FromMetadataRow (TokenType.MemberRef, i);
+ }
+
+ MemberRefRow mrRow = m_rowWriter.CreateMemberRefRow (
+ declaringType,
+ name,
+ sig);
+
+ mrTable.Rows.Add (mrRow);
+ member.MetadataToken = new MetadataToken (
+ TokenType.MemberRef, (uint) mrTable.Rows.Count);
+ m_memberRefTokenCache [member] = member.MetadataToken;
+ return member.MetadataToken;
+ }
+
+ public MetadataToken GetMethodSpecToken (GenericInstanceMethod gim)
+ {
+ uint sig = m_sigWriter.AddMethodSpec (GetMethodSpecSig (gim));
+ MethodSpecTable msTable = m_tableWriter.GetMethodSpecTable ();
+
+ MetadataToken meth = GetMemberRefToken (gim.ElementMethod);
+
+ for (int i = 0; i < msTable.Rows.Count; i++) {
+ MethodSpecRow row = msTable [i];
+ if (row.Method == meth && row.Instantiation == sig)
+ return MetadataToken.FromMetadataRow (TokenType.MethodSpec, i);
+ }
+
+ MethodSpecRow msRow = m_rowWriter.CreateMethodSpecRow (
+ meth,
+ sig);
+ msTable.Rows.Add (msRow);
+ gim.MetadataToken = new MetadataToken (TokenType.MethodSpec, (uint) msTable.Rows.Count);
+ return gim.MetadataToken;
+ }
+
+ public override void VisitModuleDefinition (ModuleDefinition mod)
+ {
+ mod.FullLoad ();
+ }
+
+ public override void VisitTypeDefinitionCollection (TypeDefinitionCollection types)
+ {
+ TypeDefTable tdTable = m_tableWriter.GetTypeDefTable ();
+
+ if (types [Constants.ModuleType] == null)
+ types.Add (new TypeDefinition (
+ Constants.ModuleType, string.Empty, TypeAttributes.NotPublic));
+
+ foreach (TypeDefinition t in types)
+ m_typeDefStack.Add (t);
+
+ m_typeDefStack.Sort (TableComparers.TypeDef.Instance);
+
+ for (int i = 0; i < m_typeDefStack.Count; i++) {
+ TypeDefinition t = (TypeDefinition) m_typeDefStack [i];
+ if (t.Module.Assembly != m_mod.Assembly)
+ throw new ReflectionException ("A type as not been correctly imported");
+
+ t.MetadataToken = new MetadataToken (TokenType.TypeDef, (uint) (i + 1));
+ }
+
+ foreach (TypeDefinition t in m_typeDefStack) {
+ TypeDefRow tdRow = m_rowWriter.CreateTypeDefRow (
+ t.Attributes,
+ m_mdWriter.AddString (t.Name),
+ m_mdWriter.AddString (t.Namespace),
+ GetTypeDefOrRefToken (t.BaseType),
+ 0,
+ 0);
+
+ tdTable.Rows.Add (tdRow);
+ }
+ }
+
+ public void CompleteTypeDefinitions ()
+ {
+ TypeDefTable tdTable = m_tableWriter.GetTypeDefTable ();
+
+ for (int i = 0; i < m_typeDefStack.Count; i++) {
+ TypeDefRow tdRow = tdTable [i];
+ TypeDefinition t = (TypeDefinition) m_typeDefStack [i];
+ tdRow.FieldList = m_fieldIndex;
+ tdRow.MethodList = m_methodIndex;
+ if (t.HasFields) {
+ foreach (FieldDefinition field in t.Fields)
+ VisitFieldDefinition (field);
+ }
+ if (t.HasConstructors) {
+ foreach (MethodDefinition ctor in t.Constructors)
+ VisitMethodDefinition (ctor);
+ }
+ if (t.HasMethods) {
+ foreach (MethodDefinition meth in t.Methods)
+ VisitMethodDefinition (meth);
+ }
+
+ if (t.HasLayoutInfo)
+ WriteLayout (t);
+ }
+
+ foreach (FieldDefinition field in m_fieldStack) {
+ if (field.HasCustomAttributes)
+ VisitCustomAttributeCollection (field.CustomAttributes);
+ if (field.MarshalSpec != null)
+ VisitMarshalSpec (field.MarshalSpec);
+ }
+
+ foreach (MethodDefinition meth in m_methodStack) {
+ if (meth.ReturnType.HasCustomAttributes)
+ VisitCustomAttributeCollection (meth.ReturnType.CustomAttributes);
+ if (meth.HasParameters) {
+ foreach (ParameterDefinition param in meth.Parameters) {
+ if (param.HasCustomAttributes)
+ VisitCustomAttributeCollection (param.CustomAttributes);
+ }
+ }
+ if (meth.HasGenericParameters)
+ VisitGenericParameterCollection (meth.GenericParameters);
+ if (meth.HasOverrides)
+ VisitOverrideCollection (meth.Overrides);
+ if (meth.HasCustomAttributes)
+ VisitCustomAttributeCollection (meth.CustomAttributes);
+ if (meth.HasSecurityDeclarations)
+ VisitSecurityDeclarationCollection (meth.SecurityDeclarations);
+ if (meth.PInvokeInfo != null) {
+ meth.Attributes |= MethodAttributes.PInvokeImpl;
+ VisitPInvokeInfo (meth.PInvokeInfo);
+ }
+ }
+
+ foreach (TypeDefinition t in m_typeDefStack)
+ t.Accept (this);
+ }
+
+ public override void VisitTypeReferenceCollection (TypeReferenceCollection refs)
+ {
+ ArrayList orderedTypeRefs = new ArrayList (refs.Count);
+ foreach (TypeReference tr in refs)
+ orderedTypeRefs.Add (tr);
+
+ orderedTypeRefs.Sort (TableComparers.TypeRef.Instance);
+
+ TypeRefTable trTable = m_tableWriter.GetTypeRefTable ();
+ foreach (TypeReference t in orderedTypeRefs) {
+ MetadataToken scope;
+
+ if (t.Module.Assembly != m_mod.Assembly)
+ throw new ReflectionException ("A type as not been correctly imported");
+
+ if (t.Scope == null)
+ continue;
+
+ if (t.DeclaringType != null)
+ scope = new MetadataToken (TokenType.TypeRef, GetRidFor (t.DeclaringType));
+ else if (t.Scope is AssemblyNameReference)
+ scope = new MetadataToken (TokenType.AssemblyRef,
+ GetRidFor ((AssemblyNameReference) t.Scope));
+ else if (t.Scope is ModuleDefinition)
+ scope = new MetadataToken (TokenType.Module,
+ GetRidFor ((ModuleDefinition) t.Scope));
+ else if (t.Scope is ModuleReference)
+ scope = new MetadataToken (TokenType.ModuleRef,
+ GetRidFor ((ModuleReference) t.Scope));
+ else
+ scope = new MetadataToken (TokenType.ExportedType, 0);
+
+ TypeRefRow trRow = m_rowWriter.CreateTypeRefRow (
+ scope,
+ m_mdWriter.AddString (t.Name),
+ m_mdWriter.AddString (t.Namespace));
+
+ trTable.Rows.Add (trRow);
+ t.MetadataToken = new MetadataToken (TokenType.TypeRef, (uint) trTable.Rows.Count);
+ }
+ }
+
+ public override void VisitGenericParameterCollection (GenericParameterCollection parameters)
+ {
+ if (parameters.Count == 0)
+ return;
+
+ foreach (GenericParameter gp in parameters)
+ m_genericParamStack.Add (gp);
+ }
+
+ public override void VisitInterfaceCollection (InterfaceCollection interfaces)
+ {
+ if (interfaces.Count == 0)
+ return;
+
+ InterfaceImplTable iiTable = m_tableWriter.GetInterfaceImplTable ();
+ foreach (TypeReference interf in interfaces) {
+ InterfaceImplRow iiRow = m_rowWriter.CreateInterfaceImplRow (
+ GetRidFor (interfaces.Container),
+ GetTypeDefOrRefToken (interf));
+
+ iiTable.Rows.Add (iiRow);
+ }
+ }
+
+ public override void VisitExternTypeCollection (ExternTypeCollection externs)
+ {
+ if (externs.Count == 0)
+ return;
+
+ ExportedTypeTable etTable = m_tableWriter.GetExportedTypeTable ();
+ foreach (TypeReference ext in externs) {
+ TypeDefinition td = ext.Resolve ();
+ if (td == null)
+ continue;
+
+ MetadataToken scope = GetExportedTypeScope (td);
+
+ ExportedTypeRow etRow = m_rowWriter.CreateExportedTypeRow (
+ td.Attributes,
+ 0,
+ m_mdWriter.AddString (td.Name),
+ m_mdWriter.AddString (td.Namespace),
+ scope);
+
+ etTable.Rows.Add (etRow);
+ ext.MetadataToken = new MetadataToken (TokenType.ExportedType, (uint) etTable.Rows.Count);
+ }
+ }
+
+ MetadataToken GetExportedTypeScope (TypeDefinition t)
+ {
+ if (t.DeclaringType != null)
+ return t.DeclaringType.MetadataToken;
+
+ if (t.Scope is AssemblyNameReference)
+ return new MetadataToken (TokenType.AssemblyRef, GetRidFor ((AssemblyNameReference) t.Scope));
+
+ if (t.Scope is ModuleDefinition)
+ return new MetadataToken (TokenType.Module, GetRidFor ((ModuleDefinition) t.Scope));
+
+ throw new NotImplementedException ();
+ }
+
+ public override void VisitOverrideCollection (OverrideCollection meths)
+ {
+ if (meths.Count == 0)
+ return;
+
+ MethodImplTable miTable = m_tableWriter.GetMethodImplTable ();
+ foreach (MethodReference ov in meths) {
+ MethodImplRow miRow = m_rowWriter.CreateMethodImplRow (
+ GetRidFor (meths.Container.DeclaringType as TypeDefinition),
+ new MetadataToken (TokenType.Method, GetRidFor (meths.Container)),
+ GetMemberRefToken (ov));
+
+ miTable.Rows.Add (miRow);
+ }
+ }
+
+ public override void VisitNestedTypeCollection (NestedTypeCollection nestedTypes)
+ {
+ if (nestedTypes.Count == 0)
+ return;
+
+ NestedClassTable ncTable = m_tableWriter.GetNestedClassTable ();
+ foreach (TypeDefinition nested in nestedTypes) {
+ NestedClassRow ncRow = m_rowWriter.CreateNestedClassRow (
+ nested.MetadataToken.RID,
+ GetRidFor (nestedTypes.Container));
+
+ ncTable.Rows.Add (ncRow);
+ }
+ }
+
+ public override void VisitParameterDefinitionCollection (ParameterDefinitionCollection parameters)
+ {
+ if (parameters.Count == 0)
+ return;
+
+ ushort seq = 1;
+ ParamTable pTable = m_tableWriter.GetParamTable ();
+ foreach (ParameterDefinition param in parameters)
+ InsertParameter (pTable, param, seq++);
+ }
+
+ void InsertParameter (ParamTable pTable, ParameterDefinition param, ushort seq)
+ {
+ ParamRow pRow = m_rowWriter.CreateParamRow (
+ param.Attributes,
+ seq,
+ m_mdWriter.AddString (param.Name));
+
+ pTable.Rows.Add (pRow);
+ param.MetadataToken = new MetadataToken (TokenType.Param, (uint) pTable.Rows.Count);
+
+ if (param.MarshalSpec != null)
+ param.MarshalSpec.Accept (this);
+
+ if (param.HasConstant)
+ WriteConstant (param, param.ParameterType);
+
+ m_paramIndex++;
+ }
+
+ static bool RequiresParameterRow (MethodReturnType mrt)
+ {
+ return mrt.HasConstant || mrt.MarshalSpec != null ||
+ mrt.CustomAttributes.Count > 0 || mrt.Parameter.Attributes != (ParameterAttributes) 0;
+ }
+
+ public override void VisitMethodDefinition (MethodDefinition method)
+ {
+ MethodTable mTable = m_tableWriter.GetMethodTable ();
+ MethodRow mRow = m_rowWriter.CreateMethodRow (
+ RVA.Zero,
+ method.ImplAttributes,
+ method.Attributes,
+ m_mdWriter.AddString (method.Name),
+ m_sigWriter.AddMethodDefSig (GetMethodDefSig (method)),
+ m_paramIndex);
+
+ mTable.Rows.Add (mRow);
+ m_methodStack.Add (method);
+ method.MetadataToken = new MetadataToken (TokenType.Method, (uint) mTable.Rows.Count);
+ m_methodIndex++;
+
+ if (RequiresParameterRow (method.ReturnType))
+ InsertParameter (m_tableWriter.GetParamTable (), method.ReturnType.Parameter, 0);
+
+ VisitParameterDefinitionCollection (method.Parameters);
+ }
+
+ public override void VisitPInvokeInfo (PInvokeInfo pinvk)
+ {
+ ImplMapTable imTable = m_tableWriter.GetImplMapTable ();
+ ImplMapRow imRow = m_rowWriter.CreateImplMapRow (
+ pinvk.Attributes,
+ new MetadataToken (TokenType.Method, GetRidFor (pinvk.Method)),
+ m_mdWriter.AddString (pinvk.EntryPoint),
+ GetRidFor (pinvk.Module));
+
+ imTable.Rows.Add (imRow);
+ }
+
+ public override void VisitEventDefinitionCollection (EventDefinitionCollection events)
+ {
+ if (events.Count == 0)
+ return;
+
+ EventMapTable emTable = m_tableWriter.GetEventMapTable ();
+ EventMapRow emRow = m_rowWriter.CreateEventMapRow (
+ GetRidFor (events.Container),
+ m_eventIndex);
+
+ emTable.Rows.Add (emRow);
+ VisitCollection (events);
+ }
+
+ public override void VisitEventDefinition (EventDefinition evt)
+ {
+ EventTable eTable = m_tableWriter.GetEventTable ();
+ EventRow eRow = m_rowWriter.CreateEventRow (
+ evt.Attributes,
+ m_mdWriter.AddString (evt.Name),
+ GetTypeDefOrRefToken (evt.EventType));
+
+ eTable.Rows.Add (eRow);
+ evt.MetadataToken = new MetadataToken (TokenType.Event, (uint) eTable.Rows.Count);
+
+ if (evt.AddMethod != null)
+ WriteSemantic (MethodSemanticsAttributes.AddOn, evt, evt.AddMethod);
+
+ if (evt.InvokeMethod != null)
+ WriteSemantic (MethodSemanticsAttributes.Fire, evt, evt.InvokeMethod);
+
+ if (evt.RemoveMethod != null)
+ WriteSemantic (MethodSemanticsAttributes.RemoveOn, evt, evt.RemoveMethod);
+
+ m_eventIndex++;
+ }
+
+ public override void VisitFieldDefinition (FieldDefinition field)
+ {
+ FieldTable fTable = m_tableWriter.GetFieldTable ();
+ FieldRow fRow = m_rowWriter.CreateFieldRow (
+ field.Attributes,
+ m_mdWriter.AddString (field.Name),
+ m_sigWriter.AddFieldSig (GetFieldSig (field)));
+
+ fTable.Rows.Add (fRow);
+ field.MetadataToken = new MetadataToken (TokenType.Field, (uint) fTable.Rows.Count);
+ m_fieldIndex++;
+
+ if (field.HasConstant)
+ WriteConstant (field, field.FieldType);
+
+ if (field.HasLayoutInfo)
+ WriteLayout (field);
+
+ m_fieldStack.Add (field);
+ }
+
+ public override void VisitPropertyDefinitionCollection (PropertyDefinitionCollection properties)
+ {
+ if (properties.Count == 0)
+ return;
+
+ PropertyMapTable pmTable = m_tableWriter.GetPropertyMapTable ();
+ PropertyMapRow pmRow = m_rowWriter.CreatePropertyMapRow (
+ GetRidFor (properties.Container),
+ m_propertyIndex);
+
+ pmTable.Rows.Add (pmRow);
+ VisitCollection (properties);
+ }
+
+ public override void VisitPropertyDefinition (PropertyDefinition property)
+ {
+ PropertyTable pTable = m_tableWriter.GetPropertyTable ();
+ PropertyRow pRow = m_rowWriter.CreatePropertyRow (
+ property.Attributes,
+ m_mdWriter.AddString (property.Name),
+ m_sigWriter.AddPropertySig (GetPropertySig (property)));
+
+ pTable.Rows.Add (pRow);
+ property.MetadataToken = new MetadataToken (TokenType.Property, (uint) pTable.Rows.Count);
+
+ if (property.GetMethod != null)
+ WriteSemantic (MethodSemanticsAttributes.Getter, property, property.GetMethod);
+
+ if (property.SetMethod != null)
+ WriteSemantic (MethodSemanticsAttributes.Setter, property, property.SetMethod);
+
+ if (property.HasConstant)
+ WriteConstant (property, property.PropertyType);
+
+ m_propertyIndex++;
+ }
+
+ public override void VisitSecurityDeclarationCollection (SecurityDeclarationCollection secDecls)
+ {
+ if (secDecls.Count == 0)
+ return;
+
+ DeclSecurityTable dsTable = m_tableWriter.GetDeclSecurityTable ();
+ foreach (SecurityDeclaration secDec in secDecls) {
+ DeclSecurityRow dsRow = m_rowWriter.CreateDeclSecurityRow (
+ secDec.Action,
+ secDecls.Container.MetadataToken,
+ m_mdWriter.AddBlob (secDec.Resolved ?
+ m_mod.GetAsByteArray (secDec) : secDec.Blob));
+
+ dsTable.Rows.Add (dsRow);
+ }
+ }
+
+ public override void VisitCustomAttributeCollection (CustomAttributeCollection customAttrs)
+ {
+ if (customAttrs.Count == 0)
+ return;
+
+ CustomAttributeTable caTable = m_tableWriter.GetCustomAttributeTable ();
+ foreach (CustomAttribute ca in customAttrs) {
+ MetadataToken parent;
+ if (customAttrs.Container is AssemblyDefinition)
+ parent = new MetadataToken (TokenType.Assembly, 1);
+ else if (customAttrs.Container is ModuleDefinition)
+ parent = new MetadataToken (TokenType.Module, 1);
+ else if (customAttrs.Container is IMetadataTokenProvider)
+ parent = ((IMetadataTokenProvider) customAttrs.Container).MetadataToken;
+ else
+ throw new ReflectionException ("Unknown Custom Attribute parent");
+
+ uint value = ca.Resolved ?
+ m_sigWriter.AddCustomAttribute (GetCustomAttributeSig (ca), ca.Constructor) :
+ m_mdWriter.AddBlob (m_mod.GetAsByteArray (ca));
+ CustomAttributeRow caRow = m_rowWriter.CreateCustomAttributeRow (
+ parent,
+ GetMemberRefToken (ca.Constructor),
+ value);
+
+ caTable.Rows.Add (caRow);
+ }
+ }
+
+ public override void VisitMarshalSpec (MarshalSpec marshalSpec)
+ {
+ FieldMarshalTable fmTable = m_tableWriter.GetFieldMarshalTable ();
+ FieldMarshalRow fmRow = m_rowWriter.CreateFieldMarshalRow (
+ marshalSpec.Container.MetadataToken,
+ m_sigWriter.AddMarshalSig (GetMarshalSig (marshalSpec)));
+
+ fmTable.Rows.Add (fmRow);
+ }
+
+ void WriteConstant (IHasConstant hc, TypeReference type)
+ {
+ ConstantTable cTable = m_tableWriter.GetConstantTable ();
+ ElementType et;
+ if (type is TypeDefinition && (type as TypeDefinition).IsEnum) {
+ Type t = hc.Constant.GetType ();
+ if (t.IsEnum)
+ t = Enum.GetUnderlyingType (t);
+
+ et = GetCorrespondingType (string.Concat (t.Namespace, '.', t.Name));
+ } else
+ et = GetCorrespondingType (type.FullName);
+
+ if (et == ElementType.Object || et == ElementType.Type || et == ElementType.String)
+ et = hc.Constant == null ?
+ ElementType.Class :
+ GetCorrespondingType (hc.Constant.GetType ().FullName);
+
+ ConstantRow cRow = m_rowWriter.CreateConstantRow (
+ et,
+ hc.MetadataToken,
+ m_mdWriter.AddBlob (EncodeConstant (et, hc.Constant)));
+
+ cTable.Rows.Add (cRow);
+ }
+
+ void WriteLayout (FieldDefinition field)
+ {
+ FieldLayoutTable flTable = m_tableWriter.GetFieldLayoutTable ();
+ FieldLayoutRow flRow = m_rowWriter.CreateFieldLayoutRow (
+ field.Offset,
+ GetRidFor (field));
+
+ flTable.Rows.Add (flRow);
+ }
+
+ void WriteLayout (TypeDefinition type)
+ {
+ ClassLayoutTable clTable = m_tableWriter.GetClassLayoutTable ();
+ ClassLayoutRow clRow = m_rowWriter.CreateClassLayoutRow (
+ type.PackingSize,
+ type.ClassSize,
+ GetRidFor (type));
+
+ clTable.Rows.Add (clRow);
+ }
+
+ void WriteSemantic (MethodSemanticsAttributes attrs,
+ IMetadataTokenProvider member, MethodDefinition meth)
+ {
+ MethodSemanticsTable msTable = m_tableWriter.GetMethodSemanticsTable ();
+ MethodSemanticsRow msRow = m_rowWriter.CreateMethodSemanticsRow (
+ attrs,
+ GetRidFor (meth),
+ member.MetadataToken);
+
+ msTable.Rows.Add (msRow);
+ }
+
+ void SortTables ()
+ {
+ TablesHeap th = m_mdWriter.GetMetadataRoot ().Streams.TablesHeap;
+ th.Sorted = 0;
+
+ if (th.HasTable (NestedClassTable.RId))
+ m_tableWriter.GetNestedClassTable ().Rows.Sort (
+ TableComparers.NestedClass.Instance);
+ th.Sorted |= ((long) 1 << NestedClassTable.RId);
+
+ if (th.HasTable (InterfaceImplTable.RId))
+ m_tableWriter.GetInterfaceImplTable ().Rows.Sort (
+ TableComparers.InterfaceImpl.Instance);
+ th.Sorted |= ((long) 1 << InterfaceImplTable.RId);
+
+ if (th.HasTable (ConstantTable.RId))
+ m_tableWriter.GetConstantTable ().Rows.Sort (
+ TableComparers.Constant.Instance);
+ th.Sorted |= ((long) 1 << ConstantTable.RId);
+
+ if (th.HasTable (MethodSemanticsTable.RId))
+ m_tableWriter.GetMethodSemanticsTable ().Rows.Sort (
+ TableComparers.MethodSem.Instance);
+ th.Sorted |= ((long) 1 << MethodSemanticsTable.RId);
+
+ if (th.HasTable (FieldMarshalTable.RId))
+ m_tableWriter.GetFieldMarshalTable ().Rows.Sort (
+ TableComparers.FieldMarshal.Instance);
+ th.Sorted |= ((long) 1 << FieldMarshalTable.RId);
+
+ if (th.HasTable (ClassLayoutTable.RId))
+ m_tableWriter.GetClassLayoutTable ().Rows.Sort (
+ TableComparers.TypeLayout.Instance);
+ th.Sorted |= ((long) 1 << ClassLayoutTable.RId);
+
+ if (th.HasTable (FieldLayoutTable.RId))
+ m_tableWriter.GetFieldLayoutTable ().Rows.Sort (
+ TableComparers.FieldLayout.Instance);
+ th.Sorted |= ((long) 1 << FieldLayoutTable.RId);
+
+ if (th.HasTable (ImplMapTable.RId))
+ m_tableWriter.GetImplMapTable ().Rows.Sort (
+ TableComparers.PInvoke.Instance);
+ th.Sorted |= ((long) 1 << ImplMapTable.RId);
+
+ if (th.HasTable (FieldRVATable.RId))
+ m_tableWriter.GetFieldRVATable ().Rows.Sort (
+ TableComparers.FieldRVA.Instance);
+ th.Sorted |= ((long) 1 << FieldRVATable.RId);
+
+ if (th.HasTable (MethodImplTable.RId))
+ m_tableWriter.GetMethodImplTable ().Rows.Sort (
+ TableComparers.Override.Instance);
+ th.Sorted |= ((long) 1 << MethodImplTable.RId);
+
+ if (th.HasTable (CustomAttributeTable.RId))
+ m_tableWriter.GetCustomAttributeTable ().Rows.Sort (
+ TableComparers.CustomAttribute.Instance);
+ th.Sorted |= ((long) 1 << CustomAttributeTable.RId);
+
+ if (th.HasTable (DeclSecurityTable.RId))
+ m_tableWriter.GetDeclSecurityTable ().Rows.Sort (
+ TableComparers.SecurityDeclaration.Instance);
+ th.Sorted |= ((long) 1 << DeclSecurityTable.RId);
+ }
+
+ void CompleteGenericTables ()
+ {
+ if (m_genericParamStack.Count == 0)
+ return;
+
+ TablesHeap th = m_mdWriter.GetMetadataRoot ().Streams.TablesHeap;
+ GenericParamTable gpTable = m_tableWriter.GetGenericParamTable ();
+
+ m_genericParamStack.Sort (TableComparers.GenericParam.Instance);
+
+ foreach (GenericParameter gp in m_genericParamStack) {
+ GenericParamRow gpRow = m_rowWriter.CreateGenericParamRow (
+ (ushort) gp.Owner.GenericParameters.IndexOf (gp),
+ gp.Attributes,
+ gp.Owner.MetadataToken,
+ m_mdWriter.AddString (gp.Name));
+
+ gpTable.Rows.Add (gpRow);
+ gp.MetadataToken = new MetadataToken (TokenType.GenericParam, (uint) gpTable.Rows.Count);
+
+ if (gp.HasCustomAttributes)
+ VisitCustomAttributeCollection (gp.CustomAttributes);
+
+ if (!gp.HasConstraints)
+ continue;
+
+ GenericParamConstraintTable gpcTable = m_tableWriter.GetGenericParamConstraintTable ();
+
+ foreach (TypeReference constraint in gp.Constraints) {
+ GenericParamConstraintRow gpcRow = m_rowWriter.CreateGenericParamConstraintRow (
+ (uint) gpTable.Rows.Count,
+ GetTypeDefOrRefToken (constraint));
+
+ gpcTable.Rows.Add (gpcRow);
+ }
+ }
+
+ th.Sorted |= ((long) 1 << GenericParamTable.RId);
+ th.Sorted |= ((long) 1 << GenericParamConstraintTable.RId);
+ }
+
+ public override void TerminateModuleDefinition (ModuleDefinition module)
+ {
+ if (module.Assembly.HasCustomAttributes)
+ VisitCustomAttributeCollection (module.Assembly.CustomAttributes);
+ if (module.Assembly.HasSecurityDeclarations)
+ VisitSecurityDeclarationCollection (module.Assembly.SecurityDeclarations);
+ if (module.HasCustomAttributes)
+ VisitCustomAttributeCollection (module.CustomAttributes);
+
+ if (module.ExternTypes.Count > 0)
+ VisitExternTypeCollection (module.ExternTypes);
+
+ CompleteGenericTables ();
+ SortTables ();
+
+ MethodTable mTable = m_tableWriter.GetMethodTable ();
+ for (int i = 0; i < m_methodStack.Count; i++) {
+ MethodDefinition meth = (MethodDefinition) m_methodStack [i];
+ if (meth.HasBody)
+ mTable [i].RVA = m_codeWriter.WriteMethodBody (meth);
+ }
+
+ if (m_fieldStack.Count > 0) {
+ FieldRVATable frTable = null;
+ foreach (FieldDefinition field in m_fieldStack) {
+ if (field.InitialValue != null && field.InitialValue.Length > 0) {
+ if (frTable == null)
+ frTable = m_tableWriter.GetFieldRVATable ();
+
+ FieldRVARow frRow = m_rowWriter.CreateFieldRVARow (
+ m_mdWriter.GetDataCursor (),
+ field.MetadataToken.RID);
+
+ m_mdWriter.AddData (field.InitialValue.Length + 3 & (~3));
+ m_mdWriter.AddFieldInitData (field.InitialValue);
+
+ frTable.Rows.Add (frRow);
+ }
+ }
+ }
+
+ if (m_symbolWriter != null)
+ m_symbolWriter.Dispose ();
+
+ if (m_mod.Assembly.EntryPoint != null)
+ m_mdWriter.EntryPointToken =
+ ((uint) TokenType.Method) | GetRidFor (m_mod.Assembly.EntryPoint);
+
+ m_mod.Image.MetadataRoot.Accept (m_mdWriter);
+ }
+
+ public static ElementType GetCorrespondingType (string fullName)
+ {
+ switch (fullName) {
+ case Constants.Boolean :
+ return ElementType.Boolean;
+ case Constants.Char :
+ return ElementType.Char;
+ case Constants.SByte :
+ return ElementType.I1;
+ case Constants.Int16 :
+ return ElementType.I2;
+ case Constants.Int32 :
+ return ElementType.I4;
+ case Constants.Int64 :
+ return ElementType.I8;
+ case Constants.Byte :
+ return ElementType.U1;
+ case Constants.UInt16 :
+ return ElementType.U2;
+ case Constants.UInt32 :
+ return ElementType.U4;
+ case Constants.UInt64 :
+ return ElementType.U8;
+ case Constants.Single :
+ return ElementType.R4;
+ case Constants.Double :
+ return ElementType.R8;
+ case Constants.String :
+ return ElementType.String;
+ case Constants.Type :
+ return ElementType.Type;
+ case Constants.Object :
+ return ElementType.Object;
+ default:
+ return ElementType.Class;
+ }
+ }
+
+ byte [] EncodeConstant (ElementType et, object value)
+ {
+ m_constWriter.Empty ();
+
+ if (value == null)
+ et = ElementType.Class;
+
+ IConvertible ic = value as IConvertible;
+ IFormatProvider fp = CultureInfo.CurrentCulture.NumberFormat;
+
+ switch (et) {
+ case ElementType.Boolean :
+ m_constWriter.Write ((byte) (ic.ToBoolean (fp) ? 1 : 0));
+ break;
+ case ElementType.Char :
+ m_constWriter.Write ((ushort) ic.ToChar (fp));
+ break;
+ case ElementType.I1 :
+ m_constWriter.Write (ic.ToSByte (fp));
+ break;
+ case ElementType.I2 :
+ m_constWriter.Write (ic.ToInt16 (fp));
+ break;
+ case ElementType.I4 :
+ m_constWriter.Write (ic.ToInt32 (fp));
+ break;
+ case ElementType.I8 :
+ m_constWriter.Write (ic.ToInt64 (fp));
+ break;
+ case ElementType.U1 :
+ m_constWriter.Write (ic.ToByte (fp));
+ break;
+ case ElementType.U2 :
+ m_constWriter.Write (ic.ToUInt16 (fp));
+ break;
+ case ElementType.U4 :
+ m_constWriter.Write (ic.ToUInt32 (fp));
+ break;
+ case ElementType.U8 :
+ m_constWriter.Write (ic.ToUInt64 (fp));
+ break;
+ case ElementType.R4 :
+ m_constWriter.Write (ic.ToSingle (fp));
+ break;
+ case ElementType.R8 :
+ m_constWriter.Write (ic.ToDouble (fp));
+ break;
+ case ElementType.String :
+ m_constWriter.Write (Encoding.Unicode.GetBytes ((string) value));
+ break;
+ case ElementType.Class :
+ m_constWriter.Write (new byte [4]);
+ break;
+ default :
+ throw new ArgumentException ("Non valid element for a constant");
+ }
+
+ return m_constWriter.ToArray ();
+ }
+
+ public SigType GetSigType (TypeReference type)
+ {
+ string name = type.FullName;
+
+ switch (name) {
+ case Constants.Void :
+ return new SigType (ElementType.Void);
+ case Constants.Object :
+ return new SigType (ElementType.Object);
+ case Constants.Boolean :
+ return new SigType (ElementType.Boolean);
+ case Constants.String :
+ return new SigType (ElementType.String);
+ case Constants.Char :
+ return new SigType (ElementType.Char);
+ case Constants.SByte :
+ return new SigType (ElementType.I1);
+ case Constants.Byte :
+ return new SigType (ElementType.U1);
+ case Constants.Int16 :
+ return new SigType (ElementType.I2);
+ case Constants.UInt16 :
+ return new SigType (ElementType.U2);
+ case Constants.Int32 :
+ return new SigType (ElementType.I4);
+ case Constants.UInt32 :
+ return new SigType (ElementType.U4);
+ case Constants.Int64 :
+ return new SigType (ElementType.I8);
+ case Constants.UInt64 :
+ return new SigType (ElementType.U8);
+ case Constants.Single :
+ return new SigType (ElementType.R4);
+ case Constants.Double :
+ return new SigType (ElementType.R8);
+ case Constants.IntPtr :
+ return new SigType (ElementType.I);
+ case Constants.UIntPtr :
+ return new SigType (ElementType.U);
+ case Constants.TypedReference :
+ return new SigType (ElementType.TypedByRef);
+ }
+
+ if (type is GenericParameter) {
+ GenericParameter gp = type as GenericParameter;
+ int pos = gp.Owner.GenericParameters.IndexOf (gp);
+ if (gp.Owner is TypeReference)
+ return new VAR (pos);
+ else if (gp.Owner is MethodReference)
+ return new MVAR (pos);
+ else
+ throw new ReflectionException ("Unkown generic parameter type");
+ } else if (type is GenericInstanceType) {
+ GenericInstanceType git = type as GenericInstanceType;
+ GENERICINST gi = new GENERICINST ();
+ gi.ValueType = git.IsValueType;
+ gi.Type = GetTypeDefOrRefToken (git.ElementType);
+ gi.Signature = new GenericInstSignature ();
+ gi.Signature.Arity = git.GenericArguments.Count;
+ gi.Signature.Types = new GenericArg [gi.Signature.Arity];
+ for (int i = 0; i < git.GenericArguments.Count; i++)
+ gi.Signature.Types [i] = GetGenericArgSig (git.GenericArguments [i]);
+
+ return gi;
+ } else if (type is ArrayType) {
+ ArrayType aryType = type as ArrayType;
+ if (aryType.IsSizedArray) {
+ SZARRAY szary = new SZARRAY ();
+ szary.CustomMods = GetCustomMods (aryType.ElementType);
+ szary.Type = GetSigType (aryType.ElementType);
+ return szary;
+ }
+
+ // not optimized
+ ArrayShape shape = new ArrayShape ();
+ shape.Rank = aryType.Dimensions.Count;
+ shape.NumSizes = 0;
+
+ for (int i = 0; i < shape.Rank; i++) {
+ ArrayDimension dim = aryType.Dimensions [i];
+ if (dim.UpperBound > 0)
+ shape.NumSizes++;
+ }
+
+ shape.Sizes = new int [shape.NumSizes];
+ shape.NumLoBounds = shape.Rank;
+ shape.LoBounds = new int [shape.NumLoBounds];
+
+ for (int i = 0; i < shape.Rank; i++) {
+ ArrayDimension dim = aryType.Dimensions [i];
+ shape.LoBounds [i] = dim.LowerBound;
+ if (dim.UpperBound > 0)
+ shape.Sizes [i] = dim.UpperBound - dim.LowerBound + 1;
+ }
+
+ ARRAY ary = new ARRAY ();
+ ary.Shape = shape;
+ ary.CustomMods = GetCustomMods (aryType.ElementType);
+ ary.Type = GetSigType (aryType.ElementType);
+ return ary;
+ } else if (type is PointerType) {
+ PTR p = new PTR ();
+ TypeReference elementType = (type as PointerType).ElementType;
+ p.Void = elementType.FullName == Constants.Void;
+ if (!p.Void) {
+ p.CustomMods = GetCustomMods (elementType);
+ p.PtrType = GetSigType (elementType);
+ }
+ return p;
+ } else if (type is FunctionPointerType) {
+ FNPTR fp = new FNPTR ();
+ FunctionPointerType fptr = type as FunctionPointerType;
+
+ int sentinel = fptr.GetSentinel ();
+ if (sentinel < 0)
+ fp.Method = GetMethodDefSig (fptr);
+ else
+ fp.Method = GetMethodRefSig (fptr);
+
+ return fp;
+ } else if (type is TypeSpecification) {
+ return GetSigType ((type as TypeSpecification).ElementType);
+ } else if (type.IsValueType) {
+ VALUETYPE vt = new VALUETYPE ();
+ vt.Type = GetTypeDefOrRefToken (type);
+ return vt;
+ } else {
+ CLASS c = new CLASS ();
+ c.Type = GetTypeDefOrRefToken (type);
+ return c;
+ }
+ }
+
+ public GenericArg GetGenericArgSig (TypeReference type)
+ {
+ GenericArg arg = new GenericArg (GetSigType (type));
+ arg.CustomMods = GetCustomMods (type);
+ return arg;
+ }
+
+ public CustomMod [] GetCustomMods (TypeReference type)
+ {
+ ModType modifier = type as ModType;
+ if (modifier == null)
+ return CustomMod.EmptyCustomMod;
+
+ ArrayList cmods = new ArrayList ();
+ do {
+ CustomMod cmod = new CustomMod ();
+ cmod.TypeDefOrRef = GetTypeDefOrRefToken (modifier.ModifierType);
+
+ if (modifier is ModifierOptional)
+ cmod.CMOD = CustomMod.CMODType.OPT;
+ else if (modifier is ModifierRequired)
+ cmod.CMOD = CustomMod.CMODType.REQD;
+
+ cmods.Add (cmod);
+ modifier = modifier.ElementType as ModType;
+ } while (modifier != null);
+
+ return cmods.ToArray (typeof (CustomMod)) as CustomMod [];
+ }
+
+ public Signature GetMemberRefSig (MemberReference member)
+ {
+ if (member is FieldReference)
+ return GetFieldSig (member as FieldReference);
+ else
+ return GetMemberRefSig (member as MethodReference);
+ }
+
+ public FieldSig GetFieldSig (FieldReference field)
+ {
+ FieldSig sig = new FieldSig ();
+ sig.CallingConvention |= 0x6;
+ sig.Field = true;
+ sig.CustomMods = GetCustomMods (field.FieldType);
+ sig.Type = GetSigType (field.FieldType);
+ return sig;
+ }
+
+ Param [] GetParametersSig (ParameterDefinitionCollection parameters)
+ {
+ Param [] ret = new Param [parameters.Count];
+ for (int i = 0; i < ret.Length; i++) {
+ ParameterDefinition pDef = parameters [i];
+ Param p = new Param ();
+ p.CustomMods = GetCustomMods (pDef.ParameterType);
+ if (pDef.ParameterType.FullName == Constants.TypedReference)
+ p.TypedByRef = true;
+ else if (IsByReferenceType (pDef.ParameterType)) {
+ p.ByRef = true;
+ p.Type = GetSigType (pDef.ParameterType);
+ } else
+ p.Type = GetSigType (pDef.ParameterType);
+ ret [i] = p;
+ }
+ return ret;
+ }
+
+ void CompleteMethodSig (IMethodSignature meth, MethodSig sig)
+ {
+ sig.HasThis = meth.HasThis;
+ sig.ExplicitThis = meth.ExplicitThis;
+ if (sig.HasThis)
+ sig.CallingConvention |= 0x20;
+ if (sig.ExplicitThis)
+ sig.CallingConvention |= 0x40;
+
+ if ((meth.CallingConvention & MethodCallingConvention.VarArg) != 0)
+ sig.CallingConvention |= 0x5;
+
+ sig.ParamCount = meth.Parameters.Count;
+ sig.Parameters = GetParametersSig (meth.Parameters);
+
+ RetType rtSig = new RetType ();
+ rtSig.CustomMods = GetCustomMods (meth.ReturnType.ReturnType);
+
+ if (meth.ReturnType.ReturnType.FullName == Constants.Void)
+ rtSig.Void = true;
+ else if (meth.ReturnType.ReturnType.FullName == Constants.TypedReference)
+ rtSig.TypedByRef = true;
+ else if (IsByReferenceType (meth.ReturnType.ReturnType)) {
+ rtSig.ByRef = true;
+ rtSig.Type = GetSigType (meth.ReturnType.ReturnType);
+ } else
+ rtSig.Type = GetSigType (meth.ReturnType.ReturnType);
+
+ sig.RetType = rtSig;
+ }
+
+ static bool IsByReferenceType (TypeReference type)
+ {
+ TypeSpecification ts = type as TypeSpecification;
+ while (ts != null) {
+ if (ts is ReferenceType)
+ return true;
+ ts = ts.ElementType as TypeSpecification;
+ }
+ return false;
+ }
+
+ public MethodRefSig GetMethodRefSig (IMethodSignature meth)
+ {
+ MethodReference methodRef = meth as MethodReference;
+ if (methodRef != null && methodRef.GenericParameters.Count > 0)
+ return GetMethodDefSig (meth);
+
+ MethodRefSig methSig = new MethodRefSig ();
+
+ CompleteMethodSig (meth, methSig);
+
+ int sentinel = meth.GetSentinel ();
+ if (sentinel >= 0)
+ methSig.Sentinel = sentinel;
+
+ if ((meth.CallingConvention & MethodCallingConvention.C) != 0)
+ methSig.CallingConvention |= 0x1;
+ else if ((meth.CallingConvention & MethodCallingConvention.StdCall) != 0)
+ methSig.CallingConvention |= 0x2;
+ else if ((meth.CallingConvention & MethodCallingConvention.ThisCall) != 0)
+ methSig.CallingConvention |= 0x3;
+ else if ((meth.CallingConvention & MethodCallingConvention.FastCall) != 0)
+ methSig.CallingConvention |= 0x4;
+
+ return methSig;
+ }
+
+ public MethodDefSig GetMethodDefSig (IMethodSignature meth)
+ {
+ MethodDefSig sig = new MethodDefSig ();
+
+ CompleteMethodSig (meth, sig);
+
+ MethodReference methodRef = meth as MethodReference;
+ if (methodRef != null && methodRef.GenericParameters.Count > 0) {
+ sig.CallingConvention |= 0x10;
+ sig.GenericParameterCount = methodRef.GenericParameters.Count;
+ }
+
+ return sig;
+ }
+
+ public PropertySig GetPropertySig (PropertyDefinition prop)
+ {
+ PropertySig ps = new PropertySig ();
+ ps.CallingConvention |= 0x8;
+
+ bool hasThis;
+ bool explicitThis;
+ MethodCallingConvention mcc;
+ ParameterDefinitionCollection parameters = prop.Parameters;
+
+ MethodDefinition meth;
+ if (prop.GetMethod != null)
+ meth = prop.GetMethod;
+ else if (prop.SetMethod != null)
+ meth = prop.SetMethod;
+ else
+ meth = null;
+
+ if (meth != null) {
+ hasThis = meth.HasThis;
+ explicitThis = meth.ExplicitThis;
+ mcc = meth.CallingConvention;
+ } else {
+ hasThis = explicitThis = false;
+ mcc = MethodCallingConvention.Default;
+ }
+
+ if (hasThis)
+ ps.CallingConvention |= 0x20;
+ if (explicitThis)
+ ps.CallingConvention |= 0x40;
+
+ if ((mcc & MethodCallingConvention.VarArg) != 0)
+ ps.CallingConvention |= 0x5;
+
+ int paramCount = parameters != null ? parameters.Count : 0;
+
+ ps.ParamCount = paramCount;
+ ps.Parameters = GetParametersSig (parameters);
+ ps.CustomMods = GetCustomMods (prop.PropertyType);
+ ps.Type = GetSigType (prop.PropertyType);
+
+ return ps;
+ }
+
+ public TypeSpec GetTypeSpecSig (TypeReference type)
+ {
+ TypeSpec ts = new TypeSpec ();
+ ts.CustomMods = GetCustomMods (type);
+ ts.Type = GetSigType (type);
+ return ts;
+ }
+
+ public MethodSpec GetMethodSpecSig (GenericInstanceMethod gim)
+ {
+ GenericInstSignature gis = new GenericInstSignature ();
+ gis.Arity = gim.GenericArguments.Count;
+ gis.Types = new GenericArg [gis.Arity];
+ for (int i = 0; i < gis.Arity; i++)
+ gis.Types [i] = GetGenericArgSig (gim.GenericArguments [i]);
+
+ return new MethodSpec (gis);
+ }
+
+ static string GetObjectTypeName (object o)
+ {
+ Type t = o.GetType ();
+ return string.Concat (t.Namespace, ".", t.Name);
+ }
+
+ static CustomAttrib.Elem CreateElem (TypeReference type, object value)
+ {
+ CustomAttrib.Elem elem = new CustomAttrib.Elem ();
+ elem.Value = value;
+ elem.ElemType = type;
+ elem.FieldOrPropType = GetCorrespondingType (type.FullName);
+
+ switch (elem.FieldOrPropType) {
+ case ElementType.Boolean :
+ case ElementType.Char :
+ case ElementType.R4 :
+ case ElementType.R8 :
+ case ElementType.I1 :
+ case ElementType.I2 :
+ case ElementType.I4 :
+ case ElementType.I8 :
+ case ElementType.U1 :
+ case ElementType.U2 :
+ case ElementType.U4 :
+ case ElementType.U8 :
+ elem.Simple = true;
+ break;
+ case ElementType.String:
+ elem.String = true;
+ break;
+ case ElementType.Type:
+ elem.Type = true;
+ break;
+ case ElementType.Object:
+ elem.BoxedValueType = true;
+ if (value == null)
+ elem.FieldOrPropType = ElementType.String;
+ else
+ elem.FieldOrPropType = GetCorrespondingType (
+ GetObjectTypeName (value));
+ break;
+ }
+
+ return elem;
+ }
+
+ static CustomAttrib.FixedArg CreateFixedArg (TypeReference type, object value)
+ {
+ CustomAttrib.FixedArg fa = new CustomAttrib.FixedArg ();
+ if (value is object []) {
+ fa.SzArray = true;
+ object [] values = value as object [];
+ TypeReference obj = ((ArrayType) type).ElementType;
+ fa.NumElem = (uint) values.Length;
+ fa.Elems = new CustomAttrib.Elem [values.Length];
+ for (int i = 0; i < values.Length; i++)
+ fa.Elems [i] = CreateElem (obj, values [i]);
+ } else {
+ fa.Elems = new CustomAttrib.Elem [1];
+ fa.Elems [0] = CreateElem (type, value);
+ }
+
+ return fa;
+ }
+
+ static CustomAttrib.NamedArg CreateNamedArg (TypeReference type, string name,
+ object value, bool field)
+ {
+ CustomAttrib.NamedArg na = new CustomAttrib.NamedArg ();
+ na.Field = field;
+ na.Property = !field;
+
+ na.FieldOrPropName = name;
+ na.FieldOrPropType = GetCorrespondingType (type.FullName);
+ na.FixedArg = CreateFixedArg (type, value);
+
+ return na;
+ }
+
+ public static CustomAttrib GetCustomAttributeSig (CustomAttribute ca)
+ {
+ CustomAttrib cas = new CustomAttrib (ca.Constructor);
+ cas.Prolog = CustomAttrib.StdProlog;
+
+ cas.FixedArgs = new CustomAttrib.FixedArg [ca.Constructor.Parameters.Count];
+
+ for (int i = 0; i < cas.FixedArgs.Length; i++)
+ cas.FixedArgs [i] = CreateFixedArg (
+ ca.Constructor.Parameters [i].ParameterType, ca.ConstructorParameters [i]);
+
+ int nn = ca.Fields.Count + ca.Properties.Count;
+ cas.NumNamed = (ushort) nn;
+ cas.NamedArgs = new CustomAttrib.NamedArg [nn];
+
+ if (cas.NamedArgs.Length > 0) {
+ int curs = 0;
+ foreach (DictionaryEntry entry in ca.Fields) {
+ string field = (string) entry.Key;
+ cas.NamedArgs [curs++] = CreateNamedArg (
+ ca.GetFieldType (field), field, entry.Value, true);
+ }
+
+ foreach (DictionaryEntry entry in ca.Properties) {
+ string property = (string) entry.Key;
+ cas.NamedArgs [curs++] = CreateNamedArg (
+ ca.GetPropertyType (property), property, entry.Value, false);
+ }
+ }
+
+ return cas;
+ }
+
+ static MarshalSig GetMarshalSig (MarshalSpec mSpec)
+ {
+ MarshalSig ms = new MarshalSig (mSpec.NativeIntrinsic);
+
+ if (mSpec is ArrayMarshalSpec) {
+ ArrayMarshalSpec amd = mSpec as ArrayMarshalSpec;
+ MarshalSig.Array ar = new MarshalSig.Array ();
+ ar.ArrayElemType = amd.ElemType;
+ ar.NumElem = amd.NumElem;
+ ar.ParamNum = amd.ParamNum;
+ ar.ElemMult = amd.ElemMult;
+ ms.Spec = ar;
+ } else if (mSpec is CustomMarshalerSpec) {
+ CustomMarshalerSpec cmd = mSpec as CustomMarshalerSpec;
+ MarshalSig.CustomMarshaler cm = new MarshalSig.CustomMarshaler ();
+ cm.Guid = cmd.Guid.ToString ();
+ cm.UnmanagedType = cmd.UnmanagedType;
+ cm.ManagedType = cmd.ManagedType;
+ cm.Cookie = cmd.Cookie;
+ ms.Spec = cm;
+ } else if (mSpec is FixedArraySpec) {
+ FixedArraySpec fad = mSpec as FixedArraySpec;
+ MarshalSig.FixedArray fa = new MarshalSig.FixedArray ();
+ fa.ArrayElemType = fad.ElemType;
+ fa.NumElem = fad.NumElem;
+ ms.Spec = fa;
+ } else if (mSpec is FixedSysStringSpec) {
+ MarshalSig.FixedSysString fss = new MarshalSig.FixedSysString ();
+ fss.Size = (mSpec as FixedSysStringSpec).Size;
+ ms.Spec = fss;
+ } else if (mSpec is SafeArraySpec) {
+ MarshalSig.SafeArray sa = new MarshalSig.SafeArray ();
+ sa.ArrayElemType = (mSpec as SafeArraySpec).ElemType;
+ ms.Spec = sa;
+ }
+
+ return ms;
+ }
+
+ public void WriteSymbols (ModuleDefinition module)
+ {
+ if (!m_saveSymbols)
+ return;
+
+ if (m_asmOutput == null)
+ m_asmOutput = module.Assembly.Name.Name + "." + (module.Assembly.Kind == AssemblyKind.Dll ? "dll" : "exe");
+
+ if (m_symbolWriter == null)
+ m_symbolWriter = SymbolStoreHelper.GetWriter (module, m_asmOutput);
+
+ foreach (TypeDefinition type in module.Types) {
+ if (type.HasMethods) {
+ foreach (MethodDefinition method in type.Methods)
+ WriteSymbols (method);
+ }
+ if (type.HasConstructors) {
+ foreach (MethodDefinition ctor in type.Constructors)
+ WriteSymbols (ctor);
+ }
+ }
+
+ m_symbolWriter.Dispose ();
+ }
+
+ void WriteSymbols (MethodDefinition meth)
+ {
+ if (!meth.HasBody)
+ return;
+
+ m_symbolWriter.Write (meth.Body);
+ }
+ }
+}
--- /dev/null
+//
+// Resource.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System.Collections;
+
+ internal abstract class Resource : IAnnotationProvider, IReflectionStructureVisitable {
+
+ string m_name;
+ ManifestResourceAttributes m_attributes;
+ IDictionary m_annotations;
+
+ public string Name {
+ get { return m_name; }
+ set { m_name = value; }
+ }
+
+ public ManifestResourceAttributes Flags {
+ get { return m_attributes; }
+ set { m_attributes = value; }
+ }
+
+ IDictionary IAnnotationProvider.Annotations {
+ get {
+ if (m_annotations == null)
+ m_annotations = new Hashtable ();
+ return m_annotations;
+ }
+ }
+
+ #region ManifestResourceAttributes
+
+ public bool IsPublic {
+ get { return (m_attributes & ManifestResourceAttributes.VisibilityMask) == ManifestResourceAttributes.Public; }
+ set {
+ if (value) {
+ m_attributes &= ~ManifestResourceAttributes.VisibilityMask;
+ m_attributes |= ManifestResourceAttributes.Public;
+ } else
+ m_attributes &= ~(ManifestResourceAttributes.VisibilityMask & ManifestResourceAttributes.Public);
+ }
+ }
+
+ public bool IsPrivate {
+ get { return (m_attributes & ManifestResourceAttributes.VisibilityMask) == ManifestResourceAttributes.Private; }
+ set {
+ if (value) {
+ m_attributes &= ~ManifestResourceAttributes.VisibilityMask;
+ m_attributes |= ManifestResourceAttributes.Private;
+ } else
+ m_attributes &= ~(ManifestResourceAttributes.VisibilityMask & ManifestResourceAttributes.Private);
+ }
+ }
+
+ #endregion
+
+ internal Resource (string name, ManifestResourceAttributes attributes)
+ {
+ m_name = name;
+ m_attributes = attributes;
+ }
+
+ public abstract void Accept (IReflectionStructureVisitor visitor);
+ }
+}
--- /dev/null
+//
+// ResourceCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Wed Sep 27 12:46:54 CEST 2006
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Cil;
+
+ internal sealed class ResourceCollection : CollectionBase, IReflectionStructureVisitable {
+
+ ModuleDefinition m_container;
+
+ public Resource this [int index] {
+ get { return List [index] as Resource; }
+ set { List [index] = value; }
+ }
+
+ public ModuleDefinition Container {
+ get { return m_container; }
+ }
+
+ public ResourceCollection (ModuleDefinition container)
+ {
+ m_container = container;
+ }
+
+ public void Add (Resource value)
+ {
+ List.Add (value);
+ }
+
+ public bool Contains (Resource value)
+ {
+ return List.Contains (value);
+ }
+
+ public int IndexOf (Resource value)
+ {
+ return List.IndexOf (value);
+ }
+
+ public void Insert (int index, Resource value)
+ {
+ List.Insert (index, value);
+ }
+
+ public void Remove (Resource value)
+ {
+ List.Remove (value);
+ }
+
+ protected override void OnValidate (object o)
+ {
+ if (! (o is Resource))
+ throw new ArgumentException ("Must be of type " + typeof (Resource).FullName);
+ }
+
+ public void Accept (IReflectionStructureVisitor visitor)
+ {
+ visitor.VisitResourceCollection (this);
+ }
+ }
+}
--- /dev/null
+//
+// SecurityAction.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal enum SecurityAction : short {
+ Request = 1,
+ Demand = 2,
+ Assert = 3,
+ Deny = 4,
+ PermitOnly = 5,
+ LinkDemand = 6,
+ InheritDemand = 7,
+ RequestMinimum = 8,
+ RequestOptional = 9,
+ RequestRefuse = 10,
+ PreJitGrant = 11,
+ PreJitDeny = 12,
+ NonCasDemand = 13,
+ NonCasLinkDemand = 14,
+ NonCasInheritance = 15
+ }
+}
--- /dev/null
+//
+// SecurityDeclaration.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+ using System.Security;
+
+ internal sealed class SecurityDeclaration : IRequireResolving, IAnnotationProvider, IReflectionVisitable {
+
+ SecurityAction m_action;
+ SecurityDeclarationReader m_reader;
+ IDictionary m_annotations;
+
+#if !CF_1_0 && !CF_2_0
+ PermissionSet m_permSet;
+#endif
+
+ bool m_resolved;
+ byte [] m_blob;
+
+ public SecurityAction Action {
+ get { return m_action; }
+ set { m_action = value; }
+ }
+
+#if !CF_1_0 && !CF_2_0
+ public PermissionSet PermissionSet {
+ get { return m_permSet; }
+ set { m_permSet = value; }
+ }
+#endif
+
+ public bool Resolved {
+ get { return m_resolved; }
+ set { m_resolved = value; }
+ }
+
+ public byte [] Blob {
+ get { return m_blob; }
+ set { m_blob = value; }
+ }
+
+ IDictionary IAnnotationProvider.Annotations {
+ get {
+ if (m_annotations == null)
+ m_annotations = new Hashtable ();
+ return m_annotations;
+ }
+ }
+
+ public SecurityDeclaration (SecurityAction action)
+ {
+ m_action = action;
+ }
+
+ internal SecurityDeclaration (SecurityAction action, SecurityDeclarationReader reader)
+ {
+ m_action = action;
+ m_reader = reader;
+ }
+
+ public SecurityDeclaration Clone ()
+ {
+ return Clone (this);
+ }
+
+ internal static SecurityDeclaration Clone (SecurityDeclaration sec)
+ {
+ SecurityDeclaration sd = new SecurityDeclaration (sec.Action);
+ if (!sec.Resolved) {
+ sd.Resolved = false;
+ sd.Blob = sec.Blob;
+ return sd;
+ }
+
+#if !CF_1_0 && !CF_2_0
+ sd.PermissionSet = sec.PermissionSet.Copy ();
+#endif
+ return sd;
+ }
+
+ public bool Resolve ()
+ {
+ if (m_resolved)
+ return true;
+
+ if (m_reader == null)
+ return false;
+
+ SecurityDeclaration clone = m_reader.FromByteArray (m_action, m_blob, true);
+ if (!clone.Resolved)
+ return false;
+
+ m_action = clone.Action;
+#if !CF_1_0 && !CF_2_0
+ m_permSet = clone.PermissionSet.Copy ();
+#endif
+ m_resolved = true;
+
+ return true;
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitSecurityDeclaration (this);
+ }
+ }
+}
+
--- /dev/null
+//
+// SecurityDeclarationCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ internal sealed class SecurityDeclarationCollection : IReflectionVisitable, IEnumerable {
+
+ IDictionary m_items;
+ IHasSecurity m_container;
+
+ public SecurityDeclaration this [int index] {
+ get { return m_items [index] as SecurityDeclaration; }
+ set { m_items [index] = value; }
+ }
+
+ public SecurityDeclaration this [SecurityAction action] {
+ get { return m_items [action] as SecurityDeclaration; }
+ set { m_items [action] = value; }
+ }
+
+ public IHasSecurity Container {
+ get { return m_container; }
+ }
+
+ public int Count {
+ get { return m_items.Count; }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ public SecurityDeclarationCollection (IHasSecurity container)
+ {
+ m_container = container;
+ m_items = new Hashtable ();
+ }
+
+ public void Add (SecurityDeclaration value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
+ // Each action can only be added once so...
+ SecurityDeclaration current = (SecurityDeclaration) m_items[value.Action];
+ if (current != null) {
+ // ... further additions are transformed into unions
+#if !CF_1_0 && !CF_2_0
+ current.PermissionSet = current.PermissionSet.Union (value.PermissionSet);
+#endif
+ } else {
+ m_items.Add (value.Action, value);
+ SetHasSecurity (true);
+ }
+ }
+
+ public void Clear ()
+ {
+ m_items.Clear ();
+ SetHasSecurity (false);
+ }
+
+ public bool Contains (SecurityAction action)
+ {
+ return (m_items [action] != null);
+ }
+
+ public bool Contains (SecurityDeclaration value)
+ {
+ if (value == null)
+ return (m_items.Count == 0);
+
+ SecurityDeclaration item = (SecurityDeclaration) m_items[value.Action];
+ if (item == null)
+ return false;
+
+#if !CF_1_0 && !CF_2_0
+ return value.PermissionSet.IsSubsetOf (item.PermissionSet);
+#else
+ // XXX For CF, this concept does not exist--so always be true
+ return true;
+#endif
+ }
+
+ public void Remove (SecurityAction action)
+ {
+ m_items.Remove (action);
+ SetHasSecurity (this.Count > 0);
+ }
+
+ public void CopyTo (Array ary, int index)
+ {
+ m_items.Values.CopyTo (ary, index);
+ }
+
+ public IEnumerator GetEnumerator ()
+ {
+ return m_items.Values.GetEnumerator ();
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitSecurityDeclarationCollection (this);
+ }
+
+ private void SetHasSecurity (bool value)
+ {
+ TypeDefinition td = (m_container as TypeDefinition);
+ if (td != null) {
+ if (value)
+ td.Attributes |= TypeAttributes.HasSecurity;
+ else
+ td.Attributes &= ~TypeAttributes.HasSecurity;
+ return;
+ }
+ MethodDefinition md = (m_container as MethodDefinition);
+ if (md != null) {
+ if (value)
+ md.Attributes |= MethodAttributes.HasSecurity;
+ else
+ md.Attributes &= ~MethodAttributes.HasSecurity;
+ }
+ }
+ }
+}
--- /dev/null
+//
+// SecurityDeclarationReader.cs
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.IO;
+ using System.Reflection;
+ using System.Security;
+ using SSP = System.Security.Permissions;
+ using System.Text;
+
+ using Mono.Cecil.Metadata;
+ using Mono.Cecil.Signatures;
+ using Mono.Xml;
+
+ internal sealed class SecurityDeclarationReader {
+
+ private SecurityParser m_parser;
+ private SignatureReader sr;
+
+ public SecurityDeclarationReader (MetadataRoot root, ReflectionReader reader)
+ {
+ sr = new SignatureReader (root, reader);
+ }
+
+ public SecurityParser Parser {
+ get {
+ if (m_parser == null)
+ m_parser = new SecurityParser ();
+ return m_parser;
+ }
+ }
+
+ public SecurityDeclaration FromByteArray (SecurityAction action, byte [] declaration)
+ {
+ return FromByteArray (action, declaration, false);
+ }
+
+ static bool IsEmptyDeclaration (byte [] declaration)
+ {
+ return declaration == null || declaration.Length == 0 ||
+ (declaration.Length == 1 && declaration [0] == 0);
+ }
+
+ public SecurityDeclaration FromByteArray (SecurityAction action, byte [] declaration, bool resolve)
+ {
+ SecurityDeclaration dec = new SecurityDeclaration (action, this);
+#if !CF_1_0 && !CF_2_0
+ dec.PermissionSet = new PermissionSet (SSP.PermissionState.None);
+
+ if (IsEmptyDeclaration (declaration))
+ return dec;
+
+ if (declaration[0] == 0x2e) {
+ // new binary format introduced in 2.0
+ int pos = 1;
+ int start;
+ int numattr = Utilities.ReadCompressedInteger (declaration, pos, out start);
+ if (numattr == 0)
+ return dec;
+
+ BinaryReader br = new BinaryReader (new MemoryStream (declaration));
+ for (int i = 0; i < numattr; i++) {
+ pos = start;
+ SSP.SecurityAttribute sa = CreateSecurityAttribute (action, br, declaration, pos, out start, resolve);
+ if (sa == null) {
+ dec.Resolved = false;
+ dec.Blob = declaration;
+ return dec;
+ }
+
+ try {
+ IPermission p = sa.CreatePermission ();
+ dec.PermissionSet.AddPermission (p);
+ } catch {
+ dec.Resolved = false;
+ dec.Blob = declaration;
+ return dec;
+ }
+ }
+
+ dec.Resolved = true;
+ } else {
+ Parser.LoadXml (Encoding.Unicode.GetString (declaration));
+ try {
+ dec.PermissionSet.FromXml (Parser.ToXml ());
+ dec.PermissionSet.ToXml ();
+ dec.Resolved = true;
+ } catch {
+ dec.Resolved = false;
+ dec.Blob = declaration;
+ }
+ }
+#endif
+ return dec;
+ }
+
+#if !CF_1_0 && !CF_2_0
+ private SSP.SecurityAttribute CreateSecurityAttribute (SecurityAction action, BinaryReader br, byte [] permset, int pos, out int start, bool resolve)
+ {
+ string cname = SignatureReader.ReadUTF8String (permset, pos, out start);
+ Type secattr = null;
+
+ // note: the SecurityAction parameter isn't important to generate the XML
+ SSP.SecurityAttribute sa = null;
+ try {
+ secattr = Type.GetType (cname, false);
+ if (secattr == null)
+ return null;
+
+ sa = Activator.CreateInstance (secattr, new object [] {(SSP.SecurityAction) action}) as SSP.SecurityAttribute;
+ } catch {}
+
+ if (sa == null)
+ return null;
+
+ // encoded length of all parameters (we don't need the value - except the updated pos)
+ Utilities.ReadCompressedInteger (permset, start, out pos);
+ int numparams = Utilities.ReadCompressedInteger (permset, pos, out start);
+ if (numparams == 0)
+ return sa;
+
+ br.BaseStream.Position = start;
+ for (int j = 0; j < numparams; j++) {
+ bool read = true;
+ CustomAttrib.NamedArg na = sr.ReadNamedArg (permset, br, ref read, resolve);
+ if (!read)
+ return null;
+
+ if (na.Field) {
+ FieldInfo fi = secattr.GetField (na.FieldOrPropName);
+ fi.SetValue (sa, na.FixedArg.Elems[0].Value);
+ } else if (na.Property) {
+ PropertyInfo pi = secattr.GetProperty (na.FieldOrPropName);
+ pi.SetValue (sa, na.FixedArg.Elems[0].Value, null);
+ }
+ }
+
+ start = (int) br.BaseStream.Position;
+
+ return sa;
+ }
+#endif
+ }
+}
--- /dev/null
+//
+// SentinelType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2007 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class SentinelType : TypeSpecification {
+
+ public SentinelType (TypeReference elementType) : base (elementType)
+ {
+ }
+ }
+}
--- /dev/null
+//
+// StructureReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.IO;
+
+ using Mono.Cecil.Binary;
+ using Mono.Cecil.Metadata;
+
+ internal sealed class StructureReader : BaseStructureVisitor {
+
+ ImageReader m_ir;
+ Image m_img;
+ bool m_manifestOnly;
+ AssemblyDefinition m_asmDef;
+ ModuleDefinition m_module;
+ MetadataStreamCollection m_streams;
+ TablesHeap m_tHeap;
+ MetadataTableReader m_tableReader;
+
+ public bool ManifestOnly {
+ get { return m_manifestOnly; }
+ }
+
+ public ImageReader ImageReader {
+ get { return m_ir; }
+ }
+
+ public Image Image {
+ get { return m_img; }
+ }
+
+ public StructureReader (ImageReader ir)
+ {
+ if (ir.Image.CLIHeader == null)
+ throw new ImageFormatException ("The image is not a managed assembly");
+
+ m_ir = ir;
+ m_img = ir.Image;
+ m_streams = m_img.MetadataRoot.Streams;
+ m_tHeap = m_streams.TablesHeap;
+ m_tableReader = ir.MetadataReader.TableReader;
+ }
+
+ public StructureReader (ImageReader ir, bool manifestOnly) : this (ir)
+ {
+ m_manifestOnly = manifestOnly;
+ }
+
+ byte [] ReadBlob (uint pointer)
+ {
+ if (pointer == 0)
+ return new byte [0];
+
+ return m_streams.BlobHeap.Read (pointer);
+ }
+
+ string ReadString (uint pointer)
+ {
+ return m_streams.StringsHeap [pointer];
+ }
+
+ public override void VisitAssemblyDefinition (AssemblyDefinition asm)
+ {
+ if (!m_tHeap.HasTable (AssemblyTable.RId))
+ throw new ReflectionException ("No assembly manifest");
+
+ asm.MetadataToken = new MetadataToken (TokenType.Assembly, 1);
+ m_asmDef = asm;
+
+ switch (m_img.MetadataRoot.Header.Version) {
+ case "v1.0.3705" :
+ asm.Runtime = TargetRuntime.NET_1_0;
+ break;
+ case "v1.1.4322" :
+ asm.Runtime = TargetRuntime.NET_1_1;
+ break;
+ case "v2.0.50727":
+ asm.Runtime = TargetRuntime.NET_2_0;
+ break;
+ case "v4.0.30319" :
+ asm.Runtime = TargetRuntime.NET_4_0;
+ break;
+ }
+
+ if ((m_img.PEFileHeader.Characteristics & ImageCharacteristics.Dll) != 0)
+ asm.Kind = AssemblyKind.Dll;
+ else if (m_img.PEOptionalHeader.NTSpecificFields.SubSystem == SubSystem.WindowsGui ||
+ m_img.PEOptionalHeader.NTSpecificFields.SubSystem == SubSystem.WindowsCeGui)
+ asm.Kind = AssemblyKind.Windows;
+ else
+ asm.Kind = AssemblyKind.Console;
+ }
+
+ public override void VisitAssemblyNameDefinition (AssemblyNameDefinition name)
+ {
+ AssemblyTable atable = m_tableReader.GetAssemblyTable ();
+ AssemblyRow arow = atable [0];
+ name.Name = ReadString (arow.Name);
+ name.Flags = arow.Flags;
+ name.PublicKey = ReadBlob (arow.PublicKey);
+
+ name.Culture = ReadString (arow.Culture);
+ name.Version = new Version (
+ arow.MajorVersion, arow.MinorVersion,
+ arow.BuildNumber, arow.RevisionNumber);
+ name.HashAlgorithm = arow.HashAlgId;
+ name.MetadataToken = new MetadataToken (TokenType.Assembly, 1);
+ }
+
+ public override void VisitAssemblyNameReferenceCollection (AssemblyNameReferenceCollection names)
+ {
+ if (!m_tHeap.HasTable (AssemblyRefTable.RId))
+ return;
+
+ AssemblyRefTable arTable = m_tableReader.GetAssemblyRefTable ();
+ for (int i = 0; i < arTable.Rows.Count; i++) {
+ AssemblyRefRow arRow = arTable [i];
+ AssemblyNameReference aname = new AssemblyNameReference (
+ ReadString (arRow.Name),
+ ReadString (arRow.Culture),
+ new Version (arRow.MajorVersion, arRow.MinorVersion,
+ arRow.BuildNumber, arRow.RevisionNumber));
+ aname.PublicKeyToken = ReadBlob (arRow.PublicKeyOrToken);
+ aname.Hash = ReadBlob (arRow.HashValue);
+ aname.Flags = arRow.Flags;
+ aname.MetadataToken = new MetadataToken (TokenType.AssemblyRef, (uint) i + 1);
+ names.Add (aname);
+ }
+ }
+
+ public override void VisitResourceCollection (ResourceCollection resources)
+ {
+ if (!m_tHeap.HasTable (ManifestResourceTable.RId))
+ return;
+
+ ManifestResourceTable mrTable = m_tableReader.GetManifestResourceTable ();
+ FileTable fTable = m_tableReader.GetFileTable ();
+
+ for (int i = 0; i < mrTable.Rows.Count; i++) {
+ ManifestResourceRow mrRow = mrTable [i];
+ if (mrRow.Implementation.RID == 0) {
+ EmbeddedResource eres = new EmbeddedResource (
+ ReadString (mrRow.Name), mrRow.Flags);
+
+ BinaryReader br = m_ir.MetadataReader.GetDataReader (
+ m_img.CLIHeader.Resources.VirtualAddress);
+ br.BaseStream.Position += mrRow.Offset;
+
+ eres.Data = br.ReadBytes (br.ReadInt32 ());
+
+ resources.Add (eres);
+ continue;
+ }
+
+ switch (mrRow.Implementation.TokenType) {
+ case TokenType.File :
+ FileRow fRow = fTable [(int) mrRow.Implementation.RID - 1];
+ LinkedResource lres = new LinkedResource (
+ ReadString (mrRow.Name), mrRow.Flags,
+ ReadString (fRow.Name));
+ lres.Hash = ReadBlob (fRow.HashValue);
+ resources.Add (lres);
+ break;
+ case TokenType.AssemblyRef :
+ AssemblyNameReference asm =
+ m_module.AssemblyReferences [(int) mrRow.Implementation.RID - 1];
+ AssemblyLinkedResource alr = new AssemblyLinkedResource (
+ ReadString (mrRow.Name),
+ mrRow.Flags, asm);
+ resources.Add (alr);
+ break;
+ }
+ }
+ }
+
+ public override void VisitModuleDefinitionCollection (ModuleDefinitionCollection modules)
+ {
+ ModuleTable mt = m_tableReader.GetModuleTable ();
+ if (mt == null || mt.Rows.Count != 1)
+ throw new ReflectionException ("Can not read main module");
+
+ ModuleRow mr = mt [0];
+ string name = ReadString (mr.Name);
+ ModuleDefinition main = new ModuleDefinition (name, m_asmDef, this, true);
+ main.Mvid = m_streams.GuidHeap [mr.Mvid];
+ main.MetadataToken = new MetadataToken (TokenType.Module, 1);
+ modules.Add (main);
+ m_module = main;
+ m_module.Accept (this);
+
+ FileTable ftable = m_tableReader.GetFileTable ();
+ if (ftable == null || ftable.Rows.Count == 0)
+ return;
+
+ foreach (FileRow frow in ftable.Rows) {
+ if (frow.Flags != FileAttributes.ContainsMetaData)
+ continue;
+
+ name = ReadString (frow.Name);
+ FileInfo location = new FileInfo (
+ m_img.FileInformation != null ? Path.Combine (m_img.FileInformation.DirectoryName, name) : name);
+ if (!File.Exists (location.FullName))
+ throw new FileNotFoundException ("Module not found : " + name);
+
+ try {
+ ImageReader module = ImageReader.Read (location.FullName);
+ mt = module.Image.MetadataRoot.Streams.TablesHeap [ModuleTable.RId] as ModuleTable;
+ if (mt == null || mt.Rows.Count != 1)
+ throw new ReflectionException ("Can not read module : " + name);
+
+ mr = mt [0];
+ ModuleDefinition modext = new ModuleDefinition (name, m_asmDef,
+ new StructureReader (module, m_manifestOnly), false);
+ modext.Mvid = module.Image.MetadataRoot.Streams.GuidHeap [mr.Mvid];
+
+ modules.Add (modext);
+ modext.Accept (this);
+ } catch (ReflectionException) {
+ throw;
+ } catch (Exception e) {
+ throw new ReflectionException ("Can not read module : " + name, e);
+ }
+ }
+ }
+
+ public override void VisitModuleReferenceCollection (ModuleReferenceCollection modules)
+ {
+ if (!m_tHeap.HasTable (ModuleRefTable.RId))
+ return;
+
+ ModuleRefTable mrTable = m_tableReader.GetModuleRefTable ();
+ for (int i = 0; i < mrTable.Rows.Count; i++) {
+ ModuleRefRow mrRow = mrTable [i];
+ ModuleReference mod = new ModuleReference (ReadString (mrRow.Name));
+ mod.MetadataToken = MetadataToken.FromMetadataRow (TokenType.ModuleRef, i);
+ modules.Add (mod);
+ }
+ }
+
+ public override void TerminateAssemblyDefinition (AssemblyDefinition asm)
+ {
+ if (m_manifestOnly)
+ return;
+
+ foreach (ModuleDefinition mod in asm.Modules)
+ mod.Controller.Reader.VisitModuleDefinition (mod);
+ }
+ }
+}
--- /dev/null
+//
+// StructureWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.IO;
+
+ using Mono.Cecil.Binary;
+ using Mono.Cecil.Metadata;
+
+ internal sealed class StructureWriter : BaseStructureVisitor {
+
+ MetadataWriter m_mdWriter;
+ MetadataTableWriter m_tableWriter;
+ MetadataRowWriter m_rowWriter;
+
+ AssemblyDefinition m_asm;
+ BinaryWriter m_binaryWriter;
+
+ public AssemblyDefinition Assembly {
+ get { return m_asm; }
+ }
+
+ static void ResetImage (ModuleDefinition mod)
+ {
+ Image ni = Image.CreateImage ();
+ ni.Accept (new CopyImageVisitor (mod.Image));
+ mod.Image = ni;
+ }
+
+ public StructureWriter (AssemblyDefinition asm, BinaryWriter writer)
+ {
+ m_asm = asm;
+ m_binaryWriter = writer;
+ }
+
+ public BinaryWriter GetWriter ()
+ {
+ return m_binaryWriter;
+ }
+
+ public override void VisitAssemblyDefinition (AssemblyDefinition asm)
+ {
+ if (asm.Kind != AssemblyKind.Dll && asm.EntryPoint == null)
+ throw new ReflectionException ("Assembly does not have an entry point defined");
+
+ if ((asm.MainModule.Image.CLIHeader.Flags & RuntimeImage.ILOnly) == 0)
+ throw new NotSupportedException ("Can not write a mixed mode assembly");
+
+ foreach (ModuleDefinition module in asm.Modules)
+ if (module.Image.CLIHeader.Metadata.VirtualAddress != RVA.Zero)
+ ResetImage (module);
+
+ asm.MetadataToken = new MetadataToken (TokenType.Assembly, 1);
+ ReflectionWriter rw = asm.MainModule.Controller.Writer;
+ rw.StructureWriter = this;
+
+ m_mdWriter = rw.MetadataWriter;
+ m_tableWriter = rw.MetadataTableWriter;
+ m_rowWriter = rw.MetadataRowWriter;
+
+ if (!rw.SaveSymbols)
+ return;
+
+ FileStream fs = m_binaryWriter.BaseStream as FileStream;
+ if (fs != null)
+ rw.OutputFile = fs.Name;
+ }
+
+ public override void VisitAssemblyNameDefinition (AssemblyNameDefinition name)
+ {
+ AssemblyTable asmTable = m_tableWriter.GetAssemblyTable ();
+
+ if (name.PublicKey != null && name.PublicKey.Length > 0)
+ name.Flags |= AssemblyFlags.PublicKey;
+
+ AssemblyRow asmRow = m_rowWriter.CreateAssemblyRow (
+ name.HashAlgorithm,
+ (ushort) name.Version.Major,
+ (ushort) name.Version.Minor,
+ (ushort) name.Version.Build,
+ (ushort) name.Version.Revision,
+ name.Flags,
+ m_mdWriter.AddBlob (name.PublicKey),
+ m_mdWriter.AddString (name.Name),
+ m_mdWriter.AddString (name.Culture));
+
+ asmTable.Rows.Add (asmRow);
+ }
+
+ public override void VisitAssemblyNameReferenceCollection (AssemblyNameReferenceCollection references)
+ {
+ foreach (AssemblyNameReference name in references)
+ VisitAssemblyNameReference (name);
+ }
+
+ public override void VisitAssemblyNameReference (AssemblyNameReference name)
+ {
+ byte [] pkortoken;
+ if (name.PublicKey != null && name.PublicKey.Length > 0)
+ pkortoken = name.PublicKey;
+ else if (name.PublicKeyToken != null && name.PublicKeyToken.Length > 0)
+ pkortoken = name.PublicKeyToken;
+ else
+ pkortoken = new byte [0];
+
+ AssemblyRefTable arTable = m_tableWriter.GetAssemblyRefTable ();
+ AssemblyRefRow arRow = m_rowWriter.CreateAssemblyRefRow (
+ (ushort) name.Version.Major,
+ (ushort) name.Version.Minor,
+ (ushort) name.Version.Build,
+ (ushort) name.Version.Revision,
+ name.Flags,
+ m_mdWriter.AddBlob (pkortoken),
+ m_mdWriter.AddString (name.Name),
+ m_mdWriter.AddString (name.Culture),
+ m_mdWriter.AddBlob (name.Hash));
+
+ arTable.Rows.Add (arRow);
+ }
+
+ public override void VisitResourceCollection (ResourceCollection resources)
+ {
+ VisitCollection (resources);
+ }
+
+ public override void VisitEmbeddedResource (EmbeddedResource res)
+ {
+ AddManifestResource (
+ m_mdWriter.AddResource (res.Data),
+ res.Name, res.Flags,
+ new MetadataToken (TokenType.ManifestResource, 0));
+ }
+
+ public override void VisitLinkedResource (LinkedResource res)
+ {
+ FileTable fTable = m_tableWriter.GetFileTable ();
+ FileRow fRow = m_rowWriter.CreateFileRow (
+ Mono.Cecil.FileAttributes.ContainsNoMetaData,
+ m_mdWriter.AddString (res.File),
+ m_mdWriter.AddBlob (res.Hash));
+
+ fTable.Rows.Add (fRow);
+
+ AddManifestResource (
+ 0, res.Name, res.Flags,
+ new MetadataToken (TokenType.File, (uint) fTable.Rows.IndexOf (fRow) + 1));
+ }
+
+ public override void VisitAssemblyLinkedResource (AssemblyLinkedResource res)
+ {
+ MetadataToken impl = new MetadataToken (TokenType.AssemblyRef,
+ (uint) m_asm.MainModule.AssemblyReferences.IndexOf (res.Assembly) + 1);
+
+ AddManifestResource (0, res.Name, res.Flags, impl);
+ }
+
+ void AddManifestResource (uint offset, string name, ManifestResourceAttributes flags, MetadataToken impl)
+ {
+ ManifestResourceTable mrTable = m_tableWriter.GetManifestResourceTable ();
+ ManifestResourceRow mrRow = m_rowWriter.CreateManifestResourceRow (
+ offset,
+ flags,
+ m_mdWriter.AddString (name),
+ impl);
+
+ mrTable.Rows.Add (mrRow);
+ }
+
+ public override void VisitModuleDefinitionCollection (ModuleDefinitionCollection modules)
+ {
+ VisitCollection (modules);
+ }
+
+ public override void VisitModuleDefinition (ModuleDefinition module)
+ {
+ if (module.Main) {
+ ModuleTable modTable = m_tableWriter.GetModuleTable ();
+ ModuleRow modRow = m_rowWriter.CreateModuleRow (
+ 0,
+ m_mdWriter.AddString (module.Name),
+ m_mdWriter.AddGuid (module.Mvid),
+ 0,
+ 0);
+
+ modTable.Rows.Add (modRow);
+ module.MetadataToken = new MetadataToken (TokenType.Module, 1);
+ } else {
+ // multiple module assemblies
+ throw new NotImplementedException ();
+ }
+ }
+
+ public override void VisitModuleReferenceCollection (ModuleReferenceCollection modules)
+ {
+ VisitCollection (modules);
+ }
+
+ public override void VisitModuleReference (ModuleReference module)
+ {
+ ModuleRefTable mrTable = m_tableWriter.GetModuleRefTable ();
+ ModuleRefRow mrRow = m_rowWriter.CreateModuleRefRow (
+ m_mdWriter.AddString (module.Name));
+
+ mrTable.Rows.Add (mrRow);
+ }
+
+ public override void TerminateAssemblyDefinition (AssemblyDefinition asm)
+ {
+ foreach (ModuleDefinition mod in asm.Modules) {
+ ReflectionWriter writer = mod.Controller.Writer;
+ writer.VisitModuleDefinition (mod);
+ writer.VisitTypeReferenceCollection (mod.TypeReferences);
+ writer.VisitTypeDefinitionCollection (mod.Types);
+ writer.VisitMemberReferenceCollection (mod.MemberReferences);
+ writer.CompleteTypeDefinitions ();
+
+ writer.TerminateModuleDefinition (mod);
+ }
+ }
+ }
+}
--- /dev/null
+//
+// TableComparers.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+
+ using Mono.Cecil.Metadata;
+
+ sealed class TableComparers {
+
+ internal sealed class TypeDef : IComparer {
+
+ public static readonly TypeDef Instance = new TypeDef ();
+
+ public int Compare (object x, object y)
+ {
+ TypeDefinition a = x as TypeDefinition;
+ TypeDefinition b = y as TypeDefinition;
+
+ if (a == null || b == null)
+ throw new ReflectionException ("TypeDefComparer can only compare TypeDefinition");
+
+ if (a.Name == Constants.ModuleType && b.Name == Constants.ModuleType)
+ return 0;
+ else if (a.Name == Constants.ModuleType)
+ return -1;
+ else if (b.Name == Constants.ModuleType)
+ return 1;
+
+ return Comparer.Default.Compare (a.FullName, b.FullName);
+ }
+ }
+
+ internal sealed class TypeRef : IComparer {
+
+ public static readonly TypeRef Instance = new TypeRef ();
+
+ public int Compare (object x, object y)
+ {
+ TypeReference a = x as TypeReference;
+ TypeReference b = y as TypeReference;
+
+ if (a == null || b == null)
+ throw new ReflectionException ("TypeRefComparer can only compare TypeReference");
+
+ if (b.DeclaringType == a)
+ return -1;
+ else if (a.DeclaringType == b)
+ return 1;
+
+ return Comparer.Default.Compare (a.FullName, b.FullName);
+ }
+ }
+
+ internal sealed class NestedClass : IComparer {
+
+ public static readonly NestedClass Instance = new NestedClass ();
+
+ public int Compare (object x, object y)
+ {
+ NestedClassRow a = x as NestedClassRow;
+ NestedClassRow b = y as NestedClassRow;
+
+ return Comparer.Default.Compare (a.NestedClass, b.NestedClass);
+ }
+ }
+
+ internal sealed class Constant : IComparer {
+
+ public static readonly Constant Instance = new Constant ();
+
+ public int Compare (object x, object y)
+ {
+ ConstantRow a = x as ConstantRow;
+ ConstantRow b = y as ConstantRow;
+
+ return Comparer.Default.Compare (
+ Utilities.CompressMetadataToken (CodedIndex.HasConstant, a.Parent),
+ Utilities.CompressMetadataToken (CodedIndex.HasConstant, b.Parent));
+ }
+
+ }
+
+ internal sealed class InterfaceImpl : IComparer {
+
+ public static readonly InterfaceImpl Instance = new InterfaceImpl ();
+
+ public int Compare (object x, object y)
+ {
+ InterfaceImplRow a = x as InterfaceImplRow;
+ InterfaceImplRow b = y as InterfaceImplRow;
+
+ int klass = Comparer.Default.Compare (a.Class, b.Class);
+
+ if (klass == 0)
+ return Comparer.Default.Compare (
+ Utilities.CompressMetadataToken (CodedIndex.TypeDefOrRef, a.Interface),
+ Utilities.CompressMetadataToken (CodedIndex.TypeDefOrRef, b.Interface));
+
+ return klass;
+ }
+ }
+
+ internal sealed class MethodSem : IComparer {
+
+ public static readonly MethodSem Instance = new MethodSem ();
+
+ public int Compare (object x, object y)
+ {
+ MethodSemanticsRow a = x as MethodSemanticsRow;
+ MethodSemanticsRow b = y as MethodSemanticsRow;
+
+ return Comparer.Default.Compare (
+ Utilities.CompressMetadataToken (CodedIndex.HasSemantics, a.Association),
+ Utilities.CompressMetadataToken (CodedIndex.HasSemantics, b.Association));
+ }
+ }
+
+ internal sealed class CustomAttribute : IComparer {
+
+ public static readonly CustomAttribute Instance = new CustomAttribute ();
+
+ public int Compare (object x, object y)
+ {
+ CustomAttributeRow a = x as CustomAttributeRow;
+ CustomAttributeRow b = y as CustomAttributeRow;
+
+ return Comparer.Default.Compare (
+ Utilities.CompressMetadataToken (CodedIndex.HasCustomAttribute, a.Parent),
+ Utilities.CompressMetadataToken (CodedIndex.HasCustomAttribute, b.Parent));
+ }
+ }
+
+ internal sealed class SecurityDeclaration : IComparer {
+
+ public static readonly SecurityDeclaration Instance = new SecurityDeclaration ();
+
+ public int Compare (object x, object y)
+ {
+ DeclSecurityRow a = x as DeclSecurityRow;
+ DeclSecurityRow b = y as DeclSecurityRow;
+
+ return Comparer.Default.Compare (
+ Utilities.CompressMetadataToken (CodedIndex.HasDeclSecurity, a.Parent),
+ Utilities.CompressMetadataToken (CodedIndex.HasDeclSecurity, b.Parent));
+ }
+ }
+
+ internal sealed class Override : IComparer {
+
+ public static readonly Override Instance = new Override ();
+
+ public int Compare (object x, object y)
+ {
+ MethodImplRow a = x as MethodImplRow;
+ MethodImplRow b = y as MethodImplRow;
+
+ return Comparer.Default.Compare (a.Class, b.Class);
+ }
+ }
+
+ internal sealed class PInvoke : IComparer {
+
+ public static readonly PInvoke Instance = new PInvoke ();
+
+ public int Compare (object x, object y)
+ {
+ ImplMapRow a = x as ImplMapRow;
+ ImplMapRow b = y as ImplMapRow;
+
+ return Comparer.Default.Compare (a.MemberForwarded.RID, b.MemberForwarded.RID);
+ }
+ }
+
+ internal sealed class FieldRVA : IComparer {
+
+ public static readonly FieldRVA Instance = new FieldRVA ();
+
+ public int Compare (object x, object y)
+ {
+ FieldRVARow a = x as FieldRVARow;
+ FieldRVARow b = y as FieldRVARow;
+
+ return Comparer.Default.Compare (a.Field, b.Field);
+ }
+ }
+
+ internal sealed class FieldLayout : IComparer {
+
+ public static readonly FieldLayout Instance = new FieldLayout ();
+
+ public int Compare (object x, object y)
+ {
+ FieldLayoutRow a = x as FieldLayoutRow;
+ FieldLayoutRow b = y as FieldLayoutRow;
+
+ return Comparer.Default.Compare (a.Field, b.Field);
+ }
+ }
+
+ internal sealed class FieldMarshal : IComparer {
+
+ public static readonly FieldMarshal Instance = new FieldMarshal ();
+
+ public int Compare (object x, object y)
+ {
+ FieldMarshalRow a = x as FieldMarshalRow;
+ FieldMarshalRow b = y as FieldMarshalRow;
+
+ return Comparer.Default.Compare (
+ Utilities.CompressMetadataToken (CodedIndex.HasFieldMarshal, a.Parent),
+ Utilities.CompressMetadataToken (CodedIndex.HasFieldMarshal, b.Parent));
+ }
+ }
+
+ internal sealed class TypeLayout : IComparer {
+
+ public static readonly TypeLayout Instance = new TypeLayout ();
+
+ public int Compare (object x, object y)
+ {
+ ClassLayoutRow a = x as ClassLayoutRow;
+ ClassLayoutRow b = y as ClassLayoutRow;
+
+ return Comparer.Default.Compare (a.Parent, b.Parent);
+ }
+ }
+
+ internal sealed class GenericParam : IComparer {
+
+ public static readonly GenericParam Instance = new GenericParam ();
+
+ public int Compare (object x, object y)
+ {
+ GenericParameter a = x as GenericParameter;
+ GenericParameter b = y as GenericParameter;
+
+ int token = Comparer.Default.Compare (
+ Utilities.CompressMetadataToken (CodedIndex.TypeOrMethodDef, a.Owner.MetadataToken),
+ Utilities.CompressMetadataToken (CodedIndex.TypeOrMethodDef, b.Owner.MetadataToken));
+
+ if (token == 0)
+ return Comparer.Default.Compare (a.Position, b.Position);
+
+ return token;
+ }
+ }
+ }
+}
--- /dev/null
+//
+// TargetRuntime.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal enum TargetRuntime {
+ NET_1_0,
+ NET_1_1,
+ NET_2_0,
+ NET_4_0,
+ }
+}
--- /dev/null
+//
+// TypeAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ [Flags]
+ internal enum TypeAttributes : uint {
+ // Visibility attributes
+ VisibilityMask = 0x00000007, // Use this mask to retrieve visibility information
+ NotPublic = 0x00000000, // Class has no public scope
+ Public = 0x00000001, // Class has public scope
+ NestedPublic = 0x00000002, // Class is nested with public visibility
+ NestedPrivate = 0x00000003, // Class is nested with private visibility
+ NestedFamily = 0x00000004, // Class is nested with family visibility
+ NestedAssembly = 0x00000005, // Class is nested with assembly visibility
+ NestedFamANDAssem = 0x00000006, // Class is nested with family and assembly visibility
+ NestedFamORAssem = 0x00000007, // Class is nested with family or assembly visibility
+
+ // Class layout attributes
+ LayoutMask = 0x00000018, // Use this mask to retrieve class layout information
+ AutoLayout = 0x00000000, // Class fields are auto-laid out
+ SequentialLayout = 0x00000008, // Class fields are laid out sequentially
+ ExplicitLayout = 0x00000010, // Layout is supplied explicitly
+
+ // Class semantics attributes
+ ClassSemanticMask = 0x00000020, // Use this mask to retrieve class semantics information
+ Class = 0x00000000, // Type is a class
+ Interface = 0x00000020, // Type is an interface
+
+ // Special semantics in addition to class semantics
+ Abstract = 0x00000080, // Class is abstract
+ Sealed = 0x00000100, // Class cannot be extended
+ SpecialName = 0x00000400, // Class name is special
+
+ // Implementation attributes
+ Import = 0x00001000, // Class/Interface is imported
+ Serializable = 0x00002000, // Class is serializable
+
+ // String formatting attributes
+ StringFormatMask = 0x00030000, // Use this mask to retrieve string information for native interop
+ AnsiClass = 0x00000000, // LPSTR is interpreted as ANSI
+ UnicodeClass = 0x00010000, // LPSTR is interpreted as Unicode
+ AutoClass = 0x00020000, // LPSTR is interpreted automatically
+
+ // Class initialization attributes
+ BeforeFieldInit = 0x00100000, // Initialize the class before first static field access
+
+ // Additional flags
+ RTSpecialName = 0x00000800, // CLI provides 'special' behavior, depending upon the name of the Type
+ HasSecurity = 0x00040000, // Type has security associate with it
+ Forwarder = 0x00200000, // Exported type is a type forwarder
+ }
+}
--- /dev/null
+//
+// TypeDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal sealed class TypeDefinition : TypeReference, IMemberDefinition, IHasSecurity {
+
+ TypeAttributes m_attributes;
+ TypeReference m_baseType;
+
+ bool m_hasInfo;
+ ushort m_packingSize;
+ uint m_classSize;
+
+ InterfaceCollection m_interfaces;
+ NestedTypeCollection m_nestedTypes;
+ MethodDefinitionCollection m_methods;
+ ConstructorCollection m_ctors;
+ FieldDefinitionCollection m_fields;
+ EventDefinitionCollection m_events;
+ PropertyDefinitionCollection m_properties;
+ SecurityDeclarationCollection m_secDecls;
+
+ public TypeAttributes Attributes {
+ get { return m_attributes; }
+ set { m_attributes = value; }
+ }
+
+ public TypeReference BaseType {
+ get { return m_baseType; }
+ set { m_baseType = value; }
+ }
+
+ public bool HasLayoutInfo {
+ get { return m_hasInfo; }
+ }
+
+ public ushort PackingSize {
+ get { return m_packingSize; }
+ set {
+ m_hasInfo = true;
+ m_packingSize = value;
+ }
+ }
+
+ public uint ClassSize {
+ get { return m_classSize; }
+ set {
+ m_hasInfo = true;
+ m_classSize = value;
+ }
+ }
+
+ public bool HasInterfaces {
+ get { return (m_interfaces == null) ? false : (m_interfaces.Count > 0); }
+ }
+
+ public InterfaceCollection Interfaces {
+ get {
+ if (m_interfaces == null)
+ m_interfaces = new InterfaceCollection (this);
+
+ return m_interfaces;
+ }
+ }
+
+ public bool HasNestedTypes {
+ get { return (m_nestedTypes == null) ? false : (m_nestedTypes.Count > 0); }
+ }
+
+ public NestedTypeCollection NestedTypes {
+ get {
+ if (m_nestedTypes == null)
+ m_nestedTypes = new NestedTypeCollection (this);
+
+ return m_nestedTypes;
+ }
+ }
+
+ public bool HasMethods {
+ get { return (m_methods == null) ? false : (m_methods.Count > 0); }
+ }
+
+ public MethodDefinitionCollection Methods {
+ get {
+ if (m_methods == null)
+ m_methods = new MethodDefinitionCollection (this);
+
+ return m_methods;
+ }
+ }
+
+ public bool HasConstructors {
+ get { return (m_ctors == null) ? false : (m_ctors.Count > 0); }
+ }
+
+ public ConstructorCollection Constructors {
+ get {
+ if (m_ctors == null)
+ m_ctors = new ConstructorCollection (this);
+
+ return m_ctors;
+ }
+ }
+
+ public bool HasFields {
+ get { return (m_fields == null) ? false : (m_fields.Count > 0); }
+ }
+
+ public FieldDefinitionCollection Fields {
+ get {
+ if (m_fields == null)
+ m_fields = new FieldDefinitionCollection (this);
+
+ return m_fields;
+ }
+ }
+
+ public bool HasEvents {
+ get { return (m_events == null) ? false : (m_events.Count > 0); }
+ }
+
+ public EventDefinitionCollection Events {
+ get {
+ if (m_events == null)
+ m_events = new EventDefinitionCollection (this);
+
+ return m_events;
+ }
+ }
+
+ public bool HasProperties {
+ get { return (m_properties == null) ? false : (m_properties.Count > 0); }
+ }
+
+ public PropertyDefinitionCollection Properties {
+ get {
+ if (m_properties == null)
+ m_properties = new PropertyDefinitionCollection (this);
+
+ return m_properties;
+ }
+ }
+
+ public bool HasSecurityDeclarations {
+ get { return (m_secDecls == null) ? false : (m_secDecls.Count > 0); }
+ }
+
+ public SecurityDeclarationCollection SecurityDeclarations {
+ get {
+ if (m_secDecls == null)
+ m_secDecls = new SecurityDeclarationCollection (this);
+
+ return m_secDecls;
+ }
+ }
+
+ #region TypeAttributes
+
+ public bool IsNotPublic {
+ get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.VisibilityMask;
+ m_attributes |= TypeAttributes.NotPublic;
+ } else
+ m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NotPublic);
+ }
+ }
+
+ public bool IsPublic {
+ get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.VisibilityMask;
+ m_attributes |= TypeAttributes.Public;
+ } else
+ m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.Public);
+ }
+ }
+
+ public bool IsNestedPublic {
+ get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.VisibilityMask;
+ m_attributes |= TypeAttributes.NestedPublic;
+ } else
+ m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedPublic);
+ }
+ }
+
+ public bool IsNestedPrivate {
+ get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.VisibilityMask;
+ m_attributes |= TypeAttributes.NestedPrivate;
+ } else
+ m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedPrivate);
+ }
+ }
+
+ public bool IsNestedFamily {
+ get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.VisibilityMask;
+ m_attributes |= TypeAttributes.NestedFamily;
+ } else
+ m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedFamily);
+ }
+ }
+
+ public bool IsNestedAssembly {
+ get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.VisibilityMask;
+ m_attributes |= TypeAttributes.NestedAssembly;
+ } else
+ m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedAssembly);
+ }
+ }
+
+ public bool IsNestedFamilyAndAssembly {
+ get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.VisibilityMask;
+ m_attributes |= TypeAttributes.NestedFamANDAssem;
+ } else
+ m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedFamANDAssem);
+ }
+ }
+
+ public bool IsNestedFamilyOrAssembly {
+ get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.VisibilityMask;
+ m_attributes |= TypeAttributes.NestedFamORAssem;
+ } else
+ m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedFamORAssem);
+ }
+ }
+
+ public bool IsAutoLayout {
+ get { return (m_attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.LayoutMask;
+ m_attributes |= TypeAttributes.AutoLayout;
+ } else
+ m_attributes &= ~(TypeAttributes.LayoutMask & TypeAttributes.AutoLayout);
+ }
+ }
+
+ public bool IsSequentialLayout {
+ get { return (m_attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.LayoutMask;
+ m_attributes |= TypeAttributes.SequentialLayout;
+ } else
+ m_attributes &= ~(TypeAttributes.LayoutMask & TypeAttributes.SequentialLayout);
+ }
+ }
+
+ public bool IsExplicitLayout {
+ get { return (m_attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.LayoutMask;
+ m_attributes |= TypeAttributes.ExplicitLayout;
+ } else
+ m_attributes &= ~(TypeAttributes.LayoutMask & TypeAttributes.ExplicitLayout);
+ }
+ }
+
+ public bool IsClass {
+ get { return (m_attributes & TypeAttributes.ClassSemanticMask) == TypeAttributes.Class; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.ClassSemanticMask;
+ m_attributes |= TypeAttributes.Class;
+ } else
+ m_attributes &= ~(TypeAttributes.ClassSemanticMask & TypeAttributes.Class);
+ }
+ }
+
+ public bool IsInterface {
+ get { return (m_attributes & TypeAttributes.ClassSemanticMask) == TypeAttributes.Interface; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.ClassSemanticMask;
+ m_attributes |= TypeAttributes.Interface;
+ } else
+ m_attributes &= ~(TypeAttributes.ClassSemanticMask & TypeAttributes.Interface);
+ }
+ }
+
+ public bool IsAbstract {
+ get { return (m_attributes & TypeAttributes.Abstract) != 0; }
+ set {
+ if (value)
+ m_attributes |= TypeAttributes.Abstract;
+ else
+ m_attributes &= ~TypeAttributes.Abstract;
+ }
+ }
+
+ public bool IsSealed {
+ get { return (m_attributes & TypeAttributes.Sealed) != 0; }
+ set {
+ if (value)
+ m_attributes |= TypeAttributes.Sealed;
+ else
+ m_attributes &= ~TypeAttributes.Sealed;
+ }
+ }
+
+ public bool IsSpecialName {
+ get { return (m_attributes & TypeAttributes.SpecialName) != 0; }
+ set {
+ if (value)
+ m_attributes |= TypeAttributes.SpecialName;
+ else
+ m_attributes &= ~TypeAttributes.SpecialName;
+ }
+ }
+
+ public bool IsImport {
+ get { return (m_attributes & TypeAttributes.Import) != 0; }
+ set {
+ if (value)
+ m_attributes |= TypeAttributes.Import;
+ else
+ m_attributes &= ~TypeAttributes.Import;
+ }
+ }
+
+ public bool IsSerializable {
+ get { return (m_attributes & TypeAttributes.Serializable) != 0; }
+ set {
+ if (value)
+ m_attributes |= TypeAttributes.Serializable;
+ else
+ m_attributes &= ~TypeAttributes.Serializable;
+ }
+ }
+
+ public bool IsAnsiClass {
+ get { return (m_attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AnsiClass; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.StringFormatMask;
+ m_attributes |= TypeAttributes.AnsiClass;
+ } else
+ m_attributes &= ~(TypeAttributes.StringFormatMask & TypeAttributes.AnsiClass);
+ }
+ }
+
+ public bool IsUnicodeClass {
+ get { return (m_attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.StringFormatMask;
+ m_attributes |= TypeAttributes.UnicodeClass;
+ } else
+ m_attributes &= ~(TypeAttributes.StringFormatMask & TypeAttributes.UnicodeClass);
+ }
+ }
+
+ public bool IsAutoClass {
+ get { return (m_attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass; }
+ set {
+ if (value) {
+ m_attributes &= ~TypeAttributes.StringFormatMask;
+ m_attributes |= TypeAttributes.AutoClass;
+ } else
+ m_attributes &= ~(TypeAttributes.StringFormatMask & TypeAttributes.AutoClass);
+ }
+ }
+
+ public bool IsBeforeFieldInit {
+ get { return (m_attributes & TypeAttributes.BeforeFieldInit) != 0; }
+ set {
+ if (value)
+ m_attributes |= TypeAttributes.BeforeFieldInit;
+ else
+ m_attributes &= ~TypeAttributes.BeforeFieldInit;
+ }
+ }
+
+ public bool IsRuntimeSpecialName {
+ get { return (m_attributes & TypeAttributes.RTSpecialName) != 0; }
+ set {
+ if (value)
+ m_attributes |= TypeAttributes.RTSpecialName;
+ else
+ m_attributes &= ~TypeAttributes.RTSpecialName;
+ }
+ }
+
+ public bool HasSecurity {
+ get { return (m_attributes & TypeAttributes.HasSecurity) != 0; }
+ set {
+ if (value)
+ m_attributes |= TypeAttributes.HasSecurity;
+ else
+ m_attributes &= ~TypeAttributes.HasSecurity;
+ }
+ }
+
+ #endregion
+
+ public bool IsEnum {
+ get { return m_baseType != null && m_baseType.FullName == Constants.Enum; }
+ }
+
+ public override bool IsValueType {
+ get {
+ return m_baseType != null && ((m_baseType.FullName == Constants.Enum) ||
+ (m_baseType.FullName == Constants.ValueType && this.FullName != Constants.Enum));
+ }
+ }
+
+ public new TypeDefinition DeclaringType {
+ get { return (TypeDefinition) base.DeclaringType; }
+ set { base.DeclaringType = value; }
+ }
+
+ internal TypeDefinition (string name, string ns, TypeAttributes attrs) :
+ base (name, ns)
+ {
+ m_hasInfo = false;
+ m_attributes = attrs;
+ }
+
+ public TypeDefinition (string name, string ns,
+ TypeAttributes attributes, TypeReference baseType) :
+ this (name, ns, attributes)
+ {
+ this.BaseType = baseType;
+ }
+
+ public override TypeDefinition Resolve ()
+ {
+ return this;
+ }
+
+ public TypeDefinition Clone ()
+ {
+ return Clone (this, new ImportContext (NullReferenceImporter.Instance, this));
+ }
+
+ internal static TypeDefinition Clone (TypeDefinition type, ImportContext context)
+ {
+ TypeDefinition nt = new TypeDefinition (
+ type.Name,
+ type.Namespace,
+ type.Attributes);
+
+ TypeReference contextType = context.GenericContext.Type;
+
+ context.GenericContext.Type = nt;
+
+ GenericParameter.CloneInto (type, nt, context);
+
+ if (type.BaseType != null)
+ nt.BaseType = context.Import (type.BaseType);
+
+ if (type.HasLayoutInfo) {
+ nt.ClassSize = type.ClassSize;
+ nt.PackingSize = type.PackingSize;
+ }
+
+ if (type.HasFields) {
+ foreach (FieldDefinition field in type.Fields)
+ nt.Fields.Add (FieldDefinition.Clone (field, context));
+ }
+ if (type.HasConstructors) {
+ foreach (MethodDefinition ctor in type.Constructors)
+ nt.Constructors.Add (MethodDefinition.Clone (ctor, context));
+ }
+ if (type.HasMethods) {
+ foreach (MethodDefinition meth in type.Methods)
+ nt.Methods.Add (MethodDefinition.Clone (meth, context));
+ }
+ if (type.HasEvents) {
+ foreach (EventDefinition evt in type.Events)
+ nt.Events.Add (EventDefinition.Clone (evt, context));
+ }
+ if (type.HasProperties) {
+ foreach (PropertyDefinition prop in type.Properties)
+ nt.Properties.Add (PropertyDefinition.Clone (prop, context));
+ }
+ if (type.HasInterfaces) {
+ foreach (TypeReference intf in type.Interfaces)
+ nt.Interfaces.Add (context.Import (intf));
+ }
+ if (type.HasNestedTypes) {
+ foreach (TypeDefinition nested in type.NestedTypes)
+ nt.NestedTypes.Add (Clone (nested, context));
+ }
+ if (type.HasCustomAttributes) {
+ foreach (CustomAttribute ca in type.CustomAttributes)
+ nt.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
+ }
+ if (type.HasSecurityDeclarations) {
+ foreach (SecurityDeclaration dec in type.SecurityDeclarations)
+ nt.SecurityDeclarations.Add (SecurityDeclaration.Clone (dec));
+ }
+
+ context.GenericContext.Type = contextType;
+
+ return nt;
+ }
+
+ public override void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitTypeDefinition (this);
+
+ this.GenericParameters.Accept (visitor);
+ this.Interfaces.Accept (visitor);
+ this.Constructors.Accept (visitor);
+ this.Methods.Accept (visitor);
+ this.Fields.Accept (visitor);
+ this.Properties.Accept (visitor);
+ this.Events.Accept (visitor);
+ this.NestedTypes.Accept (visitor);
+ this.CustomAttributes.Accept (visitor);
+ this.SecurityDeclarations.Accept (visitor);
+ }
+ }
+}
--- /dev/null
+//
+// TypeDefinitionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Mar 30 18:43:56 +0200 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Specialized;
+
+ using Mono.Cecil.Cil;
+
+ using Hcp = Mono.Cecil.HashCodeProvider;
+ using Cmp = System.Collections.Comparer;
+
+ internal sealed class TypeDefinitionCollection : NameObjectCollectionBase, IList, IReflectionVisitable {
+
+ ModuleDefinition m_container;
+
+ public TypeDefinition this [int index] {
+ get { return this.BaseGet (index) as TypeDefinition; }
+ set { this.BaseSet (index, value); }
+ }
+
+ public TypeDefinition this [string fullName] {
+ get { return this.BaseGet (fullName) as TypeDefinition; }
+ set { this.BaseSet (fullName, value); }
+ }
+
+ public ModuleDefinition Container {
+ get { return m_container; }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ bool IList.IsReadOnly {
+ get { return false; }
+ }
+
+ bool IList.IsFixedSize {
+ get { return false; }
+ }
+
+ object IList.this [int index] {
+ get { return BaseGet (index); }
+ set {
+ Check (value);
+ BaseSet (index, value);
+ }
+ }
+
+ public TypeDefinitionCollection (ModuleDefinition container) :
+ base (Hcp.Instance, Cmp.Default)
+ {
+ m_container = container;
+ }
+
+ public void Add (TypeDefinition value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
+ Attach (value);
+
+ this.BaseAdd (value.FullName, value);
+ }
+
+ public void Clear ()
+ {
+ foreach (TypeDefinition item in this)
+ Detach (item);
+
+ this.BaseClear ();
+ }
+
+ public bool Contains (TypeDefinition value)
+ {
+ return Contains (value.FullName);
+ }
+
+ public bool Contains (string fullName)
+ {
+ return this.BaseGet (fullName) != null;
+ }
+
+ public int IndexOf (TypeDefinition value)
+ {
+ string [] keys = this.BaseGetAllKeys ();
+ return Array.IndexOf (keys, value.FullName, 0, keys.Length);
+ }
+
+ public void Remove (TypeDefinition value)
+ {
+ this.BaseRemove (value.FullName);
+
+ Detach (value);
+ }
+
+ public void RemoveAt (int index)
+ {
+ TypeDefinition item = this [index];
+ Remove (item);
+
+ Detach (item);
+ }
+
+ public void CopyTo (Array ary, int index)
+ {
+ this.BaseGetAllValues ().CopyTo (ary, index);
+ }
+
+ public new IEnumerator GetEnumerator ()
+ {
+ return this.BaseGetAllValues ().GetEnumerator ();
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitTypeDefinitionCollection (this);
+ }
+
+#if CF_1_0 || CF_2_0
+ internal object [] BaseGetAllValues ()
+ {
+ object [] values = new object [this.Count];
+ for (int i=0; i < values.Length; ++i) {
+ values [i] = this.BaseGet (i);
+ }
+ return values;
+ }
+#endif
+
+ void Check (object value)
+ {
+ if (!(value is TypeDefinition))
+ throw new ArgumentException ();
+ }
+
+ int IList.Add (object value)
+ {
+ Check (value);
+ Add (value as TypeDefinition);
+ return 0;
+ }
+
+ bool IList.Contains (object value)
+ {
+ Check (value);
+ return Contains (value as TypeDefinition);
+ }
+
+ int IList.IndexOf (object value)
+ {
+ throw new NotSupportedException ();
+ }
+
+ void IList.Insert (int index, object value)
+ {
+ throw new NotSupportedException ();
+ }
+
+ void IList.Remove (object value)
+ {
+ Check (value);
+ Remove (value as TypeDefinition);
+ }
+
+ void Detach (TypeReference type)
+ {
+ type.Module = null;
+ }
+
+ void Attach (TypeReference type)
+ {
+ if (type.Module != null)
+ throw new ReflectionException ("Type is already attached, clone it instead");
+
+ type.Module = m_container;
+ type.AttachToScope (m_container);
+
+ }
+ }
+}
--- /dev/null
+//
+// TypeReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal class TypeReference : MemberReference, IGenericParameterProvider, ICustomAttributeProvider {
+
+ string m_namespace;
+ bool m_fullNameDiscarded;
+ string m_fullName;
+ protected bool m_isValueType;
+ IMetadataScope m_scope;
+ ModuleDefinition m_module;
+
+ CustomAttributeCollection m_customAttrs;
+ GenericParameterCollection m_genparams;
+
+ public override string Name {
+ get { return base.Name; }
+ set {
+ base.Name = value;
+ m_fullNameDiscarded = true;
+ }
+ }
+
+ public virtual string Namespace {
+ get { return m_namespace; }
+ set {
+ m_namespace = value;
+ m_fullNameDiscarded = true;
+ }
+ }
+
+ public virtual bool IsValueType {
+ get { return m_isValueType; }
+ set { m_isValueType = value; }
+ }
+
+ public virtual ModuleDefinition Module {
+ get { return m_module; }
+ set { m_module = value; }
+ }
+
+ public bool HasCustomAttributes {
+ get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
+ }
+
+ public CustomAttributeCollection CustomAttributes {
+ get {
+ if (m_customAttrs == null)
+ m_customAttrs = new CustomAttributeCollection (this);
+
+ return m_customAttrs;
+ }
+ }
+
+ public bool HasGenericParameters {
+ get { return (m_genparams == null) ? false : (m_genparams.Count > 0); }
+ }
+
+ public GenericParameterCollection GenericParameters {
+ get {
+ if (m_genparams == null)
+ m_genparams = new GenericParameterCollection (this);
+ return m_genparams;
+ }
+ }
+
+ public virtual IMetadataScope Scope {
+ get {
+ if (this.DeclaringType != null)
+ return this.DeclaringType.Scope;
+
+ return m_scope;
+ }
+ }
+
+ public bool IsNested {
+ get { return this.DeclaringType != null; }
+ }
+
+ public virtual string FullName {
+ get {
+ if (m_fullName != null && !m_fullNameDiscarded)
+ return m_fullName;
+
+ if (this.IsNested)
+ return string.Concat (this.DeclaringType.FullName, "/", this.Name);
+
+ if (m_namespace == null || m_namespace.Length == 0)
+ return this.Name;
+
+ m_fullName = string.Concat (m_namespace, ".", this.Name);
+ m_fullNameDiscarded = false;
+ return m_fullName;
+ }
+ }
+
+ protected TypeReference (string name, string ns) : base (name)
+ {
+ m_namespace = ns;
+ m_fullNameDiscarded = false;
+ }
+
+ internal TypeReference (string name, string ns, IMetadataScope scope) : this (name, ns)
+ {
+ m_scope = scope;
+ }
+
+ public TypeReference (string name, string ns, IMetadataScope scope, bool valueType) :
+ this (name, ns, scope)
+ {
+ m_isValueType = valueType;
+ }
+
+ public virtual TypeDefinition Resolve ()
+ {
+ ModuleDefinition module = Module;
+ if (module == null)
+ return null;
+
+ return module.Resolver.Resolve (this);
+ }
+
+ public virtual TypeReference GetOriginalType ()
+ {
+ return this;
+ }
+
+ internal void AttachToScope (IMetadataScope scope)
+ {
+ m_scope = scope;
+ }
+
+ public override void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitTypeReference (this);
+ }
+
+ public override string ToString ()
+ {
+ return this.FullName;
+ }
+ }
+}
--- /dev/null
+//
+// TypeReferenceCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Generated by /CodeGen/cecil-gen.rb do not edit
+// Fri Mar 30 18:43:56 +0200 2007
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Specialized;
+
+ using Mono.Cecil.Cil;
+
+ using Hcp = Mono.Cecil.HashCodeProvider;
+ using Cmp = System.Collections.Comparer;
+
+ internal sealed class TypeReferenceCollection : NameObjectCollectionBase, IList, IReflectionVisitable {
+
+ ModuleDefinition m_container;
+
+ public TypeReference this [int index] {
+ get { return this.BaseGet (index) as TypeReference; }
+ set { this.BaseSet (index, value); }
+ }
+
+ public TypeReference this [string fullName] {
+ get { return this.BaseGet (fullName) as TypeReference; }
+ set { this.BaseSet (fullName, value); }
+ }
+
+ public ModuleDefinition Container {
+ get { return m_container; }
+ }
+
+ public bool IsSynchronized {
+ get { return false; }
+ }
+
+ public object SyncRoot {
+ get { return this; }
+ }
+
+ bool IList.IsReadOnly {
+ get { return false; }
+ }
+
+ bool IList.IsFixedSize {
+ get { return false; }
+ }
+
+ object IList.this [int index] {
+ get { return BaseGet (index); }
+ set {
+ Check (value);
+ BaseSet (index, value);
+ }
+ }
+
+ public TypeReferenceCollection (ModuleDefinition container) :
+ base (Hcp.Instance, Cmp.Default)
+ {
+ m_container = container;
+ }
+
+ public void Add (TypeReference value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
+ Attach (value);
+
+ this.BaseAdd (value.FullName, value);
+ }
+
+ public void Clear ()
+ {
+ foreach (TypeReference item in this)
+ Detach (item);
+
+ this.BaseClear ();
+ }
+
+ public bool Contains (TypeReference value)
+ {
+ return Contains (value.FullName);
+ }
+
+ public bool Contains (string fullName)
+ {
+ return this.BaseGet (fullName) != null;
+ }
+
+ public int IndexOf (TypeReference value)
+ {
+ string [] keys = this.BaseGetAllKeys ();
+ return Array.IndexOf (keys, value.FullName, 0, keys.Length);
+ }
+
+ public void Remove (TypeReference value)
+ {
+ this.BaseRemove (value.FullName);
+
+ Detach (value);
+ }
+
+ public void RemoveAt (int index)
+ {
+ TypeReference item = this [index];
+ Remove (item);
+
+ Detach (item);
+ }
+
+ public void CopyTo (Array ary, int index)
+ {
+ this.BaseGetAllValues ().CopyTo (ary, index);
+ }
+
+ public new IEnumerator GetEnumerator ()
+ {
+ return this.BaseGetAllValues ().GetEnumerator ();
+ }
+
+ public void Accept (IReflectionVisitor visitor)
+ {
+ visitor.VisitTypeReferenceCollection (this);
+ }
+
+#if CF_1_0 || CF_2_0
+ internal object [] BaseGetAllValues ()
+ {
+ object [] values = new object [this.Count];
+ for (int i=0; i < values.Length; ++i) {
+ values [i] = this.BaseGet (i);
+ }
+ return values;
+ }
+#endif
+
+ void Check (object value)
+ {
+ if (!(value is TypeReference))
+ throw new ArgumentException ();
+ }
+
+ int IList.Add (object value)
+ {
+ Check (value);
+ Add (value as TypeReference);
+ return 0;
+ }
+
+ bool IList.Contains (object value)
+ {
+ Check (value);
+ return Contains (value as TypeReference);
+ }
+
+ int IList.IndexOf (object value)
+ {
+ throw new NotSupportedException ();
+ }
+
+ void IList.Insert (int index, object value)
+ {
+ throw new NotSupportedException ();
+ }
+
+ void IList.Remove (object value)
+ {
+ Check (value);
+ Remove (value as TypeReference);
+ }
+
+ void Detach (TypeReference type)
+ {
+ type.Module = null;
+ }
+
+ void Attach (TypeReference type)
+ {
+ if (type.Module != null)
+ throw new ReflectionException ("Type is already attached, clone it instead");
+
+ type.Module = m_container;
+ }
+ }
+}
--- /dev/null
+//
+// TypeSpecification.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ using System;
+
+ internal abstract class TypeSpecification : TypeReference {
+
+ private TypeReference m_elementType;
+
+ public override string Name {
+ get { return m_elementType.Name; }
+ set { throw new NotSupportedException (); }
+ }
+
+ public override string Namespace {
+ get { return m_elementType.Namespace; }
+ set { throw new NotSupportedException (); }
+ }
+
+ public override bool IsValueType {
+ get { return m_elementType.IsValueType; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override IMetadataScope Scope {
+ get { return m_elementType.Scope; }
+ }
+
+ public override ModuleDefinition Module {
+ get { return m_elementType.Module; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public TypeReference ElementType {
+ get { return m_elementType; }
+ set { m_elementType = value; }
+ }
+
+ public override string FullName {
+ get { return m_elementType.FullName; }
+ }
+
+ internal TypeSpecification (TypeReference elementType) : base (string.Empty, string.Empty)
+ {
+ m_elementType = elementType;
+ }
+
+ public override TypeReference GetOriginalType ()
+ {
+ return m_elementType.GetOriginalType ();
+ }
+ }
+}
--- /dev/null
+//
+// VariantType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// (C) 2005 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ internal enum VariantType {
+ I2 = 2,
+ I4 = 3,
+ R4 = 4,
+ R8 = 5,
+ CY = 6,
+ DATE = 7,
+ BSTR = 8,
+ DISPATCH = 9,
+ ERROR = 10,
+ BOOL = 11,
+ VARIANT = 12,
+ UNKNOWN = 13,
+ DECIMAL = 14,
+ I1 = 16,
+ UI1 = 17,
+ UI2 = 18,
+ UI4 = 19,
+ INT = 22,
+ UINT = 23
+ }
+}
--- /dev/null
+//
+// Mono.Xml.SecurityParser.cs class implementation
+//
+// Author:
+// Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Security;
+
+namespace Mono.Xml {
+
+ // convert an XML document into SecurityElement objects
+ internal sealed class SecurityParser : SmallXmlParser, SmallXmlParser.IContentHandler {
+
+ private SecurityElement root;
+
+ public SecurityParser () : base ()
+ {
+ stack = new Stack ();
+ }
+
+ public void LoadXml (string xml)
+ {
+ root = null;
+#if CF_1_0
+ stack = new Stack ();
+#else
+ stack.Clear ();
+#endif
+ Parse (new StringReader (xml), this);
+ }
+
+ public SecurityElement ToXml ()
+ {
+ return root;
+ }
+
+ // IContentHandler
+
+ private SecurityElement current;
+ private Stack stack;
+
+ public void OnStartParsing (SmallXmlParser parser) {}
+
+ public void OnProcessingInstruction (string name, string text) {}
+
+ public void OnIgnorableWhitespace (string s) {}
+
+ public void OnStartElement (string name, SmallXmlParser.IAttrList attrs)
+ {
+ SecurityElement newel = new SecurityElement (name);
+ if (root == null) {
+ root = newel;
+ current = newel;
+ }
+ else {
+ SecurityElement parent = (SecurityElement) stack.Peek ();
+ parent.AddChild (newel);
+ }
+ stack.Push (newel);
+ current = newel;
+ // attributes
+ int n = attrs.Length;
+ for (int i=0; i < n; i++)
+ current.AddAttribute (attrs.GetName (i), attrs.GetValue (i));
+ }
+
+ public void OnEndElement (string name)
+ {
+ current = (SecurityElement) stack.Pop ();
+ }
+
+ public void OnChars (string ch)
+ {
+ current.Text = ch;
+ }
+
+ public void OnEndParsing (SmallXmlParser parser) {}
+ }
+}
+
--- /dev/null
+//
+// SmallXmlParser.cs
+//
+// Author:
+// Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+//
+// small xml parser that is mostly compatible with
+//
+
+using System;
+using System.Collections;
+using System.Globalization;
+using System.IO;
+using System.Text;
+
+namespace Mono.Xml
+{
+ internal sealed class DefaultHandler : SmallXmlParser.IContentHandler
+ {
+ public void OnStartParsing (SmallXmlParser parser)
+ {
+ }
+
+ public void OnEndParsing (SmallXmlParser parser)
+ {
+ }
+
+ public void OnStartElement (string name, SmallXmlParser.IAttrList attrs)
+ {
+ }
+
+ public void OnEndElement (string name)
+ {
+ }
+
+ public void OnChars (string s)
+ {
+ }
+
+ public void OnIgnorableWhitespace (string s)
+ {
+ }
+
+ public void OnProcessingInstruction (string name, string text)
+ {
+ }
+ }
+
+ internal class SmallXmlParser
+ {
+ internal interface IContentHandler
+ {
+ void OnStartParsing (SmallXmlParser parser);
+ void OnEndParsing (SmallXmlParser parser);
+ void OnStartElement (string name, IAttrList attrs);
+ void OnEndElement (string name);
+ void OnProcessingInstruction (string name, string text);
+ void OnChars (string text);
+ void OnIgnorableWhitespace (string text);
+ }
+
+ internal interface IAttrList
+ {
+ int Length { get; }
+ bool IsEmpty { get; }
+ string GetName (int i);
+ string GetValue (int i);
+ string GetValue (string name);
+ string [] Names { get; }
+ string [] Values { get; }
+ }
+
+ sealed class AttrListImpl : IAttrList
+ {
+ public int Length {
+ get { return attrNames.Count; }
+ }
+ public bool IsEmpty {
+ get { return attrNames.Count == 0; }
+ }
+ public string GetName (int i)
+ {
+ return (string) attrNames [i];
+ }
+ public string GetValue (int i)
+ {
+ return (string) attrValues [i];
+ }
+ public string GetValue (string name)
+ {
+ for (int i = 0; i < attrNames.Count; i++)
+ if ((string) attrNames [i] == name)
+ return (string) attrValues [i];
+ return null;
+ }
+ public string [] Names {
+ get { return (string []) attrNames.ToArray (typeof (string)); }
+ }
+ public string [] Values {
+ get { return (string []) attrValues.ToArray (typeof (string)); }
+ }
+
+ ArrayList attrNames = new ArrayList ();
+ ArrayList attrValues = new ArrayList ();
+
+ internal void Clear ()
+ {
+ attrNames.Clear ();
+ attrValues.Clear ();
+ }
+
+ internal void Add (string name, string value)
+ {
+ attrNames.Add (name);
+ attrValues.Add (value);
+ }
+ }
+
+ IContentHandler handler;
+ TextReader reader;
+ Stack elementNames = new Stack ();
+ Stack xmlSpaces = new Stack ();
+ string xmlSpace;
+ StringBuilder buffer = new StringBuilder (200);
+ char [] nameBuffer = new char [30];
+ bool isWhitespace;
+
+ AttrListImpl attributes = new AttrListImpl ();
+ int line = 1, column;
+ bool resetColumn;
+
+ public SmallXmlParser ()
+ {
+ }
+
+ private Exception Error (string msg)
+ {
+ return new SmallXmlParserException (msg, line, column);
+ }
+
+ private Exception UnexpectedEndError ()
+ {
+ string [] arr = new string [elementNames.Count];
+ // COMPACT FRAMEWORK NOTE: CopyTo is not visible through the Stack class
+ (elementNames as ICollection).CopyTo (arr, 0);
+ return Error (String.Format (
+ "Unexpected end of stream. Element stack content is {0}", String.Join (",", arr)));
+ }
+
+
+ private bool IsNameChar (char c, bool start)
+ {
+ switch (c) {
+ case ':':
+ case '_':
+ return true;
+ case '-':
+ case '.':
+ return !start;
+ }
+ if (c > 0x100) { // optional condition for optimization
+ switch (c) {
+ case '\u0559':
+ case '\u06E5':
+ case '\u06E6':
+ return true;
+ }
+ if ('\u02BB' <= c && c <= '\u02C1')
+ return true;
+ }
+ switch (Char.GetUnicodeCategory (c)) {
+ case UnicodeCategory.LowercaseLetter:
+ case UnicodeCategory.UppercaseLetter:
+ case UnicodeCategory.OtherLetter:
+ case UnicodeCategory.TitlecaseLetter:
+ case UnicodeCategory.LetterNumber:
+ return true;
+ case UnicodeCategory.SpacingCombiningMark:
+ case UnicodeCategory.EnclosingMark:
+ case UnicodeCategory.NonSpacingMark:
+ case UnicodeCategory.ModifierLetter:
+ case UnicodeCategory.DecimalDigitNumber:
+ return !start;
+ default:
+ return false;
+ }
+ }
+
+ private bool IsWhitespace (int c)
+ {
+ switch (c) {
+ case ' ':
+ case '\r':
+ case '\t':
+ case '\n':
+ return true;
+ default:
+ return false;
+ }
+ }
+
+
+ public void SkipWhitespaces ()
+ {
+ SkipWhitespaces (false);
+ }
+
+ private void HandleWhitespaces ()
+ {
+ while (IsWhitespace (Peek ()))
+ buffer.Append ((char) Read ());
+ if (Peek () != '<' && Peek () >= 0)
+ isWhitespace = false;
+ }
+
+ public void SkipWhitespaces (bool expected)
+ {
+ while (true) {
+ switch (Peek ()) {
+ case ' ':
+ case '\r':
+ case '\t':
+ case '\n':
+ Read ();
+ if (expected)
+ expected = false;
+ continue;
+ }
+ if (expected)
+ throw Error ("Whitespace is expected.");
+ return;
+ }
+ }
+
+
+ private int Peek ()
+ {
+ return reader.Peek ();
+ }
+
+ private int Read ()
+ {
+ int i = reader.Read ();
+ if (i == '\n')
+ resetColumn = true;
+ if (resetColumn) {
+ line++;
+ resetColumn = false;
+ column = 1;
+ }
+ else
+ column++;
+ return i;
+ }
+
+ public void Expect (int c)
+ {
+ int p = Read ();
+ if (p < 0)
+ throw UnexpectedEndError ();
+ else if (p != c)
+ throw Error (String.Format ("Expected '{0}' but got {1}", (char) c, (char) p));
+ }
+
+ private string ReadUntil (char until, bool handleReferences)
+ {
+ while (true) {
+ if (Peek () < 0)
+ throw UnexpectedEndError ();
+ char c = (char) Read ();
+ if (c == until)
+ break;
+ else if (handleReferences && c == '&')
+ ReadReference ();
+ else
+ buffer.Append (c);
+ }
+ string ret = buffer.ToString ();
+ buffer.Length = 0;
+ return ret;
+ }
+
+ public string ReadName ()
+ {
+ int idx = 0;
+ if (Peek () < 0 || !IsNameChar ((char) Peek (), true))
+ throw Error ("XML name start character is expected.");
+ for (int i = Peek (); i >= 0; i = Peek ()) {
+ char c = (char) i;
+ if (!IsNameChar (c, false))
+ break;
+ if (idx == nameBuffer.Length) {
+ char [] tmp = new char [idx * 2];
+ // COMPACT FRAMEWORK NOTE: Array.Copy(sourceArray, destinationArray, count) is not available.
+ Array.Copy (nameBuffer, 0, tmp, 0, idx);
+ nameBuffer = tmp;
+ }
+ nameBuffer [idx++] = c;
+ Read ();
+ }
+ if (idx == 0)
+ throw Error ("Valid XML name is expected.");
+ return new string (nameBuffer, 0, idx);
+ }
+
+
+ public void Parse (TextReader input, IContentHandler handler)
+ {
+ this.reader = input;
+ this.handler = handler;
+
+ handler.OnStartParsing (this);
+
+ while (Peek () >= 0)
+ ReadContent ();
+ HandleBufferedContent ();
+ if (elementNames.Count > 0)
+ throw Error (String.Format ("Insufficient close tag: {0}", elementNames.Peek ()));
+
+ handler.OnEndParsing (this);
+
+ Cleanup ();
+ }
+
+ private void Cleanup ()
+ {
+ line = 1;
+ column = 0;
+ handler = null;
+ reader = null;
+#if CF_1_0
+ elementNames = new Stack ();
+ xmlSpaces = new Stack ();
+#else
+ elementNames.Clear ();
+ xmlSpaces.Clear ();
+#endif
+ attributes.Clear ();
+ buffer.Length = 0;
+ xmlSpace = null;
+ isWhitespace = false;
+ }
+
+ public void ReadContent ()
+ {
+ string name;
+ if (IsWhitespace (Peek ())) {
+ if (buffer.Length == 0)
+ isWhitespace = true;
+ HandleWhitespaces ();
+ }
+ if (Peek () == '<') {
+ Read ();
+ switch (Peek ()) {
+ case '!': // declarations
+ Read ();
+ if (Peek () == '[') {
+ Read ();
+ if (ReadName () != "CDATA")
+ throw Error ("Invalid declaration markup");
+ Expect ('[');
+ ReadCDATASection ();
+ return;
+ }
+ else if (Peek () == '-') {
+ ReadComment ();
+ return;
+ }
+ else if (ReadName () != "DOCTYPE")
+ throw Error ("Invalid declaration markup.");
+ else
+ throw Error ("This parser does not support document type.");
+ case '?': // PIs
+ HandleBufferedContent ();
+ Read ();
+ name = ReadName ();
+ SkipWhitespaces ();
+ string text = String.Empty;
+ if (Peek () != '?') {
+ while (true) {
+ text += ReadUntil ('?', false);
+ if (Peek () == '>')
+ break;
+ text += "?";
+ }
+ }
+ handler.OnProcessingInstruction (
+ name, text);
+ Expect ('>');
+ return;
+ case '/': // end tags
+ HandleBufferedContent ();
+ if (elementNames.Count == 0)
+ throw UnexpectedEndError ();
+ Read ();
+ name = ReadName ();
+ SkipWhitespaces ();
+ string expected = (string) elementNames.Pop ();
+ xmlSpaces.Pop ();
+ if (xmlSpaces.Count > 0)
+ xmlSpace = (string) xmlSpaces.Peek ();
+ else
+ xmlSpace = null;
+ if (name != expected)
+ throw Error (String.Format ("End tag mismatch: expected {0} but found {1}", expected, name));
+ handler.OnEndElement (name);
+ Expect ('>');
+ return;
+ default: // start tags (including empty tags)
+ HandleBufferedContent ();
+ name = ReadName ();
+ while (Peek () != '>' && Peek () != '/')
+ ReadAttribute (attributes);
+ handler.OnStartElement (name, attributes);
+ attributes.Clear ();
+ SkipWhitespaces ();
+ if (Peek () == '/') {
+ Read ();
+ handler.OnEndElement (name);
+ }
+ else {
+ elementNames.Push (name);
+ xmlSpaces.Push (xmlSpace);
+ }
+ Expect ('>');
+ return;
+ }
+ }
+ else
+ ReadCharacters ();
+ }
+
+ private void HandleBufferedContent ()
+ {
+ if (buffer.Length == 0)
+ return;
+ if (isWhitespace)
+ handler.OnIgnorableWhitespace (buffer.ToString ());
+ else
+ handler.OnChars (buffer.ToString ());
+ buffer.Length = 0;
+ isWhitespace = false;
+ }
+
+ private void ReadCharacters ()
+ {
+ isWhitespace = false;
+ while (true) {
+ int i = Peek ();
+ switch (i) {
+ case -1:
+ return;
+ case '<':
+ return;
+ case '&':
+ Read ();
+ ReadReference ();
+ continue;
+ default:
+ buffer.Append ((char) Read ());
+ continue;
+ }
+ }
+ }
+
+ private void ReadReference ()
+ {
+ if (Peek () == '#') {
+ // character reference
+ Read ();
+ ReadCharacterReference ();
+ } else {
+ string name = ReadName ();
+ Expect (';');
+ switch (name) {
+ case "amp":
+ buffer.Append ('&');
+ break;
+ case "quot":
+ buffer.Append ('"');
+ break;
+ case "apos":
+ buffer.Append ('\'');
+ break;
+ case "lt":
+ buffer.Append ('<');
+ break;
+ case "gt":
+ buffer.Append ('>');
+ break;
+ default:
+ throw Error ("General non-predefined entity reference is not supported in this parser.");
+ }
+ }
+ }
+
+ private int ReadCharacterReference ()
+ {
+ int n = 0;
+ if (Peek () == 'x') { // hex
+ Read ();
+ for (int i = Peek (); i >= 0; i = Peek ()) {
+ if ('0' <= i && i <= '9')
+ n = n << 4 + i - '0';
+ else if ('A' <= i && i <='F')
+ n = n << 4 + i - 'A' + 10;
+ else if ('a' <= i && i <='f')
+ n = n << 4 + i - 'a' + 10;
+ else
+ break;
+ Read ();
+ }
+ } else {
+ for (int i = Peek (); i >= 0; i = Peek ()) {
+ if ('0' <= i && i <= '9')
+ n = n << 4 + i - '0';
+ else
+ break;
+ Read ();
+ }
+ }
+ return n;
+ }
+
+ private void ReadAttribute (AttrListImpl a)
+ {
+ SkipWhitespaces (true);
+ if (Peek () == '/' || Peek () == '>')
+ // came here just to spend trailing whitespaces
+ return;
+
+ string name = ReadName ();
+ string value;
+ SkipWhitespaces ();
+ Expect ('=');
+ SkipWhitespaces ();
+ switch (Read ()) {
+ case '\'':
+ value = ReadUntil ('\'', true);
+ break;
+ case '"':
+ value = ReadUntil ('"', true);
+ break;
+ default:
+ throw Error ("Invalid attribute value markup.");
+ }
+ if (name == "xml:space")
+ xmlSpace = value;
+ a.Add (name, value);
+ }
+
+ private void ReadCDATASection ()
+ {
+ int nBracket = 0;
+ while (true) {
+ if (Peek () < 0)
+ throw UnexpectedEndError ();
+ char c = (char) Read ();
+ if (c == ']')
+ nBracket++;
+ else if (c == '>' && nBracket > 1) {
+ for (int i = nBracket; i > 2; i--)
+ buffer.Append (']');
+ break;
+ }
+ else {
+ for (int i = 0; i < nBracket; i++)
+ buffer.Append (']');
+ nBracket = 0;
+ buffer.Append (c);
+ }
+ }
+ }
+
+ private void ReadComment ()
+ {
+ Expect ('-');
+ Expect ('-');
+ while (true) {
+ if (Read () != '-')
+ continue;
+ if (Read () != '-')
+ continue;
+ if (Read () != '>')
+ throw Error ("'--' is not allowed inside comment markup.");
+ break;
+ }
+ }
+ }
+
+ internal sealed class SmallXmlParserException : SystemException
+ {
+ int line;
+ int column;
+
+ public SmallXmlParserException (string msg, int line, int column)
+ : base (String.Format ("{0}. At ({1},{2})", msg, line, column))
+ {
+ this.line = line;
+ this.column = column;
+ }
+
+ public int Line {
+ get { return line; }
+ }
+
+ public int Column {
+ get { return column; }
+ }
+ }
+}
+
+
+
./cilstrip.cs
./AssemblyStripper.cs
+# IMPORTANT: we need to keep this old copy of Cecil since newer Cecil
+# doesn't support keeping metadata tokens the same which would break AOT compilation
./Mono.Cecil/AggressiveReflectionReader.cs
./Mono.Cecil/ArrayDimension.cs
./Mono.Cecil/ArrayDimensionCollection.cs