diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..56061a31
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.suo
+bin/
+obj/
\ No newline at end of file
diff --git a/ILRuntime.sln b/ILRuntime.sln
new file mode 100644
index 00000000..97c1d356
--- /dev/null
+++ b/ILRuntime.sln
@@ -0,0 +1,40 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.24720.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILRuntime", "ILRuntime\ILRuntime.csproj", "{79EF2F29-89D1-4097-986C-5E4EEFE0FA33}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.20", "Mono.Cecil.20\Mono.Cecil.20.csproj", "{D3785D8B-4D85-4546-8763-47FC848C13E0}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Mdb", "Mono.Cecil.Mdb\Mono.Cecil.Mdb.csproj", "{86F36240-E07C-4840-9C8B-9CD94C03EC62}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil.Pdb", "Mono.Cecil.Pdb\Mono.Cecil.Pdb.csproj", "{CEA7A85F-2523-4AD0-8296-6E8E0A2E6DF7}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {79EF2F29-89D1-4097-986C-5E4EEFE0FA33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {79EF2F29-89D1-4097-986C-5E4EEFE0FA33}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {79EF2F29-89D1-4097-986C-5E4EEFE0FA33}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {79EF2F29-89D1-4097-986C-5E4EEFE0FA33}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D3785D8B-4D85-4546-8763-47FC848C13E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D3785D8B-4D85-4546-8763-47FC848C13E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D3785D8B-4D85-4546-8763-47FC848C13E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D3785D8B-4D85-4546-8763-47FC848C13E0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {86F36240-E07C-4840-9C8B-9CD94C03EC62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {86F36240-E07C-4840-9C8B-9CD94C03EC62}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {86F36240-E07C-4840-9C8B-9CD94C03EC62}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {86F36240-E07C-4840-9C8B-9CD94C03EC62}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CEA7A85F-2523-4AD0-8296-6E8E0A2E6DF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CEA7A85F-2523-4AD0-8296-6E8E0A2E6DF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CEA7A85F-2523-4AD0-8296-6E8E0A2E6DF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CEA7A85F-2523-4AD0-8296-6E8E0A2E6DF7}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/ILRuntime/ILRuntime.csproj b/ILRuntime/ILRuntime.csproj
new file mode 100644
index 00000000..6a5a44dc
--- /dev/null
+++ b/ILRuntime/ILRuntime.csproj
@@ -0,0 +1,57 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {79EF2F29-89D1-4097-986C-5E4EEFE0FA33}
+ Library
+ Properties
+ ILRuntime
+ ILRuntime
+ v4.5.2
+ 512
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ILRuntime/Properties/AssemblyInfo.cs b/ILRuntime/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000..e2b3d0c9
--- /dev/null
+++ b/ILRuntime/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("ILRuntime")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ILRuntime")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//将 ComVisible 设置为 false 将使此程序集中的类型
+//对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("79ef2f29-89d1-4097-986c-5e4eefe0fa33")]
+
+// 程序集的版本信息由下列四个值组成:
+//
+// 主版本
+// 次版本
+// 生成号
+// 修订号
+//
+//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Mono.Cecil.20/Mono.Cecil.20.csproj b/Mono.Cecil.20/Mono.Cecil.20.csproj
new file mode 100644
index 00000000..fa034e72
--- /dev/null
+++ b/Mono.Cecil.20/Mono.Cecil.20.csproj
@@ -0,0 +1,177 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {D3785D8B-4D85-4546-8763-47FC848C13E0}
+ Library
+ Properties
+ Mono.Cecil
+ Mono.Cecil.20
+ v2.0
+ 512
+
+
+
+
+ true
+ full
+ false
+ ..\bin\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Code.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Code.cs
new file mode 100644
index 00000000..fa88b63d
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Code.cs
@@ -0,0 +1,252 @@
+//
+// Code.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT 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 {
+
+ public 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,
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/CodeReader.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/CodeReader.cs
new file mode 100644
index 00000000..fde16dec
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/CodeReader.cs
@@ -0,0 +1,394 @@
+//
+// CodeReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.PE;
+using Mono.Collections.Generic;
+
+using RVA = System.UInt32;
+
+namespace Mono.Cecil.Cil
+{
+
+ sealed class CodeReader : ByteBuffer
+ {
+
+ readonly internal MetadataReader reader;
+
+ int start;
+ Section code_section;
+
+ MethodDefinition method;
+ MethodBody body;
+
+ int Offset
+ {
+ get { return base.position - start; }
+ }
+
+ public CodeReader(Section section, MetadataReader reader)
+ : base(section.Data)
+ {
+ this.code_section = section;
+ this.reader = reader;
+ }
+
+ public MethodBody ReadMethodBody(MethodDefinition method)
+ {
+ this.method = method;
+ this.body = new MethodBody(method);
+
+ reader.context = method;
+
+ ReadMethodBody();
+
+ return this.body;
+ }
+
+ public void MoveTo(int rva)
+ {
+ if (!IsInSection(rva))
+ {
+ code_section = reader.image.GetSectionAtVirtualAddress((uint)rva);
+ Reset(code_section.Data);
+ }
+
+ base.position = rva - (int)code_section.VirtualAddress;
+ }
+
+ bool IsInSection(int rva)
+ {
+ return code_section.VirtualAddress <= rva && rva < code_section.VirtualAddress + code_section.SizeOfRawData;
+ }
+
+ void ReadMethodBody()
+ {
+ MoveTo(method.RVA);
+
+ var flags = ReadByte();
+ switch (flags & 0x3)
+ {
+ case 0x2: // tiny
+ body.code_size = flags >> 2;
+ body.MaxStackSize = 8;
+ ReadCode();
+ break;
+ case 0x3: // fat
+ base.position--;
+ ReadFatMethod();
+ break;
+ default:
+ throw new InvalidOperationException();
+ }
+
+ var symbol_reader = reader.module.symbol_reader;
+
+ if (symbol_reader != null)
+ {
+ var instructions = body.Instructions;
+ symbol_reader.Read(body, offset => GetInstruction(instructions, offset));
+ }
+ }
+
+ void ReadFatMethod()
+ {
+ var flags = ReadUInt16();
+ body.max_stack_size = ReadUInt16();
+ body.code_size = (int)ReadUInt32();
+ body.local_var_token = new MetadataToken(ReadUInt32());
+ body.init_locals = (flags & 0x10) != 0;
+
+ if (body.local_var_token.RID != 0)
+ body.variables = ReadVariables(body.local_var_token);
+
+ ReadCode();
+
+ if ((flags & 0x8) != 0)
+ ReadSection();
+ }
+
+ public VariableDefinitionCollection ReadVariables(MetadataToken local_var_token)
+ {
+ var position = reader.position;
+ var variables = reader.ReadVariables(local_var_token);
+ reader.position = position;
+
+ return variables;
+ }
+
+ void ReadCode()
+ {
+ start = position;
+ var code_size = body.code_size;
+
+ if (code_size < 0 || buffer.Length <= (uint)(code_size + position))
+ code_size = 0;
+
+ var end = start + code_size;
+ var instructions = body.instructions = new InstructionCollection((code_size + 1) / 2);
+
+ while (position < end)
+ {
+ var offset = base.position - start;
+ var opcode = ReadOpCode();
+ var current = new Instruction(offset, opcode);
+
+ if (opcode.OperandType != OperandType.InlineNone)
+ current.operand = ReadOperand(current);
+
+ instructions.Add(current);
+ }
+
+ ResolveBranches(instructions);
+ }
+
+ OpCode ReadOpCode()
+ {
+ var il_opcode = ReadByte();
+ return il_opcode != 0xfe
+ ? OpCodes.OneByteOpCode[il_opcode]
+ : OpCodes.TwoBytesOpCode[ReadByte()];
+ }
+
+ object ReadOperand(Instruction instruction)
+ {
+ switch (instruction.opcode.OperandType)
+ {
+ case OperandType.InlineSwitch:
+ var length = ReadInt32();
+ var base_offset = Offset + (4 * length);
+ var branches = new int[length];
+ for (int i = 0; i < length; i++)
+ branches[i] = base_offset + ReadInt32();
+ return branches;
+ case OperandType.ShortInlineBrTarget:
+ return ReadSByte() + Offset;
+ case OperandType.InlineBrTarget:
+ return ReadInt32() + Offset;
+ case OperandType.ShortInlineI:
+ if (instruction.opcode == OpCodes.Ldc_I4_S)
+ return ReadSByte();
+
+ return ReadByte();
+ case OperandType.InlineI:
+ return ReadInt32();
+ case OperandType.ShortInlineR:
+ return ReadSingle();
+ case OperandType.InlineR:
+ return ReadDouble();
+ case OperandType.InlineI8:
+ return ReadInt64();
+ case OperandType.ShortInlineVar:
+ return GetVariable(ReadByte());
+ case OperandType.InlineVar:
+ return GetVariable(ReadUInt16());
+ case OperandType.ShortInlineArg:
+ return GetParameter(ReadByte());
+ case OperandType.InlineArg:
+ return GetParameter(ReadUInt16());
+ case OperandType.InlineSig:
+ return GetCallSite(ReadToken());
+ case OperandType.InlineString:
+ return GetString(ReadToken());
+ case OperandType.InlineTok:
+ case OperandType.InlineType:
+ case OperandType.InlineMethod:
+ case OperandType.InlineField:
+ return reader.LookupToken(ReadToken());
+ default:
+ throw new NotSupportedException();
+ }
+ }
+
+ public string GetString(MetadataToken token)
+ {
+ return reader.image.UserStringHeap.Read(token.RID);
+ }
+
+ public ParameterDefinition GetParameter(int index)
+ {
+ return Mixin.GetParameter(body, index);
+ }
+
+ public VariableDefinition GetVariable(int index)
+ {
+ return Mixin.GetVariable(body, index);
+ }
+
+ public CallSite GetCallSite(MetadataToken token)
+ {
+ return reader.ReadCallSite(token);
+ }
+
+ void ResolveBranches(Collection instructions)
+ {
+ var items = instructions.items;
+ var size = instructions.size;
+
+ for (int i = 0; i < size; i++)
+ {
+ var instruction = items[i];
+ switch (instruction.opcode.OperandType)
+ {
+ case OperandType.ShortInlineBrTarget:
+ case OperandType.InlineBrTarget:
+ instruction.operand = GetInstruction((int)instruction.operand);
+ break;
+ case OperandType.InlineSwitch:
+ var offsets = (int[])instruction.operand;
+ var branches = new Instruction[offsets.Length];
+ for (int j = 0; j < offsets.Length; j++)
+ branches[j] = GetInstruction(offsets[j]);
+
+ instruction.operand = branches;
+ break;
+ }
+ }
+ }
+
+ Instruction GetInstruction(int offset)
+ {
+ return GetInstruction(body.Instructions, offset);
+ }
+
+ static Instruction GetInstruction(Collection instructions, int offset)
+ {
+ var size = instructions.size;
+ var items = instructions.items;
+ if (offset < 0 || offset > items[size - 1].offset)
+ return null;
+
+ int min = 0;
+ int max = size - 1;
+ while (min <= max)
+ {
+ int mid = min + ((max - min) / 2);
+ var instruction = items[mid];
+ var instruction_offset = instruction.offset;
+
+ if (offset == instruction_offset)
+ return instruction;
+
+ if (offset < instruction_offset)
+ max = mid - 1;
+ else
+ min = mid + 1;
+ }
+
+ return null;
+ }
+
+ void ReadSection()
+ {
+ Align(4);
+
+ const byte fat_format = 0x40;
+ const byte more_sects = 0x80;
+
+ var flags = ReadByte();
+ if ((flags & fat_format) == 0)
+ ReadSmallSection();
+ else
+ ReadFatSection();
+
+ if ((flags & more_sects) != 0)
+ ReadSection();
+ }
+
+ void ReadSmallSection()
+ {
+ var count = ReadByte() / 12;
+ Advance(2);
+
+ ReadExceptionHandlers(
+ count,
+ () => (int)ReadUInt16(),
+ () => (int)ReadByte());
+ }
+
+ void ReadFatSection()
+ {
+ position--;
+ var count = (ReadInt32() >> 8) / 24;
+
+ ReadExceptionHandlers(
+ count,
+ ReadInt32,
+ ReadInt32);
+ }
+
+ // inline ?
+ void ReadExceptionHandlers(int count, Func read_entry, Func read_length)
+ {
+ for (int i = 0; i < count; i++)
+ {
+ var handler = new ExceptionHandler(
+ (ExceptionHandlerType)(read_entry() & 0x7));
+
+ handler.TryStart = GetInstruction(read_entry());
+ handler.TryEnd = GetInstruction(handler.TryStart.Offset + read_length());
+
+ handler.HandlerStart = GetInstruction(read_entry());
+ handler.HandlerEnd = GetInstruction(handler.HandlerStart.Offset + read_length());
+
+ ReadExceptionHandlerSpecific(handler);
+
+ this.body.ExceptionHandlers.Add(handler);
+ }
+ }
+
+ void ReadExceptionHandlerSpecific(ExceptionHandler handler)
+ {
+ switch (handler.HandlerType)
+ {
+ case ExceptionHandlerType.Catch:
+ handler.CatchType = (TypeReference)reader.LookupToken(ReadToken());
+ break;
+ case ExceptionHandlerType.Filter:
+ handler.FilterStart = GetInstruction(ReadInt32());
+ break;
+ default:
+ Advance(4);
+ break;
+ }
+ }
+
+ void Align(int align)
+ {
+ align--;
+ Advance(((position + align) & ~align) - position);
+ }
+
+ public MetadataToken ReadToken()
+ {
+ return new MetadataToken(ReadUInt32());
+ }
+
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/CodeWriter.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/CodeWriter.cs
new file mode 100644
index 00000000..7c41343c
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/CodeWriter.cs
@@ -0,0 +1,38 @@
+//
+// CodeWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Generic;
+
+using Mono.Collections.Generic;
+
+using Mono.Cecil.Metadata;
+using Mono.Cecil.PE;
+
+using RVA = System.UInt32;
+
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Document.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Document.cs
new file mode 100644
index 00000000..1dbdc447
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Document.cs
@@ -0,0 +1,112 @@
+//
+// Document.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Cil {
+
+ public enum DocumentType {
+ Other,
+ Text,
+ }
+
+ public enum DocumentHashAlgorithm {
+ None,
+ MD5,
+ SHA1,
+ }
+
+ public enum DocumentLanguage {
+ Other,
+ C,
+ Cpp,
+ CSharp,
+ Basic,
+ Java,
+ Cobol,
+ Pascal,
+ Cil,
+ JScript,
+ Smc,
+ MCpp,
+ FSharp,
+ }
+
+ public enum DocumentLanguageVendor {
+ Other,
+ Microsoft,
+ }
+
+ public sealed class Document {
+
+ string url;
+
+ byte type;
+ byte hash_algorithm;
+ byte language;
+ byte language_vendor;
+
+ byte [] hash;
+
+ public string Url {
+ get { return url; }
+ set { url = value; }
+ }
+
+ public DocumentType Type {
+ get { return (DocumentType) type; }
+ set { type = (byte) value; }
+ }
+
+ public DocumentHashAlgorithm HashAlgorithm {
+ get { return (DocumentHashAlgorithm) hash_algorithm; }
+ set { hash_algorithm = (byte) value; }
+ }
+
+ public DocumentLanguage Language {
+ get { return (DocumentLanguage) language; }
+ set { language = (byte) value; }
+ }
+
+ public DocumentLanguageVendor LanguageVendor {
+ get { return (DocumentLanguageVendor) language_vendor; }
+ set { language_vendor = (byte) value; }
+ }
+
+ public byte [] Hash {
+ get { return hash; }
+ set { hash = value; }
+ }
+
+ public Document (string url)
+ {
+ this.url = url;
+ this.hash = Empty.Array;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/ExceptionHandler.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/ExceptionHandler.cs
new file mode 100644
index 00000000..c61ff235
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/ExceptionHandler.cs
@@ -0,0 +1,89 @@
+//
+// ExceptionHandler.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT 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 {
+
+ public enum ExceptionHandlerType {
+ Catch = 0,
+ Filter = 1,
+ Finally = 2,
+ Fault = 4,
+ }
+
+ public sealed class ExceptionHandler {
+
+ Instruction try_start;
+ Instruction try_end;
+ Instruction filter_start;
+ Instruction handler_start;
+ Instruction handler_end;
+
+ TypeReference catch_type;
+ ExceptionHandlerType handler_type;
+
+ public Instruction TryStart {
+ get { return try_start; }
+ set { try_start = value; }
+ }
+
+ public Instruction TryEnd {
+ get { return try_end; }
+ set { try_end = value; }
+ }
+
+ public Instruction FilterStart {
+ get { return filter_start; }
+ set { filter_start = value; }
+ }
+
+ public Instruction HandlerStart {
+ get { return handler_start; }
+ set { handler_start = value; }
+ }
+
+ public Instruction HandlerEnd {
+ get { return handler_end; }
+ set { handler_end = value; }
+ }
+
+ public TypeReference CatchType {
+ get { return catch_type; }
+ set { catch_type = value; }
+ }
+
+ public ExceptionHandlerType HandlerType {
+ get { return handler_type; }
+ set { handler_type = value; }
+ }
+
+ public ExceptionHandler (ExceptionHandlerType handlerType)
+ {
+ this.handler_type = handlerType;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/ILProcessor.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/ILProcessor.cs
new file mode 100644
index 00000000..64368e62
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/ILProcessor.cs
@@ -0,0 +1,278 @@
+//
+// ILProcessor.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Collections.Generic;
+
+namespace Mono.Cecil.Cil {
+
+ public sealed class ILProcessor {
+
+ readonly MethodBody body;
+ readonly Collection instructions;
+
+ public MethodBody Body {
+ get { return body; }
+ }
+
+ internal ILProcessor (MethodBody body)
+ {
+ this.body = body;
+ this.instructions = body.Instructions;
+ }
+
+ public Instruction Create (OpCode opcode)
+ {
+ return Instruction.Create (opcode);
+ }
+
+ public Instruction Create (OpCode opcode, TypeReference type)
+ {
+ return Instruction.Create (opcode, type);
+ }
+
+ public Instruction Create (OpCode opcode, CallSite site)
+ {
+ return Instruction.Create (opcode, site);
+ }
+
+ public Instruction Create (OpCode opcode, MethodReference method)
+ {
+ return Instruction.Create (opcode, method);
+ }
+
+ public Instruction Create (OpCode opcode, FieldReference field)
+ {
+ return Instruction.Create (opcode, field);
+ }
+
+ public Instruction Create (OpCode opcode, string value)
+ {
+ return Instruction.Create (opcode, value);
+ }
+
+ public Instruction Create (OpCode opcode, sbyte value)
+ {
+ return Instruction.Create (opcode, value);
+ }
+
+ public Instruction Create (OpCode opcode, byte value)
+ {
+ if (opcode.OperandType == OperandType.ShortInlineVar)
+ return Instruction.Create (opcode, body.Variables [value]);
+
+ if (opcode.OperandType == OperandType.ShortInlineArg)
+ return Instruction.Create (opcode, Mixin.GetParameter (body,value));
+
+ return Instruction.Create (opcode, value);
+ }
+
+ public Instruction Create (OpCode opcode, int value)
+ {
+ if (opcode.OperandType == OperandType.InlineVar)
+ return Instruction.Create (opcode, body.Variables [value]);
+
+ if (opcode.OperandType == OperandType.InlineArg)
+ return Instruction.Create (opcode, Mixin.GetParameter (body,value));
+
+ return Instruction.Create (opcode, value);
+ }
+
+ public Instruction Create (OpCode opcode, long value)
+ {
+ return Instruction.Create (opcode, value);
+ }
+
+ public Instruction Create (OpCode opcode, float value)
+ {
+ return Instruction.Create (opcode, value);
+ }
+
+ public Instruction Create (OpCode opcode, double value)
+ {
+ return Instruction.Create (opcode, value);
+ }
+
+ public Instruction Create (OpCode opcode, Instruction target)
+ {
+ return Instruction.Create (opcode, target);
+ }
+
+ public Instruction Create (OpCode opcode, Instruction [] targets)
+ {
+ return Instruction.Create (opcode, targets);
+ }
+
+ public Instruction Create (OpCode opcode, VariableDefinition variable)
+ {
+ return Instruction.Create (opcode, variable);
+ }
+
+ public Instruction Create (OpCode opcode, ParameterDefinition parameter)
+ {
+ return Instruction.Create (opcode, parameter);
+ }
+
+ public void Emit (OpCode opcode)
+ {
+ Append (Create (opcode));
+ }
+
+ public void Emit (OpCode opcode, TypeReference type)
+ {
+ Append (Create (opcode, type));
+ }
+
+ public void Emit (OpCode opcode, MethodReference method)
+ {
+ Append (Create (opcode, method));
+ }
+
+ public void Emit (OpCode opcode, CallSite site)
+ {
+ Append (Create (opcode, site));
+ }
+
+ public void Emit (OpCode opcode, FieldReference field)
+ {
+ Append (Create (opcode, field));
+ }
+
+ public void Emit (OpCode opcode, string value)
+ {
+ Append (Create (opcode, value));
+ }
+
+ public void Emit (OpCode opcode, byte value)
+ {
+ Append (Create (opcode, value));
+ }
+
+ public void Emit (OpCode opcode, sbyte value)
+ {
+ Append (Create (opcode, value));
+ }
+
+ public void Emit (OpCode opcode, int value)
+ {
+ Append (Create (opcode, value));
+ }
+
+ public void Emit (OpCode opcode, long value)
+ {
+ Append (Create (opcode, value));
+ }
+
+ public void Emit (OpCode opcode, float value)
+ {
+ Append (Create (opcode, value));
+ }
+
+ public void Emit (OpCode opcode, double value)
+ {
+ Append (Create (opcode, value));
+ }
+
+ public void Emit (OpCode opcode, Instruction target)
+ {
+ Append (Create (opcode, target));
+ }
+
+ public void Emit (OpCode opcode, Instruction [] targets)
+ {
+ Append (Create (opcode, targets));
+ }
+
+ public void Emit (OpCode opcode, VariableDefinition variable)
+ {
+ Append (Create (opcode, variable));
+ }
+
+ public void Emit (OpCode opcode, ParameterDefinition parameter)
+ {
+ Append (Create (opcode, parameter));
+ }
+
+ public void InsertBefore (Instruction target, Instruction instruction)
+ {
+ if (target == null)
+ throw new ArgumentNullException ("target");
+ if (instruction == null)
+ throw new ArgumentNullException ("instruction");
+
+ var index = instructions.IndexOf (target);
+ if (index == -1)
+ throw new ArgumentOutOfRangeException ("target");
+
+ instructions.Insert (index, instruction);
+ }
+
+ public void InsertAfter (Instruction target, Instruction instruction)
+ {
+ if (target == null)
+ throw new ArgumentNullException ("target");
+ if (instruction == null)
+ throw new ArgumentNullException ("instruction");
+
+ var index = instructions.IndexOf (target);
+ if (index == -1)
+ throw new ArgumentOutOfRangeException ("target");
+
+ instructions.Insert (index + 1, instruction);
+ }
+
+ public void Append (Instruction instruction)
+ {
+ if (instruction == null)
+ throw new ArgumentNullException ("instruction");
+
+ instructions.Add (instruction);
+ }
+
+ public void Replace (Instruction target, Instruction instruction)
+ {
+ if (target == null)
+ throw new ArgumentNullException ("target");
+ if (instruction == null)
+ throw new ArgumentNullException ("instruction");
+
+ InsertAfter (target, instruction);
+ Remove (target);
+ }
+
+ public void Remove (Instruction instruction)
+ {
+ if (instruction == null)
+ throw new ArgumentNullException ("instruction");
+
+ if (!instructions.Remove (instruction))
+ throw new ArgumentOutOfRangeException ("instruction");
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Instruction.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Instruction.cs
new file mode 100644
index 00000000..c28d4c99
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Instruction.cs
@@ -0,0 +1,321 @@
+//
+// Instruction.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Text;
+
+namespace Mono.Cecil.Cil {
+
+ public sealed class Instruction {
+
+ internal int offset;
+ internal OpCode opcode;
+ internal object operand;
+
+ internal Instruction previous;
+ internal Instruction next;
+
+ SequencePoint sequence_point;
+
+ public int Offset {
+ get { return offset; }
+ set { offset = value; }
+ }
+
+ public OpCode OpCode {
+ get { return opcode; }
+ set { opcode = value; }
+ }
+
+ public object Operand {
+ get { return operand; }
+ set { operand = value; }
+ }
+
+ public Instruction Previous {
+ get { return previous; }
+ set { previous = value; }
+ }
+
+ public Instruction Next {
+ get { return next; }
+ set { next = value; }
+ }
+
+ public SequencePoint SequencePoint {
+ get { return sequence_point; }
+ set { sequence_point = value; }
+ }
+
+ internal Instruction (int offset, OpCode opCode)
+ {
+ this.offset = offset;
+ this.opcode = opCode;
+ }
+
+ internal Instruction (OpCode opcode, object operand)
+ {
+ this.opcode = opcode;
+ this.operand = operand;
+ }
+
+ public int GetSize ()
+ {
+ int size = opcode.Size;
+
+ switch (opcode.OperandType) {
+ case OperandType.InlineSwitch:
+ return size + (1 + ((Instruction []) operand).Length) * 4;
+ case OperandType.InlineI8:
+ case OperandType.InlineR:
+ return size + 8;
+ case OperandType.InlineBrTarget:
+ case OperandType.InlineField:
+ case OperandType.InlineI:
+ case OperandType.InlineMethod:
+ case OperandType.InlineString:
+ case OperandType.InlineTok:
+ case OperandType.InlineType:
+ case OperandType.ShortInlineR:
+ case OperandType.InlineSig:
+ return size + 4;
+ case OperandType.InlineArg:
+ case OperandType.InlineVar:
+ return size + 2;
+ case OperandType.ShortInlineBrTarget:
+ case OperandType.ShortInlineI:
+ case OperandType.ShortInlineArg:
+ case OperandType.ShortInlineVar:
+ return size + 1;
+ default:
+ return size;
+ }
+ }
+
+ public override string ToString ()
+ {
+ var instruction = new StringBuilder ();
+
+ AppendLabel (instruction, this);
+ instruction.Append (':');
+ instruction.Append (' ');
+ instruction.Append (opcode.Name);
+
+ if (operand == null)
+ return instruction.ToString ();
+
+ instruction.Append (' ');
+
+ switch (opcode.OperandType) {
+ case OperandType.ShortInlineBrTarget:
+ case OperandType.InlineBrTarget:
+ AppendLabel (instruction, (Instruction) operand);
+ break;
+ case OperandType.InlineSwitch:
+ var labels = (Instruction []) operand;
+ for (int i = 0; i < labels.Length; i++) {
+ if (i > 0)
+ instruction.Append (',');
+
+ AppendLabel (instruction, labels [i]);
+ }
+ break;
+ case OperandType.InlineString:
+ instruction.Append ('\"');
+ instruction.Append (operand);
+ instruction.Append ('\"');
+ break;
+ default:
+ instruction.Append (operand);
+ break;
+ }
+
+ return instruction.ToString ();
+ }
+
+ static void AppendLabel (StringBuilder builder, Instruction instruction)
+ {
+ builder.Append ("IL_");
+ builder.Append (instruction.offset.ToString ("x4"));
+ }
+
+ public static Instruction Create (OpCode opcode)
+ {
+ if (opcode.OperandType != OperandType.InlineNone)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, null);
+ }
+
+ public static 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 new Instruction (opcode, type);
+ }
+
+ public static Instruction Create (OpCode opcode, CallSite site)
+ {
+ if (site == null)
+ throw new ArgumentNullException ("site");
+ if (opcode.Code != Code.Calli)
+ throw new ArgumentException ("code");
+
+ return new Instruction (opcode, site);
+ }
+
+ public static 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 new Instruction (opcode, method);
+ }
+
+ public static 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 new Instruction (opcode, field);
+ }
+
+ public static Instruction Create (OpCode opcode, string value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+ if (opcode.OperandType != OperandType.InlineString)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, value);
+ }
+
+ public static Instruction Create (OpCode opcode, sbyte value)
+ {
+ if (opcode.OperandType != OperandType.ShortInlineI &&
+ opcode != OpCodes.Ldc_I4_S)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, value);
+ }
+
+ public static Instruction Create (OpCode opcode, byte value)
+ {
+ if (opcode.OperandType != OperandType.ShortInlineI ||
+ opcode == OpCodes.Ldc_I4_S)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, value);
+ }
+
+ public static Instruction Create (OpCode opcode, int value)
+ {
+ if (opcode.OperandType != OperandType.InlineI)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, value);
+ }
+
+ public static Instruction Create (OpCode opcode, long value)
+ {
+ if (opcode.OperandType != OperandType.InlineI8)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, value);
+ }
+
+ public static Instruction Create (OpCode opcode, float value)
+ {
+ if (opcode.OperandType != OperandType.ShortInlineR)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, value);
+ }
+
+ public static Instruction Create (OpCode opcode, double value)
+ {
+ if (opcode.OperandType != OperandType.InlineR)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, value);
+ }
+
+ public static Instruction Create (OpCode opcode, Instruction target)
+ {
+ if (target == null)
+ throw new ArgumentNullException ("target");
+ if (opcode.OperandType != OperandType.InlineBrTarget &&
+ opcode.OperandType != OperandType.ShortInlineBrTarget)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, target);
+ }
+
+ public static Instruction Create (OpCode opcode, Instruction [] targets)
+ {
+ if (targets == null)
+ throw new ArgumentNullException ("targets");
+ if (opcode.OperandType != OperandType.InlineSwitch)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, targets);
+ }
+
+ public static Instruction Create (OpCode opcode, VariableDefinition variable)
+ {
+ if (variable == null)
+ throw new ArgumentNullException ("variable");
+ if (opcode.OperandType != OperandType.ShortInlineVar &&
+ opcode.OperandType != OperandType.InlineVar)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, variable);
+ }
+
+ public static Instruction Create (OpCode opcode, ParameterDefinition parameter)
+ {
+ if (parameter == null)
+ throw new ArgumentNullException ("parameter");
+ if (opcode.OperandType != OperandType.ShortInlineArg &&
+ opcode.OperandType != OperandType.InlineArg)
+ throw new ArgumentException ("opcode");
+
+ return new Instruction (opcode, parameter);
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/MethodBody.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/MethodBody.cs
new file mode 100644
index 00000000..29045cd4
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/MethodBody.cs
@@ -0,0 +1,267 @@
+//
+// MethodBody.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Threading;
+
+using Mono.Collections.Generic;
+
+namespace Mono.Cecil.Cil
+{
+
+ public sealed class MethodBody : IVariableDefinitionProvider
+ {
+
+ readonly internal MethodDefinition method;
+
+ internal ParameterDefinition this_parameter;
+ internal int max_stack_size;
+ internal int code_size;
+ internal bool init_locals;
+ internal MetadataToken local_var_token;
+
+ internal Collection instructions;
+ internal Collection exceptions;
+ internal Collection variables;
+ Scope scope;
+
+ public MethodDefinition Method
+ {
+ get { return method; }
+ }
+
+ public int MaxStackSize
+ {
+ get { return max_stack_size; }
+ set { max_stack_size = value; }
+ }
+
+ public int CodeSize
+ {
+ get { return code_size; }
+ }
+
+ public bool InitLocals
+ {
+ get { return init_locals; }
+ set { init_locals = value; }
+ }
+
+ public MetadataToken LocalVarToken
+ {
+ get { return local_var_token; }
+ set { local_var_token = value; }
+ }
+
+ public Collection Instructions
+ {
+ get { return instructions ?? (instructions = new InstructionCollection()); }
+ }
+
+ public bool HasExceptionHandlers
+ {
+ get { return !Mixin.IsNullOrEmpty(exceptions); }
+ }
+
+ public Collection ExceptionHandlers
+ {
+ get { return exceptions ?? (exceptions = new Collection()); }
+ }
+
+ public bool HasVariables
+ {
+ get { return !Mixin.IsNullOrEmpty(variables); }
+ }
+
+ public Collection Variables
+ {
+ get { return variables ?? (variables = new VariableDefinitionCollection()); }
+ }
+
+ public Scope Scope
+ {
+ get { return scope; }
+ set { scope = value; }
+ }
+
+ public ParameterDefinition ThisParameter
+ {
+ get
+ {
+ if (method == null || method.DeclaringType == null)
+ throw new NotSupportedException();
+
+ if (!method.HasThis)
+ return null;
+
+ if (this_parameter == null)
+ this_parameter = ThisParameterFor(method);
+
+ return this_parameter;
+ }
+ }
+
+ static ParameterDefinition ThisParameterFor(MethodDefinition method)
+ {
+ var declaring_type = method.DeclaringType;
+ var type = declaring_type.IsValueType || declaring_type.IsPrimitive
+ ? new PointerType(declaring_type)
+ : declaring_type as TypeReference;
+
+ return new ParameterDefinition(type, method);
+ }
+
+ public MethodBody(MethodDefinition method)
+ {
+ this.method = method;
+ }
+
+ public ILProcessor GetILProcessor()
+ {
+ return new ILProcessor(this);
+ }
+ }
+
+ public interface IVariableDefinitionProvider
+ {
+ bool HasVariables { get; }
+ Collection Variables { get; }
+ }
+
+ class VariableDefinitionCollection : Collection
+ {
+
+ internal VariableDefinitionCollection()
+ {
+ }
+
+ internal VariableDefinitionCollection(int capacity)
+ : base(capacity)
+ {
+ }
+
+ protected override void OnAdd(VariableDefinition item, int index)
+ {
+ item.index = index;
+ }
+
+ protected override void OnInsert(VariableDefinition item, int index)
+ {
+ item.index = index;
+
+ for (int i = index; i < size; i++)
+ items[i].index = i + 1;
+ }
+
+ protected override void OnSet(VariableDefinition item, int index)
+ {
+ item.index = index;
+ }
+
+ protected override void OnRemove(VariableDefinition item, int index)
+ {
+ item.index = -1;
+
+ for (int i = index + 1; i < size; i++)
+ items[i].index = i - 1;
+ }
+ }
+
+ class InstructionCollection : Collection
+ {
+
+ internal InstructionCollection()
+ {
+ }
+
+ internal InstructionCollection(int capacity)
+ : base(capacity)
+ {
+ }
+
+ protected override void OnAdd(Instruction item, int index)
+ {
+ if (index == 0)
+ return;
+
+ var previous = items[index - 1];
+ previous.next = item;
+ item.previous = previous;
+ }
+
+ protected override void OnInsert(Instruction item, int index)
+ {
+ if (size == 0)
+ return;
+
+ var current = items[index];
+ if (current == null)
+ {
+ var last = items[index - 1];
+ last.next = item;
+ item.previous = last;
+ return;
+ }
+
+ var previous = current.previous;
+ if (previous != null)
+ {
+ previous.next = item;
+ item.previous = previous;
+ }
+
+ current.previous = item;
+ item.next = current;
+ }
+
+ protected override void OnSet(Instruction item, int index)
+ {
+ var current = items[index];
+
+ item.previous = current.previous;
+ item.next = current.next;
+
+ current.previous = null;
+ current.next = null;
+ }
+
+ protected override void OnRemove(Instruction item, int index)
+ {
+ var previous = item.previous;
+ if (previous != null)
+ previous.next = item.next;
+
+ var next = item.next;
+ if (next != null)
+ next.previous = item.previous;
+
+ item.previous = null;
+ item.next = null;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/OpCode.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/OpCode.cs
new file mode 100644
index 00000000..1a144213
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/OpCode.cs
@@ -0,0 +1,455 @@
+//
+// OpCode.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT 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 {
+
+ public enum FlowControl {
+ Branch,
+ Break,
+ Call,
+ Cond_Branch,
+ Meta,
+ Next,
+ Phi,
+ Return,
+ Throw,
+ }
+
+ public enum OpCodeType {
+ Annotation,
+ Macro,
+ Nternal,
+ Objmodel,
+ Prefix,
+ Primitive,
+ }
+
+ public enum OperandType {
+ InlineBrTarget,
+ InlineField,
+ InlineI,
+ InlineI8,
+ InlineMethod,
+ InlineNone,
+ InlinePhi,
+ InlineR,
+ InlineSig,
+ InlineString,
+ InlineSwitch,
+ InlineTok,
+ InlineType,
+ InlineVar,
+ InlineArg,
+ ShortInlineBrTarget,
+ ShortInlineI,
+ ShortInlineR,
+ ShortInlineVar,
+ ShortInlineArg,
+ }
+
+ public 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,
+ }
+
+ public struct OpCode {
+
+ readonly byte op1;
+ readonly byte op2;
+ readonly byte code;
+ readonly byte flow_control;
+ readonly byte opcode_type;
+ readonly byte operand_type;
+ readonly byte stack_behavior_pop;
+ readonly byte stack_behavior_push;
+
+ public string Name {
+ get { return OpCodeNames.names [(int) Code]; }
+ }
+
+ public int Size {
+ get { return op1 == 0xff ? 1 : 2; }
+ }
+
+ public byte Op1 {
+ get { return op1; }
+ }
+
+ public byte Op2 {
+ get { return op2; }
+ }
+
+ public short Value {
+ get { return op1 == 0xff ? op2 : (short) ((op1 << 8) | op2); }
+ }
+
+ public Code Code {
+ get { return (Code) code; }
+ }
+
+ public FlowControl FlowControl {
+ get { return (FlowControl) flow_control; }
+ }
+
+ public OpCodeType OpCodeType {
+ get { return (OpCodeType) opcode_type; }
+ }
+
+ public OperandType OperandType {
+ get { return (OperandType) operand_type; }
+ }
+
+ public StackBehaviour StackBehaviourPop {
+ get { return (StackBehaviour) stack_behavior_pop; }
+ }
+
+ public StackBehaviour StackBehaviourPush {
+ get { return (StackBehaviour) stack_behavior_push; }
+ }
+
+ internal OpCode (int x, int y)
+ {
+ this.op1 = (byte) ((x >> 0) & 0xff);
+ this.op2 = (byte) ((x >> 8) & 0xff);
+ this.code = (byte) ((x >> 16) & 0xff);
+ this.flow_control = (byte) ((x >> 24) & 0xff);
+
+ this.opcode_type = (byte) ((y >> 0) & 0xff);
+ this.operand_type = (byte) ((y >> 8) & 0xff);
+ this.stack_behavior_pop = (byte) ((y >> 16) & 0xff);
+ this.stack_behavior_push = (byte) ((y >> 24) & 0xff);
+
+ if (op1 == 0xff)
+ OpCodes.OneByteOpCode [op2] = this;
+ else
+ OpCodes.TwoBytesOpCode [op2] = this;
+ }
+
+ public override int GetHashCode ()
+ {
+ return Value;
+ }
+
+ public override bool Equals (object obj)
+ {
+ if (!(obj is OpCode))
+ return false;
+
+ var opcode = (OpCode) obj;
+ return op1 == opcode.op1 && op2 == opcode.op2;
+ }
+
+ public bool Equals (OpCode opcode)
+ {
+ return op1 == opcode.op1 && op2 == opcode.op2;
+ }
+
+ public static bool operator == (OpCode one, OpCode other)
+ {
+ return one.op1 == other.op1 && one.op2 == other.op2;
+ }
+
+ public static bool operator != (OpCode one, OpCode other)
+ {
+ return one.op1 != other.op1 || one.op2 != other.op2;
+ }
+
+ public override string ToString ()
+ {
+ return Name;
+ }
+ }
+
+ static class OpCodeNames {
+
+ internal static readonly string [] names;
+
+ static OpCodeNames ()
+ {
+ var table = new byte [] {
+ 3, 110, 111, 112,
+ 5, 98, 114, 101, 97, 107,
+ 7, 108, 100, 97, 114, 103, 46, 48,
+ 7, 108, 100, 97, 114, 103, 46, 49,
+ 7, 108, 100, 97, 114, 103, 46, 50,
+ 7, 108, 100, 97, 114, 103, 46, 51,
+ 7, 108, 100, 108, 111, 99, 46, 48,
+ 7, 108, 100, 108, 111, 99, 46, 49,
+ 7, 108, 100, 108, 111, 99, 46, 50,
+ 7, 108, 100, 108, 111, 99, 46, 51,
+ 7, 115, 116, 108, 111, 99, 46, 48,
+ 7, 115, 116, 108, 111, 99, 46, 49,
+ 7, 115, 116, 108, 111, 99, 46, 50,
+ 7, 115, 116, 108, 111, 99, 46, 51,
+ 7, 108, 100, 97, 114, 103, 46, 115,
+ 8, 108, 100, 97, 114, 103, 97, 46, 115,
+ 7, 115, 116, 97, 114, 103, 46, 115,
+ 7, 108, 100, 108, 111, 99, 46, 115,
+ 8, 108, 100, 108, 111, 99, 97, 46, 115,
+ 7, 115, 116, 108, 111, 99, 46, 115,
+ 6, 108, 100, 110, 117, 108, 108,
+ 9, 108, 100, 99, 46, 105, 52, 46, 109, 49,
+ 8, 108, 100, 99, 46, 105, 52, 46, 48,
+ 8, 108, 100, 99, 46, 105, 52, 46, 49,
+ 8, 108, 100, 99, 46, 105, 52, 46, 50,
+ 8, 108, 100, 99, 46, 105, 52, 46, 51,
+ 8, 108, 100, 99, 46, 105, 52, 46, 52,
+ 8, 108, 100, 99, 46, 105, 52, 46, 53,
+ 8, 108, 100, 99, 46, 105, 52, 46, 54,
+ 8, 108, 100, 99, 46, 105, 52, 46, 55,
+ 8, 108, 100, 99, 46, 105, 52, 46, 56,
+ 8, 108, 100, 99, 46, 105, 52, 46, 115,
+ 6, 108, 100, 99, 46, 105, 52,
+ 6, 108, 100, 99, 46, 105, 56,
+ 6, 108, 100, 99, 46, 114, 52,
+ 6, 108, 100, 99, 46, 114, 56,
+ 3, 100, 117, 112,
+ 3, 112, 111, 112,
+ 3, 106, 109, 112,
+ 4, 99, 97, 108, 108,
+ 5, 99, 97, 108, 108, 105,
+ 3, 114, 101, 116,
+ 4, 98, 114, 46, 115,
+ 9, 98, 114, 102, 97, 108, 115, 101, 46, 115,
+ 8, 98, 114, 116, 114, 117, 101, 46, 115,
+ 5, 98, 101, 113, 46, 115,
+ 5, 98, 103, 101, 46, 115,
+ 5, 98, 103, 116, 46, 115,
+ 5, 98, 108, 101, 46, 115,
+ 5, 98, 108, 116, 46, 115,
+ 8, 98, 110, 101, 46, 117, 110, 46, 115,
+ 8, 98, 103, 101, 46, 117, 110, 46, 115,
+ 8, 98, 103, 116, 46, 117, 110, 46, 115,
+ 8, 98, 108, 101, 46, 117, 110, 46, 115,
+ 8, 98, 108, 116, 46, 117, 110, 46, 115,
+ 2, 98, 114,
+ 7, 98, 114, 102, 97, 108, 115, 101,
+ 6, 98, 114, 116, 114, 117, 101,
+ 3, 98, 101, 113,
+ 3, 98, 103, 101,
+ 3, 98, 103, 116,
+ 3, 98, 108, 101,
+ 3, 98, 108, 116,
+ 6, 98, 110, 101, 46, 117, 110,
+ 6, 98, 103, 101, 46, 117, 110,
+ 6, 98, 103, 116, 46, 117, 110,
+ 6, 98, 108, 101, 46, 117, 110,
+ 6, 98, 108, 116, 46, 117, 110,
+ 6, 115, 119, 105, 116, 99, 104,
+ 8, 108, 100, 105, 110, 100, 46, 105, 49,
+ 8, 108, 100, 105, 110, 100, 46, 117, 49,
+ 8, 108, 100, 105, 110, 100, 46, 105, 50,
+ 8, 108, 100, 105, 110, 100, 46, 117, 50,
+ 8, 108, 100, 105, 110, 100, 46, 105, 52,
+ 8, 108, 100, 105, 110, 100, 46, 117, 52,
+ 8, 108, 100, 105, 110, 100, 46, 105, 56,
+ 7, 108, 100, 105, 110, 100, 46, 105,
+ 8, 108, 100, 105, 110, 100, 46, 114, 52,
+ 8, 108, 100, 105, 110, 100, 46, 114, 56,
+ 9, 108, 100, 105, 110, 100, 46, 114, 101, 102,
+ 9, 115, 116, 105, 110, 100, 46, 114, 101, 102,
+ 8, 115, 116, 105, 110, 100, 46, 105, 49,
+ 8, 115, 116, 105, 110, 100, 46, 105, 50,
+ 8, 115, 116, 105, 110, 100, 46, 105, 52,
+ 8, 115, 116, 105, 110, 100, 46, 105, 56,
+ 8, 115, 116, 105, 110, 100, 46, 114, 52,
+ 8, 115, 116, 105, 110, 100, 46, 114, 56,
+ 3, 97, 100, 100,
+ 3, 115, 117, 98,
+ 3, 109, 117, 108,
+ 3, 100, 105, 118,
+ 6, 100, 105, 118, 46, 117, 110,
+ 3, 114, 101, 109,
+ 6, 114, 101, 109, 46, 117, 110,
+ 3, 97, 110, 100,
+ 2, 111, 114,
+ 3, 120, 111, 114,
+ 3, 115, 104, 108,
+ 3, 115, 104, 114,
+ 6, 115, 104, 114, 46, 117, 110,
+ 3, 110, 101, 103,
+ 3, 110, 111, 116,
+ 7, 99, 111, 110, 118, 46, 105, 49,
+ 7, 99, 111, 110, 118, 46, 105, 50,
+ 7, 99, 111, 110, 118, 46, 105, 52,
+ 7, 99, 111, 110, 118, 46, 105, 56,
+ 7, 99, 111, 110, 118, 46, 114, 52,
+ 7, 99, 111, 110, 118, 46, 114, 56,
+ 7, 99, 111, 110, 118, 46, 117, 52,
+ 7, 99, 111, 110, 118, 46, 117, 56,
+ 8, 99, 97, 108, 108, 118, 105, 114, 116,
+ 5, 99, 112, 111, 98, 106,
+ 5, 108, 100, 111, 98, 106,
+ 5, 108, 100, 115, 116, 114,
+ 6, 110, 101, 119, 111, 98, 106,
+ 9, 99, 97, 115, 116, 99, 108, 97, 115, 115,
+ 6, 105, 115, 105, 110, 115, 116,
+ 9, 99, 111, 110, 118, 46, 114, 46, 117, 110,
+ 5, 117, 110, 98, 111, 120,
+ 5, 116, 104, 114, 111, 119,
+ 5, 108, 100, 102, 108, 100,
+ 6, 108, 100, 102, 108, 100, 97,
+ 5, 115, 116, 102, 108, 100,
+ 6, 108, 100, 115, 102, 108, 100,
+ 7, 108, 100, 115, 102, 108, 100, 97,
+ 6, 115, 116, 115, 102, 108, 100,
+ 5, 115, 116, 111, 98, 106,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 49, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 50, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 52, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 56, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 49, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 50, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 52, 46, 117, 110,
+ 14, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 56, 46, 117, 110,
+ 13, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 46, 117, 110,
+ 13, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 46, 117, 110,
+ 3, 98, 111, 120,
+ 6, 110, 101, 119, 97, 114, 114,
+ 5, 108, 100, 108, 101, 110,
+ 7, 108, 100, 101, 108, 101, 109, 97,
+ 9, 108, 100, 101, 108, 101, 109, 46, 105, 49,
+ 9, 108, 100, 101, 108, 101, 109, 46, 117, 49,
+ 9, 108, 100, 101, 108, 101, 109, 46, 105, 50,
+ 9, 108, 100, 101, 108, 101, 109, 46, 117, 50,
+ 9, 108, 100, 101, 108, 101, 109, 46, 105, 52,
+ 9, 108, 100, 101, 108, 101, 109, 46, 117, 52,
+ 9, 108, 100, 101, 108, 101, 109, 46, 105, 56,
+ 8, 108, 100, 101, 108, 101, 109, 46, 105,
+ 9, 108, 100, 101, 108, 101, 109, 46, 114, 52,
+ 9, 108, 100, 101, 108, 101, 109, 46, 114, 56,
+ 10, 108, 100, 101, 108, 101, 109, 46, 114, 101, 102,
+ 8, 115, 116, 101, 108, 101, 109, 46, 105,
+ 9, 115, 116, 101, 108, 101, 109, 46, 105, 49,
+ 9, 115, 116, 101, 108, 101, 109, 46, 105, 50,
+ 9, 115, 116, 101, 108, 101, 109, 46, 105, 52,
+ 9, 115, 116, 101, 108, 101, 109, 46, 105, 56,
+ 9, 115, 116, 101, 108, 101, 109, 46, 114, 52,
+ 9, 115, 116, 101, 108, 101, 109, 46, 114, 56,
+ 10, 115, 116, 101, 108, 101, 109, 46, 114, 101, 102,
+ 10, 108, 100, 101, 108, 101, 109, 46, 97, 110, 121,
+ 10, 115, 116, 101, 108, 101, 109, 46, 97, 110, 121,
+ 9, 117, 110, 98, 111, 120, 46, 97, 110, 121,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 49,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 49,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 50,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 50,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 52,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 52,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105, 56,
+ 11, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117, 56,
+ 9, 114, 101, 102, 97, 110, 121, 118, 97, 108,
+ 8, 99, 107, 102, 105, 110, 105, 116, 101,
+ 8, 109, 107, 114, 101, 102, 97, 110, 121,
+ 7, 108, 100, 116, 111, 107, 101, 110,
+ 7, 99, 111, 110, 118, 46, 117, 50,
+ 7, 99, 111, 110, 118, 46, 117, 49,
+ 6, 99, 111, 110, 118, 46, 105,
+ 10, 99, 111, 110, 118, 46, 111, 118, 102, 46, 105,
+ 10, 99, 111, 110, 118, 46, 111, 118, 102, 46, 117,
+ 7, 97, 100, 100, 46, 111, 118, 102,
+ 10, 97, 100, 100, 46, 111, 118, 102, 46, 117, 110,
+ 7, 109, 117, 108, 46, 111, 118, 102,
+ 10, 109, 117, 108, 46, 111, 118, 102, 46, 117, 110,
+ 7, 115, 117, 98, 46, 111, 118, 102,
+ 10, 115, 117, 98, 46, 111, 118, 102, 46, 117, 110,
+ 10, 101, 110, 100, 102, 105, 110, 97, 108, 108, 121,
+ 5, 108, 101, 97, 118, 101,
+ 7, 108, 101, 97, 118, 101, 46, 115,
+ 7, 115, 116, 105, 110, 100, 46, 105,
+ 6, 99, 111, 110, 118, 46, 117,
+ 7, 97, 114, 103, 108, 105, 115, 116,
+ 3, 99, 101, 113,
+ 3, 99, 103, 116,
+ 6, 99, 103, 116, 46, 117, 110,
+ 3, 99, 108, 116,
+ 6, 99, 108, 116, 46, 117, 110,
+ 5, 108, 100, 102, 116, 110,
+ 9, 108, 100, 118, 105, 114, 116, 102, 116, 110,
+ 5, 108, 100, 97, 114, 103,
+ 6, 108, 100, 97, 114, 103, 97,
+ 5, 115, 116, 97, 114, 103,
+ 5, 108, 100, 108, 111, 99,
+ 6, 108, 100, 108, 111, 99, 97,
+ 5, 115, 116, 108, 111, 99,
+ 8, 108, 111, 99, 97, 108, 108, 111, 99,
+ 9, 101, 110, 100, 102, 105, 108, 116, 101, 114,
+ 10, 117, 110, 97, 108, 105, 103, 110, 101, 100, 46,
+ 9, 118, 111, 108, 97, 116, 105, 108, 101, 46,
+ 5, 116, 97, 105, 108, 46,
+ 7, 105, 110, 105, 116, 111, 98, 106,
+ 12, 99, 111, 110, 115, 116, 114, 97, 105, 110, 101, 100, 46,
+ 5, 99, 112, 98, 108, 107,
+ 7, 105, 110, 105, 116, 98, 108, 107,
+ 3, 110, 111, 46,
+ 7, 114, 101, 116, 104, 114, 111, 119,
+ 6, 115, 105, 122, 101, 111, 102,
+ 10, 114, 101, 102, 97, 110, 121, 116, 121, 112, 101,
+ 9, 114, 101, 97, 100, 111, 110, 108, 121, 46,
+ };
+
+ names = new string [219];
+
+ for (int i = 0, p = 0; i < names.Length; i++) {
+ var buffer = new char [table [p++]];
+
+ for (int j = 0; j < buffer.Length; j++)
+ buffer [j] = (char) table [p++];
+
+ names [i] = new string (buffer);
+ }
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/OpCodes.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/OpCodes.cs
new file mode 100644
index 00000000..85712ec8
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/OpCodes.cs
@@ -0,0 +1,912 @@
+//
+// OpCodes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT 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 {
+
+ public static 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 << 0 | 0x00 << 8 | (byte) Code.Nop << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Break = new OpCode (
+ 0xff << 0 | 0x01 << 8 | (byte) Code.Break << 16 | (byte) FlowControl.Break << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ldarg_0 = new OpCode (
+ 0xff << 0 | 0x02 << 8 | (byte) Code.Ldarg_0 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldarg_1 = new OpCode (
+ 0xff << 0 | 0x03 << 8 | (byte) Code.Ldarg_1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldarg_2 = new OpCode (
+ 0xff << 0 | 0x04 << 8 | (byte) Code.Ldarg_2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldarg_3 = new OpCode (
+ 0xff << 0 | 0x05 << 8 | (byte) Code.Ldarg_3 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldloc_0 = new OpCode (
+ 0xff << 0 | 0x06 << 8 | (byte) Code.Ldloc_0 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldloc_1 = new OpCode (
+ 0xff << 0 | 0x07 << 8 | (byte) Code.Ldloc_1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldloc_2 = new OpCode (
+ 0xff << 0 | 0x08 << 8 | (byte) Code.Ldloc_2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldloc_3 = new OpCode (
+ 0xff << 0 | 0x09 << 8 | (byte) Code.Ldloc_3 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Stloc_0 = new OpCode (
+ 0xff << 0 | 0x0a << 8 | (byte) Code.Stloc_0 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stloc_1 = new OpCode (
+ 0xff << 0 | 0x0b << 8 | (byte) Code.Stloc_1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stloc_2 = new OpCode (
+ 0xff << 0 | 0x0c << 8 | (byte) Code.Stloc_2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stloc_3 = new OpCode (
+ 0xff << 0 | 0x0d << 8 | (byte) Code.Stloc_3 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ldarg_S = new OpCode (
+ 0xff << 0 | 0x0e << 8 | (byte) Code.Ldarg_S << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineArg << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldarga_S = new OpCode (
+ 0xff << 0 | 0x0f << 8 | (byte) Code.Ldarga_S << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineArg << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Starg_S = new OpCode (
+ 0xff << 0 | 0x10 << 8 | (byte) Code.Starg_S << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineArg << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ldloc_S = new OpCode (
+ 0xff << 0 | 0x11 << 8 | (byte) Code.Ldloc_S << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineVar << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldloca_S = new OpCode (
+ 0xff << 0 | 0x12 << 8 | (byte) Code.Ldloca_S << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineVar << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Stloc_S = new OpCode (
+ 0xff << 0 | 0x13 << 8 | (byte) Code.Stloc_S << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineVar << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ldnull = new OpCode (
+ 0xff << 0 | 0x14 << 8 | (byte) Code.Ldnull << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushref << 24);
+
+ public static readonly OpCode Ldc_I4_M1 = new OpCode (
+ 0xff << 0 | 0x15 << 8 | (byte) Code.Ldc_I4_M1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4_0 = new OpCode (
+ 0xff << 0 | 0x16 << 8 | (byte) Code.Ldc_I4_0 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4_1 = new OpCode (
+ 0xff << 0 | 0x17 << 8 | (byte) Code.Ldc_I4_1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4_2 = new OpCode (
+ 0xff << 0 | 0x18 << 8 | (byte) Code.Ldc_I4_2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4_3 = new OpCode (
+ 0xff << 0 | 0x19 << 8 | (byte) Code.Ldc_I4_3 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4_4 = new OpCode (
+ 0xff << 0 | 0x1a << 8 | (byte) Code.Ldc_I4_4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4_5 = new OpCode (
+ 0xff << 0 | 0x1b << 8 | (byte) Code.Ldc_I4_5 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4_6 = new OpCode (
+ 0xff << 0 | 0x1c << 8 | (byte) Code.Ldc_I4_6 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4_7 = new OpCode (
+ 0xff << 0 | 0x1d << 8 | (byte) Code.Ldc_I4_7 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4_8 = new OpCode (
+ 0xff << 0 | 0x1e << 8 | (byte) Code.Ldc_I4_8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4_S = new OpCode (
+ 0xff << 0 | 0x1f << 8 | (byte) Code.Ldc_I4_S << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineI << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I4 = new OpCode (
+ 0xff << 0 | 0x20 << 8 | (byte) Code.Ldc_I4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineI << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldc_I8 = new OpCode (
+ 0xff << 0 | 0x21 << 8 | (byte) Code.Ldc_I8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineI8 << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi8 << 24);
+
+ public static readonly OpCode Ldc_R4 = new OpCode (
+ 0xff << 0 | 0x22 << 8 | (byte) Code.Ldc_R4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.ShortInlineR << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushr4 << 24);
+
+ public static readonly OpCode Ldc_R8 = new OpCode (
+ 0xff << 0 | 0x23 << 8 | (byte) Code.Ldc_R8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineR << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushr8 << 24);
+
+ public static readonly OpCode Dup = new OpCode (
+ 0xff << 0 | 0x25 << 8 | (byte) Code.Dup << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push1_push1 << 24);
+
+ public static readonly OpCode Pop = new OpCode (
+ 0xff << 0 | 0x26 << 8 | (byte) Code.Pop << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Jmp = new OpCode (
+ 0xff << 0 | 0x27 << 8 | (byte) Code.Jmp << 16 | (byte) FlowControl.Call << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Call = new OpCode (
+ 0xff << 0 | 0x28 << 8 | (byte) Code.Call << 16 | (byte) FlowControl.Call << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Varpop << 16 | (byte) StackBehaviour.Varpush << 24);
+
+ public static readonly OpCode Calli = new OpCode (
+ 0xff << 0 | 0x29 << 8 | (byte) Code.Calli << 16 | (byte) FlowControl.Call << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineSig << 8 | (byte) StackBehaviour.Varpop << 16 | (byte) StackBehaviour.Varpush << 24);
+
+ public static readonly OpCode Ret = new OpCode (
+ 0xff << 0 | 0x2a << 8 | (byte) Code.Ret << 16 | (byte) FlowControl.Return << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Varpop << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Br_S = new OpCode (
+ 0xff << 0 | 0x2b << 8 | (byte) Code.Br_S << 16 | (byte) FlowControl.Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Brfalse_S = new OpCode (
+ 0xff << 0 | 0x2c << 8 | (byte) Code.Brfalse_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Brtrue_S = new OpCode (
+ 0xff << 0 | 0x2d << 8 | (byte) Code.Brtrue_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Beq_S = new OpCode (
+ 0xff << 0 | 0x2e << 8 | (byte) Code.Beq_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Bge_S = new OpCode (
+ 0xff << 0 | 0x2f << 8 | (byte) Code.Bge_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Bgt_S = new OpCode (
+ 0xff << 0 | 0x30 << 8 | (byte) Code.Bgt_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ble_S = new OpCode (
+ 0xff << 0 | 0x31 << 8 | (byte) Code.Ble_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Blt_S = new OpCode (
+ 0xff << 0 | 0x32 << 8 | (byte) Code.Blt_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Bne_Un_S = new OpCode (
+ 0xff << 0 | 0x33 << 8 | (byte) Code.Bne_Un_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Bge_Un_S = new OpCode (
+ 0xff << 0 | 0x34 << 8 | (byte) Code.Bge_Un_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Bgt_Un_S = new OpCode (
+ 0xff << 0 | 0x35 << 8 | (byte) Code.Bgt_Un_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ble_Un_S = new OpCode (
+ 0xff << 0 | 0x36 << 8 | (byte) Code.Ble_Un_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Blt_Un_S = new OpCode (
+ 0xff << 0 | 0x37 << 8 | (byte) Code.Blt_Un_S << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Br = new OpCode (
+ 0xff << 0 | 0x38 << 8 | (byte) Code.Br << 16 | (byte) FlowControl.Branch << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Brfalse = new OpCode (
+ 0xff << 0 | 0x39 << 8 | (byte) Code.Brfalse << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Brtrue = new OpCode (
+ 0xff << 0 | 0x3a << 8 | (byte) Code.Brtrue << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Beq = new OpCode (
+ 0xff << 0 | 0x3b << 8 | (byte) Code.Beq << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Bge = new OpCode (
+ 0xff << 0 | 0x3c << 8 | (byte) Code.Bge << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Bgt = new OpCode (
+ 0xff << 0 | 0x3d << 8 | (byte) Code.Bgt << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ble = new OpCode (
+ 0xff << 0 | 0x3e << 8 | (byte) Code.Ble << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Blt = new OpCode (
+ 0xff << 0 | 0x3f << 8 | (byte) Code.Blt << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Bne_Un = new OpCode (
+ 0xff << 0 | 0x40 << 8 | (byte) Code.Bne_Un << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Bge_Un = new OpCode (
+ 0xff << 0 | 0x41 << 8 | (byte) Code.Bge_Un << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Bgt_Un = new OpCode (
+ 0xff << 0 | 0x42 << 8 | (byte) Code.Bgt_Un << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ble_Un = new OpCode (
+ 0xff << 0 | 0x43 << 8 | (byte) Code.Ble_Un << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Blt_Un = new OpCode (
+ 0xff << 0 | 0x44 << 8 | (byte) Code.Blt_Un << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Switch = new OpCode (
+ 0xff << 0 | 0x45 << 8 | (byte) Code.Switch << 16 | (byte) FlowControl.Cond_Branch << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineSwitch << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ldind_I1 = new OpCode (
+ 0xff << 0 | 0x46 << 8 | (byte) Code.Ldind_I1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldind_U1 = new OpCode (
+ 0xff << 0 | 0x47 << 8 | (byte) Code.Ldind_U1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldind_I2 = new OpCode (
+ 0xff << 0 | 0x48 << 8 | (byte) Code.Ldind_I2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldind_U2 = new OpCode (
+ 0xff << 0 | 0x49 << 8 | (byte) Code.Ldind_U2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldind_I4 = new OpCode (
+ 0xff << 0 | 0x4a << 8 | (byte) Code.Ldind_I4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldind_U4 = new OpCode (
+ 0xff << 0 | 0x4b << 8 | (byte) Code.Ldind_U4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldind_I8 = new OpCode (
+ 0xff << 0 | 0x4c << 8 | (byte) Code.Ldind_I8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi8 << 24);
+
+ public static readonly OpCode Ldind_I = new OpCode (
+ 0xff << 0 | 0x4d << 8 | (byte) Code.Ldind_I << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldind_R4 = new OpCode (
+ 0xff << 0 | 0x4e << 8 | (byte) Code.Ldind_R4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushr4 << 24);
+
+ public static readonly OpCode Ldind_R8 = new OpCode (
+ 0xff << 0 | 0x4f << 8 | (byte) Code.Ldind_R8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushr8 << 24);
+
+ public static readonly OpCode Ldind_Ref = new OpCode (
+ 0xff << 0 | 0x50 << 8 | (byte) Code.Ldind_Ref << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushref << 24);
+
+ public static readonly OpCode Stind_Ref = new OpCode (
+ 0xff << 0 | 0x51 << 8 | (byte) Code.Stind_Ref << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stind_I1 = new OpCode (
+ 0xff << 0 | 0x52 << 8 | (byte) Code.Stind_I1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stind_I2 = new OpCode (
+ 0xff << 0 | 0x53 << 8 | (byte) Code.Stind_I2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stind_I4 = new OpCode (
+ 0xff << 0 | 0x54 << 8 | (byte) Code.Stind_I4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stind_I8 = new OpCode (
+ 0xff << 0 | 0x55 << 8 | (byte) Code.Stind_I8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi8 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stind_R4 = new OpCode (
+ 0xff << 0 | 0x56 << 8 | (byte) Code.Stind_R4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popr4 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stind_R8 = new OpCode (
+ 0xff << 0 | 0x57 << 8 | (byte) Code.Stind_R8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popr8 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Add = new OpCode (
+ 0xff << 0 | 0x58 << 8 | (byte) Code.Add << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Sub = new OpCode (
+ 0xff << 0 | 0x59 << 8 | (byte) Code.Sub << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Mul = new OpCode (
+ 0xff << 0 | 0x5a << 8 | (byte) Code.Mul << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Div = new OpCode (
+ 0xff << 0 | 0x5b << 8 | (byte) Code.Div << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Div_Un = new OpCode (
+ 0xff << 0 | 0x5c << 8 | (byte) Code.Div_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Rem = new OpCode (
+ 0xff << 0 | 0x5d << 8 | (byte) Code.Rem << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Rem_Un = new OpCode (
+ 0xff << 0 | 0x5e << 8 | (byte) Code.Rem_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode And = new OpCode (
+ 0xff << 0 | 0x5f << 8 | (byte) Code.And << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Or = new OpCode (
+ 0xff << 0 | 0x60 << 8 | (byte) Code.Or << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Xor = new OpCode (
+ 0xff << 0 | 0x61 << 8 | (byte) Code.Xor << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Shl = new OpCode (
+ 0xff << 0 | 0x62 << 8 | (byte) Code.Shl << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Shr = new OpCode (
+ 0xff << 0 | 0x63 << 8 | (byte) Code.Shr << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Shr_Un = new OpCode (
+ 0xff << 0 | 0x64 << 8 | (byte) Code.Shr_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Neg = new OpCode (
+ 0xff << 0 | 0x65 << 8 | (byte) Code.Neg << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Not = new OpCode (
+ 0xff << 0 | 0x66 << 8 | (byte) Code.Not << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Conv_I1 = new OpCode (
+ 0xff << 0 | 0x67 << 8 | (byte) Code.Conv_I1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_I2 = new OpCode (
+ 0xff << 0 | 0x68 << 8 | (byte) Code.Conv_I2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_I4 = new OpCode (
+ 0xff << 0 | 0x69 << 8 | (byte) Code.Conv_I4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_I8 = new OpCode (
+ 0xff << 0 | 0x6a << 8 | (byte) Code.Conv_I8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24);
+
+ public static readonly OpCode Conv_R4 = new OpCode (
+ 0xff << 0 | 0x6b << 8 | (byte) Code.Conv_R4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushr4 << 24);
+
+ public static readonly OpCode Conv_R8 = new OpCode (
+ 0xff << 0 | 0x6c << 8 | (byte) Code.Conv_R8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushr8 << 24);
+
+ public static readonly OpCode Conv_U4 = new OpCode (
+ 0xff << 0 | 0x6d << 8 | (byte) Code.Conv_U4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_U8 = new OpCode (
+ 0xff << 0 | 0x6e << 8 | (byte) Code.Conv_U8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24);
+
+ public static readonly OpCode Callvirt = new OpCode (
+ 0xff << 0 | 0x6f << 8 | (byte) Code.Callvirt << 16 | (byte) FlowControl.Call << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Varpop << 16 | (byte) StackBehaviour.Varpush << 24);
+
+ public static readonly OpCode Cpobj = new OpCode (
+ 0xff << 0 | 0x70 << 8 | (byte) Code.Cpobj << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ldobj = new OpCode (
+ 0xff << 0 | 0x71 << 8 | (byte) Code.Ldobj << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldstr = new OpCode (
+ 0xff << 0 | 0x72 << 8 | (byte) Code.Ldstr << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineString << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushref << 24);
+
+ public static readonly OpCode Newobj = new OpCode (
+ 0xff << 0 | 0x73 << 8 | (byte) Code.Newobj << 16 | (byte) FlowControl.Call << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Varpop << 16 | (byte) StackBehaviour.Pushref << 24);
+
+ public static readonly OpCode Castclass = new OpCode (
+ 0xff << 0 | 0x74 << 8 | (byte) Code.Castclass << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushref << 24);
+
+ public static readonly OpCode Isinst = new OpCode (
+ 0xff << 0 | 0x75 << 8 | (byte) Code.Isinst << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_R_Un = new OpCode (
+ 0xff << 0 | 0x76 << 8 | (byte) Code.Conv_R_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushr8 << 24);
+
+ public static readonly OpCode Unbox = new OpCode (
+ 0xff << 0 | 0x79 << 8 | (byte) Code.Unbox << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Throw = new OpCode (
+ 0xff << 0 | 0x7a << 8 | (byte) Code.Throw << 16 | (byte) FlowControl.Throw << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ldfld = new OpCode (
+ 0xff << 0 | 0x7b << 8 | (byte) Code.Ldfld << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldflda = new OpCode (
+ 0xff << 0 | 0x7c << 8 | (byte) Code.Ldflda << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Stfld = new OpCode (
+ 0xff << 0 | 0x7d << 8 | (byte) Code.Stfld << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Popref_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ldsfld = new OpCode (
+ 0xff << 0 | 0x7e << 8 | (byte) Code.Ldsfld << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldsflda = new OpCode (
+ 0xff << 0 | 0x7f << 8 | (byte) Code.Ldsflda << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Stsfld = new OpCode (
+ 0xff << 0 | 0x80 << 8 | (byte) Code.Stsfld << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineField << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stobj = new OpCode (
+ 0xff << 0 | 0x81 << 8 | (byte) Code.Stobj << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi_pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Conv_Ovf_I1_Un = new OpCode (
+ 0xff << 0 | 0x82 << 8 | (byte) Code.Conv_Ovf_I1_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_I2_Un = new OpCode (
+ 0xff << 0 | 0x83 << 8 | (byte) Code.Conv_Ovf_I2_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_I4_Un = new OpCode (
+ 0xff << 0 | 0x84 << 8 | (byte) Code.Conv_Ovf_I4_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_I8_Un = new OpCode (
+ 0xff << 0 | 0x85 << 8 | (byte) Code.Conv_Ovf_I8_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24);
+
+ public static readonly OpCode Conv_Ovf_U1_Un = new OpCode (
+ 0xff << 0 | 0x86 << 8 | (byte) Code.Conv_Ovf_U1_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_U2_Un = new OpCode (
+ 0xff << 0 | 0x87 << 8 | (byte) Code.Conv_Ovf_U2_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_U4_Un = new OpCode (
+ 0xff << 0 | 0x88 << 8 | (byte) Code.Conv_Ovf_U4_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_U8_Un = new OpCode (
+ 0xff << 0 | 0x89 << 8 | (byte) Code.Conv_Ovf_U8_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24);
+
+ public static readonly OpCode Conv_Ovf_I_Un = new OpCode (
+ 0xff << 0 | 0x8a << 8 | (byte) Code.Conv_Ovf_I_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_U_Un = new OpCode (
+ 0xff << 0 | 0x8b << 8 | (byte) Code.Conv_Ovf_U_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Box = new OpCode (
+ 0xff << 0 | 0x8c << 8 | (byte) Code.Box << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushref << 24);
+
+ public static readonly OpCode Newarr = new OpCode (
+ 0xff << 0 | 0x8d << 8 | (byte) Code.Newarr << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushref << 24);
+
+ public static readonly OpCode Ldlen = new OpCode (
+ 0xff << 0 | 0x8e << 8 | (byte) Code.Ldlen << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldelema = new OpCode (
+ 0xff << 0 | 0x8f << 8 | (byte) Code.Ldelema << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldelem_I1 = new OpCode (
+ 0xff << 0 | 0x90 << 8 | (byte) Code.Ldelem_I1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldelem_U1 = new OpCode (
+ 0xff << 0 | 0x91 << 8 | (byte) Code.Ldelem_U1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldelem_I2 = new OpCode (
+ 0xff << 0 | 0x92 << 8 | (byte) Code.Ldelem_I2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldelem_U2 = new OpCode (
+ 0xff << 0 | 0x93 << 8 | (byte) Code.Ldelem_U2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldelem_I4 = new OpCode (
+ 0xff << 0 | 0x94 << 8 | (byte) Code.Ldelem_I4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldelem_U4 = new OpCode (
+ 0xff << 0 | 0x95 << 8 | (byte) Code.Ldelem_U4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldelem_I8 = new OpCode (
+ 0xff << 0 | 0x96 << 8 | (byte) Code.Ldelem_I8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi8 << 24);
+
+ public static readonly OpCode Ldelem_I = new OpCode (
+ 0xff << 0 | 0x97 << 8 | (byte) Code.Ldelem_I << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldelem_R4 = new OpCode (
+ 0xff << 0 | 0x98 << 8 | (byte) Code.Ldelem_R4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushr4 << 24);
+
+ public static readonly OpCode Ldelem_R8 = new OpCode (
+ 0xff << 0 | 0x99 << 8 | (byte) Code.Ldelem_R8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushr8 << 24);
+
+ public static readonly OpCode Ldelem_Ref = new OpCode (
+ 0xff << 0 | 0x9a << 8 | (byte) Code.Ldelem_Ref << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Pushref << 24);
+
+ public static readonly OpCode Stelem_I = new OpCode (
+ 0xff << 0 | 0x9b << 8 | (byte) Code.Stelem_I << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stelem_I1 = new OpCode (
+ 0xff << 0 | 0x9c << 8 | (byte) Code.Stelem_I1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stelem_I2 = new OpCode (
+ 0xff << 0 | 0x9d << 8 | (byte) Code.Stelem_I2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stelem_I4 = new OpCode (
+ 0xff << 0 | 0x9e << 8 | (byte) Code.Stelem_I4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stelem_I8 = new OpCode (
+ 0xff << 0 | 0x9f << 8 | (byte) Code.Stelem_I8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popi8 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stelem_R4 = new OpCode (
+ 0xff << 0 | 0xa0 << 8 | (byte) Code.Stelem_R4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popr4 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stelem_R8 = new OpCode (
+ 0xff << 0 | 0xa1 << 8 | (byte) Code.Stelem_R8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popr8 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stelem_Ref = new OpCode (
+ 0xff << 0 | 0xa2 << 8 | (byte) Code.Stelem_Ref << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popref_popi_popref << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ldelem_Any = new OpCode (
+ 0xff << 0 | 0xa3 << 8 | (byte) Code.Ldelem_Any << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref_popi << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Stelem_Any = new OpCode (
+ 0xff << 0 | 0xa4 << 8 | (byte) Code.Stelem_Any << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref_popi_popref << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Unbox_Any = new OpCode (
+ 0xff << 0 | 0xa5 << 8 | (byte) Code.Unbox_Any << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Conv_Ovf_I1 = new OpCode (
+ 0xff << 0 | 0xb3 << 8 | (byte) Code.Conv_Ovf_I1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_U1 = new OpCode (
+ 0xff << 0 | 0xb4 << 8 | (byte) Code.Conv_Ovf_U1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_I2 = new OpCode (
+ 0xff << 0 | 0xb5 << 8 | (byte) Code.Conv_Ovf_I2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_U2 = new OpCode (
+ 0xff << 0 | 0xb6 << 8 | (byte) Code.Conv_Ovf_U2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_I4 = new OpCode (
+ 0xff << 0 | 0xb7 << 8 | (byte) Code.Conv_Ovf_I4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_U4 = new OpCode (
+ 0xff << 0 | 0xb8 << 8 | (byte) Code.Conv_Ovf_U4 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_I8 = new OpCode (
+ 0xff << 0 | 0xb9 << 8 | (byte) Code.Conv_Ovf_I8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24);
+
+ public static readonly OpCode Conv_Ovf_U8 = new OpCode (
+ 0xff << 0 | 0xba << 8 | (byte) Code.Conv_Ovf_U8 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi8 << 24);
+
+ public static readonly OpCode Refanyval = new OpCode (
+ 0xff << 0 | 0xc2 << 8 | (byte) Code.Refanyval << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ckfinite = new OpCode (
+ 0xff << 0 | 0xc3 << 8 | (byte) Code.Ckfinite << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushr8 << 24);
+
+ public static readonly OpCode Mkrefany = new OpCode (
+ 0xff << 0 | 0xc6 << 8 | (byte) Code.Mkrefany << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldtoken = new OpCode (
+ 0xff << 0 | 0xd0 << 8 | (byte) Code.Ldtoken << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineTok << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_U2 = new OpCode (
+ 0xff << 0 | 0xd1 << 8 | (byte) Code.Conv_U2 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_U1 = new OpCode (
+ 0xff << 0 | 0xd2 << 8 | (byte) Code.Conv_U1 << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_I = new OpCode (
+ 0xff << 0 | 0xd3 << 8 | (byte) Code.Conv_I << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_I = new OpCode (
+ 0xff << 0 | 0xd4 << 8 | (byte) Code.Conv_Ovf_I << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Conv_Ovf_U = new OpCode (
+ 0xff << 0 | 0xd5 << 8 | (byte) Code.Conv_Ovf_U << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Add_Ovf = new OpCode (
+ 0xff << 0 | 0xd6 << 8 | (byte) Code.Add_Ovf << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Add_Ovf_Un = new OpCode (
+ 0xff << 0 | 0xd7 << 8 | (byte) Code.Add_Ovf_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Mul_Ovf = new OpCode (
+ 0xff << 0 | 0xd8 << 8 | (byte) Code.Mul_Ovf << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Mul_Ovf_Un = new OpCode (
+ 0xff << 0 | 0xd9 << 8 | (byte) Code.Mul_Ovf_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Sub_Ovf = new OpCode (
+ 0xff << 0 | 0xda << 8 | (byte) Code.Sub_Ovf << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Sub_Ovf_Un = new OpCode (
+ 0xff << 0 | 0xdb << 8 | (byte) Code.Sub_Ovf_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Endfinally = new OpCode (
+ 0xff << 0 | 0xdc << 8 | (byte) Code.Endfinally << 16 | (byte) FlowControl.Return << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Leave = new OpCode (
+ 0xff << 0 | 0xdd << 8 | (byte) Code.Leave << 16 | (byte) FlowControl.Branch << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineBrTarget << 8 | (byte) StackBehaviour.PopAll << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Leave_S = new OpCode (
+ 0xff << 0 | 0xde << 8 | (byte) Code.Leave_S << 16 | (byte) FlowControl.Branch << 24,
+ (byte) OpCodeType.Macro << 0 | (byte) OperandType.ShortInlineBrTarget << 8 | (byte) StackBehaviour.PopAll << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Stind_I = new OpCode (
+ 0xff << 0 | 0xdf << 8 | (byte) Code.Stind_I << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Conv_U = new OpCode (
+ 0xff << 0 | 0xe0 << 8 | (byte) Code.Conv_U << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Arglist = new OpCode (
+ 0xfe << 0 | 0x00 << 8 | (byte) Code.Arglist << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ceq = new OpCode (
+ 0xfe << 0 | 0x01 << 8 | (byte) Code.Ceq << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Cgt = new OpCode (
+ 0xfe << 0 | 0x02 << 8 | (byte) Code.Cgt << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Cgt_Un = new OpCode (
+ 0xfe << 0 | 0x03 << 8 | (byte) Code.Cgt_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Clt = new OpCode (
+ 0xfe << 0 | 0x04 << 8 | (byte) Code.Clt << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Clt_Un = new OpCode (
+ 0xfe << 0 | 0x05 << 8 | (byte) Code.Clt_Un << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1_pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldftn = new OpCode (
+ 0xfe << 0 | 0x06 << 8 | (byte) Code.Ldftn << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldvirtftn = new OpCode (
+ 0xfe << 0 | 0x07 << 8 | (byte) Code.Ldvirtftn << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineMethod << 8 | (byte) StackBehaviour.Popref << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Ldarg = new OpCode (
+ 0xfe << 0 | 0x09 << 8 | (byte) Code.Ldarg << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineArg << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldarga = new OpCode (
+ 0xfe << 0 | 0x0a << 8 | (byte) Code.Ldarga << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineArg << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Starg = new OpCode (
+ 0xfe << 0 | 0x0b << 8 | (byte) Code.Starg << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineArg << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Ldloc = new OpCode (
+ 0xfe << 0 | 0x0c << 8 | (byte) Code.Ldloc << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineVar << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push1 << 24);
+
+ public static readonly OpCode Ldloca = new OpCode (
+ 0xfe << 0 | 0x0d << 8 | (byte) Code.Ldloca << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineVar << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Stloc = new OpCode (
+ 0xfe << 0 | 0x0e << 8 | (byte) Code.Stloc << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineVar << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Localloc = new OpCode (
+ 0xfe << 0 | 0x0f << 8 | (byte) Code.Localloc << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Endfilter = new OpCode (
+ 0xfe << 0 | 0x11 << 8 | (byte) Code.Endfilter << 16 | (byte) FlowControl.Return << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Unaligned = new OpCode (
+ 0xfe << 0 | 0x12 << 8 | (byte) Code.Unaligned << 16 | (byte) FlowControl.Meta << 24,
+ (byte) OpCodeType.Prefix << 0 | (byte) OperandType.ShortInlineI << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Volatile = new OpCode (
+ 0xfe << 0 | 0x13 << 8 | (byte) Code.Volatile << 16 | (byte) FlowControl.Meta << 24,
+ (byte) OpCodeType.Prefix << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Tail = new OpCode (
+ 0xfe << 0 | 0x14 << 8 | (byte) Code.Tail << 16 | (byte) FlowControl.Meta << 24,
+ (byte) OpCodeType.Prefix << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Initobj = new OpCode (
+ 0xfe << 0 | 0x15 << 8 | (byte) Code.Initobj << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Constrained = new OpCode (
+ 0xfe << 0 | 0x16 << 8 | (byte) Code.Constrained << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Prefix << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Cpblk = new OpCode (
+ 0xfe << 0 | 0x17 << 8 | (byte) Code.Cpblk << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Initblk = new OpCode (
+ 0xfe << 0 | 0x18 << 8 | (byte) Code.Initblk << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Popi_popi_popi << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode No = new OpCode (
+ 0xfe << 0 | 0x19 << 8 | (byte) Code.No << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Prefix << 0 | (byte) OperandType.ShortInlineI << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Rethrow = new OpCode (
+ 0xfe << 0 | 0x1a << 8 | (byte) Code.Rethrow << 16 | (byte) FlowControl.Throw << 24,
+ (byte) OpCodeType.Objmodel << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+
+ public static readonly OpCode Sizeof = new OpCode (
+ 0xfe << 0 | 0x1c << 8 | (byte) Code.Sizeof << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineType << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Refanytype = new OpCode (
+ 0xfe << 0 | 0x1d << 8 | (byte) Code.Refanytype << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Primitive << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop1 << 16 | (byte) StackBehaviour.Pushi << 24);
+
+ public static readonly OpCode Readonly = new OpCode (
+ 0xfe << 0 | 0x1e << 8 | (byte) Code.Readonly << 16 | (byte) FlowControl.Next << 24,
+ (byte) OpCodeType.Prefix << 0 | (byte) OperandType.InlineNone << 8 | (byte) StackBehaviour.Pop0 << 16 | (byte) StackBehaviour.Push0 << 24);
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/SequencePoint.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/SequencePoint.cs
new file mode 100644
index 00000000..ef87e30f
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/SequencePoint.cs
@@ -0,0 +1,70 @@
+//
+// SequencePoint.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT 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 {
+
+ public sealed class SequencePoint {
+
+ Document document;
+
+ int start_line;
+ int start_column;
+ int end_line;
+ int end_column;
+
+ public int StartLine {
+ get { return start_line; }
+ set { start_line = value; }
+ }
+
+ public int StartColumn {
+ get { return start_column; }
+ set { start_column = value; }
+ }
+
+ public int EndLine {
+ get { return end_line; }
+ set { end_line = value; }
+ }
+
+ public int EndColumn {
+ get { return end_column; }
+ set { end_column = value; }
+ }
+
+ public Document Document {
+ get { return document; }
+ set { document = value; }
+ }
+
+ public SequencePoint (Document document)
+ {
+ this.document = document;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Symbols.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Symbols.cs
new file mode 100644
index 00000000..0774d9ca
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Symbols.cs
@@ -0,0 +1,243 @@
+//
+// Symbols.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.IO;
+using System.Runtime.InteropServices;
+using SR = System.Reflection;
+
+using Mono.Collections.Generic;
+
+namespace Mono.Cecil.Cil {
+
+ [StructLayout (LayoutKind.Sequential)]
+ public struct ImageDebugDirectory {
+ public int Characteristics;
+ public int TimeDateStamp;
+ public short MajorVersion;
+ public short MinorVersion;
+ public int Type;
+ public int SizeOfData;
+ public int AddressOfRawData;
+ public int PointerToRawData;
+ }
+
+ public sealed class Scope : IVariableDefinitionProvider {
+
+ Instruction start;
+ Instruction end;
+
+ Collection scopes;
+ Collection variables;
+
+ public Instruction Start {
+ get { return start; }
+ set { start = value; }
+ }
+
+ public Instruction End {
+ get { return end; }
+ set { end = value; }
+ }
+
+ public bool HasScopes {
+ get { return !Mixin.IsNullOrEmpty (scopes); }
+ }
+
+ public Collection Scopes {
+ get {
+ if (scopes == null)
+ scopes = new Collection ();
+
+ return scopes;
+ }
+ }
+
+ public bool HasVariables {
+ get { return !Mixin.IsNullOrEmpty (variables); }
+ }
+
+ public Collection Variables {
+ get {
+ if (variables == null)
+ variables = new Collection ();
+
+ return variables;
+ }
+ }
+ }
+
+ public struct InstructionSymbol {
+
+ public readonly int Offset;
+ public readonly SequencePoint SequencePoint;
+
+ public InstructionSymbol (int offset, SequencePoint sequencePoint)
+ {
+ this.Offset = offset;
+ this.SequencePoint = sequencePoint;
+ }
+ }
+
+ public sealed class MethodSymbols {
+
+ internal int code_size;
+ internal string method_name;
+ internal MetadataToken method_token;
+ internal MetadataToken local_var_token;
+ internal Collection variables;
+ public Collection instructions;
+
+ public bool HasVariables {
+ get { return !Mixin.IsNullOrEmpty (variables); }
+ }
+
+ public Collection Variables {
+ get {
+ if (variables == null)
+ variables = new Collection ();
+
+ return variables;
+ }
+ }
+
+ public Collection Instructions {
+ get {
+ if (instructions == null)
+ instructions = new Collection ();
+
+ return instructions;
+ }
+ }
+
+ public int CodeSize {
+ get { return code_size; }
+ }
+
+ public string MethodName {
+ get { return method_name; }
+ }
+
+ public MetadataToken MethodToken {
+ get { return method_token; }
+ }
+
+ public MetadataToken LocalVarToken {
+ get { return local_var_token; }
+ }
+
+ internal MethodSymbols (string methodName)
+ {
+ this.method_name = methodName;
+ }
+
+ public MethodSymbols (MetadataToken methodToken)
+ {
+ this.method_token = methodToken;
+ }
+ }
+
+ public delegate Instruction InstructionMapper (int offset);
+
+ public interface ISymbolReader : IDisposable {
+
+ bool ProcessDebugHeader (ImageDebugDirectory directory, byte [] header);
+ void Read (MethodBody body, InstructionMapper mapper);
+ void Read (MethodSymbols symbols);
+ }
+
+ public interface ISymbolReaderProvider {
+
+ ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName);
+ ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream);
+ }
+
+ static class SymbolProvider {
+
+ static readonly string symbol_kind = Type.GetType ("Mono.Runtime") != null ? "Mdb" : "Pdb";
+
+ static SR.AssemblyName GetPlatformSymbolAssemblyName ()
+ {
+ var cecil_name = typeof (SymbolProvider).Assembly.GetName ();
+
+ var name = new SR.AssemblyName {
+ Name = "Mono.Cecil." + symbol_kind,
+ Version = cecil_name.Version,
+ };
+
+ name.SetPublicKeyToken (cecil_name.GetPublicKeyToken ());
+
+ return name;
+ }
+
+ static Type GetPlatformType (string fullname)
+ {
+ var type = Type.GetType (fullname);
+ if (type != null)
+ return type;
+
+ var assembly_name = GetPlatformSymbolAssemblyName ();
+
+ type = Type.GetType (fullname + ", " + assembly_name.FullName);
+ if (type != null)
+ return type;
+
+ try {
+ var assembly = SR.Assembly.Load (assembly_name);
+ if (assembly != null)
+ return assembly.GetType (fullname);
+ } catch (FileNotFoundException) {
+
+ }
+
+ return null;
+ }
+
+ static ISymbolReaderProvider reader_provider;
+
+ public static ISymbolReaderProvider GetPlatformReaderProvider ()
+ {
+ if (reader_provider != null)
+ return reader_provider;
+
+ var type = GetPlatformType (GetProviderTypeName ("ReaderProvider"));
+ if (type == null)
+ return null;
+
+ return reader_provider = (ISymbolReaderProvider) Activator.CreateInstance (type);
+ }
+
+ static string GetProviderTypeName (string name)
+ {
+ return "Mono.Cecil." + symbol_kind + "." + symbol_kind + name;
+ }
+
+
+ }
+
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/VariableDefinition.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/VariableDefinition.cs
new file mode 100644
index 00000000..f501bca6
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/VariableDefinition.cs
@@ -0,0 +1,52 @@
+//
+// VariableDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT 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 {
+
+ public sealed class VariableDefinition : VariableReference {
+
+ public bool IsPinned {
+ get { return variable_type.IsPinned; }
+ }
+
+ public VariableDefinition (TypeReference variableType)
+ : base (variableType)
+ {
+ }
+
+ public VariableDefinition (string name, TypeReference variableType)
+ : base (name, variableType)
+ {
+ }
+
+ public override VariableDefinition Resolve ()
+ {
+ return this;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/VariableReference.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/VariableReference.cs
new file mode 100644
index 00000000..ce0b4cdb
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/VariableReference.cs
@@ -0,0 +1,75 @@
+//
+// VariableReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT 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 {
+
+ public abstract class VariableReference {
+
+ string name;
+ internal int index = -1;
+ protected TypeReference variable_type;
+
+ public string Name {
+ get { return name; }
+ set { name = value; }
+ }
+
+ public TypeReference VariableType {
+ get { return variable_type; }
+ set { variable_type = value; }
+ }
+
+ public int Index {
+ get { return index; }
+ }
+
+ internal VariableReference (TypeReference variable_type)
+ : this (string.Empty, variable_type)
+ {
+ }
+
+ internal VariableReference (string name, TypeReference variable_type)
+ {
+ this.name = name;
+ this.variable_type = variable_type;
+ }
+
+ public abstract VariableDefinition Resolve ();
+
+ public override string ToString ()
+ {
+ if (!string.IsNullOrEmpty (name))
+ return name;
+
+ if (index >= 0)
+ return "V_" + index;
+
+ return string.Empty;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/BlobHeap.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/BlobHeap.cs
new file mode 100644
index 00000000..e19d0ced
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/BlobHeap.cs
@@ -0,0 +1,61 @@
+//
+// BlobHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.PE;
+
+namespace Mono.Cecil.Metadata
+{
+
+ sealed class BlobHeap : Heap
+ {
+
+ public BlobHeap(Section section, uint start, uint size)
+ : base(section, start, size)
+ {
+ }
+
+ public byte[] Read(uint index)
+ {
+ if (index == 0 || index > Size - 1)
+ return Empty.Array;
+
+ var data = Section.Data;
+
+ int position = (int)(index + Offset);
+ int length = (int)Mixin.ReadCompressedUInt32(data, ref position);
+
+ var buffer = new byte[length];
+
+ Buffer.BlockCopy(data, position, buffer, 0, length);
+
+ return buffer;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Buffers.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Buffers.cs
new file mode 100644
index 00000000..97b48d8b
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Buffers.cs
@@ -0,0 +1,36 @@
+//
+// TableHeapBuffer.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Generic;
+using System.Text;
+
+using Mono.Cecil.PE;
+
+using RVA = System.UInt32;
+
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/CodedIndex.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/CodedIndex.cs
new file mode 100644
index 00000000..3e30fd87
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/CodedIndex.cs
@@ -0,0 +1,46 @@
+//
+// CodedIndex.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT 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 {
+
+ enum CodedIndex {
+ TypeDefOrRef,
+ HasConstant,
+ HasCustomAttribute,
+ HasFieldMarshal,
+ HasDeclSecurity,
+ MemberRefParent,
+ HasSemantics,
+ MethodDefOrRef,
+ MemberForwarded,
+ Implementation,
+ CustomAttributeType,
+ ResolutionScope,
+ TypeOrMethodDef
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/ElementType.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/ElementType.cs
new file mode 100644
index 00000000..72fc1cca
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/ElementType.cs
@@ -0,0 +1,73 @@
+//
+// ElementType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT 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 {
+
+ enum ElementType : byte {
+ None = 0x00,
+ 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 token
+ ByRef = 0x10, // Followed by token
+ ValueType = 0x11, // Followed by token
+ Class = 0x12, // Followed by token
+ Var = 0x13, // Followed by generic parameter number
+ Array = 0x14, //
+ GenericInst = 0x15, // ... */
+ 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
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/GuidHeap.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/GuidHeap.cs
new file mode 100644
index 00000000..1adc0795
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/GuidHeap.cs
@@ -0,0 +1,59 @@
+//
+// GuidHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.PE;
+
+namespace Mono.Cecil.Metadata {
+
+ sealed class GuidHeap : Heap {
+
+ public GuidHeap (Section section, uint start, uint size)
+ : base (section, start, size)
+ {
+ }
+
+ public Guid Read (uint index)
+ {
+ if (index == 0)
+ return new Guid ();
+
+ const int guid_size = 16;
+
+ var buffer = new byte [guid_size];
+
+ index--;
+
+ Buffer.BlockCopy (Section.Data, (int) (Offset + index), buffer, 0, guid_size);
+
+ return new Guid (buffer);
+
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Heap.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Heap.cs
new file mode 100644
index 00000000..bc21acde
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Heap.cs
@@ -0,0 +1,48 @@
+//
+// Heap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.PE;
+
+namespace Mono.Cecil.Metadata {
+
+ abstract class Heap {
+
+ public int IndexSize;
+
+ public readonly Section Section;
+ public readonly uint Offset;
+ public readonly uint Size;
+
+ protected Heap (Section section, uint offset, uint size)
+ {
+ this.Section = section;
+ this.Offset = offset;
+ this.Size = size;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/MetadataToken.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/MetadataToken.cs
new file mode 100644
index 00000000..bda56b0f
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/MetadataToken.cs
@@ -0,0 +1,105 @@
+//
+// MetadataToken.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ public struct MetadataToken {
+
+ readonly uint token;
+
+ public uint RID {
+ get { return token & 0x00ffffff; }
+ }
+
+ public TokenType TokenType {
+ get { return (TokenType) (token & 0xff000000); }
+ }
+
+ public static readonly MetadataToken Zero = new MetadataToken ((uint) 0);
+
+ public MetadataToken (uint token)
+ {
+ this.token = token;
+ }
+
+ public MetadataToken (TokenType type)
+ : this (type, 0)
+ {
+ }
+
+ public MetadataToken (TokenType type, uint rid)
+ {
+ token = (uint) type | rid;
+ }
+
+ public MetadataToken (TokenType type, int rid)
+ {
+ token = (uint) type | (uint) rid;
+ }
+
+ public int ToInt32 ()
+ {
+ return (int) token;
+ }
+
+ public uint ToUInt32 ()
+ {
+ return token;
+ }
+
+ public override int GetHashCode ()
+ {
+ return (int) token;
+ }
+
+ public override bool Equals (object obj)
+ {
+ if (obj is MetadataToken) {
+ var other = (MetadataToken) obj;
+ return other.token == token;
+ }
+
+ return false;
+ }
+
+ public static bool operator == (MetadataToken one, MetadataToken other)
+ {
+ return one.token == other.token;
+ }
+
+ public static bool operator != (MetadataToken one, MetadataToken other)
+ {
+ return one.token != other.token;
+ }
+
+ public override string ToString ()
+ {
+ return string.Format ("[{0}:0x{1}]", TokenType, RID.ToString ("x4"));
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Row.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Row.cs
new file mode 100644
index 00000000..9975b7ba
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Row.cs
@@ -0,0 +1,175 @@
+//
+// Row.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Collections.Generic;
+
+namespace Mono.Cecil.Metadata {
+
+ class Row {
+ internal T1 Col1;
+ internal T2 Col2;
+
+ public Row (T1 col1, T2 col2)
+ {
+ Col1 = col1;
+ Col2 = col2;
+ }
+ }
+
+ class Row
+ {
+ internal T1 Col1;
+ internal T2 Col2;
+ internal T3 Col3;
+
+ public Row (T1 col1, T2 col2, T3 col3)
+ {
+ Col1 = col1;
+ Col2 = col2;
+ Col3 = col3;
+ }
+ }
+
+ class Row
+ {
+ internal T1 Col1;
+ internal T2 Col2;
+ internal T3 Col3;
+ internal T4 Col4;
+
+ public Row (T1 col1, T2 col2, T3 col3, T4 col4)
+ {
+ Col1 = col1;
+ Col2 = col2;
+ Col3 = col3;
+ Col4 = col4;
+ }
+ }
+
+ class Row
+ {
+ internal T1 Col1;
+ internal T2 Col2;
+ internal T3 Col3;
+ internal T4 Col4;
+ internal T5 Col5;
+
+ public Row (T1 col1, T2 col2, T3 col3, T4 col4, T5 col5)
+ {
+ Col1 = col1;
+ Col2 = col2;
+ Col3 = col3;
+ Col4 = col4;
+ Col5 = col5;
+ }
+ }
+
+ class Row
+ {
+ internal T1 Col1;
+ internal T2 Col2;
+ internal T3 Col3;
+ internal T4 Col4;
+ internal T5 Col5;
+ internal T6 Col6;
+
+ public Row (T1 col1, T2 col2, T3 col3, T4 col4, T5 col5, T6 col6)
+ {
+ Col1 = col1;
+ Col2 = col2;
+ Col3 = col3;
+ Col4 = col4;
+ Col5 = col5;
+ Col6 = col6;
+ }
+ }
+
+ class Row
+ {
+ internal T1 Col1;
+ internal T2 Col2;
+ internal T3 Col3;
+ internal T4 Col4;
+ internal T5 Col5;
+ internal T6 Col6;
+ internal T7 Col7;
+ internal T8 Col8;
+ internal T9 Col9;
+
+ public Row (T1 col1, T2 col2, T3 col3, T4 col4, T5 col5, T6 col6, T7 col7, T8 col8, T9 col9)
+ {
+ Col1 = col1;
+ Col2 = col2;
+ Col3 = col3;
+ Col4 = col4;
+ Col5 = col5;
+ Col6 = col6;
+ Col7 = col7;
+ Col8 = col8;
+ Col9 = col9;
+ }
+ }
+
+ sealed class RowEqualityComparer : IEqualityComparer>, IEqualityComparer>, IEqualityComparer> {
+
+ public bool Equals (Row x, Row y)
+ {
+ return x.Col1 == y.Col1
+ && x.Col2 == y.Col2;
+ }
+
+ public int GetHashCode (Row obj)
+ {
+ string x = obj.Col1, y = obj.Col2;
+ return (x != null ? x.GetHashCode () : 0) ^ (y != null ? y.GetHashCode () : 0);
+ }
+
+ public bool Equals (Row x, Row y)
+ {
+ return x.Col1 == y.Col1
+ && x.Col2 == y.Col2;
+ }
+
+ public int GetHashCode (Row obj)
+ {
+ return (int) (obj.Col1 ^ obj.Col2);
+ }
+
+ public bool Equals (Row x, Row y)
+ {
+ return x.Col1 == y.Col1
+ && x.Col2 == y.Col2
+ && x.Col3 == y.Col3;
+ }
+
+ public int GetHashCode (Row obj)
+ {
+ return (int) (obj.Col1 ^ obj.Col2 ^ obj.Col3);
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/StringHeap.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/StringHeap.cs
new file mode 100644
index 00000000..4a0a0af4
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/StringHeap.cs
@@ -0,0 +1,81 @@
+//
+// StringHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Generic;
+using System.Text;
+
+using Mono.Cecil.PE;
+
+namespace Mono.Cecil.Metadata {
+
+ class StringHeap : Heap {
+
+ readonly Dictionary strings = new Dictionary ();
+
+ public StringHeap (Section section, uint start, uint size)
+ : base (section, start, size)
+ {
+ }
+
+ public string Read (uint index)
+ {
+ if (index == 0)
+ return string.Empty;
+
+ string @string;
+ if (strings.TryGetValue (index, out @string))
+ return @string;
+
+ if (index > Size - 1)
+ return string.Empty;
+
+ @string = ReadStringAt (index);
+ if (@string.Length != 0)
+ strings.Add (index, @string);
+
+ return @string;
+ }
+
+ protected virtual string ReadStringAt (uint index)
+ {
+ int length = 0;
+ byte [] data = Section.Data;
+ int start = (int) (index + Offset);
+
+ for (int i = start; ; i++) {
+ if (data [i] == 0)
+ break;
+
+ length++;
+ }
+
+ return Encoding.UTF8.GetString (data, start, length);
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/TableHeap.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/TableHeap.cs
new file mode 100644
index 00000000..9bc0edd3
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/TableHeap.cs
@@ -0,0 +1,111 @@
+//
+// TableHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.PE;
+
+namespace Mono.Cecil.Metadata {
+
+ enum Table : byte {
+ Module = 0x00,
+ TypeRef = 0x01,
+ TypeDef = 0x02,
+ FieldPtr = 0x03,
+ Field = 0x04,
+ MethodPtr = 0x05,
+ Method = 0x06,
+ ParamPtr = 0x07,
+ Param = 0x08,
+ InterfaceImpl = 0x09,
+ MemberRef = 0x0a,
+ Constant = 0x0b,
+ CustomAttribute = 0x0c,
+ FieldMarshal = 0x0d,
+ DeclSecurity = 0x0e,
+ ClassLayout = 0x0f,
+ FieldLayout = 0x10,
+ StandAloneSig = 0x11,
+ EventMap = 0x12,
+ EventPtr = 0x13,
+ Event = 0x14,
+ PropertyMap = 0x15,
+ PropertyPtr = 0x16,
+ Property = 0x17,
+ MethodSemantics = 0x18,
+ MethodImpl = 0x19,
+ ModuleRef = 0x1a,
+ TypeSpec = 0x1b,
+ ImplMap = 0x1c,
+ FieldRVA = 0x1d,
+ EncLog = 0x1e,
+ EncMap = 0x1f,
+ Assembly = 0x20,
+ AssemblyProcessor = 0x21,
+ AssemblyOS = 0x22,
+ AssemblyRef = 0x23,
+ AssemblyRefProcessor = 0x24,
+ AssemblyRefOS = 0x25,
+ File = 0x26,
+ ExportedType = 0x27,
+ ManifestResource = 0x28,
+ NestedClass = 0x29,
+ GenericParam = 0x2a,
+ MethodSpec = 0x2b,
+ GenericParamConstraint = 0x2c,
+ }
+
+ struct TableInformation {
+ public uint Offset;
+ public uint Length;
+ public uint RowSize;
+ }
+
+ sealed class TableHeap : Heap {
+
+ public long Valid;
+ public long Sorted;
+
+ public const int TableCount = 45;
+
+ public readonly TableInformation [] Tables = new TableInformation [TableCount];
+
+ public TableInformation this [Table table] {
+ get { return Tables [(int) table]; }
+ }
+
+ public TableHeap (Section section, uint start, uint size)
+ : base (section, start, size)
+ {
+ }
+
+ public bool HasTable (Table table)
+ {
+ return (Valid & (1L << (int) table)) != 0;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/TokenType.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/TokenType.cs
new file mode 100644
index 00000000..2c2010ff
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/TokenType.cs
@@ -0,0 +1,56 @@
+//
+// TokenType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ public 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,
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/UserStringHeap.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/UserStringHeap.cs
new file mode 100644
index 00000000..3d3c5b6f
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/UserStringHeap.cs
@@ -0,0 +1,61 @@
+//
+// UserStringHeap.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.PE;
+
+namespace Mono.Cecil.Metadata
+{
+
+ sealed class UserStringHeap : StringHeap
+ {
+
+ public UserStringHeap(Section section, uint start, uint size)
+ : base(section, start, size)
+ {
+ }
+
+ protected override string ReadStringAt(uint index)
+ {
+ byte[] data = Section.Data;
+ int start = (int)(index + Offset);
+
+ uint length = (uint)(Mixin.ReadCompressedUInt32(data, ref start) & ~1);
+ if (length < 1)
+ return string.Empty;
+
+ var chars = new char[length / 2];
+
+ for (int i = start, j = 0; i < start + length; i += 2)
+ chars[j++] = (char)(data[i] | (data[i + 1] << 8));
+
+ return new string(chars);
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Utilities.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Utilities.cs
new file mode 100644
index 00000000..71200e3e
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Utilities.cs
@@ -0,0 +1,354 @@
+//
+// Utilities.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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
+{
+
+ static partial class Mixin
+ {
+
+ public static uint ReadCompressedUInt32(byte[] data, ref int position)
+ {
+ uint integer;
+ if ((data[position] & 0x80) == 0)
+ {
+ integer = data[position];
+ position++;
+ }
+ else if ((data[position] & 0x40) == 0)
+ {
+ integer = (uint)(data[position] & ~0x80) << 8;
+ integer |= data[position + 1];
+ position += 2;
+ }
+ else
+ {
+ integer = (uint)(data[position] & ~0xc0) << 24;
+ integer |= (uint)data[position + 1] << 16;
+ integer |= (uint)data[position + 2] << 8;
+ integer |= (uint)data[position + 3];
+ position += 4;
+ }
+ return integer;
+ }
+
+ public static MetadataToken GetMetadataToken(CodedIndex self, uint data)
+ {
+ uint rid;
+ TokenType token_type;
+ switch (self)
+ {
+ case CodedIndex.TypeDefOrRef:
+ rid = data >> 2;
+ switch (data & 3)
+ {
+ case 0:
+ token_type = TokenType.TypeDef; goto ret;
+ case 1:
+ token_type = TokenType.TypeRef; goto ret;
+ case 2:
+ token_type = TokenType.TypeSpec; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.HasConstant:
+ rid = data >> 2;
+ switch (data & 3)
+ {
+ case 0:
+ token_type = TokenType.Field; goto ret;
+ case 1:
+ token_type = TokenType.Param; goto ret;
+ case 2:
+ token_type = TokenType.Property; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.HasCustomAttribute:
+ rid = data >> 5;
+ switch (data & 31)
+ {
+ case 0:
+ token_type = TokenType.Method; goto ret;
+ case 1:
+ token_type = TokenType.Field; goto ret;
+ case 2:
+ token_type = TokenType.TypeRef; goto ret;
+ case 3:
+ token_type = TokenType.TypeDef; goto ret;
+ case 4:
+ token_type = TokenType.Param; goto ret;
+ case 5:
+ token_type = TokenType.InterfaceImpl; goto ret;
+ case 6:
+ token_type = TokenType.MemberRef; goto ret;
+ case 7:
+ token_type = TokenType.Module; goto ret;
+ case 8:
+ token_type = TokenType.Permission; goto ret;
+ case 9:
+ token_type = TokenType.Property; goto ret;
+ case 10:
+ token_type = TokenType.Event; goto ret;
+ case 11:
+ token_type = TokenType.Signature; goto ret;
+ case 12:
+ token_type = TokenType.ModuleRef; goto ret;
+ case 13:
+ token_type = TokenType.TypeSpec; goto ret;
+ case 14:
+ token_type = TokenType.Assembly; goto ret;
+ case 15:
+ token_type = TokenType.AssemblyRef; goto ret;
+ case 16:
+ token_type = TokenType.File; goto ret;
+ case 17:
+ token_type = TokenType.ExportedType; goto ret;
+ case 18:
+ token_type = TokenType.ManifestResource; goto ret;
+ case 19:
+ token_type = TokenType.GenericParam; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.HasFieldMarshal:
+ rid = data >> 1;
+ switch (data & 1)
+ {
+ case 0:
+ token_type = TokenType.Field; goto ret;
+ case 1:
+ token_type = TokenType.Param; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.HasDeclSecurity:
+ rid = data >> 2;
+ switch (data & 3)
+ {
+ case 0:
+ token_type = TokenType.TypeDef; goto ret;
+ case 1:
+ token_type = TokenType.Method; goto ret;
+ case 2:
+ token_type = TokenType.Assembly; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.MemberRefParent:
+ rid = data >> 3;
+ switch (data & 7)
+ {
+ case 0:
+ token_type = TokenType.TypeDef; goto ret;
+ case 1:
+ token_type = TokenType.TypeRef; goto ret;
+ case 2:
+ token_type = TokenType.ModuleRef; goto ret;
+ case 3:
+ token_type = TokenType.Method; goto ret;
+ case 4:
+ token_type = TokenType.TypeSpec; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.HasSemantics:
+ rid = data >> 1;
+ switch (data & 1)
+ {
+ case 0:
+ token_type = TokenType.Event; goto ret;
+ case 1:
+ token_type = TokenType.Property; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.MethodDefOrRef:
+ rid = data >> 1;
+ switch (data & 1)
+ {
+ case 0:
+ token_type = TokenType.Method; goto ret;
+ case 1:
+ token_type = TokenType.MemberRef; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.MemberForwarded:
+ rid = data >> 1;
+ switch (data & 1)
+ {
+ case 0:
+ token_type = TokenType.Field; goto ret;
+ case 1:
+ token_type = TokenType.Method; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.Implementation:
+ rid = data >> 2;
+ switch (data & 3)
+ {
+ case 0:
+ token_type = TokenType.File; goto ret;
+ case 1:
+ token_type = TokenType.AssemblyRef; goto ret;
+ case 2:
+ token_type = TokenType.ExportedType; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.CustomAttributeType:
+ rid = data >> 3;
+ switch (data & 7)
+ {
+ case 2:
+ token_type = TokenType.Method; goto ret;
+ case 3:
+ token_type = TokenType.MemberRef; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.ResolutionScope:
+ rid = data >> 2;
+ switch (data & 3)
+ {
+ case 0:
+ token_type = TokenType.Module; goto ret;
+ case 1:
+ token_type = TokenType.ModuleRef; goto ret;
+ case 2:
+ token_type = TokenType.AssemblyRef; goto ret;
+ case 3:
+ token_type = TokenType.TypeRef; goto ret;
+ default:
+ goto exit;
+ }
+ case CodedIndex.TypeOrMethodDef:
+ rid = data >> 1;
+ switch (data & 1)
+ {
+ case 0:
+ token_type = TokenType.TypeDef; goto ret;
+ case 1:
+ token_type = TokenType.Method; goto ret;
+ default: goto exit;
+ }
+ default:
+ goto exit;
+ }
+ ret:
+ return new MetadataToken(token_type, rid);
+ exit:
+ return MetadataToken.Zero;
+ }
+
+
+ public static int GetSize(CodedIndex self, Func counter)
+ {
+ int bits;
+ Table[] tables;
+
+ switch (self)
+ {
+ case CodedIndex.TypeDefOrRef:
+ bits = 2;
+ tables = new[] { Table.TypeDef, Table.TypeRef, Table.TypeSpec };
+ break;
+ case CodedIndex.HasConstant:
+ bits = 2;
+ tables = new[] { Table.Field, Table.Param, Table.Property };
+ break;
+ case CodedIndex.HasCustomAttribute:
+ bits = 5;
+ tables = new[] {
+ Table.Method, Table.Field, Table.TypeRef, Table.TypeDef, Table.Param, Table.InterfaceImpl, Table.MemberRef,
+ Table.Module, Table.DeclSecurity, Table.Property, Table.Event, Table.StandAloneSig, Table.ModuleRef,
+ Table.TypeSpec, Table.Assembly, Table.AssemblyRef, Table.File, Table.ExportedType,
+ Table.ManifestResource, Table.GenericParam
+ };
+ break;
+ case CodedIndex.HasFieldMarshal:
+ bits = 1;
+ tables = new[] { Table.Field, Table.Param };
+ break;
+ case CodedIndex.HasDeclSecurity:
+ bits = 2;
+ tables = new[] { Table.TypeDef, Table.Method, Table.Assembly };
+ break;
+ case CodedIndex.MemberRefParent:
+ bits = 3;
+ tables = new[] { Table.TypeDef, Table.TypeRef, Table.ModuleRef, Table.Method, Table.TypeSpec };
+ break;
+ case CodedIndex.HasSemantics:
+ bits = 1;
+ tables = new[] { Table.Event, Table.Property };
+ break;
+ case CodedIndex.MethodDefOrRef:
+ bits = 1;
+ tables = new[] { Table.Method, Table.MemberRef };
+ break;
+ case CodedIndex.MemberForwarded:
+ bits = 1;
+ tables = new[] { Table.Field, Table.Method };
+ break;
+ case CodedIndex.Implementation:
+ bits = 2;
+ tables = new[] { Table.File, Table.AssemblyRef, Table.ExportedType };
+ break;
+ case CodedIndex.CustomAttributeType:
+ bits = 3;
+ tables = new[] { Table.Method, Table.MemberRef };
+ break;
+ case CodedIndex.ResolutionScope:
+ bits = 2;
+ tables = new[] { Table.Module, Table.ModuleRef, Table.AssemblyRef, Table.TypeRef };
+ break;
+ case CodedIndex.TypeOrMethodDef:
+ bits = 1;
+ tables = new[] { Table.TypeDef, Table.Method };
+ break;
+ default:
+ throw new ArgumentException();
+ }
+
+ int max = 0;
+
+ for (int i = 0; i < tables.Length; i++)
+ {
+ max = System.Math.Max(counter(tables[i]), max);
+ }
+
+ return max < (1 << (16 - bits)) ? 2 : 4;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/BinaryStreamReader.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/BinaryStreamReader.cs
new file mode 100644
index 00000000..ec2477c3
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/BinaryStreamReader.cs
@@ -0,0 +1,51 @@
+//
+// BinaryStreamReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.IO;
+
+namespace Mono.Cecil.PE {
+
+ class BinaryStreamReader : BinaryReader {
+
+ public BinaryStreamReader (Stream stream)
+ : base (stream)
+ {
+ }
+
+ protected void Advance (int bytes)
+ {
+ BaseStream.Seek (bytes, SeekOrigin.Current);
+ }
+
+ protected DataDirectory ReadDataDirectory ()
+ {
+ return new DataDirectory (ReadUInt32 (), ReadUInt32 ());
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/BinaryStreamWriter.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/BinaryStreamWriter.cs
new file mode 100644
index 00000000..00a79755
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/BinaryStreamWriter.cs
@@ -0,0 +1,31 @@
+//
+// BinaryStreamWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.IO;
+
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ByteBuffer.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ByteBuffer.cs
new file mode 100644
index 00000000..a09812aa
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ByteBuffer.cs
@@ -0,0 +1,184 @@
+//
+// ByteBuffer.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.PE {
+
+ class ByteBuffer {
+
+ internal byte [] buffer;
+ internal int length;
+ internal int position;
+
+ public ByteBuffer ()
+ {
+ this.buffer = Empty.Array;
+ }
+
+ public ByteBuffer (int length)
+ {
+ this.buffer = new byte [length];
+ }
+
+ public ByteBuffer (byte [] buffer)
+ {
+ this.buffer = buffer ?? Empty.Array;
+ this.length = this.buffer.Length;
+ }
+
+ public void Reset (byte [] buffer)
+ {
+ this.buffer = buffer ?? Empty.Array;
+ this.length = this.buffer.Length;
+ }
+
+ public void Advance (int length)
+ {
+ position += length;
+ }
+
+ public byte ReadByte ()
+ {
+ return buffer [position++];
+ }
+
+ public sbyte ReadSByte ()
+ {
+ return (sbyte) ReadByte ();
+ }
+
+ public byte [] ReadBytes (int length)
+ {
+ var bytes = new byte [length];
+ Buffer.BlockCopy (buffer, position, bytes, 0, length);
+ position += length;
+ return bytes;
+ }
+
+ public ushort ReadUInt16 ()
+ {
+ ushort value = (ushort) (buffer [position]
+ | (buffer [position + 1] << 8));
+ position += 2;
+ return value;
+ }
+
+ public short ReadInt16 ()
+ {
+ return (short) ReadUInt16 ();
+ }
+
+ public uint ReadUInt32 ()
+ {
+ uint value = (uint) (buffer [position]
+ | (buffer [position + 1] << 8)
+ | (buffer [position + 2] << 16)
+ | (buffer [position + 3] << 24));
+ position += 4;
+ return value;
+ }
+
+ public int ReadInt32 ()
+ {
+ return (int) ReadUInt32 ();
+ }
+
+ public ulong ReadUInt64 ()
+ {
+ uint low = ReadUInt32 ();
+ uint high = ReadUInt32 ();
+
+ return (((ulong) high) << 32) | low;
+ }
+
+ public long ReadInt64 ()
+ {
+ return (long) ReadUInt64 ();
+ }
+
+ public uint ReadCompressedUInt32 ()
+ {
+ byte first = ReadByte ();
+ if ((first & 0x80) == 0)
+ return first;
+
+ if ((first & 0x40) == 0)
+ return ((uint) (first & ~0x80) << 8)
+ | ReadByte ();
+
+ return ((uint) (first & ~0xc0) << 24)
+ | (uint) ReadByte () << 16
+ | (uint) ReadByte () << 8
+ | ReadByte ();
+ }
+
+ public int ReadCompressedInt32 ()
+ {
+ var value = (int) (ReadCompressedUInt32 () >> 1);
+ if ((value & 1) == 0)
+ return value;
+ if (value < 0x40)
+ return value - 0x40;
+ if (value < 0x2000)
+ return value - 0x2000;
+ if (value < 0x10000000)
+ return value - 0x10000000;
+ return value - 0x20000000;
+ }
+
+ public float ReadSingle ()
+ {
+ if (!BitConverter.IsLittleEndian) {
+ var bytes = ReadBytes (4);
+ Array.Reverse (bytes);
+ return BitConverter.ToSingle (bytes, 0);
+ }
+
+ float value = BitConverter.ToSingle (buffer, position);
+ position += 4;
+ return value;
+ }
+
+ public double ReadDouble ()
+ {
+ if (!BitConverter.IsLittleEndian) {
+ var bytes = ReadBytes (8);
+ Array.Reverse (bytes);
+ return BitConverter.ToDouble (bytes, 0);
+ }
+
+ double value = BitConverter.ToDouble (buffer, position);
+ position += 8;
+ return value;
+ }
+
+
+
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ByteBufferEqualityComparer.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ByteBufferEqualityComparer.cs
new file mode 100644
index 00000000..70e89164
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ByteBufferEqualityComparer.cs
@@ -0,0 +1,78 @@
+//
+// ByteBufferEqualityComparer.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Generic;
+
+namespace Mono.Cecil.PE {
+
+ sealed class ByteBufferEqualityComparer : IEqualityComparer {
+
+ public bool Equals (ByteBuffer x, ByteBuffer y)
+ {
+ if (x.length != y.length)
+ return false;
+
+ var x_buffer = x.buffer;
+ var y_buffer = y.buffer;
+
+ for (int i = 0; i < x.length; i++)
+ if (x_buffer [i] != y_buffer [i])
+ return false;
+
+ return true;
+ }
+
+ public int GetHashCode (ByteBuffer buffer)
+ {
+#if !BYTE_BUFFER_WELL_DISTRIBUTED_HASH
+ var hash = 0;
+ var bytes = buffer.buffer;
+ for (int i = 0; i < buffer.length; i++)
+ hash = (hash * 37) ^ bytes [i];
+
+ return hash;
+#else
+ const uint p = 16777619;
+ uint hash = 2166136261;
+
+ var bytes = buffer.buffer;
+ for (int i = 0; i < buffer.length; i++)
+ hash = (hash ^ bytes [i]) * p;
+
+ hash += hash << 13;
+ hash ^= hash >> 7;
+ hash += hash << 3;
+ hash ^= hash >> 17;
+ hash += hash << 5;
+
+ return (int) hash;
+#endif
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/DataDirectory.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/DataDirectory.cs
new file mode 100644
index 00000000..fedd0e2d
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/DataDirectory.cs
@@ -0,0 +1,50 @@
+//
+// DataDirectory.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 RVA = System.UInt32;
+
+namespace Mono.Cecil.PE {
+
+ struct DataDirectory {
+
+ public readonly RVA VirtualAddress;
+ public readonly uint Size;
+
+ public bool IsZero {
+ get { return VirtualAddress == 0 && Size == 0; }
+ }
+
+ public DataDirectory (RVA rva, uint size)
+ {
+ this.VirtualAddress = rva;
+ this.Size = size;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/Image.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/Image.cs
new file mode 100644
index 00000000..62b8d9f7
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/Image.cs
@@ -0,0 +1,166 @@
+//
+// Image.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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;
+using Mono.Cecil.Cil;
+using Mono.Cecil.Metadata;
+
+using RVA = System.UInt32;
+
+namespace Mono.Cecil.PE
+{
+
+ sealed class Image
+ {
+
+ public ModuleKind Kind;
+ public TargetRuntime Runtime;
+ public TargetArchitecture Architecture;
+ public ModuleCharacteristics Characteristics;
+ public string FileName;
+
+ public Section[] Sections;
+
+ public Section MetadataSection;
+
+ public uint EntryPointToken;
+ public ModuleAttributes Attributes;
+
+ public DataDirectory Debug;
+ public DataDirectory Resources;
+ public DataDirectory StrongName;
+
+ public StringHeap StringHeap;
+ public BlobHeap BlobHeap;
+ public UserStringHeap UserStringHeap;
+ public GuidHeap GuidHeap;
+ public TableHeap TableHeap;
+
+ readonly int[] coded_index_sizes = new int[13];
+
+ readonly Func counter;
+
+ public Image()
+ {
+ counter = GetTableLength;
+ }
+
+ public bool HasTable(Table table)
+ {
+ return GetTableLength(table) > 0;
+ }
+
+ public int GetTableLength(Table table)
+ {
+ return (int)TableHeap[table].Length;
+ }
+
+ public int GetTableIndexSize(Table table)
+ {
+ return GetTableLength(table) < 65536 ? 2 : 4;
+ }
+
+ public int GetCodedIndexSize(CodedIndex coded_index)
+ {
+ var index = (int)coded_index;
+ var size = coded_index_sizes[index];
+ if (size != 0)
+ return size;
+
+ return coded_index_sizes[index] = Mixin.GetSize(coded_index, counter);
+ }
+
+ public uint ResolveVirtualAddress(RVA rva)
+ {
+ var section = GetSectionAtVirtualAddress(rva);
+ if (section == null)
+ throw new ArgumentOutOfRangeException();
+
+ return ResolveVirtualAddressInSection(rva, section);
+ }
+
+ public uint ResolveVirtualAddressInSection(RVA rva, Section section)
+ {
+ return rva + section.PointerToRawData - section.VirtualAddress;
+ }
+
+ public Section GetSection(string name)
+ {
+ var sections = this.Sections;
+ for (int i = 0; i < sections.Length; i++)
+ {
+ var section = sections[i];
+ if (section.Name == name)
+ return section;
+ }
+
+ return null;
+ }
+
+ public Section GetSectionAtVirtualAddress(RVA rva)
+ {
+ var sections = this.Sections;
+ for (int i = 0; i < sections.Length; i++)
+ {
+ var section = sections[i];
+ if (rva >= section.VirtualAddress && rva < section.VirtualAddress + section.SizeOfRawData)
+ return section;
+ }
+
+ return null;
+ }
+
+ public ImageDebugDirectory GetDebugHeader(out byte[] header)
+ {
+ var section = GetSectionAtVirtualAddress(Debug.VirtualAddress);
+ var buffer = new ByteBuffer(section.Data);
+ buffer.position = (int)(Debug.VirtualAddress - section.VirtualAddress);
+
+ var directory = new ImageDebugDirectory
+ {
+ Characteristics = buffer.ReadInt32(),
+ TimeDateStamp = buffer.ReadInt32(),
+ MajorVersion = buffer.ReadInt16(),
+ MinorVersion = buffer.ReadInt16(),
+ Type = buffer.ReadInt32(),
+ SizeOfData = buffer.ReadInt32(),
+ AddressOfRawData = buffer.ReadInt32(),
+ PointerToRawData = buffer.ReadInt32(),
+ };
+
+ buffer.position = (int)(directory.PointerToRawData - section.PointerToRawData);
+
+ header = new byte[directory.SizeOfData];
+ Buffer.BlockCopy(buffer.buffer, buffer.position, header, 0, header.Length);
+
+ return directory;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ImageReader.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ImageReader.cs
new file mode 100644
index 00000000..00d0c672
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ImageReader.cs
@@ -0,0 +1,694 @@
+//
+// ImageReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.IO;
+
+using Mono.Cecil.Metadata;
+
+using RVA = System.UInt32;
+
+namespace Mono.Cecil.PE
+{
+
+ sealed class ImageReader : BinaryStreamReader
+ {
+
+ readonly Image image;
+
+ DataDirectory cli;
+ DataDirectory metadata;
+
+ public ImageReader(Stream stream)
+ : base(stream)
+ {
+ image = new Image();
+
+ image.FileName = Mixin.GetFullyQualifiedName(stream);
+ }
+
+ void MoveTo(DataDirectory directory)
+ {
+ BaseStream.Position = image.ResolveVirtualAddress(directory.VirtualAddress);
+ }
+
+ void MoveTo(uint position)
+ {
+ BaseStream.Position = position;
+ }
+
+ void ReadImage()
+ {
+ if (BaseStream.Length < 128)
+ throw new BadImageFormatException();
+
+ // - DOSHeader
+
+ // PE 2
+ // Start 58
+ // Lfanew 4
+ // End 64
+
+ if (ReadUInt16() != 0x5a4d)
+ throw new BadImageFormatException();
+
+ Advance(58);
+
+ MoveTo(ReadUInt32());
+
+ if (ReadUInt32() != 0x00004550)
+ throw new BadImageFormatException();
+
+ // - PEFileHeader
+
+ // Machine 2
+ image.Architecture = ReadArchitecture();
+
+ // NumberOfSections 2
+ ushort sections = ReadUInt16();
+
+ // TimeDateStamp 4
+ // PointerToSymbolTable 4
+ // NumberOfSymbols 4
+ // OptionalHeaderSize 2
+ Advance(14);
+
+ // Characteristics 2
+ ushort characteristics = ReadUInt16();
+
+ ushort subsystem, dll_characteristics;
+ ReadOptionalHeaders(out subsystem, out dll_characteristics);
+ ReadSections(sections);
+ ReadCLIHeader();
+ ReadMetadata();
+
+ image.Kind = GetModuleKind(characteristics, subsystem);
+ image.Characteristics = (ModuleCharacteristics)dll_characteristics;
+ }
+
+ TargetArchitecture ReadArchitecture()
+ {
+ var machine = ReadUInt16();
+ switch (machine)
+ {
+ case 0x014c:
+ return TargetArchitecture.I386;
+ case 0x8664:
+ return TargetArchitecture.AMD64;
+ case 0x0200:
+ return TargetArchitecture.IA64;
+ case 0x01c4:
+ return TargetArchitecture.ARMv7;
+ }
+
+ throw new NotSupportedException();
+ }
+
+ static ModuleKind GetModuleKind(ushort characteristics, ushort subsystem)
+ {
+ if ((characteristics & 0x2000) != 0) // ImageCharacteristics.Dll
+ return ModuleKind.Dll;
+
+ if (subsystem == 0x2 || subsystem == 0x9) // SubSystem.WindowsGui || SubSystem.WindowsCeGui
+ return ModuleKind.Windows;
+
+ return ModuleKind.Console;
+ }
+
+ void ReadOptionalHeaders(out ushort subsystem, out ushort dll_characteristics)
+ {
+ // - PEOptionalHeader
+ // - StandardFieldsHeader
+
+ // Magic 2
+ bool pe64 = ReadUInt16() == 0x20b;
+
+ // pe32 || pe64
+
+ // LMajor 1
+ // LMinor 1
+ // CodeSize 4
+ // InitializedDataSize 4
+ // UninitializedDataSize4
+ // EntryPointRVA 4
+ // BaseOfCode 4
+ // BaseOfData 4 || 0
+
+ // - NTSpecificFieldsHeader
+
+ // ImageBase 4 || 8
+ // SectionAlignment 4
+ // FileAlignement 4
+ // OSMajor 2
+ // OSMinor 2
+ // UserMajor 2
+ // UserMinor 2
+ // SubSysMajor 2
+ // SubSysMinor 2
+ // Reserved 4
+ // ImageSize 4
+ // HeaderSize 4
+ // FileChecksum 4
+ Advance(66);
+
+ // SubSystem 2
+ subsystem = ReadUInt16();
+
+ // DLLFlags 2
+ dll_characteristics = ReadUInt16();
+ // StackReserveSize 4 || 8
+ // StackCommitSize 4 || 8
+ // HeapReserveSize 4 || 8
+ // HeapCommitSize 4 || 8
+ // LoaderFlags 4
+ // NumberOfDataDir 4
+
+ // - DataDirectoriesHeader
+
+ // ExportTable 8
+ // ImportTable 8
+ // ResourceTable 8
+ // ExceptionTable 8
+ // CertificateTable 8
+ // BaseRelocationTable 8
+
+ Advance(pe64 ? 88 : 72);
+
+ // Debug 8
+ image.Debug = ReadDataDirectory();
+
+ // Copyright 8
+ // GlobalPtr 8
+ // TLSTable 8
+ // LoadConfigTable 8
+ // BoundImport 8
+ // IAT 8
+ // DelayImportDescriptor8
+ Advance(56);
+
+ // CLIHeader 8
+ cli = ReadDataDirectory();
+
+ if (cli.IsZero)
+ throw new BadImageFormatException();
+
+ // Reserved 8
+ Advance(8);
+ }
+
+ string ReadAlignedString(int length)
+ {
+ int read = 0;
+ var buffer = new char[length];
+ while (read < length)
+ {
+ var current = ReadByte();
+ if (current == 0)
+ break;
+
+ buffer[read++] = (char)current;
+ }
+
+ Advance(-1 + ((read + 4) & ~3) - read);
+
+ return new string(buffer, 0, read);
+ }
+
+ string ReadZeroTerminatedString(int length)
+ {
+ int read = 0;
+ var buffer = new char[length];
+ var bytes = ReadBytes(length);
+ while (read < length)
+ {
+ var current = bytes[read];
+ if (current == 0)
+ break;
+
+ buffer[read++] = (char)current;
+ }
+
+ return new string(buffer, 0, read);
+ }
+
+ void ReadSections(ushort count)
+ {
+ var sections = new Section[count];
+
+ for (int i = 0; i < count; i++)
+ {
+ var section = new Section();
+
+ // Name
+ section.Name = ReadZeroTerminatedString(8);
+
+ // VirtualSize 4
+ Advance(4);
+
+ // VirtualAddress 4
+ section.VirtualAddress = ReadUInt32();
+ // SizeOfRawData 4
+ section.SizeOfRawData = ReadUInt32();
+ // PointerToRawData 4
+ section.PointerToRawData = ReadUInt32();
+
+ // PointerToRelocations 4
+ // PointerToLineNumbers 4
+ // NumberOfRelocations 2
+ // NumberOfLineNumbers 2
+ // Characteristics 4
+ Advance(16);
+
+ sections[i] = section;
+
+ ReadSectionData(section);
+ }
+
+ image.Sections = sections;
+ }
+
+ void ReadSectionData(Section section)
+ {
+ var position = BaseStream.Position;
+
+ MoveTo(section.PointerToRawData);
+
+ var length = (int)section.SizeOfRawData;
+ var data = new byte[length];
+ int offset = 0, read;
+
+ while ((read = Read(data, offset, length - offset)) > 0)
+ offset += read;
+
+ section.Data = data;
+
+ BaseStream.Position = position;
+ }
+
+ void ReadCLIHeader()
+ {
+ MoveTo(cli);
+
+ // - CLIHeader
+
+ // Cb 4
+ // MajorRuntimeVersion 2
+ // MinorRuntimeVersion 2
+ Advance(8);
+
+ // Metadata 8
+ metadata = ReadDataDirectory();
+ // Flags 4
+ image.Attributes = (ModuleAttributes)ReadUInt32();
+ // EntryPointToken 4
+ image.EntryPointToken = ReadUInt32();
+ // Resources 8
+ image.Resources = ReadDataDirectory();
+ // StrongNameSignature 8
+ image.StrongName = ReadDataDirectory();
+ // CodeManagerTable 8
+ // VTableFixups 8
+ // ExportAddressTableJumps 8
+ // ManagedNativeHeader 8
+ }
+
+ void ReadMetadata()
+ {
+ MoveTo(metadata);
+
+ if (ReadUInt32() != 0x424a5342)
+ throw new BadImageFormatException();
+
+ // MajorVersion 2
+ // MinorVersion 2
+ // Reserved 4
+ Advance(8);
+
+ var version = ReadZeroTerminatedString(ReadInt32());
+ image.Runtime = Mixin.ParseRuntime(version);
+
+ // Flags 2
+ Advance(2);
+
+ var streams = ReadUInt16();
+
+ var section = image.GetSectionAtVirtualAddress(metadata.VirtualAddress);
+ if (section == null)
+ throw new BadImageFormatException();
+
+ image.MetadataSection = section;
+
+ for (int i = 0; i < streams; i++)
+ ReadMetadataStream(section);
+
+ if (image.TableHeap != null)
+ ReadTableHeap();
+ }
+
+ void ReadMetadataStream(Section section)
+ {
+ // Offset 4
+ uint start = metadata.VirtualAddress - section.VirtualAddress + ReadUInt32(); // relative to the section start
+
+ // Size 4
+ uint size = ReadUInt32();
+
+ var name = ReadAlignedString(16);
+ switch (name)
+ {
+ case "#~":
+ case "#-":
+ image.TableHeap = new TableHeap(section, start, size);
+ break;
+ case "#Strings":
+ image.StringHeap = new StringHeap(section, start, size);
+ break;
+ case "#Blob":
+ image.BlobHeap = new BlobHeap(section, start, size);
+ break;
+ case "#GUID":
+ image.GuidHeap = new GuidHeap(section, start, size);
+ break;
+ case "#US":
+ image.UserStringHeap = new UserStringHeap(section, start, size);
+ break;
+ }
+ }
+
+ void ReadTableHeap()
+ {
+ var heap = image.TableHeap;
+
+ uint start = heap.Section.PointerToRawData;
+
+ MoveTo(heap.Offset + start);
+
+ // Reserved 4
+ // MajorVersion 1
+ // MinorVersion 1
+ Advance(6);
+
+ // HeapSizes 1
+ var sizes = ReadByte();
+
+ // Reserved2 1
+ Advance(1);
+
+ // Valid 8
+ heap.Valid = ReadInt64();
+
+ // Sorted 8
+ heap.Sorted = ReadInt64();
+
+ for (int i = 0; i < TableHeap.TableCount; i++)
+ {
+ if (!heap.HasTable((Table)i))
+ continue;
+
+ heap.Tables[i].Length = ReadUInt32();
+ }
+
+ SetIndexSize(image.StringHeap, sizes, 0x1);
+ SetIndexSize(image.GuidHeap, sizes, 0x2);
+ SetIndexSize(image.BlobHeap, sizes, 0x4);
+
+ ComputeTableInformations();
+ }
+
+ static void SetIndexSize(Heap heap, uint sizes, byte flag)
+ {
+ if (heap == null)
+ return;
+
+ heap.IndexSize = (sizes & flag) > 0 ? 4 : 2;
+ }
+
+ int GetTableIndexSize(Table table)
+ {
+ return image.GetTableIndexSize(table);
+ }
+
+ int GetCodedIndexSize(CodedIndex index)
+ {
+ return image.GetCodedIndexSize(index);
+ }
+
+ void ComputeTableInformations()
+ {
+ uint offset = (uint)BaseStream.Position - image.MetadataSection.PointerToRawData; // header
+
+ int stridx_size = image.StringHeap.IndexSize;
+ int blobidx_size = image.BlobHeap != null ? image.BlobHeap.IndexSize : 2;
+
+ var heap = image.TableHeap;
+ var tables = heap.Tables;
+
+ for (int i = 0; i < TableHeap.TableCount; i++)
+ {
+ var table = (Table)i;
+ if (!heap.HasTable(table))
+ continue;
+
+ int size;
+ switch (table)
+ {
+ case Table.Module:
+ size = 2 // Generation
+ + stridx_size // Name
+ + (image.GuidHeap.IndexSize * 3); // Mvid, EncId, EncBaseId
+ break;
+ case Table.TypeRef:
+ size = GetCodedIndexSize(CodedIndex.ResolutionScope) // ResolutionScope
+ + (stridx_size * 2); // Name, Namespace
+ break;
+ case Table.TypeDef:
+ size = 4 // Flags
+ + (stridx_size * 2) // Name, Namespace
+ + GetCodedIndexSize(CodedIndex.TypeDefOrRef) // BaseType
+ + GetTableIndexSize(Table.Field) // FieldList
+ + GetTableIndexSize(Table.Method); // MethodList
+ break;
+ case Table.FieldPtr:
+ size = GetTableIndexSize(Table.Field); // Field
+ break;
+ case Table.Field:
+ size = 2 // Flags
+ + stridx_size // Name
+ + blobidx_size; // Signature
+ break;
+ case Table.MethodPtr:
+ size = GetTableIndexSize(Table.Method); // Method
+ break;
+ case Table.Method:
+ size = 8 // Rva 4, ImplFlags 2, Flags 2
+ + stridx_size // Name
+ + blobidx_size // Signature
+ + GetTableIndexSize(Table.Param); // ParamList
+ break;
+ case Table.ParamPtr:
+ size = GetTableIndexSize(Table.Param); // Param
+ break;
+ case Table.Param:
+ size = 4 // Flags 2, Sequence 2
+ + stridx_size; // Name
+ break;
+ case Table.InterfaceImpl:
+ size = GetTableIndexSize(Table.TypeDef) // Class
+ + GetCodedIndexSize(CodedIndex.TypeDefOrRef); // Interface
+ break;
+ case Table.MemberRef:
+ size = GetCodedIndexSize(CodedIndex.MemberRefParent) // Class
+ + stridx_size // Name
+ + blobidx_size; // Signature
+ break;
+ case Table.Constant:
+ size = 2 // Type
+ + GetCodedIndexSize(CodedIndex.HasConstant) // Parent
+ + blobidx_size; // Value
+ break;
+ case Table.CustomAttribute:
+ size = GetCodedIndexSize(CodedIndex.HasCustomAttribute) // Parent
+ + GetCodedIndexSize(CodedIndex.CustomAttributeType) // Type
+ + blobidx_size; // Value
+ break;
+ case Table.FieldMarshal:
+ size = GetCodedIndexSize(CodedIndex.HasFieldMarshal) // Parent
+ + blobidx_size; // NativeType
+ break;
+ case Table.DeclSecurity:
+ size = 2 // Action
+ + GetCodedIndexSize(CodedIndex.HasDeclSecurity) // Parent
+ + blobidx_size; // PermissionSet
+ break;
+ case Table.ClassLayout:
+ size = 6 // PackingSize 2, ClassSize 4
+ + GetTableIndexSize(Table.TypeDef); // Parent
+ break;
+ case Table.FieldLayout:
+ size = 4 // Offset
+ + GetTableIndexSize(Table.Field); // Field
+ break;
+ case Table.StandAloneSig:
+ size = blobidx_size; // Signature
+ break;
+ case Table.EventMap:
+ size = GetTableIndexSize(Table.TypeDef) // Parent
+ + GetTableIndexSize(Table.Event); // EventList
+ break;
+ case Table.EventPtr:
+ size = GetTableIndexSize(Table.Event); // Event
+ break;
+ case Table.Event:
+ size = 2 // Flags
+ + stridx_size // Name
+ + GetCodedIndexSize(CodedIndex.TypeDefOrRef); // EventType
+ break;
+ case Table.PropertyMap:
+ size = GetTableIndexSize(Table.TypeDef) // Parent
+ + GetTableIndexSize(Table.Property); // PropertyList
+ break;
+ case Table.PropertyPtr:
+ size = GetTableIndexSize(Table.Property); // Property
+ break;
+ case Table.Property:
+ size = 2 // Flags
+ + stridx_size // Name
+ + blobidx_size; // Type
+ break;
+ case Table.MethodSemantics:
+ size = 2 // Semantics
+ + GetTableIndexSize(Table.Method) // Method
+ + GetCodedIndexSize(CodedIndex.HasSemantics); // Association
+ break;
+ case Table.MethodImpl:
+ size = GetTableIndexSize(Table.TypeDef) // Class
+ + GetCodedIndexSize(CodedIndex.MethodDefOrRef) // MethodBody
+ + GetCodedIndexSize(CodedIndex.MethodDefOrRef); // MethodDeclaration
+ break;
+ case Table.ModuleRef:
+ size = stridx_size; // Name
+ break;
+ case Table.TypeSpec:
+ size = blobidx_size; // Signature
+ break;
+ case Table.ImplMap:
+ size = 2 // MappingFlags
+ + GetCodedIndexSize(CodedIndex.MemberForwarded) // MemberForwarded
+ + stridx_size // ImportName
+ + GetTableIndexSize(Table.ModuleRef); // ImportScope
+ break;
+ case Table.FieldRVA:
+ size = 4 // RVA
+ + GetTableIndexSize(Table.Field); // Field
+ break;
+ case Table.EncLog:
+ case Table.EncMap:
+ size = 4;
+ break;
+ case Table.Assembly:
+ size = 16 // HashAlgId 4, Version 4 * 2, Flags 4
+ + blobidx_size // PublicKey
+ + (stridx_size * 2); // Name, Culture
+ break;
+ case Table.AssemblyProcessor:
+ size = 4; // Processor
+ break;
+ case Table.AssemblyOS:
+ size = 12; // Platform 4, Version 2 * 4
+ break;
+ case Table.AssemblyRef:
+ size = 12 // Version 2 * 4 + Flags 4
+ + (blobidx_size * 2) // PublicKeyOrToken, HashValue
+ + (stridx_size * 2); // Name, Culture
+ break;
+ case Table.AssemblyRefProcessor:
+ size = 4 // Processor
+ + GetTableIndexSize(Table.AssemblyRef); // AssemblyRef
+ break;
+ case Table.AssemblyRefOS:
+ size = 12 // Platform 4, Version 2 * 4
+ + GetTableIndexSize(Table.AssemblyRef); // AssemblyRef
+ break;
+ case Table.File:
+ size = 4 // Flags
+ + stridx_size // Name
+ + blobidx_size; // HashValue
+ break;
+ case Table.ExportedType:
+ size = 8 // Flags 4, TypeDefId 4
+ + (stridx_size * 2) // Name, Namespace
+ + GetCodedIndexSize(CodedIndex.Implementation); // Implementation
+ break;
+ case Table.ManifestResource:
+ size = 8 // Offset, Flags
+ + stridx_size // Name
+ + GetCodedIndexSize(CodedIndex.Implementation); // Implementation
+ break;
+ case Table.NestedClass:
+ size = GetTableIndexSize(Table.TypeDef) // NestedClass
+ + GetTableIndexSize(Table.TypeDef); // EnclosingClass
+ break;
+ case Table.GenericParam:
+ size = 4 // Number, Flags
+ + GetCodedIndexSize(CodedIndex.TypeOrMethodDef) // Owner
+ + stridx_size; // Name
+ break;
+ case Table.MethodSpec:
+ size = GetCodedIndexSize(CodedIndex.MethodDefOrRef) // Method
+ + blobidx_size; // Instantiation
+ break;
+ case Table.GenericParamConstraint:
+ size = GetTableIndexSize(Table.GenericParam) // Owner
+ + GetCodedIndexSize(CodedIndex.TypeDefOrRef); // Constraint
+ break;
+ default:
+ throw new NotSupportedException();
+ }
+
+ tables[i].RowSize = (uint)size;
+ tables[i].Offset = offset;
+
+ offset += (uint)size * tables[i].Length;
+ }
+ }
+
+ public static Image ReadImageFrom(Stream stream)
+ {
+ try
+ {
+ var reader = new ImageReader(stream);
+ reader.ReadImage();
+ return reader.image;
+ }
+ catch (EndOfStreamException e)
+ {
+ throw new BadImageFormatException(Mixin.GetFullyQualifiedName(stream), e);
+ }
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ImageWriter.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/ImageWriter.cs
new file mode 100644
index 00000000..e69de29b
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/Section.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/Section.cs
new file mode 100644
index 00000000..6a4c7bab
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/Section.cs
@@ -0,0 +1,43 @@
+//
+// Section.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 RVA = System.UInt32;
+
+namespace Mono.Cecil.PE {
+
+ sealed class Section {
+ public string Name;
+ public RVA VirtualAddress;
+ public uint VirtualSize;
+ public uint SizeOfRawData;
+ public uint PointerToRawData;
+ public byte [] Data;
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/TextMap.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil.PE/TextMap.cs
new file mode 100644
index 00000000..e69de29b
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/ArrayType.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/ArrayType.cs
new file mode 100644
index 00000000..55c59d87
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/ArrayType.cs
@@ -0,0 +1,159 @@
+//
+// ArrayType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Text;
+using Mono.Collections.Generic;
+using MD = Mono.Cecil.Metadata;
+
+namespace Mono.Cecil {
+
+ public struct ArrayDimension {
+
+ int? lower_bound;
+ int? upper_bound;
+
+ public int? LowerBound {
+ get { return lower_bound; }
+ set { lower_bound = value; }
+ }
+
+ public int? UpperBound {
+ get { return upper_bound; }
+ set { upper_bound = value; }
+ }
+
+ public bool IsSized {
+ get { return lower_bound.HasValue || upper_bound.HasValue; }
+ }
+
+ public ArrayDimension (int? lowerBound, int? upperBound)
+ {
+ this.lower_bound = lowerBound;
+ this.upper_bound = upperBound;
+ }
+
+ public override string ToString ()
+ {
+ return !IsSized
+ ? string.Empty
+ : lower_bound + "..." + upper_bound;
+ }
+ }
+
+ public sealed class ArrayType : TypeSpecification {
+
+ Collection dimensions;
+
+ public Collection Dimensions {
+ get {
+ if (dimensions != null)
+ return dimensions;
+
+ dimensions = new Collection ();
+ dimensions.Add (new ArrayDimension ());
+ return dimensions;
+ }
+ }
+
+ public int Rank {
+ get { return dimensions == null ? 1 : dimensions.Count; }
+ }
+
+ public bool IsVector {
+ get {
+ if (dimensions == null)
+ return true;
+
+ if (dimensions.Count > 1)
+ return false;
+
+ var dimension = dimensions [0];
+
+ return !dimension.IsSized;
+ }
+ }
+
+ public override bool IsValueType {
+ get { return false; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string Name {
+ get { return base.Name + Suffix; }
+ }
+
+ public override string FullName {
+ get { return base.FullName + Suffix; }
+ }
+
+ string Suffix {
+ get {
+ if (IsVector)
+ return "[]";
+
+ var suffix = new StringBuilder ();
+ suffix.Append ("[");
+ for (int i = 0; i < dimensions.Count; i++) {
+ if (i > 0)
+ suffix.Append (",");
+
+ suffix.Append (dimensions [i].ToString ());
+ }
+ suffix.Append ("]");
+
+ return suffix.ToString ();
+ }
+ }
+
+ public override bool IsArray {
+ get { return true; }
+ }
+
+ public ArrayType (TypeReference type)
+ : base (type)
+ {
+ Mixin.CheckType (type);
+ this.etype = MD.ElementType.Array;
+ }
+
+ public ArrayType (TypeReference type, int rank)
+ : this (type)
+ {
+ Mixin.CheckType (type);
+
+ if (rank == 1)
+ return;
+
+ dimensions = new Collection (rank);
+ for (int i = 0; i < rank; i++)
+ dimensions.Add (new ArrayDimension ());
+ this.etype = MD.ElementType.Array;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyDefinition.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyDefinition.cs
new file mode 100644
index 00000000..4ae62ee4
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyDefinition.cs
@@ -0,0 +1,163 @@
+//
+// AssemblyDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.IO;
+
+using Mono.Collections.Generic;
+
+namespace Mono.Cecil
+{
+
+ public sealed class AssemblyDefinition : ICustomAttributeProvider, ISecurityDeclarationProvider
+ {
+
+ AssemblyNameDefinition name;
+
+ internal ModuleDefinition main_module;
+ Collection modules;
+ Collection custom_attributes;
+ Collection security_declarations;
+
+ public AssemblyNameDefinition Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
+
+ public string FullName
+ {
+ get { return name != null ? name.FullName : string.Empty; }
+ }
+
+ public MetadataToken MetadataToken
+ {
+ get { return new MetadataToken(TokenType.Assembly, 1); }
+ set { }
+ }
+
+ public Collection Modules
+ {
+ get
+ {
+ if (modules != null)
+ return modules;
+
+ if (main_module.HasImage)
+ return main_module.Read(ref modules, this, (_, reader) => reader.ReadModules());
+
+ return modules = new Collection(1) { main_module };
+ }
+ }
+
+ public ModuleDefinition MainModule
+ {
+ get { return main_module; }
+ }
+
+ public MethodDefinition EntryPoint
+ {
+ get { return main_module.EntryPoint; }
+ set { main_module.EntryPoint = value; }
+ }
+
+ public bool HasCustomAttributes
+ {
+ get
+ {
+ if (custom_attributes != null)
+ return custom_attributes.Count > 0;
+
+ return Mixin.GetHasCustomAttributes(this, main_module);
+ }
+ }
+
+ public Collection CustomAttributes
+ {
+ get { return custom_attributes ?? (Mixin.GetCustomAttributes(this, ref custom_attributes, main_module)); }
+ }
+
+ public bool HasSecurityDeclarations
+ {
+ get
+ {
+ if (security_declarations != null)
+ return security_declarations.Count > 0;
+
+ return Mixin.GetHasSecurityDeclarations(this, main_module);
+ }
+ }
+
+ public Collection SecurityDeclarations
+ {
+ get { return security_declarations ?? (Mixin.GetSecurityDeclarations(this, ref security_declarations, main_module)); }
+ }
+
+ internal AssemblyDefinition()
+ {
+ }
+
+
+
+ public static AssemblyDefinition ReadAssembly(string fileName)
+ {
+ return ReadAssembly(ModuleDefinition.ReadModule(fileName));
+ }
+
+ public static AssemblyDefinition ReadAssembly(string fileName, ReaderParameters parameters)
+ {
+ return ReadAssembly(ModuleDefinition.ReadModule(fileName, parameters));
+ }
+
+ public static AssemblyDefinition ReadAssembly(Stream stream)
+ {
+ return ReadAssembly(ModuleDefinition.ReadModule(stream));
+ }
+
+ public static AssemblyDefinition ReadAssembly(Stream stream, ReaderParameters parameters)
+ {
+ return ReadAssembly(ModuleDefinition.ReadModule(stream, parameters));
+ }
+
+ static AssemblyDefinition ReadAssembly(ModuleDefinition module)
+ {
+ var assembly = module.Assembly;
+ if (assembly == null)
+ throw new ArgumentException();
+
+ return assembly;
+ }
+
+
+
+ public override string ToString()
+ {
+ return this.FullName;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyFlags.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyFlags.cs
new file mode 100644
index 00000000..72a0eb06
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyFlags.cs
@@ -0,0 +1,42 @@
+//
+// AssemblyFlags.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ [Flags]
+ public enum AssemblyAttributes : uint {
+ PublicKey = 0x0001,
+ SideBySideCompatible = 0x0000,
+ Retargetable = 0x0100,
+ WindowsRuntime = 0x0200,
+ DisableJITCompileOptimizer = 0x4000,
+ EnableJITCompileTracking = 0x8000,
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyHashAlgorithm.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyHashAlgorithm.cs
new file mode 100644
index 00000000..79a5699d
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyHashAlgorithm.cs
@@ -0,0 +1,36 @@
+//
+// AssemblyHashAlgorithm.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ public enum AssemblyHashAlgorithm : uint {
+ None = 0x0000,
+ Reserved = 0x8003, // MD5
+ SHA1 = 0x8004
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyLinkedResource.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyLinkedResource.cs
new file mode 100644
index 00000000..4d8bac0b
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyLinkedResource.cs
@@ -0,0 +1,57 @@
+//
+// AssemblyLinkedResource.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ public sealed class AssemblyLinkedResource : Resource {
+
+ AssemblyNameReference reference;
+
+ public AssemblyNameReference Assembly {
+ get { return reference; }
+ set { reference = value; }
+ }
+
+ public override ResourceType ResourceType {
+ get { return ResourceType.AssemblyLinked; }
+ }
+
+ public AssemblyLinkedResource (string name, ManifestResourceAttributes flags)
+ : base (name, flags)
+ {
+ }
+
+ public AssemblyLinkedResource (string name, ManifestResourceAttributes flags, AssemblyNameReference reference)
+ : base (name, flags)
+ {
+ this.reference = reference;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyNameDefinition.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyNameDefinition.cs
new file mode 100644
index 00000000..dc6b9057
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyNameDefinition.cs
@@ -0,0 +1,50 @@
+//
+// AssemblyNameDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ public sealed class AssemblyNameDefinition : AssemblyNameReference {
+
+ public override byte [] Hash {
+ get { return Empty.Array; }
+ }
+
+ internal AssemblyNameDefinition ()
+ {
+ this.token = new MetadataToken (TokenType.Assembly, 1);
+ }
+
+ public AssemblyNameDefinition (string name, Version version)
+ : base (name, version)
+ {
+ this.token = new MetadataToken (TokenType.Assembly, 1);
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyNameReference.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyNameReference.cs
new file mode 100644
index 00000000..da77d504
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyNameReference.cs
@@ -0,0 +1,296 @@
+//
+// AssemblyNameReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Globalization;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace Mono.Cecil
+{
+
+ public class AssemblyNameReference : IMetadataScope
+ {
+
+ string name;
+ string culture;
+ Version version;
+ uint attributes;
+ byte[] public_key;
+ byte[] public_key_token;
+ AssemblyHashAlgorithm hash_algorithm;
+ byte[] hash;
+
+ internal MetadataToken token;
+
+ string full_name;
+
+ public string Name
+ {
+ get { return name; }
+ set
+ {
+ name = value;
+ full_name = null;
+ }
+ }
+
+ public string Culture
+ {
+ get { return culture; }
+ set
+ {
+ culture = value;
+ full_name = null;
+ }
+ }
+
+ public Version Version
+ {
+ get { return version; }
+ set
+ {
+ version = value;
+ full_name = null;
+ }
+ }
+
+ public AssemblyAttributes Attributes
+ {
+ get { return (AssemblyAttributes)attributes; }
+ set { attributes = (uint)value; }
+ }
+
+ public bool HasPublicKey
+ {
+ get { return Mixin.GetAttributes(attributes,(uint)AssemblyAttributes.PublicKey); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint)AssemblyAttributes.PublicKey, value); }
+ }
+
+ public bool IsSideBySideCompatible
+ {
+ get { return Mixin.GetAttributes(attributes,(uint)AssemblyAttributes.SideBySideCompatible); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint)AssemblyAttributes.SideBySideCompatible, value); }
+ }
+
+ public bool IsRetargetable
+ {
+ get { return Mixin.GetAttributes(attributes,(uint)AssemblyAttributes.Retargetable); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint)AssemblyAttributes.Retargetable, value); }
+ }
+
+ public bool IsWindowsRuntime
+ {
+ get { return Mixin.GetAttributes(attributes,(uint)AssemblyAttributes.WindowsRuntime); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint)AssemblyAttributes.WindowsRuntime, value); }
+ }
+
+ public byte[] PublicKey
+ {
+ get { return public_key ?? Empty.Array; }
+ set
+ {
+ public_key = value;
+ HasPublicKey = !Mixin.IsNullOrEmpty(public_key);
+ public_key_token = Empty.Array;
+ full_name = null;
+ }
+ }
+
+ public byte[] PublicKeyToken
+ {
+ get
+ {
+ if (Mixin.IsNullOrEmpty(public_key_token) && !Mixin.IsNullOrEmpty(public_key))
+ {
+ var hash = HashPublicKey();
+ // we need the last 8 bytes in reverse order
+ byte[] local_public_key_token = new byte[8];
+ Array.Copy(hash, (hash.Length - 8), local_public_key_token, 0, 8);
+ Array.Reverse(local_public_key_token, 0, 8);
+ public_key_token = local_public_key_token; // publish only once finished (required for thread-safety)
+ }
+ return public_key_token ?? Empty.Array;
+ }
+ set
+ {
+ public_key_token = value;
+ full_name = null;
+ }
+ }
+
+ byte[] HashPublicKey()
+ {
+ HashAlgorithm algorithm;
+
+ switch (hash_algorithm)
+ {
+ case AssemblyHashAlgorithm.Reserved:
+
+ throw new NotSupportedException();
+
+ default:
+ // None default to SHA1
+ algorithm = new SHA1Managed();
+ break;
+
+ }
+
+ using (algorithm)
+ return algorithm.ComputeHash(public_key);
+ }
+
+ public virtual MetadataScopeType MetadataScopeType
+ {
+ get { return MetadataScopeType.AssemblyNameReference; }
+ }
+
+ public string FullName
+ {
+ get
+ {
+ if (full_name != null)
+ return full_name;
+
+ const string sep = ", ";
+
+ var builder = new StringBuilder();
+ builder.Append(name);
+ if (version != null)
+ {
+ builder.Append(sep);
+ builder.Append("Version=");
+ builder.Append(version.ToString());
+ }
+ builder.Append(sep);
+ builder.Append("Culture=");
+ builder.Append(string.IsNullOrEmpty(culture) ? "neutral" : culture);
+ builder.Append(sep);
+ builder.Append("PublicKeyToken=");
+
+ var pk_token = PublicKeyToken;
+ if (!Mixin.IsNullOrEmpty(pk_token) && pk_token.Length > 0)
+ {
+ for (int i = 0; i < pk_token.Length; i++)
+ {
+ builder.Append(pk_token[i].ToString("x2"));
+ }
+ }
+ else
+ builder.Append("null");
+
+ return full_name = builder.ToString();
+ }
+ }
+
+ 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");
+
+ var name = new AssemblyNameReference();
+ var tokens = fullName.Split(',');
+ for (int i = 0; i < tokens.Length; i++)
+ {
+ var token = tokens[i].Trim();
+
+ if (i == 0)
+ {
+ name.Name = token;
+ continue;
+ }
+
+ var parts = token.Split('=');
+ if (parts.Length != 2)
+ throw new ArgumentException("Malformed name");
+
+ switch (parts[0].ToLowerInvariant())
+ {
+ case "version":
+ name.Version = new Version(parts[1]);
+ break;
+ case "culture":
+ name.Culture = parts[1];
+ break;
+ case "publickeytoken":
+ var pk_token = parts[1];
+ if (pk_token == "null")
+ break;
+
+ name.PublicKeyToken = new byte[pk_token.Length / 2];
+ for (int j = 0; j < name.PublicKeyToken.Length; j++)
+ name.PublicKeyToken[j] = Byte.Parse(pk_token.Substring(j * 2, 2), NumberStyles.HexNumber);
+
+ break;
+ }
+ }
+
+ return name;
+ }
+
+ public AssemblyHashAlgorithm HashAlgorithm
+ {
+ get { return hash_algorithm; }
+ set { hash_algorithm = value; }
+ }
+
+ public virtual byte[] Hash
+ {
+ get { return hash; }
+ set { hash = value; }
+ }
+
+ public MetadataToken MetadataToken
+ {
+ get { return token; }
+ set { token = value; }
+ }
+
+ internal AssemblyNameReference()
+ {
+ }
+
+ public AssemblyNameReference(string name, Version version)
+ {
+ if (name == null)
+ throw new ArgumentNullException("name");
+
+ this.name = name;
+ this.version = version;
+ this.hash_algorithm = AssemblyHashAlgorithm.None;
+ this.token = new MetadataToken(TokenType.AssemblyRef);
+ }
+
+ public override string ToString()
+ {
+ return this.FullName;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyReader.cs
new file mode 100644
index 00000000..ecf70faa
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyReader.cs
@@ -0,0 +1,3287 @@
+//
+// AssemblyReader.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Generic;
+using System.IO;
+using System.Text;
+
+using Mono.Collections.Generic;
+using Mono.Cecil.Cil;
+using Mono.Cecil.Metadata;
+using Mono.Cecil.PE;
+
+using RVA = System.UInt32;
+
+namespace Mono.Cecil
+{
+
+ abstract class ModuleReader
+ {
+
+ readonly protected Image image;
+ readonly protected ModuleDefinition module;
+
+ protected ModuleReader(Image image, ReadingMode mode)
+ {
+ this.image = image;
+ this.module = new ModuleDefinition(image);
+ this.module.ReadingMode = mode;
+ }
+
+ protected abstract void ReadModule();
+
+ protected void ReadModuleManifest(MetadataReader reader)
+ {
+ reader.Populate(module);
+
+ ReadAssembly(reader);
+ }
+
+ void ReadAssembly(MetadataReader reader)
+ {
+ var name = reader.ReadAssemblyNameDefinition();
+ if (name == null)
+ {
+ module.kind = ModuleKind.NetModule;
+ return;
+ }
+
+ var assembly = new AssemblyDefinition();
+ assembly.Name = name;
+
+ module.assembly = assembly;
+ assembly.main_module = module;
+ }
+
+ public static ModuleDefinition CreateModuleFrom(Image image, ReaderParameters parameters)
+ {
+ var module = ReadModule(image, parameters);
+
+ ReadSymbols(module, parameters);
+
+ if (parameters.AssemblyResolver != null)
+ module.assembly_resolver = parameters.AssemblyResolver;
+
+ if (parameters.MetadataResolver != null)
+ module.metadata_resolver = parameters.MetadataResolver;
+
+ return module;
+ }
+
+ static void ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
+ {
+ var symbol_reader_provider = parameters.SymbolReaderProvider;
+
+ if (symbol_reader_provider == null && parameters.ReadSymbols)
+ symbol_reader_provider = SymbolProvider.GetPlatformReaderProvider();
+
+ if (symbol_reader_provider != null)
+ {
+ module.SymbolReaderProvider = symbol_reader_provider;
+
+ var reader = parameters.SymbolStream != null
+ ? symbol_reader_provider.GetSymbolReader(module, parameters.SymbolStream)
+ : symbol_reader_provider.GetSymbolReader(module, module.FullyQualifiedName);
+
+ module.ReadSymbols(reader);
+ }
+ }
+
+ static ModuleDefinition ReadModule(Image image, ReaderParameters parameters)
+ {
+ var reader = CreateModuleReader(image, parameters.ReadingMode);
+ reader.ReadModule();
+ return reader.module;
+ }
+
+ static ModuleReader CreateModuleReader(Image image, ReadingMode mode)
+ {
+ switch (mode)
+ {
+ case ReadingMode.Immediate:
+ return new ImmediateModuleReader(image);
+ case ReadingMode.Deferred:
+ return new DeferredModuleReader(image);
+ default:
+ throw new ArgumentException();
+ }
+ }
+ }
+
+ sealed class ImmediateModuleReader : ModuleReader
+ {
+
+ public ImmediateModuleReader(Image image)
+ : base(image, ReadingMode.Immediate)
+ {
+ }
+
+ protected override void ReadModule()
+ {
+ this.module.Read(this.module, (module, reader) =>
+ {
+ ReadModuleManifest(reader);
+ ReadModule(module);
+ return module;
+ });
+ }
+
+ public static void ReadModule(ModuleDefinition module)
+ {
+ if (module.HasAssemblyReferences)
+ Read(module.AssemblyReferences);
+ if (module.HasResources)
+ Read(module.Resources);
+ if (module.HasModuleReferences)
+ Read(module.ModuleReferences);
+ if (module.HasTypes)
+ ReadTypes(module.Types);
+ if (module.HasExportedTypes)
+ Read(module.ExportedTypes);
+ if (module.HasCustomAttributes)
+ Read(module.CustomAttributes);
+
+ var assembly = module.Assembly;
+ if (assembly == null)
+ return;
+
+ if (assembly.HasCustomAttributes)
+ Read(assembly.CustomAttributes);
+ if (assembly.HasSecurityDeclarations)
+ Read(assembly.SecurityDeclarations);
+ }
+
+ static void ReadTypes(Collection types)
+ {
+ for (int i = 0; i < types.Count; i++)
+ ReadType(types[i]);
+ }
+
+ static void ReadType(TypeDefinition type)
+ {
+ ReadGenericParameters(type);
+
+ if (type.HasInterfaces)
+ Read(type.Interfaces);
+
+ if (type.HasNestedTypes)
+ ReadTypes(type.NestedTypes);
+
+ if (type.HasLayoutInfo)
+ Read(type.ClassSize);
+
+ if (type.HasFields)
+ ReadFields(type);
+
+ if (type.HasMethods)
+ ReadMethods(type);
+
+ if (type.HasProperties)
+ ReadProperties(type);
+
+ if (type.HasEvents)
+ ReadEvents(type);
+
+ ReadSecurityDeclarations(type);
+ ReadCustomAttributes(type);
+ }
+
+ static void ReadGenericParameters(IGenericParameterProvider provider)
+ {
+ if (!provider.HasGenericParameters)
+ return;
+
+ var parameters = provider.GenericParameters;
+
+ for (int i = 0; i < parameters.Count; i++)
+ {
+ var parameter = parameters[i];
+
+ if (parameter.HasConstraints)
+ Read(parameter.Constraints);
+
+ if (parameter.HasCustomAttributes)
+ Read(parameter.CustomAttributes);
+ }
+ }
+
+ static void ReadSecurityDeclarations(ISecurityDeclarationProvider provider)
+ {
+ if (provider.HasSecurityDeclarations)
+ Read(provider.SecurityDeclarations);
+ }
+
+ static void ReadCustomAttributes(ICustomAttributeProvider provider)
+ {
+ if (provider.HasCustomAttributes)
+ Read(provider.CustomAttributes);
+ }
+
+ static void ReadFields(TypeDefinition type)
+ {
+ var fields = type.Fields;
+
+ for (int i = 0; i < fields.Count; i++)
+ {
+ var field = fields[i];
+
+ if (field.HasConstant)
+ Read(field.Constant);
+
+ if (field.HasLayoutInfo)
+ Read(field.Offset);
+
+ if (field.RVA > 0)
+ Read(field.InitialValue);
+
+ if (field.HasMarshalInfo)
+ Read(field.MarshalInfo);
+
+ ReadCustomAttributes(field);
+ }
+ }
+
+ static void ReadMethods(TypeDefinition type)
+ {
+ var methods = type.Methods;
+
+ for (int i = 0; i < methods.Count; i++)
+ {
+ var method = methods[i];
+
+ ReadGenericParameters(method);
+
+ if (method.HasParameters)
+ ReadParameters(method);
+
+ if (method.HasOverrides)
+ Read(method.Overrides);
+
+ if (method.IsPInvokeImpl)
+ Read(method.PInvokeInfo);
+
+ ReadSecurityDeclarations(method);
+ ReadCustomAttributes(method);
+
+ var return_type = method.MethodReturnType;
+ if (return_type.HasConstant)
+ Read(return_type.Constant);
+
+ if (return_type.HasMarshalInfo)
+ Read(return_type.MarshalInfo);
+
+ ReadCustomAttributes(return_type);
+ }
+ }
+
+ static void ReadParameters(MethodDefinition method)
+ {
+ var parameters = method.Parameters;
+
+ for (int i = 0; i < parameters.Count; i++)
+ {
+ var parameter = parameters[i];
+
+ if (parameter.HasConstant)
+ Read(parameter.Constant);
+
+ if (parameter.HasMarshalInfo)
+ Read(parameter.MarshalInfo);
+
+ ReadCustomAttributes(parameter);
+ }
+ }
+
+ static void ReadProperties(TypeDefinition type)
+ {
+ var properties = type.Properties;
+
+ for (int i = 0; i < properties.Count; i++)
+ {
+ var property = properties[i];
+
+ Read(property.GetMethod);
+
+ if (property.HasConstant)
+ Read(property.Constant);
+
+ ReadCustomAttributes(property);
+ }
+ }
+
+ static void ReadEvents(TypeDefinition type)
+ {
+ var events = type.Events;
+
+ for (int i = 0; i < events.Count; i++)
+ {
+ var @event = events[i];
+
+ Read(@event.AddMethod);
+
+ ReadCustomAttributes(@event);
+ }
+ }
+
+ static void Read(object collection)
+ {
+ }
+ }
+
+ sealed class DeferredModuleReader : ModuleReader
+ {
+
+ public DeferredModuleReader(Image image)
+ : base(image, ReadingMode.Deferred)
+ {
+ }
+
+ protected override void ReadModule()
+ {
+ this.module.Read(this.module, (module, reader) =>
+ {
+ ReadModuleManifest(reader);
+ return module;
+ });
+ }
+ }
+
+ sealed class MetadataReader : ByteBuffer
+ {
+
+ readonly internal Image image;
+ readonly internal ModuleDefinition module;
+ readonly internal MetadataSystem metadata;
+
+ internal IGenericContext context;
+ internal CodeReader code;
+
+ uint Position
+ {
+ get { return (uint)base.position; }
+ set { base.position = (int)value; }
+ }
+
+ public MetadataReader(ModuleDefinition module)
+ : base(module.Image.MetadataSection.Data)
+ {
+ this.image = module.Image;
+ this.module = module;
+ this.metadata = module.MetadataSystem;
+ this.code = new CodeReader(image.MetadataSection, this);
+ }
+
+ int GetCodedIndexSize(CodedIndex index)
+ {
+ return image.GetCodedIndexSize(index);
+ }
+
+ uint ReadByIndexSize(int size)
+ {
+ if (size == 4)
+ return ReadUInt32();
+ else
+ return ReadUInt16();
+ }
+
+ byte[] ReadBlob()
+ {
+ var blob_heap = image.BlobHeap;
+ if (blob_heap == null)
+ {
+ position += 2;
+ return Empty.Array;
+ }
+
+ return blob_heap.Read(ReadBlobIndex());
+ }
+
+ byte[] ReadBlob(uint signature)
+ {
+ var blob_heap = image.BlobHeap;
+ if (blob_heap == null)
+ return Empty.Array;
+
+ return blob_heap.Read(signature);
+ }
+
+ uint ReadBlobIndex()
+ {
+ var blob_heap = image.BlobHeap;
+ return ReadByIndexSize(blob_heap != null ? blob_heap.IndexSize : 2);
+ }
+
+ string ReadString()
+ {
+ return image.StringHeap.Read(ReadByIndexSize(image.StringHeap.IndexSize));
+ }
+
+ uint ReadStringIndex()
+ {
+ return ReadByIndexSize(image.StringHeap.IndexSize);
+ }
+
+ uint ReadTableIndex(Table table)
+ {
+ return ReadByIndexSize(image.GetTableIndexSize(table));
+ }
+
+ MetadataToken ReadMetadataToken(CodedIndex index)
+ {
+ return Mixin.GetMetadataToken(index, ReadByIndexSize(GetCodedIndexSize(index)));
+ }
+
+ int MoveTo(Table table)
+ {
+ var info = image.TableHeap[table];
+ if (info.Length != 0)
+ Position = info.Offset;
+
+ return (int)info.Length;
+ }
+
+ bool MoveTo(Table table, uint row)
+ {
+ var info = image.TableHeap[table];
+ var length = info.Length;
+ if (length == 0 || row > length)
+ return false;
+
+ Position = info.Offset + (info.RowSize * (row - 1));
+ return true;
+ }
+
+ public AssemblyNameDefinition ReadAssemblyNameDefinition()
+ {
+ if (MoveTo(Table.Assembly) == 0)
+ return null;
+
+ var name = new AssemblyNameDefinition();
+
+ name.HashAlgorithm = (AssemblyHashAlgorithm)ReadUInt32();
+
+ PopulateVersionAndFlags(name);
+
+ name.PublicKey = ReadBlob();
+
+ PopulateNameAndCulture(name);
+
+ return name;
+ }
+
+ public ModuleDefinition Populate(ModuleDefinition module)
+ {
+ if (MoveTo(Table.Module) == 0)
+ return module;
+
+ Advance(2); // Generation
+
+ module.Name = ReadString();
+ module.Mvid = image.GuidHeap.Read(ReadByIndexSize(image.GuidHeap.IndexSize));
+
+ return module;
+ }
+
+ void InitializeAssemblyReferences()
+ {
+ if (metadata.AssemblyReferences != null)
+ return;
+
+ int length = MoveTo(Table.AssemblyRef);
+ var references = metadata.AssemblyReferences = new AssemblyNameReference[length];
+
+ for (uint i = 0; i < length; i++)
+ {
+ var reference = new AssemblyNameReference();
+ reference.token = new MetadataToken(TokenType.AssemblyRef, i + 1);
+
+ PopulateVersionAndFlags(reference);
+
+ var key_or_token = ReadBlob();
+
+ if (reference.HasPublicKey)
+ reference.PublicKey = key_or_token;
+ else
+ reference.PublicKeyToken = key_or_token;
+
+ PopulateNameAndCulture(reference);
+
+ reference.Hash = ReadBlob();
+
+ references[i] = reference;
+ }
+ }
+
+ public Collection ReadAssemblyReferences()
+ {
+ InitializeAssemblyReferences();
+
+ return new Collection(metadata.AssemblyReferences);
+ }
+
+ public MethodDefinition ReadEntryPoint()
+ {
+ if (module.Image.EntryPointToken == 0)
+ return null;
+
+ var token = new MetadataToken(module.Image.EntryPointToken);
+ return GetMethodDefinition(token.RID);
+ }
+
+ public Collection ReadModules()
+ {
+ var modules = new Collection(1);
+ modules.Add(this.module);
+
+ int length = MoveTo(Table.File);
+ for (uint i = 1; i <= length; i++)
+ {
+ var attributes = (FileAttributes)ReadUInt32();
+ var name = ReadString();
+ ReadBlobIndex();
+
+ if (attributes != FileAttributes.ContainsMetaData)
+ continue;
+
+ var parameters = new ReaderParameters
+ {
+ ReadingMode = module.ReadingMode,
+ SymbolReaderProvider = module.SymbolReaderProvider,
+ };
+
+ modules.Add(ModuleDefinition.ReadModule(
+ GetModuleFileName(name), parameters));
+ }
+
+ return modules;
+ }
+
+ string GetModuleFileName(string name)
+ {
+ if (module.FullyQualifiedName == null)
+ throw new NotSupportedException();
+
+ var path = Path.GetDirectoryName(module.FullyQualifiedName);
+ return Path.Combine(path, name);
+ }
+
+ void InitializeModuleReferences()
+ {
+ if (metadata.ModuleReferences != null)
+ return;
+
+ int length = MoveTo(Table.ModuleRef);
+ var references = metadata.ModuleReferences = new ModuleReference[length];
+
+ for (uint i = 0; i < length; i++)
+ {
+ var reference = new ModuleReference(ReadString());
+ reference.token = new MetadataToken(TokenType.ModuleRef, i + 1);
+
+ references[i] = reference;
+ }
+ }
+
+ public Collection ReadModuleReferences()
+ {
+ InitializeModuleReferences();
+
+ return new Collection(metadata.ModuleReferences);
+ }
+
+ public bool HasFileResource()
+ {
+ int length = MoveTo(Table.File);
+ if (length == 0)
+ return false;
+
+ for (uint i = 1; i <= length; i++)
+ if (ReadFileRecord(i).Col1 == FileAttributes.ContainsNoMetaData)
+ return true;
+
+ return false;
+ }
+
+ public Collection ReadResources()
+ {
+ int length = MoveTo(Table.ManifestResource);
+ var resources = new Collection(length);
+
+ for (int i = 1; i <= length; i++)
+ {
+ var offset = ReadUInt32();
+ var flags = (ManifestResourceAttributes)ReadUInt32();
+ var name = ReadString();
+ var implementation = ReadMetadataToken(CodedIndex.Implementation);
+
+ Resource resource;
+
+ if (implementation.RID == 0)
+ {
+ resource = new EmbeddedResource(name, flags, offset, this);
+ }
+ else if (implementation.TokenType == TokenType.AssemblyRef)
+ {
+ resource = new AssemblyLinkedResource(name, flags)
+ {
+ Assembly = (AssemblyNameReference)GetTypeReferenceScope(implementation),
+ };
+ }
+ else if (implementation.TokenType == TokenType.File)
+ {
+ var file_record = ReadFileRecord(implementation.RID);
+
+ resource = new LinkedResource(name, flags)
+ {
+ File = file_record.Col2,
+ hash = ReadBlob(file_record.Col3)
+ };
+ }
+ else
+ throw new NotSupportedException();
+
+ resources.Add(resource);
+ }
+
+ return resources;
+ }
+
+ Row ReadFileRecord(uint rid)
+ {
+ var position = this.position;
+
+ if (!MoveTo(Table.File, rid))
+ throw new ArgumentException();
+
+ var record = new Row(
+ (FileAttributes)ReadUInt32(),
+ ReadString(),
+ ReadBlobIndex());
+
+ this.position = position;
+
+ return record;
+ }
+
+ public MemoryStream GetManagedResourceStream(uint offset)
+ {
+ var rva = image.Resources.VirtualAddress;
+ var section = image.GetSectionAtVirtualAddress(rva);
+ var position = (rva - section.VirtualAddress) + offset;
+ var buffer = section.Data;
+
+ var length = buffer[position]
+ | (buffer[position + 1] << 8)
+ | (buffer[position + 2] << 16)
+ | (buffer[position + 3] << 24);
+
+ return new MemoryStream(buffer, (int)position + 4, length);
+ }
+
+ void PopulateVersionAndFlags(AssemblyNameReference name)
+ {
+ name.Version = new Version(
+ ReadUInt16(),
+ ReadUInt16(),
+ ReadUInt16(),
+ ReadUInt16());
+
+ name.Attributes = (AssemblyAttributes)ReadUInt32();
+ }
+
+ void PopulateNameAndCulture(AssemblyNameReference name)
+ {
+ name.Name = ReadString();
+ name.Culture = ReadString();
+ }
+
+ public TypeDefinitionCollection ReadTypes()
+ {
+ InitializeTypeDefinitions();
+ var mtypes = metadata.Types;
+ var type_count = mtypes.Length - metadata.NestedTypes.Count;
+ var types = new TypeDefinitionCollection(module, type_count);
+
+ for (int i = 0; i < mtypes.Length; i++)
+ {
+ var type = mtypes[i];
+ if (IsNested(type.Attributes))
+ continue;
+
+ types.Add(type);
+ }
+
+ if (image.HasTable(Table.MethodPtr) || image.HasTable(Table.FieldPtr))
+ CompleteTypes();
+
+ return types;
+ }
+
+ void CompleteTypes()
+ {
+ var types = metadata.Types;
+
+ for (int i = 0; i < types.Length; i++)
+ {
+ var type = types[i];
+
+ InitializeCollection(type.Fields);
+ InitializeCollection(type.Methods);
+ }
+ }
+
+ void InitializeTypeDefinitions()
+ {
+ if (metadata.Types != null)
+ return;
+
+ InitializeNestedTypes();
+ InitializeFields();
+ InitializeMethods();
+
+ int length = MoveTo(Table.TypeDef);
+ var types = metadata.Types = new TypeDefinition[length];
+
+ for (uint i = 0; i < length; i++)
+ {
+ if (types[i] != null)
+ continue;
+
+ types[i] = ReadType(i + 1);
+ }
+ }
+
+ static bool IsNested(TypeAttributes attributes)
+ {
+ switch (attributes & TypeAttributes.VisibilityMask)
+ {
+ case TypeAttributes.NestedAssembly:
+ case TypeAttributes.NestedFamANDAssem:
+ case TypeAttributes.NestedFamily:
+ case TypeAttributes.NestedFamORAssem:
+ case TypeAttributes.NestedPrivate:
+ case TypeAttributes.NestedPublic:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public bool HasNestedTypes(TypeDefinition type)
+ {
+ uint[] mapping;
+ InitializeNestedTypes();
+
+ if (!metadata.TryGetNestedTypeMapping(type, out mapping))
+ return false;
+
+ return mapping.Length > 0;
+ }
+
+ public Collection ReadNestedTypes(TypeDefinition type)
+ {
+ InitializeNestedTypes();
+ uint[] mapping;
+ if (!metadata.TryGetNestedTypeMapping(type, out mapping))
+ return new MemberDefinitionCollection(type);
+
+ var nested_types = new MemberDefinitionCollection(type, mapping.Length);
+
+ for (int i = 0; i < mapping.Length; i++)
+ {
+ var nested_type = GetTypeDefinition(mapping[i]);
+
+ if (nested_type != null)
+ nested_types.Add(nested_type);
+ }
+
+ metadata.RemoveNestedTypeMapping(type);
+
+ return nested_types;
+ }
+
+ void InitializeNestedTypes()
+ {
+ if (metadata.NestedTypes != null)
+ return;
+
+ var length = MoveTo(Table.NestedClass);
+
+ metadata.NestedTypes = new Dictionary(length);
+ metadata.ReverseNestedTypes = new Dictionary(length);
+
+ if (length == 0)
+ return;
+
+ for (int i = 1; i <= length; i++)
+ {
+ var nested = ReadTableIndex(Table.TypeDef);
+ var declaring = ReadTableIndex(Table.TypeDef);
+
+ AddNestedMapping(declaring, nested);
+ }
+ }
+
+ void AddNestedMapping(uint declaring, uint nested)
+ {
+ metadata.SetNestedTypeMapping(declaring, AddMapping(metadata.NestedTypes, declaring, nested));
+ metadata.SetReverseNestedTypeMapping(nested, declaring);
+ }
+
+ static TValue[] AddMapping(Dictionary cache, TKey key, TValue value)
+ {
+ TValue[] mapped;
+ if (!cache.TryGetValue(key, out mapped))
+ {
+ mapped = new[] { value };
+ return mapped;
+ }
+
+ var new_mapped = new TValue[mapped.Length + 1];
+ Array.Copy(mapped, new_mapped, mapped.Length);
+ new_mapped[mapped.Length] = value;
+ return new_mapped;
+ }
+
+ TypeDefinition ReadType(uint rid)
+ {
+ if (!MoveTo(Table.TypeDef, rid))
+ return null;
+
+ var attributes = (TypeAttributes)ReadUInt32();
+ var name = ReadString();
+ var @namespace = ReadString();
+ var type = new TypeDefinition(@namespace, name, attributes);
+ type.token = new MetadataToken(TokenType.TypeDef, rid);
+ type.scope = module;
+ type.module = module;
+
+ metadata.AddTypeDefinition(type);
+
+ this.context = type;
+
+ type.BaseType = GetTypeDefOrRef(ReadMetadataToken(CodedIndex.TypeDefOrRef));
+
+ type.fields_range = ReadFieldsRange(rid);
+ type.methods_range = ReadMethodsRange(rid);
+
+ if (IsNested(attributes))
+ type.DeclaringType = GetNestedTypeDeclaringType(type);
+
+ return type;
+ }
+
+ TypeDefinition GetNestedTypeDeclaringType(TypeDefinition type)
+ {
+ uint declaring_rid;
+ if (!metadata.TryGetReverseNestedTypeMapping(type, out declaring_rid))
+ return null;
+
+ metadata.RemoveReverseNestedTypeMapping(type);
+ return GetTypeDefinition(declaring_rid);
+ }
+
+ Range ReadFieldsRange(uint type_index)
+ {
+ return ReadListRange(type_index, Table.TypeDef, Table.Field);
+ }
+
+ Range ReadMethodsRange(uint type_index)
+ {
+ return ReadListRange(type_index, Table.TypeDef, Table.Method);
+ }
+
+ Range ReadListRange(uint current_index, Table current, Table target)
+ {
+ var list = new Range();
+
+ list.Start = ReadTableIndex(target);
+
+ uint next_index;
+ var current_table = image.TableHeap[current];
+
+ if (current_index == current_table.Length)
+ next_index = image.TableHeap[target].Length + 1;
+ else
+ {
+ var position = Position;
+ Position += (uint)(current_table.RowSize - image.GetTableIndexSize(target));
+ next_index = ReadTableIndex(target);
+ Position = position;
+ }
+
+ list.Length = next_index - list.Start;
+
+ return list;
+ }
+
+ public Row ReadTypeLayout(TypeDefinition type)
+ {
+ InitializeTypeLayouts();
+ Row class_layout;
+ var rid = type.token.RID;
+ if (!metadata.ClassLayouts.TryGetValue(rid, out class_layout))
+ return new Row(Mixin.NoDataMarker, Mixin.NoDataMarker);
+
+ type.PackingSize = (short)class_layout.Col1;
+ type.ClassSize = (int)class_layout.Col2;
+
+ metadata.ClassLayouts.Remove(rid);
+
+ return new Row((short)class_layout.Col1, (int)class_layout.Col2);
+ }
+
+ void InitializeTypeLayouts()
+ {
+ if (metadata.ClassLayouts != null)
+ return;
+
+ int length = MoveTo(Table.ClassLayout);
+
+ var class_layouts = metadata.ClassLayouts = new Dictionary>(length);
+
+ for (uint i = 0; i < length; i++)
+ {
+ var packing_size = ReadUInt16();
+ var class_size = ReadUInt32();
+
+ var parent = ReadTableIndex(Table.TypeDef);
+
+ class_layouts.Add(parent, new Row(packing_size, class_size));
+ }
+ }
+
+ public TypeReference GetTypeDefOrRef(MetadataToken token)
+ {
+ return (TypeReference)LookupToken(token);
+ }
+
+ public TypeDefinition GetTypeDefinition(uint rid)
+ {
+ InitializeTypeDefinitions();
+
+ var type = metadata.GetTypeDefinition(rid);
+ if (type != null)
+ return type;
+
+ return ReadTypeDefinition(rid);
+ }
+
+ TypeDefinition ReadTypeDefinition(uint rid)
+ {
+ if (!MoveTo(Table.TypeDef, rid))
+ return null;
+
+ return ReadType(rid);
+ }
+
+ void InitializeTypeReferences()
+ {
+ if (metadata.TypeReferences != null)
+ return;
+
+ metadata.TypeReferences = new TypeReference[image.GetTableLength(Table.TypeRef)];
+ }
+
+ public TypeReference GetTypeReference(string scope, string full_name)
+ {
+ InitializeTypeReferences();
+
+ var length = metadata.TypeReferences.Length;
+
+ for (uint i = 1; i <= length; i++)
+ {
+ var type = GetTypeReference(i);
+
+ if (type.FullName != full_name)
+ continue;
+
+ if (string.IsNullOrEmpty(scope))
+ return type;
+
+ if (type.Scope.Name == scope)
+ return type;
+ }
+
+ return null;
+ }
+
+ TypeReference GetTypeReference(uint rid)
+ {
+ InitializeTypeReferences();
+
+ var type = metadata.GetTypeReference(rid);
+ if (type != null)
+ return type;
+
+ return ReadTypeReference(rid);
+ }
+
+ TypeReference ReadTypeReference(uint rid)
+ {
+ if (!MoveTo(Table.TypeRef, rid))
+ return null;
+
+ TypeReference declaring_type = null;
+ IMetadataScope scope;
+
+ var scope_token = ReadMetadataToken(CodedIndex.ResolutionScope);
+
+ var name = ReadString();
+ var @namespace = ReadString();
+
+ var type = new TypeReference(
+ @namespace,
+ name,
+ module,
+ null);
+
+ type.token = new MetadataToken(TokenType.TypeRef, rid);
+
+ metadata.AddTypeReference(type);
+
+ if (scope_token.TokenType == TokenType.TypeRef)
+ {
+ declaring_type = GetTypeDefOrRef(scope_token);
+
+ scope = declaring_type != null
+ ? declaring_type.Scope
+ : module;
+ }
+ else
+ scope = GetTypeReferenceScope(scope_token);
+
+ type.scope = scope;
+ type.DeclaringType = declaring_type;
+
+ MetadataSystem.TryProcessPrimitiveTypeReference(type);
+
+ return type;
+ }
+
+ IMetadataScope GetTypeReferenceScope(MetadataToken scope)
+ {
+ switch (scope.TokenType)
+ {
+ case TokenType.AssemblyRef:
+ InitializeAssemblyReferences();
+ return metadata.AssemblyReferences[(int)scope.RID - 1];
+ case TokenType.ModuleRef:
+ InitializeModuleReferences();
+ return metadata.ModuleReferences[(int)scope.RID - 1];
+ case TokenType.Module:
+ return module;
+ default:
+ throw new NotSupportedException();
+ }
+ }
+
+ public IEnumerable GetTypeReferences()
+ {
+ InitializeTypeReferences();
+
+ var length = image.GetTableLength(Table.TypeRef);
+
+ var type_references = new TypeReference[length];
+
+ for (uint i = 1; i <= length; i++)
+ type_references[i - 1] = GetTypeReference(i);
+
+ return type_references;
+ }
+
+ TypeReference GetTypeSpecification(uint rid)
+ {
+ if (!MoveTo(Table.TypeSpec, rid))
+ return null;
+
+ var reader = ReadSignature(ReadBlobIndex());
+ var type = reader.ReadTypeSignature();
+ if (type.token.RID == 0)
+ type.token = new MetadataToken(TokenType.TypeSpec, rid);
+
+ return type;
+ }
+
+ SignatureReader ReadSignature(uint signature)
+ {
+ return new SignatureReader(signature, this);
+ }
+
+ public bool HasInterfaces(TypeDefinition type)
+ {
+ InitializeInterfaces();
+ MetadataToken[] mapping;
+
+ return metadata.TryGetInterfaceMapping(type, out mapping);
+ }
+
+ public Collection ReadInterfaces(TypeDefinition type)
+ {
+ InitializeInterfaces();
+ MetadataToken[] mapping;
+
+ if (!metadata.TryGetInterfaceMapping(type, out mapping))
+ return new Collection();
+
+ var interfaces = new Collection(mapping.Length);
+
+ this.context = type;
+
+ for (int i = 0; i < mapping.Length; i++)
+ interfaces.Add(GetTypeDefOrRef(mapping[i]));
+
+ metadata.RemoveInterfaceMapping(type);
+
+ return interfaces;
+ }
+
+ void InitializeInterfaces()
+ {
+ if (metadata.Interfaces != null)
+ return;
+
+ int length = MoveTo(Table.InterfaceImpl);
+
+ metadata.Interfaces = new Dictionary(length);
+
+ for (int i = 0; i < length; i++)
+ {
+ var type = ReadTableIndex(Table.TypeDef);
+ var @interface = ReadMetadataToken(CodedIndex.TypeDefOrRef);
+
+ AddInterfaceMapping(type, @interface);
+ }
+ }
+
+ void AddInterfaceMapping(uint type, MetadataToken @interface)
+ {
+ metadata.SetInterfaceMapping(type, AddMapping(metadata.Interfaces, type, @interface));
+ }
+
+ public Collection ReadFields(TypeDefinition type)
+ {
+ var fields_range = type.fields_range;
+ if (fields_range.Length == 0)
+ return new MemberDefinitionCollection(type);
+
+ var fields = new MemberDefinitionCollection(type, (int)fields_range.Length);
+ this.context = type;
+
+ if (!MoveTo(Table.FieldPtr, fields_range.Start))
+ {
+ if (!MoveTo(Table.Field, fields_range.Start))
+ return fields;
+
+ for (uint i = 0; i < fields_range.Length; i++)
+ ReadField(fields_range.Start + i, fields);
+ }
+ else
+ ReadPointers(Table.FieldPtr, Table.Field, fields_range, fields, ReadField);
+
+ return fields;
+ }
+
+ void ReadField(uint field_rid, Collection fields)
+ {
+ var attributes = (FieldAttributes)ReadUInt16();
+ var name = ReadString();
+ var signature = ReadBlobIndex();
+
+ var field = new FieldDefinition(name, attributes, ReadFieldType(signature));
+ field.token = new MetadataToken(TokenType.Field, field_rid);
+ metadata.AddFieldDefinition(field);
+
+ if (IsDeleted(field))
+ return;
+
+ fields.Add(field);
+ }
+
+ void InitializeFields()
+ {
+ if (metadata.Fields != null)
+ return;
+
+ metadata.Fields = new FieldDefinition[image.GetTableLength(Table.Field)];
+ }
+
+ TypeReference ReadFieldType(uint signature)
+ {
+ var reader = ReadSignature(signature);
+
+ const byte field_sig = 0x6;
+
+ if (reader.ReadByte() != field_sig)
+ throw new NotSupportedException();
+
+ return reader.ReadTypeSignature();
+ }
+
+ public int ReadFieldRVA(FieldDefinition field)
+ {
+ InitializeFieldRVAs();
+ var rid = field.token.RID;
+
+ RVA rva;
+ if (!metadata.FieldRVAs.TryGetValue(rid, out rva))
+ return 0;
+
+ var size = GetFieldTypeSize(field.FieldType);
+
+ if (size == 0 || rva == 0)
+ return 0;
+
+ metadata.FieldRVAs.Remove(rid);
+
+ field.InitialValue = GetFieldInitializeValue(size, rva);
+
+ return (int)rva;
+ }
+
+ byte[] GetFieldInitializeValue(int size, RVA rva)
+ {
+ var section = image.GetSectionAtVirtualAddress(rva);
+ if (section == null)
+ return Empty.Array;
+
+ var value = new byte[size];
+ Buffer.BlockCopy(section.Data, (int)(rva - section.VirtualAddress), value, 0, size);
+ return value;
+ }
+
+ static int GetFieldTypeSize(TypeReference type)
+ {
+ int size = 0;
+
+ switch (type.etype)
+ {
+ case ElementType.Boolean:
+ case ElementType.U1:
+ case ElementType.I1:
+ size = 1;
+ break;
+ case ElementType.U2:
+ case ElementType.I2:
+ case ElementType.Char:
+ size = 2;
+ break;
+ case ElementType.U4:
+ case ElementType.I4:
+ case ElementType.R4:
+ size = 4;
+ break;
+ case ElementType.U8:
+ case ElementType.I8:
+ case ElementType.R8:
+ size = 8;
+ break;
+ case ElementType.Ptr:
+ case ElementType.FnPtr:
+ size = IntPtr.Size;
+ break;
+ case ElementType.CModOpt:
+ case ElementType.CModReqD:
+ return GetFieldTypeSize(((IModifierType)type).ElementType);
+ default:
+ var field_type = Mixin.CheckedResolve(type);
+ if (field_type.HasLayoutInfo)
+ size = field_type.ClassSize;
+
+ break;
+ }
+
+ return size;
+ }
+
+ void InitializeFieldRVAs()
+ {
+ if (metadata.FieldRVAs != null)
+ return;
+
+ int length = MoveTo(Table.FieldRVA);
+
+ var field_rvas = metadata.FieldRVAs = new Dictionary(length);
+
+ for (int i = 0; i < length; i++)
+ {
+ var rva = ReadUInt32();
+ var field = ReadTableIndex(Table.Field);
+
+ field_rvas.Add(field, rva);
+ }
+ }
+
+ public int ReadFieldLayout(FieldDefinition field)
+ {
+ InitializeFieldLayouts();
+ var rid = field.token.RID;
+ uint offset;
+ if (!metadata.FieldLayouts.TryGetValue(rid, out offset))
+ return Mixin.NoDataMarker;
+
+ metadata.FieldLayouts.Remove(rid);
+
+ return (int)offset;
+ }
+
+ void InitializeFieldLayouts()
+ {
+ if (metadata.FieldLayouts != null)
+ return;
+
+ int length = MoveTo(Table.FieldLayout);
+
+ var field_layouts = metadata.FieldLayouts = new Dictionary(length);
+
+ for (int i = 0; i < length; i++)
+ {
+ var offset = ReadUInt32();
+ var field = ReadTableIndex(Table.Field);
+
+ field_layouts.Add(field, offset);
+ }
+ }
+
+ public bool HasEvents(TypeDefinition type)
+ {
+ InitializeEvents();
+
+ Range range;
+ if (!metadata.TryGetEventsRange(type, out range))
+ return false;
+
+ return range.Length > 0;
+ }
+
+ public Collection ReadEvents(TypeDefinition type)
+ {
+ InitializeEvents();
+ Range range;
+
+ if (!metadata.TryGetEventsRange(type, out range))
+ return new MemberDefinitionCollection(type);
+
+ var events = new MemberDefinitionCollection(type, (int)range.Length);
+
+ metadata.RemoveEventsRange(type);
+
+ if (range.Length == 0)
+ return events;
+
+ this.context = type;
+
+ if (!MoveTo(Table.EventPtr, range.Start))
+ {
+ if (!MoveTo(Table.Event, range.Start))
+ return events;
+
+ for (uint i = 0; i < range.Length; i++)
+ ReadEvent(range.Start + i, events);
+ }
+ else
+ ReadPointers(Table.EventPtr, Table.Event, range, events, ReadEvent);
+
+ return events;
+ }
+
+ void ReadEvent(uint event_rid, Collection events)
+ {
+ var attributes = (EventAttributes)ReadUInt16();
+ var name = ReadString();
+ var event_type = GetTypeDefOrRef(ReadMetadataToken(CodedIndex.TypeDefOrRef));
+
+ var @event = new EventDefinition(name, attributes, event_type);
+ @event.token = new MetadataToken(TokenType.Event, event_rid);
+
+ if (IsDeleted(@event))
+ return;
+
+ events.Add(@event);
+ }
+
+ void InitializeEvents()
+ {
+ if (metadata.Events != null)
+ return;
+
+ int length = MoveTo(Table.EventMap);
+
+ metadata.Events = new Dictionary(length);
+
+ for (uint i = 1; i <= length; i++)
+ {
+ var type_rid = ReadTableIndex(Table.TypeDef);
+ Range events_range = ReadEventsRange(i);
+ metadata.AddEventsRange(type_rid, events_range);
+ }
+ }
+
+ Range ReadEventsRange(uint rid)
+ {
+ return ReadListRange(rid, Table.EventMap, Table.Event);
+ }
+
+ public bool HasProperties(TypeDefinition type)
+ {
+ InitializeProperties();
+
+ Range range;
+ if (!metadata.TryGetPropertiesRange(type, out range))
+ return false;
+
+ return range.Length > 0;
+ }
+
+ public Collection ReadProperties(TypeDefinition type)
+ {
+ InitializeProperties();
+
+ Range range;
+
+ if (!metadata.TryGetPropertiesRange(type, out range))
+ return new MemberDefinitionCollection(type);
+
+ metadata.RemovePropertiesRange(type);
+
+ var properties = new MemberDefinitionCollection(type, (int)range.Length);
+
+ if (range.Length == 0)
+ return properties;
+
+ this.context = type;
+
+ if (!MoveTo(Table.PropertyPtr, range.Start))
+ {
+ if (!MoveTo(Table.Property, range.Start))
+ return properties;
+ for (uint i = 0; i < range.Length; i++)
+ ReadProperty(range.Start + i, properties);
+ }
+ else
+ ReadPointers(Table.PropertyPtr, Table.Property, range, properties, ReadProperty);
+
+ return properties;
+ }
+
+ void ReadProperty(uint property_rid, Collection properties)
+ {
+ var attributes = (PropertyAttributes)ReadUInt16();
+ var name = ReadString();
+ var signature = ReadBlobIndex();
+
+ var reader = ReadSignature(signature);
+ const byte property_signature = 0x8;
+
+ var calling_convention = reader.ReadByte();
+
+ if ((calling_convention & property_signature) == 0)
+ throw new NotSupportedException();
+
+ var has_this = (calling_convention & 0x20) != 0;
+
+ reader.ReadCompressedUInt32(); // count
+
+ var property = new PropertyDefinition(name, attributes, reader.ReadTypeSignature());
+ property.HasThis = has_this;
+ property.token = new MetadataToken(TokenType.Property, property_rid);
+
+ if (IsDeleted(property))
+ return;
+
+ properties.Add(property);
+ }
+
+ void InitializeProperties()
+ {
+ if (metadata.Properties != null)
+ return;
+
+ int length = MoveTo(Table.PropertyMap);
+
+ metadata.Properties = new Dictionary(length);
+
+ for (uint i = 1; i <= length; i++)
+ {
+ var type_rid = ReadTableIndex(Table.TypeDef);
+ var properties_range = ReadPropertiesRange(i);
+ metadata.AddPropertiesRange(type_rid, properties_range);
+ }
+ }
+
+ Range ReadPropertiesRange(uint rid)
+ {
+ return ReadListRange(rid, Table.PropertyMap, Table.Property);
+ }
+
+ MethodSemanticsAttributes ReadMethodSemantics(MethodDefinition method)
+ {
+ InitializeMethodSemantics();
+ Row row;
+ if (!metadata.Semantics.TryGetValue(method.token.RID, out row))
+ return MethodSemanticsAttributes.None;
+
+ var type = method.DeclaringType;
+
+ switch (row.Col1)
+ {
+ case MethodSemanticsAttributes.AddOn:
+ GetEvent(type, row.Col2).add_method = method;
+ break;
+ case MethodSemanticsAttributes.Fire:
+ GetEvent(type, row.Col2).invoke_method = method;
+ break;
+ case MethodSemanticsAttributes.RemoveOn:
+ GetEvent(type, row.Col2).remove_method = method;
+ break;
+ case MethodSemanticsAttributes.Getter:
+ GetProperty(type, row.Col2).get_method = method;
+ break;
+ case MethodSemanticsAttributes.Setter:
+ GetProperty(type, row.Col2).set_method = method;
+ break;
+ case MethodSemanticsAttributes.Other:
+ switch (row.Col2.TokenType)
+ {
+ case TokenType.Event:
+ {
+ var @event = GetEvent(type, row.Col2);
+ if (@event.other_methods == null)
+ @event.other_methods = new Collection();
+
+ @event.other_methods.Add(method);
+ break;
+ }
+ case TokenType.Property:
+ {
+ var property = GetProperty(type, row.Col2);
+ if (property.other_methods == null)
+ property.other_methods = new Collection();
+
+ property.other_methods.Add(method);
+
+ break;
+ }
+ default:
+ throw new NotSupportedException();
+ }
+ break;
+ default:
+ throw new NotSupportedException();
+ }
+
+ metadata.Semantics.Remove(method.token.RID);
+
+ return row.Col1;
+ }
+
+ static EventDefinition GetEvent(TypeDefinition type, MetadataToken token)
+ {
+ if (token.TokenType != TokenType.Event)
+ throw new ArgumentException();
+
+ return GetMember(type.Events, token);
+ }
+
+ static PropertyDefinition GetProperty(TypeDefinition type, MetadataToken token)
+ {
+ if (token.TokenType != TokenType.Property)
+ throw new ArgumentException();
+
+ return GetMember(type.Properties, token);
+ }
+
+ static TMember GetMember(Collection members, MetadataToken token) where TMember : IMemberDefinition
+ {
+ for (int i = 0; i < members.Count; i++)
+ {
+ var member = members[i];
+ if (member.MetadataToken == token)
+ return member;
+ }
+
+ throw new ArgumentException();
+ }
+
+ void InitializeMethodSemantics()
+ {
+ if (metadata.Semantics != null)
+ return;
+
+ int length = MoveTo(Table.MethodSemantics);
+
+ var semantics = metadata.Semantics = new Dictionary>(0);
+
+ for (uint i = 0; i < length; i++)
+ {
+ var attributes = (MethodSemanticsAttributes)ReadUInt16();
+ var method_rid = ReadTableIndex(Table.Method);
+ var association = ReadMetadataToken(CodedIndex.HasSemantics);
+
+ semantics[method_rid] = new Row(attributes, association);
+ }
+ }
+
+ public PropertyDefinition ReadMethods(PropertyDefinition property)
+ {
+ ReadAllSemantics(property.DeclaringType);
+ return property;
+ }
+
+ public EventDefinition ReadMethods(EventDefinition @event)
+ {
+ ReadAllSemantics(@event.DeclaringType);
+ return @event;
+ }
+
+ public MethodSemanticsAttributes ReadAllSemantics(MethodDefinition method)
+ {
+ ReadAllSemantics(method.DeclaringType);
+
+ return method.SemanticsAttributes;
+ }
+
+ void ReadAllSemantics(TypeDefinition type)
+ {
+ var methods = type.Methods;
+ for (int i = 0; i < methods.Count; i++)
+ {
+ var method = methods[i];
+ if (method.sem_attrs_ready)
+ continue;
+
+ method.sem_attrs = ReadMethodSemantics(method);
+ method.sem_attrs_ready = true;
+ }
+ }
+
+ Range ReadParametersRange(uint method_rid)
+ {
+ return ReadListRange(method_rid, Table.Method, Table.Param);
+ }
+
+ public Collection ReadMethods(TypeDefinition type)
+ {
+ var methods_range = type.methods_range;
+ if (methods_range.Length == 0)
+ return new MemberDefinitionCollection(type);
+
+ var methods = new MemberDefinitionCollection(type, (int)methods_range.Length);
+ if (!MoveTo(Table.MethodPtr, methods_range.Start))
+ {
+ if (!MoveTo(Table.Method, methods_range.Start))
+ return methods;
+
+ for (uint i = 0; i < methods_range.Length; i++)
+ ReadMethod(methods_range.Start + i, methods);
+ }
+ else
+ ReadPointers(Table.MethodPtr, Table.Method, methods_range, methods, ReadMethod);
+
+ return methods;
+ }
+
+ void ReadPointers(Table ptr, Table table, Range range, Collection members, Action> reader)
+ where TMember : IMemberDefinition
+ {
+ for (uint i = 0; i < range.Length; i++)
+ {
+ MoveTo(ptr, range.Start + i);
+
+ var rid = ReadTableIndex(table);
+ MoveTo(table, rid);
+
+ reader(rid, members);
+ }
+ }
+
+ static bool IsDeleted(IMemberDefinition member)
+ {
+ return member.IsSpecialName && member.Name == "_Deleted";
+ }
+
+ void InitializeMethods()
+ {
+ if (metadata.Methods != null)
+ return;
+
+ metadata.Methods = new MethodDefinition[image.GetTableLength(Table.Method)];
+ }
+
+ void ReadMethod(uint method_rid, Collection methods)
+ {
+ var method = new MethodDefinition();
+ method.rva = ReadUInt32();
+ method.ImplAttributes = (MethodImplAttributes)ReadUInt16();
+ method.Attributes = (MethodAttributes)ReadUInt16();
+ method.Name = ReadString();
+ method.token = new MetadataToken(TokenType.Method, method_rid);
+
+ if (IsDeleted(method))
+ return;
+
+ methods.Add(method); // attach method
+
+ var signature = ReadBlobIndex();
+ var param_range = ReadParametersRange(method_rid);
+
+ this.context = method;
+
+ ReadMethodSignature(signature, method);
+ metadata.AddMethodDefinition(method);
+
+ if (param_range.Length == 0)
+ return;
+
+ var position = base.position;
+ ReadParameters(method, param_range);
+ base.position = position;
+ }
+
+ void ReadParameters(MethodDefinition method, Range param_range)
+ {
+ if (!MoveTo(Table.ParamPtr, param_range.Start))
+ {
+ if (!MoveTo(Table.Param, param_range.Start))
+ return;
+
+ for (uint i = 0; i < param_range.Length; i++)
+ ReadParameter(param_range.Start + i, method);
+ }
+ else
+ ReadParameterPointers(method, param_range);
+ }
+
+ void ReadParameterPointers(MethodDefinition method, Range range)
+ {
+ for (uint i = 0; i < range.Length; i++)
+ {
+ MoveTo(Table.ParamPtr, range.Start + i);
+
+ var rid = ReadTableIndex(Table.Param);
+
+ MoveTo(Table.Param, rid);
+
+ ReadParameter(rid, method);
+ }
+ }
+
+ void ReadParameter(uint param_rid, MethodDefinition method)
+ {
+ var attributes = (ParameterAttributes)ReadUInt16();
+ var sequence = ReadUInt16();
+ var name = ReadString();
+
+ var parameter = sequence == 0
+ ? method.MethodReturnType.Parameter
+ : method.Parameters[sequence - 1];
+
+ parameter.token = new MetadataToken(TokenType.Param, param_rid);
+ parameter.Name = name;
+ parameter.Attributes = attributes;
+ }
+
+ void ReadMethodSignature(uint signature, IMethodSignature method)
+ {
+ var reader = ReadSignature(signature);
+ reader.ReadMethodSignature(method);
+ }
+
+ public PInvokeInfo ReadPInvokeInfo(MethodDefinition method)
+ {
+ InitializePInvokes();
+ Row row;
+
+ var rid = method.token.RID;
+
+ if (!metadata.PInvokes.TryGetValue(rid, out row))
+ return null;
+
+ metadata.PInvokes.Remove(rid);
+
+ return new PInvokeInfo(
+ row.Col1,
+ image.StringHeap.Read(row.Col2),
+ module.ModuleReferences[(int)row.Col3 - 1]);
+ }
+
+ void InitializePInvokes()
+ {
+ if (metadata.PInvokes != null)
+ return;
+
+ int length = MoveTo(Table.ImplMap);
+
+ var pinvokes = metadata.PInvokes = new Dictionary>(length);
+
+ for (int i = 1; i <= length; i++)
+ {
+ var attributes = (PInvokeAttributes)ReadUInt16();
+ var method = ReadMetadataToken(CodedIndex.MemberForwarded);
+ var name = ReadStringIndex();
+ var scope = ReadTableIndex(Table.File);
+
+ if (method.TokenType != TokenType.Method)
+ continue;
+
+ pinvokes.Add(method.RID, new Row(attributes, name, scope));
+ }
+ }
+
+ public bool HasGenericParameters(IGenericParameterProvider provider)
+ {
+ InitializeGenericParameters();
+
+ Range range;
+ if (!metadata.TryGetGenericParameterRange(provider, out range))
+ return false;
+
+ return range.Length > 0;
+ }
+
+ public Collection ReadGenericParameters(IGenericParameterProvider provider)
+ {
+ InitializeGenericParameters();
+
+ Range range;
+ if (!metadata.TryGetGenericParameterRange(provider, out range)
+ || !MoveTo(Table.GenericParam, range.Start))
+ return new GenericParameterCollection(provider);
+
+ metadata.RemoveGenericParameterRange(provider);
+
+ var generic_parameters = new GenericParameterCollection(provider, (int)range.Length);
+
+ for (uint i = 0; i < range.Length; i++)
+ {
+ ReadUInt16(); // index
+ var flags = (GenericParameterAttributes)ReadUInt16();
+ ReadMetadataToken(CodedIndex.TypeOrMethodDef);
+ var name = ReadString();
+
+ var parameter = new GenericParameter(name, provider);
+ parameter.token = new MetadataToken(TokenType.GenericParam, range.Start + i);
+ parameter.Attributes = flags;
+
+ generic_parameters.Add(parameter);
+ }
+
+ return generic_parameters;
+ }
+
+ void InitializeGenericParameters()
+ {
+ if (metadata.GenericParameters != null)
+ return;
+
+ metadata.GenericParameters = InitializeRanges(
+ Table.GenericParam, () =>
+ {
+ Advance(4);
+ var next = ReadMetadataToken(CodedIndex.TypeOrMethodDef);
+ ReadStringIndex();
+ return next;
+ });
+ }
+
+ Dictionary InitializeRanges(Table table, Func get_next)
+ {
+ int length = MoveTo(table);
+ var ranges = new Dictionary(length);
+
+ if (length == 0)
+ return ranges;
+
+ MetadataToken owner = MetadataToken.Zero;
+ Range range = new Range(1, 0);
+
+ for (uint i = 1; i <= length; i++)
+ {
+ var next = get_next();
+
+ if (i == 1)
+ {
+ owner = next;
+ range.Length++;
+ }
+ else if (next != owner)
+ {
+ if (owner.RID != 0)
+ ranges.Add(owner, range);
+ range = new Range(i, 1);
+ owner = next;
+ }
+ else
+ range.Length++;
+ }
+
+ if (owner != MetadataToken.Zero && !ranges.ContainsKey(owner))
+ ranges.Add(owner, range);
+
+ return ranges;
+ }
+
+ public bool HasGenericConstraints(GenericParameter generic_parameter)
+ {
+ InitializeGenericConstraints();
+
+ MetadataToken[] mapping;
+ if (!metadata.TryGetGenericConstraintMapping(generic_parameter, out mapping))
+ return false;
+
+ return mapping.Length > 0;
+ }
+
+ public Collection ReadGenericConstraints(GenericParameter generic_parameter)
+ {
+ InitializeGenericConstraints();
+
+ MetadataToken[] mapping;
+ if (!metadata.TryGetGenericConstraintMapping(generic_parameter, out mapping))
+ return new Collection();
+
+ var constraints = new Collection(mapping.Length);
+
+ this.context = (IGenericContext)generic_parameter.Owner;
+
+ for (int i = 0; i < mapping.Length; i++)
+ constraints.Add(GetTypeDefOrRef(mapping[i]));
+
+ metadata.RemoveGenericConstraintMapping(generic_parameter);
+
+ return constraints;
+ }
+
+ void InitializeGenericConstraints()
+ {
+ if (metadata.GenericConstraints != null)
+ return;
+
+ var length = MoveTo(Table.GenericParamConstraint);
+
+ metadata.GenericConstraints = new Dictionary(length);
+
+ for (int i = 1; i <= length; i++)
+ AddGenericConstraintMapping(
+ ReadTableIndex(Table.GenericParam),
+ ReadMetadataToken(CodedIndex.TypeDefOrRef));
+ }
+
+ void AddGenericConstraintMapping(uint generic_parameter, MetadataToken constraint)
+ {
+ metadata.SetGenericConstraintMapping(
+ generic_parameter,
+ AddMapping(metadata.GenericConstraints, generic_parameter, constraint));
+ }
+
+ public bool HasOverrides(MethodDefinition method)
+ {
+ InitializeOverrides();
+ MetadataToken[] mapping;
+
+ if (!metadata.TryGetOverrideMapping(method, out mapping))
+ return false;
+
+ return mapping.Length > 0;
+ }
+
+ public Collection ReadOverrides(MethodDefinition method)
+ {
+ InitializeOverrides();
+
+ MetadataToken[] mapping;
+ if (!metadata.TryGetOverrideMapping(method, out mapping))
+ return new Collection();
+
+ var overrides = new Collection(mapping.Length);
+
+ this.context = method;
+
+ for (int i = 0; i < mapping.Length; i++)
+ overrides.Add((MethodReference)LookupToken(mapping[i]));
+
+ metadata.RemoveOverrideMapping(method);
+
+ return overrides;
+ }
+
+ void InitializeOverrides()
+ {
+ if (metadata.Overrides != null)
+ return;
+
+ var length = MoveTo(Table.MethodImpl);
+
+ metadata.Overrides = new Dictionary(length);
+
+ for (int i = 1; i <= length; i++)
+ {
+ ReadTableIndex(Table.TypeDef);
+
+ var method = ReadMetadataToken(CodedIndex.MethodDefOrRef);
+ if (method.TokenType != TokenType.Method)
+ throw new NotSupportedException();
+
+ var @override = ReadMetadataToken(CodedIndex.MethodDefOrRef);
+
+ AddOverrideMapping(method.RID, @override);
+ }
+ }
+
+ void AddOverrideMapping(uint method_rid, MetadataToken @override)
+ {
+ metadata.SetOverrideMapping(
+ method_rid,
+ AddMapping(metadata.Overrides, method_rid, @override));
+ }
+
+ public MethodBody ReadMethodBody(MethodDefinition method)
+ {
+ return code.ReadMethodBody(method);
+ }
+
+ public CallSite ReadCallSite(MetadataToken token)
+ {
+ if (!MoveTo(Table.StandAloneSig, token.RID))
+ return null;
+
+ var signature = ReadBlobIndex();
+
+ var call_site = new CallSite();
+
+ ReadMethodSignature(signature, call_site);
+
+ call_site.MetadataToken = token;
+
+ return call_site;
+ }
+
+ public VariableDefinitionCollection ReadVariables(MetadataToken local_var_token)
+ {
+ if (!MoveTo(Table.StandAloneSig, local_var_token.RID))
+ return null;
+
+ var reader = ReadSignature(ReadBlobIndex());
+ const byte local_sig = 0x7;
+
+ if (reader.ReadByte() != local_sig)
+ throw new NotSupportedException();
+
+ var count = reader.ReadCompressedUInt32();
+ if (count == 0)
+ return null;
+
+ var variables = new VariableDefinitionCollection((int)count);
+
+ for (int i = 0; i < count; i++)
+ variables.Add(new VariableDefinition(reader.ReadTypeSignature()));
+
+ return variables;
+ }
+
+ public IMetadataTokenProvider LookupToken(MetadataToken token)
+ {
+ var rid = token.RID;
+
+ if (rid == 0)
+ return null;
+
+ IMetadataTokenProvider element;
+ var position = this.position;
+ var context = this.context;
+
+ switch (token.TokenType)
+ {
+ case TokenType.TypeDef:
+ element = GetTypeDefinition(rid);
+ break;
+ case TokenType.TypeRef:
+ element = GetTypeReference(rid);
+ break;
+ case TokenType.TypeSpec:
+ element = GetTypeSpecification(rid);
+ break;
+ case TokenType.Field:
+ element = GetFieldDefinition(rid);
+ break;
+ case TokenType.Method:
+ element = GetMethodDefinition(rid);
+ break;
+ case TokenType.MemberRef:
+ element = GetMemberReference(rid);
+ break;
+ case TokenType.MethodSpec:
+ element = GetMethodSpecification(rid);
+ break;
+ default:
+ return null;
+ }
+
+ this.position = position;
+ this.context = context;
+
+ return element;
+ }
+
+ public FieldDefinition GetFieldDefinition(uint rid)
+ {
+ InitializeTypeDefinitions();
+
+ var field = metadata.GetFieldDefinition(rid);
+ if (field != null)
+ return field;
+
+ return LookupField(rid);
+ }
+
+ FieldDefinition LookupField(uint rid)
+ {
+ var type = metadata.GetFieldDeclaringType(rid);
+ if (type == null)
+ return null;
+
+ InitializeCollection(type.Fields);
+
+ return metadata.GetFieldDefinition(rid);
+ }
+
+ public MethodDefinition GetMethodDefinition(uint rid)
+ {
+ InitializeTypeDefinitions();
+
+ var method = metadata.GetMethodDefinition(rid);
+ if (method != null)
+ return method;
+
+ return LookupMethod(rid);
+ }
+
+ MethodDefinition LookupMethod(uint rid)
+ {
+ var type = metadata.GetMethodDeclaringType(rid);
+ if (type == null)
+ return null;
+
+ InitializeCollection(type.Methods);
+
+ return metadata.GetMethodDefinition(rid);
+ }
+
+ MethodSpecification GetMethodSpecification(uint rid)
+ {
+ if (!MoveTo(Table.MethodSpec, rid))
+ return null;
+
+ var element_method = (MethodReference)LookupToken(
+ ReadMetadataToken(CodedIndex.MethodDefOrRef));
+ var signature = ReadBlobIndex();
+
+ var method_spec = ReadMethodSpecSignature(signature, element_method);
+ method_spec.token = new MetadataToken(TokenType.MethodSpec, rid);
+ return method_spec;
+ }
+
+ MethodSpecification ReadMethodSpecSignature(uint signature, MethodReference method)
+ {
+ var reader = ReadSignature(signature);
+ const byte methodspec_sig = 0x0a;
+
+ var call_conv = reader.ReadByte();
+
+ if (call_conv != methodspec_sig)
+ throw new NotSupportedException();
+
+ var instance = new GenericInstanceMethod(method);
+
+ reader.ReadGenericInstanceSignature(method, instance);
+
+ return instance;
+ }
+
+ MemberReference GetMemberReference(uint rid)
+ {
+ InitializeMemberReferences();
+
+ var member = metadata.GetMemberReference(rid);
+ if (member != null)
+ return member;
+
+ member = ReadMemberReference(rid);
+ if (member != null && !member.ContainsGenericParameter)
+ metadata.AddMemberReference(member);
+ return member;
+ }
+
+ MemberReference ReadMemberReference(uint rid)
+ {
+ if (!MoveTo(Table.MemberRef, rid))
+ return null;
+
+ var token = ReadMetadataToken(CodedIndex.MemberRefParent);
+ var name = ReadString();
+ var signature = ReadBlobIndex();
+
+ MemberReference member;
+
+ switch (token.TokenType)
+ {
+ case TokenType.TypeDef:
+ case TokenType.TypeRef:
+ case TokenType.TypeSpec:
+ member = ReadTypeMemberReference(token, name, signature);
+ break;
+ case TokenType.Method:
+ member = ReadMethodMemberReference(token, name, signature);
+ break;
+ default:
+ throw new NotSupportedException();
+ }
+
+ member.token = new MetadataToken(TokenType.MemberRef, rid);
+
+ return member;
+ }
+
+ MemberReference ReadTypeMemberReference(MetadataToken type, string name, uint signature)
+ {
+ var declaring_type = GetTypeDefOrRef(type);
+
+ if (!declaring_type.IsArray)
+ this.context = declaring_type;
+
+ var member = ReadMemberReferenceSignature(signature, declaring_type);
+ member.Name = name;
+
+ return member;
+ }
+
+ MemberReference ReadMemberReferenceSignature(uint signature, TypeReference declaring_type)
+ {
+ var reader = ReadSignature(signature);
+ const byte field_sig = 0x6;
+
+ if (reader.buffer[reader.position] == field_sig)
+ {
+ reader.position++;
+ var field = new FieldReference();
+ field.DeclaringType = declaring_type;
+ field.FieldType = reader.ReadTypeSignature();
+ return field;
+ }
+ else
+ {
+ var method = new MethodReference();
+ method.DeclaringType = declaring_type;
+ reader.ReadMethodSignature(method);
+ return method;
+ }
+ }
+
+ MemberReference ReadMethodMemberReference(MetadataToken token, string name, uint signature)
+ {
+ var method = GetMethodDefinition(token.RID);
+
+ this.context = method;
+
+ var member = ReadMemberReferenceSignature(signature, method.DeclaringType);
+ member.Name = name;
+
+ return member;
+ }
+
+ void InitializeMemberReferences()
+ {
+ if (metadata.MemberReferences != null)
+ return;
+
+ metadata.MemberReferences = new MemberReference[image.GetTableLength(Table.MemberRef)];
+ }
+
+ public IEnumerable GetMemberReferences()
+ {
+ InitializeMemberReferences();
+
+ var length = image.GetTableLength(Table.MemberRef);
+
+ var type_system = module.TypeSystem;
+
+ var context = new MethodReference(string.Empty, type_system.Void);
+ context.DeclaringType = new TypeReference(string.Empty, string.Empty, module, type_system.Corlib);
+
+ var member_references = new MemberReference[length];
+
+ for (uint i = 1; i <= length; i++)
+ {
+ this.context = context;
+ member_references[i - 1] = GetMemberReference(i);
+ }
+
+ return member_references;
+ }
+
+ void InitializeConstants()
+ {
+ if (metadata.Constants != null)
+ return;
+
+ var length = MoveTo(Table.Constant);
+
+ var constants = metadata.Constants = new Dictionary>(length);
+
+ for (uint i = 1; i <= length; i++)
+ {
+ var type = (ElementType)ReadUInt16();
+ var owner = ReadMetadataToken(CodedIndex.HasConstant);
+ var signature = ReadBlobIndex();
+
+ constants.Add(owner, new Row(type, signature));
+ }
+ }
+
+ public object ReadConstant(IConstantProvider owner)
+ {
+ InitializeConstants();
+
+ Row row;
+ if (!metadata.Constants.TryGetValue(owner.MetadataToken, out row))
+ return Mixin.NoValue;
+
+ metadata.Constants.Remove(owner.MetadataToken);
+
+ switch (row.Col1)
+ {
+ case ElementType.Class:
+ case ElementType.Object:
+ return null;
+ case ElementType.String:
+ return ReadConstantString(ReadBlob(row.Col2));
+ default:
+ return ReadConstantPrimitive(row.Col1, row.Col2);
+ }
+ }
+
+ static string ReadConstantString(byte[] blob)
+ {
+ var length = blob.Length;
+ if ((length & 1) == 1)
+ length--;
+
+ return Encoding.Unicode.GetString(blob, 0, length);
+ }
+
+ object ReadConstantPrimitive(ElementType type, uint signature)
+ {
+ var reader = ReadSignature(signature);
+ return reader.ReadConstantSignature(type);
+ }
+
+ void InitializeCustomAttributes()
+ {
+ if (metadata.CustomAttributes != null)
+ return;
+
+ metadata.CustomAttributes = InitializeRanges(
+ Table.CustomAttribute, () =>
+ {
+ var next = ReadMetadataToken(CodedIndex.HasCustomAttribute);
+ ReadMetadataToken(CodedIndex.CustomAttributeType);
+ ReadBlobIndex();
+ return next;
+ });
+ }
+
+ public bool HasCustomAttributes(ICustomAttributeProvider owner)
+ {
+ InitializeCustomAttributes();
+
+ Range range;
+ if (!metadata.TryGetCustomAttributeRange(owner, out range))
+ return false;
+
+ return range.Length > 0;
+ }
+
+ public Collection ReadCustomAttributes(ICustomAttributeProvider owner)
+ {
+ InitializeCustomAttributes();
+
+ Range range;
+ if (!metadata.TryGetCustomAttributeRange(owner, out range)
+ || !MoveTo(Table.CustomAttribute, range.Start))
+ return new Collection();
+
+ var custom_attributes = new Collection((int)range.Length);
+
+ for (int i = 0; i < range.Length; i++)
+ {
+ ReadMetadataToken(CodedIndex.HasCustomAttribute);
+
+ var constructor = (MethodReference)LookupToken(
+ ReadMetadataToken(CodedIndex.CustomAttributeType));
+
+ var signature = ReadBlobIndex();
+
+ custom_attributes.Add(new CustomAttribute(signature, constructor));
+ }
+
+ metadata.RemoveCustomAttributeRange(owner);
+
+ return custom_attributes;
+ }
+
+ public byte[] ReadCustomAttributeBlob(uint signature)
+ {
+ return ReadBlob(signature);
+ }
+
+ public void ReadCustomAttributeSignature(CustomAttribute attribute)
+ {
+ var reader = ReadSignature(attribute.signature);
+
+ if (!reader.CanReadMore())
+ return;
+
+ if (reader.ReadUInt16() != 0x0001)
+ throw new InvalidOperationException();
+
+ var constructor = attribute.Constructor;
+ if (constructor.HasParameters)
+ reader.ReadCustomAttributeConstructorArguments(attribute, constructor.Parameters);
+
+ if (!reader.CanReadMore())
+ return;
+
+ var named = reader.ReadUInt16();
+
+ if (named == 0)
+ return;
+
+ reader.ReadCustomAttributeNamedArguments(named, ref attribute.fields, ref attribute.properties);
+ }
+
+ void InitializeMarshalInfos()
+ {
+ if (metadata.FieldMarshals != null)
+ return;
+
+ var length = MoveTo(Table.FieldMarshal);
+
+ var marshals = metadata.FieldMarshals = new Dictionary(length);
+
+ for (int i = 0; i < length; i++)
+ {
+ var token = ReadMetadataToken(CodedIndex.HasFieldMarshal);
+ var signature = ReadBlobIndex();
+ if (token.RID == 0)
+ continue;
+
+ marshals.Add(token, signature);
+ }
+ }
+
+ public bool HasMarshalInfo(IMarshalInfoProvider owner)
+ {
+ InitializeMarshalInfos();
+
+ return metadata.FieldMarshals.ContainsKey(owner.MetadataToken);
+ }
+
+ public MarshalInfo ReadMarshalInfo(IMarshalInfoProvider owner)
+ {
+ InitializeMarshalInfos();
+
+ uint signature;
+ if (!metadata.FieldMarshals.TryGetValue(owner.MetadataToken, out signature))
+ return null;
+
+ var reader = ReadSignature(signature);
+
+ metadata.FieldMarshals.Remove(owner.MetadataToken);
+
+ return reader.ReadMarshalInfo();
+ }
+
+ void InitializeSecurityDeclarations()
+ {
+ if (metadata.SecurityDeclarations != null)
+ return;
+
+ metadata.SecurityDeclarations = InitializeRanges(
+ Table.DeclSecurity, () =>
+ {
+ ReadUInt16();
+ var next = ReadMetadataToken(CodedIndex.HasDeclSecurity);
+ ReadBlobIndex();
+ return next;
+ });
+ }
+
+ public bool HasSecurityDeclarations(ISecurityDeclarationProvider owner)
+ {
+ InitializeSecurityDeclarations();
+
+ Range range;
+ if (!metadata.TryGetSecurityDeclarationRange(owner, out range))
+ return false;
+
+ return range.Length > 0;
+ }
+
+ public Collection ReadSecurityDeclarations(ISecurityDeclarationProvider owner)
+ {
+ InitializeSecurityDeclarations();
+
+ Range range;
+ if (!metadata.TryGetSecurityDeclarationRange(owner, out range)
+ || !MoveTo(Table.DeclSecurity, range.Start))
+ return new Collection();
+
+ var security_declarations = new Collection((int)range.Length);
+
+ for (int i = 0; i < range.Length; i++)
+ {
+ var action = (SecurityAction)ReadUInt16();
+ ReadMetadataToken(CodedIndex.HasDeclSecurity);
+ var signature = ReadBlobIndex();
+
+ security_declarations.Add(new SecurityDeclaration(action, signature, module));
+ }
+
+ metadata.RemoveSecurityDeclarationRange(owner);
+
+ return security_declarations;
+ }
+
+ public byte[] ReadSecurityDeclarationBlob(uint signature)
+ {
+ return ReadBlob(signature);
+ }
+
+ public void ReadSecurityDeclarationSignature(SecurityDeclaration declaration)
+ {
+ var signature = declaration.signature;
+ var reader = ReadSignature(signature);
+
+ if (reader.buffer[reader.position] != '.')
+ {
+ ReadXmlSecurityDeclaration(signature, declaration);
+ return;
+ }
+
+ reader.position++;
+ var count = reader.ReadCompressedUInt32();
+ var attributes = new Collection((int)count);
+
+ for (int i = 0; i < count; i++)
+ attributes.Add(reader.ReadSecurityAttribute());
+
+ declaration.security_attributes = attributes;
+ }
+
+ void ReadXmlSecurityDeclaration(uint signature, SecurityDeclaration declaration)
+ {
+ var blob = ReadBlob(signature);
+ var attributes = new Collection(1);
+
+ var attribute = new SecurityAttribute(
+ module.TypeSystem.LookupType("System.Security.Permissions", "PermissionSetAttribute"));
+
+ attribute.properties = new Collection(1);
+ attribute.properties.Add(
+ new CustomAttributeNamedArgument(
+ "XML",
+ new CustomAttributeArgument(
+ module.TypeSystem.String,
+ Encoding.Unicode.GetString(blob, 0, blob.Length))));
+
+ attributes.Add(attribute);
+
+ declaration.security_attributes = attributes;
+ }
+
+ public Collection ReadExportedTypes()
+ {
+ var length = MoveTo(Table.ExportedType);
+ if (length == 0)
+ return new Collection();
+
+ var exported_types = new Collection(length);
+
+ for (int i = 1; i <= length; i++)
+ {
+ var attributes = (TypeAttributes)ReadUInt32();
+ var identifier = ReadUInt32();
+ var name = ReadString();
+ var @namespace = ReadString();
+ var implementation = ReadMetadataToken(CodedIndex.Implementation);
+
+ ExportedType declaring_type = null;
+ IMetadataScope scope = null;
+
+ switch (implementation.TokenType)
+ {
+ case TokenType.AssemblyRef:
+ case TokenType.File:
+ scope = GetExportedTypeScope(implementation);
+ break;
+ case TokenType.ExportedType:
+ // FIXME: if the table is not properly sorted
+ declaring_type = exported_types[(int)implementation.RID - 1];
+ break;
+ }
+
+ var exported_type = new ExportedType(@namespace, name, module, scope)
+ {
+ Attributes = attributes,
+ Identifier = (int)identifier,
+ DeclaringType = declaring_type,
+ };
+ exported_type.token = new MetadataToken(TokenType.ExportedType, i);
+
+ exported_types.Add(exported_type);
+ }
+
+ return exported_types;
+ }
+
+ IMetadataScope GetExportedTypeScope(MetadataToken token)
+ {
+ var position = this.position;
+ IMetadataScope scope;
+
+ switch (token.TokenType)
+ {
+ case TokenType.AssemblyRef:
+ InitializeAssemblyReferences();
+ scope = metadata.AssemblyReferences[(int)token.RID - 1];
+ break;
+ case TokenType.File:
+ InitializeModuleReferences();
+ scope = GetModuleReferenceFromFile(token);
+ break;
+ default:
+ throw new NotSupportedException();
+ }
+
+ this.position = position;
+ return scope;
+ }
+
+ ModuleReference GetModuleReferenceFromFile(MetadataToken token)
+ {
+ if (!MoveTo(Table.File, token.RID))
+ return null;
+
+ ReadUInt32();
+ var file_name = ReadString();
+ var modules = module.ModuleReferences;
+
+ ModuleReference reference;
+ for (int i = 0; i < modules.Count; i++)
+ {
+ reference = modules[i];
+ if (reference.Name == file_name)
+ return reference;
+ }
+
+ reference = new ModuleReference(file_name);
+ modules.Add(reference);
+ return reference;
+ }
+
+ static void InitializeCollection(object o)
+ {
+ }
+ }
+
+ sealed class SignatureReader : ByteBuffer
+ {
+
+ readonly MetadataReader reader;
+ readonly uint start, sig_length;
+
+ TypeSystem TypeSystem
+ {
+ get { return reader.module.TypeSystem; }
+ }
+
+ public SignatureReader(uint blob, MetadataReader reader)
+ : base(reader.buffer)
+ {
+ this.reader = reader;
+
+ MoveToBlob(blob);
+
+ this.sig_length = ReadCompressedUInt32();
+ this.start = (uint)position;
+ }
+
+ void MoveToBlob(uint blob)
+ {
+ position = (int)(reader.image.BlobHeap.Offset + blob);
+ }
+
+ MetadataToken ReadTypeTokenSignature()
+ {
+ return Mixin.GetMetadataToken(CodedIndex.TypeDefOrRef, ReadCompressedUInt32());
+ }
+
+ GenericParameter GetGenericParameter(GenericParameterType type, uint var)
+ {
+ var context = reader.context;
+ int index = (int)var;
+
+ if (context == null)
+ return GetUnboundGenericParameter(type, index);
+
+ IGenericParameterProvider provider;
+
+ switch (type)
+ {
+ case GenericParameterType.Type:
+ provider = context.Type;
+ break;
+ case GenericParameterType.Method:
+ provider = context.Method;
+ break;
+ default:
+ throw new NotSupportedException();
+ }
+
+ if (!context.IsDefinition)
+ CheckGenericContext(provider, index);
+
+ if (index >= provider.GenericParameters.Count)
+ return GetUnboundGenericParameter(type, index);
+
+ return provider.GenericParameters[index];
+ }
+
+ GenericParameter GetUnboundGenericParameter(GenericParameterType type, int index)
+ {
+ return new GenericParameter(index, type, reader.module);
+ }
+
+ static void CheckGenericContext(IGenericParameterProvider owner, int index)
+ {
+ var owner_parameters = owner.GenericParameters;
+
+ for (int i = owner_parameters.Count; i <= index; i++)
+ owner_parameters.Add(new GenericParameter(owner));
+ }
+
+ public void ReadGenericInstanceSignature(IGenericParameterProvider provider, IGenericInstance instance)
+ {
+ var arity = ReadCompressedUInt32();
+
+ if (!provider.IsDefinition)
+ CheckGenericContext(provider, (int)arity - 1);
+
+ var instance_arguments = instance.GenericArguments;
+
+ for (int i = 0; i < arity; i++)
+ instance_arguments.Add(ReadTypeSignature());
+ }
+
+ ArrayType ReadArrayTypeSignature()
+ {
+ var array = new ArrayType(ReadTypeSignature());
+
+ var rank = ReadCompressedUInt32();
+
+ var sizes = new uint[ReadCompressedUInt32()];
+ for (int i = 0; i < sizes.Length; i++)
+ sizes[i] = ReadCompressedUInt32();
+
+ var low_bounds = new int[ReadCompressedUInt32()];
+ for (int i = 0; i < low_bounds.Length; i++)
+ low_bounds[i] = ReadCompressedInt32();
+
+ array.Dimensions.Clear();
+
+ for (int i = 0; i < rank; i++)
+ {
+ int? lower = null, upper = null;
+
+ if (i < low_bounds.Length)
+ lower = low_bounds[i];
+
+ if (i < sizes.Length)
+ upper = lower + (int)sizes[i] - 1;
+
+ array.Dimensions.Add(new ArrayDimension(lower, upper));
+ }
+
+ return array;
+ }
+
+ TypeReference GetTypeDefOrRef(MetadataToken token)
+ {
+ return reader.GetTypeDefOrRef(token);
+ }
+
+ public TypeReference ReadTypeSignature()
+ {
+ return ReadTypeSignature((ElementType)ReadByte());
+ }
+
+ TypeReference ReadTypeSignature(ElementType etype)
+ {
+ switch (etype)
+ {
+ case ElementType.ValueType:
+ {
+ var value_type = GetTypeDefOrRef(ReadTypeTokenSignature());
+ value_type.IsValueType = true;
+ return value_type;
+ }
+ case ElementType.Class:
+ return GetTypeDefOrRef(ReadTypeTokenSignature());
+ case ElementType.Ptr:
+ return new PointerType(ReadTypeSignature());
+ case ElementType.FnPtr:
+ {
+ var fptr = new FunctionPointerType();
+ ReadMethodSignature(fptr);
+ return fptr;
+ }
+ case ElementType.ByRef:
+ return new ByReferenceType(ReadTypeSignature());
+ case ElementType.Pinned:
+ return new PinnedType(ReadTypeSignature());
+ case ElementType.SzArray:
+ return new ArrayType(ReadTypeSignature());
+ case ElementType.Array:
+ return ReadArrayTypeSignature();
+ case ElementType.CModOpt:
+ return new OptionalModifierType(
+ GetTypeDefOrRef(ReadTypeTokenSignature()), ReadTypeSignature());
+ case ElementType.CModReqD:
+ return new RequiredModifierType(
+ GetTypeDefOrRef(ReadTypeTokenSignature()), ReadTypeSignature());
+ case ElementType.Sentinel:
+ return new SentinelType(ReadTypeSignature());
+ case ElementType.Var:
+ return GetGenericParameter(GenericParameterType.Type, ReadCompressedUInt32());
+ case ElementType.MVar:
+ return GetGenericParameter(GenericParameterType.Method, ReadCompressedUInt32());
+ case ElementType.GenericInst:
+ {
+ var is_value_type = ReadByte() == (byte)ElementType.ValueType;
+ var element_type = GetTypeDefOrRef(ReadTypeTokenSignature());
+ var generic_instance = new GenericInstanceType(element_type);
+
+ ReadGenericInstanceSignature(element_type, generic_instance);
+
+ if (is_value_type)
+ {
+ generic_instance.IsValueType = true;
+ element_type.GetElementType().IsValueType = true;
+ }
+
+ return generic_instance;
+ }
+ case ElementType.Object: return TypeSystem.Object;
+ case ElementType.Void: return TypeSystem.Void;
+ case ElementType.TypedByRef: return TypeSystem.TypedReference;
+ case ElementType.I: return TypeSystem.IntPtr;
+ case ElementType.U: return TypeSystem.UIntPtr;
+ default: return GetPrimitiveType(etype);
+ }
+ }
+
+ public void ReadMethodSignature(IMethodSignature method)
+ {
+ var calling_convention = ReadByte();
+
+ const byte has_this = 0x20;
+ const byte explicit_this = 0x40;
+
+ if ((calling_convention & has_this) != 0)
+ {
+ method.HasThis = true;
+ calling_convention = (byte)(calling_convention & ~has_this);
+ }
+
+ if ((calling_convention & explicit_this) != 0)
+ {
+ method.ExplicitThis = true;
+ calling_convention = (byte)(calling_convention & ~explicit_this);
+ }
+
+ method.CallingConvention = (MethodCallingConvention)calling_convention;
+
+ var generic_context = method as MethodReference;
+ if (generic_context != null && !generic_context.DeclaringType.IsArray)
+ reader.context = generic_context;
+
+ if ((calling_convention & 0x10) != 0)
+ {
+ var arity = ReadCompressedUInt32();
+
+ if (generic_context != null && !generic_context.IsDefinition)
+ CheckGenericContext(generic_context, (int)arity - 1);
+ }
+
+ var param_count = ReadCompressedUInt32();
+
+ method.MethodReturnType.ReturnType = ReadTypeSignature();
+
+ if (param_count == 0)
+ return;
+
+ Collection parameters;
+
+ var method_ref = method as MethodReference;
+ if (method_ref != null)
+ parameters = method_ref.parameters = new ParameterDefinitionCollection(method, (int)param_count);
+ else
+ parameters = method.Parameters;
+
+ for (int i = 0; i < param_count; i++)
+ parameters.Add(new ParameterDefinition(ReadTypeSignature()));
+ }
+
+ public object ReadConstantSignature(ElementType type)
+ {
+ return ReadPrimitiveValue(type);
+ }
+
+ public void ReadCustomAttributeConstructorArguments(CustomAttribute attribute, Collection parameters)
+ {
+ var count = parameters.Count;
+ if (count == 0)
+ return;
+
+ attribute.arguments = new Collection(count);
+
+ for (int i = 0; i < count; i++)
+ attribute.arguments.Add(
+ ReadCustomAttributeFixedArgument(parameters[i].ParameterType));
+ }
+
+ CustomAttributeArgument ReadCustomAttributeFixedArgument(TypeReference type)
+ {
+ if (type.IsArray)
+ return ReadCustomAttributeFixedArrayArgument((ArrayType)type);
+
+ return ReadCustomAttributeElement(type);
+ }
+
+ public void ReadCustomAttributeNamedArguments(ushort count, ref Collection fields, ref Collection properties)
+ {
+ for (int i = 0; i < count; i++)
+ ReadCustomAttributeNamedArgument(ref fields, ref properties);
+ }
+
+ void ReadCustomAttributeNamedArgument(ref Collection fields, ref Collection properties)
+ {
+ var kind = ReadByte();
+ var type = ReadCustomAttributeFieldOrPropType();
+ var name = ReadUTF8String();
+
+ Collection container;
+ switch (kind)
+ {
+ case 0x53:
+ container = GetCustomAttributeNamedArgumentCollection(ref fields);
+ break;
+ case 0x54:
+ container = GetCustomAttributeNamedArgumentCollection(ref properties);
+ break;
+ default:
+ throw new NotSupportedException();
+ }
+
+ container.Add(new CustomAttributeNamedArgument(name, ReadCustomAttributeFixedArgument(type)));
+ }
+
+ static Collection GetCustomAttributeNamedArgumentCollection(ref Collection collection)
+ {
+ if (collection != null)
+ return collection;
+
+ return collection = new Collection();
+ }
+
+ CustomAttributeArgument ReadCustomAttributeFixedArrayArgument(ArrayType type)
+ {
+ var length = ReadUInt32();
+
+ if (length == 0xffffffff)
+ return new CustomAttributeArgument(type, null);
+
+ if (length == 0)
+ return new CustomAttributeArgument(type, Empty.Array);
+
+ var arguments = new CustomAttributeArgument[length];
+ var element_type = type.ElementType;
+
+ for (int i = 0; i < length; i++)
+ arguments[i] = ReadCustomAttributeElement(element_type);
+
+ return new CustomAttributeArgument(type, arguments);
+ }
+
+ CustomAttributeArgument ReadCustomAttributeElement(TypeReference type)
+ {
+ if (type.IsArray)
+ return ReadCustomAttributeFixedArrayArgument((ArrayType)type);
+
+ return new CustomAttributeArgument(
+ type,
+ type.etype == ElementType.Object
+ ? ReadCustomAttributeElement(ReadCustomAttributeFieldOrPropType())
+ : ReadCustomAttributeElementValue(type));
+ }
+
+ object ReadCustomAttributeElementValue(TypeReference type)
+ {
+ var etype = type.etype;
+
+ switch (etype)
+ {
+ case ElementType.String:
+ return ReadUTF8String();
+ case ElementType.None:
+ if (Mixin.IsTypeOf(type,"System", "Type"))
+ return ReadTypeReference();
+
+ return ReadCustomAttributeEnum(type);
+ default:
+ return ReadPrimitiveValue(etype);
+ }
+ }
+
+ object ReadPrimitiveValue(ElementType type)
+ {
+ switch (type)
+ {
+ case ElementType.Boolean:
+ return ReadByte() == 1;
+ case ElementType.I1:
+ return (sbyte)ReadByte();
+ case ElementType.U1:
+ return ReadByte();
+ case ElementType.Char:
+ return (char)ReadUInt16();
+ case ElementType.I2:
+ return ReadInt16();
+ case ElementType.U2:
+ return ReadUInt16();
+ case ElementType.I4:
+ return ReadInt32();
+ case ElementType.U4:
+ return ReadUInt32();
+ case ElementType.I8:
+ return ReadInt64();
+ case ElementType.U8:
+ return ReadUInt64();
+ case ElementType.R4:
+ return ReadSingle();
+ case ElementType.R8:
+ return ReadDouble();
+ default:
+ throw new NotImplementedException(type.ToString());
+ }
+ }
+
+ TypeReference GetPrimitiveType(ElementType etype)
+ {
+ switch (etype)
+ {
+ case ElementType.Boolean:
+ return TypeSystem.Boolean;
+ case ElementType.Char:
+ return TypeSystem.Char;
+ case ElementType.I1:
+ return TypeSystem.SByte;
+ case ElementType.U1:
+ return TypeSystem.Byte;
+ case ElementType.I2:
+ return TypeSystem.Int16;
+ case ElementType.U2:
+ return TypeSystem.UInt16;
+ case ElementType.I4:
+ return TypeSystem.Int32;
+ case ElementType.U4:
+ return TypeSystem.UInt32;
+ case ElementType.I8:
+ return TypeSystem.Int64;
+ case ElementType.U8:
+ return TypeSystem.UInt64;
+ case ElementType.R4:
+ return TypeSystem.Single;
+ case ElementType.R8:
+ return TypeSystem.Double;
+ case ElementType.String:
+ return TypeSystem.String;
+ default:
+ throw new NotImplementedException(etype.ToString());
+ }
+ }
+
+ TypeReference ReadCustomAttributeFieldOrPropType()
+ {
+ var etype = (ElementType)ReadByte();
+
+ switch (etype)
+ {
+ case ElementType.Boxed:
+ return TypeSystem.Object;
+ case ElementType.SzArray:
+ return new ArrayType(ReadCustomAttributeFieldOrPropType());
+ case ElementType.Enum:
+ return ReadTypeReference();
+ case ElementType.Type:
+ return TypeSystem.LookupType("System", "Type");
+ default:
+ return GetPrimitiveType(etype);
+ }
+ }
+
+ public TypeReference ReadTypeReference()
+ {
+ return TypeParser.ParseType(reader.module, ReadUTF8String());
+ }
+
+ object ReadCustomAttributeEnum(TypeReference enum_type)
+ {
+ var type = Mixin.CheckedResolve(enum_type);
+ if (!type.IsEnum)
+ throw new ArgumentException();
+
+ return ReadCustomAttributeElementValue(Mixin.GetEnumUnderlyingType(type));
+ }
+
+ public SecurityAttribute ReadSecurityAttribute()
+ {
+ var attribute = new SecurityAttribute(ReadTypeReference());
+
+ ReadCompressedUInt32();
+
+ ReadCustomAttributeNamedArguments(
+ (ushort)ReadCompressedUInt32(),
+ ref attribute.fields,
+ ref attribute.properties);
+
+ return attribute;
+ }
+
+ public MarshalInfo ReadMarshalInfo()
+ {
+ var native = ReadNativeType();
+ switch (native)
+ {
+ case NativeType.Array:
+ {
+ var array = new ArrayMarshalInfo();
+ if (CanReadMore())
+ array.element_type = ReadNativeType();
+ if (CanReadMore())
+ array.size_parameter_index = (int)ReadCompressedUInt32();
+ if (CanReadMore())
+ array.size = (int)ReadCompressedUInt32();
+ if (CanReadMore())
+ array.size_parameter_multiplier = (int)ReadCompressedUInt32();
+ return array;
+ }
+ case NativeType.SafeArray:
+ {
+ var array = new SafeArrayMarshalInfo();
+ if (CanReadMore())
+ array.element_type = ReadVariantType();
+ return array;
+ }
+ case NativeType.FixedArray:
+ {
+ var array = new FixedArrayMarshalInfo();
+ if (CanReadMore())
+ array.size = (int)ReadCompressedUInt32();
+ if (CanReadMore())
+ array.element_type = ReadNativeType();
+ return array;
+ }
+ case NativeType.FixedSysString:
+ {
+ var sys_string = new FixedSysStringMarshalInfo();
+ if (CanReadMore())
+ sys_string.size = (int)ReadCompressedUInt32();
+ return sys_string;
+ }
+ case NativeType.CustomMarshaler:
+ {
+ var marshaler = new CustomMarshalInfo();
+ var guid_value = ReadUTF8String();
+ marshaler.guid = !string.IsNullOrEmpty(guid_value) ? new Guid(guid_value) : Guid.Empty;
+ marshaler.unmanaged_type = ReadUTF8String();
+ marshaler.managed_type = ReadTypeReference();
+ marshaler.cookie = ReadUTF8String();
+ return marshaler;
+ }
+ default:
+ return new MarshalInfo(native);
+ }
+ }
+
+ NativeType ReadNativeType()
+ {
+ return (NativeType)ReadByte();
+ }
+
+ VariantType ReadVariantType()
+ {
+ return (VariantType)ReadByte();
+ }
+
+ string ReadUTF8String()
+ {
+ if (buffer[position] == 0xff)
+ {
+ position++;
+ return null;
+ }
+
+ var length = (int)ReadCompressedUInt32();
+ if (length == 0)
+ return string.Empty;
+
+ var @string = Encoding.UTF8.GetString(buffer, position,
+ buffer[position + length - 1] == 0 ? length - 1 : length);
+
+ position += length;
+ return @string;
+ }
+
+ public bool CanReadMore()
+ {
+ return position - start < sig_length;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyWriter.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyWriter.cs
new file mode 100644
index 00000000..824dd349
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/AssemblyWriter.cs
@@ -0,0 +1,47 @@
+//
+// AssemblyWriter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Generic;
+using System.IO;
+using System.Text;
+
+using Mono.Collections.Generic;
+using Mono.Cecil.Cil;
+using Mono.Cecil.Metadata;
+using Mono.Cecil.PE;
+
+using RVA = System.UInt32;
+using RID = System.UInt32;
+using CodedRID = System.UInt32;
+using StringIndex = System.UInt32;
+using BlobIndex = System.UInt32;
+
+namespace Mono.Cecil {
+
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/BaseAssemblyResolver.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/BaseAssemblyResolver.cs
new file mode 100644
index 00000000..5ec6b600
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/BaseAssemblyResolver.cs
@@ -0,0 +1,172 @@
+//
+// BaseAssemblyResolver.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Generic;
+using System.IO;
+using System.Text;
+
+using Mono.Collections.Generic;
+
+namespace Mono.Cecil {
+
+ public delegate AssemblyDefinition AssemblyResolveEventHandler (object sender, AssemblyNameReference reference);
+
+ public sealed class AssemblyResolveEventArgs : EventArgs {
+
+ readonly AssemblyNameReference reference;
+
+ public AssemblyNameReference AssemblyReference {
+ get { return reference; }
+ }
+
+ public AssemblyResolveEventArgs (AssemblyNameReference reference)
+ {
+ this.reference = reference;
+ }
+ }
+
+
+ public class AssemblyResolutionException : FileNotFoundException {
+
+ readonly AssemblyNameReference reference;
+
+ public AssemblyNameReference AssemblyReference {
+ get { return reference; }
+ }
+
+ public AssemblyResolutionException (AssemblyNameReference reference)
+ : base (string.Format ("Failed to resolve assembly: '{0}'", reference))
+ {
+ this.reference = reference;
+ }
+
+
+ }
+
+ public abstract class BaseAssemblyResolver : IAssemblyResolver {
+
+ static readonly bool on_mono = Type.GetType ("Mono.Runtime") != null;
+
+ readonly Collection directories;
+
+
+
+ public void AddSearchDirectory (string directory)
+ {
+ directories.Add (directory);
+ }
+
+ public void RemoveSearchDirectory (string directory)
+ {
+ directories.Remove (directory);
+ }
+
+ public string [] GetSearchDirectories ()
+ {
+ var directories = new string [this.directories.size];
+ Array.Copy (this.directories.items, directories, directories.Length);
+ return directories;
+ }
+
+ public virtual AssemblyDefinition Resolve (string fullName)
+ {
+ return Resolve (fullName, new ReaderParameters ());
+ }
+
+ public virtual AssemblyDefinition Resolve (string fullName, ReaderParameters parameters)
+ {
+ if (fullName == null)
+ throw new ArgumentNullException ("fullName");
+
+ return Resolve (AssemblyNameReference.Parse (fullName), parameters);
+ }
+
+ public event AssemblyResolveEventHandler ResolveFailure;
+
+ protected BaseAssemblyResolver ()
+ {
+ directories = new Collection (2) { ".", "bin" };
+ }
+
+ AssemblyDefinition GetAssembly (string file, ReaderParameters parameters)
+ {
+ if (parameters.AssemblyResolver == null)
+ parameters.AssemblyResolver = this;
+
+ return ModuleDefinition.ReadModule (file, parameters).Assembly;
+ }
+
+ public virtual AssemblyDefinition Resolve (AssemblyNameReference name)
+ {
+ return Resolve (name, new ReaderParameters ());
+ }
+
+ public virtual AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters)
+ {
+ if (name == null)
+ throw new ArgumentNullException ("name");
+ if (parameters == null)
+ parameters = new ReaderParameters ();
+
+ var assembly = SearchDirectory (name, directories, parameters);
+ if (assembly != null)
+ return assembly;
+
+
+
+ if (ResolveFailure != null) {
+ assembly = ResolveFailure (this, name);
+ if (assembly != null)
+ return assembly;
+ }
+
+ throw new AssemblyResolutionException (name);
+ }
+
+ AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable directories, ReaderParameters parameters)
+ {
+ var extensions = new [] { ".exe", ".dll" };
+ foreach (var directory in directories) {
+ foreach (var extension in extensions) {
+ string file = Path.Combine (directory, name.Name + extension);
+ if (File.Exists (file))
+ return GetAssembly (file, parameters);
+ }
+ }
+
+ return null;
+ }
+
+ static bool IsZero (Version version)
+ {
+ return version == null || (version.Major == 0 && version.Minor == 0 && version.Build == 0 && version.Revision == 0);
+ }
+
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/CallSite.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/CallSite.cs
new file mode 100644
index 00000000..448ef2a5
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/CallSite.cs
@@ -0,0 +1,124 @@
+//
+// CallSite.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Text;
+
+using Mono.Collections.Generic;
+
+namespace Mono.Cecil {
+
+ public sealed class CallSite : IMethodSignature {
+
+ readonly MethodReference signature;
+
+ public bool HasThis {
+ get { return signature.HasThis; }
+ set { signature.HasThis = value; }
+ }
+
+ public bool ExplicitThis {
+ get { return signature.ExplicitThis; }
+ set { signature.ExplicitThis = value; }
+ }
+
+ public MethodCallingConvention CallingConvention {
+ get { return signature.CallingConvention; }
+ set { signature.CallingConvention = value; }
+ }
+
+ public bool HasParameters {
+ get { return signature.HasParameters; }
+ }
+
+ public Collection Parameters {
+ get { return signature.Parameters; }
+ }
+
+ public TypeReference ReturnType {
+ get { return signature.MethodReturnType.ReturnType; }
+ set { signature.MethodReturnType.ReturnType = value; }
+ }
+
+ public MethodReturnType MethodReturnType {
+ get { return signature.MethodReturnType; }
+ }
+
+ public string Name {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public string Namespace {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public ModuleDefinition Module {
+ get { return ReturnType.Module; }
+ }
+
+ public IMetadataScope Scope {
+ get { return signature.ReturnType.Scope; }
+ }
+
+ public MetadataToken MetadataToken {
+ get { return signature.token; }
+ set { signature.token = value; }
+ }
+
+ public string FullName {
+ get {
+ var signature = new StringBuilder ();
+ signature.Append (ReturnType.FullName);
+ Mixin.MethodSignatureFullName (this,signature);
+ return signature.ToString ();
+ }
+ }
+
+ internal CallSite ()
+ {
+ this.signature = new MethodReference ();
+ this.signature.token = new MetadataToken (TokenType.Signature, 0);
+ }
+
+ public CallSite (TypeReference returnType)
+ : this ()
+ {
+ if (returnType == null)
+ throw new ArgumentNullException ("returnType");
+
+ this.signature.ReturnType = returnType;
+ }
+
+ public override string ToString ()
+ {
+ return FullName;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/CustomAttribute.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/CustomAttribute.cs
new file mode 100644
index 00000000..26a1a1c8
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/CustomAttribute.cs
@@ -0,0 +1,231 @@
+//
+// CustomAttribute.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Collections.Generic;
+
+namespace Mono.Cecil {
+
+ public struct CustomAttributeArgument {
+
+ readonly TypeReference type;
+ readonly object value;
+
+ public TypeReference Type {
+ get { return type; }
+ }
+
+ public object Value {
+ get { return value; }
+ }
+
+ public CustomAttributeArgument (TypeReference type, object value)
+ {
+ Mixin.CheckType (type);
+ this.type = type;
+ this.value = value;
+ }
+ }
+
+ public struct CustomAttributeNamedArgument {
+
+ readonly string name;
+ readonly CustomAttributeArgument argument;
+
+ public string Name {
+ get { return name; }
+ }
+
+ public CustomAttributeArgument Argument {
+ get { return argument; }
+ }
+
+ public CustomAttributeNamedArgument (string name, CustomAttributeArgument argument)
+ {
+ Mixin.CheckName (name);
+ this.name = name;
+ this.argument = argument;
+ }
+ }
+
+ public interface ICustomAttribute {
+
+ TypeReference AttributeType { get; }
+
+ bool HasFields { get; }
+ bool HasProperties { get; }
+ Collection Fields { get; }
+ Collection Properties { get; }
+ }
+
+ public sealed class CustomAttribute : ICustomAttribute {
+
+ readonly internal uint signature;
+ internal bool resolved;
+ MethodReference constructor;
+ byte [] blob;
+ internal Collection arguments;
+ internal Collection fields;
+ internal Collection properties;
+
+ public MethodReference Constructor {
+ get { return constructor; }
+ set { constructor = value; }
+ }
+
+ public TypeReference AttributeType {
+ get { return constructor.DeclaringType; }
+ }
+
+ public bool IsResolved {
+ get { return resolved; }
+ }
+
+ public bool HasConstructorArguments {
+ get {
+ Resolve ();
+
+ return !Mixin.IsNullOrEmpty (arguments);
+ }
+ }
+
+ public Collection ConstructorArguments {
+ get {
+ Resolve ();
+
+ return arguments ?? (arguments = new Collection ());
+ }
+ }
+
+ public bool HasFields {
+ get {
+ Resolve ();
+
+ return !Mixin.IsNullOrEmpty (fields);
+ }
+ }
+
+ public Collection Fields {
+ get {
+ Resolve ();
+
+ return fields ?? (fields = new Collection ());
+ }
+ }
+
+ public bool HasProperties {
+ get {
+ Resolve ();
+
+ return !Mixin.IsNullOrEmpty (properties);
+ }
+ }
+
+ public Collection Properties {
+ get {
+ Resolve ();
+
+ return properties ?? (properties = new Collection ());
+ }
+ }
+
+ internal bool HasImage {
+ get { return constructor != null && constructor.HasImage; }
+ }
+
+ internal ModuleDefinition Module {
+ get { return constructor.Module; }
+ }
+
+ internal CustomAttribute (uint signature, MethodReference constructor)
+ {
+ this.signature = signature;
+ this.constructor = constructor;
+ this.resolved = false;
+ }
+
+ public CustomAttribute (MethodReference constructor)
+ {
+ this.constructor = constructor;
+ this.resolved = true;
+ }
+
+ public CustomAttribute (MethodReference constructor, byte [] blob)
+ {
+ this.constructor = constructor;
+ this.resolved = false;
+ this.blob = blob;
+ }
+
+ public byte [] GetBlob ()
+ {
+ if (blob != null)
+ return blob;
+
+ if (!HasImage)
+ throw new NotSupportedException ();
+
+ return Module.Read (ref blob, this, (attribute, reader) => reader.ReadCustomAttributeBlob (attribute.signature));
+ }
+
+ void Resolve ()
+ {
+ if (resolved || !HasImage)
+ return;
+
+ Module.Read (this, (attribute, reader) => {
+ try {
+ reader.ReadCustomAttributeSignature (attribute);
+ resolved = true;
+ } catch (ResolutionException) {
+ if (arguments != null)
+ arguments.Clear ();
+ if (fields != null)
+ fields.Clear ();
+ if (properties != null)
+ properties.Clear ();
+
+ resolved = false;
+ }
+ return this;
+ });
+ }
+ }
+
+ static partial class Mixin {
+
+ public static void CheckName (string name)
+ {
+ if (name == null)
+ throw new ArgumentNullException ("name");
+ if (name.Length == 0)
+ throw new ArgumentException ("Empty name");
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/DefaultAssemblyResolver.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/DefaultAssemblyResolver.cs
new file mode 100644
index 00000000..e0baedf7
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/DefaultAssemblyResolver.cs
@@ -0,0 +1,70 @@
+//
+// DefaultAssemblyResolver.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Generic;
+
+namespace Mono.Cecil {
+
+ public class DefaultAssemblyResolver : BaseAssemblyResolver {
+
+ readonly IDictionary cache;
+
+ public DefaultAssemblyResolver ()
+ {
+ cache = new Dictionary (StringComparer.Ordinal);
+ }
+
+ public override AssemblyDefinition Resolve (AssemblyNameReference name)
+ {
+ if (name == null)
+ throw new ArgumentNullException ("name");
+
+ AssemblyDefinition assembly;
+ if (cache.TryGetValue (name.FullName, out assembly))
+ return assembly;
+
+ assembly = base.Resolve (name);
+ cache [name.FullName] = assembly;
+
+ return assembly;
+ }
+
+ protected void RegisterAssembly (AssemblyDefinition assembly)
+ {
+ if (assembly == null)
+ throw new ArgumentNullException ("assembly");
+
+ var name = assembly.Name.FullName;
+ if (cache.ContainsKey (name))
+ return;
+
+ cache [name] = assembly;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/EmbeddedResource.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/EmbeddedResource.cs
new file mode 100644
index 00000000..e12dd0b3
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/EmbeddedResource.cs
@@ -0,0 +1,105 @@
+//
+// EmbeddedResource.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.IO;
+
+namespace Mono.Cecil {
+
+ public sealed class EmbeddedResource : Resource {
+
+ readonly MetadataReader reader;
+
+ uint? offset;
+ byte [] data;
+ Stream stream;
+
+ public override ResourceType ResourceType {
+ get { return ResourceType.Embedded; }
+ }
+
+ public EmbeddedResource (string name, ManifestResourceAttributes attributes, byte [] data) :
+ base (name, attributes)
+ {
+ this.data = data;
+ }
+
+ public EmbeddedResource (string name, ManifestResourceAttributes attributes, Stream stream) :
+ base (name, attributes)
+ {
+ this.stream = stream;
+ }
+
+ internal EmbeddedResource (string name, ManifestResourceAttributes attributes, uint offset, MetadataReader reader)
+ : base (name, attributes)
+ {
+ this.offset = offset;
+ this.reader = reader;
+ }
+
+ public Stream GetResourceStream ()
+ {
+ if (stream != null)
+ return stream;
+
+ if (data != null)
+ return new MemoryStream (data);
+
+ if (offset.HasValue)
+ return reader.GetManagedResourceStream (offset.Value);
+
+ throw new InvalidOperationException ();
+ }
+
+ public byte [] GetResourceData ()
+ {
+ if (stream != null)
+ return ReadStream (stream);
+
+ if (data != null)
+ return data;
+
+ if (offset.HasValue)
+ return reader.GetManagedResourceStream (offset.Value).ToArray ();
+
+ throw new InvalidOperationException ();
+ }
+
+ static byte [] ReadStream (Stream stream)
+ {
+ var length = (int) stream.Length;
+ var data = new byte [length];
+ int offset = 0, read;
+
+ while ((read = stream.Read (data, offset, length - offset)) > 0)
+ offset += read;
+
+ return data;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/EventAttributes.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/EventAttributes.cs
new file mode 100644
index 00000000..815efa57
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/EventAttributes.cs
@@ -0,0 +1,39 @@
+//
+// EventAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ [Flags]
+ public enum EventAttributes : ushort {
+ None = 0x0000,
+ SpecialName = 0x0200, // Event is special
+ RTSpecialName = 0x0400 // CLI provides 'special' behavior, depending upon the name of the event
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/EventDefinition.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/EventDefinition.cs
new file mode 100644
index 00000000..88bfa982
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/EventDefinition.cs
@@ -0,0 +1,170 @@
+//
+// EventDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Collections.Generic;
+
+namespace Mono.Cecil {
+
+ public sealed class EventDefinition : EventReference, IMemberDefinition {
+
+ ushort attributes;
+
+ Collection custom_attributes;
+
+ internal MethodDefinition add_method;
+ internal MethodDefinition invoke_method;
+ internal MethodDefinition remove_method;
+ internal Collection other_methods;
+
+ public EventAttributes Attributes {
+ get { return (EventAttributes) attributes; }
+ set { attributes = (ushort) value; }
+ }
+
+ public MethodDefinition AddMethod {
+ get {
+ if (add_method != null)
+ return add_method;
+
+ InitializeMethods ();
+ return add_method;
+ }
+ set { add_method = value; }
+ }
+
+ public MethodDefinition InvokeMethod {
+ get {
+ if (invoke_method != null)
+ return invoke_method;
+
+ InitializeMethods ();
+ return invoke_method;
+ }
+ set { invoke_method = value; }
+ }
+
+ public MethodDefinition RemoveMethod {
+ get {
+ if (remove_method != null)
+ return remove_method;
+
+ InitializeMethods ();
+ return remove_method;
+ }
+ set { remove_method = value; }
+ }
+
+ public bool HasOtherMethods {
+ get {
+ if (other_methods != null)
+ return other_methods.Count > 0;
+
+ InitializeMethods ();
+ return !Mixin.IsNullOrEmpty (other_methods);
+ }
+ }
+
+ public Collection OtherMethods {
+ get {
+ if (other_methods != null)
+ return other_methods;
+
+ InitializeMethods ();
+
+ if (other_methods != null)
+ return other_methods;
+
+ return other_methods = new Collection ();
+ }
+ }
+
+ public bool HasCustomAttributes {
+ get {
+ if (custom_attributes != null)
+ return custom_attributes.Count > 0;
+
+ return Mixin.GetHasCustomAttributes(this, Module);
+ }
+ }
+
+ public Collection CustomAttributes {
+ get { return custom_attributes ?? (Mixin.GetCustomAttributes(this, ref custom_attributes, Module)); }
+ }
+
+ #region EventAttributes
+
+ public bool IsSpecialName {
+ get { return Mixin.GetAttributes(attributes,(ushort) EventAttributes.SpecialName); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) EventAttributes.SpecialName, value); }
+ }
+
+ public bool IsRuntimeSpecialName {
+ get { return Mixin.GetAttributes(attributes,(ushort) FieldAttributes.RTSpecialName); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) FieldAttributes.RTSpecialName, value); }
+ }
+
+ #endregion
+
+ public new TypeDefinition DeclaringType {
+ get { return (TypeDefinition) base.DeclaringType; }
+ set { base.DeclaringType = value; }
+ }
+
+ public override bool IsDefinition {
+ get { return true; }
+ }
+
+ public EventDefinition (string name, EventAttributes attributes, TypeReference eventType)
+ : base (name, eventType)
+ {
+ this.attributes = (ushort) attributes;
+ this.token = new MetadataToken (TokenType.Event);
+ }
+
+ void InitializeMethods ()
+ {
+ var module = this.Module;
+ lock (module.SyncRoot) {
+ if (add_method != null
+ || invoke_method != null
+ || remove_method != null)
+ return;
+
+ if (!Mixin.HasImage(module))
+ return;
+
+ module.Read (this, (@event, reader) => reader.ReadMethods (@event));
+ }
+ }
+
+ public override EventDefinition Resolve ()
+ {
+ return this;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/EventReference.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/EventReference.cs
new file mode 100644
index 00000000..8952002d
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/EventReference.cs
@@ -0,0 +1,57 @@
+//
+// EventReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ public abstract class EventReference : MemberReference {
+
+ TypeReference event_type;
+
+ public TypeReference EventType {
+ get { return event_type; }
+ set { event_type = value; }
+ }
+
+ public override string FullName {
+ get { return event_type.FullName + " " + MemberFullName (); }
+ }
+
+ protected EventReference (string name, TypeReference eventType)
+ : base (name)
+ {
+ if (eventType == null)
+ throw new ArgumentNullException ("eventType");
+
+ event_type = eventType;
+ }
+
+ public abstract EventDefinition Resolve ();
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/ExportedType.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/ExportedType.cs
new file mode 100644
index 00000000..5cc7f2b0
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/ExportedType.cs
@@ -0,0 +1,249 @@
+//
+// ExportedType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ public class ExportedType : IMetadataTokenProvider {
+
+ string @namespace;
+ string name;
+ uint attributes;
+ IMetadataScope scope;
+ ModuleDefinition module;
+ int identifier;
+ ExportedType declaring_type;
+ internal MetadataToken token;
+
+ public string Namespace {
+ get { return @namespace; }
+ set { @namespace = value; }
+ }
+
+ public string Name {
+ get { return name; }
+ set { name = value; }
+ }
+
+ public TypeAttributes Attributes {
+ get { return (TypeAttributes) attributes; }
+ set { attributes = (uint) value; }
+ }
+
+ public IMetadataScope Scope {
+ get {
+ if (declaring_type != null)
+ return declaring_type.Scope;
+
+ return scope;
+ }
+ }
+
+ public ExportedType DeclaringType {
+ get { return declaring_type; }
+ set { declaring_type = value; }
+ }
+
+ public MetadataToken MetadataToken {
+ get { return token; }
+ set { token = value; }
+ }
+
+ public int Identifier {
+ get { return identifier; }
+ set { identifier = value; }
+ }
+
+ #region TypeAttributes
+
+ public bool IsNotPublic {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NotPublic); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NotPublic, value); }
+ }
+
+ public bool IsPublic {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.Public); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.Public, value); }
+ }
+
+ public bool IsNestedPublic {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPublic); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPublic, value); }
+ }
+
+ public bool IsNestedPrivate {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPrivate); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedPrivate, value); }
+ }
+
+ public bool IsNestedFamily {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamily); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamily, value); }
+ }
+
+ public bool IsNestedAssembly {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedAssembly); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedAssembly, value); }
+ }
+
+ public bool IsNestedFamilyAndAssembly {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamANDAssem); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamANDAssem, value); }
+ }
+
+ public bool IsNestedFamilyOrAssembly {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamORAssem); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.VisibilityMask, (uint) TypeAttributes.NestedFamORAssem, value); }
+ }
+
+ public bool IsAutoLayout {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.AutoLayout); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.AutoLayout, value); }
+ }
+
+ public bool IsSequentialLayout {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.SequentialLayout); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.SequentialLayout, value); }
+ }
+
+ public bool IsExplicitLayout {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.ExplicitLayout); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.LayoutMask, (uint) TypeAttributes.ExplicitLayout, value); }
+ }
+
+ public bool IsClass {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Class); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Class, value); }
+ }
+
+ public bool IsInterface {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Interface); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.ClassSemanticMask, (uint) TypeAttributes.Interface, value); }
+ }
+
+ public bool IsAbstract {
+ get { return Mixin.GetAttributes(attributes,(uint) TypeAttributes.Abstract); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint) TypeAttributes.Abstract, value); }
+ }
+
+ public bool IsSealed {
+ get { return Mixin.GetAttributes(attributes,(uint) TypeAttributes.Sealed); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint) TypeAttributes.Sealed, value); }
+ }
+
+ public bool IsSpecialName {
+ get { return Mixin.GetAttributes(attributes,(uint) TypeAttributes.SpecialName); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint) TypeAttributes.SpecialName, value); }
+ }
+
+ public bool IsImport {
+ get { return Mixin.GetAttributes(attributes,(uint) TypeAttributes.Import); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint) TypeAttributes.Import, value); }
+ }
+
+ public bool IsSerializable {
+ get { return Mixin.GetAttributes(attributes,(uint) TypeAttributes.Serializable); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint) TypeAttributes.Serializable, value); }
+ }
+
+ public bool IsAnsiClass {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AnsiClass); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AnsiClass, value); }
+ }
+
+ public bool IsUnicodeClass {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.UnicodeClass); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.UnicodeClass, value); }
+ }
+
+ public bool IsAutoClass {
+ get { return Mixin.GetMaskedAttributes(attributes,(uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AutoClass); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(uint) TypeAttributes.StringFormatMask, (uint) TypeAttributes.AutoClass, value); }
+ }
+
+ public bool IsBeforeFieldInit {
+ get { return Mixin.GetAttributes(attributes,(uint) TypeAttributes.BeforeFieldInit); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint) TypeAttributes.BeforeFieldInit, value); }
+ }
+
+ public bool IsRuntimeSpecialName {
+ get { return Mixin.GetAttributes(attributes,(uint) TypeAttributes.RTSpecialName); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint) TypeAttributes.RTSpecialName, value); }
+ }
+
+ public bool HasSecurity {
+ get { return Mixin.GetAttributes(attributes,(uint) TypeAttributes.HasSecurity); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint) TypeAttributes.HasSecurity, value); }
+ }
+
+ #endregion
+
+ public bool IsForwarder {
+ get { return Mixin.GetAttributes(attributes,(uint) TypeAttributes.Forwarder); }
+ set { attributes =Mixin.SetAttributes(attributes,(uint) TypeAttributes.Forwarder, value); }
+ }
+
+ public string FullName {
+ get {
+ if (declaring_type != null)
+ return declaring_type.FullName + "/" + name;
+
+ if (string.IsNullOrEmpty (@namespace))
+ return name;
+
+ return @namespace + "." + name;
+ }
+ }
+
+ public ExportedType (string @namespace, string name, ModuleDefinition module, IMetadataScope scope)
+ {
+ this.@namespace = @namespace;
+ this.name = name;
+ this.scope = scope;
+ this.module = module;
+ }
+
+ public override string ToString ()
+ {
+ return FullName;
+ }
+
+ public TypeDefinition Resolve ()
+ {
+ return module.Resolve (CreateReference ());
+ }
+
+ internal TypeReference CreateReference ()
+ {
+ return new TypeReference (@namespace, name, module, scope) {
+ DeclaringType = declaring_type != null ? declaring_type.CreateReference () : null,
+ };
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/FieldAttributes.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/FieldAttributes.cs
new file mode 100644
index 00000000..dd6bf361
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/FieldAttributes.cs
@@ -0,0 +1,59 @@
+//
+// FieldAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ [Flags]
+ public 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
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/FieldDefinition.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/FieldDefinition.cs
new file mode 100644
index 00000000..f90e8cb7
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/FieldDefinition.cs
@@ -0,0 +1,271 @@
+//
+// FieldDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Collections.Generic;
+
+namespace Mono.Cecil {
+
+ public sealed class FieldDefinition : FieldReference, IMemberDefinition, IConstantProvider, IMarshalInfoProvider {
+
+ ushort attributes;
+ Collection custom_attributes;
+
+ int offset = Mixin.NotResolvedMarker;
+
+ internal int rva = Mixin.NotResolvedMarker;
+ byte [] initial_value;
+
+ object constant = Mixin.NotResolved;
+
+ MarshalInfo marshal_info;
+
+ void ResolveLayout ()
+ {
+ if (offset != Mixin.NotResolvedMarker)
+ return;
+
+ if (!HasImage) {
+ offset = Mixin.NoDataMarker;
+ return;
+ }
+
+ offset = Module.Read (this, (field, reader) => reader.ReadFieldLayout (field));
+ }
+
+ public bool HasLayoutInfo {
+ get {
+ if (offset >= 0)
+ return true;
+
+ ResolveLayout ();
+
+ return offset >= 0;
+ }
+ }
+
+ public int Offset {
+ get {
+ if (offset >= 0)
+ return offset;
+
+ ResolveLayout ();
+
+ return offset >= 0 ? offset : -1;
+ }
+ set { offset = value; }
+ }
+
+ void ResolveRVA ()
+ {
+ if (rva != Mixin.NotResolvedMarker)
+ return;
+
+ if (!HasImage)
+ return;
+
+ rva = Module.Read (this, (field, reader) => reader.ReadFieldRVA (field));
+ }
+
+ public int RVA {
+ get {
+ if (rva > 0)
+ return rva;
+
+ ResolveRVA ();
+
+ return rva > 0 ? rva : 0;
+ }
+ }
+
+ public byte [] InitialValue {
+ get {
+ if (initial_value != null)
+ return initial_value;
+
+ ResolveRVA ();
+
+ if (initial_value == null)
+ initial_value = Empty.Array;
+
+ return initial_value;
+ }
+ set { initial_value = value; }
+ }
+
+ public FieldAttributes Attributes {
+ get { return (FieldAttributes) attributes; }
+ set { attributes = (ushort) value; }
+ }
+
+ public bool HasConstant {
+ get {
+ Mixin.ResolveConstant(this, ref constant, Module);
+
+ return constant != Mixin.NoValue;
+ }
+ set { if (!value) constant = Mixin.NoValue; }
+ }
+
+ public object Constant {
+ get { return HasConstant ? constant : null; }
+ set { constant = value; }
+ }
+
+ public bool HasCustomAttributes {
+ get {
+ if (custom_attributes != null)
+ return custom_attributes.Count > 0;
+
+ return Mixin.GetHasCustomAttributes(this, Module);
+ }
+ }
+
+ public Collection CustomAttributes {
+ get { return custom_attributes ?? (Mixin.GetCustomAttributes(this, ref custom_attributes, Module)); }
+ }
+
+ public bool HasMarshalInfo {
+ get {
+ if (marshal_info != null)
+ return true;
+
+ return Mixin.GetHasMarshalInfo(this, Module);
+ }
+ }
+
+ public MarshalInfo MarshalInfo {
+ get { return marshal_info ?? (Mixin.GetMarshalInfo(this, ref marshal_info, Module)); }
+ set { marshal_info = value; }
+ }
+
+ #region FieldAttributes
+
+ public bool IsCompilerControlled {
+ get { return Mixin.GetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.CompilerControlled); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.CompilerControlled, value); }
+ }
+
+ public bool IsPrivate {
+ get { return Mixin.GetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Private); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Private, value); }
+ }
+
+ public bool IsFamilyAndAssembly {
+ get { return Mixin.GetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.FamANDAssem); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.FamANDAssem, value); }
+ }
+
+ public bool IsAssembly {
+ get { return Mixin.GetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Assembly); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Assembly, value); }
+ }
+
+ public bool IsFamily {
+ get { return Mixin.GetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Family); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Family, value); }
+ }
+
+ public bool IsFamilyOrAssembly {
+ get { return Mixin.GetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.FamORAssem); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.FamORAssem, value); }
+ }
+
+ public bool IsPublic {
+ get { return Mixin.GetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Public); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(ushort) FieldAttributes.FieldAccessMask, (ushort) FieldAttributes.Public, value); }
+ }
+
+ public bool IsStatic {
+ get { return Mixin.GetAttributes(attributes,(ushort) FieldAttributes.Static); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) FieldAttributes.Static, value); }
+ }
+
+ public bool IsInitOnly {
+ get { return Mixin.GetAttributes(attributes,(ushort) FieldAttributes.InitOnly); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) FieldAttributes.InitOnly, value); }
+ }
+
+ public bool IsLiteral {
+ get { return Mixin.GetAttributes(attributes,(ushort) FieldAttributes.Literal); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) FieldAttributes.Literal, value); }
+ }
+
+ public bool IsNotSerialized {
+ get { return Mixin.GetAttributes(attributes,(ushort) FieldAttributes.NotSerialized); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) FieldAttributes.NotSerialized, value); }
+ }
+
+ public bool IsSpecialName {
+ get { return Mixin.GetAttributes(attributes,(ushort) FieldAttributes.SpecialName); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) FieldAttributes.SpecialName, value); }
+ }
+
+ public bool IsPInvokeImpl {
+ get { return Mixin.GetAttributes(attributes,(ushort) FieldAttributes.PInvokeImpl); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) FieldAttributes.PInvokeImpl, value); }
+ }
+
+ public bool IsRuntimeSpecialName {
+ get { return Mixin.GetAttributes(attributes,(ushort) FieldAttributes.RTSpecialName); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) FieldAttributes.RTSpecialName, value); }
+ }
+
+ public bool HasDefault {
+ get { return Mixin.GetAttributes(attributes,(ushort) FieldAttributes.HasDefault); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) FieldAttributes.HasDefault, value); }
+ }
+
+ #endregion
+
+ public override bool IsDefinition {
+ get { return true; }
+ }
+
+ public new TypeDefinition DeclaringType {
+ get { return (TypeDefinition) base.DeclaringType; }
+ set { base.DeclaringType = value; }
+ }
+
+ public FieldDefinition (string name, FieldAttributes attributes, TypeReference fieldType)
+ : base (name, fieldType)
+ {
+ this.attributes = (ushort) attributes;
+ }
+
+ public override FieldDefinition Resolve ()
+ {
+ return this;
+ }
+ }
+
+ static partial class Mixin {
+
+ public const int NotResolvedMarker = -2;
+ public const int NoDataMarker = -1;
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/FieldReference.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/FieldReference.cs
new file mode 100644
index 00000000..be58d3d0
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/FieldReference.cs
@@ -0,0 +1,83 @@
+//
+// FieldReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ public class FieldReference : MemberReference {
+
+ TypeReference field_type;
+
+ public TypeReference FieldType {
+ get { return field_type; }
+ set { field_type = value; }
+ }
+
+ public override string FullName {
+ get { return field_type.FullName + " " + MemberFullName (); }
+ }
+
+ internal override bool ContainsGenericParameter {
+ get { return field_type.ContainsGenericParameter || base.ContainsGenericParameter; }
+ }
+
+ internal FieldReference ()
+ {
+ this.token = new MetadataToken (TokenType.MemberRef);
+ }
+
+ public FieldReference (string name, TypeReference fieldType)
+ : base (name)
+ {
+ if (fieldType == null)
+ throw new ArgumentNullException ("fieldType");
+
+ this.field_type = fieldType;
+ this.token = new MetadataToken (TokenType.MemberRef);
+ }
+
+ public FieldReference (string name, TypeReference fieldType, TypeReference declaringType)
+ : this (name, fieldType)
+ {
+ if (declaringType == null)
+ throw new ArgumentNullException("declaringType");
+
+ this.DeclaringType = declaringType;
+ }
+
+ public virtual FieldDefinition Resolve ()
+ {
+ var module = this.Module;
+ if (module == null)
+ throw new NotSupportedException ();
+
+ return module.Resolve (this);
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/FileAttributes.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/FileAttributes.cs
new file mode 100644
index 00000000..4d3b6ca7
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/FileAttributes.cs
@@ -0,0 +1,35 @@
+//
+// FileAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ enum FileAttributes : uint {
+ ContainsMetaData = 0x0000, // This is not a resource file
+ ContainsNoMetaData = 0x0001, // This is a resource file or other non-metadata-containing file
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/FunctionPointerType.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/FunctionPointerType.cs
new file mode 100644
index 00000000..484afdaf
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/FunctionPointerType.cs
@@ -0,0 +1,128 @@
+//
+// FunctionPointerType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Text;
+using Mono.Collections.Generic;
+using MD = Mono.Cecil.Metadata;
+
+namespace Mono.Cecil {
+
+ public sealed class FunctionPointerType : TypeSpecification, IMethodSignature {
+
+ readonly MethodReference function;
+
+ public bool HasThis {
+ get { return function.HasThis; }
+ set { function.HasThis = value; }
+ }
+
+ public bool ExplicitThis {
+ get { return function.ExplicitThis; }
+ set { function.ExplicitThis = value; }
+ }
+
+ public MethodCallingConvention CallingConvention {
+ get { return function.CallingConvention; }
+ set { function.CallingConvention = value; }
+ }
+
+ public bool HasParameters {
+ get { return function.HasParameters; }
+ }
+
+ public Collection Parameters {
+ get { return function.Parameters; }
+ }
+
+ public TypeReference ReturnType {
+ get { return function.MethodReturnType.ReturnType; }
+ set { function.MethodReturnType.ReturnType = value; }
+ }
+
+ public MethodReturnType MethodReturnType {
+ get { return function.MethodReturnType; }
+ }
+
+ public override string Name {
+ get { return function.Name; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string Namespace {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override ModuleDefinition Module {
+ get { return ReturnType.Module; }
+ }
+
+ public override IMetadataScope Scope {
+ get { return function.ReturnType.Scope; }
+ }
+
+ public override bool IsFunctionPointer {
+ get { return true; }
+ }
+
+ internal override bool ContainsGenericParameter {
+ get { return function.ContainsGenericParameter; }
+ }
+
+ public override string FullName {
+ get {
+ var signature = new StringBuilder ();
+ signature.Append (function.Name);
+ signature.Append (" ");
+ signature.Append (function.ReturnType.FullName);
+ signature.Append (" *");
+ Mixin.MethodSignatureFullName (this,signature);
+ return signature.ToString ();
+ }
+ }
+
+ public FunctionPointerType ()
+ : base (null)
+ {
+ this.function = new MethodReference ();
+ this.function.Name = "method";
+ this.etype = MD.ElementType.FnPtr;
+ }
+
+ public override TypeDefinition Resolve ()
+ {
+ return null;
+ }
+
+ public override TypeReference GetElementType ()
+ {
+ return this;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericInstanceMethod.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericInstanceMethod.cs
new file mode 100644
index 00000000..12dcd21c
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericInstanceMethod.cs
@@ -0,0 +1,95 @@
+//
+// GenericInstanceMethod.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Text;
+
+using Mono.Collections.Generic;
+
+namespace Mono.Cecil
+{
+
+ public sealed class GenericInstanceMethod : MethodSpecification, IGenericInstance, IGenericContext
+ {
+
+ Collection arguments;
+
+ public bool HasGenericArguments
+ {
+ get { return !Mixin.IsNullOrEmpty(arguments); }
+ }
+
+ public Collection GenericArguments
+ {
+ get { return arguments ?? (arguments = new Collection()); }
+ }
+
+ public override bool IsGenericInstance
+ {
+ get { return true; }
+ }
+
+ IGenericParameterProvider IGenericContext.Method
+ {
+ get { return ElementMethod; }
+ }
+
+ IGenericParameterProvider IGenericContext.Type
+ {
+ get { return ElementMethod.DeclaringType; }
+ }
+
+ internal override bool ContainsGenericParameter
+ {
+ get { return Mixin.ContainsGenericParameter(this) || base.ContainsGenericParameter; }
+ }
+
+ public override string FullName
+ {
+ get
+ {
+ var signature = new StringBuilder();
+ var method = this.ElementMethod;
+ signature.Append(method.ReturnType.FullName)
+ .Append(" ")
+ .Append(method.DeclaringType.FullName)
+ .Append("::")
+ .Append(method.Name);
+ Mixin.GenericInstanceFullName(this, signature);
+ Mixin.MethodSignatureFullName(this, signature);
+ return signature.ToString();
+
+ }
+ }
+
+ public GenericInstanceMethod(MethodReference method)
+ : base(method)
+ {
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericInstanceType.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericInstanceType.cs
new file mode 100644
index 00000000..1e509d63
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericInstanceType.cs
@@ -0,0 +1,93 @@
+//
+// GenericInstanceType.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Text;
+
+using Mono.Collections.Generic;
+
+using MD = Mono.Cecil.Metadata;
+
+namespace Mono.Cecil
+{
+
+ public sealed class GenericInstanceType : TypeSpecification, IGenericInstance, IGenericContext
+ {
+
+ Collection arguments;
+
+ public bool HasGenericArguments
+ {
+ get { return !Mixin.IsNullOrEmpty(arguments); }
+ }
+
+ public Collection GenericArguments
+ {
+ get { return arguments ?? (arguments = new Collection()); }
+ }
+
+ public override TypeReference DeclaringType
+ {
+ get { return ElementType.DeclaringType; }
+ set { throw new NotSupportedException(); }
+ }
+
+ public override string FullName
+ {
+ get
+ {
+ var name = new StringBuilder();
+ name.Append(base.FullName);
+ Mixin.GenericInstanceFullName(this, name);
+ return name.ToString();
+ }
+ }
+
+ public override bool IsGenericInstance
+ {
+ get { return true; }
+ }
+
+ internal override bool ContainsGenericParameter
+ {
+ get { return Mixin.ContainsGenericParameter(this) || base.ContainsGenericParameter; }
+ }
+
+ IGenericParameterProvider IGenericContext.Type
+ {
+ get { return ElementType; }
+ }
+
+ public GenericInstanceType(TypeReference type)
+ : base(type)
+ {
+ base.IsValueType = type.IsValueType;
+ this.etype = MD.ElementType.GenericInst;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericParameter.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericParameter.cs
new file mode 100644
index 00000000..e92728d6
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericParameter.cs
@@ -0,0 +1,277 @@
+//
+// GenericParameter.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Collections.Generic;
+
+using Mono.Cecil.Metadata;
+
+namespace Mono.Cecil {
+
+ public sealed class GenericParameter : TypeReference, ICustomAttributeProvider {
+
+ internal int position;
+ internal GenericParameterType type;
+ internal IGenericParameterProvider owner;
+
+ ushort attributes;
+ Collection constraints;
+ Collection custom_attributes;
+
+ public GenericParameterAttributes Attributes {
+ get { return (GenericParameterAttributes) attributes; }
+ set { attributes = (ushort) value; }
+ }
+
+ public int Position {
+ get { return position; }
+ }
+
+ public GenericParameterType Type {
+ get { return type; }
+ }
+
+ public IGenericParameterProvider Owner {
+ get { return owner; }
+ }
+
+ public bool HasConstraints {
+ get {
+ if (constraints != null)
+ return constraints.Count > 0;
+
+ if (HasImage)
+ return Module.Read (this, (generic_parameter, reader) => reader.HasGenericConstraints (generic_parameter));
+
+ return false;
+ }
+ }
+
+ public Collection Constraints {
+ get {
+ if (constraints != null)
+ return constraints;
+
+ if (HasImage)
+ return Module.Read (ref constraints, this, (generic_parameter, reader) => reader.ReadGenericConstraints (generic_parameter));
+
+ return constraints = new Collection ();
+ }
+ }
+
+ public bool HasCustomAttributes {
+ get {
+ if (custom_attributes != null)
+ return custom_attributes.Count > 0;
+
+ return Mixin.GetHasCustomAttributes(this, Module);
+ }
+ }
+
+ public Collection CustomAttributes {
+ get { return custom_attributes ?? (Mixin.GetCustomAttributes(this, ref custom_attributes, Module)); }
+ }
+
+ public override IMetadataScope Scope {
+ get {
+ if (owner == null)
+ return null;
+
+ return owner.GenericParameterType == GenericParameterType.Method
+ ? ((MethodReference) owner).DeclaringType.Scope
+ : ((TypeReference) owner).Scope;
+ }
+ }
+
+ public override ModuleDefinition Module {
+ get { return module ?? owner.Module; }
+ }
+
+ public override string Name {
+ get {
+ if (!string.IsNullOrEmpty (base.Name))
+ return base.Name;
+
+ return base.Name = (type == GenericParameterType.Method ? "!!" : "!") + position;
+ }
+ }
+
+ public override string Namespace {
+ get { return string.Empty; }
+ set { throw new InvalidOperationException (); }
+ }
+
+ public override string FullName {
+ get { return Name; }
+ }
+
+ public override bool IsGenericParameter {
+ get { return true; }
+ }
+
+ internal override bool ContainsGenericParameter {
+ get { return true; }
+ }
+
+ public override MetadataType MetadataType {
+ get { return (MetadataType) etype; }
+ }
+
+ #region GenericParameterAttributes
+
+ public bool IsNonVariant {
+ get { return Mixin.GetMaskedAttributes(attributes,(ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.NonVariant); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.NonVariant, value); }
+ }
+
+ public bool IsCovariant {
+ get { return Mixin.GetMaskedAttributes(attributes,(ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.Covariant); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.Covariant, value); }
+ }
+
+ public bool IsContravariant {
+ get { return Mixin.GetMaskedAttributes(attributes,(ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.Contravariant); }
+ set { attributes = Mixin.SetMaskedAttributes(attributes,(ushort) GenericParameterAttributes.VarianceMask, (ushort) GenericParameterAttributes.Contravariant, value); }
+ }
+
+ public bool HasReferenceTypeConstraint {
+ get { return Mixin.GetAttributes(attributes,(ushort) GenericParameterAttributes.ReferenceTypeConstraint); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) GenericParameterAttributes.ReferenceTypeConstraint, value); }
+ }
+
+ public bool HasNotNullableValueTypeConstraint {
+ get { return Mixin.GetAttributes(attributes,(ushort) GenericParameterAttributes.NotNullableValueTypeConstraint); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) GenericParameterAttributes.NotNullableValueTypeConstraint, value); }
+ }
+
+ public bool HasDefaultConstructorConstraint {
+ get { return Mixin.GetAttributes(attributes,(ushort) GenericParameterAttributes.DefaultConstructorConstraint); }
+ set { attributes =Mixin.SetAttributes(attributes,(ushort) GenericParameterAttributes.DefaultConstructorConstraint, value); }
+ }
+
+ #endregion
+
+ public GenericParameter (IGenericParameterProvider owner)
+ : this (string.Empty, owner)
+ {
+ }
+
+ public GenericParameter (string name, IGenericParameterProvider owner)
+ : base (string.Empty, name)
+ {
+ if (owner == null)
+ throw new ArgumentNullException ();
+
+ this.position = -1;
+ this.owner = owner;
+ this.type = owner.GenericParameterType;
+ this.etype = ConvertGenericParameterType (this.type);
+ }
+
+ public GenericParameter (int position, GenericParameterType type, ModuleDefinition module)
+ : base (string.Empty, string.Empty)
+ {
+ if (module == null)
+ throw new ArgumentNullException ();
+
+ this.position = position;
+ this.type = type;
+ this.etype = ConvertGenericParameterType (type);
+ this.module = module;
+ }
+
+ static ElementType ConvertGenericParameterType (GenericParameterType type)
+ {
+ switch (type) {
+ case GenericParameterType.Type:
+ return ElementType.Var;
+ case GenericParameterType.Method:
+ return ElementType.MVar;
+ }
+
+ throw new ArgumentOutOfRangeException ();
+ }
+
+ public override TypeDefinition Resolve ()
+ {
+ return null;
+ }
+ }
+
+ sealed class GenericParameterCollection : Collection {
+
+ readonly IGenericParameterProvider owner;
+
+ internal GenericParameterCollection (IGenericParameterProvider owner)
+ {
+ this.owner = owner;
+ }
+
+ internal GenericParameterCollection (IGenericParameterProvider owner, int capacity)
+ : base (capacity)
+ {
+ this.owner = owner;
+ }
+
+ protected override void OnAdd (GenericParameter item, int index)
+ {
+ UpdateGenericParameter (item, index);
+ }
+
+ protected override void OnInsert (GenericParameter item, int index)
+ {
+ UpdateGenericParameter (item, index);
+
+ for (int i = index; i < size; i++)
+ items[i].position = i + 1;
+ }
+
+ protected override void OnSet (GenericParameter item, int index)
+ {
+ UpdateGenericParameter (item, index);
+ }
+
+ void UpdateGenericParameter (GenericParameter item, int index)
+ {
+ item.owner = owner;
+ item.position = index;
+ item.type = owner.GenericParameterType;
+ }
+
+ protected override void OnRemove (GenericParameter item, int index)
+ {
+ item.owner = null;
+ item.position = -1;
+ item.type = GenericParameterType.Type;
+
+ for (int i = index + 1; i < size; i++)
+ items[i].position = i - 1;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericParameterAttributes.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericParameterAttributes.cs
new file mode 100644
index 00000000..6d77956d
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/GenericParameterAttributes.cs
@@ -0,0 +1,45 @@
+//
+// GenericParameterAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ [Flags]
+ public enum GenericParameterAttributes : ushort {
+ VarianceMask = 0x0003,
+ NonVariant = 0x0000,
+ Covariant = 0x0001,
+ Contravariant = 0x0002,
+
+ SpecialConstraintMask = 0x001c,
+ ReferenceTypeConstraint = 0x0004,
+ NotNullableValueTypeConstraint = 0x0008,
+ DefaultConstructorConstraint = 0x0010
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/IConstantProvider.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IConstantProvider.cs
new file mode 100644
index 00000000..def7fb35
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IConstantProvider.cs
@@ -0,0 +1,57 @@
+//
+// IConstantProvider.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ public interface IConstantProvider : IMetadataTokenProvider {
+
+ bool HasConstant { get; set; }
+ object Constant { get; set; }
+ }
+
+ static partial class Mixin {
+
+ internal static object NoValue = new object ();
+ internal static object NotResolved = new object ();
+
+ public static void ResolveConstant (
+ IConstantProvider self,
+ ref object constant,
+ ModuleDefinition module)
+ {
+ lock (module.SyncRoot) {
+ if (constant != Mixin.NotResolved)
+ return;
+ if (Mixin.HasImage (module))
+ constant = module.Read (self, (provider, reader) => reader.ReadConstant (provider));
+ else
+ constant = Mixin.NoValue;
+ }
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/ICustomAttributeProvider.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/ICustomAttributeProvider.cs
new file mode 100644
index 00000000..89aa552c
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/ICustomAttributeProvider.cs
@@ -0,0 +1,63 @@
+//
+// ICustomAttributeProvider.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Collections.Generic;
+
+namespace Mono.Cecil
+{
+
+ public interface ICustomAttributeProvider : IMetadataTokenProvider
+ {
+
+ Collection CustomAttributes { get; }
+
+ bool HasCustomAttributes { get; }
+ }
+
+ static partial class Mixin
+ {
+
+ public static bool GetHasCustomAttributes(
+ ICustomAttributeProvider self,
+ ModuleDefinition module)
+ {
+ return Mixin.HasImage(module) && module.Read(self, (provider, reader) => reader.HasCustomAttributes(provider));
+ }
+
+ public static Collection GetCustomAttributes(
+ ICustomAttributeProvider self,
+ ref Collection variable,
+ ModuleDefinition module)
+ {
+ return Mixin.HasImage(module)
+ ? module.Read(ref variable, self, (provider, reader) => reader.ReadCustomAttributes(provider))
+ : variable = new Collection();
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/IGenericInstance.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IGenericInstance.cs
new file mode 100644
index 00000000..bc90c2bf
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IGenericInstance.cs
@@ -0,0 +1,66 @@
+//
+// IGenericInstance.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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;
+
+using Mono.Collections.Generic;
+
+namespace Mono.Cecil {
+
+ public interface IGenericInstance : IMetadataTokenProvider {
+
+ bool HasGenericArguments { get; }
+ Collection GenericArguments { get; }
+ }
+
+ static partial class Mixin {
+
+ public static bool ContainsGenericParameter (IGenericInstance self)
+ {
+ var arguments = self.GenericArguments;
+
+ for (int i = 0; i < arguments.Count; i++)
+ if (arguments [i].ContainsGenericParameter)
+ return true;
+
+ return false;
+ }
+
+ public static void GenericInstanceFullName (IGenericInstance self, StringBuilder builder)
+ {
+ builder.Append ("<");
+ var arguments = self.GenericArguments;
+ for (int i = 0; i < arguments.Count; i++) {
+ if (i > 0)
+ builder.Append (",");
+ builder.Append (arguments [i].FullName);
+ }
+ builder.Append (">");
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/IGenericParameterProvider.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IGenericParameterProvider.cs
new file mode 100644
index 00000000..8130174c
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IGenericParameterProvider.cs
@@ -0,0 +1,79 @@
+//
+// IGenericParameterProvider.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Collections.Generic;
+
+namespace Mono.Cecil
+{
+
+ public interface IGenericParameterProvider : IMetadataTokenProvider
+ {
+
+ bool HasGenericParameters { get; }
+ bool IsDefinition { get; }
+ ModuleDefinition Module { get; }
+ Collection GenericParameters { get; }
+ GenericParameterType GenericParameterType { get; }
+ }
+
+ public enum GenericParameterType
+ {
+ Type,
+ Method
+ }
+
+ interface IGenericContext
+ {
+
+ bool IsDefinition { get; }
+ IGenericParameterProvider Type { get; }
+ IGenericParameterProvider Method { get; }
+ }
+
+ static partial class Mixin
+ {
+
+ public static bool GetHasGenericParameters(
+ IGenericParameterProvider self,
+ ModuleDefinition module)
+ {
+ return Mixin.HasImage(module) && module.Read(self, (provider, reader) => reader.HasGenericParameters(provider));
+ }
+
+ public static Collection GetGenericParameters(
+ IGenericParameterProvider self,
+ ref Collection collection,
+ ModuleDefinition module)
+ {
+ return Mixin.HasImage(module)
+ ? module.Read(ref collection, self, (provider, reader) => reader.ReadGenericParameters(provider))
+ : collection = new GenericParameterCollection(self);
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMarshalInfoProvider.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMarshalInfoProvider.cs
new file mode 100644
index 00000000..369f76b2
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMarshalInfoProvider.cs
@@ -0,0 +1,59 @@
+//
+// IMarshalInfoProvider.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil
+{
+
+ public interface IMarshalInfoProvider : IMetadataTokenProvider
+ {
+
+ bool HasMarshalInfo { get; }
+ MarshalInfo MarshalInfo { get; set; }
+ }
+
+ static partial class Mixin
+ {
+
+ public static bool GetHasMarshalInfo(
+ IMarshalInfoProvider self,
+ ModuleDefinition module)
+ {
+ return Mixin.HasImage(module) && module.Read(self, (provider, reader) => reader.HasMarshalInfo(provider));
+ }
+
+ public static MarshalInfo GetMarshalInfo(
+ IMarshalInfoProvider self,
+ ref MarshalInfo variable,
+ ModuleDefinition module)
+ {
+ return Mixin.HasImage(module)
+ ? module.Read(ref variable, self, (provider, reader) => reader.ReadMarshalInfo(provider))
+ : null;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMemberDefinition.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMemberDefinition.cs
new file mode 100644
index 00000000..af243162
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMemberDefinition.cs
@@ -0,0 +1,105 @@
+//
+// IMemberDefinition.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil
+{
+
+ public interface IMemberDefinition : ICustomAttributeProvider
+ {
+
+ string Name { get; set; }
+ string FullName { get; }
+
+ bool IsSpecialName { get; set; }
+ bool IsRuntimeSpecialName { get; set; }
+
+ TypeDefinition DeclaringType { get; set; }
+ }
+
+ static partial class Mixin
+ {
+
+ public static bool GetAttributes(uint self, uint attributes)
+ {
+ return (self & attributes) != 0;
+ }
+
+ public static uint SetAttributes(uint self, uint attributes, bool value)
+ {
+ if (value)
+ return self | attributes;
+
+ return self & ~attributes;
+ }
+
+ public static bool GetMaskedAttributes(uint self, uint mask, uint attributes)
+ {
+ return (self & mask) == attributes;
+ }
+
+ public static uint SetMaskedAttributes(uint self, uint mask, uint attributes, bool value)
+ {
+ if (value)
+ {
+ self &= ~mask;
+ return self | attributes;
+ }
+
+ return self & ~(mask & attributes);
+ }
+
+ public static bool GetAttributes(ushort self, ushort attributes)
+ {
+ return (self & attributes) != 0;
+ }
+
+ public static ushort SetAttributes(ushort self, ushort attributes, bool value)
+ {
+ if (value)
+ return (ushort)(self | attributes);
+
+ return (ushort)(self & ~attributes);
+ }
+
+ public static bool GetMaskedAttributes(ushort self, ushort mask, uint attributes)
+ {
+ return (self & mask) == attributes;
+ }
+
+ public static ushort SetMaskedAttributes(ushort self, ushort mask, uint attributes, bool value)
+ {
+ if (value)
+ {
+ self = (ushort)(self & ~mask);
+ return (ushort)(self | attributes);
+ }
+
+ return (ushort)(self & ~(mask & attributes));
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMetadataScope.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMetadataScope.cs
new file mode 100644
index 00000000..04a02281
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMetadataScope.cs
@@ -0,0 +1,41 @@
+//
+// IMetadataScope.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ public enum MetadataScopeType {
+ AssemblyNameReference,
+ ModuleReference,
+ ModuleDefinition,
+ }
+
+ public interface IMetadataScope : IMetadataTokenProvider {
+ MetadataScopeType MetadataScopeType { get; }
+ string Name { get; set; }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMetadataTokenProvider.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMetadataTokenProvider.cs
new file mode 100644
index 00000000..6621835b
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMetadataTokenProvider.cs
@@ -0,0 +1,35 @@
+//
+// IMetadataTokenProvider.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ public interface IMetadataTokenProvider {
+
+ MetadataToken MetadataToken { get; set; }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMethodSignature.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMethodSignature.cs
new file mode 100644
index 00000000..74d285cf
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/IMethodSignature.cs
@@ -0,0 +1,75 @@
+//
+// IMethodSignature.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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;
+
+using Mono.Collections.Generic;
+
+namespace Mono.Cecil {
+
+ public interface IMethodSignature : IMetadataTokenProvider {
+
+ bool HasThis { get; set; }
+ bool ExplicitThis { get; set; }
+ MethodCallingConvention CallingConvention { get; set; }
+
+ bool HasParameters { get; }
+ Collection Parameters { get; }
+ TypeReference ReturnType { get; set; }
+ MethodReturnType MethodReturnType { get; }
+ }
+
+ static partial class Mixin {
+
+ public static bool HasImplicitThis (IMethodSignature self)
+ {
+ return self.HasThis && !self.ExplicitThis;
+ }
+
+ public static void MethodSignatureFullName (IMethodSignature self, StringBuilder builder)
+ {
+ builder.Append ("(");
+
+ if (self.HasParameters) {
+ var parameters = self.Parameters;
+ for (int i = 0; i < parameters.Count; i++) {
+ var parameter = parameters [i];
+ if (i > 0)
+ builder.Append (",");
+
+ if (parameter.ParameterType.IsSentinel)
+ builder.Append ("...,");
+
+ builder.Append (parameter.ParameterType.FullName);
+ }
+ }
+
+ builder.Append (")");
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/Import.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/Import.cs
new file mode 100644
index 00000000..c7b63464
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/Import.cs
@@ -0,0 +1,286 @@
+//
+// Import.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Generic;
+using SR = System.Reflection;
+
+using Mono.Cecil.Metadata;
+
+namespace Mono.Cecil
+{
+
+ enum ImportGenericKind
+ {
+ Definition,
+ Open,
+ }
+
+ class MetadataImporter
+ {
+
+ readonly ModuleDefinition module;
+
+ public MetadataImporter(ModuleDefinition module)
+ {
+ this.module = module;
+ }
+
+
+ public TypeReference ImportType(TypeReference type, IGenericContext context)
+ {
+ if (Mixin.IsTypeSpecification(type))
+ return ImportTypeSpecification(type, context);
+
+ var reference = new TypeReference(
+ type.Namespace,
+ type.Name,
+ module,
+ ImportScope(type.Scope),
+ type.IsValueType);
+
+ MetadataSystem.TryProcessPrimitiveTypeReference(reference);
+
+ if (type.IsNested)
+ reference.DeclaringType = ImportType(type.DeclaringType, context);
+
+ if (type.HasGenericParameters)
+ ImportGenericParameters(reference, type);
+
+ return reference;
+ }
+
+ IMetadataScope ImportScope(IMetadataScope scope)
+ {
+ switch (scope.MetadataScopeType)
+ {
+ case MetadataScopeType.AssemblyNameReference:
+ return ImportAssemblyName((AssemblyNameReference)scope);
+ case MetadataScopeType.ModuleDefinition:
+ return ImportAssemblyName(((ModuleDefinition)scope).Assembly.Name);
+ case MetadataScopeType.ModuleReference:
+ throw new NotImplementedException();
+ }
+
+ throw new NotSupportedException();
+ }
+
+ AssemblyNameReference ImportAssemblyName(AssemblyNameReference name)
+ {
+ AssemblyNameReference reference;
+ if (TryGetAssemblyNameReference(name, out reference))
+ return reference;
+
+ reference = new AssemblyNameReference(name.Name, name.Version)
+ {
+ Culture = name.Culture,
+ HashAlgorithm = name.HashAlgorithm,
+ };
+
+ var pk_token = !Mixin.IsNullOrEmpty(name.PublicKeyToken)
+ ? new byte[name.PublicKeyToken.Length]
+ : Empty.Array;
+
+ if (pk_token.Length > 0)
+ Buffer.BlockCopy(name.PublicKeyToken, 0, pk_token, 0, pk_token.Length);
+
+ reference.PublicKeyToken = pk_token;
+
+ module.AssemblyReferences.Add(reference);
+
+ return reference;
+ }
+
+ bool TryGetAssemblyNameReference(AssemblyNameReference name_reference, out AssemblyNameReference assembly_reference)
+ {
+ var references = module.AssemblyReferences;
+
+ for (int i = 0; i < references.Count; i++)
+ {
+ var reference = references[i];
+ if (name_reference.FullName != reference.FullName) // TODO compare field by field
+ continue;
+
+ assembly_reference = reference;
+ return true;
+ }
+
+ assembly_reference = null;
+ return false;
+ }
+
+ static void ImportGenericParameters(IGenericParameterProvider imported, IGenericParameterProvider original)
+ {
+ var parameters = original.GenericParameters;
+ var imported_parameters = imported.GenericParameters;
+
+ for (int i = 0; i < parameters.Count; i++)
+ imported_parameters.Add(new GenericParameter(parameters[i].Name, imported));
+ }
+
+ TypeReference ImportTypeSpecification(TypeReference type, IGenericContext context)
+ {
+ switch (type.etype)
+ {
+ case ElementType.SzArray:
+ var vector = (ArrayType)type;
+ return new ArrayType(ImportType(vector.ElementType, context));
+ case ElementType.Ptr:
+ var pointer = (PointerType)type;
+ return new PointerType(ImportType(pointer.ElementType, context));
+ case ElementType.ByRef:
+ var byref = (ByReferenceType)type;
+ return new ByReferenceType(ImportType(byref.ElementType, context));
+ case ElementType.Pinned:
+ var pinned = (PinnedType)type;
+ return new PinnedType(ImportType(pinned.ElementType, context));
+ case ElementType.Sentinel:
+ var sentinel = (SentinelType)type;
+ return new SentinelType(ImportType(sentinel.ElementType, context));
+ case ElementType.CModOpt:
+ var modopt = (OptionalModifierType)type;
+ return new OptionalModifierType(
+ ImportType(modopt.ModifierType, context),
+ ImportType(modopt.ElementType, context));
+ case ElementType.CModReqD:
+ var modreq = (RequiredModifierType)type;
+ return new RequiredModifierType(
+ ImportType(modreq.ModifierType, context),
+ ImportType(modreq.ElementType, context));
+ case ElementType.Array:
+ var array = (ArrayType)type;
+ var imported_array = new ArrayType(ImportType(array.ElementType, context));
+ if (array.IsVector)
+ return imported_array;
+
+ var dimensions = array.Dimensions;
+ var imported_dimensions = imported_array.Dimensions;
+
+ imported_dimensions.Clear();
+
+ for (int i = 0; i < dimensions.Count; i++)
+ {
+ var dimension = dimensions[i];
+
+ imported_dimensions.Add(new ArrayDimension(dimension.LowerBound, dimension.UpperBound));
+ }
+
+ return imported_array;
+ case ElementType.GenericInst:
+ var instance = (GenericInstanceType)type;
+ var element_type = ImportType(instance.ElementType, context);
+ var imported_instance = new GenericInstanceType(element_type);
+
+ var arguments = instance.GenericArguments;
+ var imported_arguments = imported_instance.GenericArguments;
+
+ for (int i = 0; i < arguments.Count; i++)
+ imported_arguments.Add(ImportType(arguments[i], context));
+
+ return imported_instance;
+ case ElementType.Var:
+ if (context == null || context.Type == null)
+ throw new InvalidOperationException();
+
+ return ((TypeReference)context.Type).GetElementType().GenericParameters[((GenericParameter)type).Position];
+ case ElementType.MVar:
+ if (context == null || context.Method == null)
+ throw new InvalidOperationException();
+
+ return context.Method.GenericParameters[((GenericParameter)type).Position];
+ }
+
+ throw new NotSupportedException(type.etype.ToString());
+ }
+
+ public FieldReference ImportField(FieldReference field, IGenericContext context)
+ {
+ var declaring_type = ImportType(field.DeclaringType, context);
+
+ return new FieldReference
+ {
+ Name = field.Name,
+ DeclaringType = declaring_type,
+ FieldType = ImportType(field.FieldType, context ?? declaring_type),
+ };
+ }
+
+ public MethodReference ImportMethod(MethodReference method, IGenericContext context)
+ {
+ if (method.IsGenericInstance)
+ return ImportMethodSpecification(method, context);
+
+ var declaring_type = ImportType(method.DeclaringType, context);
+
+ var reference = new MethodReference
+ {
+ Name = method.Name,
+ HasThis = method.HasThis,
+ ExplicitThis = method.ExplicitThis,
+ DeclaringType = declaring_type,
+ };
+
+ reference.CallingConvention = method.CallingConvention;
+
+ if (method.HasGenericParameters)
+ ImportGenericParameters(reference, method);
+
+ reference.ReturnType = ImportType(method.ReturnType, context ?? reference);
+
+ if (!method.HasParameters)
+ return reference;
+
+ var reference_parameters = reference.Parameters;
+
+ var parameters = method.Parameters;
+ for (int i = 0; i < parameters.Count; i++)
+ reference_parameters.Add(
+ new ParameterDefinition(ImportType(parameters[i].ParameterType, context ?? reference)));
+
+ return reference;
+ }
+
+ MethodSpecification ImportMethodSpecification(MethodReference method, IGenericContext context)
+ {
+ if (!method.IsGenericInstance)
+ throw new NotSupportedException();
+
+ var instance = (GenericInstanceMethod)method;
+ var element_method = ImportMethod(instance.ElementMethod, context);
+ var imported_instance = new GenericInstanceMethod(element_method);
+
+ var arguments = instance.GenericArguments;
+ var imported_arguments = imported_instance.GenericArguments;
+
+ for (int i = 0; i < arguments.Count; i++)
+ imported_arguments.Add(ImportType(arguments[i], context));
+
+ return imported_instance;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/LinkedResource.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/LinkedResource.cs
new file mode 100644
index 00000000..16c1d59b
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/LinkedResource.cs
@@ -0,0 +1,60 @@
+//
+// LinkedResource.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ public sealed class LinkedResource : Resource {
+
+ internal byte [] hash;
+ string file;
+
+ public byte [] Hash {
+ get { return hash; }
+ }
+
+ public string File {
+ get { return file; }
+ set { file = value; }
+ }
+
+ public override ResourceType ResourceType {
+ get { return ResourceType.Linked; }
+ }
+
+ public LinkedResource (string name, ManifestResourceAttributes flags)
+ : base (name, flags)
+ {
+ }
+
+ public LinkedResource (string name, ManifestResourceAttributes flags, string file)
+ : base (name, flags)
+ {
+ this.file = file;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/ManifestResourceAttributes.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/ManifestResourceAttributes.cs
new file mode 100644
index 00000000..7d6bb190
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/ManifestResourceAttributes.cs
@@ -0,0 +1,39 @@
+//
+// ManifestResourceAttributes.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ [Flags]
+ public enum ManifestResourceAttributes : uint {
+ VisibilityMask = 0x0007,
+ Public = 0x0001, // The resource is exported from the Assembly
+ Private = 0x0002 // The resource is private to the Assembly
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/MarshalInfo.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/MarshalInfo.cs
new file mode 100644
index 00000000..9d587389
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/MarshalInfo.cs
@@ -0,0 +1,171 @@
+//
+// MarshalInfo.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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 {
+
+ public class MarshalInfo {
+
+ internal NativeType native;
+
+ public NativeType NativeType {
+ get { return native; }
+ set { native = value; }
+ }
+
+ public MarshalInfo (NativeType native)
+ {
+ this.native = native;
+ }
+ }
+
+ public sealed class ArrayMarshalInfo : MarshalInfo {
+
+ internal NativeType element_type;
+ internal int size_parameter_index;
+ internal int size;
+ internal int size_parameter_multiplier;
+
+ public NativeType ElementType {
+ get { return element_type; }
+ set { element_type = value; }
+ }
+
+ public int SizeParameterIndex {
+ get { return size_parameter_index; }
+ set { size_parameter_index = value; }
+ }
+
+ public int Size {
+ get { return size; }
+ set { size = value; }
+ }
+
+ public int SizeParameterMultiplier {
+ get { return size_parameter_multiplier; }
+ set { size_parameter_multiplier = value; }
+ }
+
+ public ArrayMarshalInfo ()
+ : base (NativeType.Array)
+ {
+ element_type = NativeType.None;
+ size_parameter_index = -1;
+ size = -1;
+ size_parameter_multiplier = -1;
+ }
+ }
+
+ public sealed class CustomMarshalInfo : MarshalInfo {
+
+ internal Guid guid;
+ internal string unmanaged_type;
+ internal TypeReference managed_type;
+ internal string cookie;
+
+ public Guid Guid {
+ get { return guid; }
+ set { guid = value; }
+ }
+
+ public string UnmanagedType {
+ get { return unmanaged_type; }
+ set { unmanaged_type = value; }
+ }
+
+ public TypeReference ManagedType {
+ get { return managed_type; }
+ set { managed_type = value; }
+ }
+
+ public string Cookie {
+ get { return cookie; }
+ set { cookie = value; }
+ }
+
+ public CustomMarshalInfo ()
+ : base (NativeType.CustomMarshaler)
+ {
+ }
+ }
+
+ public sealed class SafeArrayMarshalInfo : MarshalInfo {
+
+ internal VariantType element_type;
+
+ public VariantType ElementType {
+ get { return element_type; }
+ set { element_type = value; }
+ }
+
+ public SafeArrayMarshalInfo ()
+ : base (NativeType.SafeArray)
+ {
+ element_type = VariantType.None;
+ }
+ }
+
+ public sealed class FixedArrayMarshalInfo : MarshalInfo {
+
+ internal NativeType element_type;
+ internal int size;
+
+ public NativeType ElementType {
+ get { return element_type; }
+ set { element_type = value; }
+ }
+
+ public int Size {
+ get { return size; }
+ set { size = value; }
+ }
+
+ public FixedArrayMarshalInfo ()
+ : base (NativeType.FixedArray)
+ {
+ element_type = NativeType.None;
+ }
+ }
+
+ public sealed class FixedSysStringMarshalInfo : MarshalInfo {
+
+ internal int size;
+
+ public int Size {
+ get { return size; }
+ set { size = value; }
+ }
+
+ public FixedSysStringMarshalInfo ()
+ : base (NativeType.FixedSysString)
+ {
+ size = -1;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/MemberDefinitionCollection.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/MemberDefinitionCollection.cs
new file mode 100644
index 00000000..707f36fb
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/MemberDefinitionCollection.cs
@@ -0,0 +1,92 @@
+//
+// MemberDefinitionCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Collections.Generic;
+
+namespace Mono.Cecil {
+
+ class MemberDefinitionCollection : Collection where T : IMemberDefinition {
+
+ TypeDefinition container;
+
+ internal MemberDefinitionCollection (TypeDefinition container)
+ {
+ this.container = container;
+ }
+
+ internal MemberDefinitionCollection (TypeDefinition container, int capacity)
+ : base (capacity)
+ {
+ this.container = container;
+ }
+
+ protected override void OnAdd (T item, int index)
+ {
+ Attach (item);
+ }
+
+ protected sealed override void OnSet (T item, int index)
+ {
+ Attach (item);
+ }
+
+ protected sealed override void OnInsert (T item, int index)
+ {
+ Attach (item);
+ }
+
+ protected sealed override void OnRemove (T item, int index)
+ {
+ Detach (item);
+ }
+
+ protected sealed override void OnClear ()
+ {
+ foreach (var definition in this)
+ Detach (definition);
+ }
+
+ void Attach (T element)
+ {
+ if (element.DeclaringType == container)
+ return;
+
+ if (element.DeclaringType != null)
+ throw new ArgumentException ("Member already attached");
+
+ element.DeclaringType = this.container;
+ }
+
+ static void Detach (T element)
+ {
+ element.DeclaringType = null;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/MemberReference.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/MemberReference.cs
new file mode 100644
index 00000000..b658c513
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/MemberReference.cs
@@ -0,0 +1,101 @@
+//
+// MemberReference.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace Mono.Cecil {
+
+ public abstract class MemberReference : IMetadataTokenProvider {
+
+ string name;
+ TypeReference declaring_type;
+
+ internal MetadataToken token;
+
+ public virtual string Name {
+ get { return name; }
+ set { name = value; }
+ }
+
+ public abstract string FullName {
+ get;
+ }
+
+ public virtual TypeReference DeclaringType {
+ get { return declaring_type; }
+ set { declaring_type = value; }
+ }
+
+ public MetadataToken MetadataToken {
+ get { return token; }
+ set { token = value; }
+ }
+
+ internal bool HasImage {
+ get {
+ var module = Module;
+ if (module == null)
+ return false;
+
+ return module.HasImage;
+ }
+ }
+
+ public virtual ModuleDefinition Module {
+ get { return declaring_type != null ? declaring_type.Module : null; }
+ }
+
+ public virtual bool IsDefinition {
+ get { return false; }
+ }
+
+ internal virtual bool ContainsGenericParameter {
+ get { return declaring_type != null && declaring_type.ContainsGenericParameter; }
+ }
+
+ internal MemberReference ()
+ {
+ }
+
+ internal MemberReference (string name)
+ {
+ this.name = name ?? string.Empty;
+ }
+
+ internal string MemberFullName ()
+ {
+ if (declaring_type == null)
+ return name;
+
+ return declaring_type.FullName + "::" + name;
+ }
+
+ public override string ToString ()
+ {
+ return FullName;
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/MetadataResolver.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/MetadataResolver.cs
new file mode 100644
index 00000000..9e8abe5b
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/MetadataResolver.cs
@@ -0,0 +1,369 @@
+//
+// MetadataResolver.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Collections.Generic;
+
+namespace Mono.Cecil
+{
+
+ public interface IAssemblyResolver
+ {
+ AssemblyDefinition Resolve(AssemblyNameReference name);
+ AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters);
+
+ AssemblyDefinition Resolve(string fullName);
+ AssemblyDefinition Resolve(string fullName, ReaderParameters parameters);
+ }
+
+ public interface IMetadataResolver
+ {
+ TypeDefinition Resolve(TypeReference type);
+ FieldDefinition Resolve(FieldReference field);
+ MethodDefinition Resolve(MethodReference method);
+ }
+
+
+ public class ResolutionException : Exception
+ {
+
+ readonly MemberReference member;
+
+ public MemberReference Member
+ {
+ get { return member; }
+ }
+
+ public ResolutionException(MemberReference member)
+ : base("Failed to resolve " + member.FullName)
+ {
+ this.member = member;
+ }
+
+
+ }
+
+ public class MetadataResolver : IMetadataResolver
+ {
+
+ readonly IAssemblyResolver assembly_resolver;
+
+ public IAssemblyResolver AssemblyResolver
+ {
+ get { return assembly_resolver; }
+ }
+
+ public MetadataResolver(IAssemblyResolver assemblyResolver)
+ {
+ if (assemblyResolver == null)
+ throw new ArgumentNullException("assemblyResolver");
+
+ assembly_resolver = assemblyResolver;
+ }
+
+ public virtual TypeDefinition Resolve(TypeReference type)
+ {
+ if (type == null)
+ throw new ArgumentNullException("type");
+
+ type = type.GetElementType();
+
+ var scope = type.Scope;
+ switch (scope.MetadataScopeType)
+ {
+ case MetadataScopeType.AssemblyNameReference:
+ var assembly = assembly_resolver.Resolve((AssemblyNameReference)scope);
+ if (assembly == null)
+ return null;
+
+ return GetType(assembly.MainModule, type);
+ case MetadataScopeType.ModuleDefinition:
+ return GetType((ModuleDefinition)scope, type);
+ case MetadataScopeType.ModuleReference:
+ var modules = type.Module.Assembly.Modules;
+ var module_ref = (ModuleReference)scope;
+ for (int i = 0; i < modules.Count; i++)
+ {
+ var netmodule = modules[i];
+ if (netmodule.Name == module_ref.Name)
+ return GetType(netmodule, type);
+ }
+ break;
+ }
+
+ throw new NotSupportedException();
+ }
+
+ static TypeDefinition GetType(ModuleDefinition module, TypeReference reference)
+ {
+ var type = GetTypeDefinition(module, reference);
+ if (type != null)
+ return type;
+
+ if (!module.HasExportedTypes)
+ return null;
+
+ var exported_types = module.ExportedTypes;
+
+ for (int i = 0; i < exported_types.Count; i++)
+ {
+ var exported_type = exported_types[i];
+ if (exported_type.Name != reference.Name)
+ continue;
+
+ if (exported_type.Namespace != reference.Namespace)
+ continue;
+
+ return exported_type.Resolve();
+ }
+
+ return null;
+ }
+
+ static TypeDefinition GetTypeDefinition(ModuleDefinition module, TypeReference type)
+ {
+ if (!type.IsNested)
+ return module.GetType(type.Namespace, type.Name);
+
+ var declaring_type = type.DeclaringType.Resolve();
+ if (declaring_type == null)
+ return null;
+
+ return Mixin.GetNestedType(declaring_type, type.Name);
+ }
+
+ public virtual FieldDefinition Resolve(FieldReference field)
+ {
+ if (field == null)
+ throw new ArgumentNullException("field");
+
+ var type = Resolve(field.DeclaringType);
+ if (type == null)
+ return null;
+
+ if (!type.HasFields)
+ return null;
+
+ return GetField(type, field);
+ }
+
+ FieldDefinition GetField(TypeDefinition type, FieldReference reference)
+ {
+ while (type != null)
+ {
+ var field = GetField(type.Fields, reference);
+ if (field != null)
+ return field;
+
+ if (type.BaseType == null)
+ return null;
+
+ type = Resolve(type.BaseType);
+ }
+
+ return null;
+ }
+
+ static FieldDefinition GetField(Collection fields, FieldReference reference)
+ {
+ for (int i = 0; i < fields.Count; i++)
+ {
+ var field = fields[i];
+
+ if (field.Name != reference.Name)
+ continue;
+
+ if (!AreSame(field.FieldType, reference.FieldType))
+ continue;
+
+ return field;
+ }
+
+ return null;
+ }
+
+ public virtual MethodDefinition Resolve(MethodReference method)
+ {
+ if (method == null)
+ throw new ArgumentNullException("method");
+
+ var type = Resolve(method.DeclaringType);
+ if (type == null)
+ return null;
+
+ method = method.GetElementMethod();
+
+ if (!type.HasMethods)
+ return null;
+
+ return GetMethod(type, method);
+ }
+
+ MethodDefinition GetMethod(TypeDefinition type, MethodReference reference)
+ {
+ while (type != null)
+ {
+ var method = GetMethod(type.Methods, reference);
+ if (method != null)
+ return method;
+
+ if (type.BaseType == null)
+ return null;
+
+ type = Resolve(type.BaseType);
+ }
+
+ return null;
+ }
+
+ public static MethodDefinition GetMethod(Collection methods, MethodReference reference)
+ {
+ for (int i = 0; i < methods.Count; i++)
+ {
+ var method = methods[i];
+
+ if (method.Name != reference.Name)
+ continue;
+
+ if (method.HasGenericParameters != reference.HasGenericParameters)
+ continue;
+
+ if (method.HasGenericParameters && method.GenericParameters.Count != reference.GenericParameters.Count)
+ continue;
+
+ if (!AreSame(method.ReturnType, reference.ReturnType))
+ continue;
+
+ if (method.HasParameters != reference.HasParameters)
+ continue;
+
+ if (!method.HasParameters && !reference.HasParameters)
+ return method;
+
+ if (!AreSame(method.Parameters, reference.Parameters))
+ continue;
+
+ return method;
+ }
+
+ return null;
+ }
+
+ static bool AreSame(Collection a, Collection b)
+ {
+ var count = a.Count;
+
+ if (count != b.Count)
+ return false;
+
+ if (count == 0)
+ return true;
+
+ for (int i = 0; i < count; i++)
+ if (!AreSame(a[i].ParameterType, b[i].ParameterType))
+ return false;
+
+ return true;
+ }
+
+ static bool AreSame(TypeSpecification a, TypeSpecification b)
+ {
+ if (!AreSame(a.ElementType, b.ElementType))
+ return false;
+
+ if (a.IsGenericInstance)
+ return AreSame((GenericInstanceType)a, (GenericInstanceType)b);
+
+ if (a.IsRequiredModifier || a.IsOptionalModifier)
+ return AreSame((IModifierType)a, (IModifierType)b);
+
+ if (a.IsArray)
+ return AreSame((ArrayType)a, (ArrayType)b);
+
+ return true;
+ }
+
+ static bool AreSame(ArrayType a, ArrayType b)
+ {
+ if (a.Rank != b.Rank)
+ return false;
+
+ // TODO: dimensions
+
+ return true;
+ }
+
+ static bool AreSame(IModifierType a, IModifierType b)
+ {
+ return AreSame(a.ModifierType, b.ModifierType);
+ }
+
+ static bool AreSame(GenericInstanceType a, GenericInstanceType b)
+ {
+ if (a.GenericArguments.Count != b.GenericArguments.Count)
+ return false;
+
+ 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 (ReferenceEquals(a, b))
+ return true;
+
+ if (a == null || b == null)
+ return false;
+
+ if (a.etype != b.etype)
+ return false;
+
+ if (a.IsGenericParameter)
+ return AreSame((GenericParameter)a, (GenericParameter)b);
+
+ if (Mixin.IsTypeSpecification(a))
+ return AreSame((TypeSpecification)a, (TypeSpecification)b);
+
+ if (a.Name != b.Name || a.Namespace != b.Namespace)
+ return false;
+
+ //TODO: check scope
+
+ return AreSame(a.DeclaringType, b.DeclaringType);
+ }
+ }
+}
diff --git a/Mono.Cecil.20/MonoCecil/Mono.Cecil/MetadataSystem.cs b/Mono.Cecil.20/MonoCecil/Mono.Cecil/MetadataSystem.cs
new file mode 100644
index 00000000..25cc8335
--- /dev/null
+++ b/Mono.Cecil.20/MonoCecil/Mono.Cecil/MetadataSystem.cs
@@ -0,0 +1,395 @@
+//
+// MetadataSystem.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2011 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Generic;
+
+using Mono.Cecil.Metadata;
+
+namespace Mono.Cecil {
+
+ struct Range {
+ public uint Start;
+ public uint Length;
+
+ public Range (uint index, uint length)
+ {
+ this.Start = index;
+ this.Length = length;
+ }
+ }
+
+ sealed class MetadataSystem {
+
+ internal AssemblyNameReference [] AssemblyReferences;
+ internal ModuleReference [] ModuleReferences;
+
+ internal TypeDefinition [] Types;
+ internal TypeReference [] TypeReferences;
+
+ internal FieldDefinition [] Fields;
+ internal MethodDefinition [] Methods;
+ internal MemberReference [] MemberReferences;
+
+ internal Dictionary NestedTypes;
+ internal Dictionary ReverseNestedTypes;
+ internal Dictionary Interfaces;
+ internal Dictionary> ClassLayouts;
+ internal Dictionary FieldLayouts;
+ internal Dictionary FieldRVAs;
+ internal Dictionary FieldMarshals;
+ internal Dictionary> Constants;
+ internal Dictionary Overrides;
+ internal Dictionary CustomAttributes;
+ internal Dictionary